@docsearch/js 5.0.2 → 5.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! @docsearch/js 5.0.2 (UNRELEASED ad8e8d9) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/js 5.0.3 (UNRELEASED f31abef) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  import React$1, { JSX } from "react";
3
3
  import { JSONSchema7 } from "json-schema";
4
4
  //#region ../docsearch-core/dist/esm/useKeyboardShortcuts.d.ts
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @docsearch/js 5.0.2 (UNRELEASED ad8e8d9) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/js 5.0.3 (UNRELEASED f31abef) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  //#region \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp$1 = Object.defineProperty;
@@ -1188,7 +1188,7 @@ function DocSearchButtonKey({ reactsToKey, children }) {
1188
1188
 
1189
1189
  //#endregion
1190
1190
  //#region ../docsearch-react/dist/esm/version.js
1191
- const version$2 = "5.0.2";
1191
+ const version$2 = "5.0.3";
1192
1192
 
1193
1193
  //#endregion
1194
1194
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/OverloadYield.js
@@ -31462,7 +31462,7 @@ function createAutocomplete(options) {
31462
31462
  }
31463
31463
 
31464
31464
  //#endregion
31465
- //#region ../docsearch-react/dist/esm/DocSearchAskAiModal-mjZ_EYK1.js
31465
+ //#region ../docsearch-react/dist/esm/DocSearchAskAiModal-BzQZxvTY.js
31466
31466
  init_compat();
31467
31467
  function MessageIcon() {
31468
31468
  return /* @__PURE__ */ En.createElement("svg", {
@@ -31920,18 +31920,16 @@ const EMPTY_SNIPPET_RESULT = {
31920
31920
  hierarchy: EMPTY_HIERARCHY_HIGHLIGHT_RESULT,
31921
31921
  hierarchy_camel: []
31922
31922
  };
31923
- function buildRecentConversationSources({ conversations, disableUserPersonalization, setMessages, onAskAiToggle }) {
31923
+ function buildRecentConversationSources({ conversations, disableUserPersonalization, handleSelectStoredConversation }) {
31924
31924
  return [{
31925
31925
  sourceId: SOURCE_IDS.recentConversations,
31926
31926
  getItems() {
31927
31927
  if (disableUserPersonalization) return [];
31928
31928
  return conversations.getAll().slice(0, MAX_RECENT_CONVERSATIONS_DISPLAYED);
31929
31929
  },
31930
- onSelect({ item }) {
31931
- if (item.messages) {
31932
- setMessages(item.messages);
31933
- onAskAiToggle(true);
31934
- }
31930
+ onSelect({ item, event }) {
31931
+ if (item.type !== "askAI") return;
31932
+ handleSelectStoredConversation(item, event);
31935
31933
  }
31936
31934
  }];
31937
31935
  }
@@ -32085,7 +32083,7 @@ function DocSearchAskAiModal(_ref) {
32085
32083
  recentSearchesWithFavoritesLimit
32086
32084
  });
32087
32085
  const [stoppedStream, setStoppedStream] = En.useState(false);
32088
- const { chatId, messages, status, setMessages, sendMessage, stopAskAiStreaming, askAiError, sendFeedback, conversations, startNewConversation, restoreConversation } = useAskAi({
32086
+ const { chatId, messages, status, sendMessage, stopAskAiStreaming, askAiError, sendFeedback, conversations, startNewConversation, restoreConversation } = useAskAi({
32089
32087
  agentId: askAiConfigurationId,
32090
32088
  apiKey: (askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.apiKey) || apiKey,
32091
32089
  appId: (askAiConfig === null || askAiConfig === void 0 ? void 0 : askAiConfig.appId) || appId,
@@ -32179,6 +32177,25 @@ function DocSearchAskAiModal(_ref) {
32179
32177
  appId,
32180
32178
  sendFeedback
32181
32179
  ]);
32180
+ const handleSelectStoredConversation = En.useCallback((item, event) => {
32181
+ if (isQueryEmpty(item.query) || !item.messages || item.messages.length < 1) return;
32182
+ const hitMessages = item.messages;
32183
+ const initialMessage = {
32184
+ query: item.query,
32185
+ messageId: hitMessages[0].id
32186
+ };
32187
+ restoreConversation(hitMessages, item.chatId);
32188
+ if (interceptAskAiEvent === null || interceptAskAiEvent === void 0 ? void 0 : interceptAskAiEvent(initialMessage)) {
32189
+ if (autocompleteRef.current) autocompleteRef.current.setQuery("");
32190
+ event.preventDefault();
32191
+ return;
32192
+ }
32193
+ onAskAiToggle(true, initialMessage);
32194
+ }, [
32195
+ interceptAskAiEvent,
32196
+ restoreConversation,
32197
+ onAskAiToggle
32198
+ ]);
32182
32199
  if (!autocompleteRef.current) autocompleteRef.current = createAutocomplete({
32183
32200
  id: "docsearch",
32184
32201
  defaultActiveItemId: 0,
@@ -32204,8 +32221,7 @@ function DocSearchAskAiModal(_ref) {
32204
32221
  return [...canHandleAskAi ? buildRecentConversationSources({
32205
32222
  conversations,
32206
32223
  disableUserPersonalization,
32207
- setMessages,
32208
- onAskAiToggle
32224
+ handleSelectStoredConversation
32209
32225
  }) : [], ...noQuerySources];
32210
32226
  }
32211
32227
  const algoliaSourcesPromise = buildQuerySources({
@@ -32361,20 +32377,8 @@ function DocSearchAskAiModal(_ref) {
32361
32377
  onNewConversation: handleNewConversation,
32362
32378
  onItemClick: (item, event) => {
32363
32379
  if (item.type === "askAI" && item.query) {
32364
- if (item.anchor === "stored" && "messages" in item) {
32365
- const hitMessages = item.messages;
32366
- restoreConversation(hitMessages, item.chatId);
32367
- const initialMessage = {
32368
- query: item.query,
32369
- messageId: hitMessages[0].id
32370
- };
32371
- if (interceptAskAiEvent === null || interceptAskAiEvent === void 0 ? void 0 : interceptAskAiEvent(initialMessage)) {
32372
- if (autocompleteRef.current) autocompleteRef.current.setQuery("");
32373
- event.preventDefault();
32374
- return;
32375
- }
32376
- onAskAiToggle(true, initialMessage);
32377
- } else handleSelectAskAiQuestion(true, item.query);
32380
+ if (item.anchor === "stored") handleSelectStoredConversation(item, event);
32381
+ else handleSelectAskAiQuestion(true, item.query);
32378
32382
  setAskAiState("initial");
32379
32383
  event.preventDefault();
32380
32384
  return;