@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/ES10/index.js CHANGED
@@ -10,7 +10,7 @@ import { createStore as $8tj43$createStore, reconcile as $8tj43$reconcile } from
10
10
  /*! Depict.ai search and product listing SDK */
11
11
  import { register_es_version } from "../multi_import_deduplicator.mjs";
12
12
  register_es_version("ui", "ES10");
13
- const $8db9a15135765c11$export$83d89fbfd8236492 = "3.0.6";
13
+ const $8db9a15135765c11$export$83d89fbfd8236492 = "3.0.8";
14
14
  const $ca6ab5f08bd28bca$var$_tmpl$ = /*#__PURE__*/$8tj43$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>`);
15
15
  function $ca6ab5f08bd28bca$export$8be2714ec7f169ee() {
16
16
  let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -5766,6 +5766,69 @@ function $ed0fefda39a0f15d$export$967e966fca9515e(api_response) {
5766
5766
  // Why not use const enum? See https://gitlab.com/depict-ai/depict.ai/-/merge_requests/9223#note_1675965260
5767
5767
  const $397620a4d7958ed1$export$74ee7529ce0f8a00 = "listingId";
5768
5768
  const $397620a4d7958ed1$export$5aae649db1b959fc = "externalId";
5769
+
5770
+ /**
5771
+ * 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.
5772
+ */
5773
+ async function $f454ce4c74ef4dc0$export$d9792230b7c0203e(_ref) {
5774
+ let {
5775
+ input_data_: {
5776
+ ancestors: ancestors,
5777
+ children: children,
5778
+ siblings: siblings,
5779
+ ...clonedInputData
5780
+ },
5781
+ category_transformer_ = v => v.data,
5782
+ merchant_:
5783
+ // in case no display transformer just pass the data through, so we don't break
5784
+ merchant_,
5785
+ market_: market_,
5786
+ locale_: locale_
5787
+ } = _ref;
5788
+ const breadcrumbs = [];
5789
+ const clonedAncestors = [...ancestors];
5790
+ while (clonedAncestors.length) {
5791
+ const ancestor = clonedAncestors.pop();
5792
+ if (!ancestor.show_in_breadcrumbs) continue;
5793
+ breadcrumbs.push({
5794
+ ...ancestor,
5795
+ ancestors: [...clonedAncestors]
5796
+ });
5797
+ }
5798
+ breadcrumbs.reverse();
5799
+ const quicklinksIsChildren = children.length;
5800
+ const quickLinks = (quicklinksIsChildren ? children : siblings).filter(_ref2 => {
5801
+ let {
5802
+ show_in_quicklinks: show_in_quicklinks
5803
+ } = _ref2;
5804
+ return show_in_quicklinks;
5805
+ }).map(productListing => {
5806
+ const ancestorsForUs = [...ancestors];
5807
+ if (quicklinksIsChildren) ancestorsForUs.push({
5808
+ ...clonedInputData
5809
+ });
5810
+ return {
5811
+ ...productListing,
5812
+ ancestors: ancestorsForUs
5813
+ };
5814
+ });
5815
+ const [transformedBreadcrumbs, transformedQuickLinks] = await Promise.all([category_transformer_({
5816
+ merchant: merchant_,
5817
+ market: market_,
5818
+ locale: locale_,
5819
+ data: breadcrumbs
5820
+ }), category_transformer_({
5821
+ merchant: merchant_,
5822
+ market: market_,
5823
+ locale: locale_,
5824
+ data: quickLinks
5825
+ })]);
5826
+ return {
5827
+ ...clonedInputData,
5828
+ breadcrumbs: transformedBreadcrumbs,
5829
+ quick_links: transformedQuickLinks
5830
+ };
5831
+ }
5769
5832
  function $284849364a6ef73a$var$_classPrivateMethodInitSpec(obj, privateSet) {
5770
5833
  $284849364a6ef73a$var$_checkPrivateRedeclaration(obj, privateSet);
5771
5834
  privateSet.add(obj);
@@ -5793,6 +5856,9 @@ var $284849364a6ef73a$var$_run_url_creator_for_suggest = /*#__PURE__*/new WeakSe
5793
5856
  var $284849364a6ef73a$var$_run_display_transformers_for_rest = /*#__PURE__*/new WeakSet();
5794
5857
  var $284849364a6ef73a$var$_cached_request = /*#__PURE__*/new WeakSet();
5795
5858
  class $284849364a6ef73a$export$e015ed2f2950f2e3 {
5859
+ /**
5860
+ * rest = everything except query suggestions
5861
+ */
5796
5862
  constructor(options) {
5797
5863
  $284849364a6ef73a$var$_classPrivateMethodInitSpec(this, $284849364a6ef73a$var$_cached_request);
5798
5864
  $284849364a6ef73a$var$_classPrivateMethodInitSpec(this, $284849364a6ef73a$var$_run_display_transformers_for_rest);
@@ -5849,7 +5915,7 @@ class $284849364a6ef73a$export$e015ed2f2950f2e3 {
5849
5915
  const decoded_json = await results.json();
5850
5916
  if (!Array.isArray(decoded_json === null || decoded_json === void 0 ? void 0 : decoded_json.suggestions)) break attempt_to_return_api_response;
5851
5917
  try {
5852
- return await $284849364a6ef73a$var$_classPrivateMethodGet(this, $284849364a6ef73a$var$_run_url_creator_for_suggest, $284849364a6ef73a$var$_run_url_creator_for_suggest2).call(this, input_req.merchant, input_req.market, decoded_json);
5918
+ return await $284849364a6ef73a$var$_classPrivateMethodGet(this, $284849364a6ef73a$var$_run_url_creator_for_suggest, $284849364a6ef73a$var$_run_url_creator_for_suggest2).call(this, input_req.merchant, input_req.market, input_req.locale, decoded_json);
5853
5919
  } catch (e) {
5854
5920
  $8tj43$dwarn("displayTransformer failed", e);
5855
5921
  }
@@ -5886,13 +5952,12 @@ class $284849364a6ef73a$export$e015ed2f2950f2e3 {
5886
5952
  fallback_response_: () => ({
5887
5953
  listing_id: "",
5888
5954
  listing_type: "category",
5889
- "title": "",
5890
- "description": "string",
5891
- "replace_meta_tags": true,
5892
- "slug": "",
5893
- "updated_at": new Date().toISOString(),
5894
- "breadcrumbs": [],
5895
- "quick_links": [],
5955
+ title: "",
5956
+ slug: "",
5957
+ show_in_breadcrumbs: false,
5958
+ show_in_quicklinks: false,
5959
+ breadcrumbs: [],
5960
+ quick_links: [],
5896
5961
  failed: true
5897
5962
  }),
5898
5963
  method_: "GET"
@@ -5939,21 +6004,30 @@ function $284849364a6ef73a$var$_get_cache_obj_for_endpoint2(endpoint) {
5939
6004
  })) : undefined
5940
6005
  });
5941
6006
  }
5942
- async function $284849364a6ef73a$var$_run_url_creator_for_suggest2(merchant, market, response) {
6007
+ async function $284849364a6ef73a$var$_run_url_creator_for_suggest2(merchant, market, locale, response) {
5943
6008
  var _this$display_transfo;
5944
6009
  const category_transformer = (_this$display_transfo = this.display_transformers) === null || _this$display_transfo === void 0 ? void 0 : _this$display_transfo.categories;
5945
6010
  if (!category_transformer) return response;
6011
+ const incoming_suggestions = response.suggestions;
6012
+ const type_to_transform = "listing";
5946
6013
  // find category suggestions, run thing with them, and then replace them
5947
- const category_suggestions = response.suggestions.filter(suggestion => suggestion.type === "listing");
5948
- const transformed_category_suggestions = await category_transformer({
6014
+ const category_suggestions = incoming_suggestions.filter(suggestion => suggestion.type === type_to_transform);
6015
+ const transformed_suggestions = [...(await category_transformer({
5949
6016
  market: market,
5950
6017
  merchant: merchant,
6018
+ locale: locale,
5951
6019
  data: [...category_suggestions]
5952
- });
5953
- response.suggestions = transformed_category_suggestions;
6020
+ }))];
6021
+ // Then add-back query suggestions at their original indices
6022
+ for (let i = 0; i < incoming_suggestions.length; i++) {
6023
+ const item = incoming_suggestions[i];
6024
+ if (item.type === type_to_transform) continue;
6025
+ transformed_suggestions.splice(i, 0, item);
6026
+ }
6027
+ response.suggestions = transformed_suggestions;
5954
6028
  return response;
5955
6029
  }
5956
- async function $284849364a6ef73a$var$_run_display_transformers_for_rest2(merchant, market, input_data) {
6030
+ async function $284849364a6ef73a$var$_run_display_transformers_for_rest2(merchant, market, locale, input_data) {
5957
6031
  const {
5958
6032
  display_transformers: display_transformers
5959
6033
  } = this;
@@ -5969,25 +6043,24 @@ async function $284849364a6ef73a$var$_run_display_transformers_for_rest2(merchan
5969
6043
  const transformed_displays = await product_transformer({
5970
6044
  merchant: merchant,
5971
6045
  market: market,
6046
+ locale: locale,
5972
6047
  displays: [...displays]
5973
6048
  });
5974
6049
  input_data.displays = transformed_displays;
5975
6050
  }
5976
- if (category_transformer) for (const key of ["breadcrumbs", "quick_links"]) {
5977
- const category_display_array = input_data[key];
5978
- if (!category_display_array) continue;
5979
- const transformed_category_displays = await category_transformer({
5980
- merchant: merchant,
5981
- market: market,
5982
- data: [...category_display_array]
5983
- });
5984
- input_data[key] = transformed_category_displays;
5985
- }
5986
6051
  if (content_search_links !== null && content_search_links !== void 0 && content_search_links.length && content_result_transformer) input_data.content_search_links = await content_result_transformer({
5987
6052
  merchant: merchant,
5988
6053
  market: market,
6054
+ locale: locale,
5989
6055
  data: [...content_search_links]
5990
6056
  });
6057
+ if (input_data.ancestors) return await $f454ce4c74ef4dc0$export$d9792230b7c0203e({
6058
+ input_data_: input_data,
6059
+ category_transformer_: category_transformer,
6060
+ merchant_: merchant,
6061
+ market_: market,
6062
+ locale_: locale
6063
+ });
5991
6064
  return input_data;
5992
6065
  }
5993
6066
  async function $284849364a6ef73a$var$_cached_request2(_ref3) {
@@ -6026,7 +6099,7 @@ async function $284849364a6ef73a$var$_cached_request2(_ref3) {
6026
6099
  let result;
6027
6100
  try {
6028
6101
  const unmodified_result = await api_response.json();
6029
- result = await $284849364a6ef73a$var$_classPrivateMethodGet(this, $284849364a6ef73a$var$_run_display_transformers_for_rest, $284849364a6ef73a$var$_run_display_transformers_for_rest2).call(this, input_req_.merchant, input_req_.market, unmodified_result);
6102
+ result = await $284849364a6ef73a$var$_classPrivateMethodGet(this, $284849364a6ef73a$var$_run_display_transformers_for_rest, $284849364a6ef73a$var$_run_display_transformers_for_rest2).call(this, input_req_.merchant, input_req_.market, input_req_.locale, unmodified_result);
6030
6103
  } catch (e) {
6031
6104
  $8tj43$dwarn("displayTransformer or json decoding failed", e);
6032
6105
  break return_successfully;
@@ -8775,7 +8848,7 @@ function $4b4b262708b516ee$export$f7d2f673fc2f091d(_ref) {
8775
8848
  var _plp_meta;
8776
8849
  return (_plp_meta = plp_meta()) === null || _plp_meta === void 0 ? void 0 : _plp_meta.title;
8777
8850
  });
8778
- const crumb_data_ = $4b4b262708b516ee$var$add_us_to_crumbs(plp_meta, title);
8851
+ const crumb_data_ = $4b4b262708b516ee$var$add_us_to_crumbs(plp_meta);
8779
8852
  const quicklinks_data_ = $8tj43$createMemo(() => {
8780
8853
  var _plp_meta2;
8781
8854
  return (_plp_meta2 = plp_meta()) === null || _plp_meta2 === void 0 ? void 0 : _plp_meta2.quick_links;
@@ -9065,32 +9138,17 @@ function $4b4b262708b516ee$export$f7d2f673fc2f091d(_ref) {
9065
9138
  /**
9066
9139
  * Adds the current page as last breadcrumb to the breadcrumb trail
9067
9140
  */
9068
- function $4b4b262708b516ee$var$add_us_to_crumbs(plp_meta, title) {
9141
+ function $4b4b262708b516ee$var$add_us_to_crumbs(plp_meta) {
9069
9142
  const href_accessor = $8tj43$use_href_accessor();
9070
9143
  return $8tj43$createMemo(() => {
9071
9144
  var _plp_meta3;
9072
9145
  const api_value = (_plp_meta3 = plp_meta()) === null || _plp_meta3 === void 0 ? void 0 : _plp_meta3.breadcrumbs;
9073
9146
  if (!api_value) return api_value;
9074
- return [...api_value, {
9075
- get listing_id() {
9076
- return plp_meta().listing_id;
9077
- },
9078
- get title() {
9079
- return title();
9080
- },
9147
+ return [...api_value, $8tj43$mergeProps1(plp_meta(), {
9081
9148
  get page_url() {
9082
9149
  return href_accessor();
9083
- },
9084
- get slug() {
9085
- return plp_meta().slug;
9086
- },
9087
- get listing_type() {
9088
- return plp_meta().listing_type;
9089
- },
9090
- get external_id() {
9091
- return plp_meta().external_id;
9092
9150
  }
9093
- }];
9151
+ })];
9094
9152
  });
9095
9153
  }
9096
9154
  function $9d3d794b62318ecc$export$477caf01aecaeb2a(options) {
@@ -9781,7 +9839,7 @@ function $dea31647b99a443b$export$d757d54550ebfb3d(_ref) {
9781
9839
  } = _ref;
9782
9840
  const parentTitle = $8tj43$createMemo(() => {
9783
9841
  var _category_suggestion_;
9784
- return (_category_suggestion_ = category_suggestion_().breadcrumbs.at(-1)) === null || _category_suggestion_ === void 0 ? void 0 : _category_suggestion_.title;
9842
+ return (_category_suggestion_ = category_suggestion_().ancestors.at(-1)) === null || _category_suggestion_ === void 0 ? void 0 : _category_suggestion_.title;
9785
9843
  });
9786
9844
  return (() => {
9787
9845
  const _el$ = $8tj43$getNextElement($dea31647b99a443b$var$_tmpl$2),
@@ -10512,7 +10570,7 @@ function $494c9ad553139dbc$export$a146ac6fa8346a25(_ref) {
10512
10570
  currently_showing_suggestions_[1](value => {
10513
10571
  value[0] = $8tj43$createMemo(() => previous_searches_().map(result => ({
10514
10572
  type: (0, $7cd4d275a9f8d600$export$3cf9497e790da491),
10515
- title: result,
10573
+ query: result,
10516
10574
  suggestions_result_id: "history"
10517
10575
  })));
10518
10576
  return value;
@@ -10637,23 +10695,17 @@ function $40dd3f46f55d62ba$export$e872e2339fb04a7f(_ref) {
10637
10695
  submit_query_: submit_query_,
10638
10696
  get_content_results_: get_content_results_
10639
10697
  } = _ref;
10640
- const queries_memo = $8tj43$createMemo(() => suggestion_memo_().filter(_ref2 => {
10641
- let {
10642
- type: type,
10643
- title: title
10644
- } = _ref2;
10645
- return type === (0, $7cd4d275a9f8d600$export$3cf9497e790da491) && !filtered_previous_searches_().includes(title);
10646
- } // don't show the ones we already show from the history
10698
+ const queries_memo = $8tj43$createMemo(() => suggestion_memo_().filter(suggestion => suggestion.type === (0, $7cd4d275a9f8d600$export$3cf9497e790da491) && !filtered_previous_searches_().includes(suggestion.query) // don't show the ones we already show from the history
10647
10699
  ) // + limit to three query suggestions, API sends more sometimes
10648
10700
  .slice(0, 3));
10649
10701
  const not_queries_memo = $8tj43$createMemo(() => {
10650
10702
  // For the section that shows categories and content results
10651
10703
  // We want to limit to 3 items, and we want to show the categories first
10652
10704
  const content_results = get_content_results_() || [];
10653
- const from_suggest_request = include_category_suggestions_ ? suggestion_memo_().filter(_ref3 => {
10705
+ const from_suggest_request = include_category_suggestions_ ? suggestion_memo_().filter(_ref2 => {
10654
10706
  let {
10655
10707
  type: type
10656
- } = _ref3;
10708
+ } = _ref2;
10657
10709
  return type !== (0, $7cd4d275a9f8d600$export$3cf9497e790da491);
10658
10710
  }) : [];
10659
10711
  return [...from_suggest_request.slice(0, content_results.length ? 2 : 3), ...content_results.slice(0, 1)];
@@ -10663,7 +10715,7 @@ function $40dd3f46f55d62ba$export$e872e2339fb04a7f(_ref) {
10663
10715
  const is_query = $8tj43$createMemo(() => input_obj().type === (0, $7cd4d275a9f8d600$export$3cf9497e790da491));
10664
10716
  const href_with_changed_params_accessor = $8tj43$createMemo(() => is_query() ? $e8776b492383c292$export$91c3b6774e8be0f5({
10665
10717
  param_: search_query_url_param_name_,
10666
- value_: $8tj43$createMemo(() => input_obj().title),
10718
+ value_: $8tj43$createMemo(() => input_obj().query),
10667
10719
  url_transformer_: url_transformer_
10668
10720
  }) : undefined);
10669
10721
  const href = $8tj43$createMemo(() => is_query() ? href_with_changed_params_accessor()() : input_obj().page_url);
@@ -10672,10 +10724,10 @@ function $40dd3f46f55d62ba$export$e872e2339fb04a7f(_ref) {
10672
10724
  return ((_read_selected_index_ = read_selected_index_()) === null || _read_selected_index_ === void 0 ? void 0 : _read_selected_index_[0]) === autocomplete_data_index && ((_read_selected_index_2 = read_selected_index_()) === null || _read_selected_index_2 === void 0 ? void 0 : _read_selected_index_2[1]) === index;
10673
10725
  });
10674
10726
  const parent_title_if_exists = $8tj43$createMemo(() => {
10675
- var _item$breadcrumbs$at;
10727
+ var _item$ancestors$at;
10676
10728
  const item = input_obj();
10677
- if (!("breadcrumbs" in item)) return;
10678
- return (_item$breadcrumbs$at = item.breadcrumbs.at(-1)) === null || _item$breadcrumbs$at === void 0 ? void 0 : _item$breadcrumbs$at.title;
10729
+ if (!("ancestors" in item)) return;
10730
+ return (_item$ancestors$at = item.ancestors.at(-1)) === null || _item$ancestors$at === void 0 ? void 0 : _item$ancestors$at.title;
10679
10731
  });
10680
10732
  return (() => {
10681
10733
  const _el$ = $8tj43$getNextElement($40dd3f46f55d62ba$var$_tmpl$);
@@ -10685,8 +10737,9 @@ function $40dd3f46f55d62ba$export$e872e2339fb04a7f(_ref) {
10685
10737
  if (ev.button || ev.metaKey || ev.ctrlKey)
10686
10738
  // not button 0 or cmd/ctrl click
10687
10739
  return;
10740
+ const input = input_obj();
10688
10741
  ev.preventDefault();
10689
- submit_query_(input_obj().title);
10742
+ submit_query_(is_query() ? input.query : input.title);
10690
10743
  return;
10691
10744
  }
10692
10745
  router_.navigate_.go_to_({
@@ -10714,7 +10767,7 @@ function $40dd3f46f55d62ba$export$e872e2339fb04a7f(_ref) {
10714
10767
  }), $8tj43$createComponent((0, $02b6641aa50ce528$export$ba17c5b7e6dda39f), {
10715
10768
  class_: "value line-clamp",
10716
10769
  get whole_text_to_display_() {
10717
- return $8tj43$createMemo(() => input_obj().title);
10770
+ return $8tj43$createMemo(() => input_obj().query);
10718
10771
  },
10719
10772
  searching_for_value_: searching_for_value_
10720
10773
  })] : [$8tj43$memo((() => {
@@ -10845,7 +10898,7 @@ function $40dd3f46f55d62ba$export$e872e2339fb04a7f(_ref) {
10845
10898
  return (() => {
10846
10899
  const mapped_history_results = $8tj43$createMemo(() => filtered_previous_searches_().map(result => ({
10847
10900
  type: (0, $7cd4d275a9f8d600$export$3cf9497e790da491),
10848
- title: result,
10901
+ query: result,
10849
10902
  suggestions_result_id: "history" // worthless to fix typing
10850
10903
  })));
10851
10904
 
@@ -11022,16 +11075,16 @@ function $2ebb1d6ae6763f7a$var$actual_navigation_working_on_fake_data(_ref2) {
11022
11075
  // update text field value if needed
11023
11076
  if ((selected_entry === null || selected_entry === void 0 ? void 0 : selected_entry.type) == "query") {
11024
11077
  const {
11025
- title: title
11078
+ query: query
11026
11079
  } = selected_entry;
11027
11080
  $8tj43$runWithOwner(owner, block_updating_for_one_change);
11028
- set_search_field_value(title);
11081
+ set_search_field_value(query);
11029
11082
  $8tj43$runWithOwner(owner, () => override_on_enter_for_this_entry(e => {
11030
11083
  // Open search query in new tab on cmd+enter
11031
11084
  // 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 ;)
11032
11085
  const url = new URL(location);
11033
11086
  url_transformer_ === null || url_transformer_ === void 0 || url_transformer_(url);
11034
- url.searchParams.set(search_query_param_name_, title);
11087
+ url.searchParams.set(search_query_param_name_, query);
11035
11088
  return $76b6e14a50da4597$export$1efe1013da60d0e4(e, url.href);
11036
11089
  }));
11037
11090
  } else if ((selected_entry === null || selected_entry === void 0 ? void 0 : selected_entry.type) == "listing" || (selected_entry === null || selected_entry === void 0 ? void 0 : selected_entry.type) === "content") $8tj43$runWithOwner(owner, () => override_on_enter_for_this_entry(e => {