@nuskin/react-search-components 1.0.0-comx-3067.5 → 1.0.0-comx-3067.7
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.
- package/dist/index.d.mts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +184 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +186 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
3
|
-
import { CatalogSuggestionItem, SearchService } from '@nuskin/react-search-sdk';
|
|
3
|
+
import { CatalogSuggestionItem, SearchService, SearchGtmContext } from '@nuskin/react-search-sdk';
|
|
4
4
|
export { CatalogSuggestionItem, DidYouMeanItem, SearchService, createSearchService } from '@nuskin/react-search-sdk';
|
|
5
5
|
import { Environment } from '@ns/ns-contentstack-lib';
|
|
6
6
|
|
|
@@ -138,6 +138,7 @@ interface AISearchProduct {
|
|
|
138
138
|
description?: string;
|
|
139
139
|
badge?: string;
|
|
140
140
|
url?: string;
|
|
141
|
+
routeUrl?: string;
|
|
141
142
|
category?: string;
|
|
142
143
|
}
|
|
143
144
|
interface AISearchResult {
|
|
@@ -175,6 +176,14 @@ interface SearchModalAIChatHeaderContent {
|
|
|
175
176
|
};
|
|
176
177
|
[key: string]: unknown;
|
|
177
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Consumer-supplied context for the COMX-3277 AI chat GTM events.
|
|
181
|
+
*
|
|
182
|
+
* `chatId` is derived internally from the AI chat conversation id, so it is
|
|
183
|
+
* intentionally omitted here — callers only provide what the host app knows
|
|
184
|
+
* (page type, user status, user id, etc.).
|
|
185
|
+
*/
|
|
186
|
+
type SearchModalGtmContext = Omit<SearchGtmContext, 'chatId'>;
|
|
178
187
|
interface SearchModalProps {
|
|
179
188
|
isOpen: boolean;
|
|
180
189
|
onClose: () => void;
|
|
@@ -203,12 +212,19 @@ interface SearchModalProps {
|
|
|
203
212
|
aiChatHeaderContent?: SearchModalAIChatHeaderContent | null;
|
|
204
213
|
/** API configuration for AI Commerce Chat. Required when enableAIChat is true. */
|
|
205
214
|
aiChatConfig?: SearchModalAIChatConfig;
|
|
215
|
+
/**
|
|
216
|
+
* Optional host-supplied context for the AI chat GTM (dataLayer) events
|
|
217
|
+
* defined in COMX-3277 (page type, country code, language, user status, user id).
|
|
218
|
+
* When omitted, blank-string placeholders are pushed to the dataLayer so the
|
|
219
|
+
* event schema stays stable.
|
|
220
|
+
*/
|
|
221
|
+
gtmContext?: SearchModalGtmContext;
|
|
206
222
|
history?: {
|
|
207
223
|
push: (path: string) => void;
|
|
208
224
|
} | null;
|
|
209
225
|
}
|
|
210
226
|
|
|
211
|
-
declare function SearchModal({ isOpen, onClose, service, history, copy, logo, cancelLabel, fallbackImageUrl, enableAIChat, aiChatConfig, showPricing, aiChatHeaderContent, }: Readonly<SearchModalProps>): React__default.ReactElement | null;
|
|
227
|
+
declare function SearchModal({ isOpen, onClose, service, history, copy, logo, cancelLabel, fallbackImageUrl, enableAIChat, aiChatConfig, gtmContext, showPricing, aiChatHeaderContent, }: Readonly<SearchModalProps>): React__default.ReactElement | null;
|
|
212
228
|
|
|
213
229
|
interface AIChatHeaderContentConfig {
|
|
214
230
|
/** Contentstack environment consumed by getStack, e.g. prod/test/stage */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
3
|
-
import { CatalogSuggestionItem, SearchService } from '@nuskin/react-search-sdk';
|
|
3
|
+
import { CatalogSuggestionItem, SearchService, SearchGtmContext } from '@nuskin/react-search-sdk';
|
|
4
4
|
export { CatalogSuggestionItem, DidYouMeanItem, SearchService, createSearchService } from '@nuskin/react-search-sdk';
|
|
5
5
|
import { Environment } from '@ns/ns-contentstack-lib';
|
|
6
6
|
|
|
@@ -138,6 +138,7 @@ interface AISearchProduct {
|
|
|
138
138
|
description?: string;
|
|
139
139
|
badge?: string;
|
|
140
140
|
url?: string;
|
|
141
|
+
routeUrl?: string;
|
|
141
142
|
category?: string;
|
|
142
143
|
}
|
|
143
144
|
interface AISearchResult {
|
|
@@ -175,6 +176,14 @@ interface SearchModalAIChatHeaderContent {
|
|
|
175
176
|
};
|
|
176
177
|
[key: string]: unknown;
|
|
177
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Consumer-supplied context for the COMX-3277 AI chat GTM events.
|
|
181
|
+
*
|
|
182
|
+
* `chatId` is derived internally from the AI chat conversation id, so it is
|
|
183
|
+
* intentionally omitted here — callers only provide what the host app knows
|
|
184
|
+
* (page type, user status, user id, etc.).
|
|
185
|
+
*/
|
|
186
|
+
type SearchModalGtmContext = Omit<SearchGtmContext, 'chatId'>;
|
|
178
187
|
interface SearchModalProps {
|
|
179
188
|
isOpen: boolean;
|
|
180
189
|
onClose: () => void;
|
|
@@ -203,12 +212,19 @@ interface SearchModalProps {
|
|
|
203
212
|
aiChatHeaderContent?: SearchModalAIChatHeaderContent | null;
|
|
204
213
|
/** API configuration for AI Commerce Chat. Required when enableAIChat is true. */
|
|
205
214
|
aiChatConfig?: SearchModalAIChatConfig;
|
|
215
|
+
/**
|
|
216
|
+
* Optional host-supplied context for the AI chat GTM (dataLayer) events
|
|
217
|
+
* defined in COMX-3277 (page type, country code, language, user status, user id).
|
|
218
|
+
* When omitted, blank-string placeholders are pushed to the dataLayer so the
|
|
219
|
+
* event schema stays stable.
|
|
220
|
+
*/
|
|
221
|
+
gtmContext?: SearchModalGtmContext;
|
|
206
222
|
history?: {
|
|
207
223
|
push: (path: string) => void;
|
|
208
224
|
} | null;
|
|
209
225
|
}
|
|
210
226
|
|
|
211
|
-
declare function SearchModal({ isOpen, onClose, service, history, copy, logo, cancelLabel, fallbackImageUrl, enableAIChat, aiChatConfig, showPricing, aiChatHeaderContent, }: Readonly<SearchModalProps>): React__default.ReactElement | null;
|
|
227
|
+
declare function SearchModal({ isOpen, onClose, service, history, copy, logo, cancelLabel, fallbackImageUrl, enableAIChat, aiChatConfig, gtmContext, showPricing, aiChatHeaderContent, }: Readonly<SearchModalProps>): React__default.ReactElement | null;
|
|
212
228
|
|
|
213
229
|
interface AIChatHeaderContentConfig {
|
|
214
230
|
/** Contentstack environment consumed by getStack, e.g. prod/test/stage */
|
package/dist/index.js
CHANGED
|
@@ -12006,6 +12006,7 @@ function SearchMessage({ sender, text: text4, ...props }) {
|
|
|
12006
12006
|
|
|
12007
12007
|
// src/components/Icon/iconConstants.ts
|
|
12008
12008
|
var ICON_TYPES = {
|
|
12009
|
+
ARROW_DOWN: "arrowDown",
|
|
12009
12010
|
ARROW_LEFT: "arrowLeft",
|
|
12010
12011
|
ARROW_RIGHT: "arrowRight",
|
|
12011
12012
|
ARROW_UP: "arrowUp",
|
|
@@ -12051,6 +12052,7 @@ var ICON_COLOR_BY_TYPE = {
|
|
|
12051
12052
|
[ICON_TYPES.STAR_GREY]: "#c9c9c9"
|
|
12052
12053
|
};
|
|
12053
12054
|
var TEMPORARY_GLYPH_BY_ICON_TYPE = {
|
|
12055
|
+
[ICON_TYPES.ARROW_DOWN]: "\u2193",
|
|
12054
12056
|
[ICON_TYPES.ARROW_LEFT]: "\u2190",
|
|
12055
12057
|
[ICON_TYPES.ARROW_RIGHT]: "\u2192",
|
|
12056
12058
|
[ICON_TYPES.ARROW_UP]: "\u2191",
|
|
@@ -12675,7 +12677,7 @@ var SearchPanelRoot = styled6__default.default.section`
|
|
|
12675
12677
|
${({ $chatMode }) => $chatMode && `
|
|
12676
12678
|
display: flex;
|
|
12677
12679
|
flex-direction: column;
|
|
12678
|
-
height: 805px;
|
|
12680
|
+
max-height: 805px;
|
|
12679
12681
|
overflow: hidden;
|
|
12680
12682
|
`}
|
|
12681
12683
|
`;
|
|
@@ -13317,6 +13319,33 @@ var AIStatusCursor = styled6__default.default.span`
|
|
|
13317
13319
|
}
|
|
13318
13320
|
}
|
|
13319
13321
|
`;
|
|
13322
|
+
var ChatScrollIndicator = styled6__default.default.button`
|
|
13323
|
+
align-self: center;
|
|
13324
|
+
appearance: none;
|
|
13325
|
+
background: ${colors6.hover};
|
|
13326
|
+
border: 0;
|
|
13327
|
+
border-radius: 50%;
|
|
13328
|
+
color: ${colors6.text};
|
|
13329
|
+
cursor: pointer;
|
|
13330
|
+
display: grid;
|
|
13331
|
+
place-items: center;
|
|
13332
|
+
block-size: 2rem;
|
|
13333
|
+
inline-size: 2rem;
|
|
13334
|
+
margin-block: 0.25rem 0.75rem;
|
|
13335
|
+
padding: 0;
|
|
13336
|
+
position: sticky;
|
|
13337
|
+
inset-block-end: 0.75rem;
|
|
13338
|
+
z-index: 1;
|
|
13339
|
+
|
|
13340
|
+
&:hover {
|
|
13341
|
+
background: ${colors6.borderLight};
|
|
13342
|
+
}
|
|
13343
|
+
|
|
13344
|
+
&:focus-visible {
|
|
13345
|
+
outline: 2px solid ${colors6.text};
|
|
13346
|
+
outline-offset: 2px;
|
|
13347
|
+
}
|
|
13348
|
+
`;
|
|
13320
13349
|
var SuggestionSectionHeading = styled6__default.default.div`
|
|
13321
13350
|
padding: 12px 24px 8px;
|
|
13322
13351
|
margin-bottom: 4px;
|
|
@@ -13463,7 +13492,7 @@ styled6__default.default.span`
|
|
|
13463
13492
|
font-size: 0.8125rem;
|
|
13464
13493
|
font-weight: 600;
|
|
13465
13494
|
`;
|
|
13466
|
-
|
|
13495
|
+
styled6__default.default.button`
|
|
13467
13496
|
align-items: center;
|
|
13468
13497
|
align-self: center;
|
|
13469
13498
|
appearance: none;
|
|
@@ -13593,7 +13622,7 @@ function stripPricingText(text4) {
|
|
|
13593
13622
|
);
|
|
13594
13623
|
}
|
|
13595
13624
|
function toCarouselItem(product, index2, showPricing, history) {
|
|
13596
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
13625
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
13597
13626
|
const slotKey = `ai-${(_b = (_a = product.id) != null ? _a : product.sku) != null ? _b : index2}-${index2}`;
|
|
13598
13627
|
const productName = (_f = (_d = (_c = product.name) == null ? void 0 : _c.trim()) != null ? _d : product.sku) != null ? _f : `Product ${(_e = product.id) != null ? _e : index2}`;
|
|
13599
13628
|
if (!productName) {
|
|
@@ -13608,12 +13637,13 @@ function toCarouselItem(product, index2, showPricing, history) {
|
|
|
13608
13637
|
};
|
|
13609
13638
|
}
|
|
13610
13639
|
const href = (_i = product.url) != null ? _i : "#";
|
|
13611
|
-
const
|
|
13612
|
-
const
|
|
13640
|
+
const routeHref = (_j = product.routeUrl) != null ? _j : product.sku ? `/product/${product.sku}` : href;
|
|
13641
|
+
const imageUrl = (_k = product.imageUrl) != null ? _k : product.image_url;
|
|
13642
|
+
const priceText = (_l = product.price) != null ? _l : product.pv != null ? `${product.pv} PV` : void 0;
|
|
13613
13643
|
return {
|
|
13614
13644
|
status: "ready",
|
|
13615
13645
|
slotKey,
|
|
13616
|
-
productId: String((
|
|
13646
|
+
productId: String((_n = (_m = product.id) != null ? _m : product.sku) != null ? _n : index2),
|
|
13617
13647
|
cardProps: {
|
|
13618
13648
|
mode: "cta",
|
|
13619
13649
|
title: productName,
|
|
@@ -13623,10 +13653,11 @@ function toCarouselItem(product, index2, showPricing, history) {
|
|
|
13623
13653
|
price: showPricing ? priceText : void 0,
|
|
13624
13654
|
addToCartLabel: "View Product",
|
|
13625
13655
|
addToCartAriaLabel: `View ${productName}`,
|
|
13626
|
-
onProductClick: () => {
|
|
13656
|
+
onProductClick: ({ event } = {}) => {
|
|
13627
13657
|
if (href === "#") return;
|
|
13658
|
+
event == null ? void 0 : event.preventDefault();
|
|
13628
13659
|
if (history && typeof history.push === "function") {
|
|
13629
|
-
history.push(
|
|
13660
|
+
history.push(routeHref);
|
|
13630
13661
|
}
|
|
13631
13662
|
}
|
|
13632
13663
|
}
|
|
@@ -13639,14 +13670,6 @@ function SearchChatResult({
|
|
|
13639
13670
|
productsAriaLabel = "AI recommended products"
|
|
13640
13671
|
}) {
|
|
13641
13672
|
var _a;
|
|
13642
|
-
const carouselWrapperRef = React.useRef(null);
|
|
13643
|
-
function scrollDown() {
|
|
13644
|
-
var _a2;
|
|
13645
|
-
(_a2 = carouselWrapperRef.current) == null ? void 0 : _a2.scrollIntoView({
|
|
13646
|
-
behavior: "smooth",
|
|
13647
|
-
block: "nearest"
|
|
13648
|
-
});
|
|
13649
|
-
}
|
|
13650
13673
|
const products = (_a = result.products) != null ? _a : [];
|
|
13651
13674
|
const carouselItems = products.map((p, i) => toCarouselItem(p, i, showPricing, history));
|
|
13652
13675
|
const summaryText = showPricing ? result.aiResponseText : stripPricingText(result.aiResponseText);
|
|
@@ -13667,42 +13690,11 @@ function SearchChatResult({
|
|
|
13667
13690
|
"data-testid": "chat-ai-response"
|
|
13668
13691
|
}
|
|
13669
13692
|
),
|
|
13670
|
-
carouselItems.length > 0 && /* @__PURE__ */ jsxRuntime.
|
|
13671
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactProductComponents.ProductCarousel, { items: carouselItems, ariaLabel: productsAriaLabel }),
|
|
13672
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
13673
|
-
ScrollIndicator,
|
|
13674
|
-
{
|
|
13675
|
-
type: "button",
|
|
13676
|
-
"aria-label": "Scroll to products",
|
|
13677
|
-
onClick: scrollDown,
|
|
13678
|
-
"data-testid": "chat-scroll-indicator",
|
|
13679
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
13680
|
-
"svg",
|
|
13681
|
-
{
|
|
13682
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
13683
|
-
viewBox: "0 0 24 24",
|
|
13684
|
-
fill: "none",
|
|
13685
|
-
stroke: "currentColor",
|
|
13686
|
-
strokeWidth: 2,
|
|
13687
|
-
strokeLinecap: "round",
|
|
13688
|
-
strokeLinejoin: "round",
|
|
13689
|
-
width: 16,
|
|
13690
|
-
height: 16,
|
|
13691
|
-
"aria-hidden": true,
|
|
13692
|
-
children: [
|
|
13693
|
-
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: 12, y1: 5, x2: 12, y2: 19 }),
|
|
13694
|
-
/* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "19 12 12 19 5 12" })
|
|
13695
|
-
]
|
|
13696
|
-
}
|
|
13697
|
-
)
|
|
13698
|
-
}
|
|
13699
|
-
)
|
|
13700
|
-
] })
|
|
13693
|
+
carouselItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(ProductCarouselWrapper, { "data-testid": "chat-product-carousel", children: /* @__PURE__ */ jsxRuntime.jsx(reactProductComponents.ProductCarousel, { items: carouselItems, ariaLabel: productsAriaLabel }) })
|
|
13701
13694
|
] });
|
|
13702
13695
|
}
|
|
13703
13696
|
|
|
13704
13697
|
// src/components/SearchModal/SearchModalConstants.ts
|
|
13705
|
-
var DEFAULT_AI_AUTO_TRIGGER_DELAY_MS = 4e3;
|
|
13706
13698
|
var DEFAULT_AI_STATUS_LABELS = {
|
|
13707
13699
|
analyzing: "Analyzing your question...",
|
|
13708
13700
|
pulling: "Pulling up your analytics...",
|
|
@@ -13749,9 +13741,6 @@ function getUniqueRecentSearches(entries) {
|
|
|
13749
13741
|
) === idx
|
|
13750
13742
|
);
|
|
13751
13743
|
}
|
|
13752
|
-
function getAITriggerDelayMs(delayMs) {
|
|
13753
|
-
return typeof delayMs === "number" && delayMs >= 0 ? delayMs : DEFAULT_AI_AUTO_TRIGGER_DELAY_MS;
|
|
13754
|
-
}
|
|
13755
13744
|
function getProductId(rawId) {
|
|
13756
13745
|
return typeof rawId === "string" || typeof rawId === "number" ? String(rawId) : JSON.stringify(rawId);
|
|
13757
13746
|
}
|
|
@@ -13776,6 +13765,11 @@ function SearchModalChatContent({
|
|
|
13776
13765
|
analyzingLabel,
|
|
13777
13766
|
chatEndRef
|
|
13778
13767
|
}) {
|
|
13768
|
+
const hasChatResults = aiChatHistory.length > 0;
|
|
13769
|
+
function scrollToBottom() {
|
|
13770
|
+
var _a;
|
|
13771
|
+
(_a = chatEndRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth", block: "end" });
|
|
13772
|
+
}
|
|
13779
13773
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
13780
13774
|
aiChatHistory.map((result, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
13781
13775
|
"div",
|
|
@@ -13801,6 +13795,23 @@ function SearchModalChatContent({
|
|
|
13801
13795
|
typedStatus || analyzingLabel,
|
|
13802
13796
|
/* @__PURE__ */ jsxRuntime.jsx(AIStatusCursor, { "aria-hidden": "true" })
|
|
13803
13797
|
] }),
|
|
13798
|
+
hasChatResults && /* @__PURE__ */ jsxRuntime.jsx(
|
|
13799
|
+
ChatScrollIndicator,
|
|
13800
|
+
{
|
|
13801
|
+
type: "button",
|
|
13802
|
+
"aria-label": "Scroll to bottom",
|
|
13803
|
+
onClick: scrollToBottom,
|
|
13804
|
+
"data-testid": "chat-scroll-indicator",
|
|
13805
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
13806
|
+
Icon,
|
|
13807
|
+
{
|
|
13808
|
+
cursor: ICON_CURSORS.POINTER,
|
|
13809
|
+
size: ICON_SIZES.SMALL,
|
|
13810
|
+
type: ICON_TYPES.ARROW_DOWN
|
|
13811
|
+
}
|
|
13812
|
+
)
|
|
13813
|
+
}
|
|
13814
|
+
),
|
|
13804
13815
|
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: chatEndRef })
|
|
13805
13816
|
] });
|
|
13806
13817
|
}
|
|
@@ -13949,10 +13960,11 @@ function SearchModal({
|
|
|
13949
13960
|
fallbackImageUrl = "",
|
|
13950
13961
|
enableAIChat = false,
|
|
13951
13962
|
aiChatConfig,
|
|
13963
|
+
gtmContext,
|
|
13952
13964
|
showPricing = true,
|
|
13953
13965
|
aiChatHeaderContent
|
|
13954
13966
|
}) {
|
|
13955
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
13967
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
13956
13968
|
const listboxId = React.useId();
|
|
13957
13969
|
const footerRef = React.useRef(null);
|
|
13958
13970
|
const suggestionRowRefs = React.useRef({});
|
|
@@ -13981,7 +13993,6 @@ function SearchModal({
|
|
|
13981
13993
|
const [aiChatHistory, setAiChatHistory] = React.useState([]);
|
|
13982
13994
|
const [pendingQuery, setPendingQuery] = React.useState("");
|
|
13983
13995
|
const [aiLoading, setAiLoading] = React.useState(false);
|
|
13984
|
-
const [isWaitingForAIFallback, setIsWaitingForAIFallback] = React.useState(false);
|
|
13985
13996
|
const isInChatMode = aiChatHistory.length > 0 || pendingQuery !== "" || aiLoading;
|
|
13986
13997
|
const [aiStatus, setAiStatus] = React.useState("");
|
|
13987
13998
|
const [typedStatus, setTypedStatus] = React.useState("");
|
|
@@ -13993,11 +14004,34 @@ function SearchModal({
|
|
|
13993
14004
|
aiChatConfigRef.current = aiChatConfig;
|
|
13994
14005
|
const aiChatHeaderContentRef = React.useRef(aiChatHeaderContent);
|
|
13995
14006
|
aiChatHeaderContentRef.current = aiChatHeaderContent;
|
|
14007
|
+
const gtmContextRef = React.useRef(gtmContext);
|
|
14008
|
+
gtmContextRef.current = gtmContext;
|
|
13996
14009
|
const historyEntriesRef = React.useRef(historyEntries);
|
|
13997
14010
|
historyEntriesRef.current = historyEntries;
|
|
13998
14011
|
const chatEndRef = React.useRef(null);
|
|
13999
|
-
const aiFallbackTimeoutRef = React.useRef(null);
|
|
14000
14012
|
const aiRequestCounterRef = React.useRef(0);
|
|
14013
|
+
const [suggestionsRequestFailed, setSuggestionsRequestFailed] = React.useState(false);
|
|
14014
|
+
const suggestionAwareService = React.useMemo(
|
|
14015
|
+
() => ({
|
|
14016
|
+
...service,
|
|
14017
|
+
async fetchSuggestions(searchTerm) {
|
|
14018
|
+
setSuggestionsRequestFailed(false);
|
|
14019
|
+
try {
|
|
14020
|
+
const response = await service.fetchSuggestions(searchTerm);
|
|
14021
|
+
setSuggestionsRequestFailed(false);
|
|
14022
|
+
return response;
|
|
14023
|
+
} catch (error) {
|
|
14024
|
+
setSuggestionsRequestFailed(true);
|
|
14025
|
+
throw error;
|
|
14026
|
+
}
|
|
14027
|
+
}
|
|
14028
|
+
}),
|
|
14029
|
+
[service]
|
|
14030
|
+
);
|
|
14031
|
+
const searchSuggestions = reactSearchSdk.useSearchSuggestions({
|
|
14032
|
+
service: suggestionAwareService,
|
|
14033
|
+
enabled: isOpen && !isInChatMode
|
|
14034
|
+
});
|
|
14001
14035
|
const {
|
|
14002
14036
|
didYouMean,
|
|
14003
14037
|
emptyFetched,
|
|
@@ -14007,12 +14041,16 @@ function SearchModal({
|
|
|
14007
14041
|
query,
|
|
14008
14042
|
suggestions,
|
|
14009
14043
|
updateQuery
|
|
14010
|
-
} =
|
|
14044
|
+
} = searchSuggestions;
|
|
14045
|
+
const suggestionFetchFailed = ((_a = searchSuggestions.suggestionFetchFailed) != null ? _a : false) || suggestionsRequestFailed;
|
|
14011
14046
|
const [searchInputValue, setSearchInputValue] = React.useState(query);
|
|
14012
14047
|
const searchInputValueRef = React.useRef(query);
|
|
14013
14048
|
const voiceInputBaseValueRef = React.useRef(query);
|
|
14014
14049
|
const setSearchInput = React.useCallback(
|
|
14015
|
-
(value, updateVoiceBase = true) => {
|
|
14050
|
+
(value, updateVoiceBase = true, resetSuggestionFailure = true) => {
|
|
14051
|
+
if (resetSuggestionFailure) {
|
|
14052
|
+
setSuggestionsRequestFailed(false);
|
|
14053
|
+
}
|
|
14016
14054
|
searchInputValueRef.current = value;
|
|
14017
14055
|
if (updateVoiceBase) {
|
|
14018
14056
|
voiceInputBaseValueRef.current = value;
|
|
@@ -14054,20 +14092,14 @@ function SearchModal({
|
|
|
14054
14092
|
const hasDidYouMean = didYouMean.length > 0;
|
|
14055
14093
|
const showDidYouMean = hasDidYouMean && !enableAIChat;
|
|
14056
14094
|
const visibleSuggestions = enableAIChat ? suggestions : reactSearchSdk.getVisibleSuggestions({ didYouMean, suggestions });
|
|
14057
|
-
const visibleSuggestionsRef = React.useRef(visibleSuggestions);
|
|
14058
|
-
visibleSuggestionsRef.current = visibleSuggestions;
|
|
14059
|
-
const hasDidYouMeanRef = React.useRef(hasDidYouMean);
|
|
14060
|
-
hasDidYouMeanRef.current = hasDidYouMean;
|
|
14061
|
-
const loadingRef = React.useRef(loading);
|
|
14062
|
-
loadingRef.current = loading;
|
|
14063
14095
|
const safeUseVoiceSearch = reactSearchSdk.useVoiceSearch;
|
|
14064
14096
|
const voiceSearchRaw = safeUseVoiceSearch({
|
|
14065
14097
|
onInterimResult: previewVoiceResult,
|
|
14066
14098
|
onResult: appendVoiceResult
|
|
14067
14099
|
});
|
|
14068
14100
|
const voiceSearch = isVoiceSearchState(voiceSearchRaw) ? voiceSearchRaw : null;
|
|
14069
|
-
const voiceListening = (
|
|
14070
|
-
const voiceSupported = (
|
|
14101
|
+
const voiceListening = (_b = voiceSearch == null ? void 0 : voiceSearch.listening) != null ? _b : false;
|
|
14102
|
+
const voiceSupported = (_c = voiceSearch == null ? void 0 : voiceSearch.supported) != null ? _c : false;
|
|
14071
14103
|
const startVoice = voiceSearch == null ? void 0 : voiceSearch.start;
|
|
14072
14104
|
const stopVoice = voiceSearch == null ? void 0 : voiceSearch.stop;
|
|
14073
14105
|
const toggleVoice = React.useCallback(() => {
|
|
@@ -14078,10 +14110,9 @@ function SearchModal({
|
|
|
14078
14110
|
voiceInputBaseValueRef.current = searchInputValueRef.current.trimEnd();
|
|
14079
14111
|
startVoice == null ? void 0 : startVoice();
|
|
14080
14112
|
}, [startVoice, stopVoice, voiceListening]);
|
|
14081
|
-
const showPricingFromHeader = ((
|
|
14113
|
+
const showPricingFromHeader = ((_e = (_d = aiChatHeaderContentRef.current) == null ? void 0 : _d.configurations) == null ? void 0 : _e.enablepricingpvsv) !== "false";
|
|
14082
14114
|
const resolvedShowPricing = aiChatHeaderContent ? showPricingFromHeader : showPricing;
|
|
14083
14115
|
const aiStatusLabels = getAIStatusLabels(copy);
|
|
14084
|
-
const aiAutoTriggerDelayMs = getAITriggerDelayMs(aiChatConfig == null ? void 0 : aiChatConfig.aiAutoTriggerDelayMs);
|
|
14085
14116
|
function voiceSearchProps() {
|
|
14086
14117
|
var _a2;
|
|
14087
14118
|
if (!voiceSupported || !startVoice) return {};
|
|
@@ -14093,12 +14124,22 @@ function SearchModal({
|
|
|
14093
14124
|
onVoiceInput: toggleVoice
|
|
14094
14125
|
};
|
|
14095
14126
|
}
|
|
14127
|
+
const buildGtmContext = React.useCallback(() => {
|
|
14128
|
+
var _a2;
|
|
14129
|
+
return (_a2 = gtmContextRef.current) != null ? _a2 : {};
|
|
14130
|
+
}, []);
|
|
14131
|
+
const chatEntryFiredRef = React.useRef(false);
|
|
14096
14132
|
React.useEffect(() => {
|
|
14097
|
-
if (isOpen)
|
|
14098
|
-
|
|
14099
|
-
|
|
14100
|
-
aiFallbackTimeoutRef.current = null;
|
|
14133
|
+
if (!isOpen) {
|
|
14134
|
+
chatEntryFiredRef.current = false;
|
|
14135
|
+
return;
|
|
14101
14136
|
}
|
|
14137
|
+
if (!enableAIChat || chatEntryFiredRef.current) return;
|
|
14138
|
+
chatEntryFiredRef.current = true;
|
|
14139
|
+
reactSearchSdk.trackChatEntryPoint(buildGtmContext());
|
|
14140
|
+
}, [isOpen, enableAIChat, buildGtmContext]);
|
|
14141
|
+
React.useEffect(() => {
|
|
14142
|
+
if (isOpen) return;
|
|
14102
14143
|
updateQuery("");
|
|
14103
14144
|
setAiChatHistory([]);
|
|
14104
14145
|
setPendingQuery("");
|
|
@@ -14155,46 +14196,21 @@ function SearchModal({
|
|
|
14155
14196
|
document.body.style.overflow = "";
|
|
14156
14197
|
};
|
|
14157
14198
|
}, [isOpen, onClose]);
|
|
14158
|
-
React.useEffect(() => {
|
|
14159
|
-
if (aiFallbackTimeoutRef.current) {
|
|
14160
|
-
clearTimeout(aiFallbackTimeoutRef.current);
|
|
14161
|
-
aiFallbackTimeoutRef.current = null;
|
|
14162
|
-
}
|
|
14163
|
-
setIsWaitingForAIFallback(false);
|
|
14164
|
-
if (!enableAIChat || !isOpen || isInChatMode || !hasQuery) return void 0;
|
|
14165
|
-
const trimmedQuery = query.trim();
|
|
14166
|
-
if (!trimmedQuery) return void 0;
|
|
14167
|
-
const alreadyAnswered = historyEntriesRef.current.some(
|
|
14168
|
-
(e) => e.isAI && e.query.toLowerCase() === trimmedQuery.toLowerCase()
|
|
14169
|
-
);
|
|
14170
|
-
if (alreadyAnswered) return void 0;
|
|
14171
|
-
setIsWaitingForAIFallback(true);
|
|
14172
|
-
aiFallbackTimeoutRef.current = setTimeout(() => {
|
|
14173
|
-
aiFallbackTimeoutRef.current = null;
|
|
14174
|
-
setIsWaitingForAIFallback(false);
|
|
14175
|
-
if (!loadingRef.current && visibleSuggestionsRef.current.length > 0 && !hasDidYouMeanRef.current) {
|
|
14176
|
-
return;
|
|
14177
|
-
}
|
|
14178
|
-
sendAIMessage(trimmedQuery);
|
|
14179
|
-
}, aiAutoTriggerDelayMs);
|
|
14180
|
-
return () => {
|
|
14181
|
-
if (aiFallbackTimeoutRef.current) {
|
|
14182
|
-
clearTimeout(aiFallbackTimeoutRef.current);
|
|
14183
|
-
aiFallbackTimeoutRef.current = null;
|
|
14184
|
-
}
|
|
14185
|
-
setIsWaitingForAIFallback(false);
|
|
14186
|
-
};
|
|
14187
|
-
}, [enableAIChat, isOpen, isInChatMode, hasQuery, query]);
|
|
14188
14199
|
const sendAIMessage = React.useCallback(
|
|
14189
14200
|
(queryText) => {
|
|
14190
|
-
var _a2;
|
|
14191
14201
|
const config = aiChatConfigRef.current;
|
|
14192
14202
|
if (!config || !queryText.trim()) return;
|
|
14193
|
-
setSearchInput("");
|
|
14203
|
+
setSearchInput("", true, false);
|
|
14194
14204
|
setPendingQuery(queryText.trim());
|
|
14195
14205
|
setAiStatus(aiStatusLabels.analyzing);
|
|
14206
|
+
const trimmedQuery = queryText.trim();
|
|
14207
|
+
reactSearchSdk.trackSearchType({
|
|
14208
|
+
...buildGtmContext(),
|
|
14209
|
+
searchType: reactSearchSdk.SEARCH_GTM_SEARCH_TYPES.AI_AGENT,
|
|
14210
|
+
searchResponse: trimmedQuery
|
|
14211
|
+
});
|
|
14196
14212
|
const requestId = aiRequestCounterRef.current;
|
|
14197
|
-
const
|
|
14213
|
+
const productBasePath = `/${config.market.toLowerCase()}/${config.language.toLowerCase()}/product`;
|
|
14198
14214
|
const chatService = reactSearchSdk.createChatService({
|
|
14199
14215
|
conversationsUrl: config.conversationsUrl,
|
|
14200
14216
|
messagesUrl: config.messagesUrl,
|
|
@@ -14220,8 +14236,8 @@ function SearchModal({
|
|
|
14220
14236
|
).then((result) => {
|
|
14221
14237
|
if (!result || requestId !== aiRequestCounterRef.current) return;
|
|
14222
14238
|
const products = result.products.map((p, i) => {
|
|
14223
|
-
var
|
|
14224
|
-
const productId = getProductId((_b2 = (
|
|
14239
|
+
var _a2, _b2;
|
|
14240
|
+
const productId = getProductId((_b2 = (_a2 = p.id) != null ? _a2 : p.sku) != null ? _b2 : i);
|
|
14225
14241
|
const productName = getProductName(p, productId);
|
|
14226
14242
|
return {
|
|
14227
14243
|
id: productId,
|
|
@@ -14232,7 +14248,10 @@ function SearchModal({
|
|
|
14232
14248
|
...p.retail_price != null ? { retail_price: p.retail_price } : {},
|
|
14233
14249
|
...p.description ? { description: p.description } : {},
|
|
14234
14250
|
...p.badge ? { badge: p.badge } : {},
|
|
14235
|
-
...p.sku != null ? {
|
|
14251
|
+
...p.sku != null ? {
|
|
14252
|
+
url: `${productBasePath}/${p.sku}`,
|
|
14253
|
+
routeUrl: `/product/${p.sku}`
|
|
14254
|
+
} : {}
|
|
14236
14255
|
};
|
|
14237
14256
|
});
|
|
14238
14257
|
setAiStatus("");
|
|
@@ -14245,14 +14264,24 @@ function SearchModal({
|
|
|
14245
14264
|
const priorHistory = historyEntriesRef.current.filter((e) => e.isAI && e.aiResult != null).slice().reverse().map((e) => e.aiResult);
|
|
14246
14265
|
setAiChatHistory([...priorHistory, newResult]);
|
|
14247
14266
|
historyAddEntry({ query: queryText.trim(), isAI: true, aiResult: newResult });
|
|
14267
|
+
reactSearchSdk.trackProductSearch({
|
|
14268
|
+
...buildGtmContext(),
|
|
14269
|
+
searchType: reactSearchSdk.SEARCH_GTM_SEARCH_TYPES.AI_AGENT,
|
|
14270
|
+
productResults: products.length,
|
|
14271
|
+
productResultsData: products
|
|
14272
|
+
});
|
|
14248
14273
|
}).catch(() => {
|
|
14249
14274
|
setPendingQuery("");
|
|
14250
14275
|
setAiStatus("");
|
|
14276
|
+
reactSearchSdk.trackErrorPopup({
|
|
14277
|
+
...buildGtmContext(),
|
|
14278
|
+
searchType: reactSearchSdk.SEARCH_GTM_SEARCH_TYPES.AI_AGENT
|
|
14279
|
+
});
|
|
14251
14280
|
}).finally(() => {
|
|
14252
14281
|
if (requestId === aiRequestCounterRef.current) setAiLoading(false);
|
|
14253
14282
|
});
|
|
14254
14283
|
},
|
|
14255
|
-
[aiStatusLabels, historyAddEntry, setSearchInput]
|
|
14284
|
+
[aiStatusLabels, historyAddEntry, setSearchInput, buildGtmContext]
|
|
14256
14285
|
);
|
|
14257
14286
|
const selectOption = React.useCallback(
|
|
14258
14287
|
(option) => {
|
|
@@ -14260,9 +14289,16 @@ function SearchModal({
|
|
|
14260
14289
|
if (reactSearchSdk.isSuggestionDisabled(option)) return;
|
|
14261
14290
|
const term = String((_b2 = (_a2 = option["value"]) != null ? _a2 : option["label"]) != null ? _b2 : "");
|
|
14262
14291
|
historyAddEntry({ query: term, isAI: false });
|
|
14292
|
+
if (term.trim()) {
|
|
14293
|
+
reactSearchSdk.trackProductSearch({
|
|
14294
|
+
...buildGtmContext(),
|
|
14295
|
+
searchType: reactSearchSdk.SEARCH_GTM_SEARCH_TYPES.SEMANTIC,
|
|
14296
|
+
productResultsData: [option]
|
|
14297
|
+
});
|
|
14298
|
+
}
|
|
14263
14299
|
const optionHref = service.getSuggestionHref(option);
|
|
14264
|
-
if (optionHref
|
|
14265
|
-
history
|
|
14300
|
+
if (optionHref) {
|
|
14301
|
+
pushSearchPath(history, optionHref);
|
|
14266
14302
|
onClose();
|
|
14267
14303
|
return;
|
|
14268
14304
|
}
|
|
@@ -14273,7 +14309,7 @@ function SearchModal({
|
|
|
14273
14309
|
if (!enableAIChat) setLegacyRecentSearches((_d2 = (_c2 = service.getRecentSearches) == null ? void 0 : _c2.call(service)) != null ? _d2 : []);
|
|
14274
14310
|
onClose();
|
|
14275
14311
|
},
|
|
14276
|
-
[enableAIChat, service, onClose, historyAddEntry, history]
|
|
14312
|
+
[buildGtmContext, enableAIChat, service, onClose, historyAddEntry, history]
|
|
14277
14313
|
);
|
|
14278
14314
|
const runSuggestionAction = React.useCallback(
|
|
14279
14315
|
(option) => {
|
|
@@ -14293,6 +14329,13 @@ function SearchModal({
|
|
|
14293
14329
|
setHighlightedQuery(entry.query);
|
|
14294
14330
|
} else {
|
|
14295
14331
|
historyAddEntry({ query: entry.query, isAI: false });
|
|
14332
|
+
if (entry.query.trim()) {
|
|
14333
|
+
reactSearchSdk.trackProductSearch({
|
|
14334
|
+
...buildGtmContext(),
|
|
14335
|
+
searchType: reactSearchSdk.SEARCH_GTM_SEARCH_TYPES.SEMANTIC,
|
|
14336
|
+
productResultsData: { query: entry.query.trim() }
|
|
14337
|
+
});
|
|
14338
|
+
}
|
|
14296
14339
|
const url = service.submitProductSearch(entry.query);
|
|
14297
14340
|
if (url && history && typeof history.push === "function") {
|
|
14298
14341
|
history.push(url);
|
|
@@ -14301,7 +14344,7 @@ function SearchModal({
|
|
|
14301
14344
|
onClose();
|
|
14302
14345
|
}
|
|
14303
14346
|
},
|
|
14304
|
-
[enableAIChat, service, onClose, historyAddEntry, history]
|
|
14347
|
+
[buildGtmContext, enableAIChat, service, onClose, historyAddEntry, history]
|
|
14305
14348
|
);
|
|
14306
14349
|
const handleClearRecentSearches = React.useCallback(() => {
|
|
14307
14350
|
clearRecentSearches();
|
|
@@ -14314,22 +14357,44 @@ function SearchModal({
|
|
|
14314
14357
|
const handleSearchSubmit = React.useCallback(
|
|
14315
14358
|
(value) => {
|
|
14316
14359
|
var _a2, _b2;
|
|
14360
|
+
if (enableAIChat && suggestionFetchFailed) {
|
|
14361
|
+
sendAIMessage(value);
|
|
14362
|
+
return;
|
|
14363
|
+
}
|
|
14317
14364
|
historyAddEntry({ query: value, isAI: false });
|
|
14365
|
+
const trimmed = value.trim();
|
|
14366
|
+
if (trimmed) {
|
|
14367
|
+
reactSearchSdk.trackProductSearch({
|
|
14368
|
+
...buildGtmContext(),
|
|
14369
|
+
searchType: reactSearchSdk.SEARCH_GTM_SEARCH_TYPES.SEMANTIC,
|
|
14370
|
+
productResultsData: visibleSuggestions.length > 0 ? visibleSuggestions : { query: trimmed }
|
|
14371
|
+
});
|
|
14372
|
+
}
|
|
14318
14373
|
const url = service.submitProductSearch(value);
|
|
14319
14374
|
pushSearchPath(history, url);
|
|
14320
14375
|
if (!enableAIChat) setLegacyRecentSearches((_b2 = (_a2 = service.getRecentSearches) == null ? void 0 : _a2.call(service)) != null ? _b2 : []);
|
|
14321
14376
|
onClose();
|
|
14322
14377
|
},
|
|
14323
|
-
[
|
|
14378
|
+
[
|
|
14379
|
+
buildGtmContext,
|
|
14380
|
+
enableAIChat,
|
|
14381
|
+
history,
|
|
14382
|
+
historyAddEntry,
|
|
14383
|
+
onClose,
|
|
14384
|
+
sendAIMessage,
|
|
14385
|
+
service,
|
|
14386
|
+
suggestionFetchFailed,
|
|
14387
|
+
visibleSuggestions
|
|
14388
|
+
]
|
|
14324
14389
|
);
|
|
14325
14390
|
if (!isOpen) return null;
|
|
14326
|
-
const placeholder = (
|
|
14327
|
-
const ariaLabel = (
|
|
14328
|
-
const didYouMeanText = (
|
|
14329
|
-
const noSuggestionsText = (
|
|
14330
|
-
const seeMoreText = (
|
|
14391
|
+
const placeholder = (_f = copy == null ? void 0 : copy.extended_search_textbox_desktop) != null ? _f : "Search";
|
|
14392
|
+
const ariaLabel = (_g = copy == null ? void 0 : copy.extended_search_box_aria_label) != null ? _g : placeholder;
|
|
14393
|
+
const didYouMeanText = (_h = copy == null ? void 0 : copy.did_you_mean_text) != null ? _h : "Did You Mean?";
|
|
14394
|
+
const noSuggestionsText = (_i = copy == null ? void 0 : copy.no_suggestions_text) != null ? _i : "No suggestions";
|
|
14395
|
+
const seeMoreText = (_j = copy == null ? void 0 : copy.see_more_results_text) != null ? _j : "See More Results";
|
|
14331
14396
|
const showRecentSearches = !hasQuery && !aiLoading && !isInChatMode && recentSearches.length > 0;
|
|
14332
|
-
const showNoResults = !isInChatMode && !loading && emptyFetched && visibleSuggestions.length === 0 && !aiLoading
|
|
14397
|
+
const showNoResults = !isInChatMode && !loading && emptyFetched && visibleSuggestions.length === 0 && !aiLoading;
|
|
14333
14398
|
const searchInput = /* @__PURE__ */ jsxRuntime.jsx(
|
|
14334
14399
|
SearchMessageInput,
|
|
14335
14400
|
{
|
|
@@ -14415,7 +14480,7 @@ function SearchModal({
|
|
|
14415
14480
|
query,
|
|
14416
14481
|
showRecentSearches,
|
|
14417
14482
|
handleClearRecentSearches,
|
|
14418
|
-
clearAllLabel: (
|
|
14483
|
+
clearAllLabel: (_k = copy == null ? void 0 : copy.clear_all_label) != null ? _k : "Clear all",
|
|
14419
14484
|
showAllRecent,
|
|
14420
14485
|
recentSearches,
|
|
14421
14486
|
handleRecentSearchSelect,
|