@depict-ai/ui 3.0.6 → 3.0.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/latest/index.js CHANGED
@@ -7,7 +7,7 @@ import { createStore as $9HbP8$createStore, reconcile as $9HbP8$reconcile } from
7
7
  /*! Depict.ai search and product listing SDK */
8
8
  import { register_es_version } from "../multi_import_deduplicator.mjs";
9
9
  register_es_version("ui", "latest");
10
- const $ec291e0010116877$export$83d89fbfd8236492 = "3.0.6";
10
+ const $ec291e0010116877$export$83d89fbfd8236492 = "3.0.8";
11
11
  const $fbbadcb080ad1d4a$var$_tmpl$ = /*#__PURE__*/$9HbP8$template(`<svg xmlns=http://www.w3.org/2000/svg viewBox="0 0 14 26"><path d="M2 24.656c-.078 0-.156-.016-.234-.047s-.133-.066-.187-.129c-.117-.117-.176-.258-.176-.422s.059-.305.176-.422l10.371-10.371L1.578 2.883c-.117-.117-.176-.258-.176-.422s.059-.305.176-.422.258-.176.422-.176.305.059.422.176l10.805 10.793a.59.59 0 0 1 .176.434c0 .172-.059.305-.176.422L2.422 24.48a.42.42 0 0 1-.199.129.54.54 0 0 1-.223.047zm0 0"fill=#0f0f0f>`);
12
12
  function $fbbadcb080ad1d4a$export$8be2714ec7f169ee(props = {}) {
13
13
  return (() => {
@@ -5431,6 +5431,65 @@ function $e5014ccd0b76d9f4$export$967e966fca9515e(api_response) {
5431
5431
  // Why not use const enum? See https://gitlab.com/depict-ai/depict.ai/-/merge_requests/9223#note_1675965260
5432
5432
  const $c20599a0d81d953a$export$74ee7529ce0f8a00 = "listingId";
5433
5433
  const $c20599a0d81d953a$export$5aae649db1b959fc = "externalId";
5434
+
5435
+ /**
5436
+ * Converts a v3 API response into something that has quick_links and breadcrumbs that behave as in v2 instead of ancestors, children and siblings, but gives every quicklink and breadcrumb's transformer the ancestors of the listing they are for.
5437
+ */
5438
+ async function $23f4eb8487f328d9$export$d9792230b7c0203e({
5439
+ input_data_: {
5440
+ ancestors: ancestors,
5441
+ children: children,
5442
+ siblings: siblings,
5443
+ ...clonedInputData
5444
+ },
5445
+ category_transformer_ = v => v.data,
5446
+ merchant_:
5447
+ // in case no display transformer just pass the data through, so we don't break
5448
+ merchant_,
5449
+ market_: market_,
5450
+ locale_: locale_
5451
+ }) {
5452
+ const breadcrumbs = [];
5453
+ const clonedAncestors = [...ancestors];
5454
+ while (clonedAncestors.length) {
5455
+ const ancestor = clonedAncestors.pop();
5456
+ if (!ancestor.show_in_breadcrumbs) continue;
5457
+ breadcrumbs.push({
5458
+ ...ancestor,
5459
+ ancestors: [...clonedAncestors]
5460
+ });
5461
+ }
5462
+ breadcrumbs.reverse();
5463
+ const quicklinksIsChildren = children.length;
5464
+ const quickLinks = (quicklinksIsChildren ? children : siblings).filter(({
5465
+ show_in_quicklinks: show_in_quicklinks
5466
+ }) => show_in_quicklinks).map(productListing => {
5467
+ const ancestorsForUs = [...ancestors];
5468
+ if (quicklinksIsChildren) ancestorsForUs.push({
5469
+ ...clonedInputData
5470
+ });
5471
+ return {
5472
+ ...productListing,
5473
+ ancestors: ancestorsForUs
5474
+ };
5475
+ });
5476
+ const [transformedBreadcrumbs, transformedQuickLinks] = await Promise.all([category_transformer_({
5477
+ merchant: merchant_,
5478
+ market: market_,
5479
+ locale: locale_,
5480
+ data: breadcrumbs
5481
+ }), category_transformer_({
5482
+ merchant: merchant_,
5483
+ market: market_,
5484
+ locale: locale_,
5485
+ data: quickLinks
5486
+ })]);
5487
+ return {
5488
+ ...clonedInputData,
5489
+ breadcrumbs: transformedBreadcrumbs,
5490
+ quick_links: transformedQuickLinks
5491
+ };
5492
+ }
5434
5493
  const $7fa23e2a0079eca4$var$v3_base_url = (0, $9HbP8$base_url) + "/v3/";
5435
5494
  const $7fa23e2a0079eca4$var$search_base_url = $7fa23e2a0079eca4$var$v3_base_url + "search/";
5436
5495
  class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
@@ -5456,20 +5515,32 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
5456
5515
  };
5457
5516
  #get_metadata;
5458
5517
  #get_session_id;
5459
- async #run_url_creator_for_suggest(merchant, market, response) {
5518
+ async #run_url_creator_for_suggest(merchant, market, locale, response) {
5460
5519
  const category_transformer = this.display_transformers?.categories;
5461
5520
  if (!category_transformer) return response;
5521
+ const incoming_suggestions = response.suggestions;
5522
+ const type_to_transform = "listing";
5462
5523
  // find category suggestions, run thing with them, and then replace them
5463
- const category_suggestions = response.suggestions.filter(suggestion => suggestion.type === "listing");
5464
- const transformed_category_suggestions = await category_transformer({
5524
+ const category_suggestions = incoming_suggestions.filter(suggestion => suggestion.type === type_to_transform);
5525
+ const transformed_suggestions = [...(await category_transformer({
5465
5526
  market: market,
5466
5527
  merchant: merchant,
5528
+ locale: locale,
5467
5529
  data: [...category_suggestions]
5468
- });
5469
- response.suggestions = transformed_category_suggestions;
5530
+ }))];
5531
+ // Then add-back query suggestions at their original indices
5532
+ for (let i = 0; i < incoming_suggestions.length; i++) {
5533
+ const item = incoming_suggestions[i];
5534
+ if (item.type === type_to_transform) continue;
5535
+ transformed_suggestions.splice(i, 0, item);
5536
+ }
5537
+ response.suggestions = transformed_suggestions;
5470
5538
  return response;
5471
5539
  }
5472
- async #run_display_transformers_for_rest(merchant, market, input_data) {
5540
+ /**
5541
+ * rest = everything except query suggestions
5542
+ */
5543
+ async #run_display_transformers_for_rest(merchant, market, locale, input_data) {
5473
5544
  const {
5474
5545
  display_transformers: display_transformers
5475
5546
  } = this;
@@ -5485,25 +5556,24 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
5485
5556
  const transformed_displays = await product_transformer({
5486
5557
  merchant: merchant,
5487
5558
  market: market,
5559
+ locale: locale,
5488
5560
  displays: [...displays]
5489
5561
  });
5490
5562
  input_data.displays = transformed_displays;
5491
5563
  }
5492
- if (category_transformer) for (const key of ["breadcrumbs", "quick_links"]) {
5493
- const category_display_array = input_data[key];
5494
- if (!category_display_array) continue;
5495
- const transformed_category_displays = await category_transformer({
5496
- merchant: merchant,
5497
- market: market,
5498
- data: [...category_display_array]
5499
- });
5500
- input_data[key] = transformed_category_displays;
5501
- }
5502
5564
  if (content_search_links?.length && content_result_transformer) input_data.content_search_links = await content_result_transformer({
5503
5565
  merchant: merchant,
5504
5566
  market: market,
5567
+ locale: locale,
5505
5568
  data: [...content_search_links]
5506
5569
  });
5570
+ if (input_data.ancestors) return await $23f4eb8487f328d9$export$d9792230b7c0203e({
5571
+ input_data_: input_data,
5572
+ category_transformer_: category_transformer,
5573
+ merchant_: merchant,
5574
+ market_: market,
5575
+ locale_: locale
5576
+ });
5507
5577
  return input_data;
5508
5578
  }
5509
5579
  async #cached_request({
@@ -5540,7 +5610,7 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
5540
5610
  let result;
5541
5611
  try {
5542
5612
  const unmodified_result = await api_response.json();
5543
- result = await this.#run_display_transformers_for_rest(input_req_.merchant, input_req_.market, unmodified_result);
5613
+ result = await this.#run_display_transformers_for_rest(input_req_.merchant, input_req_.market, input_req_.locale, unmodified_result);
5544
5614
  } catch (e) {
5545
5615
  $9HbP8$dwarn("displayTransformer or json decoding failed", e);
5546
5616
  break return_successfully;
@@ -5590,7 +5660,7 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
5590
5660
  const decoded_json = await results.json();
5591
5661
  if (!Array.isArray(decoded_json?.suggestions)) break attempt_to_return_api_response;
5592
5662
  try {
5593
- return await this.#run_url_creator_for_suggest(input_req.merchant, input_req.market, decoded_json);
5663
+ return await this.#run_url_creator_for_suggest(input_req.merchant, input_req.market, input_req.locale, decoded_json);
5594
5664
  } catch (e) {
5595
5665
  $9HbP8$dwarn("displayTransformer failed", e);
5596
5666
  }
@@ -5626,13 +5696,12 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
5626
5696
  fallback_response_: () => ({
5627
5697
  listing_id: "",
5628
5698
  listing_type: "category",
5629
- "title": "",
5630
- "description": "string",
5631
- "replace_meta_tags": true,
5632
- "slug": "",
5633
- "updated_at": new Date().toISOString(),
5634
- "breadcrumbs": [],
5635
- "quick_links": [],
5699
+ title: "",
5700
+ slug: "",
5701
+ show_in_breadcrumbs: false,
5702
+ show_in_quicklinks: false,
5703
+ breadcrumbs: [],
5704
+ quick_links: [],
5636
5705
  failed: true
5637
5706
  }),
5638
5707
  method_: "GET"
@@ -8229,7 +8298,7 @@ function $df5d81d0fe61ff21$export$f7d2f673fc2f091d({
8229
8298
  })));
8230
8299
  const available_filters_ = $9HbP8$createMemo(() => plp_products_()?.filters);
8231
8300
  const title = $9HbP8$createMemo(() => plp_meta()?.title);
8232
- const crumb_data_ = $df5d81d0fe61ff21$var$add_us_to_crumbs(plp_meta, title);
8301
+ const crumb_data_ = $df5d81d0fe61ff21$var$add_us_to_crumbs(plp_meta);
8233
8302
  const quicklinks_data_ = $9HbP8$createMemo(() => plp_meta()?.quick_links);
8234
8303
  const [sort_or_filter_open_, set_sort_or_filter_open_] = $9HbP8$createSignal(false);
8235
8304
  const [desktop_filter_elements_, set_desktop_filter_elements] = $9HbP8$createSignal();
@@ -8507,31 +8576,16 @@ function $df5d81d0fe61ff21$export$f7d2f673fc2f091d({
8507
8576
  /**
8508
8577
  * Adds the current page as last breadcrumb to the breadcrumb trail
8509
8578
  */
8510
- function $df5d81d0fe61ff21$var$add_us_to_crumbs(plp_meta, title) {
8579
+ function $df5d81d0fe61ff21$var$add_us_to_crumbs(plp_meta) {
8511
8580
  const href_accessor = $9HbP8$use_href_accessor();
8512
8581
  return $9HbP8$createMemo(() => {
8513
8582
  const api_value = plp_meta()?.breadcrumbs;
8514
8583
  if (!api_value) return api_value;
8515
- return [...api_value, {
8516
- get listing_id() {
8517
- return plp_meta().listing_id;
8518
- },
8519
- get title() {
8520
- return title();
8521
- },
8584
+ return [...api_value, $9HbP8$mergeProps1(plp_meta(), {
8522
8585
  get page_url() {
8523
8586
  return href_accessor();
8524
- },
8525
- get slug() {
8526
- return plp_meta().slug;
8527
- },
8528
- get listing_type() {
8529
- return plp_meta().listing_type;
8530
- },
8531
- get external_id() {
8532
- return plp_meta().external_id;
8533
8587
  }
8534
- }];
8588
+ })];
8535
8589
  });
8536
8590
  }
8537
8591
  function $ccd5db07a3a069c5$export$477caf01aecaeb2a(options) {
@@ -9138,7 +9192,7 @@ function $897bd4a76f611b38$export$d757d54550ebfb3d({
9138
9192
  category_suggestion_: category_suggestion_,
9139
9193
  router_: router_
9140
9194
  }) {
9141
- const parentTitle = $9HbP8$createMemo(() => category_suggestion_().breadcrumbs.at(-1)?.title);
9195
+ const parentTitle = $9HbP8$createMemo(() => category_suggestion_().ancestors.at(-1)?.title);
9142
9196
  return (() => {
9143
9197
  const _el$ = $9HbP8$getNextElement($897bd4a76f611b38$var$_tmpl$2),
9144
9198
  _el$2 = _el$.firstChild,
@@ -9836,7 +9890,7 @@ function $7ad3a93cbe6fa208$export$a146ac6fa8346a25({
9836
9890
  currently_showing_suggestions_[1](value => {
9837
9891
  value[0] = $9HbP8$createMemo(() => previous_searches_().map(result => ({
9838
9892
  type: (0, $a0eb8b431ec1f87b$export$3cf9497e790da491),
9839
- title: result,
9893
+ query: result,
9840
9894
  suggestions_result_id: "history"
9841
9895
  })));
9842
9896
  return value;
@@ -9956,10 +10010,7 @@ function $cea52f6b24092f05$export$e872e2339fb04a7f({
9956
10010
  submit_query_: submit_query_,
9957
10011
  get_content_results_: get_content_results_
9958
10012
  }) {
9959
- const queries_memo = $9HbP8$createMemo(() => suggestion_memo_().filter(({
9960
- type: type,
9961
- title: title
9962
- }) => type === (0, $a0eb8b431ec1f87b$export$3cf9497e790da491) && !filtered_previous_searches_().includes(title) // don't show the ones we already show from the history
10013
+ const queries_memo = $9HbP8$createMemo(() => suggestion_memo_().filter(suggestion => suggestion.type === (0, $a0eb8b431ec1f87b$export$3cf9497e790da491) && !filtered_previous_searches_().includes(suggestion.query) // don't show the ones we already show from the history
9963
10014
  ) // + limit to three query suggestions, API sends more sometimes
9964
10015
  .slice(0, 3));
9965
10016
  const not_queries_memo = $9HbP8$createMemo(() => {
@@ -9975,15 +10026,15 @@ function $cea52f6b24092f05$export$e872e2339fb04a7f({
9975
10026
  const is_query = $9HbP8$createMemo(() => input_obj().type === (0, $a0eb8b431ec1f87b$export$3cf9497e790da491));
9976
10027
  const href_with_changed_params_accessor = $9HbP8$createMemo(() => is_query() ? $a36cbc4f68bfd590$export$91c3b6774e8be0f5({
9977
10028
  param_: search_query_url_param_name_,
9978
- value_: $9HbP8$createMemo(() => input_obj().title),
10029
+ value_: $9HbP8$createMemo(() => input_obj().query),
9979
10030
  url_transformer_: url_transformer_
9980
10031
  }) : undefined);
9981
10032
  const href = $9HbP8$createMemo(() => is_query() ? href_with_changed_params_accessor()() : input_obj().page_url);
9982
10033
  const is_selected = $9HbP8$createMemo(() => read_selected_index_()?.[0] === autocomplete_data_index && read_selected_index_()?.[1] === index);
9983
10034
  const parent_title_if_exists = $9HbP8$createMemo(() => {
9984
10035
  const item = input_obj();
9985
- if (!("breadcrumbs" in item)) return;
9986
- return item.breadcrumbs.at(-1)?.title;
10036
+ if (!("ancestors" in item)) return;
10037
+ return item.ancestors.at(-1)?.title;
9987
10038
  });
9988
10039
  return (() => {
9989
10040
  const _el$ = $9HbP8$getNextElement($cea52f6b24092f05$var$_tmpl$);
@@ -9993,8 +10044,9 @@ function $cea52f6b24092f05$export$e872e2339fb04a7f({
9993
10044
  if (ev.button || ev.metaKey || ev.ctrlKey)
9994
10045
  // not button 0 or cmd/ctrl click
9995
10046
  return;
10047
+ const input = input_obj();
9996
10048
  ev.preventDefault();
9997
- submit_query_(input_obj().title);
10049
+ submit_query_(is_query() ? input.query : input.title);
9998
10050
  return;
9999
10051
  }
10000
10052
  router_.navigate_.go_to_({
@@ -10022,7 +10074,7 @@ function $cea52f6b24092f05$export$e872e2339fb04a7f({
10022
10074
  }), $9HbP8$createComponent((0, $f3213c0640246d58$export$ba17c5b7e6dda39f), {
10023
10075
  class_: "value line-clamp",
10024
10076
  get whole_text_to_display_() {
10025
- return $9HbP8$createMemo(() => input_obj().title);
10077
+ return $9HbP8$createMemo(() => input_obj().query);
10026
10078
  },
10027
10079
  searching_for_value_: searching_for_value_
10028
10080
  })] : [$9HbP8$memo((() => {
@@ -10150,7 +10202,7 @@ function $cea52f6b24092f05$export$e872e2339fb04a7f({
10150
10202
  return (() => {
10151
10203
  const mapped_history_results = $9HbP8$createMemo(() => filtered_previous_searches_().map(result => ({
10152
10204
  type: (0, $a0eb8b431ec1f87b$export$3cf9497e790da491),
10153
- title: result,
10205
+ query: result,
10154
10206
  suggestions_result_id: "history" // worthless to fix typing
10155
10207
  })));
10156
10208
 
@@ -10321,16 +10373,16 @@ function $15f380f0ce2812cc$var$actual_navigation_working_on_fake_data({
10321
10373
  // update text field value if needed
10322
10374
  if (selected_entry?.type == "query") {
10323
10375
  const {
10324
- title: title
10376
+ query: query
10325
10377
  } = selected_entry;
10326
10378
  $9HbP8$runWithOwner(owner, block_updating_for_one_change);
10327
- set_search_field_value(title);
10379
+ set_search_field_value(query);
10328
10380
  $9HbP8$runWithOwner(owner, () => override_on_enter_for_this_entry(e => {
10329
10381
  // Open search query in new tab on cmd+enter
10330
10382
  // If it's not cmd+enter, pressing enter will just submit the value that was put into the field while selecting with the arrow keys ;)
10331
10383
  const url = new URL(location);
10332
10384
  url_transformer_?.(url);
10333
- url.searchParams.set(search_query_param_name_, title);
10385
+ url.searchParams.set(search_query_param_name_, query);
10334
10386
  return $92a48aea6a9364d8$export$1efe1013da60d0e4(e, url.href);
10335
10387
  }));
10336
10388
  } else if (selected_entry?.type == "listing" || selected_entry?.type === "content") $9HbP8$runWithOwner(owner, () => override_on_enter_for_this_entry(e => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depict-ai/ui",
3
- "version": "3.0.6",
3
+ "version": "3.0.8",
4
4
  "description": "Base package containing the actual UI of Depict UI along with translations, with a not-simplified API. We recommend using @depict-ai/js-ui or @depict-ai/react-ui instead.",
5
5
  "packageManager": "yarn@3.2.2",
6
6
  "sass": "styles.scss",
@@ -236,9 +236,9 @@
236
236
  "@babel/plugin-transform-typescript": "^7.22.9",
237
237
  "@babel/runtime": "latest",
238
238
  "@babel/runtime-corejs3": "^7.22.6",
239
- "@depict-ai/plp-styling": "^2.0.1",
240
- "@depict-ai/types": "^5.0.1",
241
- "@depict-ai/utilishared": "^2.0.1",
239
+ "@depict-ai/plp-styling": "^2.0.2",
240
+ "@depict-ai/types": "^5.0.2",
241
+ "@depict-ai/utilishared": "^2.0.2",
242
242
  "solid-js": "^1.8.1"
243
243
  },
244
244
  "type": "module",