react-router-prompt
Advanced tools
@@ -1,2 +0,2 @@ | ||
| import { BlockerFunction } from 'react-router-dom'; | ||
| import { BlockerFunction } from 'react-router'; | ||
| declare interface InitialStateType { | ||
@@ -3,0 +3,0 @@ isActive: boolean; |
@@ -1,3 +0,3 @@ | ||
| import { Blocker, BlockerFunction } from 'react-router-dom'; | ||
| import { Blocker, BlockerFunction } from 'react-router'; | ||
| declare function usePrompt(when: boolean | BlockerFunction): Blocker; | ||
| export default usePrompt; |
+1
-1
| import { default as React } from 'react'; | ||
| import { BlockerFunction } from 'react-router-dom'; | ||
| import { BlockerFunction } from 'react-router'; | ||
| import { default as useConfirm } from './hooks/use-confirm'; | ||
@@ -4,0 +4,0 @@ import { default as usePrompt } from './hooks/use-prompt'; |
| import { jsx as f, Fragment as m } from "react/jsx-runtime"; | ||
| import { useEffect as l, useCallback as n } from "react"; | ||
| import { useBlocker as p, useBeforeUnload as d } from "react-router-dom"; | ||
| import { useBlocker as p, useBeforeUnload as d } from "react-router"; | ||
| function k(t) { | ||
@@ -5,0 +5,0 @@ const o = p(t); |
@@ -1,1 +0,1 @@ | ||
| (function(o,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-router-dom"],n):(o=typeof globalThis<"u"?globalThis:o||self,n(o.ReactRouterPrompt={},o["react/jsx-runtime"],o.react,o.reactRouterDom))})(this,function(o,n,u,s){"use strict";function c(e){const t=s.useBlocker(e);return u.useEffect(()=>{t.state==="blocked"&&!e&&t.reset()},[t,e]),s.useBeforeUnload(u.useCallback(r=>{(typeof e=="boolean"&&e===!0||typeof e=="function"&&e())&&(r.preventDefault(),r.returnValue="Changes that you made may not be saved.")},[e]),{capture:!0}),t}const a=e=>{const t=c(e),r=()=>{t.state==="blocked"&&t.reset()},i=()=>{t.state==="blocked"&&setTimeout(t.proceed,0)};return{isActive:t.state==="blocked",onConfirm:i,resetConfirmation:r}};function l({when:e,children:t,beforeCancel:r,beforeConfirm:i}){const{isActive:m,onConfirm:f,resetConfirmation:d}=a(e),p=u.useCallback(async()=>{i&&await i(),f()},[i,f]),k=u.useCallback(async()=>{r&&await r(),d()},[r,d]);return m?n.jsx(n.Fragment,{children:t({isActive:!0,onConfirm:p,onCancel:k})}):null}o.default=l,o.useConfirm=a,o.usePrompt=c,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
| (function(o,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react"),require("react-router")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-router"],n):(o=typeof globalThis<"u"?globalThis:o||self,n(o.ReactRouterPrompt={},o["react/jsx-runtime"],o.react,o.reactRouter))})(this,function(o,n,u,s){"use strict";function c(e){const t=s.useBlocker(e);return u.useEffect(()=>{t.state==="blocked"&&!e&&t.reset()},[t,e]),s.useBeforeUnload(u.useCallback(r=>{(typeof e=="boolean"&&e===!0||typeof e=="function"&&e())&&(r.preventDefault(),r.returnValue="Changes that you made may not be saved.")},[e]),{capture:!0}),t}const a=e=>{const t=c(e),r=()=>{t.state==="blocked"&&t.reset()},i=()=>{t.state==="blocked"&&setTimeout(t.proceed,0)};return{isActive:t.state==="blocked",onConfirm:i,resetConfirmation:r}};function l({when:e,children:t,beforeCancel:r,beforeConfirm:i}){const{isActive:m,onConfirm:f,resetConfirmation:d}=a(e),p=u.useCallback(async()=>{i&&await i(),f()},[i,f]),k=u.useCallback(async()=>{r&&await r(),d()},[r,d]);return m?n.jsx(n.Fragment,{children:t({isActive:!0,onConfirm:p,onCancel:k})}):null}o.default=l,o.useConfirm=a,o.usePrompt=c,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
+15
-18
| { | ||
| "version": "0.7.2", | ||
| "version": "0.8.0-beta-1", | ||
| "name": "react-router-prompt", | ||
@@ -33,12 +33,2 @@ "description": "React Router Navigation Prompt for v6", | ||
| ], | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "tsc && vite build", | ||
| "lint": "eslint src --ext .js,.jsx,.ts,.tsx", | ||
| "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix", | ||
| "format": "prettier \"src/**/*.{js,jsx,ts,tsx,css,scss}\" --write", | ||
| "size": "size-limit", | ||
| "prepublishOnly": "yarn build", | ||
| "prepare": "husky" | ||
| }, | ||
| "devDependencies": { | ||
@@ -64,3 +54,3 @@ "@size-limit/preset-small-lib": "^11.0.2", | ||
| "react-dom": "^19.0.0", | ||
| "react-router-dom": "^6.22.1", | ||
| "react-router": "^7.1.1", | ||
| "size-limit": "^11.0.2", | ||
@@ -74,4 +64,3 @@ "typescript": "^5.3.3", | ||
| "react": ">=16.8", | ||
| "react-dom": ">=16.8", | ||
| "react-router-dom": ">=6.19 <7" | ||
| "react-dom": ">=16.8" | ||
| }, | ||
@@ -81,9 +70,17 @@ "size-limit": [ | ||
| "path": "dist/react-router-prompt.js", | ||
| "limit": "1.2 KB" | ||
| "limit": "600 B" | ||
| }, | ||
| { | ||
| "path": "dist/react-router-prompt.umd.cjs", | ||
| "limit": "1.2 KB" | ||
| "limit": "800 B" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "build": "tsc && vite build", | ||
| "lint": "eslint src --ext .js,.jsx,.ts,.tsx", | ||
| "lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix", | ||
| "format": "prettier \"src/**/*.{js,jsx,ts,tsx,css,scss}\" --write", | ||
| "size": "size-limit" | ||
| } | ||
| } |
+11
-6
| # react-router-prompt 🚨 | ||
| > A component for the react-router 6 `Prompt`. Allows to create more flexible dialogs. | ||
| > A component for the react-router 6/7 `Prompt`. Allows to create more flexible dialogs. | ||
| Please follow [Note section](https://github.com/sshyam-gupta/react-router-prompt#note) for more details on react-router support | ||
| [](https://www.npmjs.com/package/react-router-prompt) | ||
@@ -19,3 +21,3 @@ | ||
| **React-router-dom >= 6.19** and can be used only with [**data routers**](https://reactrouter.com/en/6.8.1/routers/picking-a-router#using-v64-data-apis) | ||
| **React-router-dom >= 7** or **React-router-dom >= 7** and shall be ideally used with [**data routers**](https://reactrouter.com/6.28.1/routers/picking-a-router#using-v64-data-apis) | ||
@@ -72,9 +74,12 @@ ```bash | ||
| This version works with react-router-dom >=v6.19 | ||
| Should be used within [data routers](https://reactrouter.com/en/6.8.1/routers/picking-a-router#using-v64-data-apis) | ||
| This version works with react-router-dom >=v7 or react-router >=v7 and shall be ideally used with [**data routers**](https://reactrouter.com/6.28.1/routers/picking-a-router#using-v64-data-apis) | ||
| For react-router support `(v6 - v6.2.x)` please install v0.3.0 | ||
| - For react-router / react-router-dom support `(v7)` please install `v0.8.x` | ||
| For react-router support (v6.7.x - v6.18.x) please install v0.5.4 | ||
| - For react-router-dom support `(v6.19.x - v6.28.1)` please install `v0.7.x` | ||
| - For react-router-dom support `(v6.7.x - v6.18.x)` please install `v0.5.4` | ||
| - For react-router-dom support `(v6 - v6.2.x)` please install `v0.3.0` | ||
| _Skipped support in middle due to breaking changes on react-router apis_ | ||
@@ -81,0 +86,0 @@ |
12589
1.93%2
-33.33%110
4.76%