UNPKG

react-instantsearch

Version:
79 lines (77 loc) 3.75 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "PromptSuggestions", { enumerable: true, get: function() { return PromptSuggestions; } }); var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"); var _object_spread = require("@swc/helpers/_/_object_spread"); var _object_spread_props = require("@swc/helpers/_/_object_spread_props"); var _object_without_properties = require("@swc/helpers/_/_object_without_properties"); var _instantsearchuicomponents = require("instantsearch-ui-components"); var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react")); var _reactinstantsearchcore = require("react-instantsearch-core"); var PromptSuggestionsUi = (0, _instantsearchuicomponents.createPromptSuggestionsComponent)({ createElement: _react.createElement, Fragment: _react.Fragment }); function PromptSuggestions(_0) { var _0_classNames = _0.classNames, classNames = _0_classNames === void 0 ? {} : _0_classNames, LayoutComponent = _0.layoutComponent, onSuggestionClickOverride = _0.onSuggestionClick, // Connector params — forwarded to the hook, not the UI root. agentId = _0.agentId, transport = _0.transport, configurationId = _0.configurationId, transformHits = _0.transformHits, context = _0.context, transformItems = _0.transformItems, props = _object_without_properties._(_0, [ "classNames", "layoutComponent", "onSuggestionClick", "agentId", "transport", "configurationId", "transformHits", "context", "transformItems" ]); var source = agentId !== undefined ? { agentId: agentId, transport: transport } : { transport: transport }; var _usePromptSuggestions = (0, _reactinstantsearchcore.usePromptSuggestions)(_object_spread_props._(_object_spread._({}, source), { configurationId: configurationId, transformHits: transformHits, context: context, transformItems: transformItems }), { $$widgetType: 'ais.promptSuggestions' }), suggestions = _usePromptSuggestions.suggestions, isLoading = _usePromptSuggestions.isLoading, error = _usePromptSuggestions.error, onSuggestionClick = _usePromptSuggestions.onSuggestionClick, isChatBusy = _usePromptSuggestions.isChatBusy, sendToChat = _usePromptSuggestions.sendToChat; if (!sendToChat && !onSuggestionClickOverride) { throw new Error('No <Chat> widget is mounted on this index, so there is nothing to send a clicked suggestion to. Mount a <Chat> on the same index, or pass `onSuggestionClick` to handle the click yourself.'); } var handleClick = onSuggestionClickOverride ? function(prompt) { return onSuggestionClickOverride(prompt, { // `sendToChat` is only absent when the override above owns the click, // in which case falling through to the chat is a no-op. sendToChat: sendToChat !== null && sendToChat !== void 0 ? sendToChat : function() { return false; } }); } : onSuggestionClick; if (LayoutComponent) { return /*#__PURE__*/ _react.default.createElement(LayoutComponent, { suggestions: suggestions, isLoading: isLoading, error: error, onSuggestionClick: handleClick, isChatBusy: isChatBusy }); } return /*#__PURE__*/ _react.default.createElement(PromptSuggestionsUi, _object_spread_props._(_object_spread._({}, props), { classNames: classNames, suggestions: suggestions, isLoading: isLoading, onSuggestionClick: handleClick, disabled: isChatBusy })); }