react-instantsearch-nextjs 0.1.14 → 0.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.
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
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); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.InstantSearchNext = InstantSearchNext;
|
|
7
|
-
var _history = _interopRequireDefault(require("instantsearch.js/cjs/lib/routers/history"));
|
|
8
8
|
var _utils = require("instantsearch.js/cjs/lib/utils");
|
|
9
|
-
var _headers = require("next/headers");
|
|
10
|
-
var _navigation = require("next/navigation");
|
|
11
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
10
|
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
13
11
|
var _InitializePromise = require("./InitializePromise");
|
|
14
12
|
var _TriggerSearch = require("./TriggerSearch");
|
|
13
|
+
var _useInstantSearchRouting = require("./useInstantSearchRouting");
|
|
15
14
|
var _warn = require("./warn");
|
|
16
15
|
var _excluded = ["children", "routing"];
|
|
17
16
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
17
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
18
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
21
|
-
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; }
|
|
22
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
25
|
-
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); }
|
|
26
|
-
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); }
|
|
27
19
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
28
20
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
29
21
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
@@ -33,45 +25,19 @@ function InstantSearchNext(_ref) {
|
|
|
33
25
|
var children = _ref.children,
|
|
34
26
|
passedRouting = _ref.routing,
|
|
35
27
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
36
|
-
var pathname = (0, _navigation.usePathname)();
|
|
37
|
-
var searchParams = (0, _navigation.useSearchParams)();
|
|
38
|
-
var router = (0, _navigation.useRouter)();
|
|
39
28
|
var isMounting = (0, _react.useRef)(true);
|
|
40
29
|
(0, _react.useEffect)(function () {
|
|
41
30
|
isMounting.current = false;
|
|
31
|
+
return function () {
|
|
32
|
+
// This is to make sure that they're not reused if mounting again on a different route
|
|
33
|
+
delete window[InstantSearchInitialResults];
|
|
34
|
+
};
|
|
42
35
|
}, []);
|
|
36
|
+
var routing = (0, _useInstantSearchRouting.useInstantSearchRouting)(passedRouting, isMounting);
|
|
43
37
|
var promiseRef = (0, _react.useRef)(null);
|
|
44
38
|
var initialResults = (0, _utils.safelyRunOnBrowser)(function () {
|
|
45
39
|
return window[InstantSearchInitialResults];
|
|
46
40
|
});
|
|
47
|
-
var routing = passedRouting && {};
|
|
48
|
-
if (routing) {
|
|
49
|
-
var browserHistoryOptions = {};
|
|
50
|
-
browserHistoryOptions.getLocation = function () {
|
|
51
|
-
if (typeof window === 'undefined') {
|
|
52
|
-
var url = "".concat((0, _headers.headers)().get('x-forwarded-proto') || 'http', "://").concat((0, _headers.headers)().get('host')).concat(pathname, "?").concat(searchParams);
|
|
53
|
-
return new URL(url);
|
|
54
|
-
}
|
|
55
|
-
if (isMounting.current) {
|
|
56
|
-
return new URL("".concat(window.location.protocol, "//").concat(window.location.host).concat(pathname, "?").concat(searchParams));
|
|
57
|
-
}
|
|
58
|
-
return window.location;
|
|
59
|
-
};
|
|
60
|
-
browserHistoryOptions.push = function push(url) {
|
|
61
|
-
// This is to skip the push with empty routeState on dispose as it would clear params set on a <Link>
|
|
62
|
-
if (this.isDisposed) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
router.push(url, {
|
|
66
|
-
scroll: false
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
if (_typeof(passedRouting) === 'object') {
|
|
70
|
-
browserHistoryOptions = _objectSpread(_objectSpread({}, browserHistoryOptions), passedRouting.router);
|
|
71
|
-
routing.stateMapping = passedRouting.stateMapping;
|
|
72
|
-
}
|
|
73
|
-
routing.router = (0, _history.default)(browserHistoryOptions);
|
|
74
|
-
}
|
|
75
41
|
process.env.NODE_ENV === 'development' ? (0, _warn.warn)(false, "InstantSearchNext relies on experimental APIs and may break in the future.\nThis message will only be displayed in development mode.") : void 0;
|
|
76
42
|
return /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearchRSCContext.Provider, {
|
|
77
43
|
value: promiseRef
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useInstantSearchRouting = useInstantSearchRouting;
|
|
7
|
+
var _history = _interopRequireDefault(require("instantsearch.js/cjs/lib/routers/history"));
|
|
8
|
+
var _headers = require("next/headers");
|
|
9
|
+
var _navigation = require("next/navigation");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
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; }
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
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); }
|
|
17
|
+
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); }
|
|
18
|
+
function useInstantSearchRouting(passedRouting, isMounting) {
|
|
19
|
+
var pathname = (0, _navigation.usePathname)();
|
|
20
|
+
var searchParams = (0, _navigation.useSearchParams)();
|
|
21
|
+
var router = (0, _navigation.useRouter)();
|
|
22
|
+
var routingRef = (0, _react.useRef)();
|
|
23
|
+
var onUpdateRef = (0, _react.useRef)();
|
|
24
|
+
(0, _react.useEffect)(function () {
|
|
25
|
+
if (onUpdateRef.current) {
|
|
26
|
+
onUpdateRef.current();
|
|
27
|
+
}
|
|
28
|
+
}, [pathname, searchParams]);
|
|
29
|
+
if (passedRouting && !routingRef.current) {
|
|
30
|
+
var browserHistoryOptions = {};
|
|
31
|
+
browserHistoryOptions.getLocation = function () {
|
|
32
|
+
if (typeof window === 'undefined') {
|
|
33
|
+
var url = "".concat((0, _headers.headers)().get('x-forwarded-proto') || 'http', "://").concat((0, _headers.headers)().get('host')).concat(pathname, "?").concat(searchParams);
|
|
34
|
+
return new URL(url);
|
|
35
|
+
}
|
|
36
|
+
if (isMounting.current) {
|
|
37
|
+
return new URL("".concat(window.location.protocol, "//").concat(window.location.host).concat(pathname, "?").concat(searchParams));
|
|
38
|
+
}
|
|
39
|
+
return window.location;
|
|
40
|
+
};
|
|
41
|
+
browserHistoryOptions.push = function push(url) {
|
|
42
|
+
// This is to skip the push with empty routeState on dispose as it would clear params set on a <Link>
|
|
43
|
+
if (this.isDisposed) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
router.push(url, {
|
|
47
|
+
scroll: false
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
browserHistoryOptions.start = function start(onUpdate) {
|
|
51
|
+
onUpdateRef.current = onUpdate;
|
|
52
|
+
};
|
|
53
|
+
routingRef.current = {};
|
|
54
|
+
if (_typeof(passedRouting) === 'object') {
|
|
55
|
+
browserHistoryOptions = _objectSpread(_objectSpread({}, browserHistoryOptions), passedRouting.router);
|
|
56
|
+
routingRef.current.stateMapping = passedRouting.stateMapping;
|
|
57
|
+
}
|
|
58
|
+
routingRef.current.router = (0, _history.default)(browserHistoryOptions);
|
|
59
|
+
}
|
|
60
|
+
return routingRef.current;
|
|
61
|
+
}
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
var _excluded = ["children", "routing"];
|
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
-
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; }
|
|
4
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
-
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); }
|
|
8
|
-
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); }
|
|
9
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
11
|
-
import historyRouter from "instantsearch.js/es/lib/routers/history.js";
|
|
12
5
|
import { safelyRunOnBrowser } from "instantsearch.js/es/lib/utils/index.js";
|
|
13
|
-
import { headers } from "next/headers.js";
|
|
14
|
-
import { usePathname, useSearchParams, useRouter } from "next/navigation.js";
|
|
15
6
|
import React, { useEffect, useRef } from 'react';
|
|
16
7
|
import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRProvider } from 'react-instantsearch-core';
|
|
17
8
|
import { InitializePromise } from "./InitializePromise.js";
|
|
18
9
|
import { TriggerSearch } from "./TriggerSearch.js";
|
|
10
|
+
import { useInstantSearchRouting } from "./useInstantSearchRouting.js";
|
|
19
11
|
import { warn } from "./warn.js";
|
|
20
12
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
21
13
|
var _ref2 = /*#__PURE__*/React.createElement(InitializePromise, null);
|
|
@@ -24,45 +16,19 @@ export function InstantSearchNext(_ref) {
|
|
|
24
16
|
var children = _ref.children,
|
|
25
17
|
passedRouting = _ref.routing,
|
|
26
18
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
27
|
-
var pathname = usePathname();
|
|
28
|
-
var searchParams = useSearchParams();
|
|
29
|
-
var router = useRouter();
|
|
30
19
|
var isMounting = useRef(true);
|
|
31
20
|
useEffect(function () {
|
|
32
21
|
isMounting.current = false;
|
|
22
|
+
return function () {
|
|
23
|
+
// This is to make sure that they're not reused if mounting again on a different route
|
|
24
|
+
delete window[InstantSearchInitialResults];
|
|
25
|
+
};
|
|
33
26
|
}, []);
|
|
27
|
+
var routing = useInstantSearchRouting(passedRouting, isMounting);
|
|
34
28
|
var promiseRef = useRef(null);
|
|
35
29
|
var initialResults = safelyRunOnBrowser(function () {
|
|
36
30
|
return window[InstantSearchInitialResults];
|
|
37
31
|
});
|
|
38
|
-
var routing = passedRouting && {};
|
|
39
|
-
if (routing) {
|
|
40
|
-
var browserHistoryOptions = {};
|
|
41
|
-
browserHistoryOptions.getLocation = function () {
|
|
42
|
-
if (typeof window === 'undefined') {
|
|
43
|
-
var url = "".concat(headers().get('x-forwarded-proto') || 'http', "://").concat(headers().get('host')).concat(pathname, "?").concat(searchParams);
|
|
44
|
-
return new URL(url);
|
|
45
|
-
}
|
|
46
|
-
if (isMounting.current) {
|
|
47
|
-
return new URL("".concat(window.location.protocol, "//").concat(window.location.host).concat(pathname, "?").concat(searchParams));
|
|
48
|
-
}
|
|
49
|
-
return window.location;
|
|
50
|
-
};
|
|
51
|
-
browserHistoryOptions.push = function push(url) {
|
|
52
|
-
// This is to skip the push with empty routeState on dispose as it would clear params set on a <Link>
|
|
53
|
-
if (this.isDisposed) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
router.push(url, {
|
|
57
|
-
scroll: false
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
if (_typeof(passedRouting) === 'object') {
|
|
61
|
-
browserHistoryOptions = _objectSpread(_objectSpread({}, browserHistoryOptions), passedRouting.router);
|
|
62
|
-
routing.stateMapping = passedRouting.stateMapping;
|
|
63
|
-
}
|
|
64
|
-
routing.router = historyRouter(browserHistoryOptions);
|
|
65
|
-
}
|
|
66
32
|
process.env.NODE_ENV === 'development' ? warn(false, "InstantSearchNext relies on experimental APIs and may break in the future.\nThis message will only be displayed in development mode.") : void 0;
|
|
67
33
|
return /*#__PURE__*/React.createElement(InstantSearchRSCContext.Provider, {
|
|
68
34
|
value: promiseRef
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { InstantSearchNextProps } from './InstantSearchNext';
|
|
3
|
+
import type { UiState } from 'instantsearch.js';
|
|
4
|
+
export declare function useInstantSearchRouting<TUiState extends UiState = UiState, TRouteState = TUiState>(passedRouting: InstantSearchNextProps<TUiState, TRouteState>['routing'], isMounting: React.MutableRefObject<boolean>): boolean | import("instantsearch.js/es/middlewares").RouterProps<TUiState, TRouteState> | undefined;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
5
|
+
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); }
|
|
6
|
+
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); }
|
|
7
|
+
import historyRouter from "instantsearch.js/es/lib/routers/history.js";
|
|
8
|
+
import { headers } from "next/headers.js";
|
|
9
|
+
import { usePathname, useSearchParams, useRouter } from "next/navigation.js";
|
|
10
|
+
import { useRef, useEffect } from 'react';
|
|
11
|
+
export function useInstantSearchRouting(passedRouting, isMounting) {
|
|
12
|
+
var pathname = usePathname();
|
|
13
|
+
var searchParams = useSearchParams();
|
|
14
|
+
var router = useRouter();
|
|
15
|
+
var routingRef = useRef();
|
|
16
|
+
var onUpdateRef = useRef();
|
|
17
|
+
useEffect(function () {
|
|
18
|
+
if (onUpdateRef.current) {
|
|
19
|
+
onUpdateRef.current();
|
|
20
|
+
}
|
|
21
|
+
}, [pathname, searchParams]);
|
|
22
|
+
if (passedRouting && !routingRef.current) {
|
|
23
|
+
var browserHistoryOptions = {};
|
|
24
|
+
browserHistoryOptions.getLocation = function () {
|
|
25
|
+
if (typeof window === 'undefined') {
|
|
26
|
+
var url = "".concat(headers().get('x-forwarded-proto') || 'http', "://").concat(headers().get('host')).concat(pathname, "?").concat(searchParams);
|
|
27
|
+
return new URL(url);
|
|
28
|
+
}
|
|
29
|
+
if (isMounting.current) {
|
|
30
|
+
return new URL("".concat(window.location.protocol, "//").concat(window.location.host).concat(pathname, "?").concat(searchParams));
|
|
31
|
+
}
|
|
32
|
+
return window.location;
|
|
33
|
+
};
|
|
34
|
+
browserHistoryOptions.push = function push(url) {
|
|
35
|
+
// This is to skip the push with empty routeState on dispose as it would clear params set on a <Link>
|
|
36
|
+
if (this.isDisposed) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
router.push(url, {
|
|
40
|
+
scroll: false
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
browserHistoryOptions.start = function start(onUpdate) {
|
|
44
|
+
onUpdateRef.current = onUpdate;
|
|
45
|
+
};
|
|
46
|
+
routingRef.current = {};
|
|
47
|
+
if (_typeof(passedRouting) === 'object') {
|
|
48
|
+
browserHistoryOptions = _objectSpread(_objectSpread({}, browserHistoryOptions), passedRouting.router);
|
|
49
|
+
routingRef.current.stateMapping = passedRouting.stateMapping;
|
|
50
|
+
}
|
|
51
|
+
routingRef.current.router = historyRouter(browserHistoryOptions);
|
|
52
|
+
}
|
|
53
|
+
return routingRef.current;
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-instantsearch-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "React InstantSearch SSR utilities for Next.js",
|
|
5
5
|
"types": "dist/es/index.d.ts",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"watch:es": "yarn --silent build:es:base --watch"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"instantsearch.js": "4.66.
|
|
52
|
+
"instantsearch.js": "4.66.1",
|
|
53
53
|
"next": "13.5.1",
|
|
54
|
-
"react-instantsearch-core": "7.7.
|
|
54
|
+
"react-instantsearch-core": "7.7.1"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"next": ">= 13.4 && < 15",
|
|
58
58
|
"react-instantsearch": ">= 7.1.0 && < 8"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "d309ca3333476a842be080fcb01b8be925aad204"
|
|
61
61
|
}
|