@rufous/ui 0.2.91 → 0.2.93

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/dist/main.cjs CHANGED
@@ -1925,6 +1925,15 @@ function defaultGetLabel(option) {
1925
1925
  return String(option.label);
1926
1926
  return String(option);
1927
1927
  }
1928
+ function defaultIsEqual(a, b) {
1929
+ if (a === b) return true;
1930
+ if (a !== null && b !== null && typeof a === "object" && typeof b === "object") {
1931
+ const aVal = a.value;
1932
+ const bVal = b.value;
1933
+ if (aVal !== void 0 && bVal !== void 0) return aVal === bVal;
1934
+ }
1935
+ return false;
1936
+ }
1928
1937
  function defaultFilter(options, inputValue, getLabel) {
1929
1938
  if (!inputValue) return options;
1930
1939
  const q = inputValue.toLowerCase();
@@ -1967,6 +1976,7 @@ function AutocompleteInner(props, _ref) {
1967
1976
  } = props;
1968
1977
  const [open, setOpen] = (0, import_react18.useState)(false);
1969
1978
  const [inputStr, setInputStr] = (0, import_react18.useState)("");
1979
+ const [filterQuery, setFilterQuery] = (0, import_react18.useState)("");
1970
1980
  const [focusedIdx, setFocusedIdx] = (0, import_react18.useState)(-1);
1971
1981
  const [popupStyle, setPopupStyle] = (0, import_react18.useState)({});
1972
1982
  const containerRef = (0, import_react18.useRef)(null);
@@ -2007,14 +2017,14 @@ function AutocompleteInner(props, _ref) {
2007
2017
  const activeInput = controlledInput !== void 0 ? controlledInput : inputStr;
2008
2018
  const selectedValues = multiple ? Array.isArray(value) ? value : [] : value != null ? [value] : [];
2009
2019
  const isEqual = (0, import_react18.useCallback)(
2010
- (a, b) => isOptionEqualToValue ? isOptionEqualToValue(a, b) : a === b,
2020
+ (a, b) => isOptionEqualToValue ? isOptionEqualToValue(a, b) : defaultIsEqual(a, b),
2011
2021
  [isOptionEqualToValue]
2012
2022
  );
2013
2023
  const isSelected = (0, import_react18.useCallback)(
2014
2024
  (opt) => selectedValues.some((v) => isEqual(opt, v)),
2015
2025
  [selectedValues, isEqual]
2016
2026
  );
2017
- const filtered = filterOptions ? filterOptions(options, activeInput) : defaultFilter(options, activeInput, getOptionLabel);
2027
+ const filtered = filterOptions ? filterOptions(options, activeInput) : defaultFilter(options, filterQuery, getOptionLabel);
2018
2028
  const flatEntries = [];
2019
2029
  if (groupBy) {
2020
2030
  const groups = {};
@@ -2042,6 +2052,7 @@ function AutocompleteInner(props, _ref) {
2042
2052
  calcPopupStyle();
2043
2053
  setOpen(true);
2044
2054
  setFocusedIdx(-1);
2055
+ setFilterQuery("");
2045
2056
  onOpen?.();
2046
2057
  }, [disabled, calcPopupStyle, onOpen]);
2047
2058
  const closePopup = (0, import_react18.useCallback)((justSelected = false) => {
@@ -2086,11 +2097,13 @@ function AutocompleteInner(props, _ref) {
2086
2097
  const next = already ? selectedValues.filter((v) => !isEqual(v, opt)) : [...selectedValues, opt];
2087
2098
  onChange?.(event, next, already ? "removeOption" : "selectOption");
2088
2099
  setInputStr("");
2100
+ setFilterQuery("");
2089
2101
  onInputChange?.("");
2090
2102
  inputRef.current?.focus();
2091
2103
  } else {
2092
2104
  onChange?.(event, opt, "selectOption");
2093
2105
  setInputStr(getOptionLabel(opt));
2106
+ setFilterQuery("");
2094
2107
  onInputChange?.(getOptionLabel(opt));
2095
2108
  closePopup(true);
2096
2109
  }
@@ -2100,6 +2113,7 @@ function AutocompleteInner(props, _ref) {
2100
2113
  e.stopPropagation();
2101
2114
  onChange?.(e, multiple ? [] : null, "clear");
2102
2115
  setInputStr("");
2116
+ setFilterQuery("");
2103
2117
  onInputChange?.("");
2104
2118
  inputRef.current?.focus();
2105
2119
  };
@@ -2111,6 +2125,7 @@ function AutocompleteInner(props, _ref) {
2111
2125
  const handleInputChange = (e) => {
2112
2126
  const v = e.target.value;
2113
2127
  setInputStr(v);
2128
+ setFilterQuery(v);
2114
2129
  onInputChange?.(v);
2115
2130
  if (!open) openPopup();
2116
2131
  };
package/dist/main.js CHANGED
@@ -1764,6 +1764,15 @@ function defaultGetLabel(option) {
1764
1764
  return String(option.label);
1765
1765
  return String(option);
1766
1766
  }
1767
+ function defaultIsEqual(a, b) {
1768
+ if (a === b) return true;
1769
+ if (a !== null && b !== null && typeof a === "object" && typeof b === "object") {
1770
+ const aVal = a.value;
1771
+ const bVal = b.value;
1772
+ if (aVal !== void 0 && bVal !== void 0) return aVal === bVal;
1773
+ }
1774
+ return false;
1775
+ }
1767
1776
  function defaultFilter(options, inputValue, getLabel) {
1768
1777
  if (!inputValue) return options;
1769
1778
  const q = inputValue.toLowerCase();
@@ -1806,6 +1815,7 @@ function AutocompleteInner(props, _ref) {
1806
1815
  } = props;
1807
1816
  const [open, setOpen] = useState4(false);
1808
1817
  const [inputStr, setInputStr] = useState4("");
1818
+ const [filterQuery, setFilterQuery] = useState4("");
1809
1819
  const [focusedIdx, setFocusedIdx] = useState4(-1);
1810
1820
  const [popupStyle, setPopupStyle] = useState4({});
1811
1821
  const containerRef = useRef3(null);
@@ -1846,14 +1856,14 @@ function AutocompleteInner(props, _ref) {
1846
1856
  const activeInput = controlledInput !== void 0 ? controlledInput : inputStr;
1847
1857
  const selectedValues = multiple ? Array.isArray(value) ? value : [] : value != null ? [value] : [];
1848
1858
  const isEqual = useCallback(
1849
- (a, b) => isOptionEqualToValue ? isOptionEqualToValue(a, b) : a === b,
1859
+ (a, b) => isOptionEqualToValue ? isOptionEqualToValue(a, b) : defaultIsEqual(a, b),
1850
1860
  [isOptionEqualToValue]
1851
1861
  );
1852
1862
  const isSelected = useCallback(
1853
1863
  (opt) => selectedValues.some((v) => isEqual(opt, v)),
1854
1864
  [selectedValues, isEqual]
1855
1865
  );
1856
- const filtered = filterOptions ? filterOptions(options, activeInput) : defaultFilter(options, activeInput, getOptionLabel);
1866
+ const filtered = filterOptions ? filterOptions(options, activeInput) : defaultFilter(options, filterQuery, getOptionLabel);
1857
1867
  const flatEntries = [];
1858
1868
  if (groupBy) {
1859
1869
  const groups = {};
@@ -1881,6 +1891,7 @@ function AutocompleteInner(props, _ref) {
1881
1891
  calcPopupStyle();
1882
1892
  setOpen(true);
1883
1893
  setFocusedIdx(-1);
1894
+ setFilterQuery("");
1884
1895
  onOpen?.();
1885
1896
  }, [disabled, calcPopupStyle, onOpen]);
1886
1897
  const closePopup = useCallback((justSelected = false) => {
@@ -1925,11 +1936,13 @@ function AutocompleteInner(props, _ref) {
1925
1936
  const next = already ? selectedValues.filter((v) => !isEqual(v, opt)) : [...selectedValues, opt];
1926
1937
  onChange?.(event, next, already ? "removeOption" : "selectOption");
1927
1938
  setInputStr("");
1939
+ setFilterQuery("");
1928
1940
  onInputChange?.("");
1929
1941
  inputRef.current?.focus();
1930
1942
  } else {
1931
1943
  onChange?.(event, opt, "selectOption");
1932
1944
  setInputStr(getOptionLabel(opt));
1945
+ setFilterQuery("");
1933
1946
  onInputChange?.(getOptionLabel(opt));
1934
1947
  closePopup(true);
1935
1948
  }
@@ -1939,6 +1952,7 @@ function AutocompleteInner(props, _ref) {
1939
1952
  e.stopPropagation();
1940
1953
  onChange?.(e, multiple ? [] : null, "clear");
1941
1954
  setInputStr("");
1955
+ setFilterQuery("");
1942
1956
  onInputChange?.("");
1943
1957
  inputRef.current?.focus();
1944
1958
  };
@@ -1950,6 +1964,7 @@ function AutocompleteInner(props, _ref) {
1950
1964
  const handleInputChange = (e) => {
1951
1965
  const v = e.target.value;
1952
1966
  setInputStr(v);
1967
+ setFilterQuery(v);
1953
1968
  onInputChange?.(v);
1954
1969
  if (!open) openPopup();
1955
1970
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rufous/ui",
3
3
  "private": false,
4
- "version": "0.2.91",
4
+ "version": "0.2.93",
5
5
  "type": "module",
6
6
  "description": "Experimental: A lightweight React UI component library (Beta)",
7
7
  "style": "./dist/main.css",