@qubhq/react-router-prompt 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -11
- package/dist/index.d.ts +1 -1
- package/dist/react-router-prompt.js +14 -14
- package/dist/react-router-prompt.umd.cjs +1 -1
- package/package.json +11 -13
package/README.md
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
1
|
+
<h1 align="center">react-router-prompt 🚨</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/react-router-prompt">
|
|
5
|
+
<img alt="npm version" src="https://img.shields.io/npm/v/@qubhq/react-router-prompt.svg">
|
|
6
|
+
</a>
|
|
7
|
+
|
|
8
|
+
<a href="https://www.npmjs.com/package/react-router-prompt">
|
|
9
|
+
<img alt="npm weekly downloads" src="https://img.shields.io/npm/dw/@qubhq/react-router-prompt.svg">
|
|
10
|
+
</a>
|
|
11
|
+
|
|
12
|
+
<a href="https://www.npmjs.com/package/react-router-prompt">
|
|
13
|
+
<img alt="total downloads" src="https://img.shields.io/npm/dt/@qubhq/react-router-prompt.svg">
|
|
14
|
+
</a>
|
|
15
|
+
|
|
16
|
+
<a href="https://www.npmjs.com/package/react-router-prompt">
|
|
17
|
+
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@qubhq/react-router-prompt">
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
A Component for the react-router v7 <b>Prompt</b> (package renamed from react-router-dom). Allows to create more flexible dialogs.
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<hr />
|
|
4
27
|
|
|
5
28
|
Please follow [Note section](https://github.com/sshyam-gupta/react-router-prompt#note) for more details on react-router support
|
|
6
29
|
|
|
7
|
-
[](https://www.npmjs.com/package/react-router-prompt)
|
|
8
|
-
|
|
9
|
-
[](https://www.npmjs.com/package/react-router-prompt)
|
|
10
|
-
|
|
11
|
-
[](https://www.npmjs.com/package/react-router-prompt)
|
|
12
|
-
|
|
13
30
|
## ✨ [Demo](https://codesandbox.io/s/react-router-prompt-example-react-router-6-7-y9ug7z?file=/src/App.js)
|
|
14
31
|
|
|
15
32
|
## 🏠 [Homepage](https://github.com/sshyam-gupta/react-router-prompt#readme)
|
|
@@ -18,7 +35,7 @@ Please follow [Note section](https://github.com/sshyam-gupta/react-router-prompt
|
|
|
18
35
|
|
|
19
36
|
### Prerequisite
|
|
20
37
|
|
|
21
|
-
**React-router
|
|
38
|
+
**React-router >= 7** and shall be ideally used with [**data routers**](https://reactrouter.com/6.28.1/routers/picking-a-router#using-v64-data-apis)
|
|
22
39
|
|
|
23
40
|
```bash
|
|
24
41
|
pnpm add react-router-prompt
|
|
@@ -71,7 +88,7 @@ yarn add react-router-prompt
|
|
|
71
88
|
|
|
72
89
|
#### Note 🗒️
|
|
73
90
|
|
|
74
|
-
This version works with react-router
|
|
91
|
+
This version works with 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)
|
|
75
92
|
|
|
76
93
|
- For react-router support `(v7)` please install `v0.8.x`
|
|
77
94
|
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,6 @@ type ReactRouterPromptProps = {
|
|
|
32
32
|
* )}
|
|
33
33
|
* </ReactRouterPrompt>
|
|
34
34
|
*/
|
|
35
|
-
declare function ReactRouterPrompt({ when, children, beforeCancel, beforeConfirm, defaultBehaviour, }: ReactRouterPromptProps): import("react/jsx-runtime").JSX.Element
|
|
35
|
+
declare function ReactRouterPrompt({ when, children, beforeCancel, beforeConfirm, defaultBehaviour, }: ReactRouterPromptProps): import("react/jsx-runtime").JSX.Element;
|
|
36
36
|
export { useConfirm, usePrompt };
|
|
37
37
|
export default ReactRouterPrompt;
|
|
@@ -19,46 +19,46 @@ function y(o, c, n) {
|
|
|
19
19
|
const C = (o, c) => {
|
|
20
20
|
const [n, t] = k(null), e = y(
|
|
21
21
|
o,
|
|
22
|
-
(
|
|
23
|
-
t(
|
|
22
|
+
(i) => {
|
|
23
|
+
t(i);
|
|
24
24
|
},
|
|
25
25
|
c
|
|
26
26
|
), r = () => {
|
|
27
27
|
e.state === "blocked" && e.reset();
|
|
28
|
-
},
|
|
28
|
+
}, s = () => {
|
|
29
29
|
e.state === "blocked" && setTimeout(e.proceed, 0);
|
|
30
30
|
};
|
|
31
31
|
return {
|
|
32
32
|
isActive: e.state === "blocked",
|
|
33
|
-
onConfirm:
|
|
33
|
+
onConfirm: s,
|
|
34
34
|
resetConfirmation: r,
|
|
35
35
|
nextLocation: n || void 0
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
-
function
|
|
38
|
+
function v({
|
|
39
39
|
when: o,
|
|
40
40
|
children: c,
|
|
41
41
|
beforeCancel: n,
|
|
42
42
|
beforeConfirm: t,
|
|
43
43
|
defaultBehaviour: e = "reset"
|
|
44
44
|
}) {
|
|
45
|
-
const { isActive: r, onConfirm:
|
|
45
|
+
const { isActive: r, onConfirm: s, resetConfirmation: i, nextLocation: u } = C(
|
|
46
46
|
o,
|
|
47
47
|
e
|
|
48
48
|
), f = a(async () => {
|
|
49
|
-
t && await t(),
|
|
50
|
-
}, [t,
|
|
51
|
-
n && await n(),
|
|
52
|
-
}, [n,
|
|
53
|
-
return
|
|
54
|
-
isActive:
|
|
49
|
+
t && await t(), s();
|
|
50
|
+
}, [t, s]), l = a(async () => {
|
|
51
|
+
n && await n(), i();
|
|
52
|
+
}, [n, i]);
|
|
53
|
+
return /* @__PURE__ */ m(d, { children: c({
|
|
54
|
+
isActive: r,
|
|
55
55
|
onConfirm: f,
|
|
56
56
|
onCancel: l,
|
|
57
57
|
nextLocation: u || void 0
|
|
58
|
-
}) })
|
|
58
|
+
}) });
|
|
59
59
|
}
|
|
60
60
|
export {
|
|
61
|
-
|
|
61
|
+
v as default,
|
|
62
62
|
C as useConfirm,
|
|
63
63
|
y as usePrompt
|
|
64
64
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react/jsx-runtime"),require("react"),require("react-router")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-router"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.ReactRouterPrompt={},o["react/jsx-runtime"],o.react,o.reactRouter))})(this,function(o,s,c,d){"use strict";function l(t,r,i){const e=d.useBlocker(t);return c.useEffect(()=>{e.state==="blocked"&&e.location&&r&&r(e.location),e.state==="blocked"&&!t&&(i==="proceed"?setTimeout(e.proceed,0):e.reset())},[e,i,t,r]),d.useBeforeUnload(c.useCallback(n=>{(typeof t=="boolean"&&t===!0||typeof t=="function"&&t())&&(n.preventDefault(),n.returnValue="Changes that you made may not be saved.")},[t]),{capture:!0}),e}const m=(t,r)=>{const[i,e]=c.useState(null),n=l(t,a=>{e(a)},r),f=()=>{n.state==="blocked"&&n.reset()},u=()=>{n.state==="blocked"&&setTimeout(n.proceed,0)};return{isActive:n.state==="blocked",onConfirm:u,resetConfirmation:f,nextLocation:i||void 0}};function p({when:t,children:r,beforeCancel:i,beforeConfirm:e,defaultBehaviour:n="reset"}){const{isActive:f,onConfirm:u,resetConfirmation:a,nextLocation:k}=m(t,n),y=c.useCallback(async()=>{e&&await e(),u()},[e,u]),C=c.useCallback(async()=>{i&&await i(),a()},[i,a]);return
|
|
1
|
+
(function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react/jsx-runtime"),require("react"),require("react-router")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-router"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.ReactRouterPrompt={},o["react/jsx-runtime"],o.react,o.reactRouter))})(this,function(o,s,c,d){"use strict";function l(t,r,i){const e=d.useBlocker(t);return c.useEffect(()=>{e.state==="blocked"&&e.location&&r&&r(e.location),e.state==="blocked"&&!t&&(i==="proceed"?setTimeout(e.proceed,0):e.reset())},[e,i,t,r]),d.useBeforeUnload(c.useCallback(n=>{(typeof t=="boolean"&&t===!0||typeof t=="function"&&t())&&(n.preventDefault(),n.returnValue="Changes that you made may not be saved.")},[t]),{capture:!0}),e}const m=(t,r)=>{const[i,e]=c.useState(null),n=l(t,a=>{e(a)},r),f=()=>{n.state==="blocked"&&n.reset()},u=()=>{n.state==="blocked"&&setTimeout(n.proceed,0)};return{isActive:n.state==="blocked",onConfirm:u,resetConfirmation:f,nextLocation:i||void 0}};function p({when:t,children:r,beforeCancel:i,beforeConfirm:e,defaultBehaviour:n="reset"}){const{isActive:f,onConfirm:u,resetConfirmation:a,nextLocation:k}=m(t,n),y=c.useCallback(async()=>{e&&await e(),u()},[e,u]),C=c.useCallback(async()=>{i&&await i(),a()},[i,a]);return s.jsx(s.Fragment,{children:r({isActive:f,onConfirm:y,onCancel:C,nextLocation:k||void 0})})}o.default=p,o.useConfirm=m,o.usePrompt=l,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.8.
|
|
2
|
+
"version": "0.8.3",
|
|
3
3
|
"name": "@qubhq/react-router-prompt",
|
|
4
4
|
"description": "React Router Navigation Prompt for v6",
|
|
5
5
|
"type": "module",
|
|
@@ -30,16 +30,6 @@
|
|
|
30
30
|
"react",
|
|
31
31
|
"router"
|
|
32
32
|
],
|
|
33
|
-
"scripts": {
|
|
34
|
-
"dev": "vite",
|
|
35
|
-
"build": "tsc && vite build",
|
|
36
|
-
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
|
|
37
|
-
"lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
|
|
38
|
-
"format": "prettier \"src/**/*.{js,jsx,ts,tsx,css,scss}\" --write",
|
|
39
|
-
"size": "size-limit",
|
|
40
|
-
"prepublishOnly": "pnpm build",
|
|
41
|
-
"prepare": "husky"
|
|
42
|
-
},
|
|
43
33
|
"devDependencies": {
|
|
44
34
|
"@size-limit/preset-small-lib": "^11.0.2",
|
|
45
35
|
"@types/react": "^19.0.2",
|
|
@@ -81,5 +71,13 @@
|
|
|
81
71
|
"path": "dist/react-router-prompt.umd.cjs",
|
|
82
72
|
"limit": "800 B"
|
|
83
73
|
}
|
|
84
|
-
]
|
|
85
|
-
|
|
74
|
+
],
|
|
75
|
+
"scripts": {
|
|
76
|
+
"dev": "vite",
|
|
77
|
+
"build": "tsc && vite build",
|
|
78
|
+
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
|
|
79
|
+
"lint:fix": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
|
|
80
|
+
"format": "prettier \"src/**/*.{js,jsx,ts,tsx,css,scss}\" --write",
|
|
81
|
+
"size": "size-limit"
|
|
82
|
+
}
|
|
83
|
+
}
|