@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/latest/index.cjs CHANGED
@@ -60,7 +60,7 @@ $parcel$export(module.exports, "defaultColsAtSize", () => $a3280f0aad997933$expo
60
60
  $parcel$export(module.exports, "defaultCategoryTitlePlugin", () => $a3280f0aad997933$export$7bf543b9d9be2c22);
61
61
  $parcel$export(module.exports, "version", () => $b757f75811f3261f$export$83d89fbfd8236492);
62
62
  /*! Depict.ai search and product listing SDK */
63
- const $b757f75811f3261f$export$83d89fbfd8236492 = "2.0.1";
63
+ const $b757f75811f3261f$export$83d89fbfd8236492 = "2.0.2";
64
64
  const $4e04be41243c3d80$var$transform_elements = sorted_cols_at_size => {
65
65
  const cols_at_size = [];
66
66
  for (let i = 0; i < sorted_cols_at_size.length; i++) {
@@ -1417,9 +1417,9 @@ function $235a2771a44e28e9$export$fecbb157621501bd({
1417
1417
  return outmost_element;
1418
1418
  }
1419
1419
  $gVhhF$solidjsweb.delegateEvents(["click"]);
1420
- const $b3cf6ca8dc0e9998$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<span class="count"></span>`, 2),
1421
- $b3cf6ca8dc0e9998$var$_tmpl$2 = /*#__PURE__*/$gVhhF$solidjsweb.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);
1422
- const $b3cf6ca8dc0e9998$export$48513f6b9f8ce62d = props => {
1420
+ const $1c63082b2da848ad$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<span class="count"></span>`, 2),
1421
+ $1c63082b2da848ad$var$_tmpl$2 = /*#__PURE__*/$gVhhF$solidjsweb.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);
1422
+ const $1c63082b2da848ad$export$48513f6b9f8ce62d = props => {
1423
1423
  // 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
1424
1424
  const count = $gVhhF$solidjs.createMemo(() => props.count_);
1425
1425
  const label = $gVhhF$solidjs.createMemo(() => props.label_);
@@ -1428,7 +1428,7 @@ const $b3cf6ca8dc0e9998$export$48513f6b9f8ce62d = props => {
1428
1428
  const is_count_zero = $gVhhF$solidjs.createMemo(() => props.is_count_zero_ || count() === 0);
1429
1429
  const id = $gVhhF$depictaiutilishared.make_random_classname();
1430
1430
  return (/* We can't use actual margin because ExpandingContainer gets messed up */(() => {
1431
- const _el$ = $gVhhF$solidjsweb.getNextElement($b3cf6ca8dc0e9998$var$_tmpl$2),
1431
+ const _el$ = $gVhhF$solidjsweb.getNextElement($1c63082b2da848ad$var$_tmpl$2),
1432
1432
  _el$2 = _el$.firstChild,
1433
1433
  _el$3 = _el$2.firstChild,
1434
1434
  _el$4 = _el$3.nextSibling,
@@ -1455,7 +1455,7 @@ const $b3cf6ca8dc0e9998$export$48513f6b9f8ce62d = props => {
1455
1455
  return count() != undefined;
1456
1456
  },
1457
1457
  get children() {
1458
- const _el$6 = $gVhhF$solidjsweb.getNextElement($b3cf6ca8dc0e9998$var$_tmpl$);
1458
+ const _el$6 = $gVhhF$solidjsweb.getNextElement($1c63082b2da848ad$var$_tmpl$);
1459
1459
  $gVhhF$solidjsweb.insert(_el$6, count);
1460
1460
  return _el$6;
1461
1461
  }
@@ -1543,7 +1543,7 @@ function $d94869c80e337a3d$export$dd948f91abc3a1c4({
1543
1543
  });
1544
1544
  const render_checkbox = checkbox => {
1545
1545
  // Checkbox always calls the getters in props, so we don't wrap these values into memos
1546
- return $gVhhF$solidjsweb.createComponent((0, $b3cf6ca8dc0e9998$export$48513f6b9f8ce62d), {
1546
+ return $gVhhF$solidjsweb.createComponent((0, $1c63082b2da848ad$export$48513f6b9f8ce62d), {
1547
1547
  get value_() {
1548
1548
  return checkbox().value_;
1549
1549
  },
@@ -2245,7 +2245,7 @@ function $3bdc00a1353c1150$var$render_stuff(data, existing_filter, i18n_) {
2245
2245
  [_el$8, _co$3] = $gVhhF$solidjsweb.getNextMarker(_el$7.nextSibling),
2246
2246
  _el$9 = _el$8.nextSibling,
2247
2247
  [_el$10, _co$4] = $gVhhF$solidjsweb.getNextMarker(_el$9.nextSibling);
2248
- $gVhhF$solidjsweb.insert(_el$6, $gVhhF$solidjsweb.createComponent((0, $b3cf6ca8dc0e9998$export$48513f6b9f8ce62d), {
2248
+ $gVhhF$solidjsweb.insert(_el$6, $gVhhF$solidjsweb.createComponent((0, $1c63082b2da848ad$export$48513f6b9f8ce62d), {
2249
2249
  get value_() {
2250
2250
  return JSON.stringify(value()?.value_);
2251
2251
  },
@@ -2499,9 +2499,26 @@ function $3bdc00a1353c1150$var$expand_until_choice(data_structure) {
2499
2499
  }
2500
2500
  });
2501
2501
  }
2502
- const $0ef1681699140f1a$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div class="checkbox-grid"></div>`, 2),
2502
+
2503
+ /** @jsxImportSource solid-js */
2504
+
2505
+ function $e5f442fb78c98741$export$9f191182275e9ef(what_to_watch) {
2506
+ const [size, setSize] = $gVhhF$solidjs.createSignal();
2507
+ const resizeObserver = new ResizeObserver($gVhhF$depictaiutilishared.catchify(records => {
2508
+ for (let j = 0; j < records.length; j++) {
2509
+ const width = records[j].borderBoxSize?.[0]?.inlineSize ?? what_to_watch.getBoundingClientRect().width;
2510
+ setSize(width);
2511
+ }
2512
+ }));
2513
+ resizeObserver.observe(what_to_watch);
2514
+ $gVhhF$solidjs.onCleanup(() => resizeObserver.disconnect());
2515
+ return size;
2516
+ }
2517
+ const $0ef1681699140f1a$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div class="checkbox-grid" style="position:absolute;z-index:-1;pointer-events:none;opacity:0"></div>`, 2),
2503
2518
  $0ef1681699140f1a$var$_tmpl$2 = /*#__PURE__*/$gVhhF$solidjsweb.template(`<span class="count-wrapper"><span class="count"></span></span>`, 4),
2504
- $0ef1681699140f1a$var$_tmpl$3 = /*#__PURE__*/$gVhhF$solidjsweb.template(`<button class="major-minor-transition"><!#><!/><!#><!/></button>`, 6);
2519
+ $0ef1681699140f1a$var$_tmpl$3 = /*#__PURE__*/$gVhhF$solidjsweb.template(`<button><!#><!/><!#><!/></button>`, 6);
2520
+ const $0ef1681699140f1a$var$gap_px = 5;
2521
+ const $0ef1681699140f1a$var$max_columns = 3;
2505
2522
  const $0ef1681699140f1a$export$414f6a19d38e655c = ({
2506
2523
  filter_: filter_,
2507
2524
  selected_filters_: [get_selected_filters, set_selected_filters]
@@ -2524,74 +2541,182 @@ const $0ef1681699140f1a$export$414f6a19d38e655c = ({
2524
2541
  count_: meta.counts?.[index]
2525
2542
  }));
2526
2543
  });
2527
- return (() => {
2544
+ const [sizes_set, set_sizes_set] = $gVhhF$solidjs.createSignal(new Set(), {
2545
+ equals: false
2546
+ });
2547
+ const [cols_at_size, set_cols_at_size] = $gVhhF$solidjs.createSignal([[1, "0px", ""]]);
2548
+ const [container, set_container] = $gVhhF$solidjs.createSignal();
2549
+ const container_width_accessor = $gVhhF$solidjs.createMemo(() => {
2550
+ const element = container();
2551
+ if (!element) return;
2552
+ return $e5f442fb78c98741$export$9f191182275e9ef(element);
2553
+ });
2554
+ const [shadow_children, set_shadow_children] = $gVhhF$solidjs.createSignal(new Set(), {
2555
+ equals: false
2556
+ });
2557
+ const shadow_grid = (() => {
2528
2558
  const _el$ = $gVhhF$solidjsweb.getNextElement($0ef1681699140f1a$var$_tmpl$);
2529
- $gVhhF$solidjsweb.insert(_el$, $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Index), {
2530
- get each() {
2531
- return buttons();
2532
- },
2533
- children: value => {
2534
- const is_selected = $gVhhF$solidjs.createMemo(() => existing_filter()?.data?.includes(value().value_));
2535
- return (() => {
2536
- const _el$2 = $gVhhF$solidjsweb.getNextElement($0ef1681699140f1a$var$_tmpl$3),
2537
- _el$5 = _el$2.firstChild,
2538
- [_el$6, _co$] = $gVhhF$solidjsweb.getNextMarker(_el$5.nextSibling),
2539
- _el$7 = _el$6.nextSibling,
2540
- [_el$8, _co$2] = $gVhhF$solidjsweb.getNextMarker(_el$7.nextSibling);
2541
- $gVhhF$solidjsweb.addEventListener(_el$2, "click", $gVhhF$depictaiutilishared.catchify(() => {
2542
- const set_filter = existing_filter();
2543
- const {
2544
- field: field,
2545
- op: op
2546
- } = filter_();
2547
- const base_object = set_filter ? set_filter : {
2548
- op: op,
2549
- field: field
2550
- };
2551
- const old_data = base_object.data;
2552
- const new_data = [...(Array.isArray(old_data) ? [...old_data] : old_data ? [old_data] : [])];
2553
- const new_filter_object = {
2554
- ...base_object,
2555
- data: new_data
2556
- };
2557
- if (!is_selected()) new_filter_object.data.push(value().value_);else new_filter_object.data = new_filter_object.data.filter(v => v !== value().value_);
2558
- const selected_filters = [...get_selected_filters().filter(f => f !== set_filter), ...(new_filter_object.data.length ? [new_filter_object] : [])];
2559
- set_selected_filters(selected_filters);
2560
- }), true);
2561
- $gVhhF$solidjsweb.insert(_el$2, () => value().value_, _el$6, _co$);
2562
- $gVhhF$solidjsweb.insert(_el$2, $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
2563
- get when() {
2564
- return value().count_ != undefined;
2565
- },
2566
- get children() {
2567
- const _el$3 = $gVhhF$solidjsweb.getNextElement($0ef1681699140f1a$var$_tmpl$2),
2568
- _el$4 = _el$3.firstChild;
2569
- $gVhhF$solidjsweb.insert(_el$4, () => value().count_);
2570
- return _el$3;
2571
- }
2572
- }), _el$8, _co$2);
2573
- $gVhhF$solidjsweb.effect(_p$ => {
2574
- const _v$ = value().count_ === 0 && !is_selected(),
2575
- _v$2 = !is_selected(),
2576
- _v$3 = !!is_selected();
2577
- _v$ !== _p$._v$ && (_el$2.disabled = _p$._v$ = _v$);
2578
- _v$2 !== _p$._v$2 && _el$2.classList.toggle("minor", _p$._v$2 = _v$2);
2579
- _v$3 !== _p$._v$3 && _el$2.classList.toggle("major", _p$._v$3 = _v$3);
2580
- return _p$;
2581
- }, {
2582
- _v$: undefined,
2583
- _v$2: undefined,
2584
- _v$3: undefined
2585
- });
2586
- $gVhhF$solidjsweb.runHydrationEvents();
2587
- return _el$2;
2588
- })();
2589
- }
2590
- }));
2559
+ $gVhhF$solidjsweb.insert(_el$, () => [...shadow_children()]);
2591
2560
  return _el$;
2592
- })();
2561
+ })(); // for getting the smallest possible sizes of all the items
2562
+ $gVhhF$solidjs.createEffect(() => {
2563
+ const container_width = container_width_accessor()?.();
2564
+ if (container_width == undefined) return;
2565
+ $0ef1681699140f1a$var$adjust_sizes(container_width, sizes_set(), set_cols_at_size);
2566
+ });
2567
+ return [shadow_grid, $gVhhF$solidjsweb.createComponent((0, $f48d0fbb00835aaa$export$d21e32dfedac04be), {
2568
+ get cols_at_size() {
2569
+ return cols_at_size();
2570
+ },
2571
+ grid_spacing: $0ef1681699140f1a$var$gap_px + "px",
2572
+ rows: "all",
2573
+ layout: "grid",
2574
+ element_attributes: {
2575
+ class: "checkbox-grid",
2576
+ ref: el => set_container(el)
2577
+ },
2578
+ get children() {
2579
+ return $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Index), {
2580
+ get each() {
2581
+ return buttons();
2582
+ },
2583
+ children: value => {
2584
+ const is_selected = $gVhhF$solidjs.createMemo(() => existing_filter()?.data?.includes(value().value_));
2585
+ const MakeButton = attributes => (() => {
2586
+ const _el$2 = $gVhhF$solidjsweb.getNextElement($0ef1681699140f1a$var$_tmpl$3),
2587
+ _el$5 = _el$2.firstChild,
2588
+ [_el$6, _co$] = $gVhhF$solidjsweb.getNextMarker(_el$5.nextSibling),
2589
+ _el$7 = _el$6.nextSibling,
2590
+ [_el$8, _co$2] = $gVhhF$solidjsweb.getNextMarker(_el$7.nextSibling);
2591
+ $gVhhF$solidjsweb.spread(_el$2, $gVhhF$solidjsweb.mergeProps(attributes, {
2592
+ get disabled() {
2593
+ return $gVhhF$solidjsweb.memo(() => value().count_ === 0)() && !is_selected();
2594
+ },
2595
+ get classList() {
2596
+ return {
2597
+ minor: !is_selected(),
2598
+ major: is_selected(),
2599
+ "major-minor-transition": true
2600
+ };
2601
+ },
2602
+ get onClick() {
2603
+ return $gVhhF$depictaiutilishared.catchify(() => {
2604
+ const set_filter = existing_filter();
2605
+ const {
2606
+ field: field,
2607
+ op: op
2608
+ } = filter_();
2609
+ const base_object = set_filter ? set_filter : {
2610
+ op: op,
2611
+ field: field
2612
+ };
2613
+ const old_data = base_object.data;
2614
+ const new_data = [...(Array.isArray(old_data) ? [...old_data] : old_data ? [old_data] : [])];
2615
+ const new_filter_object = {
2616
+ ...base_object,
2617
+ data: new_data
2618
+ };
2619
+ if (!is_selected()) new_filter_object.data.push(value().value_);else new_filter_object.data = new_filter_object.data.filter(v => v !== value().value_);
2620
+ const selected_filters = [...get_selected_filters().filter(f => f !== set_filter), ...(new_filter_object.data.length ? [new_filter_object] : [])];
2621
+ set_selected_filters(selected_filters);
2622
+ });
2623
+ }
2624
+ }), false, true);
2625
+ $gVhhF$solidjsweb.insert(_el$2, () => value().value_, _el$6, _co$);
2626
+ $gVhhF$solidjsweb.insert(_el$2, $gVhhF$solidjsweb.createComponent((0, $gVhhF$solidjs.Show), {
2627
+ get when() {
2628
+ return value().count_ != undefined;
2629
+ },
2630
+ get children() {
2631
+ const _el$3 = $gVhhF$solidjsweb.getNextElement($0ef1681699140f1a$var$_tmpl$2),
2632
+ _el$4 = _el$3.firstChild;
2633
+ $gVhhF$solidjsweb.insert(_el$4, () => value().count_);
2634
+ return _el$3;
2635
+ }
2636
+ }), _el$8, _co$2);
2637
+ $gVhhF$solidjsweb.runHydrationEvents();
2638
+ return _el$2;
2639
+ })();
2640
+ const invisible_size_button = $gVhhF$solidjsweb.createComponent(MakeButton, {});
2641
+ const smallest_possible_size = $e5f442fb78c98741$export$9f191182275e9ef(invisible_size_button); // create ResizeObserver for the invisible size button where the div hugs its content
2642
+ const sizes_value = $gVhhF$solidjs.untrack(sizes_set);
2643
+ const shadow_children_value = $gVhhF$solidjs.untrack(shadow_children);
2644
+ sizes_value.add(smallest_possible_size);
2645
+ set_sizes_set(sizes_value);
2646
+ shadow_children_value.add(invisible_size_button);
2647
+ set_shadow_children(shadow_children_value);
2648
+ $gVhhF$solidjs.onCleanup(() => {
2649
+ const sizes_value = $gVhhF$solidjs.untrack(sizes_set);
2650
+ const shadow_children_value = $gVhhF$solidjs.untrack(shadow_children);
2651
+ sizes_value.delete(smallest_possible_size);
2652
+ set_sizes_set(sizes_value);
2653
+ shadow_children_value.delete(invisible_size_button);
2654
+ set_shadow_children(shadow_children_value);
2655
+ });
2656
+ // The actual button that will be visible
2657
+ return $gVhhF$solidjsweb.createComponent(MakeButton, {});
2658
+ }
2659
+ });
2660
+ }
2661
+ })];
2593
2662
  };
2594
- $gVhhF$solidjsweb.delegateEvents(["click"]);
2663
+ /**
2664
+ * Calculate and apply cols_at_size overrides to fit as many items as possible in a row, evenly spaced
2665
+ */
2666
+ function $0ef1681699140f1a$var$adjust_sizes(container_width, sizes, set_cols_at_size) {
2667
+ let current_row_index = 0;
2668
+ let current_row_items = [];
2669
+ const column_to_row_result = {};
2670
+ const check_would_fit_evenly = (min_size_of_item, at_number_of_columnns) => {
2671
+ const would_have_even_size = container_width / at_number_of_columnns - (at_number_of_columnns * 2 - 2) * ($0ef1681699140f1a$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)
2672
+ 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
2673
+ };
2674
+
2675
+ for (const size_item of sizes) {
2676
+ const size = size_item();
2677
+ if (size == undefined) return; // Only do stuff if we know all the sizes
2678
+ const current_row_length = current_row_items.length;
2679
+ const can_add_another_column_initial_val = current_row_length < $0ef1681699140f1a$var$max_columns; // allow max 4 items per row
2680
+ let can_add_another_column = can_add_another_column_initial_val;
2681
+ if (can_add_another_column)
2682
+ // can we actually? Since adding another column changes the size of all elements in the row we need to check all of them
2683
+ for (let i = -1; i < current_row_length; i++) {
2684
+ // -1 is for the new item we're adding and every item is guaranteed to exist
2685
+ const size_to_check = current_row_items[i] ?? size;
2686
+ const would_have_columns = current_row_length + 1; // if we added another column
2687
+ const would_fit_evenly = check_would_fit_evenly(size_to_check, would_have_columns); // see comments in check_would_fit_evenly
2688
+ if (!would_fit_evenly) {
2689
+ can_add_another_column = false;
2690
+ break;
2691
+ }
2692
+ }
2693
+ if (can_add_another_column) current_row_items.push(size);else {
2694
+ column_to_row_result[++current_row_index] = current_row_length || 1; // overrides is indexed by 1 it seems, therefore ++curent_row_index
2695
+ current_row_items = [size]; // save current item for next row
2696
+ }
2697
+ }
2698
+
2699
+ const items_left_to_add = current_row_items.length;
2700
+ if (items_left_to_add) {
2701
+ let num_columns = 1; // We want to have as close to max_columns as possible in the last row
2702
+ let fits = true;
2703
+ do
2704
+ // Check if more columns would fit
2705
+ for (let i = 0; i < items_left_to_add; i++) {
2706
+ const item = current_row_items[i];
2707
+ const would_fit_evenly = check_would_fit_evenly(item, num_columns + 1);
2708
+ if (!would_fit_evenly) {
2709
+ fits = false;
2710
+ break;
2711
+ }
2712
+ } while (fits && ++num_columns < $0ef1681699140f1a$var$max_columns);
2713
+ column_to_row_result[++current_row_index] = num_columns; // Add last row that's left after loop finished
2714
+ }
2715
+
2716
+ set_cols_at_size([[1, "0px", "", null, {
2717
+ overrides: column_to_row_result
2718
+ }]]);
2719
+ }
2595
2720
  function $b54e6192d0caa293$export$d9f36cf74e24d595(media_query) {
2596
2721
  const signal = $gVhhF$solidjs.createSignal(false);
2597
2722
  $gVhhF$solidjs.onCleanup($gVhhF$depictaiutilishared.javascript_media_query(media_query, ({
@@ -2636,7 +2761,7 @@ function $b51a2b8b9355e66c$export$82ed4b28ecb67608({
2636
2761
  const hex_color = $gVhhF$solidjs.createMemo(() => checkbox().value_.split(";")?.[1] || "");
2637
2762
  const rgb_color = $gVhhF$solidjs.createMemo(() => $gVhhF$depictaiutilishared.hex_to_rgb(hex_color()));
2638
2763
  const black_contrast_better = $gVhhF$solidjs.createMemo(() => rgb_color() ? $b51a2b8b9355e66c$var$does_black_contrast_better(rgb_color()) : false);
2639
- const input_row = $gVhhF$solidjsweb.createComponent((0, $b3cf6ca8dc0e9998$export$48513f6b9f8ce62d), {
2764
+ const input_row = $gVhhF$solidjsweb.createComponent((0, $1c63082b2da848ad$export$48513f6b9f8ce62d), {
2640
2765
  get value_() {
2641
2766
  return checkbox().value_;
2642
2767
  },
package/latest/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import { CategorySuggestion, SearchSuggestionsResponse } from "@depict-ai/types/
7
7
  import { BaseSearchRequest } from "@depict-ai/types/api/BaseSearchRequest";
8
8
  import { SearchSuggestionsRequest } from "@depict-ai/types/api/SearchSuggestionsRequest";
9
9
  import { ProductListingRequest } from "@depict-ai/types/api/ProductListingRequest";
10
- export const version = "2.0.1";
10
+ export const version = "2.0.2";
11
11
  export type SDKGridSpacing = string | {
12
12
  horizontal: string;
13
13
  vertical: string;