@depict-ai/ui 2.0.26 → 2.1.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.
@@ -1,6 +1,7 @@
1
1
  var $5vyXB$depictaiutilishared = require("@depict-ai/utilishared/latest");
2
2
  var $5vyXB$solidjsweb = require("solid-js/web");
3
3
  var $5vyXB$solidjs = require("solid-js");
4
+ var $5vyXB$solidjsstore = require("solid-js/store");
4
5
  require("../../multi_import_deduplicator.cjs").register_es_version("ui", "latest");
5
6
  function $parcel$export(e, n, v, s) {
6
7
  Object.defineProperty(e, n, {
@@ -69,7 +70,7 @@ $parcel$export(module.exports, "defaultColsAtSize", () => $a3280f0aad997933$expo
69
70
  $parcel$export(module.exports, "defaultCategoryTitlePlugin", () => $a3280f0aad997933$export$7bf543b9d9be2c22);
70
71
  $parcel$export(module.exports, "version", () => $b757f75811f3261f$export$83d89fbfd8236492);
71
72
  /*! Depict.ai search and product listing SDK */
72
- const $b757f75811f3261f$export$83d89fbfd8236492 = "2.0.26";
73
+ const $b757f75811f3261f$export$83d89fbfd8236492 = "2.1.0";
73
74
  const $1ab22f2cd39b3061$var$fallback_operator = "in";
74
75
  const $1ab22f2cd39b3061$var$fallback_token = "";
75
76
  const $1ab22f2cd39b3061$var$legacy_filter_prefix = "filter_";
@@ -453,7 +454,7 @@ const $4e04be41243c3d80$export$6daf8749b65a1b77 = cols_at_size => {
453
454
  return $4e04be41243c3d80$var$transform_elements(sorted_cols_at_size);
454
455
  };
455
456
  function $fc23d7668ae0011d$export$a2cc176055f8f08() {
456
- 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 `columnsAtSize` to an empty array to ensure no declarations created by the SDK leak through.";
457
+ const text = "Please try setting `columnsAtSize`/`gridSpacing` on the `SearchPage`/`CategoryPage` components to change the grid before setting it with CSS. If you do with CSS, set `columnsAtSize` to an empty array to ensure no declarations created by the SDK leak through.";
457
458
  return (0, $5vyXB$solidjsweb.isServer) ? {
458
459
  t: `<!-- ${text} -->`
459
460
  } : document.createComment(text);
@@ -474,12 +475,13 @@ let $0caf87eaa19079da$var$cached_placeholder_element;
474
475
  let $0caf87eaa19079da$var$rendering_cached_placeholder_element;
475
476
  function $0caf87eaa19079da$export$f33414a4df0afd3f({
476
477
  product_card_template_: product_card_template_,
477
- num_placeholders_: num_placeholders_
478
+ num_placeholders_: num_placeholders_,
479
+ content_blocks_: content_blocks_
478
480
  }) {
479
- const [get_elements, set_elements] = $5vyXB$solidjs.createSignal([]);
480
- let existing_num = 0;
481
+ const [num_to_actually_show, set_num_to_actually_show] = $5vyXB$solidjs.createSignal($5vyXB$solidjs.untrack(num_placeholders_));
481
482
  if (0, $5vyXB$solidjsweb.isServer)
482
483
  // want to render simple placeholders on server, effects don't run there
484
+ // FIXME when adding proper SSR: also SSR content blocks
483
485
  return $5vyXB$solidjs.createMemo(() => Array.from({
484
486
  length: num_placeholders_()
485
487
  }).map(() => {
@@ -488,19 +490,30 @@ function $0caf87eaa19079da$export$f33414a4df0afd3f({
488
490
  if (typeof template_result?.then !== "function") return template_result;
489
491
  }));
490
492
  $5vyXB$solidjs.createRenderEffect(() => {
493
+ const existing_num = num_to_actually_show();
491
494
  const to_add = num_placeholders_() - existing_num;
492
495
  if (to_add <= 0) return;
493
496
  // Below comment is from when we used recommendation renderer and manual DOM manipulation for this, but I'm still scared to remove placeholders and mess up scroll restoration, so I'm keeping the way it worked. Otherwise, <Index> could be used which would be far more elegant.
494
497
  // We don't need to remove placeholders, only need to add. The reason for that is that chrome restores the scroll position once all tasks queued as reaction of the "popstate" events have been completed in the task queue. That means that we need to get the placeholders in fast, or we might lose scroll position if the previous site was shorter.
495
498
  // The query id and the amount might update in separate tasks because one comes from href_change_ipns and the other one from another "popstate" listener. Therefore, we need to be able to dynamically add more placeholders. I'm not entirely sure about this anymore though, since we have the scroll position on a per-id basis it might work anyway but THIS WORKS, and I've been working on this bug for 3 hours so let's just keep it this way.
496
- set_elements(prev => [...prev, ...Array.from({
497
- length: to_add
498
- }).map(() => $0caf87eaa19079da$var$Placeholder({
499
- product_card_template_: product_card_template_
500
- }))]);
501
- existing_num += to_add;
499
+ // Above comments were from when we added elements in this createRenderEffect. Now I changed it to just increment the number and render them from an <Index> instead, so I can add content blocks better
500
+ // Functionality should be the same
501
+ set_num_to_actually_show(existing_num + to_add);
502
+ });
503
+ return $5vyXB$solidjsweb.createComponent((0, $5vyXB$solidjs.Index), {
504
+ get each() {
505
+ return Array.from({
506
+ length: num_to_actually_show()
507
+ });
508
+ },
509
+ children: (_item, index) => {
510
+ const possible_content_block = $5vyXB$solidjs.createMemo(() => content_blocks_?.()?.()?.[index]);
511
+ // Show content block before product card, so it's *at* that index
512
+ return [possible_content_block, $0caf87eaa19079da$var$Placeholder({
513
+ product_card_template_: product_card_template_
514
+ })]; // https://github.com/solidjs/solid/releases/tag/v1.7.0
515
+ }
502
516
  });
503
- return get_elements; // https://github.com/solidjs/solid/releases/tag/v1.7.0
504
517
  }
505
518
  /**
506
519
  * Get one placeholder element. It will be cloned for each placeholder for ultimate performance even when solid-js isn't rendering the placeholders.
@@ -585,7 +598,8 @@ function $a73063cc642f3e5f$export$43f0fb951fcb0c54({
585
598
  merchant_: merchant_,
586
599
  market_: market_,
587
600
  product_card_template_: product_card_template_,
588
- do_per_elements_: do_per_elements_
601
+ do_per_elements_: do_per_elements_,
602
+ content_blocks_: content_blocks_
589
603
  }) {
590
604
  return $5vyXB$solidjsweb.createComponent((0, $5vyXB$solidjs.For), {
591
605
  get each() {
@@ -593,6 +607,7 @@ function $a73063cc642f3e5f$export$43f0fb951fcb0c54({
593
607
  },
594
608
  children: (product_id, index) => {
595
609
  const owner = $5vyXB$solidjs.getOwner();
610
+ const possible_content_block = $5vyXB$solidjs.createMemo(() => content_blocks_?.()?.()?.[index()]);
596
611
  const display_accessor = $5vyXB$solidjs.createMemo(prev => {
597
612
  const new_display = displays_by_key_().get(product_id);
598
613
  if (prev && $a73063cc642f3e5f$var$deep_equal(prev, new_display))
@@ -645,7 +660,9 @@ function $a73063cc642f3e5f$export$43f0fb951fcb0c54({
645
660
  }
646
661
  do_per_elements_?.(elements, index);
647
662
  });
648
- return product_card_resource; // https://github.com/solidjs/solid/releases/tag/v1.7.0
663
+ return [
664
+ // Show content block before product card, so it's *at* that index
665
+ possible_content_block, product_card_resource]; // https://github.com/solidjs/solid/releases/tag/v1.7.0
649
666
  }
650
667
  });
651
668
  }
@@ -3740,7 +3757,9 @@ function $ac167f6af6a48fc3$export$a1fd619a4743ca08({
3740
3757
  min_products_to_fetch_: min_products_to_fetch_,
3741
3758
  query_base_: query_base_,
3742
3759
  depict_api_: depict_api_,
3743
- is_loading_: is_loading_
3760
+ is_loading_: is_loading_,
3761
+ content_blocks_: content_blocks_,
3762
+ set_number_loaded_displays_: set_number_loaded_displays_
3744
3763
  }) {
3745
3764
  // The following sets up an intersection observer to determine which results are in the viewport, used for the ScrollStatus indicator and knowing when to load more
3746
3765
  const target_to_index_map = new Map();
@@ -3784,11 +3803,13 @@ function $ac167f6af6a48fc3$export$a1fd619a4743ca08({
3784
3803
  query_base_: query_base_,
3785
3804
  depict_api_: depict_api_
3786
3805
  });
3806
+ $5vyXB$solidjs.createComputed(() => set_number_loaded_displays_(displays_by_key_().size));
3787
3807
  return $a73063cc642f3e5f$export$43f0fb951fcb0c54({
3788
3808
  displays_by_key_: displays_by_key_,
3789
3809
  merchant_: merchant_,
3790
3810
  market_: market_,
3791
3811
  product_card_template_: product_card_template_,
3812
+ content_blocks_: content_blocks_,
3792
3813
  do_per_elements_: (elements, index_accessor) =>
3793
3814
  // Adds/removes elements from the "results in viewport" intersection observer above
3794
3815
  $5vyXB$solidjs.createEffect(() => {
@@ -3810,6 +3831,314 @@ function $ac167f6af6a48fc3$export$a1fd619a4743ca08({
3810
3831
  })
3811
3832
  });
3812
3833
  }
3834
+ const $75777da1687ba3f6$var$_tmpl$ = ["<style", ' type="text/css">', "</style>"];
3835
+ const $75777da1687ba3f6$export$c500183c31c2b22e = "--spans-columns";
3836
+ function $75777da1687ba3f6$export$ab6b147eec64fea5(props) {
3837
+ const container_class = "x" + $5vyXB$solidjs.createUniqueId();
3838
+ const container_element_ = $5vyXB$solidjsweb.ssrElement("div", () => ({
3839
+ ...props.element_attributes,
3840
+ "classList": {
3841
+ [container_class]: true
3842
+ }
3843
+ }), () => $5vyXB$solidjsweb.escape(props.children), true); // Don't want this in the error boundary below, it should only be for the actual layouting
3844
+ return $5vyXB$solidjsweb.createComponent((0, $edafe91daf3091d7$export$b69d0d92862de18b), {
3845
+ message_: "Failed calculating css grid layout",
3846
+ severity_: "error",
3847
+ get children() {
3848
+ return $75777da1687ba3f6$export$e2f22da34aaf310a(props, container_element_, false, container_class);
3849
+ }
3850
+ });
3851
+ }
3852
+ function $75777da1687ba3f6$export$e2f22da34aaf310a(props, container_element, insert_after_container = false, container_class) {
3853
+ if (!container_class) {
3854
+ // only try to add if it wasn't provided, so that we have a code path without classList when doing SSR
3855
+ container_class = $5vyXB$depictaiutilishared.make_random_classname();
3856
+ container_element.classList.add(container_class);
3857
+ }
3858
+ const container_selector = `.depict .${container_class}`; // class so ppl can have id if needed
3859
+ const col_styling = $5vyXB$solidjs.createMemo(() => $75777da1687ba3f6$var$generate_media_queried_declarations({
3860
+ container_selector_: container_selector,
3861
+ default_grid_spacing_text: props.grid_spacing,
3862
+ cols_at_size_: props.cols_at_size,
3863
+ override_vertical_spacing_: props.override_vertical_spacing,
3864
+ top_row_shortened_by_: props.top_row_shortened_by_()
3865
+ }));
3866
+ const base_styling = $5vyXB$solidjs.createMemo(() => {
3867
+ return `${container_selector}{display:grid;}`;
3868
+ });
3869
+ const get_styling = $5vyXB$solidjs.createMemo(() => base_styling() + col_styling());
3870
+ const style_element = $5vyXB$solidjsweb.ssr($75777da1687ba3f6$var$_tmpl$, $5vyXB$solidjsweb.ssrHydrationKey(), get_styling); // need to create this after set_styling has been called or else there will be no styling in the SSR'd output
3871
+ if (insert_after_container) container_element.after(style_element);
3872
+ return [container_element, style_element];
3873
+ }
3874
+ function $75777da1687ba3f6$var$generate_media_queried_declarations({
3875
+ container_selector_: container_selector_,
3876
+ default_grid_spacing_text: default_grid_spacing_text,
3877
+ cols_at_size_: cols_at_size_,
3878
+ override_vertical_spacing_: override_vertical_spacing_,
3879
+ top_row_shortened_by_: top_row_shortened_by_
3880
+ }) {
3881
+ return cols_at_size_.map(options => {
3882
+ const [n_cols, min, max, grid_spacing_for_size] = options;
3883
+ const spacing_to_use = grid_spacing_for_size || default_grid_spacing_text;
3884
+ // See comment in else block below
3885
+ const can_use_gap = $75777da1687ba3f6$var$can_use_gap_for_unit(spacing_to_use) && (!override_vertical_spacing_ || $75777da1687ba3f6$var$can_use_gap_for_unit(override_vertical_spacing_));
3886
+ let spacing_styling;
3887
+ let additional_styling = ""; // outside the media query
3888
+ if (can_use_gap) spacing_styling = `gap:${spacing_to_use};${override_vertical_spacing_ ? `row-gap:${override_vertical_spacing_};` : ``}`;else {
3889
+ // When using percent units, which our default styling does (because convenient) and our interface relies on (hard to specify different gaps for different screen sizes)
3890
+ // row gaps in grids are relative to the whole height of the grid, maybe see also https://stackoverflow.com/a/53563865. The issue with that is that as we load more products, the gap grows. Also, it breaks existing integrations.
3891
+ // Logical thought: use margins for the vertical spacing. But margins in grids are apparently relative to the size of the individual items in grids.
3892
+ // Given that, and that content blocks can be of different width, we have to do some complicated calculations to convert the provided gap, which is in gap of the total container width, to a margin of the individual items.
3893
+ const width_multiplier = `var(${$75777da1687ba3f6$export$c500183c31c2b22e}, 1)`; // How many cards wide the current item is (needed because content blocks)
3894
+ const one_item_width_exclusing_gaps = `calc(calc(100 / ${n_cols}) - calc(calc(${n_cols * 2 - 2} * calc(${$75777da1687ba3f6$var$strip_percent_unit(spacing_to_use)} / 2)) / ${n_cols}))`; // Width of one item in percent of the whole
3895
+ // Equation from layout.tsx, also used in CheckboxGrid. Needs half spacing for some reason
3896
+ const this_item_width_meat = `calc(${one_item_width_exclusing_gaps} * ${width_multiplier})`; // Width of just the card
3897
+ const this_item_width_gaps = `calc(calc(${width_multiplier} - 1) * ${$75777da1687ba3f6$var$strip_percent_unit(spacing_to_use)})`; // Width of the gaps
3898
+ const this_item_width = `calc(${this_item_width_meat} + ${this_item_width_gaps})`; // Width of this item including gaps
3899
+ // this_item_width needs to be unitless, and since plain css can't do calc(40% / 5%) which would become unitless we need to strip all units in the calculations before
3900
+ const convert_top_spacing_to_item_width_percentage = spacing => `calc(calc(100 / ${this_item_width}) * ${spacing})`; // Now finally we can convert the desired spacing to a percentage of this individual item's width (including gaps that would be there but aren't because content blocks span them)
3901
+ spacing_styling = `column-gap:${spacing_to_use};`; // Still use gaps in the horizontal direction because that works flawlessly
3902
+ // Re-use old layout code to get the correct :nth-child declarations for the top margins
3903
+ additional_styling = $5vyXB$depictaiutilishared.n_col_styling_with_dist(container_selector_ + ">", convert_top_spacing_to_item_width_percentage(default_grid_spacing_text), [[n_cols, min, max, grid_spacing_for_size ? convert_top_spacing_to_item_width_percentage(grid_spacing_for_size) : null]], "grid", override_vertical_spacing_ ? convert_top_spacing_to_item_width_percentage(override_vertical_spacing_) : override_vertical_spacing_, top_row_shortened_by_);
3904
+ }
3905
+ const media_query_body = `${container_selector_}{${spacing_styling}grid-template-columns:repeat(${n_cols},minmax(0,1fr));}`;
3906
+ return `${$5vyXB$depictaiutilishared.layout_media_query_header(min, max)}{${media_query_body}}${additional_styling}`;
3907
+ }).join("");
3908
+ }
3909
+ function $75777da1687ba3f6$var$can_use_gap_for_unit(spacing) {
3910
+ const trimmed_spacing = spacing.trim();
3911
+ return !trimmed_spacing.includes("%");
3912
+ }
3913
+ function $75777da1687ba3f6$var$strip_percent_unit(css_value) {
3914
+ return css_value.replaceAll("%", "");
3915
+ }
3916
+ function $738c3a81fc46a340$export$cb5808ba002cdeed({
3917
+ layout_options_: layout_options_,
3918
+ sort_or_filter_open_: sort_or_filter_open_
3919
+ }) {
3920
+ return $5vyXB$solidjs.createMemo(() => {
3921
+ const layout_options = layout_options_();
3922
+ // Add grid styling that changes when filters get opened/closed
3923
+ const when_filters_closed_cols = layout_options.cols_at_size;
3924
+ return sort_or_filter_open_() ? when_filters_closed_cols.map(row => {
3925
+ const [num_cols_default,,,, override_cols] = row;
3926
+ const cloned_row = [...row];
3927
+ // @ts-ignore
3928
+ cloned_row[0] = num_cols_default - 1;
3929
+ if (override_cols)
3930
+ // @ts-ignore
3931
+ cloned_row[4] = {
3932
+ overrides: Object.fromEntries(Object.entries(override_cols.overrides).map(([row, column]) => [row, column - 1]))
3933
+ };
3934
+ return cloned_row;
3935
+ }) : when_filters_closed_cols;
3936
+ });
3937
+ }
3938
+ function $055384b985678603$export$a79e666719b3647c(cols_at_size_) {
3939
+ const size_active = $5vyXB$solidjs.createMemo(() => cols_at_size_().map(([n_cols, min_width, max_width]) => {
3940
+ const media_query = $5vyXB$depictaiutilishared.layout_media_query_header(min_width, max_width).replaceAll("@media", "");
3941
+ const matches = $b54e6192d0caa293$export$d9f36cf74e24d595(media_query);
3942
+ return [matches, n_cols];
3943
+ }));
3944
+ const n_cols_currently_showing = $5vyXB$solidjs.createMemo(() => {
3945
+ try {
3946
+ const [, n_cols_currently_showing] = size_active().find(([media_query]) => media_query());
3947
+ return n_cols_currently_showing;
3948
+ } catch (e) {
3949
+ $5vyXB$depictaiutilishared.dwarn("No active size found in columnsAtSize - can't render content blocks");
3950
+ return null;
3951
+ }
3952
+ });
3953
+ return n_cols_currently_showing;
3954
+ }
3955
+ function $3bc4a89b971a3af5$export$3f37af283f8fb843(props) {
3956
+ const style = $5vyXB$solidjs.createMemo(() => {
3957
+ const {
3958
+ style: style,
3959
+ height: height,
3960
+ width: width,
3961
+ aspectRatio: aspectRatio
3962
+ } = props;
3963
+ const is_image = aspectRatio != undefined;
3964
+ const size_data = is_image ? {
3965
+ width: "100%",
3966
+ "padding-bottom": 1 / aspectRatio * 100 + "%"
3967
+ } : {
3968
+ width: width,
3969
+ height: height
3970
+ };
3971
+ return {
3972
+ display: "block",
3973
+ ...(style || {}),
3974
+ ...size_data
3975
+ };
3976
+ });
3977
+ return $5vyXB$solidjsweb.createComponent((0, $9fe9883b1d8ecccc$export$acb3eaade4b23afd), {
3978
+ get style() {
3979
+ return style();
3980
+ },
3981
+ get ["class"]() {
3982
+ return props.class;
3983
+ }
3984
+ });
3985
+ }
3986
+ const $d92f338ba8f9da9b$var$_tmpl$ = ["<div", ' class="content-block-wrapper" style="', '">', "</div>"];
3987
+ function $d92f338ba8f9da9b$export$791ef57e62e21c3f({
3988
+ content_blocks_: incoming_content_blocks,
3989
+ cols_at_size_: cols_at_size_,
3990
+ number_of_items_shown_: number_of_items_shown_,
3991
+ set_top_row_shortened_by_: set_top_row_shortened_by_
3992
+ }) {
3993
+ // these are by row
3994
+ const [content_blocks, set_content_blocks] = $5vyXB$solidjsstore.createStore([]);
3995
+ const n_cols_currently_showing_ = $055384b985678603$export$a79e666719b3647c(cols_at_size_);
3996
+ const products_to_rows = products => {
3997
+ const cols_currently_showing = n_cols_currently_showing_();
3998
+ if (cols_currently_showing === null) return 0;
3999
+ return Math.ceil(products / cols_currently_showing);
4000
+ };
4001
+ const showing_rows = $5vyXB$solidjs.createMemo(() => products_to_rows(number_of_items_shown_()));
4002
+ $5vyXB$solidjs.createEffect(() => {
4003
+ const incoming_value = incoming_content_blocks();
4004
+ if (!incoming_value) {
4005
+ set_content_blocks([]);
4006
+ return;
4007
+ }
4008
+ const capped_value = incoming_value.slice(0, showing_rows()); // Don't show more content blocks than we have rows
4009
+ set_content_blocks($5vyXB$solidjsstore.reconcile(capped_value));
4010
+ });
4011
+ const get_wrapped_blocks_ = $d92f338ba8f9da9b$var$wrap_blocks_in_div(content_blocks, n_cols_currently_showing_);
4012
+ $5vyXB$solidjs.createComputed(() => {
4013
+ // Update our styling if a content block forces some items that should be in the top row into a lower one, so we can generate margin-top declarations for them
4014
+ const top_row_block = get_wrapped_blocks_()[0];
4015
+ const blocks_in_top_row_taken = top_row_block?.span_columns;
4016
+ if (blocks_in_top_row_taken == undefined) {
4017
+ // Fall back to zero if no content block in top row, since then no blocks in top row are taken
4018
+ set_top_row_shortened_by_(0);
4019
+ return;
4020
+ }
4021
+ set_top_row_shortened_by_(blocks_in_top_row_taken - 1); // minus one because the content block wrapper also is an element
4022
+ });
4023
+
4024
+ return $d92f338ba8f9da9b$var$remap_blocks_to_index({
4025
+ get_wrapped_blocks_: get_wrapped_blocks_,
4026
+ n_cols_currently_showing_: n_cols_currently_showing_
4027
+ });
4028
+ }
4029
+ /**
4030
+ * Calculate where to put each of the finished wrapped content blocks. Also limit blocks' max width.
4031
+ * @returns an array where index is index of the blocks in the "displays array" and value is the content block (elements) to show at that index
4032
+ */
4033
+ function $d92f338ba8f9da9b$var$remap_blocks_to_index({
4034
+ get_wrapped_blocks_: get_wrapped_blocks_,
4035
+ n_cols_currently_showing_: n_cols_currently_showing_
4036
+ }) {
4037
+ return $5vyXB$solidjs.createMemo(() => {
4038
+ // This computation should be quite cheap since it just moves around things into an array
4039
+ const content_blocks_by_index = [];
4040
+ const constructed_block_arrays = new WeakSet();
4041
+ const wrapped_blocks = get_wrapped_blocks_();
4042
+ const cols_showing = n_cols_currently_showing_();
4043
+ // Need to keep track of products displaced by blocks above when mapping rows to indexes in the actual grid
4044
+ const displaced_products = []; // undefined = is product, true = is content block if number instead of tuple number indicates content blocks in that row. Index in first array is row, index in second array is column
4045
+ for (let i = 0; i < wrapped_blocks.length; i++) {
4046
+ // i = row to show at
4047
+ const block = wrapped_blocks[i];
4048
+ if (!block) continue; // Array can have holes/not defined places
4049
+ const index_of_first_item_in_row = i * cols_showing;
4050
+ const index_of_last_item_in_row = index_of_first_item_in_row + cols_showing;
4051
+ const {
4052
+ span_rows: span_rows,
4053
+ position: position,
4054
+ span_columns: span_columns
4055
+ } = block; // span columns is already capped in the block wrapping step (wrap_blocks_in_div)
4056
+ let target_index;
4057
+ if (position === "left") target_index = index_of_first_item_in_row;else if (position === "right") target_index = index_of_last_item_in_row - span_columns;else if (position === "center") target_index = index_of_first_item_in_row + Math.floor((cols_showing - span_columns) / 2);else throw new Error("Invalid position for content block - must be left, right or center: " + JSON.stringify(position));
4058
+ // Calculate displacement of us by content blocks above us
4059
+ let displacement_by_added_blocks = 0;
4060
+ for (let j = 0; j < i; j++) {
4061
+ const row = displaced_products[j];
4062
+ if (row === undefined) continue; // there were no blocks in this row
4063
+ let items_in_row;
4064
+ if (typeof row === "number") items_in_row = row;else {
4065
+ items_in_row = row.filter(item => item).length;
4066
+ displaced_products[j] = items_in_row;
4067
+ }
4068
+ displacement_by_added_blocks += items_in_row;
4069
+ }
4070
+ const index_of_us_in_row = target_index - index_of_first_item_in_row;
4071
+ for (let j = 0; j < index_of_us_in_row; j++) if (displaced_products[i]?.[j])
4072
+ // Add blocks in our *current* row to the displacement, but only the ones to our left
4073
+ displacement_by_added_blocks++;
4074
+ // Add block to output array at the correct index
4075
+ const final_target_index = target_index - displacement_by_added_blocks;
4076
+ const existing_block = content_blocks_by_index[final_target_index];
4077
+ const block_content = block.content;
4078
+ // If two blocks want to exist at the same location (can happen, for example if one block wants to be at the end of a row and the other one at the start of the next row) add an array with both
4079
+ if (existing_block) {
4080
+ if (constructed_block_arrays.has(existing_block))
4081
+ // Only push to arrays we have created to not create funky bugs when there's an array in JSX.Element
4082
+ existing_block.push(block_content);else {
4083
+ const array = [existing_block, block_content];
4084
+ constructed_block_arrays.add(array);
4085
+ content_blocks_by_index[final_target_index] = array;
4086
+ }
4087
+ } else content_blocks_by_index[final_target_index] = block_content;
4088
+ // Update displacement
4089
+ for (let j = 0; j < span_rows; j++) {
4090
+ const row = displaced_products[i + j] ||= [];
4091
+ for (let k = index_of_us_in_row; k < index_of_us_in_row + span_columns; k++) row[k] = true;
4092
+ }
4093
+ }
4094
+ return content_blocks_by_index;
4095
+ });
4096
+ }
4097
+ /**
4098
+ * Takes a store that contains an array from where index is number of row and value is the result of executing the content block rendering function.
4099
+ * Then renders the content and wraps it into a div with the correct styling.
4100
+ * Also caps span_columns to max available columns
4101
+ */
4102
+ function $d92f338ba8f9da9b$var$wrap_blocks_in_div(rendered_content_blocks, max_span_columns) {
4103
+ const get_wrapped_blocks = $5vyXB$solidjs.mapArray(() => rendered_content_blocks, block => {
4104
+ if (!block) return;
4105
+ const get_span_columns = () => Math.min(block.span_columns, max_span_columns() ?? Infinity);
4106
+ return $5vyXB$solidjs.mergeProps(block, {
4107
+ // Create content divs for the blocks with as much fine-grained diffing as possible?
4108
+ content: $5vyXB$solidjsweb.ssr($d92f338ba8f9da9b$var$_tmpl$, $5vyXB$solidjsweb.ssrHydrationKey(), "grid-column:" + `span ${$5vyXB$solidjsweb.escape(get_span_columns(), true)}` + (";grid-row:" + `span ${$5vyXB$solidjsweb.escape(block.span_rows, true)}`) + (";spans_columns_variable_name:" + $5vyXB$solidjsweb.escape(get_span_columns(), true)), $5vyXB$solidjsweb.escape($5vyXB$solidjsweb.createComponent($d92f338ba8f9da9b$var$RenderContent, {
4109
+ get content() {
4110
+ return block.content;
4111
+ }
4112
+ }))),
4113
+ get span_columns() {
4114
+ // Cap max width of block to the number of columns available, for everyone downstream
4115
+ return get_span_columns();
4116
+ }
4117
+ });
4118
+ });
4119
+ return get_wrapped_blocks;
4120
+ }
4121
+ /**
4122
+ * Basically adds support for async content block functions and shows a rudimentary placeholder if rendering is delayed. Required due to react having a rendering delay.
4123
+ */
4124
+ function $d92f338ba8f9da9b$var$RenderContent(props) {
4125
+ const [resource] = $5vyXB$solidjs.createResource(() => props.content,
4126
+ // Could be reactive
4127
+ fn => fn());
4128
+ $5vyXB$solidjs.createEffect(() => {
4129
+ if (resource.error) console.error("Error in content block rendering", resource.error);
4130
+ });
4131
+ // The suspense is for when there's an async content block (which we have to support due to react having a rendering delay) so that we can show some height while it's loading (should kinda never be visible)
4132
+ return $5vyXB$solidjsweb.createComponent((0, $5vyXB$solidjs.Suspense), {
4133
+ get fallback() {
4134
+ return $5vyXB$solidjsweb.createComponent((0, $3bc4a89b971a3af5$export$3f37af283f8fb843), {
4135
+ width: "100%",
4136
+ height: "max(100%, 400px)"
4137
+ });
4138
+ },
4139
+ children: resource
4140
+ });
4141
+ }
3813
4142
  const $fe76fb463cc60b89$var$_tmpl$ = ["<div", ' class="', '"><!--#-->', "<!--/--><!--#-->", "<!--/--></div>"];
3814
4143
  function $fe76fb463cc60b89$export$3925f87b1545cfc6({
3815
4144
  plp_results_: plp_results_,
@@ -3825,7 +4154,8 @@ function $fe76fb463cc60b89$export$3925f87b1545cfc6({
3825
4154
  sort_or_filter_open_: sort_or_filter_open_,
3826
4155
  product_card_template_: product_card_template_,
3827
4156
  layout_options_: layout_options_,
3828
- id_currently_querying_for_: id_currently_querying_for_
4157
+ id_currently_querying_for_: id_currently_querying_for_,
4158
+ content_blocks_by_row_: content_blocks_by_row_
3829
4159
  }) {
3830
4160
  // The plp_results_ resource will be delayed because we're using createBatchedMemo to not make triplicate API requests, but we need to show the placeholders before already to match Chrome and Firefox's "content has to be there, ready for scroll restoration, before all popstate tasks have been completed"-requirement
3831
4161
  const is_loading_ = $5vyXB$solidjs.createMemo(() => plp_results_.loading || query_base_.loading);
@@ -3866,20 +4196,33 @@ function $fe76fb463cc60b89$export$3925f87b1545cfc6({
3866
4196
  let is_just_after_plp_results_update = false;
3867
4197
  let fallback_is_alive = false;
3868
4198
  const [get_should_have_placeholders_rendered, set_should_have_placeholders_rendered] = $5vyXB$solidjs.createSignal(true);
4199
+ const [top_row_shortened_by_, set_top_row_shortened_by_] = $5vyXB$solidjs.createSignal(0);
4200
+ const [product_card_suspense_is_in_fallback, set_product_card_suspense_is_in_fallback] = $5vyXB$solidjs.createSignal(false);
4201
+ const [number_loaded_displays, set_number_loaded_displays_] = $5vyXB$solidjs.createSignal(0);
4202
+ const modified_cols_at_size = $738c3a81fc46a340$export$cb5808ba002cdeed({
4203
+ layout_options_: layout_options_,
4204
+ sort_or_filter_open_: sort_or_filter_open_
4205
+ });
4206
+ const num_placeholders_ = $5vyXB$solidjs.createMemo(() => {
4207
+ // Can't use the data out of request_base for the id because request_base is too late, we need the correct amount of placeholders before the browser has restored the scroll state after processing all popstate events
4208
+ return (0, $aec24316ed262dc0$export$6c9030e511152266) + (get_scroll_restoration_data().find(({
4209
+ for_id: for_id
4210
+ }) => for_id === id_currently_querying_for_())?.min_results_loaded ?? min_products_to_fetch_);
4211
+ });
4212
+ const number_of_items_shown_ = $5vyXB$solidjs.createMemo(() => is_loading_() || product_card_suspense_is_in_fallback() ? num_placeholders_() : number_loaded_displays());
4213
+ const doesnt_have_content_blocks = $5vyXB$solidjs.createMemo(() => !content_blocks_by_row_());
4214
+ const content_blocks_ = $5vyXB$solidjs.createMemo(() => doesnt_have_content_blocks() ? () => [] : $d92f338ba8f9da9b$export$791ef57e62e21c3f({
4215
+ content_blocks_: content_blocks_by_row_,
4216
+ cols_at_size_: modified_cols_at_size,
4217
+ number_of_items_shown_: number_of_items_shown_,
4218
+ set_top_row_shortened_by_: set_top_row_shortened_by_
4219
+ }));
3869
4220
  const rendered_placeholders = $5vyXB$solidjs.createMemo(() => get_should_have_placeholders_rendered() ? $0caf87eaa19079da$export$f33414a4df0afd3f({
4221
+ content_blocks_: content_blocks_,
3870
4222
  product_card_template_: product_card_template_,
3871
- num_placeholders_: $5vyXB$solidjs.createMemo(() => {
3872
- // Can't use the data out of request_base for the id because request_base is too late, we need the correct amount of placeholders before the browser has restored the scroll state after processing all popstate events
3873
- return (0, $aec24316ed262dc0$export$6c9030e511152266) + (get_scroll_restoration_data().find(({
3874
- for_id: for_id
3875
- }) => for_id === id_currently_querying_for_())?.min_results_loaded ?? min_products_to_fetch_);
3876
- })
4223
+ num_placeholders_: num_placeholders_
3877
4224
  }) : undefined);
3878
4225
  const [get_suspense_is_blocked, set_suspense_is_blocked] = $5vyXB$solidjs.createSignal(false);
3879
- const modified_cols_at_size = $fe76fb463cc60b89$var$make_modified_cols_at_size({
3880
- layout_options_: layout_options_,
3881
- sort_or_filter_open_: sort_or_filter_open_
3882
- });
3883
4226
  const block_suspense_if_needed = () => {
3884
4227
  if (!is_just_after_plp_results_update) return;
3885
4228
  is_just_after_plp_results_update = false;
@@ -3912,6 +4255,8 @@ function $fe76fb463cc60b89$export$3925f87b1545cfc6({
3912
4255
  return (() => {
3913
4256
  fallback_is_alive = true;
3914
4257
  $5vyXB$solidjs.onCleanup(block_suspense_if_needed); // Block suspense after initial run every time after we fetch
4258
+ set_product_card_suspense_is_in_fallback(true); // Here for the content block code that needs to know how many items we're displaying
4259
+ $5vyXB$solidjs.onCleanup(() => set_product_card_suspense_is_in_fallback(false));
3915
4260
  return $5vyXB$solidjs.createMemo(() => {
3916
4261
  // 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
3917
4262
  // In future we could have individual suspense's for each product card, but that's too much for now
@@ -3936,37 +4281,64 @@ function $fe76fb463cc60b89$export$3925f87b1545cfc6({
3936
4281
  min_products_to_fetch_: min_products_to_fetch_,
3937
4282
  query_base_: query_base_,
3938
4283
  depict_api_: depict_api_,
3939
- is_loading_: is_loading_
4284
+ is_loading_: is_loading_,
4285
+ content_blocks_: content_blocks_,
4286
+ set_number_loaded_displays_: set_number_loaded_displays_
3940
4287
  });
3941
4288
  $5vyXB$solidjs.onCleanup(() => suspense_contents = undefined);
3942
4289
  return suspense_contents;
3943
4290
  })();
3944
4291
  }
3945
4292
  });
3946
- return [$fc23d7668ae0011d$export$a2cc176055f8f08(), $5vyXB$solidjsweb.createComponent((0, $f48d0fbb00835aaa$export$d21e32dfedac04be), {
3947
- get cols_at_size() {
3948
- return modified_cols_at_size();
4293
+ /* This Show is so that we show placeholders while query_base is loading and because it's cumbersome to ensure that everything that directly accesses the plp_results_ resource is within the <Suspense> boundary */
4294
+ const listing_contents = $5vyXB$solidjsweb.createComponent((0, $5vyXB$solidjs.Show), {
4295
+ get when() {
4296
+ return !is_loading_();
3949
4297
  },
3950
- get override_vertical_spacing() {
3951
- return layout_options_().override_vertical_spacing;
4298
+ get fallback() {
4299
+ return rendered_placeholders();
3952
4300
  },
3953
- get grid_spacing() {
3954
- return layout_options_().grid_spacing;
4301
+ children: product_cards_when_data
4302
+ });
4303
+ return [$fc23d7668ae0011d$export$a2cc176055f8f08(), $5vyXB$solidjsweb.createComponent((0, $5vyXB$solidjs.Show), {
4304
+ get when() {
4305
+ return doesnt_have_content_blocks();
3955
4306
  },
3956
- rows: "all",
3957
- layout: "grid",
3958
- element_attributes: {
3959
- class: "cards"
4307
+ get fallback() {
4308
+ return $5vyXB$solidjsweb.createComponent((0, $75777da1687ba3f6$export$ab6b147eec64fea5), {
4309
+ get cols_at_size() {
4310
+ return modified_cols_at_size();
4311
+ },
4312
+ get override_vertical_spacing() {
4313
+ return layout_options_().override_vertical_spacing;
4314
+ },
4315
+ get grid_spacing() {
4316
+ return layout_options_().grid_spacing;
4317
+ },
4318
+ element_attributes: {
4319
+ class: "cards css-grid"
4320
+ },
4321
+ top_row_shortened_by_: top_row_shortened_by_,
4322
+ children: listing_contents
4323
+ });
3960
4324
  },
3961
4325
  get children() {
3962
- return $5vyXB$solidjsweb.createComponent((0, $5vyXB$solidjs.Show), {
3963
- get when() {
3964
- return !is_loading_();
4326
+ return $5vyXB$solidjsweb.createComponent((0, $f48d0fbb00835aaa$export$d21e32dfedac04be), {
4327
+ get cols_at_size() {
4328
+ return modified_cols_at_size();
4329
+ },
4330
+ get override_vertical_spacing() {
4331
+ return layout_options_().override_vertical_spacing;
4332
+ },
4333
+ get grid_spacing() {
4334
+ return layout_options_().grid_spacing;
3965
4335
  },
3966
- get fallback() {
3967
- return rendered_placeholders();
4336
+ rows: "all",
4337
+ layout: "grid",
4338
+ element_attributes: {
4339
+ class: "cards"
3968
4340
  },
3969
- children: product_cards_when_data
4341
+ children: listing_contents
3970
4342
  });
3971
4343
  }
3972
4344
  })];
@@ -3975,32 +4347,6 @@ function $fe76fb463cc60b89$export$3925f87b1545cfc6({
3975
4347
  }
3976
4348
  })), $5vyXB$solidjsweb.escape(desktop_filter_elements_()));
3977
4349
  }
3978
- /**
3979
- * Changes cols_at_size depending on if filters are open or not so one card less is shown when the filters are open
3980
- * This function is special to the actual PLPResults.
3981
- */
3982
- function $fe76fb463cc60b89$var$make_modified_cols_at_size({
3983
- layout_options_: layout_options_,
3984
- sort_or_filter_open_: sort_or_filter_open_
3985
- }) {
3986
- return $5vyXB$solidjs.createMemo(() => {
3987
- const layout_options = layout_options_();
3988
- // Add grid styling that changes when filters get opened/closed
3989
- const when_filters_closed_cols = layout_options.cols_at_size;
3990
- return sort_or_filter_open_() ? when_filters_closed_cols.map(row => {
3991
- const [num_cols_default,,,, override_cols] = row;
3992
- const cloned_row = [...row];
3993
- // @ts-ignore
3994
- cloned_row[0] = num_cols_default - 1;
3995
- if (override_cols)
3996
- // @ts-ignore
3997
- cloned_row[4] = {
3998
- overrides: Object.fromEntries(Object.entries(override_cols.overrides).map(([row, column]) => [row, column - 1]))
3999
- };
4000
- return cloned_row;
4001
- }) : when_filters_closed_cols;
4002
- });
4003
- }
4004
4350
  const $be89be42ce9ea60f$var$_tmpl$ = ["<div", ' class="sorting-attributes">', "</div>"],
4005
4351
  $be89be42ce9ea60f$var$_tmpl$2 = ["<div", ' class="sorting-direction">', "</div>"],
4006
4352
  $be89be42ce9ea60f$var$_tmpl$3 = ["<div", '><div class="input-row"><input type="radio"', '><span class="custom-indicator"></span><!--#-->', "<!--/--></div></div>"],
@@ -5188,7 +5534,8 @@ function $840d88a04b2d22a7$export$f7d2f673fc2f091d({
5188
5534
  product_card_template_: product_card_template_,
5189
5535
  sideways_filter_clearing_flag_: sideways_filter_clearing_flag_,
5190
5536
  sorting_query_param_: sorting_query_param_,
5191
- filter_query_param_prefix_: filter_query_param_prefix_
5537
+ filter_query_param_prefix_: filter_query_param_prefix_,
5538
+ content_blocks_by_row_: content_blocks_by_row_
5192
5539
  }) {
5193
5540
  let results_for;
5194
5541
  let only_show_filters_opener_;
@@ -5436,6 +5783,7 @@ function $840d88a04b2d22a7$export$f7d2f673fc2f091d({
5436
5783
  product_card_template_: product_card_template_,
5437
5784
  sort_or_filter_open_: sort_or_filter_open_,
5438
5785
  desktop_filter_elements_: desktop_filter_elements_,
5786
+ content_blocks_by_row_: content_blocks_by_row_,
5439
5787
  id_currently_querying_for_: query_id_,
5440
5788
  no_results_options_: {
5441
5789
  selected_filters_: selected_filters_,
@@ -5935,6 +6283,7 @@ function $48567ac5b39bac56$export$e2bf8ce7779e827e(props) {
5935
6283
  expanded_hierarchical_filters_: expanded_hierarchical_filters_,
5936
6284
  selected_filters_: selected_filters_,
5937
6285
  sideways_filter_clearing_flag_: sideways_filter_clearing_flag_,
6286
+ content_blocks_by_row_: () => props.content_blocks_by_row,
5938
6287
  scroll_restoration_data_: scroll_restoration_data_,
5939
6288
  layout_options_: $5vyXB$solidjs.createMemo(() => ({
5940
6289
  cols_at_size: $4e04be41243c3d80$export$6daf8749b65a1b77(props.cols_at_size),
@@ -6161,37 +6510,6 @@ async function $63b10c9f461e0ef6$var$download_categories(tenant, market, type) {
6161
6510
  return [];
6162
6511
  }
6163
6512
  }
6164
- function $3bc4a89b971a3af5$export$3f37af283f8fb843(props) {
6165
- const style = $5vyXB$solidjs.createMemo(() => {
6166
- const {
6167
- style: style,
6168
- height: height,
6169
- width: width,
6170
- aspectRatio: aspectRatio
6171
- } = props;
6172
- const is_image = aspectRatio != undefined;
6173
- const size_data = is_image ? {
6174
- width: "100%",
6175
- "padding-bottom": 1 / aspectRatio * 100 + "%"
6176
- } : {
6177
- width: width,
6178
- height: height
6179
- };
6180
- return {
6181
- display: "block",
6182
- ...(style || {}),
6183
- ...size_data
6184
- };
6185
- });
6186
- return $5vyXB$solidjsweb.createComponent((0, $9fe9883b1d8ecccc$export$acb3eaade4b23afd), {
6187
- get style() {
6188
- return style();
6189
- },
6190
- get ["class"]() {
6191
- return props.class;
6192
- }
6193
- });
6194
- }
6195
6513
  const $6f604560873e4f69$var$_tmpl$ = ["<div", ' class="instant-card"><div class="img-part">', '</div><div class="right-part"><div class="title-brand-tagline"><span class="title">', "</span></div></div></div>"];
6196
6514
  function $6f604560873e4f69$export$ee1733d9a8495996() {
6197
6515
  return $5vyXB$solidjsweb.ssr($6f604560873e4f69$var$_tmpl$, $5vyXB$solidjsweb.ssrHydrationKey(), $5vyXB$solidjsweb.escape($5vyXB$solidjsweb.createComponent((0, $3bc4a89b971a3af5$export$3f37af283f8fb843), {
@@ -8061,7 +8379,8 @@ function $f1d7cb69f839a526$export$a54ec244c8863715({
8061
8379
  router_: router_,
8062
8380
  content_results_rows_: content_results_rows_,
8063
8381
  content_layout_options_: content_layout_options_,
8064
- content_search_enabled_: content_search_enabled_
8382
+ content_search_enabled_: content_search_enabled_,
8383
+ content_blocks_by_row_: content_blocks_by_row_
8065
8384
  }) {
8066
8385
  const [get_sorting] = current_sorting_;
8067
8386
  const all_products_loaded_ = $5vyXB$solidjs.createSignal(false);
@@ -8305,6 +8624,7 @@ function $f1d7cb69f839a526$export$a54ec244c8863715({
8305
8624
  layout_options_: layout_options_,
8306
8625
  sort_or_filter_open_: sort_or_filter_open_,
8307
8626
  id_currently_querying_for_: get_search_query_,
8627
+ content_blocks_by_row_: content_blocks_by_row_,
8308
8628
  no_results_options_: {
8309
8629
  selected_filters_: selected_filters_,
8310
8630
  expanded_hierarchical_filters_: expanded_hierarchical_filters_,
@@ -8744,6 +9064,7 @@ function $2c61e4cd8229c49a$export$f2dc7e4e4aa11abb(props) {
8744
9064
  search_sorting_open_: state_.sorting_open,
8745
9065
  expanded_filters_: state_.expanded_filters,
8746
9066
  content_results_rows_: state_.content_results_rows,
9067
+ content_blocks_by_row_: () => props.content_blocks_by_row,
8747
9068
  router_: shared_properties.router_,
8748
9069
  make_category_suggestion_card_: shared_properties.enable_category_suggestions_ ? category_suggestion_ => {
8749
9070
  return $dae23104ba8bb78c$export$d757d54550ebfb3d({