@depict-ai/ui 2.0.4 → 2.0.6

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.4";
11
+ const $8db9a15135765c11$export$83d89fbfd8236492 = "2.0.6";
12
12
 
13
13
  /** @jsxImportSource solid-js */
14
14
 
@@ -1789,6 +1789,9 @@ function $1e7465a8ffa97f6c$export$e0d834a0ad870cda(_ref) {
1789
1789
  selected_filters_: selected_filters_,
1790
1790
  i18n_: i18n_
1791
1791
  } = _ref;
1792
+ // If you ever attempt to implement that one can drag one range "knob" over the other like on prisjakt, see https://gitlab.com/depict-ai/depict.ai/-/merge_requests/8458/diffs?commit_id=c52dbdd15ca073489bee138b15d27bb6bf2992df
1793
+ // The issue with it is that one wants to discard the changes to the lower value as soon as the lower value has become the upper value when dragging the initially lower knob over the initially upper knob
1794
+ // But we can't reliably know when we've started dragging/changing the value (or at least I gave up at that point for now)
1792
1795
  const current_range = $8tj43$createSignal($8tj43$untrack(() => filter_().data));
1793
1796
  const selected_filter = $8tj43$createMemo(() => selected_filters_[0]().find(_ref2 => {
1794
1797
  let {
@@ -1858,6 +1861,7 @@ function $1e7465a8ffa97f6c$var$RangeSelector(_ref3) {
1858
1861
  const [get_current_range] = current_range_;
1859
1862
  const pre_price = $8tj43$createMemo(() => price_formatting_().pre_);
1860
1863
  const post_price = $8tj43$createMemo(() => price_formatting_().post_);
1864
+ const should_be_disabled_ = $8tj43$createMemo(() => Math.abs(min_() - max_()) < 2);
1861
1865
  return (() => {
1862
1866
  const _el$ = $8tj43$getNextElement($1e7465a8ffa97f6c$var$_tmpl$),
1863
1867
  _el$2 = _el$.firstChild,
@@ -1905,7 +1909,8 @@ function $1e7465a8ffa97f6c$var$RangeSelector(_ref3) {
1905
1909
  max_: max_,
1906
1910
  min_: min_,
1907
1911
  current_range_: current_range_,
1908
- i18n_: i18n_
1912
+ i18n_: i18n_,
1913
+ should_be_disabled_: should_be_disabled_
1909
1914
  }), _el$24, _co$7);
1910
1915
  $8tj43$insert(_el$9, pre_price, _el$11, _co$);
1911
1916
  $8tj43$insert(_el$9, $8tj43$createComponent((0, $60ec7a29849d81db$export$a71e92cfbb498adc), {
@@ -1928,18 +1933,24 @@ function $1e7465a8ffa97f6c$var$RangeSelector(_ref3) {
1928
1933
  }), _el$20, _co$5);
1929
1934
  $8tj43$insert(_el$16, post_price, _el$22, _co$6);
1930
1935
  $8tj43$effect(_p$ => {
1931
- const _v$ = i18n_.range_filter_low_point_aria_label_(),
1932
- _v$2 = min_(),
1933
- _v$3 = max_(),
1934
- _v$4 = i18n_.range_filter_high_point_aria_label_(),
1935
- _v$5 = min_(),
1936
- _v$6 = max_();
1937
- _v$ !== _p$._v$ && $8tj43$setAttribute(_el$4, "aria-label", _p$._v$ = _v$);
1938
- _v$2 !== _p$._v$2 && $8tj43$setAttribute(_el$4, "min", _p$._v$2 = _v$2);
1939
- _v$3 !== _p$._v$3 && $8tj43$setAttribute(_el$4, "max", _p$._v$3 = _v$3);
1940
- _v$4 !== _p$._v$4 && $8tj43$setAttribute(_el$7, "aria-label", _p$._v$4 = _v$4);
1941
- _v$5 !== _p$._v$5 && $8tj43$setAttribute(_el$7, "min", _p$._v$5 = _v$5);
1942
- _v$6 !== _p$._v$6 && $8tj43$setAttribute(_el$7, "max", _p$._v$6 = _v$6);
1936
+ const _v$ = !!(min_() === max_()),
1937
+ _v$2 = should_be_disabled_(),
1938
+ _v$3 = i18n_.range_filter_low_point_aria_label_(),
1939
+ _v$4 = min_(),
1940
+ _v$5 = max_(),
1941
+ _v$6 = should_be_disabled_(),
1942
+ _v$7 = i18n_.range_filter_high_point_aria_label_(),
1943
+ _v$8 = min_(),
1944
+ _v$9 = max_();
1945
+ _v$ !== _p$._v$ && _el$.classList.toggle("disabled", _p$._v$ = _v$);
1946
+ _v$2 !== _p$._v$2 && (_el$4.disabled = _p$._v$2 = _v$2);
1947
+ _v$3 !== _p$._v$3 && $8tj43$setAttribute(_el$4, "aria-label", _p$._v$3 = _v$3);
1948
+ _v$4 !== _p$._v$4 && $8tj43$setAttribute(_el$4, "min", _p$._v$4 = _v$4);
1949
+ _v$5 !== _p$._v$5 && $8tj43$setAttribute(_el$4, "max", _p$._v$5 = _v$5);
1950
+ _v$6 !== _p$._v$6 && (_el$7.disabled = _p$._v$6 = _v$6);
1951
+ _v$7 !== _p$._v$7 && $8tj43$setAttribute(_el$7, "aria-label", _p$._v$7 = _v$7);
1952
+ _v$8 !== _p$._v$8 && $8tj43$setAttribute(_el$7, "min", _p$._v$8 = _v$8);
1953
+ _v$9 !== _p$._v$9 && $8tj43$setAttribute(_el$7, "max", _p$._v$9 = _v$9);
1943
1954
  return _p$;
1944
1955
  }, {
1945
1956
  _v$: undefined,
@@ -1947,7 +1958,10 @@ function $1e7465a8ffa97f6c$var$RangeSelector(_ref3) {
1947
1958
  _v$3: undefined,
1948
1959
  _v$4: undefined,
1949
1960
  _v$5: undefined,
1950
- _v$6: undefined
1961
+ _v$6: undefined,
1962
+ _v$7: undefined,
1963
+ _v$8: undefined,
1964
+ _v$9: undefined
1951
1965
  });
1952
1966
  $8tj43$effect(() => _el$4.value = get_current_range()[0]);
1953
1967
  $8tj43$effect(() => _el$7.value = get_current_range()[1]);
@@ -1960,7 +1974,8 @@ function $1e7465a8ffa97f6c$var$ExponentialSlider(_ref6) {
1960
1974
  current_range_: current_range_,
1961
1975
  min_: min_,
1962
1976
  i18n_: i18n_,
1963
- max_: max_
1977
+ max_: max_,
1978
+ should_be_disabled_: should_be_disabled_
1964
1979
  } = _ref6;
1965
1980
  // inspired by https://observablehq.com/@mbostock/nonlinear-slider
1966
1981
  const transform_linear_to_nonlinear = _ref7 => {
@@ -1968,8 +1983,7 @@ function $1e7465a8ffa97f6c$var$ExponentialSlider(_ref6) {
1968
1983
  return [Math.sqrt(smaller), Math.sqrt(larger)];
1969
1984
  };
1970
1985
  const [read_current_range, write_current_range] = current_range_;
1971
- const modified_range = $8tj43$createSignal(transform_linear_to_nonlinear($8tj43$untrack(read_current_range)));
1972
- const [read_modified_range, write_modified_range] = modified_range;
1986
+ const modified_range_accessor = $8tj43$createMemo(() => transform_linear_to_nonlinear(read_current_range()));
1973
1987
  const modified_max = $8tj43$createMemo(() => Math.sqrt(max_()));
1974
1988
  const modified_min = $8tj43$createMemo(() => Math.sqrt(min_()));
1975
1989
  const offset_value_calculator_ = (value, how_many) => {
@@ -1977,42 +1991,49 @@ function $1e7465a8ffa97f6c$var$ExponentialSlider(_ref6) {
1977
1991
  const changed = number_in_linear + how_many;
1978
1992
  return Math.sqrt(changed);
1979
1993
  };
1980
- $8tj43$createComputed($8tj43$on(read_current_range, new_range_from_above => {
1981
- // to prevent from infinite looping, don't write if it's around the same
1982
- const new_modified_range = transform_linear_to_nonlinear(new_range_from_above);
1983
- const current_modified_range = read_modified_range();
1984
- if (!current_modified_range.every((item, index) => Math.round(item) === Math.round(new_modified_range[index]))) write_modified_range(new_modified_range);
1985
- }, {
1986
- defer: true
1987
- }));
1988
- $8tj43$createComputed($8tj43$on(read_modified_range, _ref8 => {
1989
- let [smaller, larger] = _ref8;
1990
- return write_current_range([Math.round(smaller * smaller), Math.round(larger * larger)]);
1991
- }, {
1992
- defer: true
1993
- }));
1994
+ const convert_back = (smaller, larger) => [Math.round(smaller * smaller), Math.round(larger * larger)];
1995
+ const modified_range_setter = new_range_or_function => {
1996
+ const old_range = $8tj43$untrack(modified_range_accessor);
1997
+ const new_range = typeof new_range_or_function === "function" ? new_range_or_function(old_range) : new_range_or_function;
1998
+ const [smaller, larger] = new_range;
1999
+ const [old_smaller, old_larger] = old_range;
2000
+ const new_range_converted = convert_back(smaller, larger);
2001
+ const old_range_converted = convert_back(old_smaller, old_larger);
2002
+ if (new_range_converted[0] === old_range_converted[0] && new_range_converted[1] === old_range_converted[1])
2003
+ // If the new value gets identical rounding errors to the old value when being converted back, don't write it to the signal since it would cause an infinite loop
2004
+ return new_range;
2005
+ write_current_range(new_range_converted);
2006
+ return new_range;
2007
+ };
1994
2008
  return $1e7465a8ffa97f6c$var$LinearSlider({
1995
- current_range_: modified_range,
2009
+ current_range_: [modified_range_accessor, modified_range_setter],
2010
+ // "Lie" to the actual slider so we don't have to implement exponential handling in there
1996
2011
  min_: modified_min,
1997
2012
  max_: modified_max,
1998
2013
  offset_value_calculator_: offset_value_calculator_,
1999
- i18n_: i18n_
2014
+ i18n_: i18n_,
2015
+ should_be_disabled_: should_be_disabled_
2000
2016
  });
2001
2017
  }
2002
- function $1e7465a8ffa97f6c$var$LinearSlider(_ref9) {
2018
+ function $1e7465a8ffa97f6c$var$LinearSlider(_ref8) {
2003
2019
  let {
2004
2020
  max_: max_,
2005
2021
  min_: min_,
2006
2022
  current_range_: current_range_,
2007
2023
  offset_value_calculator_: offset_value_calculator_,
2008
- i18n_: i18n_
2009
- } = _ref9;
2024
+ i18n_: i18n_,
2025
+ should_be_disabled_: should_be_disabled_
2026
+ } = _ref8;
2010
2027
  let range_input_1;
2011
2028
  let range_input_2;
2012
2029
  let clickable_slider;
2013
2030
  const [get_current_range, set_current_range] = current_range_;
2014
2031
  const progress_styling = $8tj43$createMemo(() => {
2015
- return "left:".concat(get_current_range()[0] / max_() * 100, "%;right:").concat(100 - get_current_range()[1] / max_() * 100, "%");
2032
+ const min = min_();
2033
+ const span = max_() - min;
2034
+ const [start, end] = get_current_range();
2035
+ if (should_be_disabled_()) return "left:50%;right:50%";
2036
+ return "left:".concat((start - min) / span * 100, "%;right:").concat(100 - (end - min) / span * 100, "%");
2016
2037
  });
2017
2038
  const set_value = (el, index) => {
2018
2039
  // initially I set the value on the elements by just having value={get_current_range()[0]}
@@ -2035,7 +2056,7 @@ function $1e7465a8ffa97f6c$var$LinearSlider(_ref9) {
2035
2056
  const click_from_left_in_slider = e.clientX - slider_beginning_left; // both of these value contain scroll position so this should work regardless of horisontal scroll if there is any
2036
2057
  const place_of_click_in_percent = click_from_left_in_slider / slider_width * 100;
2037
2058
  const one_percent_of_range = (max_() - min_()) / 100;
2038
- const place_of_click = Math.round(min_() + one_percent_of_range * place_of_click_in_percent);
2059
+ const place_of_click = min_() + one_percent_of_range * place_of_click_in_percent;
2039
2060
  const [lower, upper] = get_current_range();
2040
2061
  const distance_to_lower_point = Math.abs(place_of_click - lower);
2041
2062
  const distance_to_upper_point = Math.abs(upper - place_of_click);
@@ -2061,26 +2082,32 @@ function $1e7465a8ffa97f6c$var$LinearSlider(_ref9) {
2061
2082
  }, _el$29);
2062
2083
  $8tj43$addEventListener(_el$29, "input", $8tj43$catchify(() => $1e7465a8ffa97f6c$var$set_range_with_sanitation(min_, max_, current_range_, 1, range_input_2, offset_value_calculator_)), true);
2063
2084
  $8tj43$effect(_p$ => {
2064
- const _v$7 = i18n_.range_filter_low_point_aria_label_(),
2065
- _v$8 = min_(),
2066
- _v$9 = max_(),
2067
- _v$10 = i18n_.range_filter_high_point_aria_label_(),
2068
- _v$11 = min_(),
2069
- _v$12 = max_();
2070
- _v$7 !== _p$._v$7 && $8tj43$setAttribute(_el$28, "aria-label", _p$._v$7 = _v$7);
2071
- _v$8 !== _p$._v$8 && $8tj43$setAttribute(_el$28, "min", _p$._v$8 = _v$8);
2072
- _v$9 !== _p$._v$9 && $8tj43$setAttribute(_el$28, "max", _p$._v$9 = _v$9);
2073
- _v$10 !== _p$._v$10 && $8tj43$setAttribute(_el$29, "aria-label", _p$._v$10 = _v$10);
2074
- _v$11 !== _p$._v$11 && $8tj43$setAttribute(_el$29, "min", _p$._v$11 = _v$11);
2075
- _v$12 !== _p$._v$12 && $8tj43$setAttribute(_el$29, "max", _p$._v$12 = _v$12);
2085
+ const _v$10 = should_be_disabled_(),
2086
+ _v$11 = i18n_.range_filter_low_point_aria_label_(),
2087
+ _v$12 = min_(),
2088
+ _v$13 = max_(),
2089
+ _v$14 = should_be_disabled_(),
2090
+ _v$15 = i18n_.range_filter_high_point_aria_label_(),
2091
+ _v$16 = min_(),
2092
+ _v$17 = max_();
2093
+ _v$10 !== _p$._v$10 && (_el$28.disabled = _p$._v$10 = _v$10);
2094
+ _v$11 !== _p$._v$11 && $8tj43$setAttribute(_el$28, "aria-label", _p$._v$11 = _v$11);
2095
+ _v$12 !== _p$._v$12 && $8tj43$setAttribute(_el$28, "min", _p$._v$12 = _v$12);
2096
+ _v$13 !== _p$._v$13 && $8tj43$setAttribute(_el$28, "max", _p$._v$13 = _v$13);
2097
+ _v$14 !== _p$._v$14 && (_el$29.disabled = _p$._v$14 = _v$14);
2098
+ _v$15 !== _p$._v$15 && $8tj43$setAttribute(_el$29, "aria-label", _p$._v$15 = _v$15);
2099
+ _v$16 !== _p$._v$16 && $8tj43$setAttribute(_el$29, "min", _p$._v$16 = _v$16);
2100
+ _v$17 !== _p$._v$17 && $8tj43$setAttribute(_el$29, "max", _p$._v$17 = _v$17);
2076
2101
  return _p$;
2077
2102
  }, {
2078
- _v$7: undefined,
2079
- _v$8: undefined,
2080
- _v$9: undefined,
2081
2103
  _v$10: undefined,
2082
2104
  _v$11: undefined,
2083
- _v$12: undefined
2105
+ _v$12: undefined,
2106
+ _v$13: undefined,
2107
+ _v$14: undefined,
2108
+ _v$15: undefined,
2109
+ _v$16: undefined,
2110
+ _v$17: undefined
2084
2111
  });
2085
2112
  $8tj43$effect(() => _el$28.value = $8tj43$createMemo(() => {
2086
2113
  min_();
@@ -2390,59 +2417,62 @@ function $0ae614c5c7babb43$var$render_stuff(data, existing_filter, i18n_) {
2390
2417
  return has_expandable();
2391
2418
  },
2392
2419
  get children() {
2393
- return $8tj43$createComponent((0, $ad371564683947ab$export$6c6d7a51fa9aa15d), {
2394
- get details_() {
2395
- return $8tj43$getNextElement($0ae614c5c7babb43$var$_tmpl$3);
2396
- },
2397
- get summary_() {
2398
- return (() => {
2399
- const _el$12 = $8tj43$getNextElement($0ae614c5c7babb43$var$_tmpl$4),
2400
- _el$13 = _el$12.firstChild,
2401
- _el$14 = _el$13.firstChild,
2402
- _el$15 = _el$14.nextSibling,
2403
- [_el$16, _co$5] = $8tj43$getNextMarker(_el$15.nextSibling);
2404
- $8tj43$insert(_el$14, () => {
2405
- var _value10;
2406
- return (_value10 = value()) === null || _value10 === void 0 ? void 0 : _value10.count_;
2407
- });
2408
- $8tj43$insert(_el$13, $8tj43$createComponent((0, $457279ff15864cb9$export$e5c2828934226505), {
2409
- i18n_: i18n_,
2410
- get expanded_() {
2411
- return $8tj43$createMemo(() => {
2412
- var _value$is_expanded_$u, _value11, _value11$is_expanded_, _value11$is_expanded_2;
2413
- return (_value$is_expanded_$u = (_value11 = value()) === null || _value11 === void 0 ? void 0 : (_value11$is_expanded_ = _value11.is_expanded_) === null || _value11$is_expanded_ === void 0 ? void 0 : (_value11$is_expanded_2 = _value11$is_expanded_.ui_should_show_expanded_) === null || _value11$is_expanded_2 === void 0 ? void 0 : _value11$is_expanded_2.call(_value11$is_expanded_)) !== null && _value$is_expanded_$u !== void 0 ? _value$is_expanded_$u : false;
2414
- });
2415
- }
2416
- }), _el$16, _co$5);
2417
- $8tj43$effect(() => {
2418
- var _value12;
2419
- return _el$14.classList.toggle("count-0", !!(((_value12 = value()) === null || _value12 === void 0 ? void 0 : _value12.count_) === 0));
2420
- });
2421
- return _el$12;
2422
- })();
2423
- },
2424
- get is_open_() {
2425
- return $8tj43$createMemo(() => {
2426
- const v = value();
2427
- if (!v)
2428
- // only to prevent cleanup errors
2429
- return $8tj43$createSignal(false);
2430
- const {
2431
- is_expanded_: {
2432
- ui_should_show_expanded_: ui_should_show_expanded_,
2433
- set_user_expanded_: set_user_expanded_
2434
- }
2435
- } = v;
2436
- return [ui_should_show_expanded_, set_user_expanded_];
2437
- })();
2438
- },
2439
- get children() {
2440
- return $0ae614c5c7babb43$var$render_stuff($8tj43$createMemo(() => {
2441
- var _value13;
2442
- return ((_value13 = value()) === null || _value13 === void 0 ? void 0 : _value13.children_) || {};
2443
- }), existing_filter, i18n_);
2444
- }
2445
- });
2420
+ return (() => {
2421
+ const is_open = $8tj43$createMemo(() => {
2422
+ const v = value();
2423
+ if (!v)
2424
+ // only to prevent cleanup errors
2425
+ return $8tj43$createSignal(false);
2426
+ const {
2427
+ is_expanded_: {
2428
+ ui_should_show_expanded_: ui_should_show_expanded_,
2429
+ set_user_expanded_: set_user_expanded_
2430
+ }
2431
+ } = v;
2432
+ return [ui_should_show_expanded_, set_user_expanded_];
2433
+ });
2434
+ return $8tj43$createComponent((0, $ad371564683947ab$export$6c6d7a51fa9aa15d), {
2435
+ get details_() {
2436
+ return $8tj43$getNextElement($0ae614c5c7babb43$var$_tmpl$3);
2437
+ },
2438
+ get summary_() {
2439
+ return (() => {
2440
+ const _el$12 = $8tj43$getNextElement($0ae614c5c7babb43$var$_tmpl$4),
2441
+ _el$13 = _el$12.firstChild,
2442
+ _el$14 = _el$13.firstChild,
2443
+ _el$15 = _el$14.nextSibling,
2444
+ [_el$16, _co$5] = $8tj43$getNextMarker(_el$15.nextSibling);
2445
+ $8tj43$insert(_el$14, () => {
2446
+ var _value10;
2447
+ return (_value10 = value()) === null || _value10 === void 0 ? void 0 : _value10.count_;
2448
+ });
2449
+ $8tj43$insert(_el$13, $8tj43$createComponent((0, $457279ff15864cb9$export$e5c2828934226505), {
2450
+ i18n_: i18n_,
2451
+ get expanded_() {
2452
+ return $8tj43$createMemo(() => {
2453
+ var _value$is_expanded_$u, _value11, _value11$is_expanded_, _value11$is_expanded_2;
2454
+ return (_value$is_expanded_$u = (_value11 = value()) === null || _value11 === void 0 ? void 0 : (_value11$is_expanded_ = _value11.is_expanded_) === null || _value11$is_expanded_ === void 0 ? void 0 : (_value11$is_expanded_2 = _value11$is_expanded_.ui_should_show_expanded_) === null || _value11$is_expanded_2 === void 0 ? void 0 : _value11$is_expanded_2.call(_value11$is_expanded_)) !== null && _value$is_expanded_$u !== void 0 ? _value$is_expanded_$u : false;
2455
+ });
2456
+ }
2457
+ }), _el$16, _co$5);
2458
+ $8tj43$effect(() => {
2459
+ var _value12;
2460
+ return _el$14.classList.toggle("count-0", !!(((_value12 = value()) === null || _value12 === void 0 ? void 0 : _value12.count_) === 0));
2461
+ });
2462
+ return _el$12;
2463
+ })();
2464
+ },
2465
+ get is_open_() {
2466
+ return is_open();
2467
+ },
2468
+ get children() {
2469
+ return $0ae614c5c7babb43$var$render_stuff($8tj43$createMemo(() => {
2470
+ var _value13;
2471
+ return ((_value13 = value()) === null || _value13 === void 0 ? void 0 : _value13.children_) || {};
2472
+ }), existing_filter, i18n_);
2473
+ }
2474
+ });
2475
+ })();
2446
2476
  }
2447
2477
  }), _el$10, _co$4);
2448
2478
  $8tj43$effect(() => _el$6.classList.toggle("expandable", !!has_expandable()));
@@ -2510,7 +2540,7 @@ function $0ae614c5c7babb43$var$create_updating_signal(_ref3) {
2510
2540
  // wait for the children to have populated and us to have received the correct value_ and name_ values
2511
2541
  let updating_blocked = false;
2512
2542
  const index_of_us_in_selected_filter = existing_filter_ === null || existing_filter_ === void 0 ? void 0 : (_existing_filter_$dat = existing_filter_.data) === null || _existing_filter_$dat === void 0 ? void 0 : (_existing_filter_$dat2 = _existing_filter_$dat.findIndex) === null || _existing_filter_$dat2 === void 0 ? void 0 : _existing_filter_$dat2.call(_existing_filter_$dat, el => el.length === self_.value_.length && el.every((sub_el, index) => self_.value_[index] === sub_el));
2513
- signal_.push(...$8tj43$createSignal(index_of_us_in_selected_filter >= 0 ? true : false));
2543
+ signal_.push(...$8tj43$createSignal(index_of_us_in_selected_filter >= 0));
2514
2544
  const [read_checked, write_checked] = signal_;
2515
2545
  const child_objects = Object.values(self_.children_);
2516
2546
  const get_child_object_values = child_objects.map(_ref4 => {