@okyrychenko-dev/react-action-guard 0.6.1 → 0.7.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/README.md +2 -2
- package/dist/index.cjs +87 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +87 -85
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -139,7 +139,7 @@ interface UseAsyncActionOptions {
|
|
|
139
139
|
* @public
|
|
140
140
|
* @since 0.6.0
|
|
141
141
|
*/
|
|
142
|
-
declare
|
|
142
|
+
declare function useAsyncAction<T = unknown>(actionId: string, scope?: string | ReadonlyArray<string>, options?: UseAsyncActionOptions): (asyncFn: () => Promise<T>) => Promise<T>;
|
|
143
143
|
|
|
144
144
|
type AnalyticsEventData = Record<string, string | number | ReadonlyArray<string> | undefined>;
|
|
145
145
|
type AnalyticsProvider = "ga" | "mixpanel" | "amplitude";
|
|
@@ -243,7 +243,7 @@ type Middleware = (context: MiddlewareContext) => void | Promise<void>;
|
|
|
243
243
|
* @public
|
|
244
244
|
* @since 0.6.0
|
|
245
245
|
*/
|
|
246
|
-
declare
|
|
246
|
+
declare function createAnalyticsMiddleware(config: AnalyticsConfig): Middleware;
|
|
247
247
|
|
|
248
248
|
/**
|
|
249
249
|
* Configures and registers multiple middleware functions for the UI blocking store.
|
|
@@ -359,7 +359,7 @@ declare function configureMiddleware(middlewares: ReadonlyArray<Middleware>): vo
|
|
|
359
359
|
* @public
|
|
360
360
|
* @since 0.6.0
|
|
361
361
|
*/
|
|
362
|
-
declare
|
|
362
|
+
declare function loggerMiddleware(context: MiddlewareContext): void;
|
|
363
363
|
|
|
364
364
|
interface PerformanceConfig {
|
|
365
365
|
slowBlockThreshold?: number;
|
|
@@ -451,7 +451,7 @@ interface PerformanceConfig {
|
|
|
451
451
|
* @public
|
|
452
452
|
* @since 0.6.0
|
|
453
453
|
*/
|
|
454
|
-
declare
|
|
454
|
+
declare function createPerformanceMiddleware(config?: PerformanceConfig): Middleware;
|
|
455
455
|
|
|
456
456
|
/**
|
|
457
457
|
* Configuration options for creating or updating a blocker.
|
|
@@ -727,7 +727,7 @@ declare const uiBlockingStoreApi: zustand.StoreApi<UIBlockingStore>;
|
|
|
727
727
|
* @public
|
|
728
728
|
* @since 0.6.0
|
|
729
729
|
*/
|
|
730
|
-
declare
|
|
730
|
+
declare function useBlocker(blockerId: string, config: BlockerConfig, isActive?: boolean): void;
|
|
731
731
|
|
|
732
732
|
/**
|
|
733
733
|
* Gets detailed information about all active blockers for a specific scope.
|
|
@@ -804,7 +804,7 @@ declare const useBlocker: (blockerId: string, config: BlockerConfig, isActive?:
|
|
|
804
804
|
* @public
|
|
805
805
|
* @since 0.6.0
|
|
806
806
|
*/
|
|
807
|
-
declare
|
|
807
|
+
declare function useBlockingInfo(scope?: string): ReadonlyArray<BlockerInfo>;
|
|
808
808
|
|
|
809
809
|
/**
|
|
810
810
|
* Configuration for conditional blocker hook.
|
|
@@ -969,7 +969,7 @@ interface ConditionalBlockerConfig<TState = unknown> extends Omit<BlockerConfig,
|
|
|
969
969
|
* @public
|
|
970
970
|
* @since 0.6.0
|
|
971
971
|
*/
|
|
972
|
-
declare
|
|
972
|
+
declare function useConditionalBlocker<TState = unknown>(blockerId: string, config: ConditionalBlockerConfig<TState>): void;
|
|
973
973
|
|
|
974
974
|
/**
|
|
975
975
|
* Configuration for the confirmation dialog
|
|
@@ -1145,7 +1145,7 @@ interface UseConfirmableBlockerReturn {
|
|
|
1145
1145
|
* @public
|
|
1146
1146
|
* @since 0.6.0
|
|
1147
1147
|
*/
|
|
1148
|
-
declare
|
|
1148
|
+
declare function useConfirmableBlocker(blockerId: string, config: ConfirmableBlockerConfig): UseConfirmableBlockerReturn;
|
|
1149
1149
|
|
|
1150
1150
|
/**
|
|
1151
1151
|
* Checks if one or more scopes are currently blocked.
|
|
@@ -1219,7 +1219,7 @@ declare const useConfirmableBlocker: (blockerId: string, config: ConfirmableBloc
|
|
|
1219
1219
|
* @public
|
|
1220
1220
|
* @since 0.6.0
|
|
1221
1221
|
*/
|
|
1222
|
-
declare
|
|
1222
|
+
declare function useIsBlocked(scope?: string | ReadonlyArray<string>): boolean;
|
|
1223
1223
|
|
|
1224
1224
|
/**
|
|
1225
1225
|
* Schedule configuration for time-based blocking.
|
|
@@ -1371,7 +1371,7 @@ interface ScheduledBlockerConfig extends BlockerConfig {
|
|
|
1371
1371
|
* @public
|
|
1372
1372
|
* @since 0.6.0
|
|
1373
1373
|
*/
|
|
1374
|
-
declare
|
|
1374
|
+
declare function useScheduledBlocker(blockerId: string, config: ScheduledBlockerConfig): void;
|
|
1375
1375
|
|
|
1376
1376
|
/**
|
|
1377
1377
|
* Default scope type
|
package/dist/index.d.ts
CHANGED
|
@@ -139,7 +139,7 @@ interface UseAsyncActionOptions {
|
|
|
139
139
|
* @public
|
|
140
140
|
* @since 0.6.0
|
|
141
141
|
*/
|
|
142
|
-
declare
|
|
142
|
+
declare function useAsyncAction<T = unknown>(actionId: string, scope?: string | ReadonlyArray<string>, options?: UseAsyncActionOptions): (asyncFn: () => Promise<T>) => Promise<T>;
|
|
143
143
|
|
|
144
144
|
type AnalyticsEventData = Record<string, string | number | ReadonlyArray<string> | undefined>;
|
|
145
145
|
type AnalyticsProvider = "ga" | "mixpanel" | "amplitude";
|
|
@@ -243,7 +243,7 @@ type Middleware = (context: MiddlewareContext) => void | Promise<void>;
|
|
|
243
243
|
* @public
|
|
244
244
|
* @since 0.6.0
|
|
245
245
|
*/
|
|
246
|
-
declare
|
|
246
|
+
declare function createAnalyticsMiddleware(config: AnalyticsConfig): Middleware;
|
|
247
247
|
|
|
248
248
|
/**
|
|
249
249
|
* Configures and registers multiple middleware functions for the UI blocking store.
|
|
@@ -359,7 +359,7 @@ declare function configureMiddleware(middlewares: ReadonlyArray<Middleware>): vo
|
|
|
359
359
|
* @public
|
|
360
360
|
* @since 0.6.0
|
|
361
361
|
*/
|
|
362
|
-
declare
|
|
362
|
+
declare function loggerMiddleware(context: MiddlewareContext): void;
|
|
363
363
|
|
|
364
364
|
interface PerformanceConfig {
|
|
365
365
|
slowBlockThreshold?: number;
|
|
@@ -451,7 +451,7 @@ interface PerformanceConfig {
|
|
|
451
451
|
* @public
|
|
452
452
|
* @since 0.6.0
|
|
453
453
|
*/
|
|
454
|
-
declare
|
|
454
|
+
declare function createPerformanceMiddleware(config?: PerformanceConfig): Middleware;
|
|
455
455
|
|
|
456
456
|
/**
|
|
457
457
|
* Configuration options for creating or updating a blocker.
|
|
@@ -727,7 +727,7 @@ declare const uiBlockingStoreApi: zustand.StoreApi<UIBlockingStore>;
|
|
|
727
727
|
* @public
|
|
728
728
|
* @since 0.6.0
|
|
729
729
|
*/
|
|
730
|
-
declare
|
|
730
|
+
declare function useBlocker(blockerId: string, config: BlockerConfig, isActive?: boolean): void;
|
|
731
731
|
|
|
732
732
|
/**
|
|
733
733
|
* Gets detailed information about all active blockers for a specific scope.
|
|
@@ -804,7 +804,7 @@ declare const useBlocker: (blockerId: string, config: BlockerConfig, isActive?:
|
|
|
804
804
|
* @public
|
|
805
805
|
* @since 0.6.0
|
|
806
806
|
*/
|
|
807
|
-
declare
|
|
807
|
+
declare function useBlockingInfo(scope?: string): ReadonlyArray<BlockerInfo>;
|
|
808
808
|
|
|
809
809
|
/**
|
|
810
810
|
* Configuration for conditional blocker hook.
|
|
@@ -969,7 +969,7 @@ interface ConditionalBlockerConfig<TState = unknown> extends Omit<BlockerConfig,
|
|
|
969
969
|
* @public
|
|
970
970
|
* @since 0.6.0
|
|
971
971
|
*/
|
|
972
|
-
declare
|
|
972
|
+
declare function useConditionalBlocker<TState = unknown>(blockerId: string, config: ConditionalBlockerConfig<TState>): void;
|
|
973
973
|
|
|
974
974
|
/**
|
|
975
975
|
* Configuration for the confirmation dialog
|
|
@@ -1145,7 +1145,7 @@ interface UseConfirmableBlockerReturn {
|
|
|
1145
1145
|
* @public
|
|
1146
1146
|
* @since 0.6.0
|
|
1147
1147
|
*/
|
|
1148
|
-
declare
|
|
1148
|
+
declare function useConfirmableBlocker(blockerId: string, config: ConfirmableBlockerConfig): UseConfirmableBlockerReturn;
|
|
1149
1149
|
|
|
1150
1150
|
/**
|
|
1151
1151
|
* Checks if one or more scopes are currently blocked.
|
|
@@ -1219,7 +1219,7 @@ declare const useConfirmableBlocker: (blockerId: string, config: ConfirmableBloc
|
|
|
1219
1219
|
* @public
|
|
1220
1220
|
* @since 0.6.0
|
|
1221
1221
|
*/
|
|
1222
|
-
declare
|
|
1222
|
+
declare function useIsBlocked(scope?: string | ReadonlyArray<string>): boolean;
|
|
1223
1223
|
|
|
1224
1224
|
/**
|
|
1225
1225
|
* Schedule configuration for time-based blocking.
|
|
@@ -1371,7 +1371,7 @@ interface ScheduledBlockerConfig extends BlockerConfig {
|
|
|
1371
1371
|
* @public
|
|
1372
1372
|
* @since 0.6.0
|
|
1373
1373
|
*/
|
|
1374
|
-
declare
|
|
1374
|
+
declare function useScheduledBlocker(blockerId: string, config: ScheduledBlockerConfig): void;
|
|
1375
1375
|
|
|
1376
1376
|
/**
|
|
1377
1377
|
* Default scope type
|
package/dist/index.js
CHANGED
|
@@ -23,16 +23,18 @@ function normalizeScopeToArray(scope) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// src/store/uiBlockingStore.actions.ts
|
|
26
|
-
|
|
26
|
+
function normalizePriority(priority, fallback = DEFAULT_PRIORITY) {
|
|
27
27
|
return priority !== void 0 ? Math.max(0, priority) : fallback;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
28
|
+
}
|
|
29
|
+
function createMiddlewareContext(action, blockerId, config, prevState) {
|
|
30
|
+
return {
|
|
31
|
+
action,
|
|
32
|
+
blockerId,
|
|
33
|
+
config,
|
|
34
|
+
timestamp: Date.now(),
|
|
35
|
+
...prevState && { prevState }
|
|
36
|
+
};
|
|
37
|
+
}
|
|
36
38
|
var createUIBlockingActions = (set, get) => ({
|
|
37
39
|
// State
|
|
38
40
|
activeBlockers: /* @__PURE__ */ new Map(),
|
|
@@ -64,14 +66,14 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
64
66
|
// Actions
|
|
65
67
|
/**
|
|
66
68
|
* Adds a new blocker or overwrites an existing one.
|
|
67
|
-
*
|
|
69
|
+
*
|
|
68
70
|
* If a blocker with the same ID already exists, it will be replaced and any
|
|
69
71
|
* existing timeout will be cleared. The blocker is active immediately after
|
|
70
72
|
* being added. Triggers middleware with 'add' action.
|
|
71
|
-
*
|
|
73
|
+
*
|
|
72
74
|
* @param id - Unique identifier for the blocker. Must be unique within the store.
|
|
73
75
|
* @param config - Blocker configuration. All fields are optional with defaults applied.
|
|
74
|
-
*
|
|
76
|
+
*
|
|
75
77
|
* @example
|
|
76
78
|
* Basic usage
|
|
77
79
|
* ```ts
|
|
@@ -81,7 +83,7 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
81
83
|
* priority: 70
|
|
82
84
|
* });
|
|
83
85
|
* ```
|
|
84
|
-
*
|
|
86
|
+
*
|
|
85
87
|
* @example
|
|
86
88
|
* With timeout
|
|
87
89
|
* ```ts
|
|
@@ -92,7 +94,7 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
92
94
|
* onTimeout: (id) => console.warn(`${id} timed out`)
|
|
93
95
|
* });
|
|
94
96
|
* ```
|
|
95
|
-
*
|
|
97
|
+
*
|
|
96
98
|
* @see {@link removeBlocker} to remove a blocker
|
|
97
99
|
* @see {@link updateBlocker} to update an existing blocker
|
|
98
100
|
*/
|
|
@@ -143,13 +145,13 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
143
145
|
},
|
|
144
146
|
/**
|
|
145
147
|
* Updates an existing blocker or creates it if it doesn't exist.
|
|
146
|
-
*
|
|
148
|
+
*
|
|
147
149
|
* Merges the provided configuration with existing blocker data. If the timeout
|
|
148
150
|
* is changed, the timeout timer is restarted. Triggers middleware with 'update' action.
|
|
149
|
-
*
|
|
151
|
+
*
|
|
150
152
|
* @param id - Identifier of the blocker to update
|
|
151
153
|
* @param config - Partial configuration to merge with existing blocker data
|
|
152
|
-
*
|
|
154
|
+
*
|
|
153
155
|
* @example
|
|
154
156
|
* Update blocker reason
|
|
155
157
|
* ```ts
|
|
@@ -157,7 +159,7 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
157
159
|
* reason: 'Saving additional data...'
|
|
158
160
|
* });
|
|
159
161
|
* ```
|
|
160
|
-
*
|
|
162
|
+
*
|
|
161
163
|
* @example
|
|
162
164
|
* Extend timeout
|
|
163
165
|
* ```ts
|
|
@@ -165,7 +167,7 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
165
167
|
* timeout: 60000 // Extend to 60 seconds
|
|
166
168
|
* });
|
|
167
169
|
* ```
|
|
168
|
-
*
|
|
170
|
+
*
|
|
169
171
|
* @see {@link addBlocker} to create a new blocker
|
|
170
172
|
*/
|
|
171
173
|
updateBlocker: (id, config = {}) => {
|
|
@@ -241,12 +243,12 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
241
243
|
},
|
|
242
244
|
/**
|
|
243
245
|
* Removes a blocker from the store.
|
|
244
|
-
*
|
|
246
|
+
*
|
|
245
247
|
* Clears any associated timeout and triggers middleware with 'remove' action.
|
|
246
248
|
* Safe to call even if the blocker doesn't exist (no-op in that case).
|
|
247
|
-
*
|
|
249
|
+
*
|
|
248
250
|
* @param id - Identifier of the blocker to remove
|
|
249
|
-
*
|
|
251
|
+
*
|
|
250
252
|
* @example
|
|
251
253
|
* ```ts
|
|
252
254
|
* // Add and remove a blocker
|
|
@@ -254,7 +256,7 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
254
256
|
* // ... later
|
|
255
257
|
* store.getState().removeBlocker('temp');
|
|
256
258
|
* ```
|
|
257
|
-
*
|
|
259
|
+
*
|
|
258
260
|
* @see {@link addBlocker} to add a blocker
|
|
259
261
|
* @see {@link clearAllBlockers} to remove all blockers at once
|
|
260
262
|
*/
|
|
@@ -274,28 +276,28 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
274
276
|
},
|
|
275
277
|
/**
|
|
276
278
|
* Checks if one or more scopes are currently blocked.
|
|
277
|
-
*
|
|
279
|
+
*
|
|
278
280
|
* Returns true if ANY blocker affects the specified scope(s). Global scope
|
|
279
281
|
* blockers will cause this to return true for any scope check.
|
|
280
|
-
*
|
|
282
|
+
*
|
|
281
283
|
* @param scope - Scope(s) to check. Defaults to "global" if not specified.
|
|
282
284
|
* Can be a single scope string or array of scopes.
|
|
283
285
|
* @returns true if any of the specified scopes are currently blocked
|
|
284
|
-
*
|
|
286
|
+
*
|
|
285
287
|
* @example
|
|
286
288
|
* Single scope check
|
|
287
289
|
* ```ts
|
|
288
290
|
* const isFormBlocked = store.getState().isBlocked('form');
|
|
289
291
|
* console.log(isFormBlocked); // true or false
|
|
290
292
|
* ```
|
|
291
|
-
*
|
|
293
|
+
*
|
|
292
294
|
* @example
|
|
293
295
|
* Multiple scopes check
|
|
294
296
|
* ```ts
|
|
295
297
|
* const isBlocked = store.getState().isBlocked(['form', 'navigation']);
|
|
296
298
|
* // Returns true if either 'form' OR 'navigation' has active blockers
|
|
297
299
|
* ```
|
|
298
|
-
*
|
|
300
|
+
*
|
|
299
301
|
* @see {@link getBlockingInfo} for detailed blocker information
|
|
300
302
|
*/
|
|
301
303
|
isBlocked: (scope = DEFAULT_SCOPE) => {
|
|
@@ -314,14 +316,14 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
314
316
|
},
|
|
315
317
|
/**
|
|
316
318
|
* Gets detailed information about all blockers affecting a specific scope.
|
|
317
|
-
*
|
|
319
|
+
*
|
|
318
320
|
* Returns an array of blocker objects sorted by priority (highest first).
|
|
319
321
|
* Includes global blockers and scope-specific blockers. Each blocker object
|
|
320
322
|
* contains id, reason, priority, scope, timestamp, and timeout information.
|
|
321
|
-
*
|
|
323
|
+
*
|
|
322
324
|
* @param scope - Scope to get blocking information for
|
|
323
325
|
* @returns Array of {@link BlockerInfo} objects, sorted by priority descending
|
|
324
|
-
*
|
|
326
|
+
*
|
|
325
327
|
* @example
|
|
326
328
|
* Display blocker details
|
|
327
329
|
* ```ts
|
|
@@ -331,7 +333,7 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
331
333
|
* console.log(`Priority: ${blocker.priority}`);
|
|
332
334
|
* });
|
|
333
335
|
* ```
|
|
334
|
-
*
|
|
336
|
+
*
|
|
335
337
|
* @example
|
|
336
338
|
* Get highest priority blocker
|
|
337
339
|
* ```ts
|
|
@@ -341,7 +343,7 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
341
343
|
* console.log(`Top blocker: ${topBlocker.reason}`);
|
|
342
344
|
* }
|
|
343
345
|
* ```
|
|
344
|
-
*
|
|
346
|
+
*
|
|
345
347
|
* @see {@link isBlocked} for a simple boolean check
|
|
346
348
|
* @see {@link BlockerInfo} for the structure of returned objects
|
|
347
349
|
*/
|
|
@@ -358,16 +360,16 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
358
360
|
},
|
|
359
361
|
/**
|
|
360
362
|
* Removes all active blockers from the store.
|
|
361
|
-
*
|
|
363
|
+
*
|
|
362
364
|
* Clears all timeouts and triggers middleware with 'clear' action.
|
|
363
365
|
* Useful for resetting the blocking state.
|
|
364
|
-
*
|
|
366
|
+
*
|
|
365
367
|
* @example
|
|
366
368
|
* ```ts
|
|
367
369
|
* // Clear all blockers on logout
|
|
368
370
|
* store.getState().clearAllBlockers();
|
|
369
371
|
* ```
|
|
370
|
-
*
|
|
372
|
+
*
|
|
371
373
|
* @see {@link clearBlockersForScope} to clear blockers for a specific scope
|
|
372
374
|
*/
|
|
373
375
|
clearAllBlockers: () => {
|
|
@@ -390,26 +392,26 @@ var createUIBlockingActions = (set, get) => ({
|
|
|
390
392
|
},
|
|
391
393
|
/**
|
|
392
394
|
* Removes all blockers that affect a specific scope.
|
|
393
|
-
*
|
|
395
|
+
*
|
|
394
396
|
* Clears timeouts for removed blockers and triggers middleware with
|
|
395
397
|
* 'clear_scope' action. Global scope blockers are NOT cleared by this method.
|
|
396
|
-
*
|
|
398
|
+
*
|
|
397
399
|
* @param scope - Scope to clear blockers for
|
|
398
|
-
*
|
|
400
|
+
*
|
|
399
401
|
* @example
|
|
400
402
|
* Clear form blockers
|
|
401
403
|
* ```ts
|
|
402
404
|
* // Clear all blockers affecting 'form' scope
|
|
403
405
|
* store.getState().clearBlockersForScope('form');
|
|
404
406
|
* ```
|
|
405
|
-
*
|
|
407
|
+
*
|
|
406
408
|
* @example
|
|
407
409
|
* Clear on navigation
|
|
408
410
|
* ```ts
|
|
409
411
|
* // Clear navigation blockers when user navigates away
|
|
410
412
|
* store.getState().clearBlockersForScope('navigation');
|
|
411
413
|
* ```
|
|
412
|
-
*
|
|
414
|
+
*
|
|
413
415
|
* @see {@link clearAllBlockers} to clear all blockers
|
|
414
416
|
*/
|
|
415
417
|
clearBlockersForScope: (scope) => {
|
|
@@ -497,7 +499,7 @@ function useResolvedStoreWithSelector(selector) {
|
|
|
497
499
|
}
|
|
498
500
|
|
|
499
501
|
// src/hooks/useAsyncAction/useAsyncAction.ts
|
|
500
|
-
|
|
502
|
+
function useAsyncAction(actionId, scope, options) {
|
|
501
503
|
const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({
|
|
502
504
|
addBlocker: state.addBlocker,
|
|
503
505
|
removeBlocker: state.removeBlocker
|
|
@@ -523,8 +525,8 @@ var useAsyncAction = (actionId, scope, options) => {
|
|
|
523
525
|
[actionId, scope, options?.timeout, options?.onTimeout, addBlocker, removeBlocker]
|
|
524
526
|
);
|
|
525
527
|
return executeWithBlocking;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
+
}
|
|
529
|
+
function useBlocker(blockerId, config, isActive = true) {
|
|
528
530
|
const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({
|
|
529
531
|
addBlocker: state.addBlocker,
|
|
530
532
|
removeBlocker: state.removeBlocker
|
|
@@ -538,7 +540,7 @@ var useBlocker = (blockerId, config, isActive = true) => {
|
|
|
538
540
|
removeBlocker(blockerId);
|
|
539
541
|
};
|
|
540
542
|
}, [blockerId, isActive, addBlocker, removeBlocker]);
|
|
541
|
-
}
|
|
543
|
+
}
|
|
542
544
|
|
|
543
545
|
// src/hooks/useBlocker/useBlocker.utils.ts
|
|
544
546
|
function createBlockerConfig(config) {
|
|
@@ -548,13 +550,13 @@ function createBlockerConfig(config) {
|
|
|
548
550
|
priority: config.priority
|
|
549
551
|
};
|
|
550
552
|
}
|
|
551
|
-
|
|
553
|
+
function useBlockingInfo(scope = DEFAULT_SCOPE) {
|
|
552
554
|
const store = useResolvedStore();
|
|
553
555
|
const activeBlockers = useStore(store, (state) => state.activeBlockers);
|
|
554
556
|
return useMemo(() => {
|
|
555
557
|
return store.getState().getBlockingInfo(scope);
|
|
556
558
|
}, [activeBlockers, scope, store]);
|
|
557
|
-
}
|
|
559
|
+
}
|
|
558
560
|
function useConfigRef(config) {
|
|
559
561
|
const configRef = useRef(config);
|
|
560
562
|
useEffect(() => {
|
|
@@ -564,7 +566,7 @@ function useConfigRef(config) {
|
|
|
564
566
|
}
|
|
565
567
|
|
|
566
568
|
// src/hooks/useConditionalBlocker/useConditionalBlocker.ts
|
|
567
|
-
|
|
569
|
+
function useConditionalBlocker(blockerId, config) {
|
|
568
570
|
const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({
|
|
569
571
|
addBlocker: state.addBlocker,
|
|
570
572
|
removeBlocker: state.removeBlocker
|
|
@@ -600,8 +602,8 @@ var useConditionalBlocker = (blockerId, config) => {
|
|
|
600
602
|
}
|
|
601
603
|
};
|
|
602
604
|
}, [checkCondition, blockerId, removeBlocker]);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
+
}
|
|
606
|
+
function useConfirmableBlocker(blockerId, config) {
|
|
605
607
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
|
606
608
|
const [isExecuting, setIsExecuting] = useState(false);
|
|
607
609
|
useBlocker(
|
|
@@ -644,12 +646,12 @@ var useConfirmableBlocker = (blockerId, config) => {
|
|
|
644
646
|
onConfirm,
|
|
645
647
|
onCancel
|
|
646
648
|
};
|
|
647
|
-
}
|
|
649
|
+
}
|
|
648
650
|
|
|
649
651
|
// src/hooks/useIsBlocked/useIsBlocked.ts
|
|
650
|
-
|
|
652
|
+
function useIsBlocked(scope) {
|
|
651
653
|
return useResolvedStoreWithSelector((state) => state.isBlocked(scope));
|
|
652
|
-
}
|
|
654
|
+
}
|
|
653
655
|
|
|
654
656
|
// src/hooks/useScheduledBlocker/useScheduledBlocker.utils.ts
|
|
655
657
|
var MAX_TIMEOUT_MS = 2147483647;
|
|
@@ -689,7 +691,7 @@ function isScheduleInPast(startTime, endTime, now) {
|
|
|
689
691
|
}
|
|
690
692
|
|
|
691
693
|
// src/hooks/useScheduledBlocker/useScheduledBlocker.ts
|
|
692
|
-
|
|
694
|
+
function useScheduledBlocker(blockerId, config) {
|
|
693
695
|
const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({
|
|
694
696
|
addBlocker: state.addBlocker,
|
|
695
697
|
removeBlocker: state.removeBlocker
|
|
@@ -755,13 +757,13 @@ var useScheduledBlocker = (blockerId, config) => {
|
|
|
755
757
|
removeBlocker(blockerId);
|
|
756
758
|
};
|
|
757
759
|
}, [blockerId, addBlocker, removeBlocker, cleanup]);
|
|
758
|
-
}
|
|
760
|
+
}
|
|
759
761
|
|
|
760
762
|
// src/middleware/analyticsMiddleware.utils.ts
|
|
761
|
-
|
|
763
|
+
function capitalizeFirst(str) {
|
|
762
764
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
+
}
|
|
766
|
+
function buildEventData(context) {
|
|
765
767
|
const eventData = {
|
|
766
768
|
blocker_id: context.blockerId
|
|
767
769
|
};
|
|
@@ -776,33 +778,33 @@ var buildEventData = (context) => {
|
|
|
776
778
|
eventData.priority = priority;
|
|
777
779
|
}
|
|
778
780
|
return eventData;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
+
}
|
|
782
|
+
function trackGoogleAnalytics(action, eventData) {
|
|
781
783
|
if (window.gtag) {
|
|
782
784
|
window.gtag("event", `ui_blocking_${action}`, eventData);
|
|
783
785
|
}
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
+
}
|
|
787
|
+
function trackMixpanel(action, eventData) {
|
|
786
788
|
if (window.mixpanel) {
|
|
787
789
|
const eventName = `UI Blocking ${action.split("_").map(capitalizeFirst).join(" ")}`;
|
|
788
790
|
window.mixpanel.track(eventName, eventData);
|
|
789
791
|
}
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
+
}
|
|
793
|
+
function trackAmplitude(action, eventData) {
|
|
792
794
|
if (window.amplitude) {
|
|
793
795
|
const eventName = `UI Blocking ${action.split("_").map(capitalizeFirst).join(" ")}`;
|
|
794
796
|
window.amplitude.track(eventName, eventData);
|
|
795
797
|
}
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
+
}
|
|
799
|
+
function trackCustom(trackFn, action, eventData) {
|
|
798
800
|
try {
|
|
799
801
|
trackFn(`ui_blocking_${action}`, eventData);
|
|
800
802
|
} catch {
|
|
801
803
|
}
|
|
802
|
-
}
|
|
804
|
+
}
|
|
803
805
|
|
|
804
806
|
// src/middleware/analyticsMiddleware.ts
|
|
805
|
-
|
|
807
|
+
function trackEvent(config, context, eventData) {
|
|
806
808
|
if ("provider" in config) {
|
|
807
809
|
switch (config.provider) {
|
|
808
810
|
case "ga":
|
|
@@ -819,13 +821,13 @@ var trackEvent = (config, context, eventData) => {
|
|
|
819
821
|
if ("track" in config) {
|
|
820
822
|
trackCustom(config.track, context.action, eventData);
|
|
821
823
|
}
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
+
}
|
|
825
|
+
function createAnalyticsMiddleware(config) {
|
|
824
826
|
return (context) => {
|
|
825
827
|
const eventData = buildEventData(context);
|
|
826
828
|
trackEvent(config, context, eventData);
|
|
827
829
|
};
|
|
828
|
-
}
|
|
830
|
+
}
|
|
829
831
|
|
|
830
832
|
// src/middleware/configureMiddleware.ts
|
|
831
833
|
function configureMiddleware(middlewares) {
|
|
@@ -837,7 +839,7 @@ function configureMiddleware(middlewares) {
|
|
|
837
839
|
}
|
|
838
840
|
|
|
839
841
|
// src/middleware/loggerMiddleware.utils.ts
|
|
840
|
-
|
|
842
|
+
function getActionEmoji(action) {
|
|
841
843
|
switch (action) {
|
|
842
844
|
case "add":
|
|
843
845
|
return "\u2795";
|
|
@@ -854,8 +856,8 @@ var getActionEmoji = (action) => {
|
|
|
854
856
|
default:
|
|
855
857
|
return "\u2753";
|
|
856
858
|
}
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
+
}
|
|
860
|
+
function extractConfigDetails(config) {
|
|
859
861
|
if (!config) {
|
|
860
862
|
return {};
|
|
861
863
|
}
|
|
@@ -868,8 +870,8 @@ var extractConfigDetails = (config) => {
|
|
|
868
870
|
details.priority = priority;
|
|
869
871
|
}
|
|
870
872
|
return details;
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
+
}
|
|
874
|
+
function formatLogData(context) {
|
|
873
875
|
const configDetails = extractConfigDetails(context.config);
|
|
874
876
|
const logData = {};
|
|
875
877
|
if (context.scope !== void 0) {
|
|
@@ -888,26 +890,26 @@ var formatLogData = (context) => {
|
|
|
888
890
|
return configDetails;
|
|
889
891
|
}
|
|
890
892
|
return Object.keys(logData).length === 1 && logData.config ? configDetails : logData;
|
|
891
|
-
}
|
|
893
|
+
}
|
|
892
894
|
|
|
893
895
|
// src/middleware/loggerMiddleware.ts
|
|
894
896
|
var LOG_PREFIX = "[UIBlocking]";
|
|
895
|
-
|
|
897
|
+
function loggerMiddleware(context) {
|
|
896
898
|
const emoji = getActionEmoji(context.action);
|
|
897
899
|
const logData = formatLogData(context);
|
|
898
900
|
console.log(LOG_PREFIX, emoji, context.blockerId, logData);
|
|
899
|
-
}
|
|
901
|
+
}
|
|
900
902
|
|
|
901
903
|
// src/middleware/performanceMiddleware.utils.ts
|
|
902
|
-
|
|
904
|
+
function handleAddAction(blockerId, timestamp, blockStartTimes) {
|
|
903
905
|
blockStartTimes.set(blockerId, timestamp);
|
|
904
|
-
}
|
|
906
|
+
}
|
|
905
907
|
|
|
906
908
|
// src/middleware/performanceMiddleware.ts
|
|
907
909
|
var DEFAULT_SLOW_BLOCK_THRESHOLD = 3e3;
|
|
908
910
|
var ACTION_ADD = "add";
|
|
909
911
|
var ACTION_REMOVE = "remove";
|
|
910
|
-
|
|
912
|
+
function handleRemoveAction(context, blockStartTimes, slowBlockThreshold, onSlowBlock) {
|
|
911
913
|
const startTime = blockStartTimes.get(context.blockerId);
|
|
912
914
|
if (startTime === void 0) {
|
|
913
915
|
return;
|
|
@@ -920,8 +922,8 @@ var handleRemoveAction = (context, blockStartTimes, slowBlockThreshold, onSlowBl
|
|
|
920
922
|
);
|
|
921
923
|
onSlowBlock?.(context.blockerId, duration);
|
|
922
924
|
}
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
+
}
|
|
926
|
+
function createPerformanceMiddleware(config = {}) {
|
|
925
927
|
const { slowBlockThreshold = DEFAULT_SLOW_BLOCK_THRESHOLD, onSlowBlock } = config;
|
|
926
928
|
const blockStartTimes = /* @__PURE__ */ new Map();
|
|
927
929
|
return (context) => {
|
|
@@ -931,7 +933,7 @@ var createPerformanceMiddleware = (config = {}) => {
|
|
|
931
933
|
handleRemoveAction(context, blockStartTimes, slowBlockThreshold, onSlowBlock);
|
|
932
934
|
}
|
|
933
935
|
};
|
|
934
|
-
}
|
|
936
|
+
}
|
|
935
937
|
|
|
936
938
|
// src/createTypedHooks.ts
|
|
937
939
|
function createTypedHooks() {
|