react-instantsearch-router-nextjs 7.6.0 → 7.7.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/cjs/index.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createInstantSearchRouterNext = createInstantSearchRouterNext;
7
7
  var _history = _interopRequireDefault(require("instantsearch.js/cjs/lib/routers/history"));
8
+ var _stripLocaleFromUrl = require("./utils/stripLocaleFromUrl");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
10
11
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -62,9 +63,7 @@ function createInstantSearchRouterNext(options) {
62
63
  var nextPathname = new URL(window.location.href).pathname;
63
64
 
64
65
  // We strip the locale from the pathname if it's present
65
- if (singletonRouter.locale) {
66
- nextPathname = nextPathname.replace(previousPathname === '/' ? singletonRouter.locale : "/".concat(singletonRouter.locale), '');
67
- }
66
+ nextPathname = (0, _stripLocaleFromUrl.stripLocaleFromUrl)(nextPathname, singletonRouter.locale, previousPathname !== '/');
68
67
 
69
68
  // We only want to trigger a server request when going back/forward to a different page
70
69
  return previousPathname !== nextPathname;
@@ -88,12 +87,9 @@ function createInstantSearchRouterNext(options) {
88
87
  singletonRouter.beforePopState(ownBeforePopState);
89
88
  },
90
89
  push: function push(newUrl) {
91
- var url = newUrl;
92
- // We need to do this because there's an error when using i18n on the root path
93
- // it says for example `pages/fr.js` doesn't exist
94
- if (singletonRouter.locale) {
95
- url = url.replace("/".concat(singletonRouter.locale), '');
96
- }
90
+ // We need to do this because there's an error when using i18n on the
91
+ // root path it says for example `pages/fr.js` doesn't exist
92
+ var url = (0, _stripLocaleFromUrl.stripLocaleFromUrl)(newUrl, singletonRouter.locale);
97
93
 
98
94
  // No need to provide the second argument, Next.js will know what to do
99
95
  singletonRouter.push(url, undefined, {
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.stripLocaleFromUrl = stripLocaleFromUrl;
7
+ function stripLocaleFromUrl(url, locale) {
8
+ var includePrefixSeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
9
+ if (!locale) {
10
+ return url;
11
+ }
12
+ return url.replace(new RegExp("".concat(includePrefixSeparator ? '/' : '').concat(locale, "(\\/|\\?|$)")), '$1');
13
+ }
package/dist/es/index.js CHANGED
@@ -5,6 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
6
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
7
  import history from "instantsearch.js/es/lib/routers/history.js";
8
+ import { stripLocaleFromUrl } from "./utils/stripLocaleFromUrl.js";
8
9
  export function createInstantSearchRouterNext(options) {
9
10
  var _ref = options || {},
10
11
  beforePopState = _ref.beforePopState,
@@ -55,9 +56,7 @@ export function createInstantSearchRouterNext(options) {
55
56
  var nextPathname = new URL(window.location.href).pathname;
56
57
 
57
58
  // We strip the locale from the pathname if it's present
58
- if (singletonRouter.locale) {
59
- nextPathname = nextPathname.replace(previousPathname === '/' ? singletonRouter.locale : "/".concat(singletonRouter.locale), '');
60
- }
59
+ nextPathname = stripLocaleFromUrl(nextPathname, singletonRouter.locale, previousPathname !== '/');
61
60
 
62
61
  // We only want to trigger a server request when going back/forward to a different page
63
62
  return previousPathname !== nextPathname;
@@ -81,12 +80,9 @@ export function createInstantSearchRouterNext(options) {
81
80
  singletonRouter.beforePopState(ownBeforePopState);
82
81
  },
83
82
  push: function push(newUrl) {
84
- var url = newUrl;
85
- // We need to do this because there's an error when using i18n on the root path
86
- // it says for example `pages/fr.js` doesn't exist
87
- if (singletonRouter.locale) {
88
- url = url.replace("/".concat(singletonRouter.locale), '');
89
- }
83
+ // We need to do this because there's an error when using i18n on the
84
+ // root path it says for example `pages/fr.js` doesn't exist
85
+ var url = stripLocaleFromUrl(newUrl, singletonRouter.locale);
90
86
 
91
87
  // No need to provide the second argument, Next.js will know what to do
92
88
  singletonRouter.push(url, undefined, {
@@ -0,0 +1 @@
1
+ export declare function stripLocaleFromUrl(url: string, locale: string | undefined, includePrefixSeparator?: boolean): string;
@@ -0,0 +1,7 @@
1
+ export function stripLocaleFromUrl(url, locale) {
2
+ var includePrefixSeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
3
+ if (!locale) {
4
+ return url;
5
+ }
6
+ return url.replace(new RegExp("".concat(includePrefixSeparator ? '/' : '').concat(locale, "(\\/|\\?|$)")), '$1');
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-instantsearch-router-nextjs",
3
- "version": "7.6.0",
3
+ "version": "7.7.0",
4
4
  "description": "React InstantSearch Router for Next.js",
5
5
  "types": "dist/es/index.d.ts",
6
6
  "main": "dist/cjs/index.js",
@@ -40,16 +40,18 @@
40
40
  "clean": "rm -rf dist",
41
41
  "build": "yarn build:cjs && yarn build:es && yarn build:types",
42
42
  "build:cjs": "BABEL_ENV=cjs babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/cjs --ignore '**/__tests__/**/*','**/__mocks__/**/*' --quiet && ../../scripts/prepare-cjs.sh",
43
- "build:es": "BABEL_ENV=es babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/es --ignore '**/__tests__/**/*','**/__mocks__/**/*' --quiet",
43
+ "build:es:base": "BABEL_ENV=es babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/es --ignore '**/__tests__/**/*','**/__mocks__/**/*'",
44
+ "build:es": "yarn build:es:base --quiet",
44
45
  "build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/es",
45
46
  "test:exports": "node ./__tests__/module/is-es-module.mjs && node ./__tests__/module/is-cjs-module.cjs",
46
47
  "test:start-server": "yarn workspace example-react-instantsearch-next-routing-example build && yarn workspace example-react-instantsearch-next-routing-example start",
47
48
  "test:e2e": "start-server-and-test test:start-server 3000 'wdio run ./wdio.conf.cjs'",
48
- "test:e2e:saucelabs": "start-server-and-test test:start-server 3000 'wdio run ./wdio.saucelabs.conf.cjs'"
49
+ "test:e2e:saucelabs": "start-server-and-test test:start-server 3000 'wdio run ./wdio.saucelabs.conf.cjs'",
50
+ "watch:es": "yarn --silent build:es:base --watch"
49
51
  },
50
52
  "dependencies": {
51
- "instantsearch.js": "4.65.0",
52
- "react-instantsearch-core": "7.6.0"
53
+ "instantsearch.js": "4.66.0",
54
+ "react-instantsearch-core": "7.7.0"
53
55
  },
54
56
  "devDependencies": {
55
57
  "@types/jasmine": "3.3.16",
@@ -66,5 +68,5 @@
66
68
  "peerDependencies": {
67
69
  "next": ">= 9 && < 15"
68
70
  },
69
- "gitHead": "084aff3d29e15cea8125076c46fb753c83d4dcad"
71
+ "gitHead": "358f849cba15cbbb415da05feb582b47358aa239"
70
72
  }