react-router-scroll-to-top 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,6 @@
8
8
  [![GitHub Stars](https://img.shields.io/github/stars/dimazuien/react-router-scroll-to-top)](https://github.com/dimazuien/react-router-scroll-to-top/stargazers)
9
9
  ![CircleCI status](https://img.shields.io/circleci/build/github/dimazuien/react-router-scroll-to-top/main?label=circleci)
10
10
  ![Code scanning](https://img.shields.io/github/workflow/status/dimazuien/react-router-scroll-to-top/CodeQL?label=code%20scanning)
11
- [![Storybook](https://img.shields.io/badge/demos-%F0%9F%9A%80-yellow.svg?label=storybook)](https://dimazuien.github.io/react-router-scroll-to-top)
12
11
 
13
12
  ScrollToTop is a React component that scrolls to the top of a page when the current location gets changed. Since React Router doesn't provide out-of-the-box support for scroll restoration due to [browsers having started handling it on their own](https://majido.github.io/scroll-restoration-proposal/history-based-api.html), this package implements a component for scrolling to the top manually as it is given in [React Router docs](https://reactrouter.com/web/guides/scroll-restoration#scroll-restoration-scroll-to-top).
14
13
 
@@ -19,7 +18,7 @@ npm install react-router-scroll-to-top
19
18
  ```
20
19
 
21
20
  ```jsx
22
- import ScrollToTop from 'react-router-scroll-to-top';
21
+ import { ScrollToTop } from 'react-router-scroll-to-top';
23
22
 
24
23
  const App = () => (
25
24
  <BrowserRouter>
package/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ declare module 'react-router-scroll-to-top/src/ScrollToTop' {
2
+ import { ReactNode } from 'react';
3
+ type Props = Readonly<{
4
+ children?: ReactNode;
5
+ }>;
6
+ function ScrollToTop({ children }: Props): JSX.Element;
7
+ export default ScrollToTop;
8
+
9
+ }
10
+ declare module 'react-router-scroll-to-top/src/index' {
11
+ export { default as ScrollToTop } from 'react-router-scroll-to-top/src/ScrollToTop';
12
+ export { default as useScrollToTop } from 'react-router-scroll-to-top/src/useScrollToTop';
13
+
14
+ }
15
+ declare module 'react-router-scroll-to-top/src/useScrollToTop' {
16
+ const useScrollToTop: () => void;
17
+ export default useScrollToTop;
18
+
19
+ }
20
+ declare module 'react-router-scroll-to-top/tests/ScrollToTop.test' {
21
+ import '@testing-library/jest-dom/extend-expect';
22
+
23
+ }
24
+ declare module 'react-router-scroll-to-top/tests/useScrollToTop.test' {
25
+ import '@testing-library/jest-dom/extend-expect';
26
+
27
+ }
28
+ declare module 'react-router-scroll-to-top' {
29
+ import main = require('react-router-scroll-to-top/src/index');
30
+ export = main;
31
+ }
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see index.js.LICENSE.txt */
2
+ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["react-router-scroll-to-top"]=r():e["react-router-scroll-to-top"]=r()}(self,(function(){return function(){"use strict";var e={44:function(e,r,o){var t=o(497),n=Symbol.for("react.element"),u=Symbol.for("react.fragment"),f=Object.prototype.hasOwnProperty,c=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};r.Fragment=u,r.jsx=function(e,r,o){var t,u={},l=null,a=null;for(t in void 0!==o&&(l=""+o),void 0!==r.key&&(l=""+r.key),void 0!==r.ref&&(a=r.ref),r)f.call(r,t)&&!i.hasOwnProperty(t)&&(u[t]=r[t]);if(e&&e.defaultProps)for(t in r=e.defaultProps)void 0===u[t]&&(u[t]=r[t]);return{$$typeof:n,type:e,key:l,ref:a,props:u,_owner:c.current}}},598:function(e,r,o){e.exports=o(44)},497:function(e){e.exports=require("react")}},r={};function o(t){var n=r[t];if(void 0!==n)return n.exports;var u=r[t]={exports:{}};return e[t](u,u.exports,o),u.exports}o.d=function(e,r){for(var t in r)o.o(r,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},o.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};return function(){o.r(t),o.d(t,{ScrollToTop:function(){return f},useScrollToTop:function(){return n}});var e=o(497),r=require("react-router-dom"),n=function(){var o=(0,r.useLocation)(),t=o.pathname,n=o.state;(0,e.useEffect)((function(){!1!==(null==n?void 0:n.scrollToTop)&&window.scrollTo(0,0)}),[t,n])},u=o(598),f=function(r){var o=r.children;return n(),(0,u.jsx)(u.Fragment,{children:e.Children.toArray(o)})}}(),t}()}));
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license React
3
+ * react-jsx-runtime.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-router-scroll-to-top",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "React component that scrolls to the top of a page when the current location gets changed",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,80 +24,83 @@
24
24
  "url": "https://github.com/dimazuien/react-router-scroll-to-top/issues"
25
25
  },
26
26
  "source": "src/index.ts",
27
- "main": "dist/index.js",
28
- "browser": "dist/index.js",
29
- "module": "dist/index.module.js",
30
- "unpkg": "dist/index.umd.js",
31
- "types": "dist/index.d.ts",
32
- "typings": "dist/index.d.ts",
27
+ "main": "lib/index.js",
28
+ "typings": "index.d.ts",
33
29
  "files": [
34
- "dist"
30
+ "lib",
31
+ "index.d.ts"
35
32
  ],
36
33
  "sideEffects": false,
37
34
  "scripts": {
38
- "lint": "eslint './src/**/*.{js,jsx,ts,tsx}'",
35
+ "_postinstall": "husky install",
36
+ "build": "webpack",
37
+ "dts": "npx npm-dts generate -e src/index",
38
+ "lint": "eslint .",
39
39
  "test": "jest",
40
- "build": "microbundle --jsx React.createElement",
40
+ "prepublishOnly": "pinst --disable",
41
41
  "release": "semantic-release",
42
- "storybook": "start-storybook -p 6006",
43
- "storybook:build": "build-storybook",
44
- "storybook:upload": "gh-pages -d storybook-static --git \"$(which git)\""
42
+ "postpublish": "pinst --enable"
45
43
  },
46
- "dependencies": {},
47
44
  "devDependencies": {
48
- "@babel/core": "7.12.10",
49
- "@commitlint/cli": "11.0.0",
50
- "@commitlint/config-conventional": "11.0.0",
51
- "@semantic-release/changelog": "5.0.1",
52
- "@semantic-release/commit-analyzer": "8.0.1",
53
- "@semantic-release/git": "9.0.0",
54
- "@semantic-release/github": "7.2.0",
55
- "@semantic-release/npm": "7.0.9",
56
- "@semantic-release/release-notes-generator": "9.0.1",
57
- "@storybook/addon-docs": "6.1.11",
58
- "@storybook/react": "6.1.11",
59
- "@testing-library/jest-dom": "5.11.6",
60
- "@testing-library/react": "11.2.2",
61
- "@testing-library/user-event": "12.6.0",
62
- "@types/jest": "26.0.19",
63
- "@types/react": "17.0.0",
64
- "@types/react-dom": "17.0.0",
65
- "@types/react-router-dom": "5.1.6",
66
- "@types/testing-library__jest-dom": "5.9.5",
67
- "@typescript-eslint/eslint-plugin": "4.11.0",
68
- "@typescript-eslint/parser": "4.11.0",
69
- "babel-loader": "8.2.2",
70
- "commitizen": "4.2.2",
45
+ "@babel/core": "7.17.8",
46
+ "@babel/preset-env": "7.16.11",
47
+ "@babel/preset-react": "7.16.7",
48
+ "@babel/preset-typescript": "7.16.7",
49
+ "@commitlint/cli": "16.2.3",
50
+ "@commitlint/config-conventional": "16.2.1",
51
+ "@semantic-release/changelog": "6.0.1",
52
+ "@semantic-release/commit-analyzer": "9.0.2",
53
+ "@semantic-release/git": "10.0.1",
54
+ "@semantic-release/github": "8.0.4",
55
+ "@semantic-release/npm": "9.0.1",
56
+ "@semantic-release/release-notes-generator": "10.0.3",
57
+ "@testing-library/dom": "8.12.0",
58
+ "@testing-library/jest-dom": "5.16.3",
59
+ "@testing-library/react": "13.0.0",
60
+ "@testing-library/user-event": "14.0.4",
61
+ "@types/jest": "27.4.1",
62
+ "@types/react": "17.0.43",
63
+ "@types/react-dom": "17.0.14",
64
+ "@types/react-router-dom": "5.3.3",
65
+ "@types/testing-library__jest-dom": "5.14.3",
66
+ "@typescript-eslint/eslint-plugin": "5.17.0",
67
+ "@typescript-eslint/parser": "5.17.0",
68
+ "babel-loader": "8.2.4",
69
+ "commitizen": "4.2.4",
71
70
  "cz-conventional-changelog": "3.3.0",
72
- "eslint": "7.16.0",
73
- "eslint-config-airbnb": "18.2.1",
74
- "eslint-config-prettier": "7.1.0",
75
- "eslint-plugin-import": "2.22.1",
76
- "eslint-plugin-jest-dom": "3.6.4",
77
- "eslint-plugin-jsx-a11y": "6.4.1",
78
- "eslint-plugin-prettier": "3.3.0",
79
- "eslint-plugin-react": "7.21.5",
80
- "eslint-plugin-react-hooks": "4.2.0",
81
- "eslint-plugin-testing-library": "3.10.1",
82
- "gh-pages": "3.1.0",
83
- "github-markdown-css": "4.0.0",
84
- "husky": "4.3.6",
85
- "jest": "26.6.3",
86
- "lint-staged": "10.5.3",
87
- "lorem-ipsum": "2.0.3",
88
- "microbundle": "0.13.0",
89
- "prettier": "2.2.1",
90
- "react": "17.0.1",
91
- "react-dom": "17.0.1",
92
- "react-router-dom": "5.2.0",
93
- "semantic-release": "17.3.0",
94
- "ts-jest": "26.4.4",
95
- "ts-node": "9.1.1",
96
- "typescript": "4.1.3"
71
+ "eslint": "8.12.0",
72
+ "eslint-config-airbnb": "19.0.4",
73
+ "eslint-config-prettier": "8.5.0",
74
+ "eslint-plugin-import": "2.25.4",
75
+ "eslint-plugin-jest-dom": "4.0.1",
76
+ "eslint-plugin-jsx-a11y": "6.5.1",
77
+ "eslint-plugin-prettier": "4.0.0",
78
+ "eslint-plugin-react": "7.29.4",
79
+ "eslint-plugin-react-hooks": "4.4.0",
80
+ "eslint-plugin-simple-import-sort": "7.0.0",
81
+ "eslint-plugin-testing-library": "5.2.0",
82
+ "gh-pages": "3.2.3",
83
+ "github-markdown-css": "5.1.0",
84
+ "husky": "7.0.4",
85
+ "jest": "27.5.1",
86
+ "lint-staged": "12.3.7",
87
+ "lorem-ipsum": "2.0.4",
88
+ "npm-dts": "1.3.11",
89
+ "pinst": "3.0.0",
90
+ "prettier": "2.6.2",
91
+ "react": "18.0.0",
92
+ "react-dom": "18.0.0",
93
+ "react-router-dom": "6.3.0",
94
+ "semantic-release": "19.0.2",
95
+ "ts-jest": "27.1.4",
96
+ "ts-node": "10.7.0",
97
+ "typescript": "4.6.3",
98
+ "webpack": "5.71.0",
99
+ "webpack-cli": "4.9.2"
97
100
  },
98
101
  "peerDependencies": {
99
- "react": "^16.8 || ^17",
100
- "react-dom": "^16.8 || ^17",
101
- "react-router-dom": "^5.1"
102
+ "react": "^16.8 || ^17 || ^18",
103
+ "react-dom": "^16.8 || ^17 || ^18",
104
+ "react-router-dom": "^5.1 || ^6"
102
105
  }
103
106
  }
package/CHANGELOG.md DELETED
@@ -1,13 +0,0 @@
1
- # [1.1.0](https://github.com/dimazuien/react-router-scroll-to-top/compare/v1.0.0...v1.1.0) (2020-12-27)
2
-
3
-
4
- ### Features
5
-
6
- * add a hook ([587ce84](https://github.com/dimazuien/react-router-scroll-to-top/commit/587ce8469b62491097541687d38810870abc6ae5))
7
- * add state param that prevents scrolling to top ([a77830c](https://github.com/dimazuien/react-router-scroll-to-top/commit/a77830cef6ca582dad34f9130cb4068cb88c9f83))
8
-
9
-
10
- ### Reverts
11
-
12
- * revert release ([22b05b2](https://github.com/dimazuien/react-router-scroll-to-top/commit/22b05b253534ef1456b3feff5283da3d853d8166))
13
- * revert replacing npm with yarn ([a02ff07](https://github.com/dimazuien/react-router-scroll-to-top/commit/a02ff0735a7915682d81613a561a93abc099b24f))
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- var e=require("react"),t=require("react-router-dom");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(e),n=function(){var r=t.useLocation(),o=r.state;e.useEffect(function(){!1!==(null==o?void 0:o.scrollToTop)&&window.scrollTo(0,0)},[r.pathname,o])};exports.default=function(e){var t=e.children;return n(),o.default.createElement(o.default.Fragment,null,t)},exports.useScrollToTop=n;
2
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/useScrollToTop.tsx","../src/ScrollToTop.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\ntype ScrollToTopState =\n | Readonly<{\n scrollToTop?: boolean;\n }>\n | undefined;\n\nconst useScrollToTop = (): void => {\n const { pathname, state } = useLocation<ScrollToTopState>();\n\n useEffect(() => {\n if (state?.scrollToTop === false) return;\n\n window.scrollTo(0, 0);\n }, [pathname, state]);\n};\n\nexport default useScrollToTop;\n","import React, { FC } from 'react';\nimport useScrollToTop from './useScrollToTop';\n\nconst ScrollToTop: FC = ({ children }) => {\n useScrollToTop();\n\n return <>{children}</>;\n};\n\nexport default ScrollToTop;\n"],"names":["useScrollToTop","useLocation","state","useEffect","scrollToTop","window","scrollTo","pathname","children","React"],"mappings":"wIASMA,EAAiB,iBACOC,gBAAVC,IAAAA,MAElBC,YAAU,YACmB,WAAvBD,SAAAA,EAAOE,cAEXC,OAAOC,SAAS,EAAG,IAClB,GANKC,SAMML,qBCbQ,gBAAGM,IAAAA,SAGzB,OAFAR,IAEOS,gDAAGD"}
@@ -1,2 +0,0 @@
1
- import o,{useEffect as t}from"react";import{useLocation as r}from"react-router-dom";const e=()=>{const{pathname:o,state:e}=r();t(()=>{!1!==(null==e?void 0:e.scrollToTop)&&window.scrollTo(0,0)},[o,e])};export default({children:t})=>(e(),o.createElement(o.Fragment,null,t));export{e as useScrollToTop};
2
- //# sourceMappingURL=index.modern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/useScrollToTop.tsx","../src/ScrollToTop.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\ntype ScrollToTopState =\n | Readonly<{\n scrollToTop?: boolean;\n }>\n | undefined;\n\nconst useScrollToTop = (): void => {\n const { pathname, state } = useLocation<ScrollToTopState>();\n\n useEffect(() => {\n if (state?.scrollToTop === false) return;\n\n window.scrollTo(0, 0);\n }, [pathname, state]);\n};\n\nexport default useScrollToTop;\n","import React, { FC } from 'react';\nimport useScrollToTop from './useScrollToTop';\n\nconst ScrollToTop: FC = ({ children }) => {\n useScrollToTop();\n\n return <>{children}</>;\n};\n\nexport default ScrollToTop;\n"],"names":["useScrollToTop","pathname","state","useLocation","useEffect","scrollToTop","window","scrollTo","children","React"],"mappings":"oFASMA,MAAAA,EAAiB,KACrB,MAAMC,SAAEA,EAAFC,MAAYA,GAAUC,IAE5BC,EAAU,MACmB,WAAvBF,SAAAA,EAAOG,cAEXC,OAAOC,SAAS,EAAG,IAClB,CAACN,EAAUC,mBCbQ,EAAGM,SAAAA,MACzBR,IAEOS,gCAAGD"}
@@ -1,2 +0,0 @@
1
- import r,{useEffect as o}from"react";import{useLocation as t}from"react-router-dom";var e=function(){var r=t(),e=r.state;o(function(){!1!==(null==e?void 0:e.scrollToTop)&&window.scrollTo(0,0)},[r.pathname,e])};export default function(o){var t=o.children;return e(),r.createElement(r.Fragment,null,t)}export{e as useScrollToTop};
2
- //# sourceMappingURL=index.module.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.module.js","sources":["../src/useScrollToTop.tsx","../src/ScrollToTop.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\ntype ScrollToTopState =\n | Readonly<{\n scrollToTop?: boolean;\n }>\n | undefined;\n\nconst useScrollToTop = (): void => {\n const { pathname, state } = useLocation<ScrollToTopState>();\n\n useEffect(() => {\n if (state?.scrollToTop === false) return;\n\n window.scrollTo(0, 0);\n }, [pathname, state]);\n};\n\nexport default useScrollToTop;\n","import React, { FC } from 'react';\nimport useScrollToTop from './useScrollToTop';\n\nconst ScrollToTop: FC = ({ children }) => {\n useScrollToTop();\n\n return <>{children}</>;\n};\n\nexport default ScrollToTop;\n"],"names":["useScrollToTop","useLocation","state","useEffect","scrollToTop","window","scrollTo","pathname","children","React"],"mappings":"oFASMA,IAAAA,EAAiB,iBACOC,IAAVC,IAAAA,MAElBC,EAAU,YACmB,WAAvBD,SAAAA,EAAOE,cAEXC,OAAOC,SAAS,EAAG,IAClB,GANKC,SAMML,oBCbQ,gBAAGM,IAAAA,SAGzB,OAFAR,IAEOS,gCAAGD"}
package/dist/index.umd.js DELETED
@@ -1,2 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-router-dom"],t):t((e||self).reactRouterScrollToTop={},e.react,e.reactRouterDom)}(this,function(e,t,o){function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(t),u=function(){var e=o.useLocation(),r=e.state;t.useEffect(function(){!1!==(null==r?void 0:r.scrollToTop)&&window.scrollTo(0,0)},[e.pathname,r])};e.default=function(e){var t=e.children;return u(),n.default.createElement(n.default.Fragment,null,t)},e.useScrollToTop=u});
2
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/useScrollToTop.tsx","../src/ScrollToTop.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router-dom';\n\ntype ScrollToTopState =\n | Readonly<{\n scrollToTop?: boolean;\n }>\n | undefined;\n\nconst useScrollToTop = (): void => {\n const { pathname, state } = useLocation<ScrollToTopState>();\n\n useEffect(() => {\n if (state?.scrollToTop === false) return;\n\n window.scrollTo(0, 0);\n }, [pathname, state]);\n};\n\nexport default useScrollToTop;\n","import React, { FC } from 'react';\nimport useScrollToTop from './useScrollToTop';\n\nconst ScrollToTop: FC = ({ children }) => {\n useScrollToTop();\n\n return <>{children}</>;\n};\n\nexport default ScrollToTop;\n"],"names":["useScrollToTop","useLocation","state","useEffect","scrollToTop","window","scrollTo","pathname","children","React"],"mappings":"waASMA,EAAiB,iBACOC,gBAAVC,IAAAA,MAElBC,YAAU,YACmB,WAAvBD,SAAAA,EAAOE,cAEXC,OAAOC,SAAS,EAAG,IAClB,GANKC,SAMML,eCbQ,gBAAGM,IAAAA,SAGzB,OAFAR,IAEOS,gDAAGD"}
@@ -1,3 +0,0 @@
1
- import { FC } from 'react';
2
- declare const ScrollToTop: FC;
3
- export default ScrollToTop;
@@ -1,2 +0,0 @@
1
- export { default } from './ScrollToTop';
2
- export { default as useScrollToTop } from './useScrollToTop';
@@ -1,2 +0,0 @@
1
- declare const useScrollToTop: () => void;
2
- export default useScrollToTop;
@@ -1,4 +0,0 @@
1
- import 'github-markdown-css';
2
- import { FC } from 'react';
3
- declare const Demo: FC;
4
- export default Demo;
@@ -1,4 +0,0 @@
1
- import { Meta, Story } from '@storybook/react/types-6-0';
2
- declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
3
- export default _default;
4
- export declare const Demo: Story<import("@storybook/react/types-6-0").Args>;
@@ -1 +0,0 @@
1
- import '@testing-library/jest-dom/extend-expect';
@@ -1 +0,0 @@
1
- import '@testing-library/jest-dom/extend-expect';