@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/dist/index.cjs CHANGED
@@ -1,9 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var react = require('react');
4
- var middleware = require('zustand/middleware');
4
+ var reactZustandToolkit = require('@okyrychenko-dev/react-zustand-toolkit');
5
5
  var zustand = require('zustand');
6
+ require('zustand/react/shallow');
7
+ var jsxRuntime = require('react/jsx-runtime');
6
8
  var shallow = require('zustand/shallow');
9
+ var middleware = require('zustand/middleware');
7
10
 
8
11
  // src/hooks/useAsyncAction/useAsyncAction.ts
9
12
 
@@ -13,13 +16,6 @@ var DEFAULT_REASON = "Unknown";
13
16
  var DEFAULT_PRIORITY = 0;
14
17
  var ASYNC_ACTION_PRIORITY = 20;
15
18
  var DEVTOOLS_NAME = "UIBlocking";
16
- function createShallowStore(storeCreator) {
17
- const storeApi = zustand.createStore(storeCreator);
18
- const useScopedStore = (selector) => {
19
- return zustand.useStore(storeApi, shallow.useShallow(selector));
20
- };
21
- return { useStore: useScopedStore, useStoreApi: storeApi };
22
- }
23
19
  function normalizeScopeToArray(scope) {
24
20
  if (typeof scope === "string") {
25
21
  return [scope];
@@ -67,13 +63,40 @@ var createUIBlockingActions = (set, get) => ({
67
63
  *
68
64
  */
69
65
  addBlocker: (id, config = {}) => {
66
+ const existingBlocker = get().activeBlockers.get(id);
67
+ if (existingBlocker?.timeoutId) {
68
+ clearTimeout(existingBlocker.timeoutId);
69
+ }
70
+ let timeoutId;
71
+ if (config.timeout && config.timeout > 0) {
72
+ timeoutId = setTimeout(() => {
73
+ if (get().activeBlockers.has(id)) {
74
+ config.onTimeout?.(id);
75
+ void get().runMiddlewares({
76
+ action: "timeout",
77
+ blockerId: id,
78
+ config: {
79
+ scope: config.scope,
80
+ reason: config.reason,
81
+ priority: config.priority,
82
+ timeout: config.timeout
83
+ },
84
+ timestamp: Date.now()
85
+ });
86
+ get().removeBlocker(id);
87
+ }
88
+ }, config.timeout);
89
+ }
70
90
  set((state) => {
71
91
  const newBlockers = new Map(state.activeBlockers);
72
92
  const storedBlocker = {
73
93
  scope: config.scope ?? DEFAULT_SCOPE,
74
94
  reason: config.reason ?? DEFAULT_REASON,
75
95
  priority: config.priority ?? DEFAULT_PRIORITY,
76
- timestamp: config.timestamp ?? Date.now()
96
+ timestamp: config.timestamp ?? Date.now(),
97
+ timeout: config.timeout,
98
+ timeoutId,
99
+ onTimeout: config.onTimeout
77
100
  };
78
101
  newBlockers.set(id, storedBlocker);
79
102
  return { activeBlockers: newBlockers };
@@ -84,7 +107,8 @@ var createUIBlockingActions = (set, get) => ({
84
107
  config: {
85
108
  scope: config.scope,
86
109
  reason: config.reason,
87
- priority: config.priority
110
+ priority: config.priority,
111
+ timeout: config.timeout
88
112
  },
89
113
  timestamp: Date.now()
90
114
  });
@@ -97,6 +121,9 @@ var createUIBlockingActions = (set, get) => ({
97
121
  */
98
122
  removeBlocker: (id) => {
99
123
  const prevBlocker = get().activeBlockers.get(id);
124
+ if (prevBlocker?.timeoutId) {
125
+ clearTimeout(prevBlocker.timeoutId);
126
+ }
100
127
  set((state) => {
101
128
  const newBlockers = new Map(state.activeBlockers);
102
129
  newBlockers.delete(id);
@@ -155,6 +182,12 @@ var createUIBlockingActions = (set, get) => ({
155
182
  * Clear all blockers from the store
156
183
  */
157
184
  clearAllBlockers: () => {
185
+ const { activeBlockers } = get();
186
+ for (const [, blocker] of activeBlockers) {
187
+ if (blocker.timeoutId) {
188
+ clearTimeout(blocker.timeoutId);
189
+ }
190
+ }
158
191
  set({ activeBlockers: /* @__PURE__ */ new Map() });
159
192
  },
160
193
  /**
@@ -164,6 +197,13 @@ var createUIBlockingActions = (set, get) => ({
164
197
  *
165
198
  */
166
199
  clearBlockersForScope: (scope) => {
200
+ const { activeBlockers } = get();
201
+ for (const [, blocker] of activeBlockers) {
202
+ const blockerScopes = normalizeScopeToArray(blocker.scope);
203
+ if (blockerScopes.includes(scope) && blocker.timeoutId) {
204
+ clearTimeout(blocker.timeoutId);
205
+ }
206
+ }
167
207
  set((state) => {
168
208
  const newBlockers = /* @__PURE__ */ new Map();
169
209
  for (const [id, blocker] of state.activeBlockers) {
@@ -176,6 +216,34 @@ var createUIBlockingActions = (set, get) => ({
176
216
  });
177
217
  }
178
218
  });
219
+ var {
220
+ Provider: BaseUIBlockingProvider,
221
+ useContext: useUIBlockingContext,
222
+ useContextStore: useUIBlockingStoreFromContext,
223
+ useIsInsideProvider: useIsInsideUIBlockingProvider,
224
+ useOptionalContext
225
+ } = reactZustandToolkit.createStoreProvider(createUIBlockingActions, "UIBlocking");
226
+ function UIBlockingProvider({
227
+ children,
228
+ enableDevtools = process.env.NODE_ENV === "development",
229
+ devtoolsName = "UIBlocking",
230
+ middlewares = []
231
+ }) {
232
+ const handleStoreCreate = (store) => {
233
+ middlewares.forEach((mw, index) => {
234
+ store.getState().registerMiddleware(`provider-middleware-${index.toString()}`, mw);
235
+ });
236
+ };
237
+ return /* @__PURE__ */ jsxRuntime.jsx(
238
+ BaseUIBlockingProvider,
239
+ {
240
+ enableDevtools,
241
+ devtoolsName,
242
+ onStoreCreate: handleStoreCreate,
243
+ children
244
+ }
245
+ );
246
+ }
179
247
 
180
248
  // src/store/uiBlockingStore.config.ts
181
249
  var devtoolsConfig = {
@@ -184,11 +252,24 @@ var devtoolsConfig = {
184
252
  };
185
253
 
186
254
  // src/store/uiBlockingStore.store.ts
187
- var { useStore: useUIBlockingStore, useStoreApi: uiBlockingStoreApi } = createShallowStore(middleware.devtools(createUIBlockingActions, devtoolsConfig));
255
+ var { useStore: useUIBlockingStore, useStoreApi: uiBlockingStoreApi } = reactZustandToolkit.createShallowStore(middleware.devtools(createUIBlockingActions, devtoolsConfig));
256
+
257
+ // src/context/useResolvedStore.ts
258
+ function useOptionalContextStore() {
259
+ return useOptionalContext();
260
+ }
261
+ function useResolvedStore() {
262
+ const contextStore = useOptionalContextStore();
263
+ return contextStore ?? uiBlockingStoreApi;
264
+ }
265
+ function useResolvedStoreWithSelector(selector) {
266
+ const store = useResolvedStore();
267
+ return zustand.useStore(store, shallow.useShallow(selector));
268
+ }
188
269
 
189
270
  // src/hooks/useAsyncAction/useAsyncAction.ts
190
- var useAsyncAction = (actionId, scope) => {
191
- const { addBlocker, removeBlocker } = useUIBlockingStore((state) => ({
271
+ var useAsyncAction = (actionId, scope, options) => {
272
+ const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({
192
273
  addBlocker: state.addBlocker,
193
274
  removeBlocker: state.removeBlocker
194
275
  }));
@@ -199,19 +280,21 @@ var useAsyncAction = (actionId, scope) => {
199
280
  addBlocker(blockerId, {
200
281
  scope,
201
282
  reason: `Executing ${actionId}`,
202
- priority: ASYNC_ACTION_PRIORITY
283
+ priority: ASYNC_ACTION_PRIORITY,
284
+ timeout: options?.timeout,
285
+ onTimeout: options?.onTimeout
203
286
  });
204
287
  return await asyncFn();
205
288
  } finally {
206
289
  removeBlocker(blockerId);
207
290
  }
208
291
  },
209
- [actionId, scope, addBlocker, removeBlocker]
292
+ [actionId, scope, options?.timeout, options?.onTimeout, addBlocker, removeBlocker]
210
293
  );
211
294
  return executeWithBlocking;
212
295
  };
213
296
  var useBlocker = (blockerId, config, isActive = true) => {
214
- const { addBlocker, removeBlocker } = useUIBlockingStore((state) => ({
297
+ const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({
215
298
  addBlocker: state.addBlocker,
216
299
  removeBlocker: state.removeBlocker
217
300
  }));
@@ -235,10 +318,11 @@ function createBlockerConfig(config) {
235
318
  };
236
319
  }
237
320
  var useBlockingInfo = (scope = DEFAULT_SCOPE) => {
238
- const activeBlockers = zustand.useStore(uiBlockingStoreApi, (state) => state.activeBlockers);
321
+ const store = useResolvedStore();
322
+ const activeBlockers = zustand.useStore(store, (state) => state.activeBlockers);
239
323
  return react.useMemo(() => {
240
- return uiBlockingStoreApi.getState().getBlockingInfo(scope);
241
- }, [activeBlockers, scope]);
324
+ return store.getState().getBlockingInfo(scope);
325
+ }, [activeBlockers, scope, store]);
242
326
  };
243
327
  function useConfigRef(config) {
244
328
  const configRef = react.useRef(config);
@@ -250,7 +334,7 @@ function useConfigRef(config) {
250
334
 
251
335
  // src/hooks/useConditionalBlocker/useConditionalBlocker.ts
252
336
  var useConditionalBlocker = (blockerId, config) => {
253
- const { addBlocker, removeBlocker } = useUIBlockingStore((state) => ({
337
+ const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({
254
338
  addBlocker: state.addBlocker,
255
339
  removeBlocker: state.removeBlocker
256
340
  }));
@@ -333,7 +417,7 @@ var useConfirmableBlocker = (blockerId, config) => {
333
417
 
334
418
  // src/hooks/useIsBlocked/useIsBlocked.ts
335
419
  var useIsBlocked = (scope) => {
336
- return useUIBlockingStore((state) => state.isBlocked(scope));
420
+ return useResolvedStoreWithSelector((state) => state.isBlocked(scope));
337
421
  };
338
422
 
339
423
  // src/hooks/useScheduledBlocker/useScheduledBlocker.utils.ts
@@ -375,7 +459,7 @@ function isScheduleInPast(startTime, endTime, now) {
375
459
 
376
460
  // src/hooks/useScheduledBlocker/useScheduledBlocker.ts
377
461
  var useScheduledBlocker = (blockerId, config) => {
378
- const { addBlocker, removeBlocker } = useUIBlockingStore((state) => ({
462
+ const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({
379
463
  addBlocker: state.addBlocker,
380
464
  removeBlocker: state.removeBlocker
381
465
  }));
@@ -606,9 +690,31 @@ var createPerformanceMiddleware = (config = {}) => {
606
690
  };
607
691
  };
608
692
 
693
+ // src/createTypedHooks.ts
694
+ function createTypedHooks() {
695
+ return {
696
+ useBlocker: (blockerId, config, isActive) => {
697
+ useBlocker(blockerId, config, isActive);
698
+ },
699
+ useIsBlocked: (scope) => {
700
+ return useIsBlocked(scope);
701
+ },
702
+ useAsyncAction: (actionId, scope, options) => {
703
+ return useAsyncAction(actionId, scope, options);
704
+ },
705
+ useBlockingInfo: (scope) => useBlockingInfo(scope)
706
+ };
707
+ }
708
+
709
+ Object.defineProperty(exports, "createShallowStore", {
710
+ enumerable: true,
711
+ get: function () { return reactZustandToolkit.createShallowStore; }
712
+ });
713
+ exports.UIBlockingProvider = UIBlockingProvider;
609
714
  exports.configureMiddleware = configureMiddleware;
610
715
  exports.createAnalyticsMiddleware = createAnalyticsMiddleware;
611
716
  exports.createPerformanceMiddleware = createPerformanceMiddleware;
717
+ exports.createTypedHooks = createTypedHooks;
612
718
  exports.loggerMiddleware = loggerMiddleware;
613
719
  exports.uiBlockingStoreApi = uiBlockingStoreApi;
614
720
  exports.useAsyncAction = useAsyncAction;
@@ -617,7 +723,10 @@ exports.useBlockingInfo = useBlockingInfo;
617
723
  exports.useConditionalBlocker = useConditionalBlocker;
618
724
  exports.useConfirmableBlocker = useConfirmableBlocker;
619
725
  exports.useIsBlocked = useIsBlocked;
726
+ exports.useIsInsideUIBlockingProvider = useIsInsideUIBlockingProvider;
620
727
  exports.useScheduledBlocker = useScheduledBlocker;
728
+ exports.useUIBlockingContext = useUIBlockingContext;
621
729
  exports.useUIBlockingStore = useUIBlockingStore;
730
+ exports.useUIBlockingStoreFromContext = useUIBlockingStoreFromContext;
622
731
  //# sourceMappingURL=index.cjs.map
623
732
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/store/uiBlockingStore.constants.ts","../src/store/uiBlockingStore.utils.ts","../src/store/uiBlockingStore.actions.ts","../src/store/uiBlockingStore.config.ts","../src/store/uiBlockingStore.store.ts","../src/hooks/useAsyncAction/useAsyncAction.ts","../src/hooks/useBlocker/useBlocker.ts","../src/hooks/useBlocker/useBlocker.utils.ts","../src/hooks/useBlockingInfo/useBlockingInfo.ts","../src/hooks/useConfigRef.ts","../src/hooks/useConditionalBlocker/useConditionalBlocker.ts","../src/hooks/useConfirmableBlocker/useConfirmableBlocker.ts","../src/hooks/useIsBlocked/useIsBlocked.ts","../src/hooks/useScheduledBlocker/useScheduledBlocker.utils.ts","../src/hooks/useScheduledBlocker/useScheduledBlocker.ts","../src/middleware/analyticsMiddleware.utils.ts","../src/middleware/analyticsMiddleware.ts","../src/middleware/configureMiddleware.ts","../src/middleware/loggerMiddleware.utils.ts","../src/middleware/loggerMiddleware.ts","../src/middleware/performanceMiddleware.utils.ts","../src/middleware/performanceMiddleware.ts"],"names":["createStore","useStore","useShallow","devtools","useCallback","useEffect","useMemo","useRef","useState"],"mappings":";;;;;;;;;;AAOO,IAAM,aAAA,GAAgB,QAAA;AAKtB,IAAM,cAAA,GAAiB,SAAA;AAKvB,IAAM,gBAAA,GAAmB,CAAA;AAKzB,IAAM,qBAAA,GAAwB,EAAA;AAK9B,IAAM,aAAA,GAAgB,YAAA;ACTtB,SAAS,mBAId,YAAA,EAIA;AACA,EAAA,MAAM,QAAA,GAAiCA,oBAAmC,YAAY,CAAA;AAEtF,EAAA,MAAM,cAAA,GAAiB,CAAI,QAAA,KAA0C;AACnE,IAAA,OAAOC,gBAAA,CAAS,QAAA,EAAUC,kBAAA,CAAW,QAAQ,CAAC,CAAA;AAAA,EAChD,CAAA;AAEA,EAAA,OAAO,EAAE,QAAA,EAAU,cAAA,EAAgB,WAAA,EAAa,QAAA,EAAS;AAC3D;AAUO,SAAS,sBAAsB,KAAA,EAAsD;AAC1F,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,CAAC,KAAK,CAAA;AAAA,EACf;AACA,EAAA,OAAO,KAAA,CAAM,KAAK,KAAK,CAAA;AACzB;;;AChCO,IAAM,uBAAA,GAAkF,CAC7F,GAAA,EACA,GAAA,MACI;AAAA;AAAA,EAEJ,cAAA,sBAAoB,GAAA,EAAI;AAAA,EACxB,WAAA,sBAAiB,GAAA,EAAI;AAAA,EAErB,kBAAA,EAAoB,CAAC,IAAA,EAAc,UAAA,KAA2B;AAC5D,IAAA,GAAA,CAAI,CAAC,KAAA,KAAU;AACb,MAAA,MAAM,cAAA,GAAiB,IAAI,G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gB,GAAA,CAAI,OAAA,CAAQ,SAAS,CAAA;AAEvD,EAAA,IAAI,cAAc,MAAA,EAAW;AAC3B,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,QAAA,GAAW,QAAQ,SAAA,GAAY,SAAA;AACrC,EAAA,eAAA,CAAgB,MAAA,CAAO,QAAQ,SAAS,CAAA;AAExC,EAAA,IAAI,YAAY,kBAAA,EAAoB;AAClC,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN,sCAAsC,OAAA,CAAQ,SAAS,CAAA,OAAA,EAAU,QAAA,CAAS,UAAU,CAAA,EAAA;AAAA,KACtF;AAEA,IAAA,WAAA,GAAc,OAAA,CAAQ,WAAW,QAAQ,CAAA;AAAA,EAC3C;AACF,CAAA;AAEO,IAAM,2BAAA,GAA8B,CAAC,MAAA,GAA4B,EAAC,KAAkB;AACzF,EAAA,MAAM,EAAE,kBAAA,GAAqB,4BAAA,EAA8B,WAAA,EAAY,GAAI,MAAA;AAC3E,EAAA,MAAM,eAAA,uBAAsB,GAAA,EAAoB;AAEhD,EAAA,OAAO,CAAC,OAAA,KAAY;AAClB,IAAA,IAAI,OAAA,CAAQ,WAAW,UAAA,EAAY;AACjC,MAAA,eAAA,CAAgB,OAAA,CAAQ,SAAA,EAAW,OAAA,CAAQ,SAAA,EAAW,eAAe,CAAA;AAAA,IACvE,CAAA,MAAA,IAAW,OAAA,CAAQ,MAAA,KAAW,aAAA,EAAe;AAC3C,MAAA,kBAAA,CAAmB,OAAA,EAAS,eAAA,EAAiB,kBAAA,EAAoB,WAAW,CAAA;AAAA,IAC9E;AAAA,EACF,CAAA;AACF","file":"index.cjs","sourcesContent":["/**\n * Default values and constants for UI Blocking Store\n */\n\n/**\n * Default scope for blockers\n */\nexport const DEFAULT_SCOPE = \"global\" as const;\n\n/**\n * Default reason when none is provided\n */\nexport const DEFAULT_REASON = \"Unknown\" as const;\n\n/**\n * Default priority for blockers\n */\nexport const DEFAULT_PRIORITY = 0 as const;\n\n/**\n * Default priority for async actions\n */\nexport const ASYNC_ACTION_PRIORITY = 20 as const;\n\n/**\n * DevTools store name\n */\nexport const DEVTOOLS_NAME = \"UIBlocking\" as const;\n","import { StateCreator, StoreApi, StoreMutators, createStore, useStore } from \"zustand\";\nimport { useShallow } from \"zustand/shallow\";\n\n/**\n * Creates a Zustand store with automatic shallow comparison for all selectors\n *\n * This utility wraps the standard Zustand store creation and automatically applies\n * `useShallow` to all selectors, preventing unnecessary re-renders when selected\n * values haven't changed (shallow equality).\n *\n * @template StoreState - The type of the store state\n * @template TMutators - Array of middleware mutators (e.g., devtools, persist)\n *\n * @param storeCreator - The state creator function for Zustand\n * @returns Object containing the store hook and store API\n *\n * @see https://docs.pmnd.rs/zustand/guides/prevent-rerenders-with-use-shallow\n */\nexport function createShallowStore<\n StoreState,\n TMutators extends Array<[keyof StoreMutators<StoreState, StoreState>, unknown]> = [],\n>(\n storeCreator: StateCreator<StoreState, [], TMutators, StoreState>\n): {\n useStore: <T>(selector: (state: StoreState) => T) => T;\n useStoreApi: StoreApi<StoreState>;\n} {\n const storeApi: StoreApi<StoreState> = createStore<StoreState, TMutators>(storeCreator);\n\n const useScopedStore = <T>(selector: (state: StoreState) => T): T => {\n return useStore(storeApi, useShallow(selector));\n };\n\n return { useStore: useScopedStore, useStoreApi: storeApi };\n}\n\n/**\n * Normalize scope to array format\n *\n * @param scope - Single scope or array of scopes\n * @returns Array of scopes\n *\n * @internal\n */\nexport function normalizeScopeToArray(scope: string | ReadonlyArray<string>): Array<string> {\n if (typeof scope === \"string\") {\n return [scope];\n }\n return Array.from(scope);\n}\n","import { Middleware, MiddlewareContext } from \"../middleware\";\nimport { DEFAULT_PRIORITY, DEFAULT_REASON, DEFAULT_SCOPE } from \"./uiBlockingStore.constants\";\nimport { normalizeScopeToArray } from \"./uiBlockingStore.utils\";\nimport type {\n BlockerConfig,\n BlockerInfo,\n StoredBlocker,\n UIBlockingStore,\n} from \"./uiBlockingStore.types\";\nimport type { StateCreator } from \"zustand\";\n\n/**\n * UI Blocking Store Slice\n *\n * Implements the state and actions for UI blocking management.\n * This slice follows the Zustand slice pattern for better code organization.\n */\nexport const createUIBlockingActions: StateCreator<UIBlockingStore, [], [], UIBlockingStore> = (\n set,\n get\n) => ({\n // State\n activeBlockers: new Map(),\n middlewares: new Map(),\n\n registerMiddleware: (name: string, middleware: Middleware) => {\n set((state) => {\n const newMiddlewares = new Map(state.middlewares);\n newMiddlewares.set(name, middleware);\n return { middlewares: newMiddlewares };\n });\n console.log(`[UIBlocking] Registered middleware: ${name}`);\n },\n\n unregisterMiddleware: (name: string) => {\n set((state) => {\n const newMiddlewares = new Map(state.middlewares);\n newMiddlewares.delete(name);\n return { middlewares: newMiddlewares };\n });\n console.log(`[UIBlocking] Unregistered middleware: ${name}`);\n },\n\n runMiddlewares: async (context: MiddlewareContext) => {\n const { middlewares } = get();\n\n for (const [name, middleware] of middlewares) {\n try {\n await middleware(context);\n } catch (error) {\n console.error(`[UIBlocking] Middleware \"${name}\" error:`, error);\n }\n }\n },\n\n // Actions\n /**\n * Add a blocker to the store\n *\n * @param id - Unique blocker identifier\n * @param config - Optional blocker configuration\n *\n */\n addBlocker: (id: string, config: BlockerConfig = {}): void => {\n set((state) => {\n const newBlockers = new Map(state.activeBlockers);\n const storedBlocker: StoredBlocker = {\n scope: config.scope ?? DEFAULT_SCOPE,\n reason: config.reason ?? DEFAULT_REASON,\n priority: config.priority ?? DEFAULT_PRIORITY,\n timestamp: config.timestamp ?? Date.now(),\n };\n newBlockers.set(id, storedBlocker);\n\n return { activeBlockers: newBlockers };\n });\n\n void get().runMiddlewares({\n action: \"add\",\n blockerId: id,\n config: {\n scope: config.scope,\n reason: config.reason,\n priority: config.priority,\n },\n timestamp: Date.now(),\n });\n },\n\n /**\n * Remove a blocker from the store\n *\n * @param id - Blocker identifier to remove\n *\n */\n removeBlocker: (id: string): void => {\n const prevBlocker = get().activeBlockers.get(id);\n\n set((state) => {\n const newBlockers = new Map(state.activeBlockers);\n newBlockers.delete(id);\n\n return { activeBlockers: newBlockers };\n });\n\n if (prevBlocker) {\n void get().runMiddlewares({\n action: \"remove\",\n blockerId: id,\n config: prevBlocker,\n timestamp: Date.now(),\n prevState: prevBlocker,\n });\n }\n },\n\n /**\n * Check if a scope is currently blocked\n *\n * @param scope - Scope or array of scopes to check (default: \"global\")\n * @returns True if any of the scopes are blocked\n *\n */\n isBlocked: (scope: string | ReadonlyArray<string> = DEFAULT_SCOPE): boolean => {\n const { activeBlockers } = get();\n const scopes = normalizeScopeToArray(scope);\n\n for (const [, blocker] of activeBlockers) {\n // Global blocking blocks everything\n if (blocker.scope === DEFAULT_SCOPE) {\n return true;\n }\n\n // Check scope intersection\n const blockerScopes = normalizeScopeToArray(blocker.scope);\n\n if (scopes.some((s) => blockerScopes.includes(s))) {\n return true;\n }\n }\n\n return false;\n },\n\n /**\n * Get detailed blocking information for a specific scope\n *\n * @param scope - Scope to get blocking information for\n * @returns Array of blockers affecting the scope, sorted by priority (highest first)\n *\n */\n getBlockingInfo: (scope: string): ReadonlyArray<BlockerInfo> => {\n const { activeBlockers } = get();\n const blockers: Array<BlockerInfo> = [];\n\n for (const [id, blocker] of activeBlockers) {\n const blockerScopes = normalizeScopeToArray(blocker.scope);\n\n if (blocker.scope === DEFAULT_SCOPE || blockerScopes.includes(scope)) {\n blockers.push({ id, ...blocker });\n }\n }\n\n return blockers.sort((a, b) => b.priority - a.priority);\n },\n\n /**\n * Clear all blockers from the store\n */\n clearAllBlockers: (): void => {\n set({ activeBlockers: new Map() });\n },\n\n /**\n * Clear all blockers for a specific scope\n *\n * @param scope - Scope to clear blockers for\n *\n */\n clearBlockersForScope: (scope: string): void => {\n set((state) => {\n const newBlockers = new Map();\n\n for (const [id, blocker] of state.activeBlockers) {\n const blockerScopes = normalizeScopeToArray(blocker.scope);\n\n if (!blockerScopes.includes(scope)) {\n newBlockers.set(id, blocker);\n }\n }\n\n return { activeBlockers: newBlockers };\n });\n },\n});\n","import { DEVTOOLS_NAME } from \"./uiBlockingStore.constants\";\nimport type { DevtoolsOptions } from \"zustand/middleware\";\n\n/**\n * DevTools configuration for UI Blocking Store\n *\n * Enables Redux DevTools integration only in development mode\n * for better debugging experience without production overhead.\n */\nexport const devtoolsConfig: DevtoolsOptions = {\n name: DEVTOOLS_NAME,\n enabled: process.env.NODE_ENV !== \"production\",\n};\n","import { devtools } from \"zustand/middleware\";\nimport { createUIBlockingActions } from \"./uiBlockingStore.actions\";\nimport { devtoolsConfig } from \"./uiBlockingStore.config\";\nimport { createShallowStore } from \"./uiBlockingStore.utils\";\nimport type { UIBlockingStore } from \"./uiBlockingStore.types\";\n\n/**\n * UI Blocking Store\n *\n * Global Zustand store for managing UI blocking state across the application.\n *\n * Features:\n * - Priority-based blocking system\n * - Scope-based blocking (global, specific areas, or multiple scopes)\n * - Automatic cleanup on unmount (when using hooks)\n * - DevTools integration for debugging\n * - Automatic shallow comparison for selectors\n *\n */\nconst { useStore: useUIBlockingStore, useStoreApi: uiBlockingStoreApi } = createShallowStore<\n UIBlockingStore,\n [[\"zustand/devtools\", never]]\n>(devtools(createUIBlockingActions, devtoolsConfig));\n\nexport { useUIBlockingStore, uiBlockingStoreApi };\n","import { useCallback } from \"react\";\nimport { ASYNC_ACTION_PRIORITY, useUIBlockingStore } from \"../../store\";\n\n/**\n * Hook to wrap async functions with automatic blocking/unblocking\n *\n * Creates a wrapper function that automatically adds a blocker before executing\n * the async function and removes it after completion (success or failure).\n *\n * @template T - The return type of the async function\n * @param actionId - Unique identifier for the action (used in blocker ID and reason)\n * @param scope - Scope(s) to block during execution (default: \"global\")\n * @returns Function that wraps async functions with blocking behavior\n *\n */\nexport const useAsyncAction = <T = unknown>(\n actionId: string,\n scope?: string | ReadonlyArray<string>\n): ((asyncFn: () => Promise<T>) => Promise<T>) => {\n const { addBlocker, removeBlocker } = useUIBlockingStore((state) => ({\n addBlocker: state.addBlocker,\n removeBlocker: state.removeBlocker,\n }));\n\n const executeWithBlocking = useCallback(\n async (asyncFn: () => Promise<T>): Promise<T> => {\n const blockerId = `${actionId}-${Date.now().toString()}`;\n\n try {\n addBlocker(blockerId, {\n scope,\n reason: `Executing ${actionId}`,\n priority: ASYNC_ACTION_PRIORITY,\n });\n\n return await asyncFn();\n } finally {\n removeBlocker(blockerId);\n }\n },\n [actionId, scope, addBlocker, removeBlocker]\n );\n\n return executeWithBlocking;\n};\n","import { useEffect } from \"react\";\nimport { type BlockerConfig, useUIBlockingStore } from \"../../store\";\n\n/**\n * Hook to automatically add and remove a blocker based on component lifecycle\n *\n * Automatically adds a blocker when the component mounts (or when activated)\n * and removes it when the component unmounts (or when deactivated).\n *\n * @param blockerId - Unique identifier for the blocker\n * @param config - Blocker configuration (scope, reason, priority)\n * @param isActive - Whether the blocker is currently active (default: true)\n *\n */\nexport const useBlocker = (blockerId: string, config: BlockerConfig, isActive = true): void => {\n const { addBlocker, removeBlocker } = useUIBlockingStore((state) => ({\n addBlocker: state.addBlocker,\n removeBlocker: state.removeBlocker,\n }));\n\n useEffect(() => {\n if (!isActive || !blockerId) {\n return;\n }\n\n addBlocker(blockerId, config);\n\n return () => {\n removeBlocker(blockerId);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [blockerId, isActive, addBlocker, removeBlocker]);\n};\n","import { BlockerConfig } from \"../../store\";\n\n/**\n * Creates a blocker configuration object from partial config.\n * Filters out undefined values to create a clean BlockerConfig.\n *\n * @param config - Partial blocker configuration\n * @returns Complete BlockerConfig object\n *\n */\nexport function createBlockerConfig(config: {\n scope?: string | ReadonlyArray<string>;\n reason?: string;\n priority?: number;\n}): BlockerConfig {\n return {\n scope: config.scope,\n reason: config.reason,\n priority: config.priority,\n };\n}\n","import { useMemo } from \"react\";\nimport { useStore } from \"zustand\";\nimport { DEFAULT_SCOPE } from \"../../store\";\nimport { type BlockerInfo, uiBlockingStoreApi } from \"../../store\";\n\n/**\n * Hook to get detailed blocking information for a scope\n *\n * Returns an array of blocker information objects for the specified scope,\n * sorted by priority (highest first). Automatically re-renders when blockers change.\n *\n * Uses a stable reference - only re-renders when the actual blocker list changes,\n * not on every store update.\n *\n * @param scope - Scope to get blocking information for (default: \"global\")\n * @returns Array of blocker information objects, sorted by priority\n *\n * ```\n */\nexport const useBlockingInfo = (scope: string = DEFAULT_SCOPE): ReadonlyArray<BlockerInfo> => {\n // Subscribe to the activeBlockers Map to detect changes\n const activeBlockers = useStore(uiBlockingStoreApi, (state) => state.activeBlockers);\n\n // Recompute blockers only when activeBlockers or scope changes\n return useMemo(() => {\n return uiBlockingStoreApi.getState().getBlockingInfo(scope);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeBlockers, scope]);\n};\n","import { RefObject, useEffect, useRef } from \"react\";\n\n/**\n * Keeps a ref updated with the latest config value.\n * Useful for accessing current config in callbacks without stale closures.\n *\n * @param config - Configuration object to track\n * @returns Mutable ref that always contains the latest config\n *\n */\nexport function useConfigRef<T>(config: T): RefObject<T> {\n const configRef = useRef(config);\n\n useEffect(() => {\n configRef.current = config;\n }, [config]);\n\n return configRef;\n}\n","import { useCallback, useEffect, useRef } from \"react\";\nimport { useUIBlockingStore } from \"../../store\";\nimport { createBlockerConfig } from \"../useBlocker\";\nimport { useConfigRef } from \"../useConfigRef\";\nimport { ConditionalBlockerConfig } from \"./useConditionalBlocker.types\";\n\n/**\n * Hook for conditional blocking based on a condition function.\n *\n * Periodically checks a condition and blocks/unblocks based on the result.\n * The condition is evaluated at the specified interval (default 1000ms).\n *\n * @param blockerId - Unique identifier for this blocker\n * @param config - Configuration including condition function and check interval\n *\n */\nexport const useConditionalBlocker = <TState = unknown>(\n blockerId: string,\n config: ConditionalBlockerConfig<TState>\n): void => {\n const { addBlocker, removeBlocker } = useUIBlockingStore((state) => ({\n addBlocker: state.addBlocker,\n removeBlocker: state.removeBlocker,\n }));\n const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);\n const isBlockedRef = useRef(false);\n const configRef = useConfigRef(config);\n\n const checkCondition = useCallback(() => {\n const currentConfig = configRef.current;\n const shouldBlock = currentConfig.condition(currentConfig.state);\n\n // No state change needed\n if (shouldBlock === isBlockedRef.current) {\n return;\n }\n\n if (shouldBlock) {\n addBlocker(blockerId, createBlockerConfig(currentConfig));\n } else {\n removeBlocker(blockerId);\n }\n isBlockedRef.current = shouldBlock;\n }, [blockerId, addBlocker, removeBlocker, configRef]);\n\n useEffect(() => {\n checkCondition();\n\n const interval = configRef.current.checkInterval ?? 1000;\n intervalRef.current = setInterval(checkCondition, interval);\n\n return (): void => {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n if (isBlockedRef.current) {\n removeBlocker(blockerId);\n isBlockedRef.current = false;\n }\n };\n // configRef is stable and doesn't need to be in dependencies\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [checkCondition, blockerId, removeBlocker]);\n};\n","import { useCallback, useState } from \"react\";\nimport { useBlocker } from \"../useBlocker\";\nimport {\n ConfirmableBlockerConfig,\n UseConfirmableBlockerReturn,\n} from \"./useConfirmableBlocker.types\";\n\n/**\n * Hook for creating a confirmable action with blocking UI\n *\n */\nexport const useConfirmableBlocker = (\n blockerId: string,\n config: ConfirmableBlockerConfig\n): UseConfirmableBlockerReturn => {\n const [isDialogOpen, setIsDialogOpen] = useState(false);\n const [isExecuting, setIsExecuting] = useState(false);\n\n useBlocker(\n blockerId,\n {\n ...config,\n reason: config.reason ?? config.confirmMessage,\n },\n isDialogOpen || isExecuting\n );\n\n const execute = useCallback(() => {\n setIsDialogOpen(true);\n }, []);\n\n const onConfirm = useCallback(async () => {\n setIsDialogOpen(false);\n setIsExecuting(true);\n\n try {\n await config.onConfirm();\n } catch (error) {\n console.error(\"[UIBlocking] Confirmable action error:\", error);\n throw error;\n } finally {\n setIsExecuting(false);\n }\n }, [config]);\n\n const onCancel = useCallback(() => {\n setIsDialogOpen(false);\n config.onCancel?.();\n }, [config]);\n\n return {\n execute,\n isDialogOpen,\n isExecuting,\n confirmConfig: {\n title: config.confirmTitle ?? \"Confirm Action\",\n message: config.confirmMessage,\n confirmText: config.confirmButtonText ?? \"Confirm\",\n cancelText: config.cancelButtonText ?? \"Cancel\",\n },\n onConfirm,\n onCancel,\n };\n};\n","import { useUIBlockingStore } from \"../../store\";\n\n/**\n * Hook to check if a scope is currently blocked\n *\n * Returns a boolean indicating whether the specified scope(s) are blocked.\n * Automatically re-renders when the blocking state changes.\n *\n * @param scope - Scope or array of scopes to check (default: \"global\")\n * @returns True if any of the specified scopes are blocked\n *\n */\nexport const useIsBlocked = (scope?: string | ReadonlyArray<string>): boolean => {\n return useUIBlockingStore((state) => state.isBlocked(scope));\n};\n","import type { BlockingSchedule } from \"./useScheduledBlocker.types\";\n\n/**\n * Maximum safe timeout value for setTimeout in JavaScript (~24.8 days).\n * Values larger than this will cause setTimeout to trigger immediately.\n */\nexport const MAX_TIMEOUT_MS = 2147483647;\n\n/**\n * Validates a date value and converts it to timestamp.\n *\n * @param date - Date value as string, Date object, or number\n * @returns Timestamp in milliseconds, or NaN if invalid\n */\nexport function parseDate(date: string | Date | number): number {\n return new Date(date).getTime();\n}\n\n/**\n * Validates if a timestamp is valid (not NaN).\n *\n * @param timestamp - Timestamp to validate\n * @returns True if valid, false otherwise\n */\nexport function isValidTimestamp(timestamp: number): boolean {\n return !Number.isNaN(timestamp);\n}\n\n/**\n * Calculates the end time based on schedule configuration.\n * Duration takes precedence over end time if both are provided.\n *\n * @param schedule - Blocking schedule configuration\n * @param startTime - Start time in milliseconds\n * @returns End time in milliseconds, or undefined if not specified\n */\nexport function calculateEndTime(\n schedule: BlockingSchedule,\n startTime: number\n): number | undefined {\n if (schedule.duration) {\n return startTime + schedule.duration;\n }\n\n if (schedule.end) {\n const endTime = parseDate(schedule.end);\n return isValidTimestamp(endTime) ? endTime : undefined;\n }\n\n return undefined;\n}\n\n/**\n * Validates if a delay is within the safe setTimeout range.\n *\n * @param delay - Delay in milliseconds\n * @returns True if delay is safe to use with setTimeout\n */\nexport function isSafeTimeout(delay: number): boolean {\n return delay > 0 && delay <= MAX_TIMEOUT_MS;\n}\n\n/**\n * Determines if the current time is within a blocking schedule.\n *\n * @param startTime - Schedule start time in milliseconds\n * @param endTime - Schedule end time in milliseconds (optional)\n * @param now - Current time in milliseconds\n * @returns True if currently in the blocking period\n */\nexport function isInBlockingPeriod(\n startTime: number,\n endTime: number | undefined,\n now: number\n): boolean {\n if (startTime > now) {\n return false; // Not started yet\n }\n\n if (!endTime) {\n return true; // No end time means block indefinitely\n }\n\n return endTime > now; // Check if end time hasn't passed\n}\n\n/**\n * Checks if a schedule is completely in the past.\n *\n * @param startTime - Schedule start time in milliseconds\n * @param endTime - Schedule end time in milliseconds (optional)\n * @param now - Current time in milliseconds\n * @returns True if the schedule is in the past\n */\nexport function isScheduleInPast(\n startTime: number,\n endTime: number | undefined,\n now: number\n): boolean {\n if (!endTime) {\n return false; // No end time means it can still be active\n }\n\n return endTime <= now && startTime <= now;\n}\n","import { useCallback, useEffect, useRef } from \"react\";\nimport { useUIBlockingStore } from \"../../store\";\nimport { createBlockerConfig } from \"../useBlocker\";\nimport { useConfigRef } from \"../useConfigRef\";\nimport { ScheduledBlockerConfig } from \"./useScheduledBlocker.types\";\nimport {\n MAX_TIMEOUT_MS,\n calculateEndTime,\n isInBlockingPeriod,\n isSafeTimeout,\n isScheduleInPast,\n isValidTimestamp,\n parseDate,\n} from \"./useScheduledBlocker.utils\";\n\n/**\n * Hook for scheduling UI blocking for a specific time period.\n *\n * Blocks UI during a scheduled maintenance window or time period.\n * Supports start/end times as Date objects, ISO strings, or timestamps.\n * If both duration and end are provided, duration takes precedence.\n *\n * @param blockerId - Unique identifier for this blocker\n * @param config - Configuration including schedule and callbacks\n *\n */\nexport const useScheduledBlocker = (blockerId: string, config: ScheduledBlockerConfig): void => {\n const { addBlocker, removeBlocker } = useUIBlockingStore((state) => ({\n addBlocker: state.addBlocker,\n removeBlocker: state.removeBlocker,\n }));\n const timeoutsRef = useRef<{\n start?: ReturnType<typeof setTimeout>;\n end?: ReturnType<typeof setTimeout>;\n }>({});\n const configRef = useConfigRef(config);\n\n const cleanup = useCallback(() => {\n if (timeoutsRef.current.start) {\n clearTimeout(timeoutsRef.current.start);\n timeoutsRef.current.start = undefined;\n }\n if (timeoutsRef.current.end) {\n clearTimeout(timeoutsRef.current.end);\n timeoutsRef.current.end = undefined;\n }\n }, []);\n\n useEffect(() => {\n const currentConfig = configRef.current;\n const startTime = parseDate(currentConfig.schedule.start);\n const now = Date.now();\n\n // Validate start time\n if (!isValidTimestamp(startTime)) {\n console.error(`[UIBlocking] Invalid start time for blocker \"${blockerId}\"`);\n return;\n }\n\n const scheduleEnd = (): void => {\n const endTime = calculateEndTime(currentConfig.schedule, startTime);\n if (!endTime) {\n return;\n }\n\n const remainingTime = endTime - Date.now();\n if (remainingTime > 0) {\n timeoutsRef.current.end = setTimeout(() => {\n configRef.current.onScheduleEnd?.();\n removeBlocker(blockerId);\n }, remainingTime);\n }\n };\n\n const startBlocking = (): void => {\n const cfg = configRef.current;\n addBlocker(blockerId, createBlockerConfig(cfg));\n cfg.onScheduleStart?.();\n scheduleEnd();\n };\n\n // If start time hasn't arrived yet\n if (startTime > now) {\n const delay = startTime - now;\n\n if (!isSafeTimeout(delay)) {\n console.warn(\n `[UIBlocking] Schedule delay exceeds maximum timeout (${MAX_TIMEOUT_MS.toString()}ms) for blocker \"${blockerId}\"`\n );\n return;\n }\n\n timeoutsRef.current.start = setTimeout(startBlocking, delay);\n }\n // If already in blocking period or should start immediately\n else {\n const endTime = calculateEndTime(currentConfig.schedule, startTime);\n\n if (isInBlockingPeriod(startTime, endTime, now)) {\n startBlocking();\n } else if (isScheduleInPast(startTime, endTime, now)) {\n console.warn(`[UIBlocking] Schedule is in the past for blocker \"${blockerId}\"`);\n }\n }\n\n return (): void => {\n cleanup();\n removeBlocker(blockerId);\n };\n // configRef is stable and doesn't need to be in dependencies\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [blockerId, addBlocker, removeBlocker, cleanup]);\n};\n","import { AnalyticsEventData } from \"./analyticsMiddleware.types\";\nimport { MiddlewareContext } from \"./middleware.types\";\n\nconst capitalizeFirst = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n};\n\nexport const buildEventData = (context: MiddlewareContext): AnalyticsEventData => {\n const eventData: AnalyticsEventData = {\n blocker_id: context.blockerId,\n };\n const { scope, reason, priority } = context.config ?? {};\n\n if (scope !== undefined) {\n eventData.scope = Array.isArray(scope) ? scope.join(\",\") : scope;\n }\n\n if (reason !== undefined) {\n eventData.reason = reason;\n }\n\n if (priority !== undefined) {\n eventData.priority = priority;\n }\n\n return eventData;\n};\n\nexport const trackGoogleAnalytics = (action: string, eventData: AnalyticsEventData): void => {\n if (window.gtag) {\n window.gtag(\"event\", `ui_blocking_${action}`, eventData);\n }\n};\n\nexport const trackMixpanel = (action: string, eventData: AnalyticsEventData): void => {\n if (window.mixpanel) {\n const eventName = `UI Blocking ${action.split(\"_\").map(capitalizeFirst).join(\" \")}`;\n\n window.mixpanel.track(eventName, eventData);\n }\n};\n\nexport const trackAmplitude = (action: string, eventData: AnalyticsEventData): void => {\n if (window.amplitude) {\n const eventName = `UI Blocking ${action.split(\"_\").map(capitalizeFirst).join(\" \")}`;\n\n window.amplitude.track(eventName, eventData);\n }\n};\n\nexport const trackCustom = (\n trackFn: (event: string, data: AnalyticsEventData) => void,\n action: string,\n eventData: AnalyticsEventData\n): void => {\n try {\n trackFn(`ui_blocking_${action}`, eventData);\n } catch {\n // Silently ignore errors in custom tracker\n }\n};\n","import { AnalyticsConfig, AnalyticsEventData } from \"./analyticsMiddleware.types\";\nimport {\n buildEventData,\n trackAmplitude,\n trackCustom,\n trackGoogleAnalytics,\n trackMixpanel,\n} from \"./analyticsMiddleware.utils\";\nimport { Middleware, MiddlewareContext } from \"./middleware.types\";\n\nconst trackEvent = (\n config: AnalyticsConfig,\n context: MiddlewareContext,\n eventData: AnalyticsEventData\n): void => {\n if (\"provider\" in config) {\n switch (config.provider) {\n case \"ga\":\n trackGoogleAnalytics(context.action, eventData);\n return;\n case \"mixpanel\":\n trackMixpanel(context.action, eventData);\n return;\n case \"amplitude\":\n trackAmplitude(context.action, eventData);\n return;\n }\n }\n\n if (\"track\" in config) {\n trackCustom(config.track, context.action, eventData);\n }\n};\n\nexport const createAnalyticsMiddleware = (config: AnalyticsConfig): Middleware => {\n return (context) => {\n const eventData = buildEventData(context);\n\n trackEvent(config, context, eventData);\n };\n};\n","import { uiBlockingStoreApi } from \"../store/uiBlockingStore.store\";\nimport type { Middleware } from \"./middleware.types\";\n\n/**\n * Configure middleware for the UI blocking store\n *\n * This is a convenience function that registers multiple middleware at once.\n * Each middleware will be registered with an auto-generated name based on its index.\n *\n * @param middlewares - Array of middleware functions to register\n *\n */\nexport function configureMiddleware(middlewares: ReadonlyArray<Middleware>): void {\n const store = uiBlockingStoreApi.getState();\n\n middlewares.forEach((middleware, index) => {\n // Generate a unique name for each middleware\n const name = `middleware-${index.toString()}`;\n store.registerMiddleware(name, middleware);\n });\n}\n","import { MiddlewareBlockerConfig, MiddlewareContext } from \"./middleware.types\";\n\nexport const getActionEmoji = (action: string): string => {\n switch (action) {\n case \"add\":\n return \"➕\";\n case \"remove\":\n return \"➖\";\n case \"update\":\n return \"🔄\";\n case \"cancel\":\n return \"❌\";\n case \"timeout\":\n return \"⏱️\";\n default:\n return \"❓\";\n }\n};\n\nconst extractConfigDetails = (config?: MiddlewareBlockerConfig): Record<string, unknown> => {\n if (!config) {\n return {};\n }\n\n const { scope, reason, priority } = config;\n\n const details: Record<string, unknown> = {\n scope,\n reason,\n };\n\n if (priority !== undefined) {\n details.priority = priority;\n }\n\n return details;\n};\n\nexport const formatLogData = (context: MiddlewareContext): Record<string, unknown> => {\n const configDetails = extractConfigDetails(context.config);\n\n if (context.prevState) {\n return {\n config: configDetails,\n prevState: extractConfigDetails(context.prevState),\n };\n }\n\n return configDetails;\n};\n","import { formatLogData, getActionEmoji } from \"./loggerMiddleware.utils\";\nimport { Middleware } from \"./middleware.types\";\n\nconst LOG_PREFIX = \"[UIBlocking]\";\n\nexport const loggerMiddleware: Middleware = (context) => {\n const emoji = getActionEmoji(context.action);\n const logData = formatLogData(context);\n\n console.log(LOG_PREFIX, emoji, context.blockerId, logData);\n};\n","export const handleAddAction = (\n blockerId: string,\n timestamp: number,\n blockStartTimes: Map<string, number>\n): void => {\n blockStartTimes.set(blockerId, timestamp);\n};\n","import { Middleware, MiddlewareContext } from \"./middleware.types\";\nimport { PerformanceConfig } from \"./performanceMiddleware.types\";\nimport { handleAddAction } from \"./performanceMiddleware.utils\";\n\nconst DEFAULT_SLOW_BLOCK_THRESHOLD = 3000;\nconst ACTION_ADD = \"add\";\nconst ACTION_REMOVE = \"remove\";\n\nconst handleRemoveAction = (\n context: MiddlewareContext,\n blockStartTimes: Map<string, number>,\n slowBlockThreshold: number,\n onSlowBlock?: (blockerId: string, duration: number) => void\n): void => {\n const startTime = blockStartTimes.get(context.blockerId);\n\n if (startTime === undefined) {\n return;\n }\n\n const duration = context.timestamp - startTime;\n blockStartTimes.delete(context.blockerId);\n\n if (duration >= slowBlockThreshold) {\n console.warn(\n `[UIBlocking] Slow block detected: \"${context.blockerId}\" took ${duration.toString()}ms`\n );\n\n onSlowBlock?.(context.blockerId, duration);\n }\n};\n\nexport const createPerformanceMiddleware = (config: PerformanceConfig = {}): Middleware => {\n const { slowBlockThreshold = DEFAULT_SLOW_BLOCK_THRESHOLD, onSlowBlock } = config;\n const blockStartTimes = new Map<string, number>();\n\n return (context) => {\n if (context.action === ACTION_ADD) {\n handleAddAction(context.blockerId, context.timestamp, blockStartTimes);\n } else if (context.action === ACTION_REMOVE) {\n handleRemoveAction(context, blockStartTimes, slowBlockThreshold, onSlowBlock);\n }\n };\n};\n"]}
1
+ {"version":3,"sources":["../src/store/uiBlockingStore.constants.ts","../src/store/uiBlockingStore.utils.ts","../src/store/uiBlockingStore.actions.ts","../src/context/UIBlockingContext.tsx","../src/store/uiBlockingStore.config.ts","../src/store/uiBlockingStore.store.ts","../src/context/useResolvedStore.ts","../src/hooks/useAsyncAction/useAsyncAction.ts","../src/hooks/useBlocker/useBlocker.ts","../src/hooks/useBlocker/useBlocker.utils.ts","../src/hooks/useBlockingInfo/useBlockingInfo.ts","../src/hooks/useConfigRef.ts","../src/hooks/useConditionalBlocker/useConditionalBlocker.ts","../src/hooks/useConfirmableBlocker/useConfirmableBlocker.ts","../src/hooks/useIsBlocked/useIsBlocked.ts","../src/hooks/useScheduledBlocker/useScheduledBlocker.utils.ts","../src/hooks/useScheduledBlocker/useScheduledBlocker.ts","../src/middleware/analyticsMiddleware.utils.ts","../src/middleware/analyticsMiddleware.ts","../src/middleware/configureMiddleware.ts","../src/middleware/loggerMiddleware.utils.ts","../src/middleware/loggerMiddleware.ts","../src/middleware/performanceMiddleware.utils.ts","../src/middleware/performanceMiddleware.ts","../src/createTypedHooks.ts"],"names":["createStoreProvider","jsx","createShallowStore","devtools","useStore","useShallow","useCallback","useEffect","useMemo","useRef","useState"],"mappings":";;;;;;;;;;;;;AAOO,IAAM,aAAA,GAAgB,QAAA;AAKtB,IAAM,cAAA,GAAiB,SAAA;AAKvB,IAAM,gBAAA,GAAmB,CAAA;AAKzB,IAAM,qBAAA,GAAwB,EAAA;AAK9B,IAAM,aAAA,GAAgB,YAAA;AC+BtB,SAAS,sBAAsB,KAAA,EAAsD;AAC1F,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,CAAC,KAAK,CAAA;AAAA,EACf;AACA,EAAA,OAAO,KAAA,CAAM,KAAK,KAAK,CAAA;AACzB;;;AC9CO,IAAM,uBAAA,GAAkF,CAC7F,GAAA,EACA,GAAA,MACI;AAAA;AAAA,EAEJ,cAAA,sBAAoB,GAAA,EAAI;AAAA,EACxB,WAAA,sBAAiB,GAAA,EAAI;AAAA,EAErB,kBAAA,EAAoB,CAAC,IAAA,EAAc,UAAA,KAA2B;AAC5D,IAAA,GAAA,CAAI,CAAC,KAAA,KAAU;AACb,MAAA,MAAM,cAAA,GAAi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A,EAAY;AACjC,MAAA,eAAA,CAAgB,OAAA,CAAQ,SAAA,EAAW,OAAA,CAAQ,SAAA,EAAW,eAAe,CAAA;AAAA,IACvE,CAAA,MAAA,IAAW,OAAA,CAAQ,MAAA,KAAW,aAAA,EAAe;AAC3C,MAAA,kBAAA,CAAmB,OAAA,EAAS,eAAA,EAAiB,kBAAA,EAAoB,WAAW,CAAA;AAAA,IAC9E;AAAA,EACF,CAAA;AACF;;;ACWO,SAAS,gBAAA,GAA8D;AAG5E,EAAA,OAAO;AAAA,IACL,UAAA,EAAY,CAAC,SAAA,EAAW,MAAA,EAAQ,QAAA,KAAa;AAG3C,MAAA,UAAA,CAAW,SAAA,EAAW,QAAQ,QAAQ,CAAA;AAAA,IACxC,CAAA;AAAA,IAEA,YAAA,EAAc,CAAC,KAAA,KAAU;AAGvB,MAAA,OAAO,aAAa,KAAK,CAAA;AAAA,IAC3B,CAAA;AAAA,IAEA,cAAA,EAAgB,CACd,QAAA,EACA,KAAA,EACA,OAAA,KACG;AACH,MAAA,OAAO,cAAA,CAAkB,QAAA,EAAU,KAAA,EAAO,OAAO,CAAA;AAAA,IACnD,CAAA;AAAA,IAEA,eAAA,EAAiB,CAAC,KAAA,KAAU,eAAA,CAAgB,KAAK;AAAA,GACnD;AACF","file":"index.cjs","sourcesContent":["/**\n * Default values and constants for UI Blocking Store\n */\n\n/**\n * Default scope for blockers\n */\nexport const DEFAULT_SCOPE = \"global\" as const;\n\n/**\n * Default reason when none is provided\n */\nexport const DEFAULT_REASON = \"Unknown\" as const;\n\n/**\n * Default priority for blockers\n */\nexport const DEFAULT_PRIORITY = 0 as const;\n\n/**\n * Default priority for async actions\n */\nexport const ASYNC_ACTION_PRIORITY = 20 as const;\n\n/**\n * DevTools store name\n */\nexport const DEVTOOLS_NAME = \"UIBlocking\" as const;\n","import { StateCreator, StoreApi, StoreMutators, createStore, useStore } from \"zustand\";\nimport { useShallow } from \"zustand/react/shallow\";\n\nexport interface ShallowStoreBindings<StoreState> {\n useStore: {\n (): StoreState;\n <T>(selector: (state: StoreState) => T): T;\n };\n useStoreApi: StoreApi<StoreState>;\n}\n\n/**\n * Creates a Zustand store with automatic shallow comparison for all selectors\n *\n * This utility wraps the standard Zustand store creation and automatically applies\n * `useShallow` to all selectors, preventing unnecessary re-renders when selected\n * values haven't changed (shallow equality).\n *\n * Supports two usage patterns:\n * - `useStore()` - Returns the entire store state\n * - `useStore(selector)` - Returns the result of the selector function\n *\n * @template StoreState - The type of the store state\n * @template TMutators - Array of middleware mutators (e.g., devtools, persist)\n *\n * @param storeCreator - The state creator function for Zustand\n * @returns Object containing the store hook and store API\n *\n * @see https://docs.pmnd.rs/zustand/guides/prevent-rerenders-with-use-shallow\n */\nexport function createShallowStore<\n StoreState,\n TMutators extends Array<[keyof StoreMutators<StoreState, StoreState>, unknown]> = [],\n>(\n storeCreator: StateCreator<StoreState, [], TMutators, StoreState>\n): ShallowStoreBindings<StoreState> {\n const storeApi: StoreApi<StoreState> = createStore<StoreState, TMutators>(storeCreator);\n\n function useScopedStore(): StoreState;\n function useScopedStore<T>(selector: (state: StoreState) => T): T;\n function useScopedStore<T>(selector?: (state: StoreState) => T): T | StoreState {\n const actualSelector = (state: StoreState): T | StoreState =>\n selector ? selector(state) : state;\n\n return useStore(storeApi, useShallow(actualSelector));\n }\n\n return { useStore: useScopedStore, useStoreApi: storeApi };\n}\n\n/**\n * Normalize scope to array format\n *\n * @param scope - Single scope or array of scopes\n * @returns Array of scopes\n *\n * @internal\n */\nexport function normalizeScopeToArray(scope: string | ReadonlyArray<string>): Array<string> {\n if (typeof scope === \"string\") {\n return [scope];\n }\n return Array.from(scope);\n}\n","import { Middleware, MiddlewareContext } from \"../middleware\";\nimport { DEFAULT_PRIORITY, DEFAULT_REASON, DEFAULT_SCOPE } from \"./uiBlockingStore.constants\";\nimport { normalizeScopeToArray } from \"./uiBlockingStore.utils\";\nimport type {\n BlockerConfig,\n BlockerInfo,\n StoredBlocker,\n UIBlockingStore,\n} from \"./uiBlockingStore.types\";\nimport type { StateCreator } from \"zustand\";\n\n/**\n * UI Blocking Store Slice\n *\n * Implements the state and actions for UI blocking management.\n * This slice follows the Zustand slice pattern for better code organization.\n */\nexport const createUIBlockingActions: StateCreator<UIBlockingStore, [], [], UIBlockingStore> = (\n set,\n get\n) => ({\n // State\n activeBlockers: new Map(),\n middlewares: new Map(),\n\n registerMiddleware: (name: string, middleware: Middleware) => {\n set((state) => {\n const newMiddlewares = new Map(state.middlewares);\n newMiddlewares.set(name, middleware);\n return { middlewares: newMiddlewares };\n });\n console.log(`[UIBlocking] Registered middleware: ${name}`);\n },\n\n unregisterMiddleware: (name: string) => {\n set((state) => {\n const newMiddlewares = new Map(state.middlewares);\n newMiddlewares.delete(name);\n return { middlewares: newMiddlewares };\n });\n console.log(`[UIBlocking] Unregistered middleware: ${name}`);\n },\n\n runMiddlewares: async (context: MiddlewareContext) => {\n const { middlewares } = get();\n\n for (const [name, middleware] of middlewares) {\n try {\n await middleware(context);\n } catch (error) {\n console.error(`[UIBlocking] Middleware \"${name}\" error:`, error);\n }\n }\n },\n\n // Actions\n /**\n * Add a blocker to the store\n *\n * @param id - Unique blocker identifier\n * @param config - Optional blocker configuration\n *\n */\n addBlocker: (id: string, config: BlockerConfig = {}): void => {\n // Clear existing timeout if blocker is being overwritten\n const existingBlocker = get().activeBlockers.get(id);\n if (existingBlocker?.timeoutId) {\n clearTimeout(existingBlocker.timeoutId);\n }\n\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n\n // Set up timeout if specified\n if (config.timeout && config.timeout > 0) {\n timeoutId = setTimeout(() => {\n // Check if blocker still exists\n if (get().activeBlockers.has(id)) {\n // Call onTimeout callback before removing\n config.onTimeout?.(id);\n\n // Run timeout middleware\n void get().runMiddlewares({\n action: \"timeout\",\n blockerId: id,\n config: {\n scope: config.scope,\n reason: config.reason,\n priority: config.priority,\n timeout: config.timeout,\n },\n timestamp: Date.now(),\n });\n\n // Remove the blocker (this will also run \"remove\" middleware)\n get().removeBlocker(id);\n }\n }, config.timeout);\n }\n\n set((state) => {\n const newBlockers = new Map(state.activeBlockers);\n const storedBlocker: StoredBlocker = {\n scope: config.scope ?? DEFAULT_SCOPE,\n reason: config.reason ?? DEFAULT_REASON,\n priority: config.priority ?? DEFAULT_PRIORITY,\n timestamp: config.timestamp ?? Date.now(),\n timeout: config.timeout,\n timeoutId,\n onTimeout: config.onTimeout,\n };\n newBlockers.set(id, storedBlocker);\n\n return { activeBlockers: newBlockers };\n });\n\n void get().runMiddlewares({\n action: \"add\",\n blockerId: id,\n config: {\n scope: config.scope,\n reason: config.reason,\n priority: config.priority,\n timeout: config.timeout,\n },\n timestamp: Date.now(),\n });\n },\n\n /**\n * Remove a blocker from the store\n *\n * @param id - Blocker identifier to remove\n *\n */\n removeBlocker: (id: string): void => {\n const prevBlocker = get().activeBlockers.get(id);\n\n // Clear timeout if it exists\n if (prevBlocker?.timeoutId) {\n clearTimeout(prevBlocker.timeoutId);\n }\n\n set((state) => {\n const newBlockers = new Map(state.activeBlockers);\n newBlockers.delete(id);\n\n return { activeBlockers: newBlockers };\n });\n\n if (prevBlocker) {\n void get().runMiddlewares({\n action: \"remove\",\n blockerId: id,\n config: prevBlocker,\n timestamp: Date.now(),\n prevState: prevBlocker,\n });\n }\n },\n\n /**\n * Check if a scope is currently blocked\n *\n * @param scope - Scope or array of scopes to check (default: \"global\")\n * @returns True if any of the scopes are blocked\n *\n */\n isBlocked: (scope: string | ReadonlyArray<string> = DEFAULT_SCOPE): boolean => {\n const { activeBlockers } = get();\n const scopes = normalizeScopeToArray(scope);\n\n for (const [, blocker] of activeBlockers) {\n // Global blocking blocks everything\n if (blocker.scope === DEFAULT_SCOPE) {\n return true;\n }\n\n // Check scope intersection\n const blockerScopes = normalizeScopeToArray(blocker.scope);\n\n if (scopes.some((s) => blockerScopes.includes(s))) {\n return true;\n }\n }\n\n return false;\n },\n\n /**\n * Get detailed blocking information for a specific scope\n *\n * @param scope - Scope to get blocking information for\n * @returns Array of blockers affecting the scope, sorted by priority (highest first)\n *\n */\n getBlockingInfo: (scope: string): ReadonlyArray<BlockerInfo> => {\n const { activeBlockers } = get();\n const blockers: Array<BlockerInfo> = [];\n\n for (const [id, blocker] of activeBlockers) {\n const blockerScopes = normalizeScopeToArray(blocker.scope);\n\n if (blocker.scope === DEFAULT_SCOPE || blockerScopes.includes(scope)) {\n blockers.push({ id, ...blocker });\n }\n }\n\n return blockers.sort((a, b) => b.priority - a.priority);\n },\n\n /**\n * Clear all blockers from the store\n */\n clearAllBlockers: (): void => {\n // Clear all timeouts before clearing blockers\n const { activeBlockers } = get();\n for (const [, blocker] of activeBlockers) {\n if (blocker.timeoutId) {\n clearTimeout(blocker.timeoutId);\n }\n }\n\n set({ activeBlockers: new Map() });\n },\n\n /**\n * Clear all blockers for a specific scope\n *\n * @param scope - Scope to clear blockers for\n *\n */\n clearBlockersForScope: (scope: string): void => {\n // Clear timeouts for blockers that will be removed\n const { activeBlockers } = get();\n for (const [, blocker] of activeBlockers) {\n const blockerScopes = normalizeScopeToArray(blocker.scope);\n if (blockerScopes.includes(scope) && blocker.timeoutId) {\n clearTimeout(blocker.timeoutId);\n }\n }\n\n set((state) => {\n const newBlockers = new Map();\n\n for (const [id, blocker] of state.activeBlockers) {\n const blockerScopes = normalizeScopeToArray(blocker.scope);\n\n if (!blockerScopes.includes(scope)) {\n newBlockers.set(id, blocker);\n }\n }\n\n return { activeBlockers: newBlockers };\n });\n },\n});\n","import { createStoreProvider } from \"@okyrychenko-dev/react-zustand-toolkit\";\nimport { type ReactNode } from \"react\";\nimport { type StoreApi } from \"zustand\";\nimport { createUIBlockingActions } from \"../store/uiBlockingStore.actions\";\nimport type { Middleware } from \"../middleware\";\nimport type { UIBlockingStore } from \"../store/uiBlockingStore.types\";\n\n/**\n * Props for UIBlockingProvider component\n */\nexport interface UIBlockingProviderProps {\n children: ReactNode;\n /** Enable Redux DevTools integration (default: true in development) */\n enableDevtools?: boolean;\n /** Name for Redux DevTools (default: \"UIBlocking\") */\n devtoolsName?: string;\n /** Initial middlewares to register */\n middlewares?: ReadonlyArray<Middleware>;\n}\n\n/**\n * Base provider created using toolkit's createStoreProvider\n * This creates isolated store instances for SSR, testing, and micro-frontends\n */\nconst {\n Provider: BaseUIBlockingProvider,\n useContext: useUIBlockingContext,\n useContextStore: useUIBlockingStoreFromContext,\n useIsInsideProvider: useIsInsideUIBlockingProvider,\n useOptionalContext,\n} = createStoreProvider(createUIBlockingActions, \"UIBlocking\");\n\n/**\n * Provider component for isolated UI blocking state\n *\n * Uses toolkit's createStoreProvider with built-in DevTools support\n * and onStoreCreate callback for middleware registration.\n */\nexport function UIBlockingProvider({\n children,\n enableDevtools = process.env.NODE_ENV === \"development\",\n devtoolsName = \"UIBlocking\",\n middlewares = [],\n}: UIBlockingProviderProps): ReactNode {\n const handleStoreCreate = (store: StoreApi<UIBlockingStore>): void => {\n // Register initial middlewares\n middlewares.forEach((mw, index) => {\n store.getState().registerMiddleware(`provider-middleware-${index.toString()}`, mw);\n });\n };\n\n return (\n <BaseUIBlockingProvider\n enableDevtools={enableDevtools}\n devtoolsName={devtoolsName}\n onStoreCreate={handleStoreCreate}\n >\n {children}\n </BaseUIBlockingProvider>\n );\n}\n\n// Export hooks from base provider\nexport {\n useUIBlockingContext,\n useUIBlockingStoreFromContext,\n useIsInsideUIBlockingProvider,\n useOptionalContext,\n};\n","import { DEVTOOLS_NAME } from \"./uiBlockingStore.constants\";\nimport type { DevtoolsOptions } from \"zustand/middleware\";\n\n/**\n * DevTools configuration for UI Blocking Store\n *\n * Enables Redux DevTools integration only in development mode\n * for better debugging experience without production overhead.\n */\nexport const devtoolsConfig: DevtoolsOptions = {\n name: DEVTOOLS_NAME,\n enabled: process.env.NODE_ENV !== \"production\",\n};\n","import { createShallowStore } from \"@okyrychenko-dev/react-zustand-toolkit\";\nimport { devtools } from \"zustand/middleware\";\nimport { createUIBlockingActions } from \"./uiBlockingStore.actions\";\nimport { devtoolsConfig } from \"./uiBlockingStore.config\";\nimport type { UIBlockingStore } from \"./uiBlockingStore.types\";\n\n/**\n * UI Blocking Store\n *\n * Global Zustand store for managing UI blocking state across the application.\n *\n * Features:\n * - Priority-based blocking system\n * - Scope-based blocking (global, specific areas, or multiple scopes)\n * - Automatic cleanup on unmount (when using hooks)\n * - DevTools integration for debugging\n * - Automatic shallow comparison for selectors\n *\n */\nconst { useStore: useUIBlockingStore, useStoreApi: uiBlockingStoreApi } = createShallowStore<\n UIBlockingStore,\n [[\"zustand/devtools\", never]]\n>(devtools(createUIBlockingActions, devtoolsConfig));\n\nexport { useUIBlockingStore, uiBlockingStoreApi };\n","import { type StoreApi, useStore } from \"zustand\";\nimport { useShallow } from \"zustand/shallow\";\nimport { uiBlockingStoreApi } from \"../store/uiBlockingStore.store\";\nimport { useOptionalContext } from \"./UIBlockingContext\";\nimport type { UIBlockingStore } from \"../store/uiBlockingStore.types\";\n\n/**\n * Hook to get the optional context store (returns null if not inside provider)\n * @internal\n */\nfunction useOptionalContextStore(): StoreApi<UIBlockingStore> | null {\n return useOptionalContext();\n}\n\n/**\n * Hook that resolves to either the context store or global store\n *\n * This hook automatically uses the store from UIBlockingProvider if available,\n * otherwise falls back to the global store. This enables both patterns:\n *\n * 1. Global store (default behavior, no Provider needed)\n * 2. Context store (for SSR, testing, micro-frontends)\n *\n * @returns The resolved store API\n */\nexport function useResolvedStore(): StoreApi<UIBlockingStore> {\n const contextStore = useOptionalContextStore();\n // Return context store if inside Provider, otherwise global store\n return contextStore ?? uiBlockingStoreApi;\n}\n\n/**\n * Hook to use the resolved store with a selector\n *\n * Automatically applies shallow comparison to prevent unnecessary re-renders.\n *\n * @param selector - Selector function to pick state from the store\n * @returns Selected state value\n */\nexport function useResolvedStoreWithSelector<T>(selector: (state: UIBlockingStore) => T): T {\n const store = useResolvedStore();\n return useStore(store, useShallow(selector));\n}\n","import { useCallback } from \"react\";\nimport { useResolvedStoreWithSelector } from \"../../context\";\nimport { ASYNC_ACTION_PRIORITY } from \"../../store\";\n\n/**\n * Options for useAsyncAction hook\n */\nexport interface UseAsyncActionOptions {\n /** Timeout in milliseconds after which the blocker will be automatically removed */\n timeout?: number;\n /** Callback invoked when the blocker is automatically removed due to timeout */\n onTimeout?: (blockerId: string) => void;\n}\n\n/**\n * Hook to wrap async functions with automatic blocking/unblocking\n *\n * Creates a wrapper function that automatically adds a blocker before executing\n * the async function and removes it after completion (success or failure).\n *\n * Supports both global store and context store (via UIBlockingProvider).\n *\n * @template T - The return type of the async function\n * @param actionId - Unique identifier for the action (used in blocker ID and reason)\n * @param scope - Scope(s) to block during execution (default: \"global\")\n * @param options - Optional configuration including timeout\n * @returns Function that wraps async functions with blocking behavior\n *\n */\nexport const useAsyncAction = <T = unknown>(\n actionId: string,\n scope?: string | ReadonlyArray<string>,\n options?: UseAsyncActionOptions\n): ((asyncFn: () => Promise<T>) => Promise<T>) => {\n const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({\n addBlocker: state.addBlocker,\n removeBlocker: state.removeBlocker,\n }));\n\n const executeWithBlocking = useCallback(\n async (asyncFn: () => Promise<T>): Promise<T> => {\n const blockerId = `${actionId}-${Date.now().toString()}`;\n\n try {\n addBlocker(blockerId, {\n scope,\n reason: `Executing ${actionId}`,\n priority: ASYNC_ACTION_PRIORITY,\n timeout: options?.timeout,\n onTimeout: options?.onTimeout,\n });\n\n return await asyncFn();\n } finally {\n removeBlocker(blockerId);\n }\n },\n [actionId, scope, options?.timeout, options?.onTimeout, addBlocker, removeBlocker]\n );\n\n return executeWithBlocking;\n};\n","import { useEffect } from \"react\";\nimport { useResolvedStoreWithSelector } from \"../../context\";\nimport type { BlockerConfig } from \"../../store\";\n\n/**\n * Hook to automatically add and remove a blocker based on component lifecycle\n *\n * Automatically adds a blocker when the component mounts (or when activated)\n * and removes it when the component unmounts (or when deactivated).\n *\n * Supports both global store and context store (via UIBlockingProvider).\n *\n * @param blockerId - Unique identifier for the blocker\n * @param config - Blocker configuration (scope, reason, priority)\n * @param isActive - Whether the blocker is currently active (default: true)\n *\n */\nexport const useBlocker = (blockerId: string, config: BlockerConfig, isActive = true): void => {\n const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({\n addBlocker: state.addBlocker,\n removeBlocker: state.removeBlocker,\n }));\n\n useEffect(() => {\n if (!isActive || !blockerId) {\n return;\n }\n\n addBlocker(blockerId, config);\n\n return () => {\n removeBlocker(blockerId);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [blockerId, isActive, addBlocker, removeBlocker]);\n};\n","import { BlockerConfig } from \"../../store\";\n\n/**\n * Creates a blocker configuration object from partial config.\n * Filters out undefined values to create a clean BlockerConfig.\n *\n * @param config - Partial blocker configuration\n * @returns Complete BlockerConfig object\n *\n */\nexport function createBlockerConfig(config: {\n scope?: string | ReadonlyArray<string>;\n reason?: string;\n priority?: number;\n}): BlockerConfig {\n return {\n scope: config.scope,\n reason: config.reason,\n priority: config.priority,\n };\n}\n","import { useMemo } from \"react\";\nimport { useStore } from \"zustand\";\nimport { useResolvedStore } from \"../../context\";\nimport { DEFAULT_SCOPE } from \"../../store\";\nimport type { BlockerInfo } from \"../../store\";\n\n/**\n * Hook to get detailed blocking information for a scope\n *\n * Returns an array of blocker information objects for the specified scope,\n * sorted by priority (highest first). Automatically re-renders when blockers change.\n *\n * Uses a stable reference - only re-renders when the actual blocker list changes,\n * not on every store update.\n *\n * Supports both global store and context store (via UIBlockingProvider).\n *\n * @param scope - Scope to get blocking information for (default: \"global\")\n * @returns Array of blocker information objects, sorted by priority\n *\n * ```\n */\nexport const useBlockingInfo = (scope: string = DEFAULT_SCOPE): ReadonlyArray<BlockerInfo> => {\n const store = useResolvedStore();\n\n // Subscribe to the activeBlockers Map to detect changes\n const activeBlockers = useStore(store, (state) => state.activeBlockers);\n\n // Recompute blockers only when activeBlockers or scope changes\n return useMemo(() => {\n return store.getState().getBlockingInfo(scope);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeBlockers, scope, store]);\n};\n","import { RefObject, useEffect, useRef } from \"react\";\n\n/**\n * Keeps a ref updated with the latest config value.\n * Useful for accessing current config in callbacks without stale closures.\n *\n * @param config - Configuration object to track\n * @returns Mutable ref that always contains the latest config\n *\n */\nexport function useConfigRef<T>(config: T): RefObject<T> {\n const configRef = useRef(config);\n\n useEffect(() => {\n configRef.current = config;\n }, [config]);\n\n return configRef;\n}\n","import { useCallback, useEffect, useRef } from \"react\";\nimport { useResolvedStoreWithSelector } from \"../../context\";\nimport { createBlockerConfig } from \"../useBlocker\";\nimport { useConfigRef } from \"../useConfigRef\";\nimport { ConditionalBlockerConfig } from \"./useConditionalBlocker.types\";\n\n/**\n * Hook for conditional blocking based on a condition function.\n *\n * Periodically checks a condition and blocks/unblocks based on the result.\n * The condition is evaluated at the specified interval (default 1000ms).\n *\n * Supports both global store and context store (via UIBlockingProvider).\n *\n * @param blockerId - Unique identifier for this blocker\n * @param config - Configuration including condition function and check interval\n *\n */\nexport const useConditionalBlocker = <TState = unknown>(\n blockerId: string,\n config: ConditionalBlockerConfig<TState>\n): void => {\n const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({\n addBlocker: state.addBlocker,\n removeBlocker: state.removeBlocker,\n }));\n const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);\n const isBlockedRef = useRef(false);\n const configRef = useConfigRef(config);\n\n const checkCondition = useCallback(() => {\n const currentConfig = configRef.current;\n const shouldBlock = currentConfig.condition(currentConfig.state);\n\n // No state change needed\n if (shouldBlock === isBlockedRef.current) {\n return;\n }\n\n if (shouldBlock) {\n addBlocker(blockerId, createBlockerConfig(currentConfig));\n } else {\n removeBlocker(blockerId);\n }\n isBlockedRef.current = shouldBlock;\n }, [blockerId, addBlocker, removeBlocker, configRef]);\n\n useEffect(() => {\n checkCondition();\n\n const interval = configRef.current.checkInterval ?? 1000;\n intervalRef.current = setInterval(checkCondition, interval);\n\n return (): void => {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n if (isBlockedRef.current) {\n removeBlocker(blockerId);\n isBlockedRef.current = false;\n }\n };\n // configRef is stable and doesn't need to be in dependencies\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [checkCondition, blockerId, removeBlocker]);\n};\n","import { useCallback, useState } from \"react\";\nimport { useBlocker } from \"../useBlocker\";\nimport {\n ConfirmableBlockerConfig,\n UseConfirmableBlockerReturn,\n} from \"./useConfirmableBlocker.types\";\n\n/**\n * Hook for creating a confirmable action with blocking UI\n *\n */\nexport const useConfirmableBlocker = (\n blockerId: string,\n config: ConfirmableBlockerConfig\n): UseConfirmableBlockerReturn => {\n const [isDialogOpen, setIsDialogOpen] = useState(false);\n const [isExecuting, setIsExecuting] = useState(false);\n\n useBlocker(\n blockerId,\n {\n ...config,\n reason: config.reason ?? config.confirmMessage,\n },\n isDialogOpen || isExecuting\n );\n\n const execute = useCallback(() => {\n setIsDialogOpen(true);\n }, []);\n\n const onConfirm = useCallback(async () => {\n setIsDialogOpen(false);\n setIsExecuting(true);\n\n try {\n await config.onConfirm();\n } catch (error) {\n console.error(\"[UIBlocking] Confirmable action error:\", error);\n throw error;\n } finally {\n setIsExecuting(false);\n }\n }, [config]);\n\n const onCancel = useCallback(() => {\n setIsDialogOpen(false);\n config.onCancel?.();\n }, [config]);\n\n return {\n execute,\n isDialogOpen,\n isExecuting,\n confirmConfig: {\n title: config.confirmTitle ?? \"Confirm Action\",\n message: config.confirmMessage,\n confirmText: config.confirmButtonText ?? \"Confirm\",\n cancelText: config.cancelButtonText ?? \"Cancel\",\n },\n onConfirm,\n onCancel,\n };\n};\n","import { useResolvedStoreWithSelector } from \"../../context\";\n\n/**\n * Hook to check if a scope is currently blocked\n *\n * Returns a boolean indicating whether the specified scope(s) are blocked.\n * Automatically re-renders when the blocking state changes.\n *\n * Supports both global store and context store (via UIBlockingProvider).\n *\n * @param scope - Scope or array of scopes to check (default: \"global\")\n * @returns True if any of the specified scopes are blocked\n *\n */\nexport const useIsBlocked = (scope?: string | ReadonlyArray<string>): boolean => {\n return useResolvedStoreWithSelector((state) => state.isBlocked(scope));\n};\n","import type { BlockingSchedule } from \"./useScheduledBlocker.types\";\n\n/**\n * Maximum safe timeout value for setTimeout in JavaScript (~24.8 days).\n * Values larger than this will cause setTimeout to trigger immediately.\n */\nexport const MAX_TIMEOUT_MS = 2147483647;\n\n/**\n * Validates a date value and converts it to timestamp.\n *\n * @param date - Date value as string, Date object, or number\n * @returns Timestamp in milliseconds, or NaN if invalid\n */\nexport function parseDate(date: string | Date | number): number {\n return new Date(date).getTime();\n}\n\n/**\n * Validates if a timestamp is valid (not NaN).\n *\n * @param timestamp - Timestamp to validate\n * @returns True if valid, false otherwise\n */\nexport function isValidTimestamp(timestamp: number): boolean {\n return !Number.isNaN(timestamp);\n}\n\n/**\n * Calculates the end time based on schedule configuration.\n * Duration takes precedence over end time if both are provided.\n *\n * @param schedule - Blocking schedule configuration\n * @param startTime - Start time in milliseconds\n * @returns End time in milliseconds, or undefined if not specified\n */\nexport function calculateEndTime(\n schedule: BlockingSchedule,\n startTime: number\n): number | undefined {\n if (schedule.duration) {\n return startTime + schedule.duration;\n }\n\n if (schedule.end) {\n const endTime = parseDate(schedule.end);\n return isValidTimestamp(endTime) ? endTime : undefined;\n }\n\n return undefined;\n}\n\n/**\n * Validates if a delay is within the safe setTimeout range.\n *\n * @param delay - Delay in milliseconds\n * @returns True if delay is safe to use with setTimeout\n */\nexport function isSafeTimeout(delay: number): boolean {\n return delay > 0 && delay <= MAX_TIMEOUT_MS;\n}\n\n/**\n * Determines if the current time is within a blocking schedule.\n *\n * @param startTime - Schedule start time in milliseconds\n * @param endTime - Schedule end time in milliseconds (optional)\n * @param now - Current time in milliseconds\n * @returns True if currently in the blocking period\n */\nexport function isInBlockingPeriod(\n startTime: number,\n endTime: number | undefined,\n now: number\n): boolean {\n if (startTime > now) {\n return false; // Not started yet\n }\n\n if (!endTime) {\n return true; // No end time means block indefinitely\n }\n\n return endTime > now; // Check if end time hasn't passed\n}\n\n/**\n * Checks if a schedule is completely in the past.\n *\n * @param startTime - Schedule start time in milliseconds\n * @param endTime - Schedule end time in milliseconds (optional)\n * @param now - Current time in milliseconds\n * @returns True if the schedule is in the past\n */\nexport function isScheduleInPast(\n startTime: number,\n endTime: number | undefined,\n now: number\n): boolean {\n if (!endTime) {\n return false; // No end time means it can still be active\n }\n\n return endTime <= now && startTime <= now;\n}\n","import { useCallback, useEffect, useRef } from \"react\";\nimport { useResolvedStoreWithSelector } from \"../../context\";\nimport { createBlockerConfig } from \"../useBlocker\";\nimport { useConfigRef } from \"../useConfigRef\";\nimport { ScheduledBlockerConfig } from \"./useScheduledBlocker.types\";\nimport {\n MAX_TIMEOUT_MS,\n calculateEndTime,\n isInBlockingPeriod,\n isSafeTimeout,\n isScheduleInPast,\n isValidTimestamp,\n parseDate,\n} from \"./useScheduledBlocker.utils\";\n\n/**\n * Hook for scheduling UI blocking for a specific time period.\n *\n * Blocks UI during a scheduled maintenance window or time period.\n * Supports start/end times as Date objects, ISO strings, or timestamps.\n * If both duration and end are provided, duration takes precedence.\n *\n * Supports both global store and context store (via UIBlockingProvider).\n *\n * @param blockerId - Unique identifier for this blocker\n * @param config - Configuration including schedule and callbacks\n *\n */\nexport const useScheduledBlocker = (blockerId: string, config: ScheduledBlockerConfig): void => {\n const { addBlocker, removeBlocker } = useResolvedStoreWithSelector((state) => ({\n addBlocker: state.addBlocker,\n removeBlocker: state.removeBlocker,\n }));\n const timeoutsRef = useRef<{\n start?: ReturnType<typeof setTimeout>;\n end?: ReturnType<typeof setTimeout>;\n }>({});\n const configRef = useConfigRef(config);\n\n const cleanup = useCallback(() => {\n if (timeoutsRef.current.start) {\n clearTimeout(timeoutsRef.current.start);\n timeoutsRef.current.start = undefined;\n }\n if (timeoutsRef.current.end) {\n clearTimeout(timeoutsRef.current.end);\n timeoutsRef.current.end = undefined;\n }\n }, []);\n\n useEffect(() => {\n const currentConfig = configRef.current;\n const startTime = parseDate(currentConfig.schedule.start);\n const now = Date.now();\n\n // Validate start time\n if (!isValidTimestamp(startTime)) {\n console.error(`[UIBlocking] Invalid start time for blocker \"${blockerId}\"`);\n return;\n }\n\n const scheduleEnd = (): void => {\n const endTime = calculateEndTime(currentConfig.schedule, startTime);\n if (!endTime) {\n return;\n }\n\n const remainingTime = endTime - Date.now();\n if (remainingTime > 0) {\n timeoutsRef.current.end = setTimeout(() => {\n configRef.current.onScheduleEnd?.();\n removeBlocker(blockerId);\n }, remainingTime);\n }\n };\n\n const startBlocking = (): void => {\n const cfg = configRef.current;\n addBlocker(blockerId, createBlockerConfig(cfg));\n cfg.onScheduleStart?.();\n scheduleEnd();\n };\n\n // If start time hasn't arrived yet\n if (startTime > now) {\n const delay = startTime - now;\n\n if (!isSafeTimeout(delay)) {\n console.warn(\n `[UIBlocking] Schedule delay exceeds maximum timeout (${MAX_TIMEOUT_MS.toString()}ms) for blocker \"${blockerId}\"`\n );\n return;\n }\n\n timeoutsRef.current.start = setTimeout(startBlocking, delay);\n }\n // If already in blocking period or should start immediately\n else {\n const endTime = calculateEndTime(currentConfig.schedule, startTime);\n\n if (isInBlockingPeriod(startTime, endTime, now)) {\n startBlocking();\n } else if (isScheduleInPast(startTime, endTime, now)) {\n console.warn(`[UIBlocking] Schedule is in the past for blocker \"${blockerId}\"`);\n }\n }\n\n return (): void => {\n cleanup();\n removeBlocker(blockerId);\n };\n // configRef is stable and doesn't need to be in dependencies\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [blockerId, addBlocker, removeBlocker, cleanup]);\n};\n","import { AnalyticsEventData } from \"./analyticsMiddleware.types\";\nimport { MiddlewareContext } from \"./middleware.types\";\n\nconst capitalizeFirst = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n};\n\nexport const buildEventData = (context: MiddlewareContext): AnalyticsEventData => {\n const eventData: AnalyticsEventData = {\n blocker_id: context.blockerId,\n };\n const { scope, reason, priority } = context.config ?? {};\n\n if (scope !== undefined) {\n eventData.scope = Array.isArray(scope) ? scope.join(\",\") : scope;\n }\n\n if (reason !== undefined) {\n eventData.reason = reason;\n }\n\n if (priority !== undefined) {\n eventData.priority = priority;\n }\n\n return eventData;\n};\n\nexport const trackGoogleAnalytics = (action: string, eventData: AnalyticsEventData): void => {\n if (window.gtag) {\n window.gtag(\"event\", `ui_blocking_${action}`, eventData);\n }\n};\n\nexport const trackMixpanel = (action: string, eventData: AnalyticsEventData): void => {\n if (window.mixpanel) {\n const eventName = `UI Blocking ${action.split(\"_\").map(capitalizeFirst).join(\" \")}`;\n\n window.mixpanel.track(eventName, eventData);\n }\n};\n\nexport const trackAmplitude = (action: string, eventData: AnalyticsEventData): void => {\n if (window.amplitude) {\n const eventName = `UI Blocking ${action.split(\"_\").map(capitalizeFirst).join(\" \")}`;\n\n window.amplitude.track(eventName, eventData);\n }\n};\n\nexport const trackCustom = (\n trackFn: (event: string, data: AnalyticsEventData) => void,\n action: string,\n eventData: AnalyticsEventData\n): void => {\n try {\n trackFn(`ui_blocking_${action}`, eventData);\n } catch {\n // Silently ignore errors in custom tracker\n }\n};\n","import { AnalyticsConfig, AnalyticsEventData } from \"./analyticsMiddleware.types\";\nimport {\n buildEventData,\n trackAmplitude,\n trackCustom,\n trackGoogleAnalytics,\n trackMixpanel,\n} from \"./analyticsMiddleware.utils\";\nimport { Middleware, MiddlewareContext } from \"./middleware.types\";\n\nconst trackEvent = (\n config: AnalyticsConfig,\n context: MiddlewareContext,\n eventData: AnalyticsEventData\n): void => {\n if (\"provider\" in config) {\n switch (config.provider) {\n case \"ga\":\n trackGoogleAnalytics(context.action, eventData);\n return;\n case \"mixpanel\":\n trackMixpanel(context.action, eventData);\n return;\n case \"amplitude\":\n trackAmplitude(context.action, eventData);\n return;\n }\n }\n\n if (\"track\" in config) {\n trackCustom(config.track, context.action, eventData);\n }\n};\n\nexport const createAnalyticsMiddleware = (config: AnalyticsConfig): Middleware => {\n return (context) => {\n const eventData = buildEventData(context);\n\n trackEvent(config, context, eventData);\n };\n};\n","import { uiBlockingStoreApi } from \"../store/uiBlockingStore.store\";\nimport type { Middleware } from \"./middleware.types\";\n\n/**\n * Configure middleware for the UI blocking store\n *\n * This is a convenience function that registers multiple middleware at once.\n * Each middleware will be registered with an auto-generated name based on its index.\n *\n * @param middlewares - Array of middleware functions to register\n *\n */\nexport function configureMiddleware(middlewares: ReadonlyArray<Middleware>): void {\n const store = uiBlockingStoreApi.getState();\n\n middlewares.forEach((middleware, index) => {\n // Generate a unique name for each middleware\n const name = `middleware-${index.toString()}`;\n store.registerMiddleware(name, middleware);\n });\n}\n","import { MiddlewareBlockerConfig, MiddlewareContext } from \"./middleware.types\";\n\nexport const getActionEmoji = (action: string): string => {\n switch (action) {\n case \"add\":\n return \"➕\";\n case \"remove\":\n return \"➖\";\n case \"update\":\n return \"🔄\";\n case \"cancel\":\n return \"❌\";\n case \"timeout\":\n return \"⏱️\";\n default:\n return \"❓\";\n }\n};\n\nconst extractConfigDetails = (config?: MiddlewareBlockerConfig): Record<string, unknown> => {\n if (!config) {\n return {};\n }\n\n const { scope, reason, priority } = config;\n\n const details: Record<string, unknown> = {\n scope,\n reason,\n };\n\n if (priority !== undefined) {\n details.priority = priority;\n }\n\n return details;\n};\n\nexport const formatLogData = (context: MiddlewareContext): Record<string, unknown> => {\n const configDetails = extractConfigDetails(context.config);\n\n if (context.prevState) {\n return {\n config: configDetails,\n prevState: extractConfigDetails(context.prevState),\n };\n }\n\n return configDetails;\n};\n","import { formatLogData, getActionEmoji } from \"./loggerMiddleware.utils\";\nimport { Middleware } from \"./middleware.types\";\n\nconst LOG_PREFIX = \"[UIBlocking]\";\n\nexport const loggerMiddleware: Middleware = (context) => {\n const emoji = getActionEmoji(context.action);\n const logData = formatLogData(context);\n\n console.log(LOG_PREFIX, emoji, context.blockerId, logData);\n};\n","export const handleAddAction = (\n blockerId: string,\n timestamp: number,\n blockStartTimes: Map<string, number>\n): void => {\n blockStartTimes.set(blockerId, timestamp);\n};\n","import { Middleware, MiddlewareContext } from \"./middleware.types\";\nimport { PerformanceConfig } from \"./performanceMiddleware.types\";\nimport { handleAddAction } from \"./performanceMiddleware.utils\";\n\nconst DEFAULT_SLOW_BLOCK_THRESHOLD = 3000;\nconst ACTION_ADD = \"add\";\nconst ACTION_REMOVE = \"remove\";\n\nconst handleRemoveAction = (\n context: MiddlewareContext,\n blockStartTimes: Map<string, number>,\n slowBlockThreshold: number,\n onSlowBlock?: (blockerId: string, duration: number) => void\n): void => {\n const startTime = blockStartTimes.get(context.blockerId);\n\n if (startTime === undefined) {\n return;\n }\n\n const duration = context.timestamp - startTime;\n blockStartTimes.delete(context.blockerId);\n\n if (duration >= slowBlockThreshold) {\n console.warn(\n `[UIBlocking] Slow block detected: \"${context.blockerId}\" took ${duration.toString()}ms`\n );\n\n onSlowBlock?.(context.blockerId, duration);\n }\n};\n\nexport const createPerformanceMiddleware = (config: PerformanceConfig = {}): Middleware => {\n const { slowBlockThreshold = DEFAULT_SLOW_BLOCK_THRESHOLD, onSlowBlock } = config;\n const blockStartTimes = new Map<string, number>();\n\n return (context) => {\n if (context.action === ACTION_ADD) {\n handleAddAction(context.blockerId, context.timestamp, blockStartTimes);\n } else if (context.action === ACTION_REMOVE) {\n handleRemoveAction(context, blockStartTimes, slowBlockThreshold, onSlowBlock);\n }\n };\n};\n","import { type UseAsyncActionOptions, useAsyncAction } from \"./hooks/useAsyncAction\";\nimport { useBlocker } from \"./hooks/useBlocker\";\nimport { useBlockingInfo } from \"./hooks/useBlockingInfo\";\nimport { useIsBlocked } from \"./hooks/useIsBlocked\";\nimport type { BlockerConfigTyped, ScopeValue } from \"./types\";\n\n/**\n * Return type for createTypedHooks factory\n */\nexport interface TypedHooks<TScope extends string> {\n /**\n * Type-safe version of useBlocker hook\n */\n useBlocker: (blockerId: string, config: BlockerConfigTyped<TScope>, isActive?: boolean) => void;\n\n /**\n * Type-safe version of useIsBlocked hook\n */\n useIsBlocked: (scope?: ScopeValue<TScope>) => boolean;\n\n /**\n * Type-safe version of useAsyncAction hook\n */\n useAsyncAction: <T = unknown>(\n actionId: string,\n scope?: ScopeValue<TScope>,\n options?: UseAsyncActionOptions\n ) => (asyncFn: () => Promise<T>) => Promise<T>;\n\n /**\n * Type-safe version of useBlockingInfo hook\n */\n useBlockingInfo: (scope: TScope) => ReturnType<typeof useBlockingInfo>;\n}\n\n/**\n * Creates type-safe versions of all blocking hooks with your custom scope types\n *\n * @template TScope - Union type of allowed scope strings\n * @returns Object with type-safe hook functions\n *\n * @example\n * ```typescript\n * // Define your app's scopes\n * type AppScopes = \"global\" | \"form\" | \"navigation\" | \"checkout\";\n *\n * // Create typed hooks\n * const { useBlocker, useIsBlocked, useAsyncAction } = createTypedHooks<AppScopes>();\n *\n * // Now TypeScript will catch typos\n * useBlocker(\"id\", { scope: \"form\" }); // ✓ OK\n * useBlocker(\"id\", { scope: \"typo\" }); // ✗ Type error!\n * ```\n */\nexport function createTypedHooks<TScope extends string>(): TypedHooks<TScope> {\n // TScope extends string, so all typed scopes are assignable to string | ReadonlyArray<string>\n // This allows us to pass typed values directly without casting\n return {\n useBlocker: (blockerId, config, isActive) => {\n // BlockerConfigTyped<TScope> is structurally compatible with BlockerConfig\n // because TScope extends string\n useBlocker(blockerId, config, isActive);\n },\n\n useIsBlocked: (scope) => {\n // ScopeValue<TScope> = TScope | ReadonlyArray<TScope>\n // Since TScope extends string, this is assignable to string | ReadonlyArray<string>\n return useIsBlocked(scope);\n },\n\n useAsyncAction: <T = unknown>(\n actionId: string,\n scope?: ScopeValue<TScope>,\n options?: UseAsyncActionOptions\n ) => {\n return useAsyncAction<T>(actionId, scope, options);\n },\n\n useBlockingInfo: (scope) => useBlockingInfo(scope),\n };\n}\n"]}