react-instantsearch-nextjs 0.1.14 → 0.2.1

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.
@@ -10,6 +10,7 @@ var _utils = require("instantsearch.js/cjs/lib/utils");
10
10
  var _navigation = require("next/navigation");
11
11
  var _react = _interopRequireWildcard(require("react"));
12
12
  var _reactInstantsearchCore = require("react-instantsearch-core");
13
+ var _htmlEscape = require("./htmlEscape");
13
14
  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); }
14
15
  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; }
15
16
  var _ref2 = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
@@ -49,7 +50,7 @@ function InitializePromise() {
49
50
  inserted = true;
50
51
  return /*#__PURE__*/_react.default.createElement("script", {
51
52
  dangerouslySetInnerHTML: {
52
- __html: "window[Symbol.for(\"InstantSearchInitialResults\")] = ".concat(JSON.stringify(results))
53
+ __html: "window[Symbol.for(\"InstantSearchInitialResults\")] = ".concat((0, _htmlEscape.htmlEscapeJsonString)(JSON.stringify(results)))
53
54
  }
54
55
  });
55
56
  });
@@ -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,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ESCAPE_REGEX = void 0;
7
+ exports.htmlEscapeJsonString = htmlEscapeJsonString;
8
+ // This file was taken from the Next.js repo : https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/packages/next/src/server/htmlescape.ts
9
+ // License: https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/license.md
10
+
11
+ // This utility is based on https://github.com/zertosh/htmlescape
12
+ // License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
13
+
14
+ var ESCAPE_LOOKUP = {
15
+ '&': "\\u0026",
16
+ '>': "\\u003e",
17
+ '<': "\\u003c",
18
+ "\u2028": "\\u2028",
19
+ "\u2029": "\\u2029"
20
+ };
21
+ var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
22
+ exports.ESCAPE_REGEX = ESCAPE_REGEX;
23
+ function htmlEscapeJsonString(str) {
24
+ return str.replace(ESCAPE_REGEX, function (match) {
25
+ return ESCAPE_LOOKUP[match];
26
+ });
27
+ }
@@ -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
+ }
@@ -3,6 +3,7 @@ import { walkIndex } from "instantsearch.js/es/lib/utils/index.js";
3
3
  import { ServerInsertedHTMLContext } from "next/navigation.js";
4
4
  import React, { useContext } from 'react';
5
5
  import { useInstantSearchContext, useRSCContext, wrapPromiseWithState } from 'react-instantsearch-core';
6
+ import { htmlEscapeJsonString } from "./htmlEscape.js";
6
7
  var _ref2 = /*#__PURE__*/React.createElement(React.Fragment, null);
7
8
  export function InitializePromise() {
8
9
  var _search = useInstantSearchContext();
@@ -40,7 +41,7 @@ export function InitializePromise() {
40
41
  inserted = true;
41
42
  return /*#__PURE__*/React.createElement("script", {
42
43
  dangerouslySetInnerHTML: {
43
- __html: "window[Symbol.for(\"InstantSearchInitialResults\")] = ".concat(JSON.stringify(results))
44
+ __html: "window[Symbol.for(\"InstantSearchInitialResults\")] = ".concat(htmlEscapeJsonString(JSON.stringify(results)))
44
45
  }
45
46
  });
46
47
  });
@@ -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,2 @@
1
+ export declare const ESCAPE_REGEX: RegExp;
2
+ export declare function htmlEscapeJsonString(str: string): string;
@@ -0,0 +1,19 @@
1
+ // This file was taken from the Next.js repo : https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/packages/next/src/server/htmlescape.ts
2
+ // License: https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/license.md
3
+
4
+ // This utility is based on https://github.com/zertosh/htmlescape
5
+ // License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
6
+
7
+ var ESCAPE_LOOKUP = {
8
+ '&': "\\u0026",
9
+ '>': "\\u003e",
10
+ '<': "\\u003c",
11
+ "\u2028": "\\u2028",
12
+ "\u2029": "\\u2029"
13
+ };
14
+ export var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
15
+ export function htmlEscapeJsonString(str) {
16
+ return str.replace(ESCAPE_REGEX, function (match) {
17
+ return ESCAPE_LOOKUP[match];
18
+ });
19
+ }
@@ -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.1.14",
3
+ "version": "0.2.1",
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.0",
52
+ "instantsearch.js": "4.67.0",
53
53
  "next": "13.5.1",
54
- "react-instantsearch-core": "7.7.0"
54
+ "react-instantsearch-core": "7.7.2"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "next": ">= 13.4 && < 15",
58
58
  "react-instantsearch": ">= 7.1.0 && < 8"
59
59
  },
60
- "gitHead": "358f849cba15cbbb415da05feb582b47358aa239"
60
+ "gitHead": "17da3c2268354325cc22103260d944d3e4feff90"
61
61
  }