@askdialog/dialog-react 2.2.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
@@ -137,7 +137,7 @@ Search input: typing runs a debounced search, submitting (Enter) searches immedi
137
137
 
138
138
  #### DialogSearchResults
139
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.
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
141
 
142
142
  **Props:**
143
143
  - `controller` (SearchController) - From `useDialogSearch` (required)
@@ -1,10 +1,12 @@
1
1
  import { RefObject } from 'react';
2
2
  export interface AnchorRect {
3
3
  top: number;
4
+ bottom: number;
4
5
  left: number;
5
6
  width: number;
6
7
  }
7
8
  export declare const useAnchorRect: (active: boolean) => {
8
9
  anchorRef: RefObject<HTMLDivElement | null>;
9
10
  rect: AnchorRect | undefined;
11
+ viewportHeight: number;
10
12
  };
@@ -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 +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: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-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
+ .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,14 +1,14 @@
1
- import { jsxs as h, jsx as t, Fragment as b } from "react/jsx-runtime";
2
- import { useRef as f, useState as v, useEffect as y, useMemo as k, useLayoutEffect as R, useCallback as w, useSyncExternalStore as E } from "react";
3
- import { registerDialogInstallation as P, addAuditCapability as x, resolveTextDirection as A, SearchStatus as p, DialogSearchError as D, createSearchController as M } from "@askdialog/dialog-sdk";
4
- import { createPortal as I } from "react-dom";
5
- const B = ({
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 _ = ({
6
6
  title: e = "Your expert",
7
- description: s = "A question about this product?"
7
+ description: t = "A question about this product?"
8
8
  }) => /* @__PURE__ */ h("div", { className: "dialog-block-header-container", children: [
9
- /* @__PURE__ */ t("div", { className: "dialog-block-title", children: e }),
10
- /* @__PURE__ */ t("div", { className: "dialog-block-description", children: s })
11
- ] }), K = ({ color: e = "#181825" }) => /* @__PURE__ */ h(
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(
12
12
  "svg",
13
13
  {
14
14
  width: "20",
@@ -18,7 +18,7 @@ const B = ({
18
18
  xmlns: "http://www.w3.org/2000/svg",
19
19
  children: [
20
20
  /* @__PURE__ */ h("g", { clipPath: "url(#clip0_466_934)", children: [
21
- /* @__PURE__ */ t(
21
+ /* @__PURE__ */ n(
22
22
  "path",
23
23
  {
24
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",
@@ -28,7 +28,7 @@ const B = ({
28
28
  strokeLinejoin: "round"
29
29
  }
30
30
  ),
31
- /* @__PURE__ */ t(
31
+ /* @__PURE__ */ n(
32
32
  "path",
33
33
  {
34
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",
@@ -39,58 +39,58 @@ const B = ({
39
39
  }
40
40
  )
41
41
  ] }),
42
- /* @__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" }) }) })
43
43
  ]
44
44
  }
45
- ), $ = ({
45
+ ), K = ({
46
46
  client: e,
47
- questions: s,
48
- productId: r,
49
- productTitle: n,
50
- selectedVariantId: o
47
+ questions: t,
48
+ productId: s,
49
+ productTitle: r,
50
+ selectedVariantId: c
51
51
  }) => {
52
- const c = (l) => {
52
+ const l = (o) => {
53
53
  e.sendProductMessage({
54
- productId: r,
55
- productTitle: n,
56
- selectedVariantId: o,
57
- question: l,
54
+ productId: s,
55
+ productTitle: r,
56
+ selectedVariantId: c,
57
+ question: o,
58
58
  fromQuestionSuggestion: !0
59
59
  });
60
60
  };
61
- return /* @__PURE__ */ t(b, { children: s.map((l) => /* @__PURE__ */ h(
61
+ return /* @__PURE__ */ n(y, { children: t.map((o) => /* @__PURE__ */ h(
62
62
  "button",
63
63
  {
64
64
  className: "dialog-block-suggestions-item",
65
- onClick: () => c(l.question),
65
+ onClick: () => l(o.question),
66
66
  children: [
67
- /* @__PURE__ */ t(K, { color: e.theme.primaryColor }),
68
- /* @__PURE__ */ t("span", { className: "dialog-block-suggestions-item-label", children: l.question })
67
+ /* @__PURE__ */ n(H, { color: e.theme.primaryColor }),
68
+ /* @__PURE__ */ n("span", { className: "dialog-block-suggestions-item-label", children: o.question })
69
69
  ]
70
70
  },
71
- l.question
71
+ o.question
72
72
  )) });
73
- }, _ = () => /* @__PURE__ */ h(b, { children: [
74
- /* @__PURE__ */ t("div", { className: "dialog-block-suggestions-skeleton-item" }),
75
- /* @__PURE__ */ t("div", { className: "dialog-block-suggestions-skeleton-item" }),
76
- /* @__PURE__ */ t("div", { className: "dialog-block-suggestions-skeleton-item" })
77
- ] }), T = ({
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
+ ] }), $ = ({
78
78
  client: e,
79
- questions: s,
80
- isLoading: r,
81
- productId: n,
82
- productTitle: o,
83
- selectedVariantId: c
84
- }) => /* @__PURE__ */ t("div", { className: "dialog-block-suggestions-container", children: r || !s ? /* @__PURE__ */ t(_, {}) : /* @__PURE__ */ t(
85
- $,
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,
86
86
  {
87
87
  client: e,
88
- questions: s,
89
- productId: n,
90
- productTitle: o,
91
- selectedVariantId: c
88
+ questions: t,
89
+ productId: r,
90
+ productTitle: c,
91
+ selectedVariantId: l
92
92
  }
93
- ) }), j = ({ color: e = "#ffffff" }) => /* @__PURE__ */ t(
93
+ ) }), T = ({ color: e = "#ffffff" }) => /* @__PURE__ */ n(
94
94
  "svg",
95
95
  {
96
96
  width: "20",
@@ -98,7 +98,7 @@ const B = ({
98
98
  viewBox: "0 0 20 20",
99
99
  fill: "none",
100
100
  xmlns: "http://www.w3.org/2000/svg",
101
- children: /* @__PURE__ */ t(
101
+ children: /* @__PURE__ */ n(
102
102
  "path",
103
103
  {
104
104
  d: "M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",
@@ -111,165 +111,165 @@ const B = ({
111
111
  }
112
112
  ), V = ({
113
113
  client: e,
114
- placeholder: s = "Ask anything...",
115
- productId: r,
116
- productTitle: n,
117
- selectedVariantId: o
114
+ placeholder: t = "Ask anything...",
115
+ productId: s,
116
+ productTitle: r,
117
+ selectedVariantId: c
118
118
  }) => {
119
- const c = f(null), [l, a] = v(""), i = () => {
119
+ const l = v(null), [o, i] = C(""), a = () => {
120
120
  var d;
121
- (d = c.current) == null || d.focus();
121
+ (d = l.current) == null || d.focus();
122
122
  }, u = () => {
123
- const d = l;
123
+ const d = o;
124
124
  d.trim() && (e.sendProductMessage({
125
- productId: r,
126
- productTitle: n,
127
- selectedVariantId: o,
125
+ productId: s,
126
+ productTitle: r,
127
+ selectedVariantId: c,
128
128
  question: d,
129
129
  fromQuestionSuggestion: !0
130
- }), a(""));
130
+ }), i(""));
131
131
  };
132
- return /* @__PURE__ */ h("div", { className: "dialog-input-wrapper", onClick: i, children: [
133
- /* @__PURE__ */ t(
132
+ return /* @__PURE__ */ h("div", { className: "dialog-input-wrapper", onClick: a, children: [
133
+ /* @__PURE__ */ n(
134
134
  "input",
135
135
  {
136
136
  id: "dialog-ask-anything-input-ai-input",
137
- ref: c,
138
- value: l,
139
- onChange: (d) => a(d.target.value),
137
+ ref: l,
138
+ value: o,
139
+ onChange: (d) => i(d.target.value),
140
140
  className: "dialog-ask-anything-input-ai-input",
141
- placeholder: s,
141
+ placeholder: t,
142
142
  onKeyDown: (d) => {
143
143
  d.key === "Enter" && u();
144
144
  }
145
145
  }
146
146
  ),
147
- /* @__PURE__ */ t(
147
+ /* @__PURE__ */ n(
148
148
  "button",
149
149
  {
150
150
  id: "send-message-button-ai-input",
151
151
  className: "dialog-input-submit",
152
- disabled: !l.trim(),
152
+ disabled: !o.trim(),
153
153
  onClick: u,
154
- children: /* @__PURE__ */ t(j, { color: e.theme.ctaTextColor })
154
+ children: /* @__PURE__ */ n(T, { color: e.theme.ctaTextColor })
155
155
  }
156
156
  )
157
157
  ] });
158
- }, N = (e) => e.replace(/([A-Z])/g, "-$1").toLowerCase(), F = (e) => {
158
+ }, L = (e) => e.replace(/([A-Z])/g, "-$1").toLowerCase(), j = (e) => {
159
159
  if (!e) return;
160
- const s = document.body;
161
- Object.keys(e).forEach((r) => {
162
- const n = r, o = N(r);
163
- if (e[n] !== void 0) {
164
- if (typeof e[n] == "object") {
165
- Object.keys(e[n]).forEach(
166
- (c) => {
167
- var a;
168
- const l = c;
169
- if (l !== void 0) {
170
- const i = N(c), u = e[n];
171
- s.style.setProperty(
172
- `--dialog-theme-${o}-${i}`,
173
- (a = u[l]) == null ? void 0 : a.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()
174
174
  );
175
175
  }
176
176
  }
177
177
  );
178
178
  return;
179
179
  }
180
- if (n === "ctaBorderType") {
181
- const c = e[n] === "rounded" ? "24px" : "0";
182
- s.style.setProperty(`--dialog-theme-${o}`, c);
180
+ if (r === "ctaBorderType") {
181
+ const l = e[r] === "rounded" ? "24px" : "0";
182
+ t.style.setProperty(`--dialog-theme-${c}`, l);
183
183
  return;
184
184
  }
185
- s.style.setProperty(
186
- `--dialog-theme-${o}`,
187
- e[n].toString()
185
+ t.style.setProperty(
186
+ `--dialog-theme-${c}`,
187
+ e[r].toString()
188
188
  );
189
189
  }
190
190
  });
191
- }, H = ({ theme: e, children: s }) => (y(() => {
192
- e && F(e);
193
- }, [e]), /* @__PURE__ */ t(b, { children: s })), ae = ({
191
+ }, q = ({ theme: e, children: t }) => (f(() => {
192
+ e && j(e);
193
+ }, [e]), /* @__PURE__ */ n(y, { children: t })), de = ({
194
194
  client: e,
195
- productId: s,
196
- productTitle: r,
197
- selectedVariantId: n,
198
- enableInput: o = !0
195
+ productId: t,
196
+ productTitle: s,
197
+ selectedVariantId: r,
198
+ enableInput: c = !0
199
199
  }) => {
200
- const [c, l] = v(!0), [a, i] = v(
200
+ const [l, o] = C(!0), [i, a] = C(
201
201
  void 0
202
202
  );
203
- y(() => {
204
- P({
203
+ f(() => {
204
+ E({
205
205
  method: "react",
206
- version: "2.2.0"
207
- }), x("pdp-block");
206
+ version: "2.2.1"
207
+ }), A("pdp-block");
208
208
  }, []);
209
- const u = k(
210
- () => c ? "" : a == null ? void 0 : a.assistantName,
211
- [a, c]
212
- ), g = k(
213
- () => c ? "" : a == null ? void 0 : a.description,
214
- [a, c]
215
- ), d = k(
216
- () => c ? "" : a == null ? void 0 : a.inputPlaceholder,
217
- [a, c]
218
- ), C = k(
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
219
  () => {
220
- var m;
221
- return A((m = e.getLocalizationInformations()) == null ? void 0 : m.languageCode);
220
+ var g;
221
+ return D((g = e.getLocalizationInformations()) == null ? void 0 : g.languageCode);
222
222
  },
223
223
  [e]
224
224
  );
225
- return y(() => {
226
- let m = !0;
225
+ return f(() => {
226
+ let g = !0;
227
227
  return (async () => {
228
- l(!0), i(void 0);
228
+ o(!0), a(void 0);
229
229
  try {
230
- const S = await e.getSuggestions(s);
231
- m && i(S);
232
- } catch (S) {
233
- console.error("error", S);
230
+ const w = await e.getSuggestions(t);
231
+ g && a(w);
232
+ } catch (w) {
233
+ console.error("error", w);
234
234
  } finally {
235
- m && l(!1);
235
+ g && o(!1);
236
236
  }
237
237
  })(), () => {
238
- m = !1;
238
+ g = !1;
239
239
  };
240
- }, [e, s]), /* @__PURE__ */ t(H, { theme: e.theme, children: /* @__PURE__ */ h(
240
+ }, [e, t]), /* @__PURE__ */ n(q, { theme: e.theme, children: /* @__PURE__ */ h(
241
241
  "div",
242
242
  {
243
243
  id: "dialog-instant",
244
244
  className: "dialog-block-container",
245
- dir: C,
245
+ dir: p,
246
246
  children: [
247
- /* @__PURE__ */ t(B, { title: u, description: g }),
248
- /* @__PURE__ */ t(
249
- T,
247
+ /* @__PURE__ */ n(_, { title: u, description: m }),
248
+ /* @__PURE__ */ n(
249
+ $,
250
250
  {
251
251
  client: e,
252
- questions: a == null ? void 0 : a.questions,
253
- isLoading: c,
254
- productId: s,
255
- productTitle: r,
256
- selectedVariantId: n
252
+ questions: i == null ? void 0 : i.questions,
253
+ isLoading: l,
254
+ productId: t,
255
+ productTitle: s,
256
+ selectedVariantId: r
257
257
  }
258
258
  ),
259
- o && /* @__PURE__ */ t(
259
+ c && /* @__PURE__ */ n(
260
260
  V,
261
261
  {
262
262
  client: e,
263
263
  placeholder: d,
264
- productId: s,
265
- productTitle: r,
266
- selectedVariantId: n
264
+ productId: t,
265
+ productTitle: s,
266
+ selectedVariantId: r
267
267
  }
268
268
  )
269
269
  ]
270
270
  }
271
271
  ) });
272
- }, O = () => /* @__PURE__ */ t(
272
+ }, F = () => /* @__PURE__ */ n(
273
273
  "svg",
274
274
  {
275
275
  width: 16,
@@ -278,7 +278,7 @@ const B = ({
278
278
  fill: "none",
279
279
  xmlns: "http://www.w3.org/2000/svg",
280
280
  "aria-hidden": "true",
281
- children: /* @__PURE__ */ t(
281
+ children: /* @__PURE__ */ n(
282
282
  "path",
283
283
  {
284
284
  d: "M8 13V3M8 3L3 8M8 3L13 8",
@@ -289,9 +289,9 @@ const B = ({
289
289
  }
290
290
  )
291
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", Q = ({
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
293
  color: e = "currentColor"
294
- }) => /* @__PURE__ */ t(
294
+ }) => /* @__PURE__ */ n(
295
295
  "svg",
296
296
  {
297
297
  width: 16,
@@ -300,164 +300,200 @@ const B = ({
300
300
  fill: "none",
301
301
  xmlns: "http://www.w3.org/2000/svg",
302
302
  "aria-hidden": "true",
303
- children: /* @__PURE__ */ t("path", { d: q, fill: e })
303
+ children: /* @__PURE__ */ n("path", { d: Q, fill: e })
304
304
  }
305
- ), ie = ({
305
+ ), ue = ({
306
306
  controller: e,
307
- placeholder: s = "Search products...",
308
- autoFocus: r = !1,
309
- submitAriaLabel: n = "Search"
307
+ placeholder: t = "Search products...",
308
+ autoFocus: s = !1,
309
+ submitAriaLabel: r = "Search"
310
310
  }) => {
311
- const [o, c] = v("");
312
- return /* @__PURE__ */ h("form", { className: "dialog-search-bar", role: "search", onSubmit: (a) => {
313
- a.preventDefault(), e.submit(o);
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
314
  }, children: [
315
315
  /* @__PURE__ */ h("div", { className: "dialog-search-bar-field", children: [
316
- /* @__PURE__ */ t("span", { className: "dialog-search-bar-icon", children: /* @__PURE__ */ t(Q, {}) }),
317
- /* @__PURE__ */ t(
316
+ /* @__PURE__ */ n("span", { className: "dialog-search-bar-icon", children: /* @__PURE__ */ n(U, {}) }),
317
+ /* @__PURE__ */ n(
318
318
  "input",
319
319
  {
320
320
  type: "text",
321
+ name: "dialog-search-query",
321
322
  className: "dialog-search-bar-input",
322
- value: o,
323
- "aria-label": s,
324
- placeholder: s,
325
- autoFocus: r,
326
- onChange: (a) => {
327
- c(a.target.value), e.setQuery(a.target.value);
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);
328
329
  }
329
330
  }
330
331
  )
331
332
  ] }),
332
- /* @__PURE__ */ t(
333
+ /* @__PURE__ */ n(
333
334
  "button",
334
335
  {
335
336
  type: "submit",
336
337
  className: "dialog-search-bar-submit",
337
- "aria-label": n,
338
- children: /* @__PURE__ */ t(O, {})
338
+ "aria-label": r,
339
+ children: /* @__PURE__ */ n(F, {})
339
340
  }
340
341
  )
341
342
  ] });
342
- }, U = ({
343
+ }, W = ({
343
344
  controller: e,
344
- state: s
345
+ state: t
345
346
  }) => {
346
- const r = s.response;
347
- return r === void 0 || r.nbPages <= 1 ? null : /* @__PURE__ */ h("nav", { "aria-label": "Search results pages", className: "dialog-search-pagination", children: [
348
- /* @__PURE__ */ t(
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(
349
350
  "button",
350
351
  {
351
352
  type: "button",
352
- disabled: r.page === 0,
353
- onClick: () => e.setPage(r.page - 1),
353
+ disabled: s.page === 0,
354
+ onClick: () => e.setPage(s.page - 1),
354
355
  children: "Previous"
355
356
  }
356
357
  ),
357
358
  /* @__PURE__ */ h("span", { children: [
358
359
  "Page ",
359
- r.page + 1,
360
+ s.page + 1,
360
361
  " / ",
361
- r.nbPages
362
+ s.nbPages
362
363
  ] }),
363
- /* @__PURE__ */ t(
364
+ /* @__PURE__ */ n(
364
365
  "button",
365
366
  {
366
367
  type: "button",
367
- disabled: r.page >= r.nbPages - 1,
368
- onClick: () => e.setPage(r.page + 1),
368
+ disabled: s.page >= s.nbPages - 1,
369
+ onClick: () => e.setPage(s.page + 1),
369
370
  children: "Next"
370
371
  }
371
372
  )
372
373
  ] });
373
- }, W = (e) => {
374
+ }, z = (e) => {
374
375
  if (e === void 0)
375
376
  return "";
376
- const { min: s, max: r } = e, n = ({ amount: o, currencyCode: c }) => new Intl.NumberFormat(void 0, {
377
+ const { min: t, max: s } = e, r = ({ amount: c, currencyCode: l }) => new Intl.NumberFormat(void 0, {
377
378
  style: "currency",
378
- currency: c
379
- }).format(Number(o));
379
+ currency: l
380
+ }).format(Number(c));
380
381
  try {
381
- return s.amount === r.amount ? n(s) : `${n(s)} – ${n(r)}`;
382
+ return t.amount === s.amount ? r(t) : `${r(t)} – ${r(s)}`;
382
383
  } catch {
383
384
  return "";
384
385
  }
385
- }, z = (e) => {
386
+ }, Z = (e) => {
386
387
  try {
387
- const { protocol: s } = new URL(e, window.location.href);
388
- return s === "http:" || s === "https:" ? e : void 0;
388
+ const { protocol: t } = new URL(e, window.location.href);
389
+ return t === "http:" || t === "https:" ? e : void 0;
389
390
  } catch {
390
391
  return;
391
392
  }
392
- }, Z = ({
393
+ }, X = ({
393
394
  controller: e,
394
- hit: s,
395
- index: r
395
+ hit: t,
396
+ index: s
396
397
  }) => {
397
- const n = f(null);
398
- y(() => {
399
- n.current !== null && e.observeResult(n.current, r);
400
- }, [e, s, r]);
401
- const o = (d) => {
402
- const C = d.metaKey || d.ctrlKey || d.shiftKey || d.altKey;
403
- e.selectResult(r, { navigate: !C }) && d.preventDefault();
404
- }, c = (d) => {
405
- d.button === 1 && e.selectResult(r, { navigate: !1 });
406
- }, { product: l } = s, a = l.title ?? l.id, i = W(l.priceRange), u = l.url === void 0 ? void 0 : z(l.url), g = /* @__PURE__ */ h(b, { children: [
407
- /* @__PURE__ */ t("div", { className: "dialog-search-card-image", children: l.imageUrl !== void 0 && /* @__PURE__ */ t("img", { src: l.imageUrl, alt: a, loading: "lazy" }) }),
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" }) }),
408
409
  /* @__PURE__ */ h("div", { className: "dialog-search-card-info", children: [
409
- /* @__PURE__ */ t("p", { className: "dialog-search-card-title", children: a }),
410
- i !== "" && /* @__PURE__ */ t("p", { className: "dialog-search-card-price", children: i })
410
+ /* @__PURE__ */ n("p", { className: "dialog-search-card-title", children: i }),
411
+ a !== "" && /* @__PURE__ */ n("p", { className: "dialog-search-card-price", children: a })
411
412
  ] })
412
413
  ] });
413
- return /* @__PURE__ */ t("li", { ref: n, className: "dialog-search-card", children: u === void 0 ? /* @__PURE__ */ t("div", { className: "dialog-search-card-body", children: g }) : /* @__PURE__ */ t(
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(
414
415
  "a",
415
416
  {
416
417
  className: "dialog-search-card-body",
417
418
  href: u,
418
- onClick: o,
419
- onAuxClick: c,
420
- children: g
419
+ onClick: c,
420
+ onAuxClick: l,
421
+ children: m
421
422
  }
422
423
  ) });
423
424
  }, G = (e) => {
424
- const s = f(null), [r, n] = v(void 0);
425
+ const t = v(null), [s, r] = C(void 0), [c, l] = C(0);
425
426
  return R(() => {
426
427
  if (!e)
427
428
  return;
428
429
  const o = () => {
429
- const c = s.current;
430
- if (c === null)
430
+ const i = t.current;
431
+ if (i === null)
431
432
  return;
432
- const { top: l, left: a, width: i } = c.getBoundingClientRect();
433
- n(
434
- (u) => u !== void 0 && u.top === l && u.left === a && u.width === i ? u : { top: l, left: a, width: i }
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 }
435
436
  );
436
437
  };
437
438
  return o(), window.addEventListener("scroll", o, !0), window.addEventListener("resize", o), () => {
438
439
  window.removeEventListener("scroll", o, !0), window.removeEventListener("resize", o);
439
440
  };
440
- }, [e]), { anchorRef: s, rect: r };
441
- }, L = 8, X = 16, Y = (e) => e instanceof D ? `Search failed (${e.status}${e.code ? ` ${e.code}` : ""}): ${e.message}` : "Search failed: network error. Check your connection and try again.", J = (e, s) => {
442
- const r = s.response;
443
- switch (s.status) {
444
- case p.LOADING:
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:
445
481
  return /* @__PURE__ */ h("p", { role: "status", className: "dialog-search-status", children: [
446
482
  "Searching “",
447
- s.query,
483
+ t.query,
448
484
  "”…"
449
485
  ] });
450
- case p.ERROR:
486
+ case b.ERROR:
451
487
  return /* @__PURE__ */ h("div", { className: "dialog-search-error", children: [
452
- /* @__PURE__ */ t(
488
+ /* @__PURE__ */ n(
453
489
  "p",
454
490
  {
455
491
  role: "alert",
456
492
  className: "dialog-search-status dialog-search-status-error",
457
- children: Y(s.error)
493
+ children: ee(t.error)
458
494
  }
459
495
  ),
460
- /* @__PURE__ */ t(
496
+ /* @__PURE__ */ n(
461
497
  "button",
462
498
  {
463
499
  type: "button",
@@ -467,118 +503,119 @@ const B = ({
467
503
  }
468
504
  )
469
505
  ] });
470
- case p.EMPTY:
506
+ case b.EMPTY:
471
507
  return /* @__PURE__ */ h("p", { role: "status", className: "dialog-search-status", children: [
472
508
  "No products match “",
473
- r == null ? void 0 : r.query,
509
+ s == null ? void 0 : s.query,
474
510
  "”."
475
511
  ] });
476
- case p.SUCCESS:
477
- return r === void 0 ? null : /* @__PURE__ */ h(b, { children: [
512
+ case b.SUCCESS:
513
+ return s === void 0 ? null : /* @__PURE__ */ h(y, { children: [
478
514
  /* @__PURE__ */ h("p", { role: "status", className: "dialog-search-status", children: [
479
- r.nbHits,
515
+ s.nbHits,
480
516
  " result",
481
- r.nbHits > 1 ? "s" : ""
517
+ s.nbHits > 1 ? "s" : ""
482
518
  ] }),
483
- /* @__PURE__ */ t("ul", { className: "dialog-search-results", children: r.hits.map((n, o) => /* @__PURE__ */ t(
484
- Z,
519
+ /* @__PURE__ */ n("ul", { className: "dialog-search-results", children: s.hits.map((r, c) => /* @__PURE__ */ n(
520
+ X,
485
521
  {
486
522
  controller: e,
487
- hit: n,
488
- index: o
523
+ hit: r,
524
+ index: c
489
525
  },
490
- n.id
526
+ r.id
491
527
  )) }),
492
- /* @__PURE__ */ t(U, { controller: e, state: s })
528
+ /* @__PURE__ */ n(W, { controller: e, state: t })
493
529
  ] });
494
530
  default:
495
531
  return null;
496
532
  }
497
- }, ce = ({
533
+ }, he = ({
498
534
  controller: e,
499
- state: s
535
+ state: t
500
536
  }) => {
501
- const r = s.status !== p.IDLE, { anchorRef: n, rect: o } = G(r);
502
- return /* @__PURE__ */ h(b, { children: [
503
- /* @__PURE__ */ t("div", { ref: n }),
504
- r && o !== void 0 && I(
505
- /* @__PURE__ */ t(
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(
506
542
  "div",
507
543
  {
544
+ ref: i,
508
545
  className: "dialog-search-panel",
509
- style: {
510
- top: o.top + L,
511
- left: o.left,
512
- width: o.width,
513
- maxHeight: `calc(100vh - ${o.top + L + X}px)`
514
- },
515
- children: J(e, s)
546
+ style: se(c, l),
547
+ children: re(e, t)
516
548
  }
517
549
  ),
518
550
  document.body
519
551
  )
520
552
  ] });
521
- }, ee = {
522
- status: p.IDLE,
553
+ }, ne = {
554
+ status: b.IDLE,
523
555
  query: "",
524
556
  page: 0
525
- }, le = (e) => {
526
- const s = f(e);
527
- s.current = e;
528
- const r = f(void 0), n = w(() => {
529
- if (r.current === void 0) {
530
- const { client: i, surface: u = "search_page", ...g } = s.current;
531
- r.current = M({
532
- search: (d, C) => i.search(d, C),
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),
533
565
  analytics: {
534
566
  surface: u,
535
- trackViewSearchResults: (d) => i.trackViewSearchResults(d),
536
- trackSelectSearchResult: (d) => i.trackSelectSearchResult(d)
567
+ trackViewSearchResults: (d) => a.trackViewSearchResults(d),
568
+ trackSelectSearchResult: (d) => a.trackSelectSearchResult(d)
537
569
  },
538
- ...g
570
+ ...m
539
571
  });
540
572
  }
541
- return r.current;
542
- }, []), o = f(void 0);
543
- o.current ?? (o.current = {
544
- setQuery: (i) => n().setQuery(i),
545
- submit: (i) => n().submit(i),
546
- setPage: (i) => n().setPage(i),
547
- retry: () => n().retry(),
548
- observeResult: (i, u) => n().observeResult(i, u),
549
- selectResult: (i, u) => n().selectResult(i, u),
550
- subscribe: (i) => n().subscribe(i),
551
- getState: () => n().getState(),
552
- dispose: () => n().dispose()
553
- }), y(() => {
554
- P({
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({
555
592
  method: "react",
556
- version: "2.2.0"
593
+ version: "2.2.1"
557
594
  });
558
- const i = n();
595
+ const a = r();
559
596
  return () => {
560
- i.dispose(), r.current === i && (r.current = void 0);
597
+ a.dispose(), s.current === a && (s.current = void 0);
561
598
  };
562
- }, [n]);
563
- const c = w(
564
- (i) => n().subscribe(i),
565
- [n]
566
- ), l = w(
567
- () => n().getState(),
568
- [n]
569
- ), a = E(
570
- c,
599
+ }, [r]);
600
+ const l = N(
601
+ (a) => r().subscribe(a),
602
+ [r]
603
+ ), o = N(
604
+ () => r().getState(),
605
+ [r]
606
+ ), i = x(
571
607
  l,
572
- () => ee
608
+ o,
609
+ () => ne
573
610
  );
574
- return { controller: o.current, state: a };
611
+ return { controller: c.current, state: i };
575
612
  };
576
613
  export {
577
614
  V as DialogInput,
578
- ae as DialogProductBlock,
579
- ie as DialogSearchBar,
580
- U as DialogSearchPagination,
581
- Z as DialogSearchProductCard,
582
- ce as DialogSearchResults,
583
- le as useDialogSearch
615
+ de as DialogProductBlock,
616
+ ue as DialogSearchBar,
617
+ W as DialogSearchPagination,
618
+ X as DialogSearchProductCard,
619
+ he as DialogSearchResults,
620
+ ge as useDialogSearch
584
621
  };
@@ -1 +1 @@
1
- (function(g,e){typeof exports=="object"&&typeof module<"u"?e(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"],e):(g=typeof globalThis<"u"?globalThis:g||self,e(g["dialog-react"]={},g["react/jsx-runtime"],g.React,g.dialogSdk,g.ReactDOM))})(this,(function(g,e,d,f,N){"use strict";const L=({title:s="Your expert",description:r="A question about this product?"})=>e.jsxs("div",{className:"dialog-block-header-container",children:[e.jsx("div",{className:"dialog-block-title",children:s}),e.jsx("div",{className:"dialog-block-description",children:r})]}),P=({color:s="#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:s,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:s,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"})})})]}),m=({client:s,questions:r,productId:t,productTitle:o,selectedVariantId:a})=>{const i=l=>{s.sendProductMessage({productId:t,productTitle:o,selectedVariantId:a,question:l,fromQuestionSuggestion:!0})};return e.jsx(e.Fragment,{children:r.map(l=>e.jsxs("button",{className:"dialog-block-suggestions-item",onClick:()=>i(l.question),children:[e.jsx(P,{color:s.theme.primaryColor}),e.jsx("span",{className:"dialog-block-suggestions-item-label",children:l.question})]},l.question))})},E=()=>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"})]}),D=({client:s,questions:r,isLoading:t,productId:o,productTitle:a,selectedVariantId:i})=>e.jsx("div",{className:"dialog-block-suggestions-container",children:t||!r?e.jsx(E,{}):e.jsx(m,{client:s,questions:r,productId:o,productTitle:a,selectedVariantId:i})}),M=({color:s="#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:s,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),v=({client:s,placeholder:r="Ask anything...",productId:t,productTitle:o,selectedVariantId:a})=>{const i=d.useRef(null),[l,c]=d.useState(""),n=()=>{var u;(u=i.current)==null||u.focus()},h=()=>{const u=l;u.trim()&&(s.sendProductMessage({productId:t,productTitle:o,selectedVariantId:a,question:u,fromQuestionSuggestion:!0}),c(""))},p=u=>{u.key==="Enter"&&h()};return e.jsxs("div",{className:"dialog-input-wrapper",onClick:n,children:[e.jsx("input",{id:"dialog-ask-anything-input-ai-input",ref:i,value:l,onChange:u=>c(u.target.value),className:"dialog-ask-anything-input-ai-input",placeholder:r,onKeyDown:p}),e.jsx("button",{id:"send-message-button-ai-input",className:"dialog-input-submit",disabled:!l.trim(),onClick:h,children:e.jsx(M,{color:s.theme.ctaTextColor})})]})},y=s=>s.replace(/([A-Z])/g,"-$1").toLowerCase(),A=s=>{if(!s)return;const r=document.body;Object.keys(s).forEach(t=>{const o=t,a=y(t);if(s[o]!==void 0){if(typeof s[o]=="object"){Object.keys(s[o]).forEach(i=>{var c;const l=i;if(l!==void 0){const n=y(i),h=s[o];r.style.setProperty(`--dialog-theme-${a}-${n}`,(c=h[l])==null?void 0:c.toString())}});return}if(o==="ctaBorderType"){const i=s[o]==="rounded"?"24px":"0";r.style.setProperty(`--dialog-theme-${a}`,i);return}r.style.setProperty(`--dialog-theme-${a}`,s[o].toString())}})},F=({theme:s,children:r})=>(d.useEffect(()=>{s&&A(s)},[s]),e.jsx(e.Fragment,{children:r})),I=({client:s,productId:r,productTitle:t,selectedVariantId:o,enableInput:a=!0})=>{const[i,l]=d.useState(!0),[c,n]=d.useState(void 0);d.useEffect(()=>{f.registerDialogInstallation({method:"react",version:"2.2.0"}),f.addAuditCapability("pdp-block")},[]);const h=d.useMemo(()=>i?"":c==null?void 0:c.assistantName,[c,i]),p=d.useMemo(()=>i?"":c==null?void 0:c.description,[c,i]),u=d.useMemo(()=>i?"":c==null?void 0:c.inputPlaceholder,[c,i]),C=d.useMemo(()=>{var b;return f.resolveTextDirection((b=s.getLocalizationInformations())==null?void 0:b.languageCode)},[s]);return d.useEffect(()=>{let b=!0;return(async()=>{l(!0),n(void 0);try{const S=await s.getSuggestions(r);b&&n(S)}catch(S){console.error("error",S)}finally{b&&l(!1)}})(),()=>{b=!1}},[s,r]),e.jsx(F,{theme:s.theme,children:e.jsxs("div",{id:"dialog-instant",className:"dialog-block-container",dir:C,children:[e.jsx(L,{title:h,description:p}),e.jsx(D,{client:s,questions:c==null?void 0:c.questions,isLoading:i,productId:r,productTitle:t,selectedVariantId:o}),a&&e.jsx(v,{client:s,placeholder:u,productId:r,productTitle:t,selectedVariantId:o})]})})},_=()=>e.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:e.jsx("path",{d:"M8 13V3M8 3L3 8M8 3L13 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),T="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",B=({color:s="currentColor"})=>e.jsx("svg",{width:16,height:16,viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:e.jsx("path",{d:T,fill:s})}),O=({controller:s,placeholder:r="Search products...",autoFocus:t=!1,submitAriaLabel:o="Search"})=>{const[a,i]=d.useState(""),l=c=>{c.preventDefault(),s.submit(a)};return e.jsxs("form",{className:"dialog-search-bar",role:"search",onSubmit:l,children:[e.jsxs("div",{className:"dialog-search-bar-field",children:[e.jsx("span",{className:"dialog-search-bar-icon",children:e.jsx(B,{})}),e.jsx("input",{type:"text",className:"dialog-search-bar-input",value:a,"aria-label":r,placeholder:r,autoFocus:t,onChange:c=>{i(c.target.value),s.setQuery(c.target.value)}})]}),e.jsx("button",{type:"submit",className:"dialog-search-bar-submit","aria-label":o,children:e.jsx(_,{})})]})},k=({controller:s,state:r})=>{const t=r.response;return t===void 0||t.nbPages<=1?null:e.jsxs("nav",{"aria-label":"Search results pages",className:"dialog-search-pagination",children:[e.jsx("button",{type:"button",disabled:t.page===0,onClick:()=>s.setPage(t.page-1),children:"Previous"}),e.jsxs("span",{children:["Page ",t.page+1," / ",t.nbPages]}),e.jsx("button",{type:"button",disabled:t.page>=t.nbPages-1,onClick:()=>s.setPage(t.page+1),children:"Next"})]})},$=s=>{if(s===void 0)return"";const{min:r,max:t}=s,o=({amount:a,currencyCode:i})=>new Intl.NumberFormat(void 0,{style:"currency",currency:i}).format(Number(a));try{return r.amount===t.amount?o(r):`${o(r)} – ${o(t)}`}catch{return""}},q=s=>{try{const{protocol:r}=new URL(s,window.location.href);return r==="http:"||r==="https:"?s:void 0}catch{return}},w=({controller:s,hit:r,index:t})=>{const o=d.useRef(null);d.useEffect(()=>{o.current!==null&&s.observeResult(o.current,t)},[s,r,t]);const a=u=>{const C=u.metaKey||u.ctrlKey||u.shiftKey||u.altKey;s.selectResult(t,{navigate:!C})&&u.preventDefault()},i=u=>{u.button===1&&s.selectResult(t,{navigate:!1})},{product:l}=r,c=l.title??l.id,n=$(l.priceRange),h=l.url===void 0?void 0:q(l.url),p=e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"dialog-search-card-image",children:l.imageUrl!==void 0&&e.jsx("img",{src:l.imageUrl,alt:c,loading:"lazy"})}),e.jsxs("div",{className:"dialog-search-card-info",children:[e.jsx("p",{className:"dialog-search-card-title",children:c}),n!==""&&e.jsx("p",{className:"dialog-search-card-price",children:n})]})]});return e.jsx("li",{ref:o,className:"dialog-search-card",children:h===void 0?e.jsx("div",{className:"dialog-search-card-body",children:p}):e.jsx("a",{className:"dialog-search-card-body",href:h,onClick:a,onAuxClick:i,children:p})})},x=s=>{const r=d.useRef(null),[t,o]=d.useState(void 0);return d.useLayoutEffect(()=>{if(!s)return;const a=()=>{const i=r.current;if(i===null)return;const{top:l,left:c,width:n}=i.getBoundingClientRect();o(h=>h!==void 0&&h.top===l&&h.left===c&&h.width===n?h:{top:l,left:c,width:n})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[s]),{anchorRef:r,rect:t}},K=s=>s instanceof f.DialogSearchError?`Search failed (${s.status}${s.code?` ${s.code}`:""}): ${s.message}`:"Search failed: network error. Check your connection and try again.",V=(s,r)=>{const t=r.response;switch(r.status){case f.SearchStatus.LOADING:return e.jsxs("p",{role:"status",className:"dialog-search-status",children:["Searching “",r.query,"”…"]});case f.SearchStatus.ERROR:return e.jsxs("div",{className:"dialog-search-error",children:[e.jsx("p",{role:"alert",className:"dialog-search-status dialog-search-status-error",children:K(r.error)}),e.jsx("button",{type:"button",className:"dialog-search-retry",onClick:()=>s.retry(),children:"Retry"})]});case f.SearchStatus.EMPTY:return e.jsxs("p",{role:"status",className:"dialog-search-status",children:["No products match “",t==null?void 0:t.query,"”."]});case f.SearchStatus.SUCCESS:return t===void 0?null:e.jsxs(e.Fragment,{children:[e.jsxs("p",{role:"status",className:"dialog-search-status",children:[t.nbHits," result",t.nbHits>1?"s":""]}),e.jsx("ul",{className:"dialog-search-results",children:t.hits.map((o,a)=>e.jsx(w,{controller:s,hit:o,index:a},o.id))}),e.jsx(k,{controller:s,state:r})]});default:return null}},H=({controller:s,state:r})=>{const t=r.status!==f.SearchStatus.IDLE,{anchorRef:o,rect:a}=x(t);return e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:o}),t&&a!==void 0&&N.createPortal(e.jsx("div",{className:"dialog-search-panel",style:{top:a.top+8,left:a.left,width:a.width,maxHeight:`calc(100vh - ${a.top+8+16}px)`},children:V(s,r)}),document.body)]})},j={status:f.SearchStatus.IDLE,query:"",page:0},Q=s=>{const r=d.useRef(s);r.current=s;const t=d.useRef(void 0),o=d.useCallback(()=>{if(t.current===void 0){const{client:n,surface:h="search_page",...p}=r.current;t.current=f.createSearchController({search:(u,C)=>n.search(u,C),analytics:{surface:h,trackViewSearchResults:u=>n.trackViewSearchResults(u),trackSelectSearchResult:u=>n.trackSelectSearchResult(u)},...p})}return t.current},[]),a=d.useRef(void 0);a.current??(a.current={setQuery:n=>o().setQuery(n),submit:n=>o().submit(n),setPage:n=>o().setPage(n),retry:()=>o().retry(),observeResult:(n,h)=>o().observeResult(n,h),selectResult:(n,h)=>o().selectResult(n,h),subscribe:n=>o().subscribe(n),getState:()=>o().getState(),dispose:()=>o().dispose()}),d.useEffect(()=>{f.registerDialogInstallation({method:"react",version:"2.2.0"});const n=o();return()=>{n.dispose(),t.current===n&&(t.current=void 0)}},[o]);const i=d.useCallback(n=>o().subscribe(n),[o]),l=d.useCallback(()=>o().getState(),[o]),c=d.useSyncExternalStore(i,l,()=>j);return{controller:a.current,state:c}};g.DialogInput=v,g.DialogProductBlock=I,g.DialogSearchBar=O,g.DialogSearchPagination=k,g.DialogSearchProductCard=w,g.DialogSearchResults=H,g.useDialogSearch=Q,Object.defineProperty(g,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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askdialog/dialog-react",
3
- "version": "2.2.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.8.0"
29
+ "@askdialog/dialog-sdk": "2.8.1"
30
30
  },
31
31
  "author": "Dialog",
32
32
  "publishConfig": {