@depict-ai/react-ui 1.5.2 → 1.5.4
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/ES10/index.cjs +864 -0
- package/{dist → ES10}/index.d.ts +170 -177
- package/ES10/index.js +843 -0
- package/latest/index.cjs +831 -0
- package/latest/index.d.ts +529 -0
- package/latest/index.js +810 -0
- package/locales/ES10/index.cjs +1 -0
- package/locales/ES10/index.d.ts +2 -0
- package/locales/ES10/index.js +1 -0
- package/locales/index.cjs +1 -0
- package/locales/index.d.ts +2 -2
- package/locales/index.js +1 -1
- package/locales/latest/index.cjs +1 -0
- package/locales/latest/index.d.ts +2 -0
- package/locales/latest/index.js +1 -0
- package/multi_import_deduplicator.cjs +31 -0
- package/multi_import_deduplicator.mjs +31 -0
- package/package.json +89 -52
- package/server/ES10/index.cjs +135 -0
- package/server/ES10/index.d.ts +529 -0
- package/server/ES10/index.js +115 -0
- package/server/latest/index.cjs +134 -0
- package/server/latest/index.d.ts +529 -0
- package/server/latest/index.js +114 -0
- package/dist/main.js +0 -879
- package/dist/module.js +0 -860
- package/dist-server/index.d.ts +0 -58
- package/dist-server/main.js +0 -136
- package/dist-server/module.js +0 -119
- package/locales/require.js +0 -1
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { BaseProductListingConfig, BaseProviderConfig, BaseSearchProviderConfig, ModernDisplayWithPageUrl, BaseSearchPageConfig, BaseCategoryPageConfig, CategoryTitle, embedded_num_products, ImagePlaceholder as _ImagePlaceholder1, TextPlaceholder as _TextPlaceholder1, ExclusiveId, fetchDepictRecommendations } from "@depict-ai/ui/ES10";
|
|
2
|
+
import { Display, ModernDisplay } from "@depict-ai/utilishared/ES10";
|
|
3
|
+
import React, { ReactNode, PropsWithChildren, ReactElement } from "react";
|
|
4
|
+
import { DPC } from "@depict-ai/dpc/ES10";
|
|
5
|
+
import { Locale } from "@depict-ai/ui/locales/ES10";
|
|
6
|
+
export const version = "1.5.4";
|
|
7
|
+
interface PLPConfig<T extends Display> extends BaseProductListingConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The product card to use for rendering products.
|
|
10
|
+
*/
|
|
11
|
+
productCard: DepictProductCard<T>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The Depict product card props.
|
|
15
|
+
*/
|
|
16
|
+
export interface DepictProductCardProps<T extends Display> {
|
|
17
|
+
/** The display data to render. */
|
|
18
|
+
display: T | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Depict product card to use for rendering products.
|
|
22
|
+
*/
|
|
23
|
+
export type DepictProductCard<T extends Display> = (props: DepictProductCardProps<T>) => ReactNode;
|
|
24
|
+
interface UsePerformanceClientReturn {
|
|
25
|
+
dpc: DPC;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Hook used to access the Depict Performance Client.
|
|
29
|
+
* Calls on the returned DPC instance can not be done server side.
|
|
30
|
+
* @example
|
|
31
|
+
* Send an add-to-cart event
|
|
32
|
+
* ```tsx
|
|
33
|
+
* import { useEffect } from "react";
|
|
34
|
+
* import { usePerformanceClient } from "@depict-ai/react-ui";
|
|
35
|
+
*
|
|
36
|
+
* const ProductPage = ({ productId }) => {
|
|
37
|
+
* const { dpc } = usePerformanceClient();
|
|
38
|
+
*
|
|
39
|
+
* useEffect(() => {
|
|
40
|
+
* dpc.setProductId(productId);
|
|
41
|
+
* }, [dpc, productId]);
|
|
42
|
+
*
|
|
43
|
+
* return <div>Showing product {productId}</div>;
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
* @returns {UsePerformanceClientReturn}
|
|
47
|
+
}
|
|
48
|
+
*/
|
|
49
|
+
export const usePerformanceClient: () => UsePerformanceClientReturn;
|
|
50
|
+
/**
|
|
51
|
+
* relativeUrl: The relative url to navigate to.
|
|
52
|
+
* replace: Whether to replace the current url or push a new one.
|
|
53
|
+
*/
|
|
54
|
+
type NavigateFunction = (relativeUrl: string, options: {
|
|
55
|
+
replace: boolean;
|
|
56
|
+
scroll: boolean;
|
|
57
|
+
}) => void;
|
|
58
|
+
/**
|
|
59
|
+
* The config for the DepictProvider.
|
|
60
|
+
*/
|
|
61
|
+
type ProviderConfig<OriginalDisplay extends Display, OutputDisplay extends ModernDisplay | never> = BaseProviderConfig<OriginalDisplay, OutputDisplay> & {
|
|
62
|
+
/**
|
|
63
|
+
* The function to use for navigating to a new page.
|
|
64
|
+
* This function will be used internally by our components to navigate.
|
|
65
|
+
*
|
|
66
|
+
* You don't need to provide any in a Next.js context.
|
|
67
|
+
*
|
|
68
|
+
* @param relativeUrl - The relative url to navigate to.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* Here is how you would use it with react-router, @reach/router, Gatsby or similar.
|
|
72
|
+
* ```tsx
|
|
73
|
+
* import { DepictProvider, Navigation } from "@depict-ai/react-ui";
|
|
74
|
+
* import { useNavigate } from "react-router-dom";
|
|
75
|
+
* // import { navigate } from "gatsby";
|
|
76
|
+
*
|
|
77
|
+
* function Router() {
|
|
78
|
+
* const navigate = useNavigate();
|
|
79
|
+
* return (
|
|
80
|
+
* <DepictProvider
|
|
81
|
+
* merchant="houdini"
|
|
82
|
+
* market="en-de"
|
|
83
|
+
* navigateFunction={navigate}
|
|
84
|
+
* search={{
|
|
85
|
+
* searchPagePath: "/search",
|
|
86
|
+
* }}
|
|
87
|
+
* >
|
|
88
|
+
* <Routes>[...]</Routes>
|
|
89
|
+
* </DepictProvider>
|
|
90
|
+
* );
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
* @example
|
|
94
|
+
* If you're using another library, you can define your own navigate function, that's compatible with the `NavigateFunction` type.
|
|
95
|
+
* ```tsx
|
|
96
|
+
* const navigateFunction = (relativeUrl: string, { replace }) => {
|
|
97
|
+
* router.push(relativeUrl, { replace });
|
|
98
|
+
* };
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
navigateFunction?: NavigateFunction;
|
|
102
|
+
/**
|
|
103
|
+
* The locale to use for the Depict components.
|
|
104
|
+
* @default en
|
|
105
|
+
*/
|
|
106
|
+
locale?: Locale;
|
|
107
|
+
/**
|
|
108
|
+
* Unique ID of the currently logged in user, if applicable.
|
|
109
|
+
*/
|
|
110
|
+
userId?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Options that are required for search functionality.
|
|
113
|
+
*/
|
|
114
|
+
search?: BaseSearchProviderConfig;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* The DepictProvider is a wrapper component that should be used to wrap any component that uses Depict components.
|
|
118
|
+
*
|
|
119
|
+
* Make sure it's mounted on every page where the search modal should be available.
|
|
120
|
+
*
|
|
121
|
+
* @param props - The props for the DepictProvider.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```tsx
|
|
125
|
+
* const App = () => { *
|
|
126
|
+
* return (
|
|
127
|
+
* <DepictProvider
|
|
128
|
+
* merchant="YOUR_MERCHANT"
|
|
129
|
+
* market="YOUR_MARKET"
|
|
130
|
+
* search={{
|
|
131
|
+
* searchPagePath: "/search",
|
|
132
|
+
* }}
|
|
133
|
+
* >
|
|
134
|
+
* <App />
|
|
135
|
+
* </DepictProvider>
|
|
136
|
+
* );
|
|
137
|
+
* };
|
|
138
|
+
* ```
|
|
139
|
+
* @returns {JSX.Element} The DepictProvider.
|
|
140
|
+
*/
|
|
141
|
+
export function DepictProvider<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never = InputDisplay extends ModernDisplay ? ModernDisplayWithPageUrl<InputDisplay> : never>(props: PropsWithChildren<ProviderConfig<InputDisplay, OutputDisplay>>): import("react").FunctionComponentElement<{
|
|
142
|
+
children?: import("react").ReactNode;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* A component used to align other Depict components to.
|
|
146
|
+
* @example
|
|
147
|
+
* Align the search modal
|
|
148
|
+
* ```tsx
|
|
149
|
+
* import React from "react";
|
|
150
|
+
* import { ComponentAligner, useSearchModal } from "@depict-ai/react-ui";
|
|
151
|
+
*
|
|
152
|
+
* const App = () => {
|
|
153
|
+
* const ref = React.createRef();
|
|
154
|
+
*
|
|
155
|
+
* const { open } = useSearchModal({
|
|
156
|
+
* location: "aligned",
|
|
157
|
+
* alignerRef: ref,
|
|
158
|
+
* });
|
|
159
|
+
*
|
|
160
|
+
* return (
|
|
161
|
+
* <div>
|
|
162
|
+
* <ComponentAligner ref={ref} />
|
|
163
|
+
* <button onClick={open}>Open</button>
|
|
164
|
+
* </div>
|
|
165
|
+
* );
|
|
166
|
+
* };
|
|
167
|
+
* ```
|
|
168
|
+
* @returns {JSX.Element}
|
|
169
|
+
*/
|
|
170
|
+
export const ComponentAligner: import("react").ForwardRefExoticComponent<import("react").RefAttributes<unknown>>;
|
|
171
|
+
interface SearchPageConfig<T extends Display> extends BaseSearchPageConfig, PLPConfig<T> {
|
|
172
|
+
/**
|
|
173
|
+
* When using multiple search instances on the same page, you need to set a unique stateKey for each one. We recommend using an incrementing number, such as "1", "2", "3", etc. To associate a modal with a SearchPage keyed component, set the same stateKey on both. If no stateKey is provided, the "default" instance will be used.
|
|
174
|
+
*/
|
|
175
|
+
stateKey?: string;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* SearchPage is a component that renders a Depict search results page.
|
|
179
|
+
* @param props - The props for the search page. Go to definition for more info.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```tsx
|
|
183
|
+
* import { DepictProductCard, ImagePlaceholder, Display, SearchPage } from '@depict-ai/react-ui'
|
|
184
|
+
*
|
|
185
|
+
* function Search() {
|
|
186
|
+
* return <SearchPage productCard={MyCustomSearchProductCard} />
|
|
187
|
+
* }
|
|
188
|
+
*
|
|
189
|
+
* interface MyCustomDisplay extends Display {}
|
|
190
|
+
*
|
|
191
|
+
* export const MyCustomSearchProductCard: DepictProductCard<MyCustomDisplay> = ({
|
|
192
|
+
* display,
|
|
193
|
+
* }) => {
|
|
194
|
+
* if (!display) {
|
|
195
|
+
* return <ImagePlaceholder aspectRatio={3 / 4} />
|
|
196
|
+
* }
|
|
197
|
+
*
|
|
198
|
+
* return (
|
|
199
|
+
* <>
|
|
200
|
+
* <MyCustomProductCard
|
|
201
|
+
* product={{
|
|
202
|
+
* id: display.product_id,
|
|
203
|
+
* name: display.title,
|
|
204
|
+
* description: display.title,
|
|
205
|
+
* images: [{ url: display.image_url }],
|
|
206
|
+
* price: {
|
|
207
|
+
* value: display.sale_price,
|
|
208
|
+
* },
|
|
209
|
+
* }}
|
|
210
|
+
* />
|
|
211
|
+
* </>
|
|
212
|
+
* )
|
|
213
|
+
* }
|
|
214
|
+
*
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export function SearchPage<OriginalDisplay extends Display, OutputDisplay extends ModernDisplay | never>(props: SearchPageConfig<[OutputDisplay] extends [never] ? OriginalDisplay : ModernDisplayWithPageUrl<OutputDisplay>>): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
218
|
+
interface CategoryPageConfig<T extends Display> extends BaseCategoryPageConfig, PLPConfig<T> {
|
|
219
|
+
/**
|
|
220
|
+
* The category id to show.
|
|
221
|
+
*/
|
|
222
|
+
categoryId: string;
|
|
223
|
+
/**
|
|
224
|
+
* categoryTitlePlugin is an optional plugin that can be used to customize the title of the category page.
|
|
225
|
+
* @default CategoryTitle
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```tsx
|
|
229
|
+
* <CategoryPage categoryId="jeans" productCard={MyCustomCategoryProductCard} categoryTitlePlugin={EmbeddedNumProducts} />
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
categoryTitlePlugin?: typeof CategoryTitle | typeof embedded_num_products;
|
|
233
|
+
/**
|
|
234
|
+
* Whether this page is a collection or a category. If not specified it will be inferred as described in the docs https://docs.depict.ai/reference/category-sdk/specifying-listing-type-in-the-category-page-sdk
|
|
235
|
+
*/
|
|
236
|
+
listingType?: "collection" | "category";
|
|
237
|
+
/**
|
|
238
|
+
* When using multiple CategoryPage components on the same page, you need to set a unique stateKey for each one. We recommend using an incrementing number, such as "1", "2", "3", etc. To associate a certain BreadCrumbs or QuickLinks component with a certain CategoryPage component, set the same stateKey on both.
|
|
239
|
+
*/
|
|
240
|
+
stateKey?: string;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* CategoryPage is a component that renders a Depict category page. Go to definition on the props for more info.
|
|
244
|
+
* @param props the props for the category page.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```tsx
|
|
248
|
+
* import { DepictProductCard, ImagePlaceholder, Display, CategoryPage } from '@depict-ai/react-ui'
|
|
249
|
+
*
|
|
250
|
+
* function Category() {
|
|
251
|
+
* return <CategoryPage categoryId="jeans" productCard={MyCustomCategoryProductCard} />
|
|
252
|
+
* }
|
|
253
|
+
*
|
|
254
|
+
* interface MyCustomDisplay extends Display {}
|
|
255
|
+
*
|
|
256
|
+
* export const MyCustomCategoryProductCard: DepictProductCard<MyCustomDisplay> = ({
|
|
257
|
+
* display,
|
|
258
|
+
* }) => {
|
|
259
|
+
* if (!display) {
|
|
260
|
+
* return <ImagePlaceholder aspectRatio={3 / 4} />
|
|
261
|
+
* }
|
|
262
|
+
*
|
|
263
|
+
* return (
|
|
264
|
+
* <>
|
|
265
|
+
* <MyCustomProductCard
|
|
266
|
+
* product={{
|
|
267
|
+
* id: display.product_id,
|
|
268
|
+
* name: display.title,
|
|
269
|
+
* description: display.title,
|
|
270
|
+
* images: [{ url: display.image_url }],
|
|
271
|
+
* price: {
|
|
272
|
+
* value: display.sale_price,
|
|
273
|
+
* },
|
|
274
|
+
* }}
|
|
275
|
+
* />
|
|
276
|
+
* </>
|
|
277
|
+
* )
|
|
278
|
+
* }
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
export function CategoryPage<OriginalDisplay extends Display, OutputDisplay extends ModernDisplay | never>(props: CategoryPageConfig<[OutputDisplay] extends [never] ? OriginalDisplay : ModernDisplayWithPageUrl<OutputDisplay>>): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
282
|
+
/**
|
|
283
|
+
* BreadCrumbs is the "trail" in the header of a category page.
|
|
284
|
+
* @property stateKey - When using multiple CategoryPage components on the same page, you need to set a unique stateKey for each one. To associate a certain BreadCrumbs component with a certain CategoryPage component, set the same stateKey on both.
|
|
285
|
+
*/
|
|
286
|
+
export function BreadCrumbs(react_props: {
|
|
287
|
+
stateKey?: string | undefined;
|
|
288
|
+
}): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
289
|
+
/**
|
|
290
|
+
* QuickLinks is a component enabling the user to go sideways and downwards in the category tree.
|
|
291
|
+
* @property stateKey - When using multiple CategoryPage components on the same page, you need to set a unique stateKey for each one. To associate a certain QuickLinks component with a certain CategoryPage component, set the same stateKey on both.
|
|
292
|
+
*/
|
|
293
|
+
export function QuickLinks(react_props?: {
|
|
294
|
+
stateKey?: string | undefined;
|
|
295
|
+
}): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
296
|
+
/**
|
|
297
|
+
* A placeholder that can be used instead of an image or other block of content while it's loading.
|
|
298
|
+
* The placeholder has `display:block`, meaning it will create a new "row" in the layout for itself. Can be used either for images with a defined aspect ratio (ContainedImage) or blocks.
|
|
299
|
+
* @property aspectRatio if aspectRatio is defined the placeholder will be in "image mode" and fill out the available width and then adjust the height according to the aspectRatio
|
|
300
|
+
* @property width If width and height is set, the defined width and height will be used.
|
|
301
|
+
* @property height If width and height is set, the defined width and height will be used.
|
|
302
|
+
* @property class extra classes to add to the placeholder
|
|
303
|
+
* @property style extra styles to add to the placeholder
|
|
304
|
+
*/
|
|
305
|
+
export const ImagePlaceholder: React.FC<Parameters<typeof _ImagePlaceholder1>[0] & {
|
|
306
|
+
className?: string;
|
|
307
|
+
}>;
|
|
308
|
+
/**
|
|
309
|
+
* A Placeholder to use instead of some text, while it's loading. This is the inline version, meant to be embedded into sentences (or exist instead of them), etc.
|
|
310
|
+
* If you want a block version, use `ImagePlaceholder` with `width`and `height` set instead.
|
|
311
|
+
* @property height height of the placeholder. Set to `1em` by default.
|
|
312
|
+
* @property width width of the placeholder. For specific number of characters use `ch`, ex: `width="7ch"`
|
|
313
|
+
* @property className extra classes to add to the placeholder
|
|
314
|
+
* @property style extra styles to add to the placeholder
|
|
315
|
+
*/
|
|
316
|
+
export const TextPlaceholder: React.FC<Parameters<typeof _TextPlaceholder1>[0] & {
|
|
317
|
+
className?: string;
|
|
318
|
+
}>;
|
|
319
|
+
/**
|
|
320
|
+
* Parameters to configure the search modal.
|
|
321
|
+
*/
|
|
322
|
+
interface UseSearchModalParams {
|
|
323
|
+
/**
|
|
324
|
+
* How the modal should be opened.
|
|
325
|
+
* Will default to "centered" if nothing else is specified.
|
|
326
|
+
* - "centered" - The modal will be opened in the center of the screen.
|
|
327
|
+
* - "aligned" - The modal will be opened aligned to the alignerRef element.
|
|
328
|
+
*/
|
|
329
|
+
location?: ModalLocation;
|
|
330
|
+
/**
|
|
331
|
+
* The ref to the element that the modal should be aligned to.
|
|
332
|
+
* This is only used when location is "aligned".
|
|
333
|
+
* @default undefined
|
|
334
|
+
* @example
|
|
335
|
+
* ```tsx
|
|
336
|
+
import React from "react";
|
|
337
|
+
import { ComponentAligner, useSearchModal } from "@depict-ai/react-ui";
|
|
338
|
+
const App = () => {
|
|
339
|
+
const ref = React.createRef();
|
|
340
|
+
const { open } = useSearchModal({
|
|
341
|
+
location: "aligned",
|
|
342
|
+
alignerRef: ref,
|
|
343
|
+
});
|
|
344
|
+
return (
|
|
345
|
+
<div>
|
|
346
|
+
<ComponentAligner ref={ref} />
|
|
347
|
+
<button onClick={open}>Open</button>
|
|
348
|
+
</div>
|
|
349
|
+
);
|
|
350
|
+
};
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
alignerRef?: React.RefObject<HTMLElement>;
|
|
354
|
+
/**
|
|
355
|
+
* When using multiple search instances on the same page, you need to set a unique stateKey for each one. We recommend using an incrementing number, such as "1", "2", "3", etc. To associate a modal with a SearchPage keyed component, set the same stateKey on both. If no stateKey is provided, the "default" instance will be used.
|
|
356
|
+
*/
|
|
357
|
+
stateKey?: string;
|
|
358
|
+
}
|
|
359
|
+
type OpenModal = () => void;
|
|
360
|
+
/**
|
|
361
|
+
* How the modal should be opened.
|
|
362
|
+
*/
|
|
363
|
+
type ModalLocation = "centered" | "aligned";
|
|
364
|
+
interface UseSearchModalReturn {
|
|
365
|
+
open: OpenModal;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Hook used to open the search modal.
|
|
369
|
+
* @example
|
|
370
|
+
* Open a centered modal:
|
|
371
|
+
* ```tsx
|
|
372
|
+
* import React from "react";
|
|
373
|
+
* import { useSearchModal } from "@depict-ai/react-ui";
|
|
374
|
+
*
|
|
375
|
+
* const App = () => {
|
|
376
|
+
* const { open } = useSearchModal({
|
|
377
|
+
* location: "centered",
|
|
378
|
+
* });
|
|
379
|
+
*
|
|
380
|
+
* return (
|
|
381
|
+
* <div>
|
|
382
|
+
* <button onClick={open}>Open</button>
|
|
383
|
+
* </div>
|
|
384
|
+
* );
|
|
385
|
+
* };
|
|
386
|
+
* ```
|
|
387
|
+
* @returns {UseSearchModalReturn}
|
|
388
|
+
*/
|
|
389
|
+
export function useSearchModal(params?: UseSearchModalParams): UseSearchModalReturn;
|
|
390
|
+
interface SearchFieldProps {
|
|
391
|
+
/**
|
|
392
|
+
* A reference to the DOM element that the modal should be aligned to.
|
|
393
|
+
*
|
|
394
|
+
* The top of the modal will be aligned to the top of the element.
|
|
395
|
+
*
|
|
396
|
+
* The height of the search field in the modal will be the same as the height of the element.
|
|
397
|
+
* If not provided, the modal will be aligned to the search field itself.
|
|
398
|
+
*/
|
|
399
|
+
alignerRef?: React.RefObject<HTMLElement>;
|
|
400
|
+
/**
|
|
401
|
+
* When using multiple search instances on the same page, you need to set a unique stateKey for each one. We recommend using an incrementing number, such as "1", "2", "3", etc. To associate a modal with a SearchPage keyed component, set the same stateKey on both. If no stateKey is provided, the "default" instance will be used.
|
|
402
|
+
*/
|
|
403
|
+
stateKey?: string;
|
|
404
|
+
}
|
|
405
|
+
interface UseSearchFieldReturn {
|
|
406
|
+
/**
|
|
407
|
+
* A React component that renders the search field.
|
|
408
|
+
*/
|
|
409
|
+
SearchField: () => ReactElement;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Hook used to configure the Depict search field.
|
|
413
|
+
* @example
|
|
414
|
+
* Render a search field that opens a modal aligned to the search field itself:
|
|
415
|
+
* ```tsx
|
|
416
|
+
* import React from "react";
|
|
417
|
+
* import { useSearchField } from "@depict-ai/react-ui";
|
|
418
|
+
*
|
|
419
|
+
* const App = () => {
|
|
420
|
+
* const { SearchField } = useSearchField();
|
|
421
|
+
*
|
|
422
|
+
* return (
|
|
423
|
+
* <div>
|
|
424
|
+
* <SearchField />
|
|
425
|
+
* </div>
|
|
426
|
+
* );
|
|
427
|
+
* };
|
|
428
|
+
* ```
|
|
429
|
+
* @example
|
|
430
|
+
* Render a search field that opens a modal aligned another DOM element:
|
|
431
|
+
* ```tsx
|
|
432
|
+
* import React from "react";
|
|
433
|
+
* import { ComponentAligner, useSearchField } from "@depict-ai/react-ui";
|
|
434
|
+
*
|
|
435
|
+
* const App = () => {
|
|
436
|
+
* const ref = useRef(null);
|
|
437
|
+
* const { SearchField } = useSearchField({
|
|
438
|
+
* alignerRef: ref
|
|
439
|
+
* });
|
|
440
|
+
*
|
|
441
|
+
* return (
|
|
442
|
+
* <div>
|
|
443
|
+
* <ComponentAligner ref={ref} />
|
|
444
|
+
* <SearchField />
|
|
445
|
+
* </div>
|
|
446
|
+
* );
|
|
447
|
+
* };
|
|
448
|
+
* ```
|
|
449
|
+
* @returns {UseSearchFieldReturn}
|
|
450
|
+
*/
|
|
451
|
+
export const useSearchField: (props?: SearchFieldProps) => UseSearchFieldReturn;
|
|
452
|
+
type FetchRecsOptions = Omit<Parameters<typeof fetchDepictRecommendations>[0], "merchant" | "market" | "userId" | "sessionId"> & ExclusiveId;
|
|
453
|
+
interface UseFetchRecommendationsReturn<T extends Display> {
|
|
454
|
+
/**
|
|
455
|
+
* Fetch recommendations from the Depict API.
|
|
456
|
+
* @example
|
|
457
|
+
* General recommendations for a landing page:
|
|
458
|
+
* ```tsx
|
|
459
|
+
* fetchRecommendations({ type: "landing_page" });
|
|
460
|
+
* ```
|
|
461
|
+
* @example
|
|
462
|
+
* Fetch targeted recommendations for a product details page (PDP):
|
|
463
|
+
* ```tsx
|
|
464
|
+
* fetchRecommendations({ type: "related", productId: "t-shirt-white" })
|
|
465
|
+
* ```
|
|
466
|
+
* @returns {Promise<T[]>}
|
|
467
|
+
*/
|
|
468
|
+
fetchRecommendations: (opts: FetchRecsOptions) => Promise<T[]>;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Hook used to fetch Depict recommendations.
|
|
472
|
+
* @example
|
|
473
|
+
* Fetch general recommendations for a landing page:
|
|
474
|
+
* ```tsx
|
|
475
|
+
* import React from "react";
|
|
476
|
+
* import { useFetchRecommendations } from "@depict-ai/react-ui";
|
|
477
|
+
*
|
|
478
|
+
* export const LandingPage = () => {
|
|
479
|
+
* const [recs, setRecs] = React.useState();
|
|
480
|
+
* const { fetchRecommendations } = useFetchRecommendations();
|
|
481
|
+
*
|
|
482
|
+
* React.useEffect(() => {
|
|
483
|
+
* fetchRecommendations({ type: "landing_page" }).then(setRecs);
|
|
484
|
+
* }, [fetchRecommendations]);
|
|
485
|
+
*
|
|
486
|
+
* return (
|
|
487
|
+
* <div>
|
|
488
|
+
* {recs?.map((display) => (
|
|
489
|
+
* <ProductCard display={display} />
|
|
490
|
+
* ))}
|
|
491
|
+
* </div>
|
|
492
|
+
* );
|
|
493
|
+
* };
|
|
494
|
+
* ```
|
|
495
|
+
* @example
|
|
496
|
+
* Fetch targeted recommendations for a product details page (PDP):
|
|
497
|
+
* ```tsx
|
|
498
|
+
* import React from "react";
|
|
499
|
+
* import { useFetchRecommendations } from "@depict-ai/react-ui";
|
|
500
|
+
*
|
|
501
|
+
* export const ProductPage = ({ productId }) => {
|
|
502
|
+
* const [recs, setRecs] = React.useState();
|
|
503
|
+
* const { fetchRecommendations } = useFetchRecommendations();
|
|
504
|
+
*
|
|
505
|
+
* React.useEffect(() => {
|
|
506
|
+
* fetchRecommendations({ type: "related", productId }).then(setRecs);
|
|
507
|
+
* }, [fetchRecommendations, productId]);
|
|
508
|
+
*
|
|
509
|
+
* return (
|
|
510
|
+
* <div>
|
|
511
|
+
* {recs?.map((display) => (
|
|
512
|
+
* <ProductCard display={display} />
|
|
513
|
+
* ))}
|
|
514
|
+
* </div>
|
|
515
|
+
* );
|
|
516
|
+
* };
|
|
517
|
+
* ```
|
|
518
|
+
* @returns {UseFetchRecommendationsReturn}
|
|
519
|
+
*/
|
|
520
|
+
export function useFetchRecommendations<T extends Display>(): UseFetchRecommendationsReturn<T>;
|
|
521
|
+
/**
|
|
522
|
+
* Helper function to navigate to a new page depending on the navigation library used.
|
|
523
|
+
*/
|
|
524
|
+
export const Navigation: {
|
|
525
|
+
nextRouterNavigation: (router: import("next/router").NextRouter) => import("ui/components/DepictProvider").NavigateFunction;
|
|
526
|
+
};
|
|
527
|
+
export { CategoryTitle, embedded_num_products as EmbeddedNumProducts } from "@depict-ai/ui";
|
|
528
|
+
export type { PageURLCreator } from "@depict-ai/ui";
|
|
529
|
+
export type { Locale } from "@depict-ai/ui/locales";
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createElement as $7h5e1$createElement, useRef as $7h5e1$useRef, Fragment as $7h5e1$Fragment } from "react";
|
|
2
|
+
import { jsx as $7h5e1$jsx } from "react/jsx-runtime";
|
|
3
|
+
import { ImagePlaceholder as $7h5e1$ImagePlaceholder, TextPlaceholder as $7h5e1$TextPlaceholder } from "@depict-ai/ui/ES10";
|
|
4
|
+
import { renderToString as $7h5e1$renderToString, generateHydrationScript as $7h5e1$generateHydrationScript } from "solid-js/web";
|
|
5
|
+
import { register_es_version } from "../../multi_import_deduplicator.mjs";
|
|
6
|
+
register_es_version("react-ui", "ES10");
|
|
7
|
+
function $e8e755ef02e716bf$export$4b564d7f5a1b1d43(_ref) {
|
|
8
|
+
let {
|
|
9
|
+
solid_component: solid_component,
|
|
10
|
+
props: props,
|
|
11
|
+
wrapper_type = "div",
|
|
12
|
+
wrapper_style = {}
|
|
13
|
+
} = _ref;
|
|
14
|
+
const wrapper_element_ref = (0, $7h5e1$useRef)();
|
|
15
|
+
// The worst thing that can happen by multiple generateHydrationScript's is that events dispatched before the hydration are duplicated in solid's shared context which leads to them being deduplicated again here https://github.com/ryansolid/dom-expressions/blob/21fdba5bcab25986a2b93003aaace100b2231cdc/packages/dom-expressions/src/client.js#L280
|
|
16
|
+
const rendered_html = (0, $7h5e1$renderToString)(() => solid_component(props, () => {})) + (0, $7h5e1$generateHydrationScript)();
|
|
17
|
+
return (0, $7h5e1$createElement)((0, $7h5e1$Fragment), null, (0, $7h5e1$createElement)(wrapper_type, {
|
|
18
|
+
ref: wrapper_element_ref,
|
|
19
|
+
style: wrapper_style,
|
|
20
|
+
dangerouslySetInnerHTML: {
|
|
21
|
+
__html: rendered_html
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
const $9bd9bb8700ab2ada$export$83d89fbfd8236492 = "1.5.4";
|
|
26
|
+
function $5c4add0a8fe94894$export$9fac37a9c21c2f3b(props) {
|
|
27
|
+
return props.children;
|
|
28
|
+
}
|
|
29
|
+
function $5c4add0a8fe94894$export$a54ec244c8863715() {
|
|
30
|
+
return (0, $7h5e1$jsx)("div", {
|
|
31
|
+
children: []
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function $5c4add0a8fe94894$export$f7d2f673fc2f091d() {
|
|
35
|
+
return (0, $7h5e1$jsx)("div", {
|
|
36
|
+
children: []
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function $5c4add0a8fe94894$export$5646050d516e06bc() {
|
|
40
|
+
return (0, $7h5e1$jsx)("div", {
|
|
41
|
+
children: []
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function $5c4add0a8fe94894$export$466cdc317043f6cb() {
|
|
45
|
+
return (0, $7h5e1$jsx)("div", {
|
|
46
|
+
children: []
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function $5c4add0a8fe94894$export$80e99ee6b29cadd2() {
|
|
50
|
+
return (0, $7h5e1$createElement)("div", {
|
|
51
|
+
className: "depict aligner",
|
|
52
|
+
style: {
|
|
53
|
+
height: "100%"
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function $5c4add0a8fe94894$export$3f37af283f8fb843(raw_react_props) {
|
|
58
|
+
const react_props = {
|
|
59
|
+
class: raw_react_props.className,
|
|
60
|
+
...raw_react_props
|
|
61
|
+
};
|
|
62
|
+
return (0, $e8e755ef02e716bf$export$4b564d7f5a1b1d43)({
|
|
63
|
+
solid_component: props_store => (0, $7h5e1$ImagePlaceholder)(props_store),
|
|
64
|
+
props: react_props,
|
|
65
|
+
wrapper_type: "span"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function $5c4add0a8fe94894$export$89c6019e4baa40b1(raw_react_props) {
|
|
69
|
+
const react_props = {
|
|
70
|
+
...raw_react_props,
|
|
71
|
+
class: raw_react_props.className
|
|
72
|
+
};
|
|
73
|
+
return (0, $e8e755ef02e716bf$export$4b564d7f5a1b1d43)({
|
|
74
|
+
solid_component: props_store => (0, $7h5e1$TextPlaceholder)(props_store),
|
|
75
|
+
props: react_props,
|
|
76
|
+
wrapper_type: "span",
|
|
77
|
+
wrapper_style: {
|
|
78
|
+
"height": "100%"
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function $5c4add0a8fe94894$export$9bb30bbe003b82e0() {
|
|
83
|
+
return {
|
|
84
|
+
SearchField: () => (0, $7h5e1$jsx)("div", {
|
|
85
|
+
children: []
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function $5c4add0a8fe94894$export$a7f6cffb6b8ba11c() {}
|
|
90
|
+
function $5c4add0a8fe94894$export$912994940e660d32() {
|
|
91
|
+
return {
|
|
92
|
+
open: () => {}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function $5c4add0a8fe94894$export$38b98fae14bd1f64() {
|
|
96
|
+
const mock = {
|
|
97
|
+
get: function (target, property) {
|
|
98
|
+
if (typeof target[property] === "undefined") return () => {
|
|
99
|
+
throw new Error("Depict Performance Client is currently not available on the server. Please wrap your call in a useEffect hook or user event handler.");
|
|
100
|
+
};
|
|
101
|
+
return target[property];
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
dpc: new Proxy({}, mock)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function $5c4add0a8fe94894$export$6501da23a2770fc() {
|
|
109
|
+
return {
|
|
110
|
+
fetchRecommendations: () => {
|
|
111
|
+
throw new Error("fetchRecommendations is currently not available on the server due to personalisation/user_id related issues. Please only call it on the client.");
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export { $5c4add0a8fe94894$export$9fac37a9c21c2f3b as DepictProvider, $5c4add0a8fe94894$export$a54ec244c8863715 as SearchPage, $5c4add0a8fe94894$export$f7d2f673fc2f091d as CategoryPage, $5c4add0a8fe94894$export$5646050d516e06bc as BreadCrumbs, $5c4add0a8fe94894$export$466cdc317043f6cb as QuickLinks, $5c4add0a8fe94894$export$80e99ee6b29cadd2 as ComponentAligner, $5c4add0a8fe94894$export$3f37af283f8fb843 as ImagePlaceholder, $5c4add0a8fe94894$export$89c6019e4baa40b1 as TextPlaceholder, $5c4add0a8fe94894$export$9bb30bbe003b82e0 as useSearchField, $5c4add0a8fe94894$export$a7f6cffb6b8ba11c as openModal, $5c4add0a8fe94894$export$912994940e660d32 as useSearchModal, $5c4add0a8fe94894$export$38b98fae14bd1f64 as usePerformanceClient, $5c4add0a8fe94894$export$6501da23a2770fc as useFetchRecommendations, $9bd9bb8700ab2ada$export$83d89fbfd8236492 as version };
|