react-instantsearch-core
7.25.07.26.0
dist/es/components/DynamicWidgets.js~
dist/es/components/DynamicWidgets.jsModified+45−47
Index: package/dist/es/components/DynamicWidgets.js
===================================================================
--- package/dist/es/components/DynamicWidgets.js
+++ package/dist/es/components/DynamicWidgets.js
@@ -1,55 +1,53 @@
-var _excluded = ["children", "fallbackComponent"];
-function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
-function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
-function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
-import React, { Fragment } from 'react';
-import { useDynamicWidgets } from "../connectors/useDynamicWidgets.js";
-import { invariant } from "../lib/invariant.js";
-import { warn } from "../lib/warn.js";
+import { _ } from '@swc/helpers/cjs/_object_without_properties.cjs';
+import { _ as _$1 } from '@swc/helpers/cjs/_type_of.cjs';
+import React__default, { Fragment } from 'react';
+import { useDynamicWidgets } from '../connectors/useDynamicWidgets.js';
+import { invariant } from '../lib/invariant.js';
+
function DefaultFallbackComponent() {
- return null;
+ return null;
}
-export function DynamicWidgets(_ref) {
- var children = _ref.children,
- _ref$fallbackComponen = _ref.fallbackComponent,
- Fallback = _ref$fallbackComponen === void 0 ? DefaultFallbackComponent : _ref$fallbackComponen,
- props = _objectWithoutProperties(_ref, _excluded);
- var FallbackComponent = React.useRef(Fallback);
- process.env.NODE_ENV === 'development' ? warn(Fallback === FallbackComponent.current, 'The `fallbackComponent` prop of `DynamicWidgets` changed between renders. Please provide a stable reference, as described in https://www.algolia.com/doc/api-reference/widgets/dynamic-facets/react/#widget-param-fallbackcomponent') : void 0;
- var _useDynamicWidgets = useDynamicWidgets(props, {
- $$widgetType: 'ais.dynamicWidgets'
- }),
- attributesToRender = _useDynamicWidgets.attributesToRender;
- var widgets = new Map();
- React.Children.forEach(children, function (child) {
- var attribute = getWidgetAttribute(child);
- invariant(attribute !== undefined, "<DynamicWidgets> only supports InstantSearch widgets with an `attribute` or `attributes` prop.");
- widgets.set(attribute, child);
- });
- return /*#__PURE__*/React.createElement(React.Fragment, null, attributesToRender.map(function (attribute) {
- return /*#__PURE__*/React.createElement(Fragment, {
- key: attribute
- }, widgets.get(attribute) || /*#__PURE__*/React.createElement(FallbackComponent.current, {
- attribute: attribute
+function DynamicWidgets(_0) {
+ var children = _0.children, tmp = _0.fallbackComponent, Fallback = tmp === void 0 ? DefaultFallbackComponent : tmp, props = _(_0, [
+ "children",
+ "fallbackComponent"
+ ]);
+ var FallbackComponent = React__default.useRef(Fallback);
+ var attributesToRender = useDynamicWidgets(props, {
+ $$widgetType: 'ais.dynamicWidgets'
+ }).attributesToRender;
+ var widgets = new Map();
+ React__default.Children.forEach(children, function(child) {
+ var attribute = getWidgetAttribute(child);
+ invariant(attribute !== undefined);
+ widgets.set(attribute, child);
+ });
+ return /*#__PURE__*/ React__default.createElement(React__default.Fragment, null, attributesToRender.map(function(attribute) {
+ return /*#__PURE__*/ React__default.createElement(Fragment, {
+ key: attribute
+ }, widgets.get(attribute) || /*#__PURE__*/ React__default.createElement(FallbackComponent.current, {
+ attribute: attribute
+ }));
}));
- }));
}
function isReactElement(element) {
- return _typeof(element) === 'object' && element.props;
+ return (typeof element === "undefined" ? "undefined" : _$1(element)) === 'object' && element.props;
}
function getWidgetAttribute(element) {
- if (!isReactElement(element)) {
+ if (!isReactElement(element)) {
+ return undefined;
+ }
+ if (element.props.attribute) {
+ return element.props.attribute;
+ }
+ if (Array.isArray(element.props.attributes)) {
+ return element.props.attributes[0];
+ }
+ if (element.props.children) {
+ invariant(React__default.Children.count(element.props.children) === 1);
+ return getWidgetAttribute(React__default.Children.only(element.props.children));
+ }
return undefined;
- }
- if (element.props.attribute) {
- return element.props.attribute;
- }
- if (Array.isArray(element.props.attributes)) {
- return element.props.attributes[0];
- }
- if (element.props.children) {
- invariant(React.Children.count(element.props.children) === 1, "<DynamicWidgets> only supports a single component in nested components. Make sure to not render multiple children in a parent component.\n\nExample of an unsupported scenario:\n\n```\n<DynamicWidgets>\n <MyComponent>\n <RefinementList attribute=\"brand\" />\n <Menu attribute=\"categories\" />\n </MyComponent>\n</DynamicWidgets>\n```\n");
- return getWidgetAttribute(React.Children.only(element.props.children));
- }
- return undefined;
-}
\ No newline at end of file
+}
+
+export { DynamicWidgets };