@depict-ai/ui 2.0.0 → 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.0";
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++) {
@@ -704,9 +704,18 @@ function $b432b11321ad4c97$export$9756467d34d91cdb(props) {
704
704
  return $83e8cf2c0b87a58a$export$23fca46f3143581f(() => {
705
705
  const rows_object_ = $8tj43$createMemo(() => {
706
706
  var _view_more_button$row;
707
- const view_more_button = props.view_more_button;
708
- if (!view_more_button) return "all";
707
+ const {
708
+ view_more_button: view_more_button,
709
+ max_rows: max_rows
710
+ } = props;
711
+ if (!view_more_button) {
712
+ if (max_rows) return {
713
+ max_rows: max_rows
714
+ };
715
+ return "all";
716
+ }
709
717
  return {
718
+ max_rows: max_rows,
710
719
  start_rows: view_more_button.start_rows,
711
720
  rows_per_click: (_view_more_button$row = view_more_button.rows_per_click) !== null && _view_more_button$row !== void 0 ? _view_more_button$row : 2,
712
721
  button: (() => {
@@ -1428,9 +1437,9 @@ function $4711a82d08d2021b$export$fecbb157621501bd(_ref) {
1428
1437
  return outmost_element;
1429
1438
  }
1430
1439
  $8tj43$delegateEvents(["click"]);
1431
- const $6b73914551534ea8$var$_tmpl$ = /*#__PURE__*/$8tj43$template(`<span class="count"></span>`, 2),
1432
- $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);
1433
- 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 => {
1434
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
1435
1444
  const count = $8tj43$createMemo(() => props.count_);
1436
1445
  const label = $8tj43$createMemo(() => props.label_);
@@ -1439,7 +1448,7 @@ const $6b73914551534ea8$export$48513f6b9f8ce62d = props => {
1439
1448
  const is_count_zero = $8tj43$createMemo(() => props.is_count_zero_ || count() === 0);
1440
1449
  const id = $8tj43$make_random_classname();
1441
1450
  return (/* We can't use actual margin because ExpandingContainer gets messed up */(() => {
1442
- const _el$ = $8tj43$getNextElement($6b73914551534ea8$var$_tmpl$2),
1451
+ const _el$ = $8tj43$getNextElement($19e828709c7723a0$var$_tmpl$2),
1443
1452
  _el$2 = _el$.firstChild,
1444
1453
  _el$3 = _el$2.firstChild,
1445
1454
  _el$4 = _el$3.nextSibling,
@@ -1470,7 +1479,7 @@ const $6b73914551534ea8$export$48513f6b9f8ce62d = props => {
1470
1479
  return count() != undefined;
1471
1480
  },
1472
1481
  get children() {
1473
- const _el$6 = $8tj43$getNextElement($6b73914551534ea8$var$_tmpl$);
1482
+ const _el$6 = $8tj43$getNextElement($19e828709c7723a0$var$_tmpl$);
1474
1483
  $8tj43$insert(_el$6, count);
1475
1484
  return _el$6;
1476
1485
  }
@@ -1566,7 +1575,7 @@ function $133484ef10e4e954$export$dd948f91abc3a1c4(_ref) {
1566
1575
  });
1567
1576
  const render_checkbox = checkbox => {
1568
1577
  // Checkbox always calls the getters in props, so we don't wrap these values into memos
1569
- return $8tj43$createComponent((0, $6b73914551534ea8$export$48513f6b9f8ce62d), {
1578
+ return $8tj43$createComponent((0, $19e828709c7723a0$export$48513f6b9f8ce62d), {
1570
1579
  get value_() {
1571
1580
  return checkbox().value_;
1572
1581
  },
@@ -2310,7 +2319,7 @@ function $0ae614c5c7babb43$var$render_stuff(data, existing_filter, i18n_) {
2310
2319
  [_el$8, _co$3] = $8tj43$getNextMarker(_el$7.nextSibling),
2311
2320
  _el$9 = _el$8.nextSibling,
2312
2321
  [_el$10, _co$4] = $8tj43$getNextMarker(_el$9.nextSibling);
2313
- $8tj43$insert(_el$6, $8tj43$createComponent((0, $6b73914551534ea8$export$48513f6b9f8ce62d), {
2322
+ $8tj43$insert(_el$6, $8tj43$createComponent((0, $19e828709c7723a0$export$48513f6b9f8ce62d), {
2314
2323
  get value_() {
2315
2324
  var _value2;
2316
2325
  return JSON.stringify((_value2 = value()) === null || _value2 === void 0 ? void 0 : _value2.value_);
@@ -2600,9 +2609,27 @@ function $0ae614c5c7babb43$var$expand_until_choice(data_structure) {
2600
2609
  }
2601
2610
  });
2602
2611
  }
2603
- 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),
2604
2629
  $830ea8efda59884e$var$_tmpl$2 = /*#__PURE__*/$8tj43$template(`<span class="count-wrapper"><span class="count"></span></span>`, 4),
2605
- $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;
2606
2633
  const $830ea8efda59884e$export$414f6a19d38e655c = _ref => {
2607
2634
  let {
2608
2635
  filter_: filter_,
@@ -2632,77 +2659,187 @@ const $830ea8efda59884e$export$414f6a19d38e655c = _ref => {
2632
2659
  };
2633
2660
  });
2634
2661
  });
2635
- 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 = (() => {
2636
2676
  const _el$ = $8tj43$getNextElement($830ea8efda59884e$var$_tmpl$);
2637
- $8tj43$insert(_el$, $8tj43$createComponent((0, $8tj43$Index), {
2638
- get each() {
2639
- return buttons();
2640
- },
2641
- children: value => {
2642
- const is_selected = $8tj43$createMemo(() => {
2643
- var _existing_filter, _existing_filter$data;
2644
- 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_);
2645
- });
2646
- return (() => {
2647
- const _el$2 = $8tj43$getNextElement($830ea8efda59884e$var$_tmpl$3),
2648
- _el$5 = _el$2.firstChild,
2649
- [_el$6, _co$] = $8tj43$getNextMarker(_el$5.nextSibling),
2650
- _el$7 = _el$6.nextSibling,
2651
- [_el$8, _co$2] = $8tj43$getNextMarker(_el$7.nextSibling);
2652
- $8tj43$addEventListener(_el$2, "click", $8tj43$catchify(() => {
2653
- const set_filter = existing_filter();
2654
- const {
2655
- field: field,
2656
- op: op
2657
- } = filter_();
2658
- const base_object = set_filter ? set_filter : {
2659
- op: op,
2660
- field: field
2661
- };
2662
- const old_data = base_object.data;
2663
- const new_data = [...(Array.isArray(old_data) ? [...old_data] : old_data ? [old_data] : [])];
2664
- const new_filter_object = {
2665
- ...base_object,
2666
- data: new_data
2667
- };
2668
- if (!is_selected()) new_filter_object.data.push(value().value_);else new_filter_object.data = new_filter_object.data.filter(v => v !== value().value_);
2669
- const selected_filters = [...get_selected_filters().filter(f => f !== set_filter), ...(new_filter_object.data.length ? [new_filter_object] : [])];
2670
- set_selected_filters(selected_filters);
2671
- }), true);
2672
- $8tj43$insert(_el$2, () => value().value_, _el$6, _co$);
2673
- $8tj43$insert(_el$2, $8tj43$createComponent((0, $8tj43$Show), {
2674
- get when() {
2675
- return value().count_ != undefined;
2676
- },
2677
- get children() {
2678
- const _el$3 = $8tj43$getNextElement($830ea8efda59884e$var$_tmpl$2),
2679
- _el$4 = _el$3.firstChild;
2680
- $8tj43$insert(_el$4, () => value().count_);
2681
- return _el$3;
2682
- }
2683
- }), _el$8, _co$2);
2684
- $8tj43$effect(_p$ => {
2685
- const _v$ = value().count_ === 0 && !is_selected(),
2686
- _v$2 = !is_selected(),
2687
- _v$3 = !!is_selected();
2688
- _v$ !== _p$._v$ && (_el$2.disabled = _p$._v$ = _v$);
2689
- _v$2 !== _p$._v$2 && _el$2.classList.toggle("minor", _p$._v$2 = _v$2);
2690
- _v$3 !== _p$._v$3 && _el$2.classList.toggle("major", _p$._v$3 = _v$3);
2691
- return _p$;
2692
- }, {
2693
- _v$: undefined,
2694
- _v$2: undefined,
2695
- _v$3: undefined
2696
- });
2697
- $8tj43$runHydrationEvents();
2698
- return _el$2;
2699
- })();
2700
- }
2701
- }));
2677
+ $8tj43$insert(_el$, () => [...shadow_children()]);
2702
2678
  return _el$;
2703
- })();
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
+ })];
2704
2784
  };
2705
- $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
+ }
2706
2843
  function $00a5b94f0c11efbb$export$d9f36cf74e24d595(media_query) {
2707
2844
  const signal = $8tj43$createSignal(false);
2708
2845
  $8tj43$onCleanup($8tj43$javascript_media_query(media_query, _ref => {
@@ -2761,7 +2898,7 @@ function $2cb856c297c53e6c$export$82ed4b28ecb67608(_ref) {
2761
2898
  });
2762
2899
  const rgb_color = $8tj43$createMemo(() => $8tj43$hex_to_rgb(hex_color()));
2763
2900
  const black_contrast_better = $8tj43$createMemo(() => rgb_color() ? $2cb856c297c53e6c$var$does_black_contrast_better(rgb_color()) : false);
2764
- const input_row = $8tj43$createComponent((0, $6b73914551534ea8$export$48513f6b9f8ce62d), {
2901
+ const input_row = $8tj43$createComponent((0, $19e828709c7723a0$export$48513f6b9f8ce62d), {
2765
2902
  get value_() {
2766
2903
  return checkbox().value_;
2767
2904
  },