Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algolia/recommend-react

Package Overview
Dependencies
Maintainers
84
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/recommend-react - npm Package Compare versions

Comparing version 1.8.1 to 1.8.2

2

dist/esm/FrequentlyBoughtTogether.d.ts
import { GetFrequentlyBoughtTogetherProps } from '@algolia/recommend-core';
import { FrequentlyBoughtTogetherProps as FrequentlyBoughtTogetherVDOMProps } from '@algolia/recommend-vdom';
export declare type FrequentlyBoughtTogetherProps<TObject> = GetFrequentlyBoughtTogetherProps<TObject> & Omit<FrequentlyBoughtTogetherVDOMProps<TObject>, 'items' | 'status'>;
export type FrequentlyBoughtTogetherProps<TObject> = GetFrequentlyBoughtTogetherProps<TObject> & Omit<FrequentlyBoughtTogetherVDOMProps<TObject>, 'items' | 'status' | 'createElement' | 'Fragment'>;
export declare function FrequentlyBoughtTogether<TObject>(props: FrequentlyBoughtTogetherProps<TObject>): JSX.Element;

@@ -5,11 +5,11 @@ import _extends from "@babel/runtime/helpers/extends";

import { useFrequentlyBoughtTogether } from './useFrequentlyBoughtTogether';
var UncontrolledFrequentlyBoughtTogether = createFrequentlyBoughtTogetherComponent({
createElement: createElement,
Fragment: Fragment
const UncontrolledFrequentlyBoughtTogether = createFrequentlyBoughtTogetherComponent({
createElement,
Fragment
});
export function FrequentlyBoughtTogether(props) {
var _useFrequentlyBoughtT = useFrequentlyBoughtTogether(props),
recommendations = _useFrequentlyBoughtT.recommendations,
status = _useFrequentlyBoughtT.status;
const {
recommendations,
status
} = useFrequentlyBoughtTogether(props);
return /*#__PURE__*/React.createElement(UncontrolledFrequentlyBoughtTogether, _extends({}, props, {

@@ -16,0 +16,0 @@ items: recommendations,

import { GetRelatedProductsProps } from '@algolia/recommend-core';
import { RelatedProductsProps as RelatedProductsVDOMProps } from '@algolia/recommend-vdom';
export declare type RelatedProductsProps<TObject> = GetRelatedProductsProps<TObject> & Omit<RelatedProductsVDOMProps<TObject>, 'items' | 'status'>;
export type RelatedProductsProps<TObject> = GetRelatedProductsProps<TObject> & Omit<RelatedProductsVDOMProps<TObject>, 'items' | 'status' | 'createElement' | 'Fragment'>;
export declare function RelatedProducts<TObject>(props: RelatedProductsProps<TObject>): JSX.Element;

@@ -5,11 +5,11 @@ import _extends from "@babel/runtime/helpers/extends";

import { useRelatedProducts } from './useRelatedProducts';
var UncontrolledRelatedProducts = createRelatedProductsComponent({
createElement: createElement,
Fragment: Fragment
const UncontrolledRelatedProducts = createRelatedProductsComponent({
createElement,
Fragment
});
export function RelatedProducts(props) {
var _useRelatedProducts = useRelatedProducts(props),
recommendations = _useRelatedProducts.recommendations,
status = _useRelatedProducts.status;
const {
recommendations,
status
} = useRelatedProducts(props);
return /*#__PURE__*/React.createElement(UncontrolledRelatedProducts, _extends({}, props, {

@@ -16,0 +16,0 @@ items: recommendations,

import { GetTrendingFacetsProps } from '@algolia/recommend-core';
import { TrendingComponentProps as TrendingFacetsVDOMProps } from '@algolia/recommend-vdom';
export declare type TrendingFacetsProps<TObject> = GetTrendingFacetsProps<TObject> & Omit<TrendingFacetsVDOMProps<TObject>, 'items' | 'status'>;
export type TrendingFacetsProps<TObject> = GetTrendingFacetsProps<TObject> & Omit<TrendingFacetsVDOMProps<TObject>, 'items' | 'status' | 'createElement' | 'Fragment'>;
export declare function TrendingFacets<TObject>(props: TrendingFacetsProps<TObject>): JSX.Element;

@@ -5,11 +5,11 @@ import _extends from "@babel/runtime/helpers/extends";

import { useTrendingFacets } from './useTrendingFacets';
var UncontrolledTrendingFacets = createTrendingFacetsComponent({
createElement: createElement,
Fragment: Fragment
const UncontrolledTrendingFacets = createTrendingFacetsComponent({
createElement,
Fragment
});
export function TrendingFacets(props) {
var _useTrendingFacets = useTrendingFacets(props),
recommendations = _useTrendingFacets.recommendations,
status = _useTrendingFacets.status;
const {
recommendations,
status
} = useTrendingFacets(props);
return /*#__PURE__*/React.createElement(UncontrolledTrendingFacets, _extends({}, props, {

@@ -16,0 +16,0 @@ items: recommendations,

import { GetTrendingItemsProps } from '@algolia/recommend-core';
import { TrendingItemsProps as TrendingItemsVDOMProps } from '@algolia/recommend-vdom';
export declare type TrendingItemsProps<TObject> = GetTrendingItemsProps<TObject> & Omit<TrendingItemsVDOMProps<TObject>, 'items' | 'status'>;
export type TrendingItemsProps<TObject> = GetTrendingItemsProps<TObject> & Omit<TrendingItemsVDOMProps<TObject>, 'items' | 'status' | 'createElement' | 'Fragment'>;
export declare function TrendingItems<TObject>(props: TrendingItemsProps<TObject>): JSX.Element;

@@ -5,11 +5,11 @@ import _extends from "@babel/runtime/helpers/extends";

import { useTrendingItems } from './useTrendingItems';
var UncontrolledTrendingItems = createTrendingItemsComponent({
createElement: createElement,
Fragment: Fragment
const UncontrolledTrendingItems = createTrendingItemsComponent({
createElement,
Fragment
});
export function TrendingItems(props) {
var _useTrendingItems = useTrendingItems(props),
recommendations = _useTrendingItems.recommendations,
status = _useTrendingItems.status;
const {
recommendations,
status
} = useTrendingItems(props);
return /*#__PURE__*/React.createElement(UncontrolledTrendingItems, _extends({}, props, {

@@ -16,0 +16,0 @@ items: recommendations,

import { GetRelatedProductsProps } from '@algolia/recommend-core';
declare type UseAlgoliaAgentProps = Pick<GetRelatedProductsProps<any>, 'recommendClient'>;
type UseAlgoliaAgentProps = Pick<GetRelatedProductsProps<any>, 'recommendClient'>;
export declare function useAlgoliaAgent(props: UseAlgoliaAgentProps): void;
export {};
import { useEffect } from 'react';
import { version } from './version';
export function useAlgoliaAgent(props) {
useEffect(function () {
useEffect(() => {
props.recommendClient.addAlgoliaAgent('recommend-react', version);
}, [props.recommendClient]);
}
import { GetFrequentlyBoughtTogetherProps } from '@algolia/recommend-core';
export declare type UseFrequentlyBoughtTogetherProps<TObject> = GetFrequentlyBoughtTogetherProps<TObject>;
export type UseFrequentlyBoughtTogetherProps<TObject> = GetFrequentlyBoughtTogetherProps<TObject>;
export declare function useFrequentlyBoughtTogether<TObject>({ indexName, maxRecommendations, objectIDs: userObjectIDs, queryParameters: userQueryParameters, recommendClient, threshold, transformItems: userTransformItems, }: UseFrequentlyBoughtTogetherProps<TObject>): {

@@ -4,0 +4,0 @@ status: import("@algolia/recommend-vdom").RecommendStatus;

@@ -1,8 +0,1 @@

import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { getFrequentlyBoughtTogether } from '@algolia/recommend-core';

@@ -13,42 +6,38 @@ import { useEffect, useRef, useState } from 'react';

import { useStatus } from './useStatus';
export function useFrequentlyBoughtTogether(_ref) {
var indexName = _ref.indexName,
maxRecommendations = _ref.maxRecommendations,
userObjectIDs = _ref.objectIDs,
userQueryParameters = _ref.queryParameters,
recommendClient = _ref.recommendClient,
threshold = _ref.threshold,
userTransformItems = _ref.transformItems;
var _useState = useState({
export function useFrequentlyBoughtTogether({
indexName,
maxRecommendations,
objectIDs: userObjectIDs,
queryParameters: userQueryParameters,
recommendClient,
threshold,
transformItems: userTransformItems
}) {
const [result, setResult] = useState({
recommendations: []
}),
_useState2 = _slicedToArray(_useState, 2),
result = _useState2[0],
setResult = _useState2[1];
var _useStatus = useStatus('loading'),
status = _useStatus.status,
setStatus = _useStatus.setStatus;
var objectIDs = useStableValue(userObjectIDs);
var queryParameters = useStableValue(userQueryParameters);
});
const {
status,
setStatus
} = useStatus('loading');
const objectIDs = useStableValue(userObjectIDs);
const queryParameters = useStableValue(userQueryParameters);
useAlgoliaAgent({
recommendClient: recommendClient
recommendClient
});
var transformItemsRef = useRef(userTransformItems);
useEffect(function () {
const transformItemsRef = useRef(userTransformItems);
useEffect(() => {
transformItemsRef.current = userTransformItems;
}, [userTransformItems]);
useEffect(function () {
useEffect(() => {
setStatus('loading');
getFrequentlyBoughtTogether({
indexName: indexName,
maxRecommendations: maxRecommendations,
objectIDs: objectIDs,
queryParameters: queryParameters,
recommendClient: recommendClient,
threshold: threshold,
indexName,
maxRecommendations,
objectIDs,
queryParameters,
recommendClient,
threshold,
transformItems: transformItemsRef.current
}).then(function (response) {
}).then(response => {
setResult(response);

@@ -58,5 +47,6 @@ setStatus('idle');

}, [indexName, maxRecommendations, objectIDs, queryParameters, recommendClient, setStatus, threshold]);
return _objectSpread(_objectSpread({}, result), {}, {
status: status
});
return {
...result,
status
};
}
import { GetRecommendationsProps } from '@algolia/recommend-core';
export declare type UseRecommendationsProps<TObject> = GetRecommendationsProps<TObject>;
export type UseRecommendationsProps<TObject> = GetRecommendationsProps<TObject>;
export declare function useRecommendations<TObject>({ fallbackParameters: userFallbackParameters, indexName, maxRecommendations, model, objectIDs: userObjectIDs, queryParameters: userQueryParameters, recommendClient, threshold, transformItems: userTransformItems, }: UseRecommendationsProps<TObject>): {

@@ -4,0 +4,0 @@ status: import("@algolia/recommend-vdom").RecommendStatus;

@@ -1,8 +0,1 @@

import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { getRecommendations } from '@algolia/recommend-core';

@@ -13,47 +6,43 @@ import { useEffect, useRef, useState } from 'react';

import { useStatus } from './useStatus';
export function useRecommendations(_ref) {
var userFallbackParameters = _ref.fallbackParameters,
indexName = _ref.indexName,
maxRecommendations = _ref.maxRecommendations,
model = _ref.model,
userObjectIDs = _ref.objectIDs,
userQueryParameters = _ref.queryParameters,
recommendClient = _ref.recommendClient,
threshold = _ref.threshold,
userTransformItems = _ref.transformItems;
var _useState = useState({
export function useRecommendations({
fallbackParameters: userFallbackParameters,
indexName,
maxRecommendations,
model,
objectIDs: userObjectIDs,
queryParameters: userQueryParameters,
recommendClient,
threshold,
transformItems: userTransformItems
}) {
const [result, setResult] = useState({
recommendations: []
}),
_useState2 = _slicedToArray(_useState, 2),
result = _useState2[0],
setResult = _useState2[1];
var _useStatus = useStatus('loading'),
status = _useStatus.status,
setStatus = _useStatus.setStatus;
var objectIDs = useStableValue(userObjectIDs);
var queryParameters = useStableValue(userQueryParameters);
var fallbackParameters = useStableValue(userFallbackParameters);
});
const {
status,
setStatus
} = useStatus('loading');
const objectIDs = useStableValue(userObjectIDs);
const queryParameters = useStableValue(userQueryParameters);
const fallbackParameters = useStableValue(userFallbackParameters);
useAlgoliaAgent({
recommendClient: recommendClient
recommendClient
});
var transformItemsRef = useRef(userTransformItems);
useEffect(function () {
const transformItemsRef = useRef(userTransformItems);
useEffect(() => {
transformItemsRef.current = userTransformItems;
}, [userTransformItems]);
useEffect(function () {
useEffect(() => {
setStatus('loading');
getRecommendations({
fallbackParameters: fallbackParameters,
indexName: indexName,
maxRecommendations: maxRecommendations,
model: model,
objectIDs: objectIDs,
queryParameters: queryParameters,
recommendClient: recommendClient,
threshold: threshold,
fallbackParameters,
indexName,
maxRecommendations,
model,
objectIDs,
queryParameters,
recommendClient,
threshold,
transformItems: transformItemsRef.current
}).then(function (response) {
}).then(response => {
setResult(response);

@@ -63,5 +52,6 @@ setStatus('idle');

}, [fallbackParameters, indexName, maxRecommendations, model, objectIDs, queryParameters, recommendClient, setStatus, threshold]);
return _objectSpread(_objectSpread({}, result), {}, {
status: status
});
return {
...result,
status
};
}
import { GetRelatedProductsProps } from '@algolia/recommend-core';
export declare type UseRelatedProductsProps<TObject> = GetRelatedProductsProps<TObject>;
export type UseRelatedProductsProps<TObject> = GetRelatedProductsProps<TObject>;
export declare function useRelatedProducts<TObject>({ fallbackParameters: userFallbackParameters, indexName, maxRecommendations, objectIDs: userObjectIDs, queryParameters: userQueryParameters, recommendClient, threshold, transformItems: userTransformItems, }: UseRelatedProductsProps<TObject>): {

@@ -4,0 +4,0 @@ status: import("@algolia/recommend-vdom").RecommendStatus;

@@ -1,8 +0,1 @@

import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { getRelatedProducts } from '@algolia/recommend-core';

@@ -13,45 +6,41 @@ import { useEffect, useRef, useState } from 'react';

import { useStatus } from './useStatus';
export function useRelatedProducts(_ref) {
var userFallbackParameters = _ref.fallbackParameters,
indexName = _ref.indexName,
maxRecommendations = _ref.maxRecommendations,
userObjectIDs = _ref.objectIDs,
userQueryParameters = _ref.queryParameters,
recommendClient = _ref.recommendClient,
threshold = _ref.threshold,
userTransformItems = _ref.transformItems;
var _useState = useState({
export function useRelatedProducts({
fallbackParameters: userFallbackParameters,
indexName,
maxRecommendations,
objectIDs: userObjectIDs,
queryParameters: userQueryParameters,
recommendClient,
threshold,
transformItems: userTransformItems
}) {
const [result, setResult] = useState({
recommendations: []
}),
_useState2 = _slicedToArray(_useState, 2),
result = _useState2[0],
setResult = _useState2[1];
var _useStatus = useStatus('loading'),
status = _useStatus.status,
setStatus = _useStatus.setStatus;
var objectIDs = useStableValue(userObjectIDs);
var queryParameters = useStableValue(userQueryParameters);
var fallbackParameters = useStableValue(userFallbackParameters);
});
const {
status,
setStatus
} = useStatus('loading');
const objectIDs = useStableValue(userObjectIDs);
const queryParameters = useStableValue(userQueryParameters);
const fallbackParameters = useStableValue(userFallbackParameters);
useAlgoliaAgent({
recommendClient: recommendClient
recommendClient
});
var transformItemsRef = useRef(userTransformItems);
useEffect(function () {
const transformItemsRef = useRef(userTransformItems);
useEffect(() => {
transformItemsRef.current = userTransformItems;
}, [userTransformItems]);
useEffect(function () {
useEffect(() => {
setStatus('loading');
getRelatedProducts({
fallbackParameters: fallbackParameters,
indexName: indexName,
maxRecommendations: maxRecommendations,
objectIDs: objectIDs,
queryParameters: queryParameters,
recommendClient: recommendClient,
threshold: threshold,
fallbackParameters,
indexName,
maxRecommendations,
objectIDs,
queryParameters,
recommendClient,
threshold,
transformItems: transformItemsRef.current
}).then(function (response) {
}).then(response => {
setResult(response);

@@ -61,5 +50,6 @@ setStatus('idle');

}, [fallbackParameters, indexName, maxRecommendations, objectIDs, queryParameters, recommendClient, setStatus, threshold]);
return _objectSpread(_objectSpread({}, result), {}, {
status: status
});
return {
...result,
status
};
}

@@ -1,20 +0,14 @@

import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import { dequal } from 'dequal/lite';
import { useEffect, useState } from 'react';
export function useStableValue(value) {
var _useState = useState(function () {
return value;
}),
_useState2 = _slicedToArray(_useState, 2),
stableValue = _useState2[0],
setStableValue = _useState2[1];
useEffect(function () {
const [stableValue, setStableValue] = useState(() => value);
useEffect(() => {
if (dequal(stableValue, value) === false) {
setStableValue(value);
} // We only want to trigger the effect when `value` changes.
}
// We only want to trigger the effect when `value` changes.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]);
return stableValue;
}

@@ -1,20 +0,14 @@

import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import { useEffect, useRef, useState } from 'react'; // If you update this logic, please also update the implementation in the
import { useEffect, useRef, useState } from 'react';
// If you update this logic, please also update the implementation in the
// `recommend-js` package.
export function useStatus(initialStatus) {
var timerId = useRef(undefined);
var _useState = useState(initialStatus),
_useState2 = _slicedToArray(_useState, 2),
status = _useState2[0],
setStatus = _useState2[1];
useEffect(function () {
const timerId = useRef(undefined);
const [status, setStatus] = useState(initialStatus);
useEffect(() => {
if (status !== 'stalled' && timerId.current) {
clearTimeout(timerId.current);
}
if (status === 'loading') {
timerId.current = setTimeout(function () {
timerId.current = setTimeout(() => {
setStatus('stalled');

@@ -25,5 +19,5 @@ }, 300);

return {
status: status,
setStatus: setStatus
status,
setStatus
};
}
import { GetTrendingFacetsProps } from '@algolia/recommend-core';
export declare type UseTrendingFacetsProps<TObject> = GetTrendingFacetsProps<TObject>;
export type UseTrendingFacetsProps<TObject> = GetTrendingFacetsProps<TObject>;
export declare function useTrendingFacets<TObject>({ indexName, maxRecommendations, recommendClient, threshold, transformItems: userTransformItems, facetName, }: UseTrendingFacetsProps<TObject>): {

@@ -4,0 +4,0 @@ status: import("@algolia/recommend-vdom").RecommendStatus;

@@ -1,8 +0,1 @@

import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { getTrendingFacets } from '@algolia/recommend-core';

@@ -12,38 +5,34 @@ import { useEffect, useRef, useState } from 'react';

import { useStatus } from './useStatus';
export function useTrendingFacets(_ref) {
var indexName = _ref.indexName,
maxRecommendations = _ref.maxRecommendations,
recommendClient = _ref.recommendClient,
threshold = _ref.threshold,
userTransformItems = _ref.transformItems,
facetName = _ref.facetName;
var _useState = useState({
export function useTrendingFacets({
indexName,
maxRecommendations,
recommendClient,
threshold,
transformItems: userTransformItems,
facetName
}) {
const [result, setResult] = useState({
recommendations: []
}),
_useState2 = _slicedToArray(_useState, 2),
result = _useState2[0],
setResult = _useState2[1];
var _useStatus = useStatus('loading'),
status = _useStatus.status,
setStatus = _useStatus.setStatus;
});
const {
status,
setStatus
} = useStatus('loading');
useAlgoliaAgent({
recommendClient: recommendClient
recommendClient
});
var transformItemsRef = useRef(userTransformItems);
useEffect(function () {
const transformItemsRef = useRef(userTransformItems);
useEffect(() => {
transformItemsRef.current = userTransformItems;
}, [userTransformItems]);
useEffect(function () {
useEffect(() => {
setStatus('loading');
getTrendingFacets({
recommendClient: recommendClient,
recommendClient,
transformItems: transformItemsRef.current,
indexName: indexName,
maxRecommendations: maxRecommendations,
threshold: threshold,
facetName: facetName
}).then(function (response) {
indexName,
maxRecommendations,
threshold,
facetName
}).then(response => {
setResult(response);

@@ -53,5 +42,6 @@ setStatus('idle');

}, [indexName, maxRecommendations, recommendClient, setStatus, threshold, facetName]);
return _objectSpread(_objectSpread({}, result), {}, {
status: status
});
return {
...result,
status
};
}
import { GetTrendingItemsProps } from '@algolia/recommend-core';
export declare type UseTrendingItemsProps<TObject> = GetTrendingItemsProps<TObject>;
export type UseTrendingItemsProps<TObject> = GetTrendingItemsProps<TObject>;
export declare function useTrendingItems<TObject>({ fallbackParameters: userFallbackParameters, indexName, maxRecommendations, queryParameters: userQueryParameters, recommendClient, threshold, transformItems: userTransformItems, facetName, facetValue, }: UseTrendingItemsProps<TObject>): {

@@ -4,0 +4,0 @@ status: import("@algolia/recommend-vdom").RecommendStatus;

@@ -1,8 +0,1 @@

import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { getTrendingItems } from '@algolia/recommend-core';

@@ -13,46 +6,42 @@ import { useEffect, useRef, useState } from 'react';

import { useStatus } from './useStatus';
export function useTrendingItems(_ref) {
var userFallbackParameters = _ref.fallbackParameters,
indexName = _ref.indexName,
maxRecommendations = _ref.maxRecommendations,
userQueryParameters = _ref.queryParameters,
recommendClient = _ref.recommendClient,
threshold = _ref.threshold,
userTransformItems = _ref.transformItems,
facetName = _ref.facetName,
facetValue = _ref.facetValue;
var _useState = useState({
export function useTrendingItems({
fallbackParameters: userFallbackParameters,
indexName,
maxRecommendations,
queryParameters: userQueryParameters,
recommendClient,
threshold,
transformItems: userTransformItems,
facetName,
facetValue
}) {
const [result, setResult] = useState({
recommendations: []
}),
_useState2 = _slicedToArray(_useState, 2),
result = _useState2[0],
setResult = _useState2[1];
var _useStatus = useStatus('loading'),
status = _useStatus.status,
setStatus = _useStatus.setStatus;
var queryParameters = useStableValue(userQueryParameters);
var fallbackParameters = useStableValue(userFallbackParameters);
});
const {
status,
setStatus
} = useStatus('loading');
const queryParameters = useStableValue(userQueryParameters);
const fallbackParameters = useStableValue(userFallbackParameters);
useAlgoliaAgent({
recommendClient: recommendClient
recommendClient
});
var transformItemsRef = useRef(userTransformItems);
useEffect(function () {
const transformItemsRef = useRef(userTransformItems);
useEffect(() => {
transformItemsRef.current = userTransformItems;
}, [userTransformItems]);
useEffect(function () {
useEffect(() => {
setStatus('loading');
getTrendingItems({
recommendClient: recommendClient,
recommendClient,
transformItems: transformItemsRef.current,
fallbackParameters: fallbackParameters,
indexName: indexName,
maxRecommendations: maxRecommendations,
queryParameters: queryParameters,
threshold: threshold,
facetName: facetName,
facetValue: facetValue
}).then(function (response) {
fallbackParameters,
indexName,
maxRecommendations,
queryParameters,
threshold,
facetName,
facetValue
}).then(response => {
setResult(response);

@@ -62,5 +51,6 @@ setStatus('idle');

}, [fallbackParameters, indexName, maxRecommendations, queryParameters, recommendClient, setStatus, threshold, facetName, facetValue]);
return _objectSpread(_objectSpread({}, result), {}, {
status: status
});
return {
...result,
status
};
}

@@ -1,1 +0,1 @@

export declare const version = "1.8.1";
export declare const version = "1.8.2";

@@ -1,1 +0,1 @@

export var version = '1.8.1';
export const version = '1.8.2';

@@ -1,3 +0,3 @@

/*! @algolia/recommend-react 1.8.1 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/recommend */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/recommend-react"]={},e.React)}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(t);function o(){return o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o.apply(this,arguments)}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.filter(Boolean).join(" ")}function i(e){var t=e.createElement,n=e.Fragment;return function(e){return 0===e.recommendations.length&&"idle"===e.status?t(e.Fallback,null):t("section",{className:c("auc-Recommend",e.classNames.root)},t(e.Header,{classNames:e.classNames,recommendations:e.recommendations,translations:e.translations,createElement:t,Fragment:n}),t(e.View,null))}}function s(e){var t=e.createElement;return function(e){return!e.recommendations||e.recommendations.length<1?null:e.translations.title?t("h3",{className:c("auc-Recommend-title",e.classNames.title)},e.translations.title):null}}function m(e){var t=e.createElement,n=e.Fragment;return function(e){return t("div",{className:c("auc-Recommend-container",e.classNames.container)},t("ol",{className:c("auc-Recommend-list",e.classNames.list)},e.items.map((function(r){return t("li",{key:r.objectID,className:c("auc-Recommend-item",e.classNames.item)},t(e.itemComponent,{createElement:t,Fragment:n,item:r}))}))))}}function u(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function f(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function p(e,t){if(e){if("string"==typeof e)return b(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?b(e,t):void 0}}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,a=[],c=!0,i=!1;try{for(n=n.call(e);!(c=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);c=!0);}catch(e){i=!0,o=e}finally{try{c||null==n.return||n.return()}finally{if(i)throw o}}return a}}(e,t)||p(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e){var t=e.hits,n=e.maxRecommendations,r=e.nrOfObjs,o={};t.forEach((function(e){e.forEach((function(e,t){o[e.objectID]?o[e.objectID]={indexSum:o[e.objectID].indexSum+t,nr:o[e.objectID].nr+1}:o[e.objectID]={indexSum:t,nr:1}}))}));var a=function(e,t){for(var n=[],r=0,o=Object.keys(e);r<o.length;r++){var a=o[r];e[a].nr<2&&(e[a].indexSum+=100),n.push({objectID:a,avgOfIndices:e[a].indexSum/t})}return n.sort((function(e,t){return e.avgOfIndices>t.avgOfIndices?1:-1}))}(o,r);return a.reduce((function(e,n){var r=t.flat().find((function(e){return e.objectID===n.objectID}));return r?e.concat(r):e}),[]).slice(0,n&&n>0?n:void 0)}function y(e){return function(e){if(Array.isArray(e))return b(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||p(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e){var t,n,r,o=e.hits,a=e.maxRecommendations;return(t=function(e,t){return(e._score||0)>(t._score||0)?-1:1},n=o,r=y(n),r.sort(t),r).slice(0,a&&a>0?a:void 0)}var j="1.8.1";function v(e){t.useEffect((function(){e.recommendClient.addAlgoliaAgent("recommend-react","1.8.1")}),[e.recommendClient])}var P=Object.prototype.hasOwnProperty;function E(e,t){var n,r;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((r=e.length)===t.length)for(;r--&&E(e[r],t[r]););return-1===r}if(!n||"object"==typeof e){for(n in r=0,e){if(P.call(e,n)&&++r&&!P.call(t,n))return!1;if(!(n in t)||!E(e[n],t[n]))return!1}return Object.keys(t).length===r}}return e!=e&&t!=t}function w(e){var n=g(t.useState((function(){return e})),2),r=n[0],o=n[1];return t.useEffect((function(){!1===E(r,e)&&o(e)}),[e]),r}function D(e){var n=t.useRef(void 0),r=g(t.useState(e),2),o=r[0],a=r[1];return t.useEffect((function(){"stalled"!==o&&n.current&&clearTimeout(n.current),"loading"===o&&(n.current=setTimeout((function(){a("stalled")}),300))}),[o]),{status:o,setStatus:a}}function N(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function x(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?N(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):N(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function F(e){var n=e.indexName,r=e.maxRecommendations,o=e.objectIDs,a=e.queryParameters,c=e.recommendClient,i=e.threshold,s=e.transformItems,m=g(t.useState({recommendations:[]}),2),u=m[0],l=m[1],f=D("loading"),d=f.status,b=f.setStatus,p=w(o),y=w(a);v({recommendClient:c});var h=t.useRef(s);return t.useEffect((function(){h.current=s}),[s]),t.useEffect((function(){b("loading"),function(e){var t=e.objectIDs,n=e.recommendClient,r=e.transformItems,o=void 0===r?function(e){return e}:r,a=e.indexName,c=e.maxRecommendations,i=e.queryParameters,s=e.threshold,m=t.map((function(e){return{indexName:a,maxRecommendations:c,objectID:e,queryParameters:i,threshold:s}}));return n.addAlgoliaAgent("recommend-core",j),n.getFrequentlyBoughtTogether(m).then((function(e){return O({maxRecommendations:c,hits:e.results.map((function(e){return e.hits})),nrOfObjs:t.length})})).then((function(e){return{recommendations:o(e)}}))}({indexName:n,maxRecommendations:r,objectIDs:p,queryParameters:y,recommendClient:c,threshold:i,transformItems:h.current}).then((function(e){l(e),b("idle")}))}),[n,r,p,y,c,b,i]),x(x({},u),{},{status:d})}var R,I,S,C=(R={createElement:t.createElement,Fragment:t.Fragment},I=R.createElement,S=R.Fragment,function(e){var t,n,r,c,l,f=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?u(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({title:"Frequently bought together",sliderLabel:"Frequently bought together products"},e.translations),d=null!==(t=e.classNames)&&void 0!==t?t:{},b=null!==(n=e.children)&&void 0!==n?n:i({createElement:I,Fragment:S}),p=null!==(r=e.fallbackComponent)&&void 0!==r?r:function(){return null},g=null!==(c=e.headerComponent)&&void 0!==c?c:s({createElement:I,Fragment:S}),O=null!==(l=e.view)&&void 0!==l?l:m({createElement:I,Fragment:S});return b({classNames:d,Fallback:function(){return I(p,{Fragment:S,createElement:I})},Header:g,recommendations:e.items,status:e.status,translations:f,View:function(t){return I(O,o({classNames:d,itemComponent:e.itemComponent,items:e.items,translations:f,Fragment:S,createElement:I},t))}})});function k(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function A(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?k(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):k(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function q(e){var n=e.fallbackParameters,r=e.indexName,o=e.maxRecommendations,a=e.objectIDs,c=e.queryParameters,i=e.recommendClient,s=e.threshold,m=e.transformItems,u=g(t.useState({recommendations:[]}),2),l=u[0],f=u[1],d=D("loading"),b=d.status,p=d.setStatus,y=w(a),h=w(c),P=w(n);v({recommendClient:i});var E=t.useRef(m);return t.useEffect((function(){E.current=m}),[m]),t.useEffect((function(){p("loading"),function(e){var t=e.objectIDs,n=e.recommendClient,r=e.transformItems,o=void 0===r?function(e){return e}:r,a=e.fallbackParameters,c=e.indexName,i=e.maxRecommendations,s=e.queryParameters,m=e.threshold,u=t.map((function(e){return{fallbackParameters:a,indexName:c,maxRecommendations:i,objectID:e,queryParameters:s,threshold:m}}));return n.addAlgoliaAgent("recommend-core",j),n.getRelatedProducts(u).then((function(e){return O({maxRecommendations:i,hits:e.results.map((function(e){return e.hits})),nrOfObjs:t.length})})).then((function(e){return{recommendations:o(e)}}))}({fallbackParameters:P,indexName:r,maxRecommendations:o,objectIDs:y,queryParameters:h,recommendClient:i,threshold:s,transformItems:E.current}).then((function(e){f(e),p("idle")}))}),[P,r,o,y,h,i,p,s]),A(A({},l),{},{status:b})}var T=function(e){var t=e.createElement,n=e.Fragment;return function(e){var r,c,u,f,d,b=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({title:"Related products",sliderLabel:"Related products"},e.translations),p=null!==(r=e.classNames)&&void 0!==r?r:{},g=null!==(c=e.children)&&void 0!==c?c:i({createElement:t,Fragment:n}),O=null!==(u=e.fallbackComponent)&&void 0!==u?u:function(){return null},y=null!==(f=e.headerComponent)&&void 0!==f?f:s({createElement:t,Fragment:n}),h=null!==(d=e.view)&&void 0!==d?d:m({createElement:t,Fragment:n});return g({classNames:p,Fallback:function(){return t(O,{Fragment:n,createElement:t})},Header:y,recommendations:e.items,status:e.status,translations:b,View:function(r){return t(h,o({classNames:p,itemComponent:e.itemComponent,items:e.items,translations:b,Fragment:n,createElement:t},r))}})}}({createElement:t.createElement,Fragment:t.Fragment});function V(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function H(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?V(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):V(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function B(e){var n=e.indexName,r=e.maxRecommendations,o=e.recommendClient,a=e.threshold,c=e.transformItems,i=e.facetName,s=g(t.useState({recommendations:[]}),2),m=s[0],u=s[1],l=D("loading"),f=l.status,d=l.setStatus;v({recommendClient:o});var b=t.useRef(c);return t.useEffect((function(){b.current=c}),[c]),t.useEffect((function(){d("loading"),function(e){var t=e.recommendClient,n=e.transformItems,r=void 0===n?function(e){return e}:n,o=e.indexName,a=e.maxRecommendations,c=e.threshold,i=e.facetName,s={indexName:o,maxRecommendations:a,threshold:c,facetName:i};return t.addAlgoliaAgent("recommend-core",j),t.getTrendingFacets([s]).then((function(e){return h({maxRecommendations:a,hits:e.results.map((function(e){return e.hits})).flat()})})).then((function(e){return{recommendations:r(e)}}))}({recommendClient:o,transformItems:b.current,indexName:n,maxRecommendations:r,threshold:a,facetName:i}).then((function(e){u(e),d("idle")}))}),[n,r,o,d,a,i]),H(H({},m),{},{status:f})}var L=function(e){var t=e.createElement,n=e.Fragment;return function(e){var r,m,u,l,d,b=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?f(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({title:"Trending facets",sliderLabel:"Trending facets"},e.translations),p=null!==(r=e.classNames)&&void 0!==r?r:{},g=null!==(m=e.children)&&void 0!==m?m:i({createElement:t,Fragment:n}),O=null!==(u=e.fallbackComponent)&&void 0!==u?u:function(){return null},y=null!==(l=e.headerComponent)&&void 0!==l?l:s({createElement:t,Fragment:n}),h=null!==(d=e.view)&&void 0!==d?d:function(e){var t=e.createElement,n=e.Fragment;return function(e){return t("div",{className:c("auc-Recommend-container",e.classNames.container)},t("ol",{className:c("auc-Recommend-list",e.classNames.list)},e.items.map((function(r){return t("li",{key:r.facetValue,className:c("auc-Recommend-item",e.classNames.item)},t(e.itemComponent,{createElement:t,Fragment:n,item:r}))}))))}}({createElement:t,Fragment:n});return g({classNames:p,Fallback:function(){return t(O,{Fragment:n,createElement:t})},Header:y,recommendations:e.items,status:e.status,translations:b,View:function(r){return t(h,o({classNames:p,itemComponent:e.itemComponent,items:e.items,translations:b,Fragment:n,createElement:t},r))}})}}({createElement:t.createElement,Fragment:t.Fragment});function _(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function M(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?_(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function U(e){var n=e.fallbackParameters,r=e.indexName,o=e.maxRecommendations,a=e.queryParameters,c=e.recommendClient,i=e.threshold,s=e.transformItems,m=e.facetName,u=e.facetValue,l=g(t.useState({recommendations:[]}),2),f=l[0],d=l[1],b=D("loading"),p=b.status,O=b.setStatus,P=w(a),E=w(n);v({recommendClient:c});var N=t.useRef(s);return t.useEffect((function(){N.current=s}),[s]),t.useEffect((function(){O("loading"),function(e){var t=e.recommendClient,n=e.transformItems,r=void 0===n?function(e){return e}:n,o=e.fallbackParameters,a=e.indexName,c=e.maxRecommendations,i=e.queryParameters,s=e.threshold,m=e.facetName,u=e.facetValue,l={fallbackParameters:o,indexName:a,maxRecommendations:c,queryParameters:i,threshold:s,facetName:m,facetValue:u};return t.addAlgoliaAgent("recommend-core",j),t.getTrendingItems([l]).then((function(e){return h({maxRecommendations:c,hits:(t="objectID",n=e.results.map((function(e){return e.hits})).flat(),y(new Map(n.map((function(e){return[e[t],e]}))).values()))});var t,n})).then((function(e){return{recommendations:r(e)}}))}({recommendClient:c,transformItems:N.current,fallbackParameters:E,indexName:r,maxRecommendations:o,queryParameters:P,threshold:i,facetName:m,facetValue:u}).then((function(e){d(e),O("idle")}))}),[E,r,o,P,c,O,i,m,u]),M(M({},f),{},{status:p})}var $=function(e){var t=e.createElement,n=e.Fragment;return function(e){var r,c,u,l,f,b=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({title:"Trending items",sliderLabel:"Trending items"},e.translations),p=null!==(r=e.classNames)&&void 0!==r?r:{},g=null!==(c=e.children)&&void 0!==c?c:i({createElement:t,Fragment:n}),O=null!==(u=e.fallbackComponent)&&void 0!==u?u:function(){return null},y=null!==(l=e.headerComponent)&&void 0!==l?l:s({createElement:t,Fragment:n}),h=null!==(f=e.view)&&void 0!==f?f:m({createElement:t,Fragment:n});return g({classNames:p,Fallback:function(){return t(O,{Fragment:n,createElement:t})},Header:y,recommendations:e.items,status:e.status,translations:b,View:function(r){return t(h,o({classNames:p,itemComponent:e.itemComponent,items:e.items,translations:b,Fragment:n,createElement:t},r))}})}}({createElement:t.createElement,Fragment:t.Fragment});function z(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function G(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?z(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):z(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}e.FrequentlyBoughtTogether=function(e){var t=F(e),n=t.recommendations,a=t.status;return r.default.createElement(C,o({},e,{items:n,status:a}))},e.RelatedProducts=function(e){var t=q(e),n=t.recommendations,a=t.status;return r.default.createElement(T,o({},e,{items:n,status:a}))},e.TrendingFacets=function(e){var t=B(e),n=t.recommendations,a=t.status;return r.default.createElement(L,o({},e,{items:n,status:a}))},e.TrendingItems=function(e){var t=U(e),n=t.recommendations,a=t.status;return r.default.createElement($,o({},e,{items:n,status:a}))},e.useFrequentlyBoughtTogether=F,e.useRecommendations=function(e){var n=e.fallbackParameters,r=e.indexName,o=e.maxRecommendations,a=e.model,c=e.objectIDs,i=e.queryParameters,s=e.recommendClient,m=e.threshold,u=e.transformItems,l=g(t.useState({recommendations:[]}),2),f=l[0],d=l[1],b=D("loading"),p=b.status,y=b.setStatus,h=w(c),P=w(i),E=w(n);v({recommendClient:s});var N=t.useRef(u);return t.useEffect((function(){N.current=u}),[u]),t.useEffect((function(){y("loading"),function(e){var t=e.objectIDs,n=e.recommendClient,r=e.transformItems,o=void 0===r?function(e){return e}:r,a=e.fallbackParameters,c=e.indexName,i=e.maxRecommendations,s=e.model,m=e.queryParameters,u=e.threshold,l=t.map((function(e){return{fallbackParameters:a,indexName:c,maxRecommendations:i,model:s,objectID:e,queryParameters:m,threshold:u}}));return n.addAlgoliaAgent("recommend-core",j),n.getRecommendations(l).then((function(e){return O({maxRecommendations:i,hits:e.results.map((function(e){return e.hits})),nrOfObjs:t.length})})).then((function(e){return{recommendations:o(e)}}))}({fallbackParameters:E,indexName:r,maxRecommendations:o,model:a,objectIDs:h,queryParameters:P,recommendClient:s,threshold:m,transformItems:N.current}).then((function(e){d(e),y("idle")}))}),[E,r,o,a,h,P,s,y,m]),G(G({},f),{},{status:p})},e.useRelatedProducts=q,e.useTrendingFacets=B,e.useTrendingItems=U,Object.defineProperty(e,"__esModule",{value:!0})}));
/*! @algolia/recommend-react 1.8.2 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/recommend */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/recommend-react"]={},e.React)}(this,(function(e,t){"use strict";function n(){return n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},n.apply(this,arguments)}function a(...e){return e.filter(Boolean).join(" ")}function r({createElement:e,Fragment:t}){return function(n){return 0===n.recommendations.length&&"idle"===n.status?e(n.Fallback,null):e("section",{className:a("auc-Recommend",n.classNames.root)},e(n.Header,{classNames:n.classNames,recommendations:n.recommendations,translations:n.translations,createElement:e,Fragment:t}),e(n.View,null))}}function s({createElement:e}){return function(t){return!t.recommendations||t.recommendations.length<1?null:t.translations.title?e("h3",{className:a("auc-Recommend-title",t.classNames.title)},t.translations.title):null}}function m({createElement:e,Fragment:t}){return function(n){return e("div",{className:a("auc-Recommend-container",n.classNames.container)},e("ol",{className:a("auc-Recommend-list",n.classNames.list)},n.items.map((r=>e("li",{key:r.objectID,className:a("auc-Recommend-item",n.classNames.item)},e(n.itemComponent,{createElement:e,Fragment:t,item:r}))))))}}function o({hits:e,maxRecommendations:t,nrOfObjs:n}){const a={};e.forEach((e=>{e.forEach(((e,t)=>{a[e.objectID]?a[e.objectID]={indexSum:a[e.objectID].indexSum+t,nr:a[e.objectID].nr+1}:a[e.objectID]={indexSum:t,nr:1}}))}));const r=((e,t)=>{const n=[];for(const a of Object.keys(e))e[a].nr<2&&(e[a].indexSum+=100),n.push({objectID:a,avgOfIndices:e[a].indexSum/t});return n.sort(((e,t)=>e.avgOfIndices>t.avgOfIndices?1:-1))})(a,n);return r.reduce(((t,n)=>{const a=e.flat().find((e=>e.objectID===n.objectID));return a?t.concat(a):t}),[]).slice(0,t&&t>0?t:void 0)}function c({hits:e,maxRecommendations:t}){return function(e,t){const n=[...t];return n.sort(e),n}(((e,t)=>(e._score||0)>(t._score||0)?-1:1),e).slice(0,t&&t>0?t:void 0)}const i="1.8.2";function l(e){t.useEffect((()=>{e.recommendClient.addAlgoliaAgent("recommend-react","1.8.2")}),[e.recommendClient])}var u=Object.prototype.hasOwnProperty;function d(e,t){var n,a;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((a=e.length)===t.length)for(;a--&&d(e[a],t[a]););return-1===a}if(!n||"object"==typeof e){for(n in a=0,e){if(u.call(e,n)&&++a&&!u.call(t,n))return!1;if(!(n in t)||!d(e[n],t[n]))return!1}return Object.keys(t).length===a}}return e!=e&&t!=t}function f(e){const[n,a]=t.useState((()=>e));return t.useEffect((()=>{!1===d(n,e)&&a(e)}),[e]),n}function g(e){const n=t.useRef(void 0),[a,r]=t.useState(e);return t.useEffect((()=>{"stalled"!==a&&n.current&&clearTimeout(n.current),"loading"===a&&(n.current=setTimeout((()=>{r("stalled")}),300))}),[a]),{status:a,setStatus:r}}function h({indexName:e,maxRecommendations:n,objectIDs:a,queryParameters:r,recommendClient:s,threshold:m,transformItems:c}){const[u,d]=t.useState({recommendations:[]}),{status:h,setStatus:b}=g("loading"),E=f(a),N=f(r);l({recommendClient:s});const x=t.useRef(c);return t.useEffect((()=>{x.current=c}),[c]),t.useEffect((()=>{b("loading"),function({objectIDs:e,recommendClient:t,transformItems:n=(e=>e),indexName:a,maxRecommendations:r,queryParameters:s,threshold:m}){const c=e.map((e=>({indexName:a,maxRecommendations:r,objectID:e,queryParameters:s,threshold:m})));return t.addAlgoliaAgent("recommend-core",i),t.getFrequentlyBoughtTogether(c).then((t=>o({maxRecommendations:r,hits:t.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:n(e)})))}({indexName:e,maxRecommendations:n,objectIDs:E,queryParameters:N,recommendClient:s,threshold:m,transformItems:x.current}).then((e=>{d(e),b("idle")}))}),[e,n,E,N,s,b,m]),{...u,status:h}}const b=function({createElement:e,Fragment:t}){return function(a){const o={title:"Frequently bought together",sliderLabel:"Frequently bought together products",...a.translations},c=a.classNames??{},i=a.children??r({createElement:e,Fragment:t}),l=a.fallbackComponent??function(){return null},u=a.headerComponent??s({createElement:e,Fragment:t}),d=a.view??m({createElement:e,Fragment:t});return i({classNames:c,Fallback:()=>e(l,{Fragment:t,createElement:e}),Header:u,recommendations:a.items,status:a.status,translations:o,View:r=>e(d,n({classNames:c,itemComponent:a.itemComponent,items:a.items,translations:o,Fragment:t,createElement:e},r))})}}({createElement:t.createElement,Fragment:t.Fragment});function E({fallbackParameters:e,indexName:n,maxRecommendations:a,objectIDs:r,queryParameters:s,recommendClient:m,threshold:c,transformItems:u}){const[d,h]=t.useState({recommendations:[]}),{status:b,setStatus:E}=g("loading"),N=f(r),x=f(s),p=f(e);l({recommendClient:m});const F=t.useRef(u);return t.useEffect((()=>{F.current=u}),[u]),t.useEffect((()=>{E("loading"),function({objectIDs:e,recommendClient:t,transformItems:n=(e=>e),fallbackParameters:a,indexName:r,maxRecommendations:s,queryParameters:m,threshold:c}){const l=e.map((e=>({fallbackParameters:a,indexName:r,maxRecommendations:s,objectID:e,queryParameters:m,threshold:c})));return t.addAlgoliaAgent("recommend-core",i),t.getRelatedProducts(l).then((t=>o({maxRecommendations:s,hits:t.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:n(e)})))}({fallbackParameters:p,indexName:n,maxRecommendations:a,objectIDs:N,queryParameters:x,recommendClient:m,threshold:c,transformItems:F.current}).then((e=>{h(e),E("idle")}))}),[p,n,a,N,x,m,E,c]),{...d,status:b}}const N=function({createElement:e,Fragment:t}){return function(a){const o={title:"Related products",sliderLabel:"Related products",...a.translations},c=a.classNames??{},i=a.children??r({createElement:e,Fragment:t}),l=a.fallbackComponent??function(){return null},u=a.headerComponent??s({createElement:e,Fragment:t}),d=a.view??m({createElement:e,Fragment:t});return i({classNames:c,Fallback:()=>e(l,{Fragment:t,createElement:e}),Header:u,recommendations:a.items,status:a.status,translations:o,View:r=>e(d,n({classNames:c,itemComponent:a.itemComponent,items:a.items,translations:o,Fragment:t,createElement:e},r))})}}({createElement:t.createElement,Fragment:t.Fragment});function x({indexName:e,maxRecommendations:n,recommendClient:a,threshold:r,transformItems:s,facetName:m}){const[o,u]=t.useState({recommendations:[]}),{status:d,setStatus:f}=g("loading");l({recommendClient:a});const h=t.useRef(s);return t.useEffect((()=>{h.current=s}),[s]),t.useEffect((()=>{f("loading"),function({recommendClient:e,transformItems:t=(e=>e),indexName:n,maxRecommendations:a,threshold:r,facetName:s}){const m={indexName:n,maxRecommendations:a,threshold:r,facetName:s};return e.addAlgoliaAgent("recommend-core",i),e.getTrendingFacets([m]).then((e=>c({maxRecommendations:a,hits:e.results.map((e=>e.hits)).flat()}))).then((e=>({recommendations:t(e)})))}({recommendClient:a,transformItems:h.current,indexName:e,maxRecommendations:n,threshold:r,facetName:m}).then((e=>{u(e),f("idle")}))}),[e,n,a,f,r,m]),{...o,status:d}}const p=function({createElement:e,Fragment:t}){return function(m){const o={title:"Trending facets",sliderLabel:"Trending facets",...m.translations},c=m.classNames??{},i=m.children??r({createElement:e,Fragment:t}),l=m.fallbackComponent??function(){return null},u=m.headerComponent??s({createElement:e,Fragment:t}),d=m.view??function({createElement:e,Fragment:t}){return function(n){return e("div",{className:a("auc-Recommend-container",n.classNames.container)},e("ol",{className:a("auc-Recommend-list",n.classNames.list)},n.items.map((r=>e("li",{key:r.facetValue,className:a("auc-Recommend-item",n.classNames.item)},e(n.itemComponent,{createElement:e,Fragment:t,item:r}))))))}}({createElement:e,Fragment:t});return i({classNames:c,Fallback:()=>e(l,{Fragment:t,createElement:e}),Header:u,recommendations:m.items,status:m.status,translations:o,View:a=>e(d,n({classNames:c,itemComponent:m.itemComponent,items:m.items,translations:o,Fragment:t,createElement:e},a))})}}({createElement:t.createElement,Fragment:t.Fragment});function F({fallbackParameters:e,indexName:n,maxRecommendations:a,queryParameters:r,recommendClient:s,threshold:m,transformItems:o,facetName:u,facetValue:d}){const[h,b]=t.useState({recommendations:[]}),{status:E,setStatus:N}=g("loading"),x=f(r),p=f(e);l({recommendClient:s});const F=t.useRef(o);return t.useEffect((()=>{F.current=o}),[o]),t.useEffect((()=>{N("loading"),function({recommendClient:e,transformItems:t=(e=>e),fallbackParameters:n,indexName:a,maxRecommendations:r,queryParameters:s,threshold:m,facetName:o,facetValue:l}){const u={fallbackParameters:n,indexName:a,maxRecommendations:r,queryParameters:s,threshold:m,facetName:o,facetValue:l};return e.addAlgoliaAgent("recommend-core",i),e.getTrendingItems([u]).then((e=>{return c({maxRecommendations:r,hits:(t="objectID",n=e.results.map((e=>e.hits)).flat(),[...new Map(n.map((e=>[e[t],e]))).values()])});var t,n})).then((e=>({recommendations:t(e)})))}({recommendClient:s,transformItems:F.current,fallbackParameters:p,indexName:n,maxRecommendations:a,queryParameters:x,threshold:m,facetName:u,facetValue:d}).then((e=>{b(e),N("idle")}))}),[p,n,a,x,s,N,m,u,d]),{...h,status:E}}const R=function({createElement:e,Fragment:t}){return function(a){const o={title:"Trending items",sliderLabel:"Trending items",...a.translations},c=a.classNames??{},i=a.children??r({createElement:e,Fragment:t}),l=a.fallbackComponent??function(){return null},u=a.headerComponent??s({createElement:e,Fragment:t}),d=a.view??m({createElement:e,Fragment:t});return i({classNames:c,Fallback:()=>e(l,{Fragment:t,createElement:e}),Header:u,recommendations:a.items,status:a.status,translations:o,View:r=>e(d,n({classNames:c,itemComponent:a.itemComponent,items:a.items,translations:o,Fragment:t,createElement:e},r))})}}({createElement:t.createElement,Fragment:t.Fragment});e.FrequentlyBoughtTogether=function(e){const{recommendations:a,status:r}=h(e);return t.createElement(b,n({},e,{items:a,status:r}))},e.RelatedProducts=function(e){const{recommendations:a,status:r}=E(e);return t.createElement(N,n({},e,{items:a,status:r}))},e.TrendingFacets=function(e){const{recommendations:a,status:r}=x(e);return t.createElement(p,n({},e,{items:a,status:r}))},e.TrendingItems=function(e){const{recommendations:a,status:r}=F(e);return t.createElement(R,n({},e,{items:a,status:r}))},e.useFrequentlyBoughtTogether=h,e.useRecommendations=function({fallbackParameters:e,indexName:n,maxRecommendations:a,model:r,objectIDs:s,queryParameters:m,recommendClient:c,threshold:u,transformItems:d}){const[h,b]=t.useState({recommendations:[]}),{status:E,setStatus:N}=g("loading"),x=f(s),p=f(m),F=f(e);l({recommendClient:c});const R=t.useRef(d);return t.useEffect((()=>{R.current=d}),[d]),t.useEffect((()=>{N("loading"),function({objectIDs:e,recommendClient:t,transformItems:n=(e=>e),fallbackParameters:a,indexName:r,maxRecommendations:s,model:m,queryParameters:c,threshold:l}){const u=e.map((e=>({fallbackParameters:a,indexName:r,maxRecommendations:s,model:m,objectID:e,queryParameters:c,threshold:l})));return t.addAlgoliaAgent("recommend-core",i),t.getRecommendations(u).then((t=>o({maxRecommendations:s,hits:t.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:n(e)})))}({fallbackParameters:F,indexName:n,maxRecommendations:a,model:r,objectIDs:x,queryParameters:p,recommendClient:c,threshold:u,transformItems:R.current}).then((e=>{b(e),N("idle")}))}),[F,n,a,r,x,p,c,N,u]),{...h,status:E}},e.useRelatedProducts=E,e.useTrendingFacets=x,e.useTrendingItems=F}));
//# sourceMappingURL=index.js.map
{
"name": "@algolia/recommend-react",
"description": "Horizontal slider UI component.",
"version": "1.8.1",
"version": "1.8.2",
"license": "MIT",

@@ -27,3 +27,3 @@ "homepage": "https://github.com/algolia/recommend",

"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm",
"build:umd": "rollup --config",
"build:umd": "rollup --config --bundleConfigAsCjs",
"build": "yarn build:clean && yarn build:esm && yarn build:umd && yarn build:types",

@@ -33,5 +33,5 @@ "prepare": "yarn build:esm && yarn build:types"

"dependencies": {
"@algolia/recommend-core": "1.8.1",
"@algolia/recommend-vdom": "1.8.1",
"dequal": "^2.0.0"
"@algolia/recommend-core": "1.8.2",
"@algolia/recommend-vdom": "1.8.2",
"dequal": "2.0.3"
},

@@ -38,0 +38,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc