@depict-ai/ui 1.1.5 → 1.2.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/dist/client/main.cjs +139 -49
- package/dist/client/module.js +140 -50
- package/dist/index.d.ts +220 -121
- package/dist/server/main.cjs +139 -49
- package/dist/server/module.js +140 -50
- package/dist/tsconfig2.tsbuildinfo +1 -0
- package/package.json +4 -4
- package/dist/client/main.js +0 -9068
- package/dist/server/main.js +0 -8063
- package/locales/require.js +0 -1154
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Display, ModernDisplay, Node_Array, Elem, ColsAtSize } from "@depict-ai/utilishared";
|
|
2
|
+
import { BaseCategoryDisplay, ProductListingResponse } from "@depict-ai/types/api/ProductListingResponse";
|
|
3
|
+
import { CategorySuggestion, SearchSuggestionsResponse } from "@depict-ai/types/api/SearchSuggestionsResponse";
|
|
2
4
|
import { JSX, Accessor, Setter, Signal } from "solid-js";
|
|
3
5
|
import { SearchResponse } from "@depict-ai/types/api/SearchResponse";
|
|
4
6
|
import { SearchRequest, SearchFilter } from "@depict-ai/types/api/SearchRequest";
|
|
5
7
|
import { BaseSearchRequest } from "@depict-ai/types/api/BaseSearchRequest";
|
|
6
|
-
import { SearchSuggestionsResponse, CategorySuggestion } from "@depict-ai/types/api/SearchSuggestionsResponse";
|
|
7
8
|
import { SearchSuggestionsRequest } from "@depict-ai/types/api/SearchSuggestionsRequest";
|
|
8
9
|
import { ProductListingRequest } from "@depict-ai/types/api/ProductListingRequest";
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export const version = "1.2.0";
|
|
11
|
+
type PageURLCreatorAlwaysThereData = {
|
|
12
|
+
merchant: string;
|
|
13
|
+
market: string;
|
|
14
|
+
};
|
|
15
|
+
type PageURLCreatorCategoryData = {
|
|
16
|
+
type: "categories";
|
|
17
|
+
data: (BaseCategoryDisplay | CategorySuggestion)[];
|
|
18
|
+
};
|
|
19
|
+
type PageURLCreatorProductData<T extends ModernDisplay> = {
|
|
20
|
+
displays: T[];
|
|
21
|
+
type: "products";
|
|
22
|
+
};
|
|
23
|
+
type CanBePromiseWrapped<T> = T | Promise<T>;
|
|
24
|
+
export type ModernDisplayWithPageUrl<T extends ModernDisplay> = {
|
|
25
|
+
[K in keyof T]: K extends "variant_displays" ? (T[K][number] & {
|
|
26
|
+
page_url: string;
|
|
27
|
+
})[] : T[K];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* PageUrlCreator is, in its most basic form, a function that takes in a list of categories or products and returns a list of page_urls for the provided categories or products.
|
|
31
|
+
* It's main use case is to allow for the creation of links to the product or category pages on the merchant's site.
|
|
32
|
+
* It can also be used for the depict customers which already have links to change those links (i.e. for staging sites).
|
|
33
|
+
* Also, it can be used to enrich the data for each product card in a batched way, which is why it can be an async function and return a whole display in the case of products.
|
|
34
|
+
*/
|
|
35
|
+
type PageURLCreatorOptions<InputDisplay extends ModernDisplay> = (PageURLCreatorAlwaysThereData & PageURLCreatorCategoryData) | (PageURLCreatorAlwaysThereData & PageURLCreatorProductData<InputDisplay>);
|
|
36
|
+
export type PageURLCreator<InputDisplay extends ModernDisplay, OutputDisplay extends ModernDisplay | never> = (options: PageURLCreatorOptions<InputDisplay>) => (typeof options)["type"] extends "categories" ? CanBePromiseWrapped<{
|
|
37
|
+
page_url: string;
|
|
38
|
+
}[]> : CanBePromiseWrapped<{
|
|
39
|
+
page_url: string;
|
|
40
|
+
}[]> | CanBePromiseWrapped<OutputDisplay extends ModernDisplay ? ModernDisplayWithPageUrl<OutputDisplay>[] : never>;
|
|
41
|
+
export type SomethingTakingAPageURLCreator<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never> = InputDisplay extends ModernDisplay ? "page_url" extends keyof InputDisplay["variant_displays"][number] ? {
|
|
42
|
+
page_url_creator?: PageURLCreator<InputDisplay, OutputDisplay>;
|
|
43
|
+
} : {
|
|
44
|
+
page_url_creator: PageURLCreator<InputDisplay, OutputDisplay>;
|
|
45
|
+
} : {
|
|
46
|
+
page_url_creator?: never;
|
|
47
|
+
};
|
|
11
48
|
/**
|
|
12
49
|
* Basically allows you to use SearchModal
|
|
13
50
|
* So the idea is to have a modal. It should either be rendered and exist, in which case it is in the foreground and open, or it's completely gone. This makes things easier.
|
|
@@ -188,27 +225,57 @@ export type InstantCard<T extends Display> = (display: T, context: {
|
|
|
188
225
|
merchant: string;
|
|
189
226
|
market: string;
|
|
190
227
|
}) => JSX.Element;
|
|
191
|
-
|
|
228
|
+
type CategorySuggestionAfterURLCreator = CategorySuggestion & {
|
|
229
|
+
page_url: string;
|
|
230
|
+
};
|
|
231
|
+
type ReplaceCategorySuggestion<T> = T extends CategorySuggestion ? CategorySuggestionAfterURLCreator : T extends CategorySuggestion[] ? CategorySuggestionAfterURLCreator[] : T;
|
|
232
|
+
type SearchSuggestionsResponseAfterURLCreator = {
|
|
233
|
+
[K in keyof SearchSuggestionsResponse]: ReplaceCategorySuggestion<SearchSuggestionsResponse[K]>;
|
|
234
|
+
};
|
|
235
|
+
type AddPageUrlToDisplay<T extends any[]> = (T[number] & {
|
|
236
|
+
page_url: string;
|
|
237
|
+
})[];
|
|
238
|
+
type SearchResponseAfterURLCreator = {
|
|
239
|
+
[K in keyof SearchResponse]: K extends "displays" ? AddPageUrlToDisplay<SearchResponse[K]> : SearchResponse[K];
|
|
240
|
+
};
|
|
241
|
+
type BaseCategoryDisplayAfterURLCreator = BaseCategoryDisplay & {
|
|
242
|
+
page_url: string;
|
|
243
|
+
};
|
|
244
|
+
type ReplaceBaseCategoryDisplay<T> = T extends BaseCategoryDisplay ? BaseCategoryDisplayAfterURLCreator : T extends BaseCategoryDisplay[] ? BaseCategoryDisplayAfterURLCreator[] : T;
|
|
245
|
+
type _AddPageUrlToDisplay1<T extends any[]> = (T[number] & {
|
|
246
|
+
page_url: string;
|
|
247
|
+
})[];
|
|
248
|
+
type ProductListingResponseAfterURLCreator = {
|
|
249
|
+
[K in keyof ProductListingResponse]: K extends "displays" ? _AddPageUrlToDisplay1<ProductListingResponse[K]> : K extends "breadcrumb" | "quick_links" ? ReplaceBaseCategoryDisplay<ProductListingResponse[K]> : ProductListingResponse[K];
|
|
250
|
+
};
|
|
251
|
+
type DepictAPIConstructorOptions<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never> = {
|
|
192
252
|
get_metadata?: () => Promise<{
|
|
193
253
|
[k: string]: string;
|
|
194
254
|
} | undefined>;
|
|
195
255
|
get_user_id?: () => string | undefined;
|
|
196
256
|
get_session_id?: () => string | undefined;
|
|
197
|
-
}
|
|
198
|
-
|
|
257
|
+
} & SomethingTakingAPageURLCreator<InputDisplay, OutputDisplay>;
|
|
258
|
+
/**
|
|
259
|
+
* Class that handles all communication done in PLP code with the Depict API. (Notably not for recommendations currently).
|
|
260
|
+
* It handles caching, retries and errors and is the only place that should be making requests to the Depict API.
|
|
261
|
+
*/
|
|
262
|
+
export class DepictAPI<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never = InputDisplay extends ModernDisplay ? ModernDisplayWithPageUrl<InputDisplay> : never> {
|
|
199
263
|
#private;
|
|
200
|
-
|
|
201
|
-
|
|
264
|
+
page_url_creator: PageURLCreator<ModernDisplay, OutputDisplay> | undefined;
|
|
265
|
+
constructor(options: DepictAPIConstructorOptions<InputDisplay, OutputDisplay>);
|
|
266
|
+
suggest(input_req: SearchSuggestionsRequest): Promise<SearchSuggestionsResponseAfterURLCreator & {
|
|
202
267
|
failed?: true;
|
|
203
268
|
}>;
|
|
204
|
-
query(input_req: SearchRequest): Promise<
|
|
269
|
+
query(input_req: SearchRequest): Promise<SearchResponseAfterURLCreator & {
|
|
205
270
|
failed?: true;
|
|
206
271
|
}>;
|
|
207
|
-
list(input_req: ProductListingRequest): Promise<
|
|
272
|
+
list(input_req: ProductListingRequest): Promise<ProductListingResponseAfterURLCreator & {
|
|
208
273
|
failed?: true;
|
|
209
274
|
}>;
|
|
210
|
-
get_recommended<
|
|
211
|
-
displays:
|
|
275
|
+
get_recommended<T extends Display>(input_req: BaseSearchRequest): Promise<{
|
|
276
|
+
displays: T[];
|
|
277
|
+
} & {
|
|
278
|
+
failed?: true | undefined;
|
|
212
279
|
}>;
|
|
213
280
|
}
|
|
214
281
|
/**
|
|
@@ -228,6 +295,11 @@ export interface SDKRenderingInfo {
|
|
|
228
295
|
market: string;
|
|
229
296
|
}
|
|
230
297
|
export type ProductCardTemplate<T extends Display> = (display: T | null, info?: SDKRenderingInfo) => JSX.Element | Promise<JSX.Element>;
|
|
298
|
+
/**
|
|
299
|
+
* Will be sent to backend to indicate whether the query_id_ is for a collection or category.
|
|
300
|
+
* Backend defaults to category if not specified.
|
|
301
|
+
*/
|
|
302
|
+
export type ListingType = "collection" | "category";
|
|
231
303
|
export function show_toast({ children, on_close_, close_after_, ...more_attributes }: {
|
|
232
304
|
children?: JSX.Element;
|
|
233
305
|
close_after_: number;
|
|
@@ -298,98 +370,28 @@ export type SDKColsAtSize = [number, number?][];
|
|
|
298
370
|
* @returns
|
|
299
371
|
*/
|
|
300
372
|
export const convert_sdk_cols_at_size_to_layout: (cols_at_size: SDKColsAtSize) => ColsAtSize;
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* The merchant to use for the search.
|
|
304
|
-
* @example "YOUR_MERCHANT", "stronger"
|
|
305
|
-
*/
|
|
306
|
-
merchant: string;
|
|
307
|
-
/**
|
|
308
|
-
* The market to use for the search.
|
|
309
|
-
* @example "YOUR_MARKET", "no", "en-de"
|
|
310
|
-
*/
|
|
311
|
-
market: string;
|
|
312
|
-
/**
|
|
313
|
-
* Optional unique identifier of a logged in user. Should be persistent across devices and sessions.
|
|
314
|
-
*/
|
|
315
|
-
userId?: string;
|
|
316
|
-
/**
|
|
317
|
-
* Optional unique identifer of the current session. Only necessary when performing server side requests to Depict.
|
|
318
|
-
*/
|
|
319
|
-
sessionId?: string;
|
|
320
|
-
/**
|
|
321
|
-
* Custom metadata to be sent with each request to the Depict API. Only necessary if specifically instructed by Depict.
|
|
322
|
-
*/
|
|
323
|
-
metaData?: Record<string, string>;
|
|
324
|
-
};
|
|
325
|
-
export type BaseSearchProviderConfig = {
|
|
326
|
-
/**
|
|
327
|
-
* The path to the search page.
|
|
328
|
-
* @example "/search", "/sok"
|
|
329
|
-
*/
|
|
330
|
-
searchPagePath: string;
|
|
331
|
-
/**
|
|
332
|
-
* The name of the url parameter that will be used for the search query.
|
|
333
|
-
* @example "q", "search_query", "query"
|
|
334
|
-
* @default "query"
|
|
335
|
-
*/
|
|
336
|
-
urlParamName?: string;
|
|
337
|
-
/**
|
|
338
|
-
* Whether to enable category suggestions in the search modal and search page.
|
|
339
|
-
* @default false
|
|
340
|
-
*/
|
|
341
|
-
enableCategorySuggestions?: boolean;
|
|
342
|
-
};
|
|
343
|
-
export interface BaseProductListingConfig {
|
|
344
|
-
/**
|
|
345
|
-
* How many columns to show at each media size.
|
|
346
|
-
* @default
|
|
347
|
-
* [[2, 901], [3, 1024], [4]]
|
|
348
|
-
* @example
|
|
349
|
-
* [[2, 901], [3, 1024], [4]]
|
|
350
|
-
* means 2 columns at sizes up to 901px, 3 columns at sizes up to 1024px and after that 4 columns at any viewport size.
|
|
351
|
-
*/
|
|
352
|
-
columnsAtSize?: SDKColsAtSize;
|
|
353
|
-
/**
|
|
354
|
-
* The spacing between products.
|
|
355
|
-
* @default "2%"
|
|
356
|
-
* @example
|
|
357
|
-
* "2%", "10px", "1rem", {horizontal: "1%", vertical: "5px"}
|
|
358
|
-
*/
|
|
359
|
-
gridSpacing?: SDKGridSpacing;
|
|
360
|
-
}
|
|
361
|
-
export interface BaseSearchPageConfig extends BaseProductListingConfig {
|
|
362
|
-
/**
|
|
363
|
-
* Whether to show the search input field in the search page.
|
|
364
|
-
* @default true
|
|
365
|
-
*/
|
|
366
|
-
includeInputField?: boolean;
|
|
367
|
-
}
|
|
368
|
-
export interface BaseCategoryPageConfig extends BaseProductListingConfig {
|
|
369
|
-
/**
|
|
370
|
-
* Whether to show the breadcrumbs in the category page.
|
|
371
|
-
* @default true
|
|
372
|
-
*/
|
|
373
|
-
showBreadcrumbs?: boolean;
|
|
374
|
-
/**
|
|
375
|
-
* Whether to show the quicklinks in the category page.
|
|
376
|
-
* @default true
|
|
377
|
-
*/
|
|
378
|
-
showQuicklinks?: boolean;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Will be sent to backend to indicate whether the query_id_ is for a collection or category.
|
|
382
|
-
* Backend defaults to category if not specified.
|
|
383
|
-
*/
|
|
384
|
-
export type ListingType = "collection" | "category";
|
|
385
|
-
type DepictCategoryConstructorOptions = {
|
|
373
|
+
type GeneralCategoryListingOptions = {
|
|
386
374
|
market: string;
|
|
387
375
|
merchant: string;
|
|
388
376
|
localization: category_i18n;
|
|
389
377
|
on_navigation?: OnNavigation;
|
|
390
|
-
api?: DepictAPI;
|
|
391
378
|
};
|
|
392
|
-
|
|
379
|
+
type CategoryConstructorOptionsWithApi<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never> = GeneralCategoryListingOptions & {
|
|
380
|
+
api: DepictAPI<InputDisplay, OutputDisplay>;
|
|
381
|
+
} & {
|
|
382
|
+
page_url_creator?: never;
|
|
383
|
+
};
|
|
384
|
+
type CategoryConstructorOptionsWithoutApi<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never> = GeneralCategoryListingOptions & {
|
|
385
|
+
api?: never;
|
|
386
|
+
} & (InputDisplay extends ModernDisplay ? "page_url" extends keyof InputDisplay["variant_displays"][number] ? {
|
|
387
|
+
page_url_creator?: PageURLCreator<InputDisplay, OutputDisplay>;
|
|
388
|
+
} : {
|
|
389
|
+
page_url_creator: PageURLCreator<InputDisplay, OutputDisplay>;
|
|
390
|
+
} : {
|
|
391
|
+
page_url_creator?: never;
|
|
392
|
+
});
|
|
393
|
+
type DepictCategoryConstructorOptions<InputDisplay extends Display, OutputDisplay extends ModernDisplay> = CategoryConstructorOptionsWithApi<InputDisplay, OutputDisplay> | CategoryConstructorOptionsWithoutApi<InputDisplay, OutputDisplay>;
|
|
394
|
+
export class DepictCategory<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never = InputDisplay extends ModernDisplay ? ModernDisplayWithPageUrl<InputDisplay> : never> {
|
|
393
395
|
#private;
|
|
394
396
|
get localization(): category_i18n;
|
|
395
397
|
set localization(locale_obj: category_i18n);
|
|
@@ -403,22 +405,24 @@ export class DepictCategory {
|
|
|
403
405
|
set listing_type(listing_type: ListingType | undefined);
|
|
404
406
|
get on_navigation(): OnNavigation;
|
|
405
407
|
set on_navigation(new_function: OnNavigation);
|
|
406
|
-
constructor({ api, on_navigation, ...props_on_class }: DepictCategoryConstructorOptions);
|
|
408
|
+
constructor({ api, on_navigation, page_url_creator, ...props_on_class }: DepictCategoryConstructorOptions<InputDisplay, OutputDisplay>);
|
|
407
409
|
}
|
|
408
|
-
export function CategoryPage<
|
|
409
|
-
depict_category: DepictCategory
|
|
410
|
+
export function CategoryPage<OriginalDisplay extends Display, OutputDisplay extends ModernDisplay | never>({ depict_category, grid_spacing, cols_at_size, product_card_template, show_breadcrumbs, show_quicklinks, category_title, }: {
|
|
411
|
+
depict_category: DepictCategory<OriginalDisplay, OutputDisplay>;
|
|
410
412
|
grid_spacing: SDKGridSpacing;
|
|
411
413
|
cols_at_size: SDKColsAtSize;
|
|
412
|
-
product_card_template: ProductCardTemplate<
|
|
414
|
+
product_card_template: ProductCardTemplate<[
|
|
415
|
+
OutputDisplay
|
|
416
|
+
] extends [never] ? OriginalDisplay : ModernDisplayWithPageUrl<OutputDisplay>>;
|
|
413
417
|
show_quicklinks?: boolean;
|
|
414
418
|
show_breadcrumbs?: boolean;
|
|
415
419
|
category_title: typeof CategoryTitle | typeof embedded_num_products;
|
|
416
420
|
}): import("@depict-ai/utilishared").Node_Array;
|
|
417
|
-
export function BreadCrumbs({ depict_category }: {
|
|
418
|
-
depict_category: DepictCategory
|
|
421
|
+
export function BreadCrumbs<T extends Display>({ depict_category }: {
|
|
422
|
+
depict_category: DepictCategory<T>;
|
|
419
423
|
}): HTMLElement;
|
|
420
|
-
export function QuickLinks({ depict_category }: {
|
|
421
|
-
depict_category: DepictCategory
|
|
424
|
+
export function QuickLinks<T extends Display>({ depict_category }: {
|
|
425
|
+
depict_category: DepictCategory<T>;
|
|
422
426
|
}): HTMLElement;
|
|
423
427
|
/**
|
|
424
428
|
* Gets available categories/collections (query_ids for the product-listing endpoint) for a merchant
|
|
@@ -464,7 +468,7 @@ interface Styles {
|
|
|
464
468
|
}
|
|
465
469
|
export const styles_to_valid_css_string: (styles: Styles) => string;
|
|
466
470
|
/** A function that renders category suggestion cards. Set to false to disable category suggestions. */
|
|
467
|
-
export type RenderCategorySuggestion = (category_suggestion: Accessor<
|
|
471
|
+
export type RenderCategorySuggestion = (category_suggestion: Accessor<CategorySuggestionAfterURLCreator>, index: number) => JSX.Element;
|
|
468
472
|
/**
|
|
469
473
|
* Connects the height of the search field to the height of the aligner.
|
|
470
474
|
* @param aligner
|
|
@@ -473,7 +477,7 @@ export type RenderCategorySuggestion = (category_suggestion: Accessor<CategorySu
|
|
|
473
477
|
export function connect_search_field_height_to_aligner_height(aligner: HTMLElement): {
|
|
474
478
|
cleanup: () => void;
|
|
475
479
|
};
|
|
476
|
-
type
|
|
480
|
+
type GeneralConstructorOptions<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never> = {
|
|
477
481
|
search_query_url_param_name?: string;
|
|
478
482
|
market: string;
|
|
479
483
|
merchant: string;
|
|
@@ -482,10 +486,18 @@ type ConstructorOptions<T extends Display> = {
|
|
|
482
486
|
url_transformer?: (url_object: URL) => unknown;
|
|
483
487
|
enable_category_suggestions?: boolean;
|
|
484
488
|
disable_scrolling_during_modal?: boolean;
|
|
485
|
-
api?: DepictAPI;
|
|
486
489
|
bottom_distance_under_modal?: Accessor<number | undefined>;
|
|
487
|
-
render_instant_card?: InstantCard<
|
|
490
|
+
render_instant_card?: InstantCard<OutputDisplay extends ModernDisplay ? OutputDisplay : InputDisplay>;
|
|
491
|
+
};
|
|
492
|
+
type ConstructorOptionsWithApi<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never> = GeneralConstructorOptions<InputDisplay, OutputDisplay> & {
|
|
493
|
+
api: DepictAPI<InputDisplay, OutputDisplay>;
|
|
494
|
+
} & {
|
|
495
|
+
page_url_creator?: never;
|
|
488
496
|
};
|
|
497
|
+
type ConstructorOptionsWithoutAPI<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never> = GeneralConstructorOptions<InputDisplay, OutputDisplay> & {
|
|
498
|
+
api?: never;
|
|
499
|
+
} & SomethingTakingAPageURLCreator<InputDisplay, OutputDisplay>;
|
|
500
|
+
type ConstructorOptions<InputDisplay extends Display, OutputDisplay extends ModernDisplay> = ConstructorOptionsWithApi<InputDisplay, OutputDisplay> | ConstructorOptionsWithoutAPI<InputDisplay, OutputDisplay>;
|
|
489
501
|
export type OpenModalArguments = [
|
|
490
502
|
options_for_modal?: {
|
|
491
503
|
style_props_?: Signal<JSX.CSSProperties>;
|
|
@@ -497,9 +509,9 @@ export type OpenModalArguments = [
|
|
|
497
509
|
on_dispose?: VoidFunction
|
|
498
510
|
];
|
|
499
511
|
export const get_search_query_updating_blocked_signal: (depict_search: DepictSearch<any>) => Signal<boolean> | undefined;
|
|
500
|
-
export class DepictSearch<
|
|
512
|
+
export class DepictSearch<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never = InputDisplay extends ModernDisplay ? ModernDisplayWithPageUrl<InputDisplay> : never> {
|
|
501
513
|
#private;
|
|
502
|
-
constructor({ search_query_url_param_name: search_query_url_param_name_, url_transformer, on_navigation, enable_category_suggestions, disable_scrolling_during_modal, api, bottom_distance_under_modal, render_instant_card, ...props_on_class }: ConstructorOptions<
|
|
514
|
+
constructor({ search_query_url_param_name: search_query_url_param_name_, url_transformer, on_navigation, enable_category_suggestions, page_url_creator, disable_scrolling_during_modal, api, bottom_distance_under_modal, render_instant_card, ...props_on_class }: ConstructorOptions<InputDisplay, OutputDisplay>);
|
|
503
515
|
get on_navigation(): OnNavigation;
|
|
504
516
|
set on_navigation(new_function: OnNavigation);
|
|
505
517
|
get localization(): search_i18n;
|
|
@@ -510,17 +522,19 @@ export class DepictSearch<T extends Display> {
|
|
|
510
522
|
set merchant(tenant: string);
|
|
511
523
|
get market(): string;
|
|
512
524
|
set market(market: string);
|
|
513
|
-
fetchSearchResults(query: string, filters?: SearchFilter[], maxResults?: number): Promise<
|
|
525
|
+
fetchSearchResults(query: string, filters?: SearchFilter[], maxResults?: number): Promise<([OutputDisplay] extends [never] ? InputDisplay : ModernDisplayWithPageUrl<OutputDisplay>)[]>;
|
|
514
526
|
}
|
|
515
|
-
export function SearchPage<
|
|
516
|
-
depict_search: DepictSearch<
|
|
527
|
+
export function SearchPage<OriginalDisplay extends Display, TransformedDisplay extends never | ModernDisplay>(props: {
|
|
528
|
+
depict_search: DepictSearch<OriginalDisplay, TransformedDisplay>;
|
|
517
529
|
include_input_field?: boolean | {
|
|
518
530
|
on_open_?: VoidFunction;
|
|
519
531
|
on_close_?: VoidFunction;
|
|
520
532
|
};
|
|
521
533
|
grid_spacing: SDKGridSpacing;
|
|
522
534
|
cols_at_size: SDKColsAtSize;
|
|
523
|
-
product_card_template: ProductCardTemplate<
|
|
535
|
+
product_card_template: ProductCardTemplate<[
|
|
536
|
+
TransformedDisplay
|
|
537
|
+
] extends [never] ? OriginalDisplay : ModernDisplayWithPageUrl<TransformedDisplay>>;
|
|
524
538
|
extra_depict_options?: {
|
|
525
539
|
recommendations_cols_at_size?: SDKColsAtSize;
|
|
526
540
|
};
|
|
@@ -532,6 +546,91 @@ interface SearchFieldParams {
|
|
|
532
546
|
aligner_ref?: HTMLElement | null;
|
|
533
547
|
}
|
|
534
548
|
export function SearchField({ depict_search, modal_dispose_handler, click_handler, aligner_ref, }: SearchFieldParams): import("@depict-ai/utilishared").Node_Array;
|
|
549
|
+
export type BaseProviderConfig<InputDisplay extends Display, PossibleTransformedDisplay extends ModernDisplay | never = InputDisplay extends ModernDisplay ? ModernDisplayWithPageUrl<InputDisplay> : never> = {
|
|
550
|
+
/**
|
|
551
|
+
* The merchant to use for the search.
|
|
552
|
+
* @example "YOUR_MERCHANT", "stronger"
|
|
553
|
+
*/
|
|
554
|
+
merchant: string;
|
|
555
|
+
/**
|
|
556
|
+
* The market to use for the search.
|
|
557
|
+
* @example "YOUR_MARKET", "no", "en-de"
|
|
558
|
+
*/
|
|
559
|
+
market: string;
|
|
560
|
+
/**
|
|
561
|
+
* Optional unique identifier of a logged in user. Should be persistent across devices and sessions.
|
|
562
|
+
*/
|
|
563
|
+
userId?: string;
|
|
564
|
+
/**
|
|
565
|
+
* Optional unique identifer of the current session. Only necessary when performing server side requests to Depict.
|
|
566
|
+
*/
|
|
567
|
+
sessionId?: string;
|
|
568
|
+
/**
|
|
569
|
+
* Custom metadata to be sent with each request to the Depict API. Only necessary if specifically instructed by Depict.
|
|
570
|
+
*/
|
|
571
|
+
metaData?: Record<string, string>;
|
|
572
|
+
} & (InputDisplay extends ModernDisplay ? "page_url" extends keyof InputDisplay["variant_displays"][number] ? {
|
|
573
|
+
pageURLCreator?: PageURLCreator<InputDisplay, PossibleTransformedDisplay>;
|
|
574
|
+
} : {
|
|
575
|
+
pageURLCreator: PageURLCreator<InputDisplay, PossibleTransformedDisplay>;
|
|
576
|
+
} : {
|
|
577
|
+
pageURLCreator?: never;
|
|
578
|
+
});
|
|
579
|
+
export type BaseSearchProviderConfig = {
|
|
580
|
+
/**
|
|
581
|
+
* The path to the search page.
|
|
582
|
+
* @example "/search", "/sok"
|
|
583
|
+
*/
|
|
584
|
+
searchPagePath: string;
|
|
585
|
+
/**
|
|
586
|
+
* The name of the url parameter that will be used for the search query.
|
|
587
|
+
* @example "q", "search_query", "query"
|
|
588
|
+
* @default "query"
|
|
589
|
+
*/
|
|
590
|
+
urlParamName?: string;
|
|
591
|
+
/**
|
|
592
|
+
* Whether to enable category suggestions in the search modal and search page.
|
|
593
|
+
* @default false
|
|
594
|
+
*/
|
|
595
|
+
enableCategorySuggestions?: boolean;
|
|
596
|
+
};
|
|
597
|
+
export interface BaseProductListingConfig {
|
|
598
|
+
/**
|
|
599
|
+
* How many columns to show at each media size.
|
|
600
|
+
* @default
|
|
601
|
+
* [[2, 901], [3, 1024], [4]]
|
|
602
|
+
* @example
|
|
603
|
+
* [[2, 901], [3, 1024], [4]]
|
|
604
|
+
* means 2 columns at sizes up to 901px, 3 columns at sizes up to 1024px and after that 4 columns at any viewport size.
|
|
605
|
+
*/
|
|
606
|
+
columnsAtSize?: SDKColsAtSize;
|
|
607
|
+
/**
|
|
608
|
+
* The spacing between products.
|
|
609
|
+
* @default "2%"
|
|
610
|
+
* @example
|
|
611
|
+
* "2%", "10px", "1rem", {horizontal: "1%", vertical: "5px"}
|
|
612
|
+
*/
|
|
613
|
+
gridSpacing?: SDKGridSpacing;
|
|
614
|
+
}
|
|
615
|
+
export interface BaseSearchPageConfig extends BaseProductListingConfig {
|
|
616
|
+
/**
|
|
617
|
+
* Whether to show the search input field in the search page.
|
|
618
|
+
* @default true
|
|
619
|
+
*/
|
|
620
|
+
includeInputField?: boolean;
|
|
621
|
+
}
|
|
622
|
+
export interface BaseCategoryPageConfig extends BaseProductListingConfig {
|
|
623
|
+
/**
|
|
624
|
+
* Whether to show the breadcrumbs in the category page.
|
|
625
|
+
* @default true
|
|
626
|
+
*/
|
|
627
|
+
showBreadcrumbs?: boolean;
|
|
628
|
+
/**
|
|
629
|
+
* Whether to show the quicklinks in the category page.
|
|
630
|
+
* @default true
|
|
631
|
+
*/
|
|
632
|
+
showQuicklinks?: boolean;
|
|
633
|
+
}
|
|
535
634
|
type CenteredLocation = {
|
|
536
635
|
location?: "centered";
|
|
537
636
|
};
|
|
@@ -543,8 +642,8 @@ type AlignedLocation = {
|
|
|
543
642
|
* How the modal should be opened.
|
|
544
643
|
*/
|
|
545
644
|
type ModalLocation = AlignedLocation | CenteredLocation;
|
|
546
|
-
type OpenModalParams<
|
|
547
|
-
search: DepictSearch<
|
|
645
|
+
type OpenModalParams<OriginalDisplay extends Display, OutputDisplay extends ModernDisplay | never> = ModalLocation & {
|
|
646
|
+
search: DepictSearch<OriginalDisplay, OutputDisplay>;
|
|
548
647
|
/**
|
|
549
648
|
* If true, the search field in the modal opened will be empty and de-coupled from the other SearchFields.
|
|
550
649
|
*/
|
|
@@ -554,7 +653,7 @@ type OpenModalParams<T extends Display> = ModalLocation & {
|
|
|
554
653
|
* Open the modal with support for alignment.
|
|
555
654
|
* @returns {void}
|
|
556
655
|
*/
|
|
557
|
-
export const open_modal_with_alignment: <
|
|
656
|
+
export const open_modal_with_alignment: <OriginalDisplay extends Display, OutputDisplay extends ModernDisplay>(openModalParams: OpenModalParams<OriginalDisplay, OutputDisplay>) => void;
|
|
558
657
|
export function open_search_with_shift_slash(open_search: VoidFunction): () => void;
|
|
559
658
|
export interface PageReplacer {
|
|
560
659
|
readonly render_: () => Node_Array;
|