@depict-ai/ui 1.3.6 → 1.3.8

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/index.d.ts CHANGED
@@ -1,18 +1,209 @@
1
- import { Signal, JSX, Accessor, Setter } from "solid-js";
2
- import { ColsAtSize, Display, ModernDisplay, Node_Array, Elem } from "@depict-ai/utilishared";
1
+ import { Accessor, JSX, Signal, Setter } from "solid-js";
2
+ import { Elem, Display, ColsAtSize, ModernDisplay, Node_Array } from "@depict-ai/utilishared";
3
+ import { SearchFilter, SearchRequest } from "@depict-ai/types/api/SearchRequest";
4
+ import { SearchFilter as _SearchFilter1, SearchResponse } from "@depict-ai/types/api/SearchResponse";
3
5
  import { BaseCategoryDisplay, ProductListingResponse } from "@depict-ai/types/api/ProductListingResponse";
4
6
  import { CategorySuggestion, SearchSuggestionsResponse } from "@depict-ai/types/api/SearchSuggestionsResponse";
5
- import { SearchResponse } from "@depict-ai/types/api/SearchResponse";
6
- import { SearchRequest, SearchFilter } from "@depict-ai/types/api/SearchRequest";
7
7
  import { BaseSearchRequest } from "@depict-ai/types/api/BaseSearchRequest";
8
8
  import { SearchSuggestionsRequest } from "@depict-ai/types/api/SearchSuggestionsRequest";
9
9
  import { ProductListingRequest } from "@depict-ai/types/api/ProductListingRequest";
10
- export const version = "1.3.6";
10
+ export const version = "1.3.8";
11
+ export function accessor_of_object_to_object_with_accessor_values<O extends Record<string | symbol, any>>(obj: Accessor<O>): { [K in keyof O]: Accessor<O[K]>; };
12
+ /**
13
+ * Like standard_price_format except that the price and the formatting are reactive accessors
14
+ */
15
+ export function SolidFormatPrice(props: {
16
+ price_: number;
17
+ price_formatting_: {
18
+ pre_: string;
19
+ post_: string;
20
+ decimal_places_delimiter_: string;
21
+ thousands_delimiter_: string;
22
+ places_after_comma_: number | "auto";
23
+ };
24
+ }): JSX.Element;
25
+ /**
26
+ * PLP internationalisation shared between search and category listing
27
+ */
28
+ type plp_shared_i18n = {
29
+ scroll_to_top_: string;
30
+ back_: string;
31
+ open_sorting_: string;
32
+ close_sorting_: string;
33
+ open_filters_: string;
34
+ close_filters_: string;
35
+ close_: string;
36
+ ok_: string;
37
+ filters_cleared_: string;
38
+ we_cleared_your_filters_: string;
39
+ restore_: string;
40
+ sorting_text_: string;
41
+ filter_text_: string;
42
+ selected_filters_title_: string;
43
+ filters_: string;
44
+ view_less_: string;
45
+ view_more_: string;
46
+ clear_all_from_filter_crumbs_: string;
47
+ clear_individual_filter_: string;
48
+ of_: string;
49
+ clear_all_filters_from_big_button_: string;
50
+ try_without_filters_: string;
51
+ range_filter_low_point_aria_label_: string;
52
+ range_filter_high_point_aria_label_: string;
53
+ morphing_sign_expanded_aria_label_: string;
54
+ morphing_sign_collapsed_aria_label_: string;
55
+ price_formatting_: {
56
+ pre_: string;
57
+ post_: string;
58
+ decimal_places_delimiter_: string;
59
+ thousands_delimiter_: string;
60
+ places_after_comma_: number | "auto";
61
+ };
62
+ };
63
+ /**
64
+ * Search internationalisation
65
+ */
66
+ interface search_i18n extends plp_shared_i18n {
67
+ placeholder_text_: string;
68
+ show_n_results_: (number_of_results: HTMLElement) => Elem[];
69
+ no_results_text_: string;
70
+ search_recs_title_: string;
71
+ clear_filters_query_sorting_after_submit_: string;
72
+ modal_view_all_results_: (number_of_results: HTMLElement) => Elem[];
73
+ modal_discover_more_: string;
74
+ get_showing_results_for_: (query: HTMLElement, number_of_results: HTMLElement) => Elem[];
75
+ previous_searches_text_: string;
76
+ category_: string;
77
+ suggestions_: string;
78
+ search_submit_button_aria_label_: string;
79
+ search_field_field_aria_label_: string;
80
+ previous_searches_delete_entry_from_history_: string;
81
+ }
82
+ /**
83
+ * Category internationalisation
84
+ */
85
+ interface category_i18n extends plp_shared_i18n {
86
+ show_n_products_: (number_of_results: HTMLElement) => Elem[];
87
+ no_products_text_: string;
88
+ product_: string;
89
+ products_: string;
90
+ breadcrumbs_aria_label_: string;
91
+ quicklinks_aria_label_: string;
92
+ breadcrumbs_separator_: string;
93
+ }
94
+ /**
95
+ * For anything that is not exposed and only used internally we can use solid signals to get more performant rendering.
96
+ * For anything that can be used outside of solid, like Product Cards and InstantCards these types should not be used.
97
+ *
98
+ * Any solid_ type below should not be exposed outside of this library, as the accessors can be confusing and unnecessary.
99
+ */
100
+ /** For internal components using i18n that gets wrapped in solid's Accessors */
101
+ type solid_plp_shared_i18n = {
102
+ [K in keyof plp_shared_i18n]: Accessor<plp_shared_i18n[K]>;
103
+ };
104
+ /** @jsxImportSource solid-js */
105
+ export function GenericSliderArrowButton(props?: {
106
+ width_?: number;
107
+ height_?: number;
108
+ }): SVGElement;
109
+ export function show_toast({ children, on_close_, close_after_, ...more_attributes }: {
110
+ children?: JSX.Element;
111
+ close_after_: number;
112
+ on_close_?: VoidFunction;
113
+ } & JSX.HTMLAttributes<HTMLDivElement>): {
114
+ close_toast_: VoidFunction;
115
+ };
116
+ export type SDKGridSpacing = string | {
117
+ horizontal: string;
118
+ vertical: string;
119
+ };
120
+ export type WithRequired<T, K extends keyof T> = T & {
121
+ [P in K]-?: T[P];
122
+ };
123
+ type FilterWithData = WithRequired<SearchFilter, "data">;
124
+ export interface SDKRenderingInfo {
125
+ set_on_index_change: (fn: (index: number) => void) => void;
126
+ merchant: string;
127
+ market: string;
128
+ }
129
+ export type ProductCardTemplate<T extends Display> = (display: T | null, info?: SDKRenderingInfo) => JSX.Element | Promise<JSX.Element>;
130
+ /**
131
+ * Will be sent to backend to indicate whether the query_id_ is for a collection or category.
132
+ * Backend defaults to category if not specified.
133
+ */
134
+ export type ListingType = "collection" | "category";
135
+ export function CrossIcon(props?: JSX.SvgSVGAttributes<SVGSVGElement>): SVGElement;
136
+ export function SelectedFilters({ number_of_rendered_selected_filters_items_, i18n_, selected_filters_, local_filter_cache_: [read_local_filter_cache], get_search_filters_open_, get_search_sorting_open_, local_filter_cache_, expanded_hierarchical_filters_, }: {
137
+ get_search_filters_open_: Accessor<boolean>;
138
+ get_search_sorting_open_: Accessor<boolean>;
139
+ expanded_hierarchical_filters_: Signal<{
140
+ value_: string[];
141
+ expanded_: boolean;
142
+ }[]>;
143
+ number_of_rendered_selected_filters_items_: Signal<number>;
144
+ i18n_: solid_plp_shared_i18n;
145
+ selected_filters_: Signal<FilterWithData[]>;
146
+ local_filter_cache_: Signal<SearchFilter[]>;
147
+ }): HTMLDivElement;
148
+ /**
149
+ * Use `javascript_media_query` but return a reactive accessor instead of taking a callback function
150
+ */
151
+ export function media_query_to_accessor(media_query: string): import("solid-js").Accessor<boolean>;
11
152
  declare class SDKError extends Error {
12
153
  }
13
154
  export class ProductCardError extends SDKError {
14
155
  constructor(templateError: Error);
15
156
  }
157
+ /**
158
+ * Base placeholder component used by ImagePlaceholder and TextPlaceholder
159
+ */
160
+ export function BasePlaceholder(props: {
161
+ style: JSX.CSSProperties;
162
+ class?: string;
163
+ }): JSX.Element;
164
+ /**
165
+ * 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.
166
+ * If you want a block version, use `ImagePlaceholder` with `width`and `height` set instead.
167
+ * @property height height of the placeholder. Set to `1em` by default.
168
+ * @property width width of the placeholder. For specific number of characters use `ch`, ex: `width="7ch"`
169
+ * @property class extra classes to add to the placeholder
170
+ * @property style extra styles to add to the placeholder
171
+ */
172
+ export function TextPlaceholder(props: {
173
+ style?: JSX.CSSProperties;
174
+ height: string;
175
+ width: string;
176
+ class?: string;
177
+ }): JSX.Element;
178
+ interface FilterBodyProps {
179
+ available_filters_: Accessor<_SearchFilter1[] | undefined>;
180
+ expanded_filters_: Signal<{
181
+ section_: string;
182
+ expanded_: boolean;
183
+ }[]>;
184
+ selected_filters_: Signal<{
185
+ field: string;
186
+ op: _SearchFilter1["op"];
187
+ data: any;
188
+ }[]>;
189
+ local_filter_cache_: Signal<_SearchFilter1[]>;
190
+ i18n_: solid_plp_shared_i18n;
191
+ expanded_hierarchical_filters_: Signal<{
192
+ value_: string[];
193
+ expanded_: boolean;
194
+ }[]>;
195
+ are_in_modal_?: boolean;
196
+ }
197
+ export function FilterBody(props: FilterBodyProps): JSX.Element;
198
+ export function create_modified_filters({ available_filters_, local_filter_cache_: [read_local_cache, write_local_cache], selected_filters_: [read_selected_filters], }: {
199
+ available_filters_: Accessor<_SearchFilter1[] | undefined>;
200
+ selected_filters_: Signal<{
201
+ field: string;
202
+ op: _SearchFilter1["op"];
203
+ data: any;
204
+ }[]>;
205
+ local_filter_cache_: Signal<_SearchFilter1[]>;
206
+ }): void;
16
207
  export type SolidLayoutOptions = {
17
208
  cols_at_size: ColsAtSize;
18
209
  grid_spacing: string;
@@ -95,12 +286,6 @@ export function general_modal_abstraction<StaticOptions extends {
95
286
  open_modal_: (extra_options_for_modal?: ExtraOptionsProvidedOnOpen, on_dispose?: VoidFunction) => void;
96
287
  close_modal_: () => void;
97
288
  }>;
98
- export function CrossIcon(props?: JSX.SvgSVGAttributes<SVGSVGElement>): SVGElement;
99
- /** @jsxImportSource solid-js */
100
- export function GenericSliderArrowButton(props?: {
101
- width_?: number;
102
- height_?: number;
103
- }): SVGElement;
104
289
  export type OnNavigation = ((options: {
105
290
  is_replace: boolean;
106
291
  new_url: URL;
@@ -168,88 +353,6 @@ type RecsAPIWrapperOptions = {
168
353
  * @return This function is guaranteed to return an array of Displays. If anything fails, you will get an empty array.
169
354
  */
170
355
  export function fetchDepictRecommendations<T extends Display = Display>({ merchant, market, headers, ...fetch_recs_options }: RecsAPIWrapperOptions): Promise<T[]>;
171
- /**
172
- * Like standard_price_format except that the price and the formatting are reactive accessors
173
- */
174
- export function SolidFormatPrice(props: {
175
- price_: number;
176
- price_formatting_: {
177
- pre_: string;
178
- post_: string;
179
- decimal_places_delimiter_: string;
180
- thousands_delimiter_: string;
181
- places_after_comma_: number | "auto";
182
- };
183
- }): JSX.Element;
184
- /**
185
- * PLP internationalisation shared between search and category listing
186
- */
187
- type plp_shared_i18n = {
188
- scroll_to_top_: string;
189
- back_: string;
190
- open_sorting_: string;
191
- close_sorting_: string;
192
- open_filters_: string;
193
- close_filters_: string;
194
- close_: string;
195
- ok_: string;
196
- filters_cleared_: string;
197
- we_cleared_your_filters_: string;
198
- restore_: string;
199
- sorting_text_: string;
200
- filter_text_: string;
201
- selected_filters_title_: string;
202
- filters_: string;
203
- view_less_: string;
204
- view_more_: string;
205
- clear_all_from_filter_crumbs_: string;
206
- clear_individual_filter_: string;
207
- of_: string;
208
- clear_all_filters_from_big_button_: string;
209
- try_without_filters_: string;
210
- range_filter_low_point_aria_label_: string;
211
- range_filter_high_point_aria_label_: string;
212
- morphing_sign_expanded_aria_label_: string;
213
- morphing_sign_collapsed_aria_label_: string;
214
- price_formatting_: {
215
- pre_: string;
216
- post_: string;
217
- decimal_places_delimiter_: string;
218
- thousands_delimiter_: string;
219
- places_after_comma_: number | "auto";
220
- };
221
- };
222
- /**
223
- * Search internationalisation
224
- */
225
- interface search_i18n extends plp_shared_i18n {
226
- placeholder_text_: string;
227
- show_n_results_: (number_of_results: HTMLElement) => Elem[];
228
- no_results_text_: string;
229
- search_recs_title_: string;
230
- clear_filters_query_sorting_after_submit_: string;
231
- modal_view_all_results_: (number_of_results: HTMLElement) => Elem[];
232
- modal_discover_more_: string;
233
- get_showing_results_for_: (query: HTMLElement, number_of_results: HTMLElement) => Elem[];
234
- previous_searches_text_: string;
235
- category_: string;
236
- suggestions_: string;
237
- search_submit_button_aria_label_: string;
238
- search_field_field_aria_label_: string;
239
- previous_searches_delete_entry_from_history_: string;
240
- }
241
- /**
242
- * Category internationalisation
243
- */
244
- interface category_i18n extends plp_shared_i18n {
245
- show_n_products_: (number_of_results: HTMLElement) => Elem[];
246
- no_products_text_: string;
247
- product_: string;
248
- products_: string;
249
- breadcrumbs_aria_label_: string;
250
- quicklinks_aria_label_: string;
251
- breadcrumbs_separator_: string;
252
- }
253
356
  export type InstantCard<T extends Display> = (display: T, context: {
254
357
  index: number;
255
358
  i18n: search_i18n;
@@ -309,56 +412,6 @@ export class DepictAPI<InputDisplay extends Display, OutputDisplay extends Moder
309
412
  failed?: true | undefined;
310
413
  }>;
311
414
  }
312
- /**
313
- * Use `javascript_media_query` but return a reactive accessor instead of taking a callback function
314
- */
315
- export function media_query_to_accessor(media_query: string): import("solid-js").Accessor<boolean>;
316
- export type SDKGridSpacing = string | {
317
- horizontal: string;
318
- vertical: string;
319
- };
320
- export type WithRequired<T, K extends keyof T> = T & {
321
- [P in K]-?: T[P];
322
- };
323
- export interface SDKRenderingInfo {
324
- set_on_index_change: (fn: (index: number) => void) => void;
325
- merchant: string;
326
- market: string;
327
- }
328
- export type ProductCardTemplate<T extends Display> = (display: T | null, info?: SDKRenderingInfo) => JSX.Element | Promise<JSX.Element>;
329
- /**
330
- * Will be sent to backend to indicate whether the query_id_ is for a collection or category.
331
- * Backend defaults to category if not specified.
332
- */
333
- export type ListingType = "collection" | "category";
334
- export function show_toast({ children, on_close_, close_after_, ...more_attributes }: {
335
- children?: JSX.Element;
336
- close_after_: number;
337
- on_close_?: VoidFunction;
338
- } & JSX.HTMLAttributes<HTMLDivElement>): {
339
- close_toast_: VoidFunction;
340
- };
341
- /**
342
- * Base placeholder component used by ImagePlaceholder and TextPlaceholder
343
- */
344
- export function BasePlaceholder(props: {
345
- style: JSX.CSSProperties;
346
- class?: string;
347
- }): JSX.Element;
348
- /**
349
- * 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.
350
- * If you want a block version, use `ImagePlaceholder` with `width`and `height` set instead.
351
- * @property height height of the placeholder. Set to `1em` by default.
352
- * @property width width of the placeholder. For specific number of characters use `ch`, ex: `width="7ch"`
353
- * @property class extra classes to add to the placeholder
354
- * @property style extra styles to add to the placeholder
355
- */
356
- export function TextPlaceholder(props: {
357
- style?: JSX.CSSProperties;
358
- height: string;
359
- width: string;
360
- class?: string;
361
- }): JSX.Element;
362
415
  /**
363
416
  * Disables scrolling until the solidjs reactive scoped is disposed (onCleanup)
364
417
  * @returns A cleanup function to manually re-enable scrolling.
@@ -400,7 +453,9 @@ type GeneralCategoryListingOptions = {
400
453
  market: string;
401
454
  merchant: string;
402
455
  localization: category_i18n;
456
+ unique_instance_key_for_state?: string;
403
457
  on_navigation?: OnNavigation;
458
+ query_id_state_key?: string;
404
459
  };
405
460
  type CategoryConstructorOptionsWithApi<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never> = GeneralCategoryListingOptions & {
406
461
  api: DepictAPI<InputDisplay, OutputDisplay>;
@@ -431,7 +486,7 @@ export class DepictCategory<InputDisplay extends Display, OutputDisplay extends
431
486
  set listing_type(listing_type: ListingType | undefined);
432
487
  get on_navigation(): OnNavigation;
433
488
  set on_navigation(new_function: OnNavigation);
434
- constructor({ api, on_navigation, page_url_creator, ...props_on_class }: DepictCategoryConstructorOptions<InputDisplay, OutputDisplay>);
489
+ constructor({ api, on_navigation, page_url_creator, unique_instance_key_for_state, query_id_state_key, ...props_on_class }: DepictCategoryConstructorOptions<InputDisplay, OutputDisplay>);
435
490
  }
436
491
  export function CategoryPage<OriginalDisplay extends Display, OutputDisplay extends ModernDisplay | never>(props: {
437
492
  depict_category: DepictCategory<OriginalDisplay, OutputDisplay>;
@@ -511,6 +566,7 @@ type GeneralConstructorOptions<InputDisplay extends Display, OutputDisplay exten
511
566
  on_navigation?: OnNavigation;
512
567
  url_transformer?: (url_object: URL) => unknown;
513
568
  enable_category_suggestions?: boolean;
569
+ unique_instance_key_for_state?: string;
514
570
  disable_scrolling_during_modal?: boolean;
515
571
  bottom_distance_under_modal?: Accessor<number | undefined>;
516
572
  render_instant_card?: InstantCard<OutputDisplay extends ModernDisplay ? OutputDisplay : InputDisplay>;
@@ -537,7 +593,7 @@ export type OpenModalArguments = [
537
593
  export const get_search_query_updating_blocked_signal: (depict_search: DepictSearch<any>) => Signal<boolean> | undefined;
538
594
  export class DepictSearch<InputDisplay extends Display, OutputDisplay extends ModernDisplay | never = InputDisplay extends ModernDisplay ? ModernDisplayWithPageUrl<InputDisplay> : never> {
539
595
  #private;
540
- 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>);
596
+ constructor({ unique_instance_key_for_state, 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>);
541
597
  get on_navigation(): OnNavigation;
542
598
  set on_navigation(new_function: OnNavigation);
543
599
  get localization(): search_i18n;
@@ -595,6 +651,13 @@ export type BaseProviderConfig<InputDisplay extends Display, PossibleTransformed
595
651
  * Custom metadata to be sent with each request to the Depict API. Only necessary if specifically instructed by Depict.
596
652
  */
597
653
  metaData?: Record<string, string>;
654
+ /**
655
+ * You can't have more than one instance of the same provider on the same page, unless you specify a unique instance key for each one.
656
+ * This is because there's state in the URL and history.state and the state of the different instances would collide.
657
+ * By setting this property, you can specify a unique key for each instance, so that the state of each instance is kept separate.
658
+ * We recommend to just use an incrementing number for this, e.g. "1", "2", "3", ...
659
+ */
660
+ uniqueInstanceKeyForState?: string;
598
661
  } & (InputDisplay extends ModernDisplay ? "page_url" extends keyof InputDisplay["variant_displays"][number] ? {
599
662
  pageURLCreator?: PageURLCreator<InputDisplay, PossibleTransformedDisplay>;
600
663
  } : {