@askdialog/dialog-react 2.1.0 → 2.2.1

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/README.md CHANGED
@@ -86,6 +86,71 @@ Standalone input component for asking questions.
86
86
  />
87
87
  ```
88
88
 
89
+ ### Storefront search
90
+
91
+ React binding of the SDK search controller (`createSearchController`): debounce, cancellation, stale-response protection, pagination and search attribution analytics all come from the SDK — these components only render and route.
92
+
93
+ ```tsx
94
+ import { Dialog } from '@askdialog/dialog-sdk';
95
+ import {
96
+ DialogSearchBar,
97
+ DialogSearchResults,
98
+ useDialogSearch,
99
+ } from '@askdialog/dialog-react';
100
+ import '@askdialog/dialog-react/style.css';
101
+
102
+ const client = new Dialog({ apiKey: 'your-api-key', locale: 'en' });
103
+
104
+ function SearchPage() {
105
+ const { controller, state } = useDialogSearch({ client });
106
+
107
+ return (
108
+ <>
109
+ <DialogSearchBar controller={controller} placeholder="Search products..." />
110
+ <DialogSearchResults controller={controller} state={state} />
111
+ </>
112
+ );
113
+ }
114
+ ```
115
+
116
+ #### useDialogSearch
117
+
118
+ Creates one search controller per hook instance and disposes it on unmount.
119
+
120
+ **Options:**
121
+ - `client` (Dialog) - Dialog SDK client instance (required)
122
+ - `surface` (SearchSurface, optional) - Where results are displayed, for analytics (default: `'search_page'`)
123
+ - `navigate` ((url, hit) => void, optional) - Router adapter called after selection attribution (e.g. `(url) => router.push(url)`). Omit it to let the cards' plain `<a href>` links navigate natively.
124
+ - `debounceMs` (number, optional) - Keystroke debounce (default: 250)
125
+ - `hitsPerPage` (number, optional) - Results per page (default: 12)
126
+
127
+ **Returns:** `{ controller, state }` — pass both to the components below. `state.status` is `idle` / `loading` / `success` / `empty` / `error`.
128
+
129
+ #### DialogSearchBar
130
+
131
+ Search input: typing runs a debounced search, submitting (Enter) searches immediately.
132
+
133
+ **Props:**
134
+ - `controller` (SearchController) - From `useDialogSearch` (required)
135
+ - `placeholder` (string, optional) - Input placeholder text
136
+ - `autoFocus` (boolean, optional) - Focus the input on mount
137
+
138
+ #### DialogSearchResults
139
+
140
+ Floating results panel overlaying the page content: portaled to `document.body` in `position: fixed`, anchored under the spot where the component is rendered (place it right after the bar), so no ancestor stacking context or `overflow: hidden` can hide it. Renders the controller states; successful searches render a scrollable list of `DialogSearchProductCard` rows plus the pagination controls. Each card links to the product page and records search attribution (viewport impressions, select on click and middle-click) automatically. Clicking outside the panel (and outside the bar) closes it; typing again or re-focusing the bar reopens it with the results kept.
141
+
142
+ **Props:**
143
+ - `controller` (SearchController) - From `useDialogSearch` (required)
144
+ - `state` (SearchControllerState) - From `useDialogSearch` (required)
145
+
146
+ #### DialogSearchPagination
147
+
148
+ Previous/next controls with a page indicator; hidden while there is a single page. Rendered by `DialogSearchResults` — exported only for custom layouts.
149
+
150
+ **Props:**
151
+ - `controller` (SearchController) - From `useDialogSearch` (required)
152
+ - `state` (SearchControllerState) - From `useDialogSearch` (required)
153
+
89
154
  ## Theming
90
155
 
91
156
  The components use CSS variables for theming. You can customize the theme through the Dialog SDK client:
@@ -0,0 +1,10 @@
1
+ import { FC } from 'react';
2
+ import { SearchController } from '@askdialog/dialog-sdk';
3
+ interface DialogSearchBarProps {
4
+ controller: SearchController;
5
+ placeholder?: string;
6
+ autoFocus?: boolean;
7
+ submitAriaLabel?: string;
8
+ }
9
+ export declare const DialogSearchBar: FC<DialogSearchBarProps>;
10
+ export {};
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import { SearchController, SearchControllerState } from '@askdialog/dialog-sdk';
3
+ interface DialogSearchPaginationProps {
4
+ controller: SearchController;
5
+ state: SearchControllerState;
6
+ }
7
+ export declare const DialogSearchPagination: FC<DialogSearchPaginationProps>;
8
+ export {};
@@ -0,0 +1,9 @@
1
+ import { FC } from 'react';
2
+ import { SearchController, SearchHit } from '@askdialog/dialog-sdk';
3
+ interface DialogSearchProductCardProps {
4
+ controller: SearchController;
5
+ hit: SearchHit;
6
+ index: number;
7
+ }
8
+ export declare const DialogSearchProductCard: FC<DialogSearchProductCardProps>;
9
+ export {};
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import { SearchController, SearchControllerState } from '@askdialog/dialog-sdk';
3
+ interface DialogSearchResultsProps {
4
+ controller: SearchController;
5
+ state: SearchControllerState;
6
+ }
7
+ export declare const DialogSearchResults: FC<DialogSearchResultsProps>;
8
+ export {};
@@ -0,0 +1,3 @@
1
+ import { SearchPriceRange } from '@askdialog/dialog-sdk';
2
+ export declare const formatSearchPrice: (priceRange: SearchPriceRange | undefined) => string;
3
+ export declare const safeProductHref: (url: string) => string | undefined;
@@ -0,0 +1,12 @@
1
+ import { RefObject } from 'react';
2
+ export interface AnchorRect {
3
+ top: number;
4
+ bottom: number;
5
+ left: number;
6
+ width: number;
7
+ }
8
+ export declare const useAnchorRect: (active: boolean) => {
9
+ anchorRef: RefObject<HTMLDivElement | null>;
10
+ rect: AnchorRect | undefined;
11
+ viewportHeight: number;
12
+ };
@@ -0,0 +1,16 @@
1
+ import { Dialog, SearchController, SearchControllerState, SearchHit, SearchSurface } from '@askdialog/dialog-sdk';
2
+ export interface UseDialogSearchOptions {
3
+ client: Dialog;
4
+ /** Where the results are displayed, for search analytics. */
5
+ surface?: SearchSurface;
6
+ /** Router adapter called after selection attribution; omit to let the cards' `<a href>` navigate natively. */
7
+ navigate?: (url: string, hit: SearchHit) => void;
8
+ debounceMs?: number;
9
+ hitsPerPage?: number;
10
+ }
11
+ export interface DialogSearch {
12
+ controller: SearchController;
13
+ state: SearchControllerState;
14
+ }
15
+ /** Options are read when the controller is created — later changes don't rebind a live controller. */
16
+ export declare const useDialogSearch: (options: UseDialogSearchOptions) => DialogSearch;
@@ -0,0 +1,6 @@
1
+ import { RefObject } from 'react';
2
+ import { SearchControllerState } from '@askdialog/dialog-sdk';
3
+ export declare const useOutsideDismiss: (state: SearchControllerState, anchorRef: RefObject<HTMLDivElement | null>) => {
4
+ isOpen: boolean;
5
+ panelRef: RefObject<HTMLDivElement | null>;
6
+ };
@@ -1,2 +1,7 @@
1
1
  export { DialogProductBlock } from './DialogProductBlock/DialogProductBlock';
2
2
  export { DialogInput } from './DialogProductBlock/DialogInput';
3
+ export { DialogSearchBar } from './DialogSearch/DialogSearchBar';
4
+ export { DialogSearchPagination } from './DialogSearch/DialogSearchPagination';
5
+ export { DialogSearchProductCard } from './DialogSearch/DialogSearchProductCard';
6
+ export { DialogSearchResults } from './DialogSearch/DialogSearchResults';
7
+ export { useDialogSearch, type DialogSearch, type UseDialogSearchOptions, } from './DialogSearch/useDialogSearch';
@@ -1 +1 @@
1
- .dialog-block-header-container{display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start}.dialog-block-title{color:var(--dialog-theme-title-color, #272727);font-family:var(--dialog-theme-font-family);font-size:var(--dialog-theme-title-font-size);font-style:normal;font-weight:500;line-height:20px;letter-spacing:1.3px;text-transform:uppercase}.dialog-block-description{color:var(--dialog-theme-description-color, #6c6c6c);font-family:var(--dialog-theme-font-family);font-size:var(--dialog-theme-description-font-size);font-style:normal;font-weight:500;line-height:20px}.dialog-block-suggestions-item{background-color:#f1f1f1;border:none;outline:none;padding:12px 16px;width:fit-content;cursor:pointer;display:flex;justify-content:flex-start;background-color:#fff;align-items:center;gap:8px;border:1px solid #dddce2;border-radius:24px}.dialog-block-suggestions-item:hover{transform:scale(1.01)}.dialog-block-suggestions-item-label{color:var(--dialog-theme-content-color, #575665);font-size:var(--dialog-theme-content-font-size, 14px);font-weight:500;text-align:left;flex:1}.dialog-block-suggestions-item-icon path{stroke:var(--dialog-theme-primary-color)}.dialog-block-suggestions-skeleton-item,.dialog-block-suggestions-skeleton-item:empty{display:block;width:100%;width:90%;height:18px;border-radius:18px;padding:12px 16px;background-color:#f1f1f1;animation:pulse 1.5s ease-in-out infinite}@keyframes pulse{0%{background-color:#f1f1f1}50%{background-color:#fff}to{background-color:#f1f1f1}}.dialog-block-suggestions-container{display:flex;flex-direction:column;gap:12px;width:100%}.dialog-input-wrapper{position:relative;width:100%;height:50px;max-height:50px;padding:16px 20px;border:1px solid #d9d9d9;border-radius:var(--dialog-theme-cta-border-type, 24px);background:#fff;display:flex;align-items:center;box-sizing:border-box}.dialog-input-container{display:flex;justify-items:center;align-items:center;gap:12px;width:100%;height:100%}.dialog-ask-anything-input-ai-input{outline:unset;box-shadow:unset;border:unset;width:100%;font-size:16px;background:transparent;padding-right:35px}.dialog-input-submit{width:40px;height:40px;border-radius:100%;display:flex;align-items:center;justify-content:center;background-color:var(--dialog-theme-primary-color);position:absolute;cursor:pointer;top:calc(50% - 20px);right:4px;border:unset}.dialog-input-submit:disabled{opacity:.5}.dialog-block-container{position:relative;display:flex;flex-direction:column;justify-content:flex-start;align-items:flex-start;padding:24px 0;width:fit-content;gap:24px}.dialog-block-container>*{box-sizing:border-box}
1
+ .dialog-block-header-container{display:flex;flex-direction:column;align-items:flex-start;justify-content:flex-start}.dialog-block-title{color:var(--dialog-theme-title-color, #272727);font-family:var(--dialog-theme-font-family);font-size:var(--dialog-theme-title-font-size);font-style:normal;font-weight:500;line-height:20px;letter-spacing:1.3px;text-transform:uppercase}.dialog-block-description{color:var(--dialog-theme-description-color, #6c6c6c);font-family:var(--dialog-theme-font-family);font-size:var(--dialog-theme-description-font-size);font-style:normal;font-weight:500;line-height:20px}.dialog-block-suggestions-item{background-color:#f1f1f1;border:none;outline:none;padding:12px 16px;width:fit-content;cursor:pointer;display:flex;justify-content:flex-start;background-color:#fff;align-items:center;gap:8px;border:1px solid #dddce2;border-radius:24px}.dialog-block-suggestions-item:hover{transform:scale(1.01)}.dialog-block-suggestions-item-label{color:var(--dialog-theme-content-color, #575665);font-size:var(--dialog-theme-content-font-size, 14px);font-weight:500;text-align:start;flex:1}.dialog-block-suggestions-item-icon path{stroke:var(--dialog-theme-primary-color)}.dialog-block-suggestions-skeleton-item,.dialog-block-suggestions-skeleton-item:empty{display:block;width:100%;width:90%;height:18px;border-radius:18px;padding:12px 16px;background-color:#f1f1f1;animation:pulse 1.5s ease-in-out infinite}@keyframes pulse{0%{background-color:#f1f1f1}50%{background-color:#fff}to{background-color:#f1f1f1}}.dialog-block-suggestions-container{display:flex;flex-direction:column;gap:12px;width:100%}.dialog-input-wrapper{position:relative;width:100%;height:50px;max-height:50px;padding:16px 20px;border:1px solid #d9d9d9;border-radius:var(--dialog-theme-cta-border-type, 24px);background:#fff;display:flex;align-items:center;box-sizing:border-box}.dialog-input-container{display:flex;justify-items:center;align-items:center;gap:12px;width:100%;height:100%}.dialog-ask-anything-input-ai-input{outline:unset;box-shadow:unset;border:unset;width:100%;font-size:16px;background:transparent;padding-inline-end:35px}.dialog-input-submit{width:40px;height:40px;border-radius:100%;display:flex;align-items:center;justify-content:center;background-color:var(--dialog-theme-primary-color);position:absolute;cursor:pointer;top:calc(50% - 20px);inset-inline-end:4px;border:unset}.dialog-input-submit:disabled{opacity:.5}.dialog-block-container{position:relative;display:flex;flex-direction:column;justify-content:flex-start;align-items:flex-start;padding:24px 0;width:fit-content;gap:24px}.dialog-block-container>*{box-sizing:border-box}.dialog-search-bar{box-sizing:border-box;display:flex;align-items:center;gap:8px;width:100%;margin:0;padding:10px 10px 10px 14px;background:#fffc;backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);border:1px solid rgba(0,0,0,.05);border-radius:24px;box-shadow:0 6px 20px -6px #0000001a}.dialog-search-bar:focus-within{border-color:#00000026;box-shadow:0 6px 20px -6px #0000001a,0 0 0 2px #1717171f}.dialog-search-bar-field{display:flex;flex:1 0 0;min-width:0;align-items:center;gap:6px;padding:2px 0}.dialog-search-bar-icon{display:inline-flex;flex-shrink:0;color:#737373}.dialog-search-bar-input{flex:1 0 0;min-width:0;margin:0;padding:0;border:none;outline:none;background:transparent;font-family:Inter,sans-serif;font-weight:500;font-size:16px;line-height:24px;color:#171717;text-overflow:ellipsis;box-shadow:none;-moz-appearance:none;appearance:none;-webkit-appearance:none}.dialog-search-bar-input::placeholder{color:#a3a3a3;opacity:1}.dialog-search-bar-input:focus,.dialog-search-bar-input:focus-visible{outline:none;box-shadow:none;border:none}.dialog-search-bar-submit{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;width:28px;height:28px;padding:6px;border:none;border-radius:9999px;background:#171717;color:#fff;box-shadow:0 1px 1px #1717170d;cursor:pointer}.dialog-search-bar-submit:focus-visible{outline:2px solid #171717;outline-offset:2px}.dialog-search-pagination{display:flex;align-items:center;justify-content:center;gap:12px;margin-top:4px;font-family:Inter,sans-serif;font-weight:500;font-size:12px;line-height:16px;color:#737373}.dialog-search-pagination button{margin:0;padding:6px 14px;border:1px solid rgba(0,0,0,.05);border-radius:9999px;background:#fff;font:inherit;color:inherit;cursor:pointer;transition:background-color .12s ease}.dialog-search-pagination button:hover:not(:disabled){background-color:#fafafa}.dialog-search-pagination button:disabled{opacity:.4;cursor:default}.dialog-search-card{width:100%}.dialog-search-card-body{display:flex;align-items:center;gap:8px;border-radius:12px;color:inherit;text-decoration:none}a.dialog-search-card-body:hover{background:#00000008}.dialog-search-card-image{position:relative;flex-shrink:0;width:64px;height:64px;border-radius:12px;overflow:hidden;background:#f2f2f2}.dialog-search-card-image:after{content:"";position:absolute;top:0;right:0;bottom:0;left:0;border-radius:12px;background:#00000008;pointer-events:none}.dialog-search-card-image img{display:block;width:100%;height:100%;object-fit:cover}.dialog-search-card-info{display:flex;flex:1 1 0;min-width:0;flex-direction:column;gap:4px}.dialog-search-card-title{margin:0;font-family:Inter,sans-serif;font-weight:500;font-size:13px;line-height:20px;color:#171717;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dialog-search-card-price{margin:0;font-family:Inter,sans-serif;font-weight:500;font-size:12px;line-height:16px;color:#737373}.dialog-search-panel{position:fixed;z-index:9999;box-sizing:border-box;display:flex;flex-direction:column;gap:8px;margin:0;padding:10px 14px;background:#ffffffe6;backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px);border:1px solid rgba(0,0,0,.05);border-radius:24px;box-shadow:0 6px 20px -6px #0000001a}.dialog-search-status{margin:0;font-family:Inter,sans-serif;font-weight:500;font-size:14px;line-height:20px;color:#a3a3a3}.dialog-search-status-error{color:#b3261e}.dialog-search-error{display:flex;flex-direction:column;align-items:flex-start;gap:8px}.dialog-search-retry{margin:0;padding:6px 14px;border:1px solid rgba(0,0,0,.05);border-radius:9999px;background:#fff;font-family:Inter,sans-serif;font-weight:500;font-size:13px;line-height:20px;color:#737373;cursor:pointer;transition:background-color .12s ease}.dialog-search-retry:hover{background-color:#fafafa}.dialog-search-results{display:flex;flex-direction:column;gap:12px;margin:0;padding:0;list-style:none;max-height:480px;min-height:0;overflow-y:auto}
@@ -1,13 +1,14 @@
1
- import { jsxs as d, jsx as t, Fragment as f } from "react/jsx-runtime";
2
- import { useRef as L, useState as k, useEffect as C, useMemo as m } from "react";
3
- import { registerDialogInstallation as v, addAuditCapability as w } from "@askdialog/dialog-sdk";
4
- const S = ({
1
+ import { jsxs as h, jsx as n, Fragment as y } from "react/jsx-runtime";
2
+ import { useRef as v, useState as C, useEffect as f, useMemo as S, useLayoutEffect as R, useCallback as N, useSyncExternalStore as x } from "react";
3
+ import { registerDialogInstallation as E, addAuditCapability as A, resolveTextDirection as D, SearchStatus as b, DialogSearchError as I, createSearchController as M } from "@askdialog/dialog-sdk";
4
+ import { createPortal as B } from "react-dom";
5
+ const _ = ({
5
6
  title: e = "Your expert",
6
- description: i = "A question about this product?"
7
- }) => /* @__PURE__ */ d("div", { className: "dialog-block-header-container", children: [
8
- /* @__PURE__ */ t("div", { className: "dialog-block-title", children: e }),
9
- /* @__PURE__ */ t("div", { className: "dialog-block-description", children: i })
10
- ] }), N = ({ color: e = "#181825" }) => /* @__PURE__ */ d(
7
+ description: t = "A question about this product?"
8
+ }) => /* @__PURE__ */ h("div", { className: "dialog-block-header-container", children: [
9
+ /* @__PURE__ */ n("div", { className: "dialog-block-title", children: e }),
10
+ /* @__PURE__ */ n("div", { className: "dialog-block-description", children: t })
11
+ ] }), H = ({ color: e = "#181825" }) => /* @__PURE__ */ h(
11
12
  "svg",
12
13
  {
13
14
  width: "20",
@@ -16,8 +17,8 @@ const S = ({
16
17
  fill: "none",
17
18
  xmlns: "http://www.w3.org/2000/svg",
18
19
  children: [
19
- /* @__PURE__ */ d("g", { clipPath: "url(#clip0_466_934)", children: [
20
- /* @__PURE__ */ t(
20
+ /* @__PURE__ */ h("g", { clipPath: "url(#clip0_466_934)", children: [
21
+ /* @__PURE__ */ n(
21
22
  "path",
22
23
  {
23
24
  d: "M5.41675 10.8333L6.07046 12.1408C6.2917 12.5832 6.40232 12.8045 6.55011 12.9962C6.68124 13.1663 6.83375 13.3188 7.00388 13.45C7.19559 13.5977 7.41684 13.7084 7.85932 13.9296L9.16675 14.5833L7.85932 15.237C7.41684 15.4583 7.19559 15.5689 7.00388 15.7167C6.83375 15.8478 6.68124 16.0003 6.55011 16.1704C6.40232 16.3622 6.2917 16.5834 6.07046 17.0259L5.41675 18.3333L4.76303 17.0259C4.54179 16.5834 4.43117 16.3622 4.28339 16.1704C4.15225 16.0003 3.99974 15.8478 3.82962 15.7167C3.6379 15.5689 3.41666 15.4583 2.97418 15.237L1.66675 14.5833L2.97418 13.9296C3.41666 13.7084 3.6379 13.5977 3.82962 13.45C3.99974 13.3188 4.15225 13.1663 4.28339 12.9962C4.43117 12.8045 4.54179 12.5832 4.76303 12.1408L5.41675 10.8333Z",
@@ -27,7 +28,7 @@ const S = ({
27
28
  strokeLinejoin: "round"
28
29
  }
29
30
  ),
30
- /* @__PURE__ */ t(
31
+ /* @__PURE__ */ n(
31
32
  "path",
32
33
  {
33
34
  d: "M12.5001 1.66666L13.4823 4.22034C13.7173 4.83136 13.8348 5.13688 14.0175 5.39386C14.1795 5.62162 14.3785 5.82061 14.6062 5.98256C14.8632 6.16529 15.1687 6.2828 15.7797 6.5178L18.3334 7.49999L15.7797 8.48217C15.1687 8.71718 14.8632 8.83469 14.6062 9.01742C14.3785 9.17937 14.1795 9.37836 14.0175 9.60612C13.8348 9.8631 13.7173 10.1686 13.4823 10.7796L12.5001 13.3333L11.5179 10.7796C11.2829 10.1686 11.1654 9.8631 10.9827 9.60612C10.8207 9.37836 10.6217 9.17937 10.3939 9.01742C10.137 8.83469 9.83145 8.71718 9.22043 8.48217L6.66675 7.49999L9.22043 6.5178C9.83145 6.28279 10.137 6.16529 10.3939 5.98256C10.6217 5.82061 10.8207 5.62162 10.9827 5.39386C11.1654 5.13688 11.2829 4.83136 11.5179 4.22034L12.5001 1.66666Z",
@@ -38,58 +39,58 @@ const S = ({
38
39
  }
39
40
  )
40
41
  ] }),
41
- /* @__PURE__ */ t("defs", { children: /* @__PURE__ */ t("clipPath", { id: "clip0_466_934", children: /* @__PURE__ */ t("rect", { width: "20", height: "20", fill: "white" }) }) })
42
+ /* @__PURE__ */ n("defs", { children: /* @__PURE__ */ n("clipPath", { id: "clip0_466_934", children: /* @__PURE__ */ n("rect", { width: "20", height: "20", fill: "white" }) }) })
42
43
  ]
43
44
  }
44
- ), P = ({
45
+ ), K = ({
45
46
  client: e,
46
- questions: i,
47
- productId: l,
48
- productTitle: s,
49
- selectedVariantId: a
47
+ questions: t,
48
+ productId: s,
49
+ productTitle: r,
50
+ selectedVariantId: c
50
51
  }) => {
51
- const n = (r) => {
52
+ const l = (o) => {
52
53
  e.sendProductMessage({
53
- productId: l,
54
- productTitle: s,
55
- selectedVariantId: a,
56
- question: r,
54
+ productId: s,
55
+ productTitle: r,
56
+ selectedVariantId: c,
57
+ question: o,
57
58
  fromQuestionSuggestion: !0
58
59
  });
59
60
  };
60
- return /* @__PURE__ */ t(f, { children: i.map((r) => /* @__PURE__ */ d(
61
+ return /* @__PURE__ */ n(y, { children: t.map((o) => /* @__PURE__ */ h(
61
62
  "button",
62
63
  {
63
64
  className: "dialog-block-suggestions-item",
64
- onClick: () => n(r.question),
65
+ onClick: () => l(o.question),
65
66
  children: [
66
- /* @__PURE__ */ t(N, { color: e.theme.primaryColor }),
67
- /* @__PURE__ */ t("span", { className: "dialog-block-suggestions-item-label", children: r.question })
67
+ /* @__PURE__ */ n(H, { color: e.theme.primaryColor }),
68
+ /* @__PURE__ */ n("span", { className: "dialog-block-suggestions-item-label", children: o.question })
68
69
  ]
69
70
  },
70
- r.question
71
+ o.question
71
72
  )) });
72
- }, x = () => /* @__PURE__ */ d(f, { children: [
73
- /* @__PURE__ */ t("div", { className: "dialog-block-suggestions-skeleton-item" }),
74
- /* @__PURE__ */ t("div", { className: "dialog-block-suggestions-skeleton-item" }),
75
- /* @__PURE__ */ t("div", { className: "dialog-block-suggestions-skeleton-item" })
76
- ] }), j = ({
73
+ }, O = () => /* @__PURE__ */ h(y, { children: [
74
+ /* @__PURE__ */ n("div", { className: "dialog-block-suggestions-skeleton-item" }),
75
+ /* @__PURE__ */ n("div", { className: "dialog-block-suggestions-skeleton-item" }),
76
+ /* @__PURE__ */ n("div", { className: "dialog-block-suggestions-skeleton-item" })
77
+ ] }), $ = ({
77
78
  client: e,
78
- questions: i,
79
- isLoading: l,
80
- productId: s,
81
- productTitle: a,
82
- selectedVariantId: n
83
- }) => /* @__PURE__ */ t("div", { className: "dialog-block-suggestions-container", children: l || !i ? /* @__PURE__ */ t(x, {}) : /* @__PURE__ */ t(
84
- P,
79
+ questions: t,
80
+ isLoading: s,
81
+ productId: r,
82
+ productTitle: c,
83
+ selectedVariantId: l
84
+ }) => /* @__PURE__ */ n("div", { className: "dialog-block-suggestions-container", children: s || !t ? /* @__PURE__ */ n(O, {}) : /* @__PURE__ */ n(
85
+ K,
85
86
  {
86
87
  client: e,
87
- questions: i,
88
- productId: s,
89
- productTitle: a,
90
- selectedVariantId: n
88
+ questions: t,
89
+ productId: r,
90
+ productTitle: c,
91
+ selectedVariantId: l
91
92
  }
92
- ) }), B = ({ color: e = "#ffffff" }) => /* @__PURE__ */ t(
93
+ ) }), T = ({ color: e = "#ffffff" }) => /* @__PURE__ */ n(
93
94
  "svg",
94
95
  {
95
96
  width: "20",
@@ -97,7 +98,7 @@ const S = ({
97
98
  viewBox: "0 0 20 20",
98
99
  fill: "none",
99
100
  xmlns: "http://www.w3.org/2000/svg",
100
- children: /* @__PURE__ */ t(
101
+ children: /* @__PURE__ */ n(
101
102
  "path",
102
103
  {
103
104
  d: "M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",
@@ -108,154 +109,513 @@ const S = ({
108
109
  }
109
110
  )
110
111
  }
111
- ), M = ({
112
+ ), V = ({
112
113
  client: e,
113
- placeholder: i = "Ask anything...",
114
- productId: l,
115
- productTitle: s,
116
- selectedVariantId: a
114
+ placeholder: t = "Ask anything...",
115
+ productId: s,
116
+ productTitle: r,
117
+ selectedVariantId: c
117
118
  }) => {
118
- const n = L(null), [r, o] = k(""), u = () => {
119
- var c;
120
- (c = n.current) == null || c.focus();
121
- }, g = () => {
122
- const c = r;
123
- c.trim() && (e.sendProductMessage({
124
- productId: l,
125
- productTitle: s,
126
- selectedVariantId: a,
127
- question: c,
119
+ const l = v(null), [o, i] = C(""), a = () => {
120
+ var d;
121
+ (d = l.current) == null || d.focus();
122
+ }, u = () => {
123
+ const d = o;
124
+ d.trim() && (e.sendProductMessage({
125
+ productId: s,
126
+ productTitle: r,
127
+ selectedVariantId: c,
128
+ question: d,
128
129
  fromQuestionSuggestion: !0
129
- }), o(""));
130
+ }), i(""));
130
131
  };
131
- return /* @__PURE__ */ d("div", { className: "dialog-input-wrapper", onClick: u, children: [
132
- /* @__PURE__ */ t(
132
+ return /* @__PURE__ */ h("div", { className: "dialog-input-wrapper", onClick: a, children: [
133
+ /* @__PURE__ */ n(
133
134
  "input",
134
135
  {
135
136
  id: "dialog-ask-anything-input-ai-input",
136
- ref: n,
137
- value: r,
138
- onChange: (c) => o(c.target.value),
137
+ ref: l,
138
+ value: o,
139
+ onChange: (d) => i(d.target.value),
139
140
  className: "dialog-ask-anything-input-ai-input",
140
- placeholder: i,
141
- onKeyDown: (c) => {
142
- c.key === "Enter" && g();
141
+ placeholder: t,
142
+ onKeyDown: (d) => {
143
+ d.key === "Enter" && u();
143
144
  }
144
145
  }
145
146
  ),
146
- /* @__PURE__ */ t(
147
+ /* @__PURE__ */ n(
147
148
  "button",
148
149
  {
149
150
  id: "send-message-button-ai-input",
150
151
  className: "dialog-input-submit",
151
- disabled: !r.trim(),
152
- onClick: g,
153
- children: /* @__PURE__ */ t(B, { color: e.theme.ctaTextColor })
152
+ disabled: !o.trim(),
153
+ onClick: u,
154
+ children: /* @__PURE__ */ n(T, { color: e.theme.ctaTextColor })
154
155
  }
155
156
  )
156
157
  ] });
157
- }, y = (e) => e.replace(/([A-Z])/g, "-$1").toLowerCase(), A = (e) => {
158
+ }, L = (e) => e.replace(/([A-Z])/g, "-$1").toLowerCase(), j = (e) => {
158
159
  if (!e) return;
159
- const i = document.body;
160
- Object.keys(e).forEach((l) => {
161
- const s = l, a = y(l);
162
- if (e[s] !== void 0) {
163
- if (typeof e[s] == "object") {
164
- Object.keys(e[s]).forEach(
165
- (n) => {
166
- var o;
167
- const r = n;
168
- if (r !== void 0) {
169
- const u = y(n), g = e[s];
170
- i.style.setProperty(
171
- `--dialog-theme-${a}-${u}`,
172
- (o = g[r]) == null ? void 0 : o.toString()
160
+ const t = document.body;
161
+ Object.keys(e).forEach((s) => {
162
+ const r = s, c = L(s);
163
+ if (e[r] !== void 0) {
164
+ if (typeof e[r] == "object") {
165
+ Object.keys(e[r]).forEach(
166
+ (l) => {
167
+ var i;
168
+ const o = l;
169
+ if (o !== void 0) {
170
+ const a = L(l), u = e[r];
171
+ t.style.setProperty(
172
+ `--dialog-theme-${c}-${a}`,
173
+ (i = u[o]) == null ? void 0 : i.toString()
173
174
  );
174
175
  }
175
176
  }
176
177
  );
177
178
  return;
178
179
  }
179
- if (s === "ctaBorderType") {
180
- const n = e[s] === "rounded" ? "24px" : "0";
181
- i.style.setProperty(`--dialog-theme-${a}`, n);
180
+ if (r === "ctaBorderType") {
181
+ const l = e[r] === "rounded" ? "24px" : "0";
182
+ t.style.setProperty(`--dialog-theme-${c}`, l);
182
183
  return;
183
184
  }
184
- i.style.setProperty(
185
- `--dialog-theme-${a}`,
186
- e[s].toString()
185
+ t.style.setProperty(
186
+ `--dialog-theme-${c}`,
187
+ e[r].toString()
187
188
  );
188
189
  }
189
190
  });
190
- }, K = ({ theme: e, children: i }) => (C(() => {
191
- e && A(e);
192
- }, [e]), /* @__PURE__ */ t(f, { children: i })), E = ({
191
+ }, q = ({ theme: e, children: t }) => (f(() => {
192
+ e && j(e);
193
+ }, [e]), /* @__PURE__ */ n(y, { children: t })), de = ({
193
194
  client: e,
194
- productId: i,
195
- productTitle: l,
196
- selectedVariantId: s,
197
- enableInput: a = !0
195
+ productId: t,
196
+ productTitle: s,
197
+ selectedVariantId: r,
198
+ enableInput: c = !0
198
199
  }) => {
199
- const [n, r] = k(!0), [o, u] = k(
200
+ const [l, o] = C(!0), [i, a] = C(
200
201
  void 0
201
202
  );
202
- C(() => {
203
- v({
203
+ f(() => {
204
+ E({
204
205
  method: "react",
205
- version: "2.1.0"
206
- }), w("pdp-block");
206
+ version: "2.2.1"
207
+ }), A("pdp-block");
207
208
  }, []);
208
- const g = m(
209
- () => n ? "" : o == null ? void 0 : o.assistantName,
210
- [o, n]
211
- ), b = m(
212
- () => n ? "" : o == null ? void 0 : o.description,
213
- [o, n]
214
- ), c = m(
215
- () => n ? "" : o == null ? void 0 : o.inputPlaceholder,
216
- [o, n]
209
+ const u = S(
210
+ () => l ? "" : i == null ? void 0 : i.assistantName,
211
+ [i, l]
212
+ ), m = S(
213
+ () => l ? "" : i == null ? void 0 : i.description,
214
+ [i, l]
215
+ ), d = S(
216
+ () => l ? "" : i == null ? void 0 : i.inputPlaceholder,
217
+ [i, l]
218
+ ), p = S(
219
+ () => {
220
+ var g;
221
+ return D((g = e.getLocalizationInformations()) == null ? void 0 : g.languageCode);
222
+ },
223
+ [e]
217
224
  );
218
- return C(() => {
219
- let h = !0;
225
+ return f(() => {
226
+ let g = !0;
220
227
  return (async () => {
221
- r(!0), u(void 0);
228
+ o(!0), a(void 0);
222
229
  try {
223
- const p = await e.getSuggestions(i);
224
- h && u(p);
225
- } catch (p) {
226
- console.error("error", p);
230
+ const w = await e.getSuggestions(t);
231
+ g && a(w);
232
+ } catch (w) {
233
+ console.error("error", w);
227
234
  } finally {
228
- h && r(!1);
235
+ g && o(!1);
229
236
  }
230
237
  })(), () => {
231
- h = !1;
238
+ g = !1;
232
239
  };
233
- }, [e, i]), /* @__PURE__ */ t(K, { theme: e.theme, children: /* @__PURE__ */ d("div", { id: "dialog-instant", className: "dialog-block-container", children: [
234
- /* @__PURE__ */ t(S, { title: g, description: b }),
235
- /* @__PURE__ */ t(
236
- j,
240
+ }, [e, t]), /* @__PURE__ */ n(q, { theme: e.theme, children: /* @__PURE__ */ h(
241
+ "div",
242
+ {
243
+ id: "dialog-instant",
244
+ className: "dialog-block-container",
245
+ dir: p,
246
+ children: [
247
+ /* @__PURE__ */ n(_, { title: u, description: m }),
248
+ /* @__PURE__ */ n(
249
+ $,
250
+ {
251
+ client: e,
252
+ questions: i == null ? void 0 : i.questions,
253
+ isLoading: l,
254
+ productId: t,
255
+ productTitle: s,
256
+ selectedVariantId: r
257
+ }
258
+ ),
259
+ c && /* @__PURE__ */ n(
260
+ V,
261
+ {
262
+ client: e,
263
+ placeholder: d,
264
+ productId: t,
265
+ productTitle: s,
266
+ selectedVariantId: r
267
+ }
268
+ )
269
+ ]
270
+ }
271
+ ) });
272
+ }, F = () => /* @__PURE__ */ n(
273
+ "svg",
274
+ {
275
+ width: 16,
276
+ height: 16,
277
+ viewBox: "0 0 16 16",
278
+ fill: "none",
279
+ xmlns: "http://www.w3.org/2000/svg",
280
+ "aria-hidden": "true",
281
+ children: /* @__PURE__ */ n(
282
+ "path",
237
283
  {
238
- client: e,
239
- questions: o == null ? void 0 : o.questions,
240
- isLoading: n,
241
- productId: i,
242
- productTitle: l,
243
- selectedVariantId: s
284
+ d: "M8 13V3M8 3L3 8M8 3L13 8",
285
+ stroke: "currentColor",
286
+ strokeWidth: "1.5",
287
+ strokeLinecap: "round",
288
+ strokeLinejoin: "round"
289
+ }
290
+ )
291
+ }
292
+ ), Q = "M5.3217 0.588255C5.63241 -0.196084 6.36759 -0.196085 6.6783 0.588254C6.98901 1.37259 7.68193 2.82807 8.42693 3.57307C9.17193 4.31807 10.6274 5.01099 11.4117 5.3217C12.1961 5.63241 12.1961 6.36759 11.4117 6.6783C10.6274 6.98901 9.17193 7.68193 8.42693 8.42693C7.68193 9.17193 6.98901 10.6274 6.6783 11.4117C6.36759 12.1961 5.63241 12.1961 5.3217 11.4117C5.01099 10.6274 4.31807 9.17193 3.57307 8.42693C2.82808 7.68193 1.37259 6.98901 0.588255 6.6783C-0.196084 6.36759 -0.196085 5.63241 0.588254 5.3217C1.37259 5.01099 2.82807 4.31807 3.57307 3.57307C4.31807 2.82808 5.01099 1.37259 5.3217 0.588255Z", U = ({
293
+ color: e = "currentColor"
294
+ }) => /* @__PURE__ */ n(
295
+ "svg",
296
+ {
297
+ width: 16,
298
+ height: 16,
299
+ viewBox: "0 0 12 12",
300
+ fill: "none",
301
+ xmlns: "http://www.w3.org/2000/svg",
302
+ "aria-hidden": "true",
303
+ children: /* @__PURE__ */ n("path", { d: Q, fill: e })
304
+ }
305
+ ), ue = ({
306
+ controller: e,
307
+ placeholder: t = "Search products...",
308
+ autoFocus: s = !1,
309
+ submitAriaLabel: r = "Search"
310
+ }) => {
311
+ const [c, l] = C("");
312
+ return /* @__PURE__ */ h("form", { className: "dialog-search-bar", role: "search", onSubmit: (i) => {
313
+ i.preventDefault(), e.submit(c);
314
+ }, children: [
315
+ /* @__PURE__ */ h("div", { className: "dialog-search-bar-field", children: [
316
+ /* @__PURE__ */ n("span", { className: "dialog-search-bar-icon", children: /* @__PURE__ */ n(U, {}) }),
317
+ /* @__PURE__ */ n(
318
+ "input",
319
+ {
320
+ type: "text",
321
+ name: "dialog-search-query",
322
+ className: "dialog-search-bar-input",
323
+ value: c,
324
+ "aria-label": t,
325
+ placeholder: t,
326
+ autoFocus: s,
327
+ onChange: (i) => {
328
+ l(i.target.value), e.setQuery(i.target.value);
329
+ }
330
+ }
331
+ )
332
+ ] }),
333
+ /* @__PURE__ */ n(
334
+ "button",
335
+ {
336
+ type: "submit",
337
+ className: "dialog-search-bar-submit",
338
+ "aria-label": r,
339
+ children: /* @__PURE__ */ n(F, {})
340
+ }
341
+ )
342
+ ] });
343
+ }, W = ({
344
+ controller: e,
345
+ state: t
346
+ }) => {
347
+ const s = t.response;
348
+ return s === void 0 || s.nbPages <= 1 ? null : /* @__PURE__ */ h("nav", { "aria-label": "Search results pages", className: "dialog-search-pagination", children: [
349
+ /* @__PURE__ */ n(
350
+ "button",
351
+ {
352
+ type: "button",
353
+ disabled: s.page === 0,
354
+ onClick: () => e.setPage(s.page - 1),
355
+ children: "Previous"
244
356
  }
245
357
  ),
246
- a && /* @__PURE__ */ t(
247
- M,
358
+ /* @__PURE__ */ h("span", { children: [
359
+ "Page ",
360
+ s.page + 1,
361
+ " / ",
362
+ s.nbPages
363
+ ] }),
364
+ /* @__PURE__ */ n(
365
+ "button",
248
366
  {
249
- client: e,
250
- placeholder: c,
251
- productId: i,
252
- productTitle: l,
253
- selectedVariantId: s
367
+ type: "button",
368
+ disabled: s.page >= s.nbPages - 1,
369
+ onClick: () => e.setPage(s.page + 1),
370
+ children: "Next"
254
371
  }
255
372
  )
256
- ] }) });
373
+ ] });
374
+ }, z = (e) => {
375
+ if (e === void 0)
376
+ return "";
377
+ const { min: t, max: s } = e, r = ({ amount: c, currencyCode: l }) => new Intl.NumberFormat(void 0, {
378
+ style: "currency",
379
+ currency: l
380
+ }).format(Number(c));
381
+ try {
382
+ return t.amount === s.amount ? r(t) : `${r(t)} – ${r(s)}`;
383
+ } catch {
384
+ return "";
385
+ }
386
+ }, Z = (e) => {
387
+ try {
388
+ const { protocol: t } = new URL(e, window.location.href);
389
+ return t === "http:" || t === "https:" ? e : void 0;
390
+ } catch {
391
+ return;
392
+ }
393
+ }, X = ({
394
+ controller: e,
395
+ hit: t,
396
+ index: s
397
+ }) => {
398
+ const r = v(null);
399
+ f(() => {
400
+ r.current !== null && e.observeResult(r.current, s);
401
+ }, [e, t, s]);
402
+ const c = (d) => {
403
+ const p = d.metaKey || d.ctrlKey || d.shiftKey || d.altKey;
404
+ e.selectResult(s, { navigate: !p }) && d.preventDefault();
405
+ }, l = (d) => {
406
+ d.button === 1 && e.selectResult(s, { navigate: !1 });
407
+ }, { product: o } = t, i = o.title ?? o.id, a = z(o.priceRange), u = o.url === void 0 ? void 0 : Z(o.url), m = /* @__PURE__ */ h(y, { children: [
408
+ /* @__PURE__ */ n("div", { className: "dialog-search-card-image", children: o.imageUrl !== void 0 && /* @__PURE__ */ n("img", { src: o.imageUrl, alt: i, loading: "lazy" }) }),
409
+ /* @__PURE__ */ h("div", { className: "dialog-search-card-info", children: [
410
+ /* @__PURE__ */ n("p", { className: "dialog-search-card-title", children: i }),
411
+ a !== "" && /* @__PURE__ */ n("p", { className: "dialog-search-card-price", children: a })
412
+ ] })
413
+ ] });
414
+ return /* @__PURE__ */ n("li", { ref: r, className: "dialog-search-card", children: u === void 0 ? /* @__PURE__ */ n("div", { className: "dialog-search-card-body", children: m }) : /* @__PURE__ */ n(
415
+ "a",
416
+ {
417
+ className: "dialog-search-card-body",
418
+ href: u,
419
+ onClick: c,
420
+ onAuxClick: l,
421
+ children: m
422
+ }
423
+ ) });
424
+ }, G = (e) => {
425
+ const t = v(null), [s, r] = C(void 0), [c, l] = C(0);
426
+ return R(() => {
427
+ if (!e)
428
+ return;
429
+ const o = () => {
430
+ const i = t.current;
431
+ if (i === null)
432
+ return;
433
+ const a = i.previousElementSibling ?? i, { top: u, bottom: m, left: d, width: p } = a.getBoundingClientRect();
434
+ l(window.innerHeight), r(
435
+ (g) => g !== void 0 && g.top === u && g.bottom === m && g.left === d && g.width === p ? g : { top: u, bottom: m, left: d, width: p }
436
+ );
437
+ };
438
+ return o(), window.addEventListener("scroll", o, !0), window.addEventListener("resize", o), () => {
439
+ window.removeEventListener("scroll", o, !0), window.removeEventListener("resize", o);
440
+ };
441
+ }, [e]), { anchorRef: t, rect: s, viewportHeight: c };
442
+ }, Y = (e, t) => {
443
+ const [s, r] = C(!1), c = v(null), l = e.status !== b.IDLE && !s;
444
+ return f(() => {
445
+ r(!1);
446
+ }, [e.query]), f(() => {
447
+ if (!l)
448
+ return;
449
+ const o = (i) => {
450
+ var p, g;
451
+ const a = i.target;
452
+ if (!(a instanceof Node))
453
+ return;
454
+ const u = (p = t.current) == null ? void 0 : p.previousElementSibling, m = ((g = c.current) == null ? void 0 : g.contains(a)) ?? !1, d = (u == null ? void 0 : u.contains(a)) ?? !1;
455
+ !m && !d && r(!0);
456
+ };
457
+ return document.addEventListener("pointerdown", o), () => document.removeEventListener("pointerdown", o);
458
+ }, [l, t]), f(() => {
459
+ var a;
460
+ const o = (a = t.current) == null ? void 0 : a.previousElementSibling;
461
+ if (o == null)
462
+ return;
463
+ const i = () => r(!1);
464
+ return o.addEventListener("focusin", i), () => o.removeEventListener("focusin", i);
465
+ }, [t]), { isOpen: l, panelRef: c };
466
+ }, k = 8, P = 16, J = 200, ee = (e) => e instanceof I ? `Search failed (${e.status}${e.code ? ` ${e.code}` : ""}): ${e.message}` : "Search failed: network error. Check your connection and try again.", te = (e, t) => e.bottom > 0 && e.top < t, se = (e, t) => {
467
+ const s = t - e.bottom - k - P, r = e.top - k - P, c = { left: e.left, width: e.width };
468
+ return s < J && r > s ? {
469
+ ...c,
470
+ bottom: t - e.top + k,
471
+ maxHeight: Math.max(r, 0)
472
+ } : {
473
+ ...c,
474
+ top: e.bottom + k,
475
+ maxHeight: Math.max(s, 0)
476
+ };
477
+ }, re = (e, t) => {
478
+ const s = t.response;
479
+ switch (t.status) {
480
+ case b.LOADING:
481
+ return /* @__PURE__ */ h("p", { role: "status", className: "dialog-search-status", children: [
482
+ "Searching “",
483
+ t.query,
484
+ "”…"
485
+ ] });
486
+ case b.ERROR:
487
+ return /* @__PURE__ */ h("div", { className: "dialog-search-error", children: [
488
+ /* @__PURE__ */ n(
489
+ "p",
490
+ {
491
+ role: "alert",
492
+ className: "dialog-search-status dialog-search-status-error",
493
+ children: ee(t.error)
494
+ }
495
+ ),
496
+ /* @__PURE__ */ n(
497
+ "button",
498
+ {
499
+ type: "button",
500
+ className: "dialog-search-retry",
501
+ onClick: () => e.retry(),
502
+ children: "Retry"
503
+ }
504
+ )
505
+ ] });
506
+ case b.EMPTY:
507
+ return /* @__PURE__ */ h("p", { role: "status", className: "dialog-search-status", children: [
508
+ "No products match “",
509
+ s == null ? void 0 : s.query,
510
+ "”."
511
+ ] });
512
+ case b.SUCCESS:
513
+ return s === void 0 ? null : /* @__PURE__ */ h(y, { children: [
514
+ /* @__PURE__ */ h("p", { role: "status", className: "dialog-search-status", children: [
515
+ s.nbHits,
516
+ " result",
517
+ s.nbHits > 1 ? "s" : ""
518
+ ] }),
519
+ /* @__PURE__ */ n("ul", { className: "dialog-search-results", children: s.hits.map((r, c) => /* @__PURE__ */ n(
520
+ X,
521
+ {
522
+ controller: e,
523
+ hit: r,
524
+ index: c
525
+ },
526
+ r.id
527
+ )) }),
528
+ /* @__PURE__ */ n(W, { controller: e, state: t })
529
+ ] });
530
+ default:
531
+ return null;
532
+ }
533
+ }, he = ({
534
+ controller: e,
535
+ state: t
536
+ }) => {
537
+ const s = t.status !== b.IDLE, { anchorRef: r, rect: c, viewportHeight: l } = G(s), { isOpen: o, panelRef: i } = Y(t, r);
538
+ return /* @__PURE__ */ h(y, { children: [
539
+ /* @__PURE__ */ n("div", { ref: r }),
540
+ o && c !== void 0 && te(c, l) && B(
541
+ /* @__PURE__ */ n(
542
+ "div",
543
+ {
544
+ ref: i,
545
+ className: "dialog-search-panel",
546
+ style: se(c, l),
547
+ children: re(e, t)
548
+ }
549
+ ),
550
+ document.body
551
+ )
552
+ ] });
553
+ }, ne = {
554
+ status: b.IDLE,
555
+ query: "",
556
+ page: 0
557
+ }, ge = (e) => {
558
+ const t = v(e);
559
+ t.current = e;
560
+ const s = v(void 0), r = N(() => {
561
+ if (s.current === void 0) {
562
+ const { client: a, surface: u = "search_page", ...m } = t.current;
563
+ s.current = M({
564
+ search: (d, p) => a.search(d, p),
565
+ analytics: {
566
+ surface: u,
567
+ trackViewSearchResults: (d) => a.trackViewSearchResults(d),
568
+ trackSelectSearchResult: (d) => a.trackSelectSearchResult(d)
569
+ },
570
+ ...m
571
+ });
572
+ }
573
+ return s.current;
574
+ }, []), c = v(void 0);
575
+ c.current ?? (c.current = {
576
+ setQuery: (a) => r().setQuery(a),
577
+ submit: (a) => r().submit(a),
578
+ setPage: (a) => r().setPage(a),
579
+ retry: () => r().retry(),
580
+ observeResult: (a, u) => r().observeResult(a, u),
581
+ selectResult: (a, u) => r().selectResult(a, u),
582
+ subscribe: (a) => r().subscribe(a),
583
+ getState: () => r().getState(),
584
+ // Clear the ref so the next access creates a fresh controller instead of
585
+ // dispatching into the disposed one; never create a controller here.
586
+ dispose: () => {
587
+ var a;
588
+ (a = s.current) == null || a.dispose(), s.current = void 0;
589
+ }
590
+ }), f(() => {
591
+ E({
592
+ method: "react",
593
+ version: "2.2.1"
594
+ });
595
+ const a = r();
596
+ return () => {
597
+ a.dispose(), s.current === a && (s.current = void 0);
598
+ };
599
+ }, [r]);
600
+ const l = N(
601
+ (a) => r().subscribe(a),
602
+ [r]
603
+ ), o = N(
604
+ () => r().getState(),
605
+ [r]
606
+ ), i = x(
607
+ l,
608
+ o,
609
+ () => ne
610
+ );
611
+ return { controller: c.current, state: i };
257
612
  };
258
613
  export {
259
- M as DialogInput,
260
- E as DialogProductBlock
614
+ V as DialogInput,
615
+ de as DialogProductBlock,
616
+ ue as DialogSearchBar,
617
+ W as DialogSearchPagination,
618
+ X as DialogSearchProductCard,
619
+ he as DialogSearchResults,
620
+ ge as useDialogSearch
261
621
  };
@@ -1 +1 @@
1
- (function(d,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react"),require("@askdialog/dialog-sdk")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@askdialog/dialog-sdk"],e):(d=typeof globalThis<"u"?globalThis:d||self,e(d["dialog-react"]={},d["react/jsx-runtime"],d.React,d.dialogSdk))})(this,(function(d,e,g,C){"use strict";const L=({title:o="Your expert",description:t="A question about this product?"})=>e.jsxs("div",{className:"dialog-block-header-container",children:[e.jsx("div",{className:"dialog-block-title",children:o}),e.jsx("div",{className:"dialog-block-description",children:t})]}),v=({color:o="#181825"})=>e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsxs("g",{clipPath:"url(#clip0_466_934)",children:[e.jsx("path",{d:"M5.41675 10.8333L6.07046 12.1408C6.2917 12.5832 6.40232 12.8045 6.55011 12.9962C6.68124 13.1663 6.83375 13.3188 7.00388 13.45C7.19559 13.5977 7.41684 13.7084 7.85932 13.9296L9.16675 14.5833L7.85932 15.237C7.41684 15.4583 7.19559 15.5689 7.00388 15.7167C6.83375 15.8478 6.68124 16.0003 6.55011 16.1704C6.40232 16.3622 6.2917 16.5834 6.07046 17.0259L5.41675 18.3333L4.76303 17.0259C4.54179 16.5834 4.43117 16.3622 4.28339 16.1704C4.15225 16.0003 3.99974 15.8478 3.82962 15.7167C3.6379 15.5689 3.41666 15.4583 2.97418 15.237L1.66675 14.5833L2.97418 13.9296C3.41666 13.7084 3.6379 13.5977 3.82962 13.45C3.99974 13.3188 4.15225 13.1663 4.28339 12.9962C4.43117 12.8045 4.54179 12.5832 4.76303 12.1408L5.41675 10.8333Z",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M12.5001 1.66666L13.4823 4.22034C13.7173 4.83136 13.8348 5.13688 14.0175 5.39386C14.1795 5.62162 14.3785 5.82061 14.6062 5.98256C14.8632 6.16529 15.1687 6.2828 15.7797 6.5178L18.3334 7.49999L15.7797 8.48217C15.1687 8.71718 14.8632 8.83469 14.6062 9.01742C14.3785 9.17937 14.1795 9.37836 14.0175 9.60612C13.8348 9.8631 13.7173 10.1686 13.4823 10.7796L12.5001 13.3333L11.5179 10.7796C11.2829 10.1686 11.1654 9.8631 10.9827 9.60612C10.8207 9.37836 10.6217 9.17937 10.3939 9.01742C10.137 8.83469 9.83145 8.71718 9.22043 8.48217L6.66675 7.49999L9.22043 6.5178C9.83145 6.28279 10.137 6.16529 10.3939 5.98256C10.6217 5.82061 10.8207 5.62162 10.9827 5.39386C11.1654 5.13688 11.2829 4.83136 11.5179 4.22034L12.5001 1.66666Z",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),e.jsx("defs",{children:e.jsx("clipPath",{id:"clip0_466_934",children:e.jsx("rect",{width:"20",height:"20",fill:"white"})})})]}),S=({client:o,questions:t,productId:a,productTitle:n,selectedVariantId:l})=>{const i=r=>{o.sendProductMessage({productId:a,productTitle:n,selectedVariantId:l,question:r,fromQuestionSuggestion:!0})};return e.jsx(e.Fragment,{children:t.map(r=>e.jsxs("button",{className:"dialog-block-suggestions-item",onClick:()=>i(r.question),children:[e.jsx(v,{color:o.theme.primaryColor}),e.jsx("span",{className:"dialog-block-suggestions-item-label",children:r.question})]},r.question))})},w=()=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),e.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),e.jsx("div",{className:"dialog-block-suggestions-skeleton-item"})]}),N=({client:o,questions:t,isLoading:a,productId:n,productTitle:l,selectedVariantId:i})=>e.jsx("div",{className:"dialog-block-suggestions-container",children:a||!t?e.jsx(w,{}):e.jsx(S,{client:o,questions:t,productId:n,productTitle:l,selectedVariantId:i})}),m=({color:o="#ffffff"})=>e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),b=({client:o,placeholder:t="Ask anything...",productId:a,productTitle:n,selectedVariantId:l})=>{const i=g.useRef(null),[r,s]=g.useState(""),u=()=>{var c;(c=i.current)==null||c.focus()},h=()=>{const c=r;c.trim()&&(o.sendProductMessage({productId:a,productTitle:n,selectedVariantId:l,question:c,fromQuestionSuggestion:!0}),s(""))},p=c=>{c.key==="Enter"&&h()};return e.jsxs("div",{className:"dialog-input-wrapper",onClick:u,children:[e.jsx("input",{id:"dialog-ask-anything-input-ai-input",ref:i,value:r,onChange:c=>s(c.target.value),className:"dialog-ask-anything-input-ai-input",placeholder:t,onKeyDown:p}),e.jsx("button",{id:"send-message-button-ai-input",className:"dialog-input-submit",disabled:!r.trim(),onClick:h,children:e.jsx(m,{color:o.theme.ctaTextColor})})]})},y=o=>o.replace(/([A-Z])/g,"-$1").toLowerCase(),P=o=>{if(!o)return;const t=document.body;Object.keys(o).forEach(a=>{const n=a,l=y(a);if(o[n]!==void 0){if(typeof o[n]=="object"){Object.keys(o[n]).forEach(i=>{var s;const r=i;if(r!==void 0){const u=y(i),h=o[n];t.style.setProperty(`--dialog-theme-${l}-${u}`,(s=h[r])==null?void 0:s.toString())}});return}if(n==="ctaBorderType"){const i=o[n]==="rounded"?"24px":"0";t.style.setProperty(`--dialog-theme-${l}`,i);return}t.style.setProperty(`--dialog-theme-${l}`,o[n].toString())}})},M=({theme:o,children:t})=>(g.useEffect(()=>{o&&P(o)},[o]),e.jsx(e.Fragment,{children:t})),j=({client:o,productId:t,productTitle:a,selectedVariantId:n,enableInput:l=!0})=>{const[i,r]=g.useState(!0),[s,u]=g.useState(void 0);g.useEffect(()=>{C.registerDialogInstallation({method:"react",version:"2.1.0"}),C.addAuditCapability("pdp-block")},[]);const h=g.useMemo(()=>i?"":s==null?void 0:s.assistantName,[s,i]),p=g.useMemo(()=>i?"":s==null?void 0:s.description,[s,i]),c=g.useMemo(()=>i?"":s==null?void 0:s.inputPlaceholder,[s,i]);return g.useEffect(()=>{let f=!0;return(async()=>{r(!0),u(void 0);try{const k=await o.getSuggestions(t);f&&u(k)}catch(k){console.error("error",k)}finally{f&&r(!1)}})(),()=>{f=!1}},[o,t]),e.jsx(M,{theme:o.theme,children:e.jsxs("div",{id:"dialog-instant",className:"dialog-block-container",children:[e.jsx(L,{title:h,description:p}),e.jsx(N,{client:o,questions:s==null?void 0:s.questions,isLoading:i,productId:t,productTitle:a,selectedVariantId:n}),l&&e.jsx(b,{client:o,placeholder:c,productId:t,productTitle:a,selectedVariantId:n})]})})};d.DialogInput=b,d.DialogProductBlock=j,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(g,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react/jsx-runtime"),require("react"),require("@askdialog/dialog-sdk"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@askdialog/dialog-sdk","react-dom"],s):(g=typeof globalThis<"u"?globalThis:g||self,s(g["dialog-react"]={},g["react/jsx-runtime"],g.React,g.dialogSdk,g.ReactDOM))})(this,(function(g,s,d,p,N){"use strict";const P=({title:e="Your expert",description:t="A question about this product?"})=>s.jsxs("div",{className:"dialog-block-header-container",children:[s.jsx("div",{className:"dialog-block-title",children:e}),s.jsx("div",{className:"dialog-block-description",children:t})]}),m=({color:e="#181825"})=>s.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[s.jsxs("g",{clipPath:"url(#clip0_466_934)",children:[s.jsx("path",{d:"M5.41675 10.8333L6.07046 12.1408C6.2917 12.5832 6.40232 12.8045 6.55011 12.9962C6.68124 13.1663 6.83375 13.3188 7.00388 13.45C7.19559 13.5977 7.41684 13.7084 7.85932 13.9296L9.16675 14.5833L7.85932 15.237C7.41684 15.4583 7.19559 15.5689 7.00388 15.7167C6.83375 15.8478 6.68124 16.0003 6.55011 16.1704C6.40232 16.3622 6.2917 16.5834 6.07046 17.0259L5.41675 18.3333L4.76303 17.0259C4.54179 16.5834 4.43117 16.3622 4.28339 16.1704C4.15225 16.0003 3.99974 15.8478 3.82962 15.7167C3.6379 15.5689 3.41666 15.4583 2.97418 15.237L1.66675 14.5833L2.97418 13.9296C3.41666 13.7084 3.6379 13.5977 3.82962 13.45C3.99974 13.3188 4.15225 13.1663 4.28339 12.9962C4.43117 12.8045 4.54179 12.5832 4.76303 12.1408L5.41675 10.8333Z",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),s.jsx("path",{d:"M12.5001 1.66666L13.4823 4.22034C13.7173 4.83136 13.8348 5.13688 14.0175 5.39386C14.1795 5.62162 14.3785 5.82061 14.6062 5.98256C14.8632 6.16529 15.1687 6.2828 15.7797 6.5178L18.3334 7.49999L15.7797 8.48217C15.1687 8.71718 14.8632 8.83469 14.6062 9.01742C14.3785 9.17937 14.1795 9.37836 14.0175 9.60612C13.8348 9.8631 13.7173 10.1686 13.4823 10.7796L12.5001 13.3333L11.5179 10.7796C11.2829 10.1686 11.1654 9.8631 10.9827 9.60612C10.8207 9.37836 10.6217 9.17937 10.3939 9.01742C10.137 8.83469 9.83145 8.71718 9.22043 8.48217L6.66675 7.49999L9.22043 6.5178C9.83145 6.28279 10.137 6.16529 10.3939 5.98256C10.6217 5.82061 10.8207 5.62162 10.9827 5.39386C11.1654 5.13688 11.2829 4.83136 11.5179 4.22034L12.5001 1.66666Z",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),s.jsx("defs",{children:s.jsx("clipPath",{id:"clip0_466_934",children:s.jsx("rect",{width:"20",height:"20",fill:"white"})})})]}),E=({client:e,questions:t,productId:r,productTitle:o,selectedVariantId:i})=>{const l=n=>{e.sendProductMessage({productId:r,productTitle:o,selectedVariantId:i,question:n,fromQuestionSuggestion:!0})};return s.jsx(s.Fragment,{children:t.map(n=>s.jsxs("button",{className:"dialog-block-suggestions-item",onClick:()=>l(n.question),children:[s.jsx(m,{color:e.theme.primaryColor}),s.jsx("span",{className:"dialog-block-suggestions-item-label",children:n.question})]},n.question))})},L=()=>s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"})]}),_=({client:e,questions:t,isLoading:r,productId:o,productTitle:i,selectedVariantId:l})=>s.jsx("div",{className:"dialog-block-suggestions-container",children:r||!t?s.jsx(L,{}):s.jsx(E,{client:e,questions:t,productId:o,productTitle:i,selectedVariantId:l})}),A=({color:e="#ffffff"})=>s.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:s.jsx("path",{d:"M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),C=({client:e,placeholder:t="Ask anything...",productId:r,productTitle:o,selectedVariantId:i})=>{const l=d.useRef(null),[n,a]=d.useState(""),c=()=>{var u;(u=l.current)==null||u.focus()},h=()=>{const u=n;u.trim()&&(e.sendProductMessage({productId:r,productTitle:o,selectedVariantId:i,question:u,fromQuestionSuggestion:!0}),a(""))},b=u=>{u.key==="Enter"&&h()};return s.jsxs("div",{className:"dialog-input-wrapper",onClick:c,children:[s.jsx("input",{id:"dialog-ask-anything-input-ai-input",ref:l,value:n,onChange:u=>a(u.target.value),className:"dialog-ask-anything-input-ai-input",placeholder:t,onKeyDown:b}),s.jsx("button",{id:"send-message-button-ai-input",className:"dialog-input-submit",disabled:!n.trim(),onClick:h,children:s.jsx(A,{color:e.theme.ctaTextColor})})]})},y=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),D=e=>{if(!e)return;const t=document.body;Object.keys(e).forEach(r=>{const o=r,i=y(r);if(e[o]!==void 0){if(typeof e[o]=="object"){Object.keys(e[o]).forEach(l=>{var a;const n=l;if(n!==void 0){const c=y(l),h=e[o];t.style.setProperty(`--dialog-theme-${i}-${c}`,(a=h[n])==null?void 0:a.toString())}});return}if(o==="ctaBorderType"){const l=e[o]==="rounded"?"24px":"0";t.style.setProperty(`--dialog-theme-${i}`,l);return}t.style.setProperty(`--dialog-theme-${i}`,e[o].toString())}})},M=({theme:e,children:t})=>(d.useEffect(()=>{e&&D(e)},[e]),s.jsx(s.Fragment,{children:t})),I=({client:e,productId:t,productTitle:r,selectedVariantId:o,enableInput:i=!0})=>{const[l,n]=d.useState(!0),[a,c]=d.useState(void 0);d.useEffect(()=>{p.registerDialogInstallation({method:"react",version:"2.2.1"}),p.addAuditCapability("pdp-block")},[]);const h=d.useMemo(()=>l?"":a==null?void 0:a.assistantName,[a,l]),b=d.useMemo(()=>l?"":a==null?void 0:a.description,[a,l]),u=d.useMemo(()=>l?"":a==null?void 0:a.inputPlaceholder,[a,l]),S=d.useMemo(()=>{var f;return p.resolveTextDirection((f=e.getLocalizationInformations())==null?void 0:f.languageCode)},[e]);return d.useEffect(()=>{let f=!0;return(async()=>{n(!0),c(void 0);try{const v=await e.getSuggestions(t);f&&c(v)}catch(v){console.error("error",v)}finally{f&&n(!1)}})(),()=>{f=!1}},[e,t]),s.jsx(M,{theme:e.theme,children:s.jsxs("div",{id:"dialog-instant",className:"dialog-block-container",dir:S,children:[s.jsx(P,{title:h,description:b}),s.jsx(_,{client:e,questions:a==null?void 0:a.questions,isLoading:l,productId:t,productTitle:r,selectedVariantId:o}),i&&s.jsx(C,{client:e,placeholder:u,productId:t,productTitle:r,selectedVariantId:o})]})})},F=()=>s.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:s.jsx("path",{d:"M8 13V3M8 3L3 8M8 3L13 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O="M5.3217 0.588255C5.63241 -0.196084 6.36759 -0.196085 6.6783 0.588254C6.98901 1.37259 7.68193 2.82807 8.42693 3.57307C9.17193 4.31807 10.6274 5.01099 11.4117 5.3217C12.1961 5.63241 12.1961 6.36759 11.4117 6.6783C10.6274 6.98901 9.17193 7.68193 8.42693 8.42693C7.68193 9.17193 6.98901 10.6274 6.6783 11.4117C6.36759 12.1961 5.63241 12.1961 5.3217 11.4117C5.01099 10.6274 4.31807 9.17193 3.57307 8.42693C2.82808 7.68193 1.37259 6.98901 0.588255 6.6783C-0.196084 6.36759 -0.196085 5.63241 0.588254 5.3217C1.37259 5.01099 2.82807 4.31807 3.57307 3.57307C4.31807 2.82808 5.01099 1.37259 5.3217 0.588255Z",T=({color:e="currentColor"})=>s.jsx("svg",{width:16,height:16,viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:s.jsx("path",{d:O,fill:e})}),B=({controller:e,placeholder:t="Search products...",autoFocus:r=!1,submitAriaLabel:o="Search"})=>{const[i,l]=d.useState(""),n=a=>{a.preventDefault(),e.submit(i)};return s.jsxs("form",{className:"dialog-search-bar",role:"search",onSubmit:n,children:[s.jsxs("div",{className:"dialog-search-bar-field",children:[s.jsx("span",{className:"dialog-search-bar-icon",children:s.jsx(T,{})}),s.jsx("input",{type:"text",name:"dialog-search-query",className:"dialog-search-bar-input",value:i,"aria-label":t,placeholder:t,autoFocus:r,onChange:a=>{l(a.target.value),e.setQuery(a.target.value)}})]}),s.jsx("button",{type:"submit",className:"dialog-search-bar-submit","aria-label":o,children:s.jsx(F,{})})]})},w=({controller:e,state:t})=>{const r=t.response;return r===void 0||r.nbPages<=1?null:s.jsxs("nav",{"aria-label":"Search results pages",className:"dialog-search-pagination",children:[s.jsx("button",{type:"button",disabled:r.page===0,onClick:()=>e.setPage(r.page-1),children:"Previous"}),s.jsxs("span",{children:["Page ",r.page+1," / ",r.nbPages]}),s.jsx("button",{type:"button",disabled:r.page>=r.nbPages-1,onClick:()=>e.setPage(r.page+1),children:"Next"})]})},q=e=>{if(e===void 0)return"";const{min:t,max:r}=e,o=({amount:i,currencyCode:l})=>new Intl.NumberFormat(void 0,{style:"currency",currency:l}).format(Number(i));try{return t.amount===r.amount?o(t):`${o(t)} – ${o(r)}`}catch{return""}},x=e=>{try{const{protocol:t}=new URL(e,window.location.href);return t==="http:"||t==="https:"?e:void 0}catch{return}},k=({controller:e,hit:t,index:r})=>{const o=d.useRef(null);d.useEffect(()=>{o.current!==null&&e.observeResult(o.current,r)},[e,t,r]);const i=u=>{const S=u.metaKey||u.ctrlKey||u.shiftKey||u.altKey;e.selectResult(r,{navigate:!S})&&u.preventDefault()},l=u=>{u.button===1&&e.selectResult(r,{navigate:!1})},{product:n}=t,a=n.title??n.id,c=q(n.priceRange),h=n.url===void 0?void 0:x(n.url),b=s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dialog-search-card-image",children:n.imageUrl!==void 0&&s.jsx("img",{src:n.imageUrl,alt:a,loading:"lazy"})}),s.jsxs("div",{className:"dialog-search-card-info",children:[s.jsx("p",{className:"dialog-search-card-title",children:a}),c!==""&&s.jsx("p",{className:"dialog-search-card-price",children:c})]})]});return s.jsx("li",{ref:o,className:"dialog-search-card",children:h===void 0?s.jsx("div",{className:"dialog-search-card-body",children:b}):s.jsx("a",{className:"dialog-search-card-body",href:h,onClick:i,onAuxClick:l,children:b})})},H=e=>{const t=d.useRef(null),[r,o]=d.useState(void 0),[i,l]=d.useState(0);return d.useLayoutEffect(()=>{if(!e)return;const n=()=>{const a=t.current;if(a===null)return;const c=a.previousElementSibling??a,{top:h,bottom:b,left:u,width:S}=c.getBoundingClientRect();l(window.innerHeight),o(f=>f!==void 0&&f.top===h&&f.bottom===b&&f.left===u&&f.width===S?f:{top:h,bottom:b,left:u,width:S})};return n(),window.addEventListener("scroll",n,!0),window.addEventListener("resize",n),()=>{window.removeEventListener("scroll",n,!0),window.removeEventListener("resize",n)}},[e]),{anchorRef:t,rect:r,viewportHeight:i}},V=(e,t)=>{const[r,o]=d.useState(!1),i=d.useRef(null),l=e.status!==p.SearchStatus.IDLE&&!r;return d.useEffect(()=>{o(!1)},[e.query]),d.useEffect(()=>{if(!l)return;const n=a=>{var S,f;const c=a.target;if(!(c instanceof Node))return;const h=(S=t.current)==null?void 0:S.previousElementSibling,b=((f=i.current)==null?void 0:f.contains(c))??!1,u=(h==null?void 0:h.contains(c))??!1;!b&&!u&&o(!0)};return document.addEventListener("pointerdown",n),()=>document.removeEventListener("pointerdown",n)},[l,t]),d.useEffect(()=>{var c;const n=(c=t.current)==null?void 0:c.previousElementSibling;if(n==null)return;const a=()=>o(!1);return n.addEventListener("focusin",a),()=>n.removeEventListener("focusin",a)},[t]),{isOpen:l,panelRef:i}},K=e=>e instanceof p.DialogSearchError?`Search failed (${e.status}${e.code?` ${e.code}`:""}): ${e.message}`:"Search failed: network error. Check your connection and try again.",$=(e,t)=>e.bottom>0&&e.top<t,X=(e,t)=>{const r=t-e.bottom-8-16,o=e.top-8-16,i={left:e.left,width:e.width};return r<200&&o>r?{...i,bottom:t-e.top+8,maxHeight:Math.max(o,0)}:{...i,top:e.bottom+8,maxHeight:Math.max(r,0)}},j=(e,t)=>{const r=t.response;switch(t.status){case p.SearchStatus.LOADING:return s.jsxs("p",{role:"status",className:"dialog-search-status",children:["Searching “",t.query,"”…"]});case p.SearchStatus.ERROR:return s.jsxs("div",{className:"dialog-search-error",children:[s.jsx("p",{role:"alert",className:"dialog-search-status dialog-search-status-error",children:K(t.error)}),s.jsx("button",{type:"button",className:"dialog-search-retry",onClick:()=>e.retry(),children:"Retry"})]});case p.SearchStatus.EMPTY:return s.jsxs("p",{role:"status",className:"dialog-search-status",children:["No products match “",r==null?void 0:r.query,"”."]});case p.SearchStatus.SUCCESS:return r===void 0?null:s.jsxs(s.Fragment,{children:[s.jsxs("p",{role:"status",className:"dialog-search-status",children:[r.nbHits," result",r.nbHits>1?"s":""]}),s.jsx("ul",{className:"dialog-search-results",children:r.hits.map((o,i)=>s.jsx(k,{controller:e,hit:o,index:i},o.id))}),s.jsx(w,{controller:e,state:t})]});default:return null}},W=({controller:e,state:t})=>{const r=t.status!==p.SearchStatus.IDLE,{anchorRef:o,rect:i,viewportHeight:l}=H(r),{isOpen:n,panelRef:a}=V(t,o);return s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:o}),n&&i!==void 0&&$(i,l)&&N.createPortal(s.jsx("div",{ref:a,className:"dialog-search-panel",style:X(i,l),children:j(e,t)}),document.body)]})},Q={status:p.SearchStatus.IDLE,query:"",page:0},U=e=>{const t=d.useRef(e);t.current=e;const r=d.useRef(void 0),o=d.useCallback(()=>{if(r.current===void 0){const{client:c,surface:h="search_page",...b}=t.current;r.current=p.createSearchController({search:(u,S)=>c.search(u,S),analytics:{surface:h,trackViewSearchResults:u=>c.trackViewSearchResults(u),trackSelectSearchResult:u=>c.trackSelectSearchResult(u)},...b})}return r.current},[]),i=d.useRef(void 0);i.current??(i.current={setQuery:c=>o().setQuery(c),submit:c=>o().submit(c),setPage:c=>o().setPage(c),retry:()=>o().retry(),observeResult:(c,h)=>o().observeResult(c,h),selectResult:(c,h)=>o().selectResult(c,h),subscribe:c=>o().subscribe(c),getState:()=>o().getState(),dispose:()=>{var c;(c=r.current)==null||c.dispose(),r.current=void 0}}),d.useEffect(()=>{p.registerDialogInstallation({method:"react",version:"2.2.1"});const c=o();return()=>{c.dispose(),r.current===c&&(r.current=void 0)}},[o]);const l=d.useCallback(c=>o().subscribe(c),[o]),n=d.useCallback(()=>o().getState(),[o]),a=d.useSyncExternalStore(l,n,()=>Q);return{controller:i.current,state:a}};g.DialogInput=C,g.DialogProductBlock=I,g.DialogSearchBar=B,g.DialogSearchPagination=w,g.DialogSearchProductCard=k,g.DialogSearchResults=W,g.useDialogSearch=U,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,2 @@
1
+ import { FC } from 'react';
2
+ export declare const ArrowUpIcon: FC;
@@ -0,0 +1,6 @@
1
+ import { FC } from 'react';
2
+ interface ShurikenIconProps {
3
+ color?: string;
4
+ }
5
+ export declare const ShurikenIcon: FC<ShurikenIconProps>;
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askdialog/dialog-react",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/dialog-react.umd.js",
@@ -26,7 +26,7 @@
26
26
  "devDependencies": {
27
27
  "@types/react": "^19.2.7",
28
28
  "@types/react-dom": "^19.2.3",
29
- "@askdialog/dialog-sdk": "2.3.0"
29
+ "@askdialog/dialog-sdk": "2.8.1"
30
30
  },
31
31
  "author": "Dialog",
32
32
  "publishConfig": {