@okyrychenko-dev/react-action-guard-router 0.2.3 → 1.0.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/utils.ts","../../src/core/useBeforeUnload.ts","../../src/core/useShouldBlock.ts","../../src/tanstack-router/useNavigationBlocker.ts"],"names":["useEffect"],"mappings":";;;;;;;AAMO,SAAS,iBAAiB,SAAA,EAA+C;AAC9E,EAAA,OAAO,OAAO,SAAA,KAAc,UAAA,GAAa,SAAA,EAAU,GAAI,SAAA;AACzD;AAMA,IAAM,OAAA,GAAU,CAAC,KAAA,KACf,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,MAAA,IAAU,KAAA;AAKpD,SAAS,WAAc,KAAA,EAAyC;AACrE,EAAA,IAAI,CAAC,OAAA,CAAQ,KAAK,CAAA,EAAG;AACnB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAO,MAAM,IAAA,KAAS,UAAA;AAC/B;AAiBO,SAAS,oBAAA,CACd,OAAA,EACA,SAAA,EACA,eAAA,EACe;AACf,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAA,EAAW,eAAA,CAAgB,OAAO,CAAA,EAAE;AAAA,EAC7D;AAEA,EAAA,MAAM,MAAA,GAAS,UAAU,OAAO,CAAA;AAChC,EAAA,IAAI,UAAA,CAAoB,MAAM,CAAA,EAAG;AAC/B,IAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,SAAS,OAAA,CAAQ,OAAA,CAAQ,MAAM,CAAA,EAAE;AAAA,EAC3D;AAEA,EAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAA,EAAW,MAAA,EAAO;AAC3C;AAqBO,SAAS,UAAa,KAAA,EAAyC;AACpE,EAAA,OAAO,KAAA,KAAU,UAAa,KAAA,KAAU,IA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AI,YAAA,CAAa,SAAS,OAAA,EAAS;AACjC,QAAA,YAAA,CAAa,OAAA,CACV,IAAA,CAAK,CAAC,SAAA,KAAc;AACnB,UAAA,IAAI,SAAA,EAAW;AACb,YAAA,OAAA,IAAU;AACV,YAAA,OAAA,EAAQ;AACR,YAAA,YAAA,CAAa,MAAM,CAAA;AAAA,UACrB;AAAA,QACF,CAAC,CAAA,CACA,KAAA,CAAM,CAAC,KAAA,KAAmB;AAEzB,UAAA,OAAA,EAAQ;AACR,UAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,YAAA,OAAA,CAAQ,KAAA,CAAM,mDAAmD,KAAK,CAAA;AAAA,UACxE;AAAA,QACF,CAAC,CAAA;AACH,QAAA;AAAA,MACF;AAEA,MAAA,IAAI,aAAa,SAAA,EAAW;AAC1B,QAAA,OAAA,IAAU;AACV,QAAA,OAAA,EAAQ;AACR,QAAA,YAAA,CAAa,MAAM,CAAA;AAAA,MACrB;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAO,MAAM;AACX,MAAA,OAAA,EAAQ;AAAA,IACV,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,WAAA,EAAa,OAAA,EAAS,SAAS,OAAA,EAAS,MAAA,EAAQ,SAAS,CAAC,CAAA;AAG9D,EAAA,eAAA,CAAgB,kBAAA,IAAsB,WAAA,EAAa,OAAA,IAAW,sBAAsB,CAAA;AAEpF,EAAA,OAAO;AAAA,IACL,UAAA,EAAY;AAAA,GACd;AACF","file":"index.js","sourcesContent":["/**\n * Resolves a condition value (boolean or function returning boolean)\n *\n * @param condition - Boolean value or function\n * @returns Resolved boolean value\n */\nexport function resolveCondition(condition: boolean | (() => boolean)): boolean {\n return typeof condition === \"function\" ? condition() : condition;\n}\n\ninterface Thenable {\n then: (...args: Array<unknown>) => unknown;\n}\n\nconst hasThen = (value: unknown): value is Thenable =>\n typeof value === \"object\" && value !== null && \"then\" in value;\n\n/**\n * Checks if a value behaves like a Promise (thenable)\n */\nexport function isThenable<T>(value: unknown): value is PromiseLike<T> {\n if (!hasThen(value)) {\n return false;\n }\n return typeof value.then === \"function\";\n}\n\nexport interface ConfirmResultSync {\n kind: \"sync\";\n confirmed: boolean;\n}\n\nexport interface ConfirmResultAsync {\n kind: \"async\";\n promise: Promise<boolean>;\n}\n\nexport type ConfirmResult = ConfirmResultSync | ConfirmResultAsync;\n\n/**\n * Normalizes custom confirm result into sync or async branch.\n */\nexport function resolveConfirmResult(\n message: string,\n onConfirm: ((message: string) => boolean | PromiseLike<boolean>) | undefined,\n fallbackConfirm: (message: string) => boolean\n): ConfirmResult {\n if (!onConfirm) {\n return { kind: \"sync\", confirmed: fallbackConfirm(message) };\n }\n\n const result = onConfirm(message);\n if (isThenable<boolean>(result)) {\n return { kind: \"async\", promise: Promise.resolve(result) };\n }\n\n return { kind: \"sync\", confirmed: result };\n}\n\n/**\n * Generates a unique blocker ID based on scope and timestamp\n *\n * @param prefix - Prefix for the ID\n * @param scope - Optional scope\n * @returns Unique blocker ID\n */\nexport function createBlockerId(prefix: string, scope?: string | Array<string>): string {\n const scopePart = scope ? `-${Array.isArray(scope) ? scope.join(\"-\") : scope}` : \"\";\n const timestamp = String(Date.now());\n return `${prefix}${scopePart}-${timestamp}`;\n}\n\n/**\n * Checks if a value is defined and not empty\n *\n * @param value - Value to check\n * @returns True if value is defined and not empty\n */\nexport function isDefined<T>(value: T | undefined | null): value is T {\n return value !== undefined && value !== null;\n}\n\n/**\n * Normalizes scope to an array\n *\n * @param scope - String or array of strings\n * @returns Array of scope strings\n */\nexport function normalizeScope(scope: string | Array<string> | undefined): Array<string> {\n if (!scope) {\n return [];\n }\n return Array.isArray(scope) ? scope : [scope];\n}\n","import { useEffect } from \"react\";\nimport { resolveCondition } from \"./utils\";\n\n/**\n * Default message shown when preventing browser unload\n */\nexport const DEFAULT_UNLOAD_MESSAGE = \"Changes you made may not be saved.\";\n\n/**\n * Blocks browser tab close/refresh when condition is met.\n *\n * This hook adds a `beforeunload` event listener to warn users\n * before they close or refresh the browser tab. Modern browsers\n * may ignore custom messages and show their own generic warning.\n *\n * @param when - Boolean or function returning boolean to determine if blocking should be active\n * @param message - Optional custom message (may be ignored by browsers)\n *\n * @example\n * ```tsx\n * function MyForm() {\n * const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);\n *\n * useBeforeUnload(hasUnsavedChanges, 'You have unsaved changes');\n *\n * return <form>...</form>;\n * }\n * ```\n *\n * @example\n * ```tsx\n * // With function condition\n * function EditPage() {\n * const isFormDirty = useIsBlocked('form');\n *\n * useBeforeUnload(() => isFormDirty);\n *\n * return <div>...</div>;\n * }\n * ```\n */\nexport function useBeforeUnload(\n when: boolean | (() => boolean),\n message = DEFAULT_UNLOAD_MESSAGE\n): void {\n useEffect(() => {\n const shouldBlock = resolveCondition(when);\n\n if (!shouldBlock) {\n return;\n }\n\n const handleBeforeUnload = (event: BeforeUnloadEvent): void => {\n // Prevent default to trigger the browser's confirmation dialog\n event.preventDefault();\n\n // Fallback for legacy browsers/WebViews that still rely on returnValue.\n if (\"returnValue\" in event) {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n event.returnValue = message;\n }\n };\n\n window.addEventListener(\"beforeunload\", handleBeforeUnload);\n\n return () => {\n window.removeEventListener(\"beforeunload\", handleBeforeUnload);\n };\n }, [when, message]);\n}\n","import { useIsBlocked } from \"@okyrychenko-dev/react-action-guard\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { isDefined, normalizeScope, resolveCondition } from \"./utils\";\n\n/**\n * Shared hook to determine if blocking should be active based on\n * condition and/or scope state.\n *\n * This hook uses `useMemo` for optimal performance, ensuring blocking state\n * is computed synchronously without additional re-renders.\n *\n * @param when - Optional condition (boolean or function)\n * @param scope - Optional scope(s) to check\n * @returns Whether blocking should be active\n *\n * @internal\n */\nexport function useShouldBlock(\n when?: boolean | (() => boolean),\n scope?: string | Array<string>\n): boolean {\n // Memoize scope normalization to avoid recalculation on every render\n const scopes = useMemo(() => normalizeScope(scope), [scope]);\n\n // Check if any specified scopes are blocked\n const isScopeBlocked = useIsBlocked(scopes.length === 1 ? scopes[0] : scopes);\n\n // Development-only validation\n const warnedMissingConditionRef = useRef(false);\n const warnedFunctionRef = useRef(false);\n\n useEffect(() => {\n if (process.env.NODE_ENV !== \"development\") {\n return;\n }\n\n if (!warnedMissingConditionRef.current && !isDefined(when) && !scope) {\n warnedMissingConditionRef.current = true;\n console.warn(\n '[react-action-guard-router] useShouldBlock: Neither \"when\" nor \"scope\" provided. ' +\n \"This hook will always return false. Please provide at least one condition.\"\n );\n }\n\n if (!warnedFunctionRef.current && typeof when === \"function\") {\n warnedFunctionRef.current = true;\n console.warn(\n '[react-action-guard-router] useShouldBlock: \"when\" is a function. ' +\n \"Make sure to wrap it with useCallback to avoid unnecessary re-computations.\"\n );\n }\n }, [when, scope]);\n\n // Compute blocking state synchronously using useMemo\n // This avoids the useState + useEffect pattern which causes an extra render\n const shouldBlock = useMemo(() => {\n let blockCondition = false;\n\n // Check manual condition\n if (isDefined(when)) {\n blockCondition = resolveCondition(when);\n }\n\n // Check scope-based blocking (OR logic - block if either condition is true)\n if (scope && isScopeBlocked) {\n blockCondition = true;\n }\n\n return blockCondition;\n }, [when, scope, isScopeBlocked]);\n\n return shouldBlock;\n}\n","import { useRouter } from \"@tanstack/react-router\";\nimport { useEffect } from \"react\";\nimport {\n DEFAULT_UNLOAD_MESSAGE,\n resolveConfirmResult,\n useBeforeUnload,\n useShouldBlock,\n} from \"../core\";\nimport type { NavigationBlockerReturn } from \"../core/types\";\nimport type { SafeTanStackRouter, UseNavigationBlockerOptions } from \"./types\";\n\ninterface RetryableUpdate {\n [key: string]: unknown;\n retry: () => void;\n}\n\nconst hasBlockingHistory = (value: unknown): value is SafeTanStackRouter => {\n if (!value || typeof value !== \"object\") {\n return false;\n }\n if (!(\"history\" in value)) {\n return false;\n }\n const history = value.history;\n if (!history || typeof history !== \"object\") {\n return false;\n }\n if (!(\"block\" in history)) {\n return false;\n }\n return typeof history.block === \"function\";\n};\n\nconst hasRetry = (value: Record<string, unknown>): value is RetryableUpdate =>\n typeof value.retry === \"function\";\n\nconst attemptRetry = (update: Record<string, unknown>): void => {\n if (hasRetry(update)) {\n try {\n update.retry();\n } catch {\n // Swallow retry errors to avoid breaking blocking flow.\n }\n }\n};\n\n/**\n * Blocks navigation in TanStack Router applications based on conditions or scope state.\n *\n * This hook integrates with TanStack Router's history blocking mechanism and\n * react-action-guard's scope system to prevent navigation when certain conditions\n * are met or when specific scopes are blocked.\n *\n * **Features:**\n * - Block navigation based on boolean condition or function\n * - Automatically block when react-action-guard scopes are active\n * - Support for browser `beforeunload` event (tab close/refresh)\n * - Customizable confirmation dialog\n * - Callbacks for block/allow events\n *\n * @param options - Configuration options\n * @returns Object with `isBlocking` state\n *\n * @example\n * ```tsx\n * // Block based on scope\n * function EditForm() {\n * useNavigationBlocker({\n * scope: 'form',\n * message: 'You have unsaved changes. Leave anyway?',\n * });\n *\n * return <form>...</form>;\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Block based on condition\n * function UnsavedChanges() {\n * const [hasChanges, setHasChanges] = useState(false);\n *\n * useNavigationBlocker({\n * when: hasChanges,\n * message: 'Discard changes?',\n * onBlock: () => console.log('Navigation blocked'),\n * });\n * }\n * ```\n *\n * @example\n * ```tsx\n * // Type-safe with scopes\n * import { createTypedHooks } from '@okyrychenko-dev/react-action-guard';\n *\n * type AppScopes = 'global' | 'form' | 'checkout';\n * const { useBlocker } = createTypedHooks<AppScopes>();\n *\n * function MyComponent() {\n * useBlocker('blocker-id', { scope: 'form' });\n *\n * useNavigationBlocker({\n * scope: 'form', // Type-safe!\n * message: 'Leave?',\n * });\n * }\n * ```\n */\nexport function useNavigationBlocker(\n options: UseNavigationBlockerOptions\n): NavigationBlockerReturn {\n const { when, scope, message, onBlock, onAllow, blockBrowserUnload = true, onConfirm } = options;\n\n const router = useRouter();\n\n // Use shared logic to determine if blocking should be active\n const shouldBlock = useShouldBlock(when, scope);\n\n // Block navigation using TanStack Router's history\n useEffect(() => {\n if (!shouldBlock || !hasBlockingHistory(router)) {\n return;\n }\n\n // Block navigation with properly typed update parameter\n type NavigationUpdate = Record<string, unknown> & { retry?: () => void };\n const unblock = router.history.block((update: NavigationUpdate) => {\n // Early return if no message\n if (!message) {\n return;\n }\n\n // Trigger onBlock callback\n onBlock?.();\n\n const confirmation = resolveConfirmResult(message, onConfirm, (value) =>\n window.confirm(value)\n );\n\n if (confirmation.kind === \"async\") {\n confirmation.promise\n .then((confirmed) => {\n if (confirmed) {\n onAllow?.();\n unblock();\n attemptRetry(update);\n }\n })\n .catch((error: unknown) => {\n // On error, unblock but don't retry\n unblock();\n if (process.env.NODE_ENV !== \"production\") {\n console.error(\"[react-action-guard-router] Confirmation error:\", error);\n }\n });\n return;\n }\n\n if (confirmation.confirmed) {\n onAllow?.();\n unblock();\n attemptRetry(update);\n }\n });\n\n return () => {\n unblock();\n };\n }, [shouldBlock, message, onBlock, onAllow, router, onConfirm]);\n\n // Also block browser unload if requested\n useBeforeUnload(blockBrowserUnload && shouldBlock, message ?? DEFAULT_UNLOAD_MESSAGE);\n\n return {\n isBlocking: shouldBlock,\n };\n}\n"]}
1
+ {"version":3,"sources":["../../src/core/utils.ts","../../src/core/useShouldBlock.ts","../../src/core/confirmationOwner.utils.ts","../../src/tanstack-router/useNavigationBlocker.ts"],"names":["isDefined","useEffect"],"mappings":";;;;;;AASO,SAAS,iBAAiB,SAAA,EAA+C;AAC9E,EAAA,OAAO,UAAA,CAAW,SAAS,CAAA,GAAI,SAAA,EAAU,GAAI,SAAA;AAC/C;AAMA,IAAM,UAAU,CAAC,KAAA,KAAsC,QAAA,CAAS,KAAK,KAAK,MAAA,IAAU,KAAA;AAK7E,SAAS,WAAc,KAAA,EAAyC;AACrE,EAAA,IAAI,CAAC,OAAA,CAAQ,KAAK,CAAA,EAAG;AACnB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,UAAA,CAAW,MAA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O,EAAE,YAAY,WAAA,EAAY;AACnC","file":"index.js","sourcesContent":["import { isArray, isFunction, isObject } from \"@okyrychenko-dev/type-utils\";\nimport type { Optional } from \"@okyrychenko-dev/type-utils\";\n\n/**\n * Resolves a condition value (boolean or function returning boolean)\n *\n * @param condition - Boolean value or function\n * @returns Resolved boolean value\n */\nexport function resolveCondition(condition: boolean | (() => boolean)): boolean {\n return isFunction(condition) ? condition() : condition;\n}\n\ninterface Thenable {\n then: (...args: Array<unknown>) => unknown;\n}\n\nconst hasThen = (value: unknown): value is Thenable => isObject(value) && \"then\" in value;\n\n/**\n * Checks if a value behaves like a Promise (thenable)\n */\nexport function isThenable<T>(value: unknown): value is PromiseLike<T> {\n if (!hasThen(value)) {\n return false;\n }\n\n return isFunction(value.then);\n}\n\nexport interface ConfirmResultSync {\n kind: \"sync\";\n confirmed: boolean;\n}\n\nexport interface ConfirmResultAsync {\n kind: \"async\";\n promise: Promise<boolean>;\n}\n\nexport type ConfirmResult = ConfirmResultSync | ConfirmResultAsync;\n\n/**\n * Normalizes custom confirm result into sync or async branch.\n */\nexport function resolveConfirmResult(\n message: string,\n onConfirm: Optional<(message: string) => boolean | PromiseLike<boolean>>,\n fallbackConfirm: (message: string) => boolean\n): ConfirmResult {\n if (!onConfirm) {\n return { kind: \"sync\", confirmed: fallbackConfirm(message) };\n }\n\n const result = onConfirm(message);\n\n if (isThenable<boolean>(result)) {\n return { kind: \"async\", promise: Promise.resolve(result) };\n }\n\n return { kind: \"sync\", confirmed: result };\n}\n\n/**\n * Generates a unique blocker ID based on scope and timestamp\n *\n * @param prefix - Prefix for the ID\n * @param scope - Optional scope\n * @returns Unique blocker ID\n */\nexport function createBlockerId(prefix: string, scope?: string | Array<string>): string {\n const scopePart = scope ? `-${isArray(scope) ? scope.join(\"-\") : scope}` : \"\";\n const timestamp = String(Date.now());\n\n return `${prefix}${scopePart}-${timestamp}`;\n}\n\n/**\n * Checks if a value is defined and not empty\n *\n * @param value - Value to check\n * @returns True if value is defined and not empty\n */\nexport { isDefined } from \"@okyrychenko-dev/type-utils\";\n\n/**\n * Normalizes scope to an array\n *\n * @param scope - String or array of strings\n * @returns Array of scope strings\n */\nexport function normalizeScope(scope: Optional<string | Array<string>>): Array<string> {\n if (!scope) {\n return [];\n }\n\n return isArray(scope) ? scope : [scope];\n}\n\n/** Identifies protection independently of scope order and duplicate entries. */\nexport function createScopeKey(scope: Optional<string | Array<string>>): string {\n return JSON.stringify([...new Set(normalizeScope(scope))].sort());\n}\n","import { useIsBlocked } from \"@okyrychenko-dev/react-action-guard\";\nimport { isDefined } from \"@okyrychenko-dev/type-utils\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { normalizeScope, resolveCondition } from \"./utils\";\n\n/**\n * Shared hook to determine if blocking should be active based on\n * condition and/or scope state.\n *\n * Pure function conditions are evaluated synchronously on every render.\n * Mutating a ref alone does not trigger a render.\n *\n * @param when - Optional condition (boolean or function)\n * @param scope - Optional scope(s) to check\n * @returns Whether blocking should be active\n *\n * @internal\n */\nexport function useShouldBlock(\n when?: boolean | (() => boolean),\n scope?: string | Array<string>\n): boolean {\n // Memoize scope normalization to avoid recalculation on every render\n const scopes = useMemo(() => normalizeScope(scope), [scope]);\n\n // Check if any specified scopes are blocked\n const isScopeBlocked = useIsBlocked(scopes.length === 1 ? scopes[0] : scopes);\n\n // Development-only validation\n const warnedMissingConditionRef = useRef(false);\n\n useEffect(() => {\n if (process.env.NODE_ENV !== \"development\") {\n return;\n }\n\n if (!warnedMissingConditionRef.current && !isDefined(when) && !scope) {\n warnedMissingConditionRef.current = true;\n console.warn(\n '[react-action-guard-router] useShouldBlock: Neither \"when\" nor \"scope\" provided. ' +\n \"This hook will always return false. Please provide at least one condition.\"\n );\n }\n }, [when, scope]);\n\n const blockCondition = isDefined(when) && resolveCondition(when);\n\n return blockCondition || Boolean(scope && isScopeBlocked);\n}\n","import type { ConfirmationOwner } from \"./confirmationOwner.types\";\n\nexport function createConfirmationOwner(): ConfirmationOwner {\n let currentAttempt = 0;\n\n function invalidate(): void {\n currentAttempt += 1;\n }\n\n function begin(): () => boolean {\n const attempt = ++currentAttempt;\n\n function settle(): boolean {\n if (attempt !== currentAttempt) {\n return false;\n }\n invalidate();\n\n return true;\n }\n\n return settle;\n }\n\n return { begin, invalidate };\n}\n","import { useBlocker } from \"@tanstack/react-router\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport {\n createConfirmationOwner,\n createScopeKey,\n resolveConfirmResult,\n useShouldBlock,\n} from \"../core\";\nimport type { NavigationBlockerReturn } from \"../core\";\nimport type { UseNavigationBlockerOptions } from \"./types\";\n\n/** Blocks native TanStack transitions while retaining protection after confirmation. */\nexport function useNavigationBlocker(\n options: UseNavigationBlockerOptions\n): NavigationBlockerReturn {\n const { when, scope, message, onBlock, onAllow, blockBrowserUnload = true, onConfirm } = options;\n\n const shouldBlock = useShouldBlock(when, scope);\n const scopeKey = createScopeKey(scope);\n const [confirmationOwner] = useState(createConfirmationOwner);\n\n const { begin, invalidate } = confirmationOwner;\n\n useEffect(() => {\n return invalidate;\n }, [when, scopeKey, shouldBlock, message, onConfirm, invalidate]);\n\n const shouldBlockFn = useCallback(async () => {\n const settle = begin();\n\n onBlock?.();\n\n if (!message) {\n return true;\n }\n\n try {\n const confirmation = resolveConfirmResult(message, onConfirm, (value) =>\n window.confirm(value)\n );\n let confirmed: boolean;\n\n if (confirmation.kind === \"async\") {\n confirmed = await confirmation.promise;\n } else {\n confirmed = confirmation.confirmed;\n }\n\n if (!settle() || !confirmed) {\n return true;\n }\n\n onAllow?.();\n\n return false;\n } catch {\n return true;\n }\n }, [message, onBlock, onAllow, onConfirm, begin]);\n\n useBlocker({\n shouldBlockFn,\n enableBeforeUnload: blockBrowserUnload && shouldBlock,\n disabled: !shouldBlock,\n });\n\n return { isBlocking: shouldBlock };\n}\n"]}
@@ -35,41 +35,6 @@ interface BaseNavigationBlockerOptions {
35
35
  blockBrowserUnload?: boolean;
36
36
  /**
37
37
  * Custom confirmation handler for showing your own dialog UI.
38
- *
39
- * If provided, this will be called instead of window.confirm() to allow
40
- * custom dialog components. Async handlers are supported, but note:
41
- * - Next.js Pages Router re-attempts navigation after resolve.
42
- * - Router adapters may ignore stale resolves if a newer confirm starts.
43
- *
44
- * @param message - The confirmation message to display
45
- * @returns boolean | Promise<boolean> - true to allow navigation, false to block
46
- *
47
- * @example
48
- * ```tsx
49
- * // With custom dialog component
50
- * const [dialogState, setDialogState] = useState(null);
51
- *
52
- * onConfirm: (message) => {
53
- * return new Promise((resolve) => {
54
- * setDialogState({ message, resolve });
55
- * });
56
- * }
57
- *
58
- * // In JSX:
59
- * {dialogState && (
60
- * <CustomDialog
61
- * message={dialogState.message}
62
- * onConfirm={() => {
63
- * dialogState.resolve(true);
64
- * setDialogState(null);
65
- * }}
66
- * onCancel={() => {
67
- * dialogState.resolve(false);
68
- * setDialogState(null);
69
- * }}
70
- * />
71
- * )}
72
- * ```
73
38
  */
74
39
  onConfirm?: (message: string) => boolean | PromiseLike<boolean>;
75
40
  }
@@ -35,41 +35,6 @@ interface BaseNavigationBlockerOptions {
35
35
  blockBrowserUnload?: boolean;
36
36
  /**
37
37
  * Custom confirmation handler for showing your own dialog UI.
38
- *
39
- * If provided, this will be called instead of window.confirm() to allow
40
- * custom dialog components. Async handlers are supported, but note:
41
- * - Next.js Pages Router re-attempts navigation after resolve.
42
- * - Router adapters may ignore stale resolves if a newer confirm starts.
43
- *
44
- * @param message - The confirmation message to display
45
- * @returns boolean | Promise<boolean> - true to allow navigation, false to block
46
- *
47
- * @example
48
- * ```tsx
49
- * // With custom dialog component
50
- * const [dialogState, setDialogState] = useState(null);
51
- *
52
- * onConfirm: (message) => {
53
- * return new Promise((resolve) => {
54
- * setDialogState({ message, resolve });
55
- * });
56
- * }
57
- *
58
- * // In JSX:
59
- * {dialogState && (
60
- * <CustomDialog
61
- * message={dialogState.message}
62
- * onConfirm={() => {
63
- * dialogState.resolve(true);
64
- * setDialogState(null);
65
- * }}
66
- * onCancel={() => {
67
- * dialogState.resolve(false);
68
- * setDialogState(null);
69
- * }}
70
- * />
71
- * )}
72
- * ```
73
38
  */
74
39
  onConfirm?: (message: string) => boolean | PromiseLike<boolean>;
75
40
  }
package/package.json CHANGED
@@ -1,57 +1,63 @@
1
1
  {
2
2
  "name": "@okyrychenko-dev/react-action-guard-router",
3
- "version": "0.2.3",
3
+ "version": "1.0.0",
4
4
  "type": "module",
5
5
  "description": "Navigation blocking adapters for React Action Guard across React Router, TanStack Router, and Next.js",
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
6
9
  "main": "./dist/index.js",
7
10
  "module": "./dist/index.js",
8
11
  "types": "./dist/index.d.ts",
9
12
  "exports": {
10
13
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.cts",
20
+ "default": "./dist/index.cjs"
21
+ }
14
22
  },
15
23
  "./react-router": {
16
- "types": "./dist/react-router/index.d.ts",
17
- "import": "./dist/react-router/index.js",
18
- "require": "./dist/react-router/index.cjs"
24
+ "import": {
25
+ "types": "./dist/react-router/index.d.ts",
26
+ "default": "./dist/react-router/index.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/react-router/index.d.cts",
30
+ "default": "./dist/react-router/index.cjs"
31
+ }
19
32
  },
20
33
  "./tanstack-router": {
21
- "types": "./dist/tanstack-router/index.d.ts",
22
- "import": "./dist/tanstack-router/index.js",
23
- "require": "./dist/tanstack-router/index.cjs"
34
+ "import": {
35
+ "types": "./dist/tanstack-router/index.d.ts",
36
+ "default": "./dist/tanstack-router/index.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/tanstack-router/index.d.cts",
40
+ "default": "./dist/tanstack-router/index.cjs"
41
+ }
24
42
  },
25
43
  "./nextjs": {
26
- "types": "./dist/nextjs/index.d.ts",
27
- "import": "./dist/nextjs/index.js",
28
- "require": "./dist/nextjs/index.cjs"
44
+ "import": {
45
+ "types": "./dist/nextjs/index.d.ts",
46
+ "default": "./dist/nextjs/index.js"
47
+ },
48
+ "require": {
49
+ "types": "./dist/nextjs/index.d.cts",
50
+ "default": "./dist/nextjs/index.cjs"
51
+ }
29
52
  }
30
53
  },
31
54
  "sideEffects": false,
32
55
  "files": [
33
56
  "dist",
34
57
  "README.md",
58
+ "CHANGELOG.md",
35
59
  "LICENSE"
36
60
  ],
37
- "scripts": {
38
- "build": "tsup",
39
- "dev": "tsup --watch",
40
- "clean": "rm -rf dist",
41
- "prepublishOnly": "npm run clean && npm run build",
42
- "typecheck": "tsc --noEmit",
43
- "lint": "eslint src --ext .ts,.tsx",
44
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
45
- "format": "npm run lint:fix && prettier --write \"src/**/*.{ts,tsx}\"",
46
- "format:check": "npm run lint && prettier --check \"src/**/*.{ts,tsx}\"",
47
- "test": "vitest",
48
- "test:ui": "vitest --ui",
49
- "test:run": "vitest run",
50
- "test:coverage": "vitest run --coverage",
51
- "prepare": "husky",
52
- "storybook": "storybook dev -p 6007",
53
- "build-storybook": "storybook build"
54
- },
55
61
  "keywords": [
56
62
  "react",
57
63
  "router",
@@ -68,21 +74,22 @@
68
74
  "license": "MIT",
69
75
  "repository": {
70
76
  "type": "git",
71
- "url": "https://github.com/okyrychenko-dev/react-action-guard-router"
77
+ "url": "git+https://github.com/okyrychenko-dev/react-action-guard.git",
78
+ "directory": "packages/router"
72
79
  },
73
80
  "bugs": {
74
- "url": "https://github.com/okyrychenko-dev/react-action-guard-router/issues"
81
+ "url": "https://github.com/okyrychenko-dev/react-action-guard/issues"
75
82
  },
76
- "homepage": "https://github.com/okyrychenko-dev/react-action-guard-router#readme",
83
+ "homepage": "https://github.com/okyrychenko-dev/react-action-guard/tree/main/packages/router#readme",
77
84
  "publishConfig": {
78
85
  "access": "public"
79
86
  },
80
87
  "peerDependencies": {
81
- "@okyrychenko-dev/react-action-guard": "^1.0.3",
82
- "@tanstack/react-router": "^1.0.0",
88
+ "@okyrychenko-dev/react-action-guard": "^2.0.0",
89
+ "@tanstack/react-router": "^1.170.41",
83
90
  "next": "^13.4.0 || ^14.0.0 || ^15.0.0",
84
91
  "react": "^18.0.0 || ^19.0.0",
85
- "react-router-dom": "^6.0.0 || ^7.0.0"
92
+ "react-router-dom": "^6.19.0 || ^7.0.0"
86
93
  },
87
94
  "peerDependenciesMeta": {
88
95
  "react-router-dom": {
@@ -95,46 +102,53 @@
95
102
  "optional": true
96
103
  }
97
104
  },
98
- "overrides": {
99
- "@okyrychenko-dev/react-zustand-toolkit": "^0.4.0",
100
- "postcss": ">=8.5.10"
101
- },
102
105
  "devDependencies": {
103
- "@eslint/js": "^9.39.1",
104
- "@okyrychenko-dev/react-action-guard": "^1.0.3",
105
- "@storybook/addon-a11y": "10.0.8",
106
- "@storybook/addon-docs": "10.0.8",
107
- "@storybook/react-vite": "10.0.8",
108
- "@tanstack/react-router": "^1.94.4",
106
+ "@okyrychenko-dev/react-action-guard": "2.0.0",
107
+ "@playwright/test": "^1.63.0",
108
+ "@storybook/addon-a11y": "^10.3.6",
109
+ "@storybook/addon-docs": "^10.3.6",
110
+ "@storybook/react-vite": "^10.3.6",
111
+ "@tanstack/react-router": "^1.170.41",
109
112
  "@testing-library/dom": "^10.4.1",
110
113
  "@testing-library/jest-dom": "^6.9.1",
111
114
  "@testing-library/react": "^16.3.0",
112
115
  "@types/node": "^24.10.4",
113
116
  "@types/react": "^19.2.5",
114
- "@typescript-eslint/eslint-plugin": "^8.46.4",
115
- "@typescript-eslint/parser": "^8.46.4",
116
- "@vitest/coverage-v8": "^4.0.9",
117
- "@vitest/ui": "^4.0.9",
117
+ "@types/react-dom": "~19.2.7",
118
118
  "clsx": "^2.1.1",
119
- "eslint": "^9.39.1",
120
- "eslint-config-prettier": "^10.1.8",
121
- "eslint-plugin-import": "^2.32.0",
122
- "eslint-plugin-react": "^7.37.5",
123
- "eslint-plugin-react-hooks": "^7.0.1",
124
- "eslint-plugin-storybook": "10.0.8",
125
- "happy-dom": "^20.0.10",
126
- "husky": "^9.1.7",
119
+ "eslint-plugin-storybook": "^10.3.6",
127
120
  "next": "^15.1.6",
128
- "prettier": "^3.6.2",
129
121
  "react": "^19.2.0",
130
122
  "react-dom": "^19.2.0",
131
- "react-router-dom": "^7.1.3",
123
+ "react-router-dom": "7.14.2",
132
124
  "remark-gfm": "^4.0.1",
133
125
  "storybook": "^10.3.6",
134
- "tsup": "^8.5.1",
135
- "typescript": "^5.3.3",
136
- "typescript-eslint": "^8.46.4",
137
- "vitest": "^4.0.9",
126
+ "vite": "8.2.1",
138
127
  "zustand": "^5.0.8"
128
+ },
129
+ "allowScripts": {
130
+ "esbuild@0.27.2": true,
131
+ "sharp@0.34.5": true
132
+ },
133
+ "dependencies": {
134
+ "@okyrychenko-dev/type-utils": "^0.1.2"
135
+ },
136
+ "scripts": {
137
+ "build": "tsup",
138
+ "dev": "tsup --watch",
139
+ "clean": "rm -rf dist",
140
+ "typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
141
+ "lint": "eslint src browser --ext .ts,.tsx",
142
+ "lint:fix": "eslint src browser --ext .ts,.tsx --fix",
143
+ "format": "prettier --write \"src/**/*.{ts,tsx}\" \"browser/**/*.{ts,tsx,html,md}\" playwright.config.ts",
144
+ "format:check": "prettier --check \"src/**/*.{ts,tsx}\" \"browser/**/*.{ts,tsx,html,md}\" playwright.config.ts",
145
+ "test": "vitest",
146
+ "test:ui": "vitest --ui",
147
+ "test:run": "vitest run",
148
+ "test:coverage": "vitest run --coverage",
149
+ "storybook": "storybook dev -p 6007",
150
+ "build-storybook": "storybook build",
151
+ "browser:serve": "vite browser --host 127.0.0.1 --port 4173 --strictPort",
152
+ "test:browser": "playwright test"
139
153
  }
140
- }
154
+ }