@depict-ai/ui 2.0.7 → 2.0.9

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
@@ -1,11 +1,11 @@
1
- import { add_to_version_info as $9HbP8$add_to_version_info, catchify as $9HbP8$catchify, slider_fractional_factory as $9HbP8$slider_fractional_factory, make_random_classname as $9HbP8$make_random_classname, n_col_styling_with_dist as $9HbP8$n_col_styling_with_dist, layout_get_visible_recs_without_partial_rows as $9HbP8$layout_get_visible_recs_without_partial_rows, layout_get_total_rec_amount_for_row as $9HbP8$layout_get_total_rec_amount_for_row, layout_media_query_header as $9HbP8$layout_media_query_header, report as $9HbP8$report, Amazing_Slider as $9HbP8$Amazing_Slider, slider_snap_css as $9HbP8$slider_snap_css, slider_fading_factory as $9HbP8$slider_fading_factory, observer as $9HbP8$observer, is_safari as $9HbP8$is_safari, useExpandingContainer as $9HbP8$useExpandingContainer, standard_price_format as $9HbP8$standard_price_format, dlog as $9HbP8$dlog, hex_to_rgb as $9HbP8$hex_to_rgb, relative_luminance_from_rgb as $9HbP8$relative_luminance_from_rgb, javascript_media_query as $9HbP8$javascript_media_query, fetch_recs as $9HbP8$fetch_recs, snakeCasifyObject as $9HbP8$snakeCasifyObject, instant_exec_on_suspect_history_change as $9HbP8$instant_exec_on_suspect_history_change, base_url as $9HbP8$base_url, get_depict_id as $9HbP8$get_depict_id, get_user_id as $9HbP8$get_user_id, get_session_id as $9HbP8$get_session_id, sort_obj as $9HbP8$sort_obj, fetch_retry as $9HbP8$fetch_retry, add_version_query_params as $9HbP8$add_version_query_params, dwarn as $9HbP8$dwarn, make_url_with_query_params as $9HbP8$make_url_with_query_params, edit_current_page_meta_tags as $9HbP8$edit_current_page_meta_tags, use_href_accessor as $9HbP8$use_href_accessor, base64_encode_unicode as $9HbP8$base64_encode_unicode, base64_decode_unicode as $9HbP8$base64_decode_unicode, queueMacroTask as $9HbP8$queueMacroTask, is_debug as $9HbP8$is_debug, make_asyncIterable_exiter as $9HbP8$make_asyncIterable_exiter, href_change_ipns as $9HbP8$href_change_ipns, ContainedImage as $9HbP8$ContainedImage, buildThresholdList as $9HbP8$buildThresholdList, deparallelize_no_drop as $9HbP8$deparallelize_no_drop, ListenableSet as $9HbP8$ListenableSet, insert_surfaces as $9HbP8$insert_surfaces } from "@depict-ai/utilishared/latest";
2
- import { createSignal as $9HbP8$createSignal, onCleanup as $9HbP8$onCleanup, createMemo as $9HbP8$createMemo, createResource as $9HbP8$createResource, Suspense as $9HbP8$Suspense, Show as $9HbP8$Show, createRenderEffect as $9HbP8$createRenderEffect, createRoot as $9HbP8$createRoot, For as $9HbP8$For, getOwner as $9HbP8$getOwner, runWithOwner as $9HbP8$runWithOwner, createEffect as $9HbP8$createEffect, untrack as $9HbP8$untrack, createUniqueId as $9HbP8$createUniqueId, createComputed as $9HbP8$createComputed, ErrorBoundary as $9HbP8$ErrorBoundary, Index as $9HbP8$Index, on as $9HbP8$on, batch as $9HbP8$batch, createReaction as $9HbP8$createReaction } from "solid-js";
1
+ import { add_to_version_info as $9HbP8$add_to_version_info, catchify as $9HbP8$catchify, slider_fractional_factory as $9HbP8$slider_fractional_factory, camelCasifyObject as $9HbP8$camelCasifyObject, make_random_classname as $9HbP8$make_random_classname, n_col_styling_with_dist as $9HbP8$n_col_styling_with_dist, layout_get_visible_recs_without_partial_rows as $9HbP8$layout_get_visible_recs_without_partial_rows, layout_get_total_rec_amount_for_row as $9HbP8$layout_get_total_rec_amount_for_row, layout_media_query_header as $9HbP8$layout_media_query_header, report as $9HbP8$report, Amazing_Slider as $9HbP8$Amazing_Slider, slider_snap_css as $9HbP8$slider_snap_css, slider_fading_factory as $9HbP8$slider_fading_factory, observer as $9HbP8$observer, is_safari as $9HbP8$is_safari, useExpandingContainer as $9HbP8$useExpandingContainer, standard_price_format as $9HbP8$standard_price_format, dlog as $9HbP8$dlog, hex_to_rgb as $9HbP8$hex_to_rgb, relative_luminance_from_rgb as $9HbP8$relative_luminance_from_rgb, javascript_media_query as $9HbP8$javascript_media_query, fetch_recs as $9HbP8$fetch_recs, snakeCasifyObject as $9HbP8$snakeCasifyObject, instant_exec_on_suspect_history_change as $9HbP8$instant_exec_on_suspect_history_change, base_url as $9HbP8$base_url, get_depict_id as $9HbP8$get_depict_id, get_user_id as $9HbP8$get_user_id, get_session_id as $9HbP8$get_session_id, sort_obj as $9HbP8$sort_obj, fetch_retry as $9HbP8$fetch_retry, add_version_query_params as $9HbP8$add_version_query_params, dwarn as $9HbP8$dwarn, make_url_with_query_params as $9HbP8$make_url_with_query_params, edit_current_page_meta_tags as $9HbP8$edit_current_page_meta_tags, use_href_accessor as $9HbP8$use_href_accessor, base64_encode_unicode as $9HbP8$base64_encode_unicode, base64_decode_unicode as $9HbP8$base64_decode_unicode, queueMacroTask as $9HbP8$queueMacroTask, is_debug as $9HbP8$is_debug, make_asyncIterable_exiter as $9HbP8$make_asyncIterable_exiter, href_change_ipns as $9HbP8$href_change_ipns, ContainedImage as $9HbP8$ContainedImage, buildThresholdList as $9HbP8$buildThresholdList, deparallelize_no_drop as $9HbP8$deparallelize_no_drop, ListenableSet as $9HbP8$ListenableSet, insert_surfaces as $9HbP8$insert_surfaces } from "@depict-ai/utilishared/latest";
2
+ import { createSignal as $9HbP8$createSignal, onCleanup as $9HbP8$onCleanup, createMemo as $9HbP8$createMemo, createResource as $9HbP8$createResource, Suspense as $9HbP8$Suspense, Show as $9HbP8$Show, createRenderEffect as $9HbP8$createRenderEffect, createRoot as $9HbP8$createRoot, For as $9HbP8$For, getOwner as $9HbP8$getOwner, runWithOwner as $9HbP8$runWithOwner, createEffect as $9HbP8$createEffect, createUniqueId as $9HbP8$createUniqueId, untrack as $9HbP8$untrack, createComputed as $9HbP8$createComputed, ErrorBoundary as $9HbP8$ErrorBoundary, Index as $9HbP8$Index, on as $9HbP8$on, batch as $9HbP8$batch, createReaction as $9HbP8$createReaction } from "solid-js";
3
3
  import { template as $9HbP8$template, getNextElement as $9HbP8$getNextElement, insert as $9HbP8$insert, createComponent as $9HbP8$createComponent, mergeProps as $9HbP8$mergeProps, isServer as $9HbP8$isServer, spread as $9HbP8$spread, runHydrationEvents as $9HbP8$runHydrationEvents, addEventListener as $9HbP8$addEventListener, className as $9HbP8$className, memo as $9HbP8$memo, delegateEvents as $9HbP8$delegateEvents, effect as $9HbP8$effect, classList as $9HbP8$classList, setAttribute as $9HbP8$setAttribute, getNextMarker as $9HbP8$getNextMarker, style as $9HbP8$style, Dynamic as $9HbP8$Dynamic, use as $9HbP8$use } from "solid-js/web";
4
4
 
5
5
  /*! Depict.ai search and product listing SDK */
6
6
  import { register_es_version } from "../multi_import_deduplicator.mjs";
7
7
  register_es_version("ui", "latest");
8
- const $ec291e0010116877$export$83d89fbfd8236492 = "2.0.7";
8
+ const $ec291e0010116877$export$83d89fbfd8236492 = "2.0.9";
9
9
 
10
10
  /** @jsxImportSource solid-js */
11
11
 
@@ -57,7 +57,7 @@ const $b5cccc8ee7d24677$export$6daf8749b65a1b77 = cols_at_size => {
57
57
  return $b5cccc8ee7d24677$var$transform_elements(sorted_cols_at_size);
58
58
  };
59
59
  function $a458486f22b22f63$export$a2cc176055f8f08() {
60
- const text = "Please try setting `colsAtSize` on the `SearchPage`/`CategoryPage` components to change the grid before setting it with CSS. If you do with CSS, set `ColsAtSize` to an empty array to ensure no declarations created by the SDK leak through.";
60
+ const text = "Please try setting `columnsAtSize` on the `SearchPage`/`CategoryPage` components to change the grid before setting it with CSS. If you do with CSS, set `ColsAtSize` to an empty array to ensure no declarations created by the SDK leak through.";
61
61
  return (0, $9HbP8$isServer) ? {
62
62
  t: `<!-- ${text} -->`
63
63
  } : document.createComment(text);
@@ -182,6 +182,7 @@ function $29ec7cddbe1d3484$export$7f8bd308237ab5a5(get_displays_) {
182
182
  });
183
183
  return displays_by_key_;
184
184
  }
185
+ const $29ec7cddbe1d3484$var$result_ids = ["search_result_id", "product_listing_result_id", "recommendation_id"];
185
186
  function $29ec7cddbe1d3484$export$43f0fb951fcb0c54({
186
187
  displays_by_key_: displays_by_key_,
187
188
  merchant_: merchant_,
@@ -195,17 +196,24 @@ function $29ec7cddbe1d3484$export$43f0fb951fcb0c54({
195
196
  },
196
197
  children: (product_id, index) => {
197
198
  const owner = $9HbP8$getOwner();
198
- const display_accessor = $9HbP8$createMemo(() => displays_by_key_().get(product_id));
199
- const [product_card_resource] = $9HbP8$createResource(display_accessor,
200
- // re-render when the reference to the display object changes
201
- // this should only be the case when the merchant or market changes and the new request has completed
202
- display => {
199
+ const display_accessor = $9HbP8$createMemo(prev => {
200
+ const new_display = displays_by_key_().get(product_id);
201
+ if (prev && $29ec7cddbe1d3484$var$deep_equal(prev, new_display))
202
+ // If displays are identical, they haven't changed due to merchant/market changing OR we made a new query and the displays are the same. Return the old display (same object reference) to avoid re-rendering.
203
+ // This doesn't work if people mutate the displays from within the template but we hope they don't
204
+ // (We can't know if the display changing is due to merchant/market changing or a new query otherwise and don't want to run into https://gitlab.com/depict-ai/depict.ai/-/merge_requests/6890/diffs)
205
+ return prev;
206
+ return new_display;
207
+ });
208
+ const [product_card_resource] = $9HbP8$createResource(() => [merchant_(), market_(), display_accessor()],
209
+ // re-render when the reference to the display object changes or the merchant or market changes
210
+ // (We don't want to re-render if nothing has changed)
211
+ ([merchant, market, display]) => {
203
212
  // get display in the function that re-runs when merchant or market have changed, since the display may have changed but product_id not
204
213
  return product_card_template_(display, {
205
214
  set_on_index_change: fn => $9HbP8$runWithOwner(owner, () => $9HbP8$createEffect(() => fn(index()))),
206
- merchant: $9HbP8$untrack(merchant_),
207
- // this means that the merchant and market provided to the template is wrong while we do another fetch, but I don't see how anyone would need to know the correct market there
208
- market: $9HbP8$untrack(market_) // recommendation_grid can provide a sneaky undefined here just FYI
215
+ merchant: merchant,
216
+ market: market // recommendation_grid can provide a sneaky undefined here just FYI
209
217
  });
210
218
  });
211
219
 
@@ -220,15 +228,13 @@ function $29ec7cddbe1d3484$export$43f0fb951fcb0c54({
220
228
  elements.push(element);
221
229
  // Add tracking ids
222
230
  if (!(element instanceof HTMLElement)) continue; // Apparently only HTMLElements have dataset
223
- const {
224
- dataset: dataset
225
- } = element;
226
- const {
227
- search_result_id: search_result_id,
228
- product_listing_result_id: product_listing_result_id,
229
- recommendation_id: recommendation_id
230
- } = display;
231
- if (search_result_id) dataset.searchResultId = search_result_id;else if (product_listing_result_id) dataset.productListingResultId = product_listing_result_id;else if (recommendation_id) dataset.recommendationId = recommendation_id;
231
+ for (let i = 0; i < $29ec7cddbe1d3484$var$result_ids.length; i++) {
232
+ const id = $29ec7cddbe1d3484$var$result_ids[i];
233
+ const value = display[id];
234
+ if (value) Object.assign(element.dataset, $9HbP8$camelCasifyObject({
235
+ [id]: value
236
+ }));
237
+ }
232
238
  }
233
239
  do_per_elements_?.(elements, index);
234
240
  });
@@ -236,6 +242,23 @@ function $29ec7cddbe1d3484$export$43f0fb951fcb0c54({
236
242
  }
237
243
  });
238
244
  }
245
+ // Source: https://dmitripavlutin.com/how-to-compare-objects-in-javascript/
246
+ function $29ec7cddbe1d3484$var$deep_equal(object1, object2) {
247
+ const keys1 = Object.keys(object1);
248
+ const keys2 = Object.keys(object2);
249
+ if (keys1.length !== keys2.length) return false;
250
+ for (const key of keys1) {
251
+ if ($29ec7cddbe1d3484$var$result_ids.includes(key)) continue; // ignore result ids that change per response
252
+ const val1 = object1[key];
253
+ const val2 = object2[key];
254
+ const areObjects = $29ec7cddbe1d3484$var$is_object(val1) && $29ec7cddbe1d3484$var$is_object(val2);
255
+ if (areObjects && !$29ec7cddbe1d3484$var$deep_equal(val1, val2) || !areObjects && val1 !== val2) return false;
256
+ }
257
+ return true;
258
+ }
259
+ function $29ec7cddbe1d3484$var$is_object(object) {
260
+ return object != null && typeof object === "object";
261
+ }
239
262
 
240
263
  // Errors caused by SDK consuming code interfacing with the SDK, not the SDK itself or other Depict packages
241
264
  class $4fd48cb976bf1789$export$e1d52e4f0c7557a1 extends Error {}
@@ -544,7 +567,13 @@ function $16b52438165aafe2$export$23fca46f3143581f(component, error_message) {
544
567
  return component_in_error_boundary(elements => {
545
568
  const have_multiple = Array.isArray(elements);
546
569
  if (have_multiple ? !elements?.length : !elements) return;
547
- (0, $9HbP8$observer).onremoved(have_multiple ? elements[0] : elements, dispose);
570
+ (0, $9HbP8$observer).onremoved(have_multiple ? elements[0] : elements, ({
571
+ element: element
572
+ }) => {
573
+ if (document.documentElement.contains(element)) return; // If element has instantly been re-inserted, don't dispose
574
+ // See https://depictaiworkspace.slack.com/archives/C050GHEPBTR/p1695809102791259?thread_ts=1695106805.459729&cid=C050GHEPBTR
575
+ dispose();
576
+ });
548
577
  });
549
578
  });else
550
579
  // we're already in a root so cleanups are handled
@@ -592,51 +621,52 @@ function $3da8afe3ed57cf34$export$7da560f849543dff({
592
621
  }) {
593
622
  const is_showing_something = $9HbP8$createMemo(() => recommendations_resource_.loading || recommendations_resource_()?.length);
594
623
  const num_placeholders_ = () => 20;
624
+ const elements = (() => {
625
+ const _el$ = $9HbP8$getNextElement($3da8afe3ed57cf34$var$_tmpl$),
626
+ _el$2 = _el$.firstChild,
627
+ [_el$3, _co$] = $9HbP8$getNextMarker(_el$2.nextSibling),
628
+ _el$4 = _el$3.nextSibling,
629
+ [_el$5, _co$2] = $9HbP8$getNextMarker(_el$4.nextSibling);
630
+ $9HbP8$insert(_el$, (0, $a458486f22b22f63$export$a2cc176055f8f08), _el$3, _co$);
631
+ $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps({
632
+ get rows() {
633
+ return rows_object_();
634
+ },
635
+ layout: "grid",
636
+ element_attributes: {
637
+ class: "cards"
638
+ }
639
+ }, layout_options_, {
640
+ get children() {
641
+ return $9HbP8$createComponent((0, $9HbP8$Suspense), {
642
+ get fallback() {
643
+ return $6e41f1fde994db72$export$f33414a4df0afd3f({
644
+ num_placeholders_: num_placeholders_,
645
+ product_card_template_: product_card_template_
646
+ });
647
+ },
648
+ get children() {
649
+ return (() => {
650
+ // IIFE to make sure we access both the recommendations_resource and the resources containing the product card rendering results themselves within the Suspense boundary
651
+ const displays_by_key_ = $29ec7cddbe1d3484$export$7f8bd308237ab5a5($9HbP8$createMemo(() => recommendations_resource_() || []));
652
+ return $29ec7cddbe1d3484$export$43f0fb951fcb0c54({
653
+ displays_by_key_: displays_by_key_,
654
+ merchant_: merchant_,
655
+ market_: market_,
656
+ product_card_template_: product_card_template_
657
+ });
658
+ })();
659
+ }
660
+ });
661
+ }
662
+ })), _el$5, _co$2);
663
+ return _el$;
664
+ })();
595
665
  return $9HbP8$createComponent((0, $9HbP8$Show), {
596
666
  get when() {
597
667
  return is_showing_something();
598
668
  },
599
- get children() {
600
- const _el$ = $9HbP8$getNextElement($3da8afe3ed57cf34$var$_tmpl$),
601
- _el$2 = _el$.firstChild,
602
- [_el$3, _co$] = $9HbP8$getNextMarker(_el$2.nextSibling),
603
- _el$4 = _el$3.nextSibling,
604
- [_el$5, _co$2] = $9HbP8$getNextMarker(_el$4.nextSibling);
605
- $9HbP8$insert(_el$, (0, $a458486f22b22f63$export$a2cc176055f8f08), _el$3, _co$);
606
- $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps({
607
- get rows() {
608
- return rows_object_();
609
- },
610
- layout: "grid",
611
- element_attributes: {
612
- class: "cards"
613
- }
614
- }, layout_options_, {
615
- get children() {
616
- return $9HbP8$createComponent((0, $9HbP8$Suspense), {
617
- get fallback() {
618
- return $6e41f1fde994db72$export$f33414a4df0afd3f({
619
- num_placeholders_: num_placeholders_,
620
- product_card_template_: product_card_template_
621
- });
622
- },
623
- get children() {
624
- return (() => {
625
- // IIFE to make sure we access both the recommendations_resource and the resources containing the product card rendering results themselves within the Suspense boundary
626
- const displays_by_key_ = $29ec7cddbe1d3484$export$7f8bd308237ab5a5($9HbP8$createMemo(() => recommendations_resource_() || []));
627
- return $29ec7cddbe1d3484$export$43f0fb951fcb0c54({
628
- displays_by_key_: displays_by_key_,
629
- merchant_: merchant_,
630
- market_: market_,
631
- product_card_template_: product_card_template_
632
- });
633
- })();
634
- }
635
- });
636
- }
637
- })), _el$5, _co$2);
638
- return _el$;
639
- }
669
+ children: elements
640
670
  });
641
671
  }
642
672
  const $9ea5383493360761$var$_tmpl$ = /*#__PURE__*/$9HbP8$template(`<button class="show-more major" type="button"></button>`, 2),
@@ -4242,7 +4272,7 @@ function $0449e7d49398c077$export$a1fd619a4743ca08({
4242
4272
  const [get_extra_displays, set_extra_displays_] = $9HbP8$createSignal([], {
4243
4273
  equals: false
4244
4274
  });
4245
- const displays_by_key_ = $29ec7cddbe1d3484$export$7f8bd308237ab5a5($9HbP8$createMemo(() => [...plp_results_().displays, ...get_extra_displays()]));
4275
+ const displays_by_key_ = $29ec7cddbe1d3484$export$7f8bd308237ab5a5($9HbP8$createMemo(() => [...(plp_results_()?.displays || []), ...get_extra_displays()]));
4246
4276
  const percentage_in_view_ = $0e0b96a8dc1ad492$export$63dd0350f8559dda({
4247
4277
  get_last_result_in_viewport_: get_last_result_in_viewport_,
4248
4278
  displays_by_key_: displays_by_key_,
@@ -4361,18 +4391,18 @@ function $2d25e42846eac370$export$3925f87b1545cfc6({
4361
4391
  layout_options_: layout_options_,
4362
4392
  sort_or_filter_open_: sort_or_filter_open_
4363
4393
  });
4364
- $9HbP8$createComputed(() => {
4365
- if (!is_loading_()) return;
4366
- set_should_have_placeholders_rendered(true);
4367
- set_suspense_is_blocked(false);
4368
- is_just_after_plp_results_update = true;
4369
- });
4370
4394
  const block_suspense_if_needed = () => {
4371
4395
  if (!is_just_after_plp_results_update) return;
4372
4396
  is_just_after_plp_results_update = false;
4373
4397
  fallback_is_alive = false;
4374
4398
  set_suspense_is_blocked(true);
4375
4399
  };
4400
+ $9HbP8$createComputed(() => {
4401
+ if (!is_loading_()) return;
4402
+ set_should_have_placeholders_rendered(true);
4403
+ set_suspense_is_blocked(false);
4404
+ is_just_after_plp_results_update = true;
4405
+ });
4376
4406
  $9HbP8$createEffect($9HbP8$on(plp_results_, () => {
4377
4407
  if (!fallback_is_alive) {
4378
4408
  // if all product card rendering functions after the initial rendering are synchronous the suspense boundary will never go into the fallback, so we don't know when they have finished rendering, and we can't block the suspense. Therefore, we're just doing it with this effect
@@ -4382,6 +4412,48 @@ function $2d25e42846eac370$export$3925f87b1545cfc6({
4382
4412
  }, {
4383
4413
  defer: true
4384
4414
  }));
4415
+ /*
4416
+ This suspense ensures that if someone has async templates, we still show placeholders until the product cards actually have finished rendering (automagically since they're createResource's)
4417
+ We're creating it outside the <Show> so that we can benefit from <For>'s optimisation between changing results
4418
+ (For the whole idea of the displays being cached to work we can't tear down and re-run ProductCards for every new result.
4419
+ We have to keep ProductCards alive, but hidden, and feed them new data as soon as we had it)
4420
+ */
4421
+ const product_cards_when_data = $9HbP8$createComponent((0, $9HbP8$Suspense), {
4422
+ get fallback() {
4423
+ return (() => {
4424
+ fallback_is_alive = true;
4425
+ $9HbP8$onCleanup(block_suspense_if_needed); // Block suspense after initial run every time after we fetch
4426
+ return $9HbP8$createMemo(() => {
4427
+ // We need to be able to block the suspense since when async product cards are *rendering* we want to show the placeholders on initial load but not when loading more
4428
+ // In future we could have individual suspense's for each product card, but that's too much for now
4429
+ if (get_suspense_is_blocked()) return suspense_contents;
4430
+ set_should_have_placeholders_rendered(true); // just in case
4431
+ $9HbP8$onCleanup(() => set_should_have_placeholders_rendered(false));
4432
+ return rendered_placeholders; // I lifted the placeholders into the memo since we don't want to re-render them when switching from <Show> to <Suspense>
4433
+ });
4434
+ })();
4435
+ },
4436
+
4437
+ get children() {
4438
+ return (() => {
4439
+ suspense_contents = $0449e7d49398c077$export$a1fd619a4743ca08({
4440
+ product_card_template_: product_card_template_,
4441
+ plp_results_: plp_results_,
4442
+ last_result_in_viewport_: last_result_in_viewport_,
4443
+ first_result_in_viewport_: first_result_in_viewport_,
4444
+ market_: market_,
4445
+ merchant_: merchant_,
4446
+ all_products_loaded_: all_products_loaded_,
4447
+ min_products_to_fetch_: min_products_to_fetch_,
4448
+ query_base_: query_base_,
4449
+ depict_api_: depict_api_,
4450
+ is_loading_: is_loading_
4451
+ });
4452
+ $9HbP8$onCleanup(() => suspense_contents = undefined);
4453
+ return suspense_contents;
4454
+ })();
4455
+ }
4456
+ });
4385
4457
  return [$9HbP8$memo((0, $a458486f22b22f63$export$a2cc176055f8f08)), $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), {
4386
4458
  get cols_at_size() {
4387
4459
  return modified_cols_at_size();
@@ -4405,44 +4477,7 @@ function $2d25e42846eac370$export$3925f87b1545cfc6({
4405
4477
  get fallback() {
4406
4478
  return rendered_placeholders();
4407
4479
  },
4408
- get children() {
4409
- return $9HbP8$createComponent((0, $9HbP8$Suspense), {
4410
- get fallback() {
4411
- return (() => {
4412
- fallback_is_alive = true;
4413
- $9HbP8$onCleanup(block_suspense_if_needed); // Block suspense after initial run every time after we fetch
4414
- return $9HbP8$createMemo(() => {
4415
- // We need to be able to block the suspense since when async product cards are *rendering* we want to show the placeholders on initial load but not when loading more
4416
- // In future we could have individual suspense's for each product card, but that's too much for now
4417
- if (get_suspense_is_blocked()) return suspense_contents;
4418
- set_should_have_placeholders_rendered(true); // just in case
4419
- $9HbP8$onCleanup(() => set_should_have_placeholders_rendered(false));
4420
- return rendered_placeholders; // I lifted the placeholders into the memo since we don't want to re-render them when switching from <Show> to <Suspense>
4421
- });
4422
- })();
4423
- },
4424
-
4425
- get children() {
4426
- return (() => {
4427
- suspense_contents = $0449e7d49398c077$export$a1fd619a4743ca08({
4428
- product_card_template_: product_card_template_,
4429
- plp_results_: plp_results_,
4430
- last_result_in_viewport_: last_result_in_viewport_,
4431
- first_result_in_viewport_: first_result_in_viewport_,
4432
- market_: market_,
4433
- merchant_: merchant_,
4434
- all_products_loaded_: all_products_loaded_,
4435
- min_products_to_fetch_: min_products_to_fetch_,
4436
- query_base_: query_base_,
4437
- depict_api_: depict_api_,
4438
- is_loading_: is_loading_
4439
- });
4440
- $9HbP8$onCleanup(() => suspense_contents = undefined);
4441
- return suspense_contents;
4442
- })();
4443
- }
4444
- });
4445
- }
4480
+ children: product_cards_when_data
4446
4481
  });
4447
4482
  }
4448
4483
  })];
@@ -7451,58 +7486,61 @@ function $172e1b898d457050$export$7de92c4c2205ebf3({
7451
7486
  product_card_template_: product_card_template_,
7452
7487
  showing_recommendation_rows_: showing_recommendation_rows_,
7453
7488
  view_more_button_ = true,
7454
- layout_options_: layout_options_
7489
+ layout_options_: layout_options_,
7490
+ all_products_loaded_: all_products_loaded_
7455
7491
  }) {
7456
7492
  const [get_showing_recommendation_rows] = showing_recommendation_rows_; // We reset this in after_submit in search.tsx FYI
7457
7493
  const rows_object = view_more_button_ ? $172e1b898d457050$var$make_state_saved_rows(showing_recommendation_rows_, i18n_) : "all";
7458
7494
  const [recommendations_resource] = $9HbP8$createResource(search_query_base_, query => depict_api_.get_recommended(query).then(r => r.displays));
7459
7495
  const is_showing_something = $9HbP8$createMemo(() => recommendations_resource.loading || recommendations_resource()?.length);
7460
7496
  const num_placeholders_ = $9HbP8$createMemo(() => (0, $7747fe1a8c5652e3$export$6c9030e511152266) + get_showing_recommendation_rows() * Math.max(...layout_options_().cols_at_size.map(([per_column]) => per_column)));
7497
+ // Don't tear down elements every time one updates the page - don't put them within <Show>
7498
+ const elements = (() => {
7499
+ const _el$ = $9HbP8$getNextElement($172e1b898d457050$var$_tmpl$),
7500
+ _el$2 = _el$.firstChild,
7501
+ _el$3 = _el$2.nextSibling,
7502
+ [_el$4, _co$] = $9HbP8$getNextMarker(_el$3.nextSibling),
7503
+ _el$5 = _el$4.nextSibling,
7504
+ [_el$6, _co$2] = $9HbP8$getNextMarker(_el$5.nextSibling);
7505
+ $9HbP8$insert(_el$2, () => i18n_.search_recs_title_());
7506
+ $9HbP8$insert(_el$, (0, $a458486f22b22f63$export$a2cc176055f8f08), _el$4, _co$);
7507
+ $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps({
7508
+ rows: rows_object,
7509
+ layout: "grid",
7510
+ element_attributes: {
7511
+ class: "cards"
7512
+ }
7513
+ }, layout_options_, {
7514
+ get children() {
7515
+ return $9HbP8$createComponent((0, $9HbP8$Suspense), {
7516
+ get fallback() {
7517
+ return $6e41f1fde994db72$export$f33414a4df0afd3f({
7518
+ num_placeholders_: num_placeholders_,
7519
+ product_card_template_: product_card_template_
7520
+ });
7521
+ },
7522
+ get children() {
7523
+ return (() => {
7524
+ // IIFE to make sure we access both the recommendations_resource and the resources containing the product card rendering results themselves within the Suspense boundary
7525
+ const displays_by_key_ = $29ec7cddbe1d3484$export$7f8bd308237ab5a5($9HbP8$createMemo(() => recommendations_resource() || []));
7526
+ return $29ec7cddbe1d3484$export$43f0fb951fcb0c54({
7527
+ displays_by_key_: displays_by_key_,
7528
+ merchant_: $9HbP8$createMemo(() => search_query_base_().tenant),
7529
+ market_: $9HbP8$createMemo(() => search_query_base_().market),
7530
+ product_card_template_: product_card_template_
7531
+ });
7532
+ })();
7533
+ }
7534
+ });
7535
+ }
7536
+ })), _el$6, _co$2);
7537
+ return _el$;
7538
+ })();
7461
7539
  return $9HbP8$createComponent((0, $9HbP8$Show), {
7462
7540
  get when() {
7463
- return is_showing_something();
7541
+ return $9HbP8$memo(() => !!is_showing_something())() && all_products_loaded_();
7464
7542
  },
7465
- get children() {
7466
- const _el$ = $9HbP8$getNextElement($172e1b898d457050$var$_tmpl$),
7467
- _el$2 = _el$.firstChild,
7468
- _el$3 = _el$2.nextSibling,
7469
- [_el$4, _co$] = $9HbP8$getNextMarker(_el$3.nextSibling),
7470
- _el$5 = _el$4.nextSibling,
7471
- [_el$6, _co$2] = $9HbP8$getNextMarker(_el$5.nextSibling);
7472
- $9HbP8$insert(_el$2, () => i18n_.search_recs_title_());
7473
- $9HbP8$insert(_el$, (0, $a458486f22b22f63$export$a2cc176055f8f08), _el$4, _co$);
7474
- $9HbP8$insert(_el$, $9HbP8$createComponent((0, $c8d5ff4524619fcd$export$d21e32dfedac04be), $9HbP8$mergeProps({
7475
- rows: rows_object,
7476
- layout: "grid",
7477
- element_attributes: {
7478
- class: "cards"
7479
- }
7480
- }, layout_options_, {
7481
- get children() {
7482
- return $9HbP8$createComponent((0, $9HbP8$Suspense), {
7483
- get fallback() {
7484
- return $6e41f1fde994db72$export$f33414a4df0afd3f({
7485
- num_placeholders_: num_placeholders_,
7486
- product_card_template_: product_card_template_
7487
- });
7488
- },
7489
- get children() {
7490
- return (() => {
7491
- // IIFE to make sure we access both the recommendations_resource and the resources containing the product card rendering results themselves within the Suspense boundary
7492
- const displays_by_key_ = $29ec7cddbe1d3484$export$7f8bd308237ab5a5($9HbP8$createMemo(() => recommendations_resource() || []));
7493
- return $29ec7cddbe1d3484$export$43f0fb951fcb0c54({
7494
- displays_by_key_: displays_by_key_,
7495
- merchant_: $9HbP8$createMemo(() => search_query_base_().tenant),
7496
- market_: $9HbP8$createMemo(() => search_query_base_().market),
7497
- product_card_template_: product_card_template_
7498
- });
7499
- })();
7500
- }
7501
- });
7502
- }
7503
- })), _el$6, _co$2);
7504
- return _el$;
7505
- }
7543
+ children: elements
7506
7544
  });
7507
7545
  }
7508
7546
  function $172e1b898d457050$var$make_state_saved_rows([get_showing_recommendation_rows, set_showing_recommendation_rows], i18n_) {
@@ -9937,9 +9975,7 @@ function $7097477c78a89208$export$a54ec244c8863715({
9937
9975
  }
9938
9976
  }), _el$19, _co$8);
9939
9977
  $9HbP8$insert(_el$7, $9HbP8$createComponent((0, $9HbP8$Show), {
9940
- get when() {
9941
- return get_all_products_loaded() && !disable_search_recommendations_;
9942
- },
9978
+ when: !disable_search_recommendations_,
9943
9979
  keyed: false,
9944
9980
  get children() {
9945
9981
  return $9HbP8$createComponent((0, $b7436a6d1fd64e3b$export$b69d0d92862de18b), {
@@ -9955,7 +9991,8 @@ function $7097477c78a89208$export$a54ec244c8863715({
9955
9991
  },
9956
9992
  showing_recommendation_rows_: showing_recommendation_rows_,
9957
9993
  view_more_button_: search_recs_view_more_,
9958
- product_card_template_: product_card_template_
9994
+ product_card_template_: product_card_template_,
9995
+ all_products_loaded_: get_all_products_loaded
9959
9996
  });
9960
9997
  }
9961
9998
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depict-ai/ui",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
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",