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