@depict-ai/ui 2.0.1 → 2.0.2

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
@@ -8,7 +8,7 @@ import $8tj43$babelruntimehelpersdefineProperty from "@babel/runtime/helpers/def
8
8
  /*! Depict.ai search and product listing SDK */
9
9
  import { register_es_version } from "../multi_import_deduplicator.mjs";
10
10
  register_es_version("ui", "ES10");
11
- const $8db9a15135765c11$export$83d89fbfd8236492 = "2.0.1";
11
+ const $8db9a15135765c11$export$83d89fbfd8236492 = "2.0.2";
12
12
  const $a9c7ba6087881ac2$var$transform_elements = sorted_cols_at_size => {
13
13
  const cols_at_size = [];
14
14
  for (let i = 0; i < sorted_cols_at_size.length; i++) {
@@ -1437,9 +1437,9 @@ function $4711a82d08d2021b$export$fecbb157621501bd(_ref) {
1437
1437
  return outmost_element;
1438
1438
  }
1439
1439
  $8tj43$delegateEvents(["click"]);
1440
- const $6b73914551534ea8$var$_tmpl$ = /*#__PURE__*/$8tj43$template(`<span class="count"></span>`, 2),
1441
- $6b73914551534ea8$var$_tmpl$2 = /*#__PURE__*/$8tj43$template(`<label class="input-row"><div class="left"><input type="checkbox"><span class="custom-indicator"></span><span class="text line-clamp"></span></div><!#><!/></label>`, 11);
1442
- const $6b73914551534ea8$export$48513f6b9f8ce62d = props => {
1440
+ const $19e828709c7723a0$var$_tmpl$ = /*#__PURE__*/$8tj43$template(`<span class="count"></span>`, 2),
1441
+ $19e828709c7723a0$var$_tmpl$2 = /*#__PURE__*/$8tj43$template(`<label class="input-row"><div class="left"><input type="checkbox"><span class="custom-indicator"></span><span class="text line-clamp"></span></div><!#><!/></label>`, 11);
1442
+ const $19e828709c7723a0$export$48513f6b9f8ce62d = props => {
1443
1443
  // It seems like there's no diffing without memos here (since we often just have computations in the getters above that update to the same result often because their dependencies change with unrelated changes often), so put memos here to avoid unneeded DOM changes
1444
1444
  const count = $8tj43$createMemo(() => props.count_);
1445
1445
  const label = $8tj43$createMemo(() => props.label_);
@@ -1448,7 +1448,7 @@ const $6b73914551534ea8$export$48513f6b9f8ce62d = props => {
1448
1448
  const is_count_zero = $8tj43$createMemo(() => props.is_count_zero_ || count() === 0);
1449
1449
  const id = $8tj43$make_random_classname();
1450
1450
  return (/* We can't use actual margin because ExpandingContainer gets messed up */(() => {
1451
- const _el$ = $8tj43$getNextElement($6b73914551534ea8$var$_tmpl$2),
1451
+ const _el$ = $8tj43$getNextElement($19e828709c7723a0$var$_tmpl$2),
1452
1452
  _el$2 = _el$.firstChild,
1453
1453
  _el$3 = _el$2.firstChild,
1454
1454
  _el$4 = _el$3.nextSibling,
@@ -1479,7 +1479,7 @@ const $6b73914551534ea8$export$48513f6b9f8ce62d = props => {
1479
1479
  return count() != undefined;
1480
1480
  },
1481
1481
  get children() {
1482
- const _el$6 = $8tj43$getNextElement($6b73914551534ea8$var$_tmpl$);
1482
+ const _el$6 = $8tj43$getNextElement($19e828709c7723a0$var$_tmpl$);
1483
1483
  $8tj43$insert(_el$6, count);
1484
1484
  return _el$6;
1485
1485
  }
@@ -1575,7 +1575,7 @@ function $133484ef10e4e954$export$dd948f91abc3a1c4(_ref) {
1575
1575
  });
1576
1576
  const render_checkbox = checkbox => {
1577
1577
  // Checkbox always calls the getters in props, so we don't wrap these values into memos
1578
- return $8tj43$createComponent((0, $6b73914551534ea8$export$48513f6b9f8ce62d), {
1578
+ return $8tj43$createComponent((0, $19e828709c7723a0$export$48513f6b9f8ce62d), {
1579
1579
  get value_() {
1580
1580
  return checkbox().value_;
1581
1581
  },
@@ -2319,7 +2319,7 @@ function $0ae614c5c7babb43$var$render_stuff(data, existing_filter, i18n_) {
2319
2319
  [_el$8, _co$3] = $8tj43$getNextMarker(_el$7.nextSibling),
2320
2320
  _el$9 = _el$8.nextSibling,
2321
2321
  [_el$10, _co$4] = $8tj43$getNextMarker(_el$9.nextSibling);
2322
- $8tj43$insert(_el$6, $8tj43$createComponent((0, $6b73914551534ea8$export$48513f6b9f8ce62d), {
2322
+ $8tj43$insert(_el$6, $8tj43$createComponent((0, $19e828709c7723a0$export$48513f6b9f8ce62d), {
2323
2323
  get value_() {
2324
2324
  var _value2;
2325
2325
  return JSON.stringify((_value2 = value()) === null || _value2 === void 0 ? void 0 : _value2.value_);
@@ -2609,9 +2609,27 @@ function $0ae614c5c7babb43$var$expand_until_choice(data_structure) {
2609
2609
  }
2610
2610
  });
2611
2611
  }
2612
- const $830ea8efda59884e$var$_tmpl$ = /*#__PURE__*/$8tj43$template(`<div class="checkbox-grid"></div>`, 2),
2612
+
2613
+ /** @jsxImportSource solid-js */
2614
+
2615
+ function $0dc044cffe1e825b$export$9f191182275e9ef(what_to_watch) {
2616
+ const [size, setSize] = $8tj43$createSignal();
2617
+ const resizeObserver = new ResizeObserver($8tj43$catchify(records => {
2618
+ for (let j = 0; j < records.length; j++) {
2619
+ var _records$j$borderBoxS, _records$j$borderBoxS2, _records$j$borderBoxS3;
2620
+ const width = (_records$j$borderBoxS = (_records$j$borderBoxS2 = records[j].borderBoxSize) === null || _records$j$borderBoxS2 === void 0 ? void 0 : (_records$j$borderBoxS3 = _records$j$borderBoxS2[0]) === null || _records$j$borderBoxS3 === void 0 ? void 0 : _records$j$borderBoxS3.inlineSize) !== null && _records$j$borderBoxS !== void 0 ? _records$j$borderBoxS : what_to_watch.getBoundingClientRect().width;
2621
+ setSize(width);
2622
+ }
2623
+ }));
2624
+ resizeObserver.observe(what_to_watch);
2625
+ $8tj43$onCleanup(() => resizeObserver.disconnect());
2626
+ return size;
2627
+ }
2628
+ const $830ea8efda59884e$var$_tmpl$ = /*#__PURE__*/$8tj43$template(`<div class="checkbox-grid" style="position:absolute;z-index:-1;pointer-events:none;opacity:0"></div>`, 2),
2613
2629
  $830ea8efda59884e$var$_tmpl$2 = /*#__PURE__*/$8tj43$template(`<span class="count-wrapper"><span class="count"></span></span>`, 4),
2614
- $830ea8efda59884e$var$_tmpl$3 = /*#__PURE__*/$8tj43$template(`<button class="major-minor-transition"><!#><!/><!#><!/></button>`, 6);
2630
+ $830ea8efda59884e$var$_tmpl$3 = /*#__PURE__*/$8tj43$template(`<button><!#><!/><!#><!/></button>`, 6);
2631
+ const $830ea8efda59884e$var$gap_px = 5;
2632
+ const $830ea8efda59884e$var$max_columns = 3;
2615
2633
  const $830ea8efda59884e$export$414f6a19d38e655c = _ref => {
2616
2634
  let {
2617
2635
  filter_: filter_,
@@ -2641,77 +2659,187 @@ const $830ea8efda59884e$export$414f6a19d38e655c = _ref => {
2641
2659
  };
2642
2660
  });
2643
2661
  });
2644
- return (() => {
2662
+ const [sizes_set, set_sizes_set] = $8tj43$createSignal(new Set(), {
2663
+ equals: false
2664
+ });
2665
+ const [cols_at_size, set_cols_at_size] = $8tj43$createSignal([[1, "0px", ""]]);
2666
+ const [container, set_container] = $8tj43$createSignal();
2667
+ const container_width_accessor = $8tj43$createMemo(() => {
2668
+ const element = container();
2669
+ if (!element) return;
2670
+ return $0dc044cffe1e825b$export$9f191182275e9ef(element);
2671
+ });
2672
+ const [shadow_children, set_shadow_children] = $8tj43$createSignal(new Set(), {
2673
+ equals: false
2674
+ });
2675
+ const shadow_grid = (() => {
2645
2676
  const _el$ = $8tj43$getNextElement($830ea8efda59884e$var$_tmpl$);
2646
- $8tj43$insert(_el$, $8tj43$createComponent((0, $8tj43$Index), {
2647
- get each() {
2648
- return buttons();
2649
- },
2650
- children: value => {
2651
- const is_selected = $8tj43$createMemo(() => {
2652
- var _existing_filter, _existing_filter$data;
2653
- return (_existing_filter = existing_filter()) === null || _existing_filter === void 0 ? void 0 : (_existing_filter$data = _existing_filter.data) === null || _existing_filter$data === void 0 ? void 0 : _existing_filter$data.includes(value().value_);
2654
- });
2655
- return (() => {
2656
- const _el$2 = $8tj43$getNextElement($830ea8efda59884e$var$_tmpl$3),
2657
- _el$5 = _el$2.firstChild,
2658
- [_el$6, _co$] = $8tj43$getNextMarker(_el$5.nextSibling),
2659
- _el$7 = _el$6.nextSibling,
2660
- [_el$8, _co$2] = $8tj43$getNextMarker(_el$7.nextSibling);
2661
- $8tj43$addEventListener(_el$2, "click", $8tj43$catchify(() => {
2662
- const set_filter = existing_filter();
2663
- const {
2664
- field: field,
2665
- op: op
2666
- } = filter_();
2667
- const base_object = set_filter ? set_filter : {
2668
- op: op,
2669
- field: field
2670
- };
2671
- const old_data = base_object.data;
2672
- const new_data = [...(Array.isArray(old_data) ? [...old_data] : old_data ? [old_data] : [])];
2673
- const new_filter_object = {
2674
- ...base_object,
2675
- data: new_data
2676
- };
2677
- if (!is_selected()) new_filter_object.data.push(value().value_);else new_filter_object.data = new_filter_object.data.filter(v => v !== value().value_);
2678
- const selected_filters = [...get_selected_filters().filter(f => f !== set_filter), ...(new_filter_object.data.length ? [new_filter_object] : [])];
2679
- set_selected_filters(selected_filters);
2680
- }), true);
2681
- $8tj43$insert(_el$2, () => value().value_, _el$6, _co$);
2682
- $8tj43$insert(_el$2, $8tj43$createComponent((0, $8tj43$Show), {
2683
- get when() {
2684
- return value().count_ != undefined;
2685
- },
2686
- get children() {
2687
- const _el$3 = $8tj43$getNextElement($830ea8efda59884e$var$_tmpl$2),
2688
- _el$4 = _el$3.firstChild;
2689
- $8tj43$insert(_el$4, () => value().count_);
2690
- return _el$3;
2691
- }
2692
- }), _el$8, _co$2);
2693
- $8tj43$effect(_p$ => {
2694
- const _v$ = value().count_ === 0 && !is_selected(),
2695
- _v$2 = !is_selected(),
2696
- _v$3 = !!is_selected();
2697
- _v$ !== _p$._v$ && (_el$2.disabled = _p$._v$ = _v$);
2698
- _v$2 !== _p$._v$2 && _el$2.classList.toggle("minor", _p$._v$2 = _v$2);
2699
- _v$3 !== _p$._v$3 && _el$2.classList.toggle("major", _p$._v$3 = _v$3);
2700
- return _p$;
2701
- }, {
2702
- _v$: undefined,
2703
- _v$2: undefined,
2704
- _v$3: undefined
2705
- });
2706
- $8tj43$runHydrationEvents();
2707
- return _el$2;
2708
- })();
2709
- }
2710
- }));
2677
+ $8tj43$insert(_el$, () => [...shadow_children()]);
2711
2678
  return _el$;
2712
- })();
2679
+ })(); // for getting the smallest possible sizes of all the items
2680
+ $8tj43$createEffect(() => {
2681
+ var _container_width_acce;
2682
+ const container_width = (_container_width_acce = container_width_accessor()) === null || _container_width_acce === void 0 ? void 0 : _container_width_acce();
2683
+ if (container_width == undefined) return;
2684
+ $830ea8efda59884e$var$adjust_sizes(container_width, sizes_set(), set_cols_at_size);
2685
+ });
2686
+ return [shadow_grid, $8tj43$createComponent((0, $63f1f8dbcd07d3b0$export$d21e32dfedac04be), {
2687
+ get cols_at_size() {
2688
+ return cols_at_size();
2689
+ },
2690
+ grid_spacing: $830ea8efda59884e$var$gap_px + "px",
2691
+ rows: "all",
2692
+ layout: "grid",
2693
+ element_attributes: {
2694
+ class: "checkbox-grid",
2695
+ ref: el => set_container(el)
2696
+ },
2697
+ get children() {
2698
+ return $8tj43$createComponent((0, $8tj43$Index), {
2699
+ get each() {
2700
+ return buttons();
2701
+ },
2702
+ children: value => {
2703
+ const is_selected = $8tj43$createMemo(() => {
2704
+ var _existing_filter, _existing_filter$data;
2705
+ return (_existing_filter = existing_filter()) === null || _existing_filter === void 0 ? void 0 : (_existing_filter$data = _existing_filter.data) === null || _existing_filter$data === void 0 ? void 0 : _existing_filter$data.includes(value().value_);
2706
+ });
2707
+ const MakeButton = attributes => (() => {
2708
+ const _el$2 = $8tj43$getNextElement($830ea8efda59884e$var$_tmpl$3),
2709
+ _el$5 = _el$2.firstChild,
2710
+ [_el$6, _co$] = $8tj43$getNextMarker(_el$5.nextSibling),
2711
+ _el$7 = _el$6.nextSibling,
2712
+ [_el$8, _co$2] = $8tj43$getNextMarker(_el$7.nextSibling);
2713
+ $8tj43$spread(_el$2, $8tj43$mergeProps(attributes, {
2714
+ get disabled() {
2715
+ return $8tj43$memo(() => value().count_ === 0)() && !is_selected();
2716
+ },
2717
+ get classList() {
2718
+ return {
2719
+ minor: !is_selected(),
2720
+ major: is_selected(),
2721
+ "major-minor-transition": true
2722
+ };
2723
+ },
2724
+ get onClick() {
2725
+ return $8tj43$catchify(() => {
2726
+ const set_filter = existing_filter();
2727
+ const {
2728
+ field: field,
2729
+ op: op
2730
+ } = filter_();
2731
+ const base_object = set_filter ? set_filter : {
2732
+ op: op,
2733
+ field: field
2734
+ };
2735
+ const old_data = base_object.data;
2736
+ const new_data = [...(Array.isArray(old_data) ? [...old_data] : old_data ? [old_data] : [])];
2737
+ const new_filter_object = {
2738
+ ...base_object,
2739
+ data: new_data
2740
+ };
2741
+ if (!is_selected()) new_filter_object.data.push(value().value_);else new_filter_object.data = new_filter_object.data.filter(v => v !== value().value_);
2742
+ const selected_filters = [...get_selected_filters().filter(f => f !== set_filter), ...(new_filter_object.data.length ? [new_filter_object] : [])];
2743
+ set_selected_filters(selected_filters);
2744
+ });
2745
+ }
2746
+ }), false, true);
2747
+ $8tj43$insert(_el$2, () => value().value_, _el$6, _co$);
2748
+ $8tj43$insert(_el$2, $8tj43$createComponent((0, $8tj43$Show), {
2749
+ get when() {
2750
+ return value().count_ != undefined;
2751
+ },
2752
+ get children() {
2753
+ const _el$3 = $8tj43$getNextElement($830ea8efda59884e$var$_tmpl$2),
2754
+ _el$4 = _el$3.firstChild;
2755
+ $8tj43$insert(_el$4, () => value().count_);
2756
+ return _el$3;
2757
+ }
2758
+ }), _el$8, _co$2);
2759
+ $8tj43$runHydrationEvents();
2760
+ return _el$2;
2761
+ })();
2762
+ const invisible_size_button = $8tj43$createComponent(MakeButton, {});
2763
+ const smallest_possible_size = $0dc044cffe1e825b$export$9f191182275e9ef(invisible_size_button); // create ResizeObserver for the invisible size button where the div hugs its content
2764
+ const sizes_value = $8tj43$untrack(sizes_set);
2765
+ const shadow_children_value = $8tj43$untrack(shadow_children);
2766
+ sizes_value.add(smallest_possible_size);
2767
+ set_sizes_set(sizes_value);
2768
+ shadow_children_value.add(invisible_size_button);
2769
+ set_shadow_children(shadow_children_value);
2770
+ $8tj43$onCleanup(() => {
2771
+ const sizes_value = $8tj43$untrack(sizes_set);
2772
+ const shadow_children_value = $8tj43$untrack(shadow_children);
2773
+ sizes_value.delete(smallest_possible_size);
2774
+ set_sizes_set(sizes_value);
2775
+ shadow_children_value.delete(invisible_size_button);
2776
+ set_shadow_children(shadow_children_value);
2777
+ });
2778
+ // The actual button that will be visible
2779
+ return $8tj43$createComponent(MakeButton, {});
2780
+ }
2781
+ });
2782
+ }
2783
+ })];
2713
2784
  };
2714
- $8tj43$delegateEvents(["click"]);
2785
+ /**
2786
+ * Calculate and apply cols_at_size overrides to fit as many items as possible in a row, evenly spaced
2787
+ */
2788
+ function $830ea8efda59884e$var$adjust_sizes(container_width, sizes, set_cols_at_size) {
2789
+ let current_row_index = 0;
2790
+ let current_row_items = [];
2791
+ const column_to_row_result = {};
2792
+ const check_would_fit_evenly = (min_size_of_item, at_number_of_columnns) => {
2793
+ const would_have_even_size = container_width / at_number_of_columnns - (at_number_of_columnns * 2 - 2) * ($830ea8efda59884e$var$gap_px / 2) / at_number_of_columnns; // What size would our element have (without gaps), given that now every column had the same width (equation from Layout.tsx)
2794
+ return would_have_even_size >= min_size_of_item; // would this item still fit if we added another column? (probably what the caller has done with at_number_of_columns), given that every item has the same size
2795
+ };
2796
+
2797
+ for (const size_item of sizes) {
2798
+ const size = size_item();
2799
+ if (size == undefined) return; // Only do stuff if we know all the sizes
2800
+ const current_row_length = current_row_items.length;
2801
+ const can_add_another_column_initial_val = current_row_length < $830ea8efda59884e$var$max_columns; // allow max 4 items per row
2802
+ let can_add_another_column = can_add_another_column_initial_val;
2803
+ if (can_add_another_column)
2804
+ // can we actually? Since adding another column changes the size of all elements in the row we need to check all of them
2805
+ for (let i = -1; i < current_row_length; i++) {
2806
+ var _ref3;
2807
+ // -1 is for the new item we're adding and every item is guaranteed to exist
2808
+ const size_to_check = (_ref3 = current_row_items[i]) !== null && _ref3 !== void 0 ? _ref3 : size;
2809
+ const would_have_columns = current_row_length + 1; // if we added another column
2810
+ const would_fit_evenly = check_would_fit_evenly(size_to_check, would_have_columns); // see comments in check_would_fit_evenly
2811
+ if (!would_fit_evenly) {
2812
+ can_add_another_column = false;
2813
+ break;
2814
+ }
2815
+ }
2816
+ if (can_add_another_column) current_row_items.push(size);else {
2817
+ column_to_row_result[++current_row_index] = current_row_length || 1; // overrides is indexed by 1 it seems, therefore ++curent_row_index
2818
+ current_row_items = [size]; // save current item for next row
2819
+ }
2820
+ }
2821
+
2822
+ const items_left_to_add = current_row_items.length;
2823
+ if (items_left_to_add) {
2824
+ let num_columns = 1; // We want to have as close to max_columns as possible in the last row
2825
+ let fits = true;
2826
+ do
2827
+ // Check if more columns would fit
2828
+ for (let i = 0; i < items_left_to_add; i++) {
2829
+ const item = current_row_items[i];
2830
+ const would_fit_evenly = check_would_fit_evenly(item, num_columns + 1);
2831
+ if (!would_fit_evenly) {
2832
+ fits = false;
2833
+ break;
2834
+ }
2835
+ } while (fits && ++num_columns < $830ea8efda59884e$var$max_columns);
2836
+ column_to_row_result[++current_row_index] = num_columns; // Add last row that's left after loop finished
2837
+ }
2838
+
2839
+ set_cols_at_size([[1, "0px", "", null, {
2840
+ overrides: column_to_row_result
2841
+ }]]);
2842
+ }
2715
2843
  function $00a5b94f0c11efbb$export$d9f36cf74e24d595(media_query) {
2716
2844
  const signal = $8tj43$createSignal(false);
2717
2845
  $8tj43$onCleanup($8tj43$javascript_media_query(media_query, _ref => {
@@ -2770,7 +2898,7 @@ function $2cb856c297c53e6c$export$82ed4b28ecb67608(_ref) {
2770
2898
  });
2771
2899
  const rgb_color = $8tj43$createMemo(() => $8tj43$hex_to_rgb(hex_color()));
2772
2900
  const black_contrast_better = $8tj43$createMemo(() => rgb_color() ? $2cb856c297c53e6c$var$does_black_contrast_better(rgb_color()) : false);
2773
- const input_row = $8tj43$createComponent((0, $6b73914551534ea8$export$48513f6b9f8ce62d), {
2901
+ const input_row = $8tj43$createComponent((0, $19e828709c7723a0$export$48513f6b9f8ce62d), {
2774
2902
  get value_() {
2775
2903
  return checkbox().value_;
2776
2904
  },