@eqtylab/equality 4.2.0 → 4.3.1

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/index.cjs CHANGED
@@ -1830,18 +1830,79 @@ var DrawerDescription = React15__namespace.forwardRef(({ className, ...props },
1830
1830
  DrawerDescription.displayName = vaul.Drawer.Description.displayName;
1831
1831
  var DrawerInnerContent = ({ className, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(styles21__default.default["drawer-inner-content"], className), ...props });
1832
1832
  DrawerInnerContent.displayName = "DrawerInnerContent";
1833
- var CheckIcon2 = LucideIcons.Check;
1834
- var ChevronRightIcon2 = LucideIcons.ChevronRight;
1835
- var CircleIcon = LucideIcons.Circle;
1836
- var SearchIcon2 = LucideIcons.Search;
1837
- var DropdownMenuSearchContext = React15__namespace.createContext(null);
1838
- var useDropdownMenuSearch = () => React15__namespace.useContext(DropdownMenuSearchContext);
1839
- var useIsSearching = () => {
1840
- const ctx = useDropdownMenuSearch();
1841
- return !!ctx && ctx.query.trim().length > 0;
1842
- };
1843
- var DropdownMenuBreadcrumbContext = React15__namespace.createContext([]);
1844
- var useBreadcrumbAncestry = () => React15__namespace.useContext(DropdownMenuBreadcrumbContext);
1833
+ function useMatchRegistry() {
1834
+ const itemsRef = React15__namespace.useRef(/* @__PURE__ */ new Map());
1835
+ const [matchCount, setMatchCount] = React15__namespace.useState(0);
1836
+ const registerItem = React15__namespace.useCallback((id, matches) => {
1837
+ const delta = Number(matches) - Number(itemsRef.current.get(id) ?? false);
1838
+ itemsRef.current.set(id, matches);
1839
+ if (delta) setMatchCount((count2) => count2 + delta);
1840
+ }, []);
1841
+ const unregisterItem = React15__namespace.useCallback((id) => {
1842
+ if (itemsRef.current.get(id)) setMatchCount((count2) => count2 - 1);
1843
+ itemsRef.current.delete(id);
1844
+ }, []);
1845
+ return React15__namespace.useMemo(
1846
+ () => ({ registerItem, unregisterItem, matchCount }),
1847
+ [registerItem, unregisterItem, matchCount]
1848
+ );
1849
+ }
1850
+ function useListSearchState(open) {
1851
+ const [enabled, setEnabled] = React15__namespace.useState(false);
1852
+ const [visible, setVisible] = React15__namespace.useState(false);
1853
+ const [query, setQuery] = React15__namespace.useState("");
1854
+ const [listId, setListId] = React15__namespace.useState(void 0);
1855
+ const [focusSignal, setFocusSignal] = React15__namespace.useState(0);
1856
+ const requestFocus = React15__namespace.useCallback(() => setFocusSignal((n) => n + 1), []);
1857
+ const { registerItem, unregisterItem, matchCount } = useMatchRegistry();
1858
+ const reveal = React15__namespace.useCallback((seed) => {
1859
+ setVisible(true);
1860
+ setQuery(seed);
1861
+ }, []);
1862
+ const resetForOpen = React15__namespace.useCallback(() => {
1863
+ setVisible(false);
1864
+ setQuery("");
1865
+ }, []);
1866
+ const [previousOpen, setPreviousOpen] = React15__namespace.useState(open);
1867
+ if (open !== previousOpen) {
1868
+ setPreviousOpen(open);
1869
+ if (open) resetForOpen();
1870
+ }
1871
+ return React15__namespace.useMemo(
1872
+ () => ({
1873
+ enabled,
1874
+ setEnabled,
1875
+ visible,
1876
+ reveal,
1877
+ query,
1878
+ setQuery,
1879
+ focusSignal,
1880
+ requestFocus,
1881
+ registerItem,
1882
+ unregisterItem,
1883
+ matchCount,
1884
+ resetForOpen,
1885
+ listId,
1886
+ setListId
1887
+ }),
1888
+ [
1889
+ enabled,
1890
+ visible,
1891
+ reveal,
1892
+ query,
1893
+ focusSignal,
1894
+ requestFocus,
1895
+ registerItem,
1896
+ unregisterItem,
1897
+ matchCount,
1898
+ resetForOpen,
1899
+ listId
1900
+ ]
1901
+ );
1902
+ }
1903
+ var isSearchActive = (state) => !!state && state.query.trim().length > 0;
1904
+ var isSearchEmpty = (state) => isSearchActive(state) && state.matchCount === 0;
1905
+ var formatResultCount = (count2) => `${count2} result${count2 === 1 ? "" : "s"} available`;
1845
1906
  function getNodeText(node) {
1846
1907
  if (node == null || typeof node === "boolean") return "";
1847
1908
  if (typeof node === "string" || typeof node === "number") return String(node);
@@ -1851,6 +1912,66 @@ function getNodeText(node) {
1851
1912
  }
1852
1913
  return "";
1853
1914
  }
1915
+ var matchesQuery = (query, textValue, children) => {
1916
+ const normalized = query.trim().toLowerCase();
1917
+ return !normalized || (textValue ?? getNodeText(children)).toLowerCase().includes(normalized);
1918
+ };
1919
+ function useRegisterMatch(registry, enabled, id, matches) {
1920
+ const registerItem = registry?.registerItem;
1921
+ const unregisterItem = registry?.unregisterItem;
1922
+ React15__namespace.useEffect(() => {
1923
+ if (!enabled || !registerItem || !unregisterItem) return;
1924
+ registerItem(id, matches);
1925
+ return () => unregisterItem(id);
1926
+ }, [enabled, registerItem, unregisterItem, id, matches]);
1927
+ }
1928
+ function useFilterableItem(state, textValue, children, group) {
1929
+ const id = React15__namespace.useId();
1930
+ const matches = matchesQuery(state?.query ?? "", textValue, children);
1931
+ const enabled = state?.enabled ?? false;
1932
+ useRegisterMatch(state, enabled, id, matches);
1933
+ useRegisterMatch(group, enabled, id, matches);
1934
+ return matches;
1935
+ }
1936
+ function useSearchInput(state, alwaysVisible, forwardedRef) {
1937
+ const { setEnabled, reveal, visible, focusSignal } = state;
1938
+ const inputRef = React15__namespace.useRef(null);
1939
+ const ref = React15__namespace.useCallback(
1940
+ (node) => assignRefs(node, inputRef, forwardedRef),
1941
+ [forwardedRef]
1942
+ );
1943
+ React15__namespace.useEffect(() => {
1944
+ setEnabled(true);
1945
+ return () => setEnabled(false);
1946
+ }, [setEnabled]);
1947
+ React15__namespace.useEffect(() => {
1948
+ if (!visible) return;
1949
+ const input = inputRef.current;
1950
+ if (!input) return;
1951
+ input.focus();
1952
+ input.setSelectionRange(input.value.length, input.value.length);
1953
+ }, [visible, focusSignal]);
1954
+ React15__namespace.useEffect(() => {
1955
+ if (alwaysVisible && !visible) reveal("");
1956
+ }, [alwaysVisible, visible, reveal]);
1957
+ return { ref, isRendered: alwaysVisible || visible };
1958
+ }
1959
+ var isPrintableKey = (event) => event.key.length === 1 && !event.metaKey && !event.ctrlKey && !event.altKey && /\S/.test(event.key);
1960
+ function assignRefs(node, ...refs) {
1961
+ refs.forEach((ref) => {
1962
+ if (typeof ref === "function") ref(node);
1963
+ else if (ref) ref.current = node;
1964
+ });
1965
+ }
1966
+ var CheckIcon2 = LucideIcons.Check;
1967
+ var ChevronRightIcon2 = LucideIcons.ChevronRight;
1968
+ var CircleIcon = LucideIcons.Circle;
1969
+ var SearchIcon2 = LucideIcons.Search;
1970
+ var DropdownMenuSearchContext = React15__namespace.createContext(null);
1971
+ var useDropdownMenuSearch = () => React15__namespace.useContext(DropdownMenuSearchContext);
1972
+ var useIsSearching = () => isSearchActive(useDropdownMenuSearch());
1973
+ var DropdownMenuBreadcrumbContext = React15__namespace.createContext([]);
1974
+ var useBreadcrumbAncestry = () => React15__namespace.useContext(DropdownMenuBreadcrumbContext);
1854
1975
  var SUB_CONTENT_NAME = "DropdownMenuSubContent";
1855
1976
  var SUB_TRIGGER_NAME = "DropdownMenuSubTrigger";
1856
1977
  function hasDisplayName(node, name) {
@@ -1880,100 +2001,24 @@ function getSubTriggerLabel(nodes) {
1880
2001
  const trigger = React15__namespace.Children.toArray(nodes).find(isSubTrigger);
1881
2002
  return trigger ? getNodeText(trigger.props.children) : "";
1882
2003
  }
1883
- function useFilterableItem(textValue, children) {
1884
- const ctx = useDropdownMenuSearch();
1885
- const id = React15__namespace.useId();
1886
- const query = ctx?.query.trim().toLowerCase() ?? "";
1887
- const visible = !query || (textValue ?? getNodeText(children)).toLowerCase().includes(query);
1888
- const enabled = ctx?.enabled ?? false;
1889
- const registerItem = ctx?.registerItem;
1890
- const unregisterItem = ctx?.unregisterItem;
1891
- React15__namespace.useEffect(() => {
1892
- if (!enabled || !registerItem || !unregisterItem) return;
1893
- registerItem(id, visible);
1894
- return () => unregisterItem(id);
1895
- }, [enabled, registerItem, unregisterItem, id, visible]);
1896
- return visible;
1897
- }
1898
2004
  var DropdownMenu = ({
1899
2005
  children,
2006
+ open,
1900
2007
  onOpenChange,
1901
2008
  ...props
1902
2009
  }) => {
1903
- const [enabled, setEnabled] = React15__namespace.useState(false);
1904
- const [visible, setVisible] = React15__namespace.useState(false);
1905
- const [query, setQuery] = React15__namespace.useState("");
1906
- const [focusSignal, setFocusSignal] = React15__namespace.useState(0);
1907
- const requestFocus = React15__namespace.useCallback(() => setFocusSignal((n) => n + 1), []);
1908
- const [listId, setListId] = React15__namespace.useState(void 0);
1909
- const itemsRef = React15__namespace.useRef(/* @__PURE__ */ new Map());
1910
- const [matchCount, setMatchCount] = React15__namespace.useState(0);
1911
- const recount = React15__namespace.useCallback(() => {
1912
- let count2 = 0;
1913
- itemsRef.current.forEach((matches) => {
1914
- if (matches) count2 += 1;
1915
- });
1916
- setMatchCount(count2);
1917
- }, []);
1918
- const registerItem = React15__namespace.useCallback(
1919
- (id, matches) => {
1920
- itemsRef.current.set(id, matches);
1921
- recount();
1922
- },
1923
- [recount]
1924
- );
1925
- const unregisterItem = React15__namespace.useCallback(
1926
- (id) => {
1927
- itemsRef.current.delete(id);
1928
- recount();
1929
- },
1930
- [recount]
1931
- );
1932
- const reveal = React15__namespace.useCallback((seed) => {
1933
- setVisible(true);
1934
- setQuery(seed);
1935
- }, []);
2010
+ const search = useListSearchState(open);
2011
+ const { resetForOpen } = search;
1936
2012
  const handleOpenChange = React15__namespace.useCallback(
1937
- (open) => {
1938
- if (open) {
1939
- setVisible(false);
1940
- setQuery("");
1941
- }
1942
- onOpenChange?.(open);
2013
+ (nextOpen) => {
2014
+ if (nextOpen) resetForOpen();
2015
+ onOpenChange?.(nextOpen);
1943
2016
  },
1944
- [onOpenChange]
2017
+ [onOpenChange, resetForOpen]
1945
2018
  );
1946
- const value = React15__namespace.useMemo(
1947
- () => ({
1948
- enabled,
1949
- setEnabled,
1950
- visible,
1951
- reveal,
1952
- query,
1953
- setQuery,
1954
- focusSignal,
1955
- requestFocus,
1956
- listId,
1957
- setListId,
1958
- registerItem,
1959
- unregisterItem,
1960
- matchCount
1961
- }),
1962
- [
1963
- enabled,
1964
- visible,
1965
- reveal,
1966
- query,
1967
- focusSignal,
1968
- requestFocus,
1969
- listId,
1970
- registerItem,
1971
- unregisterItem,
1972
- matchCount
1973
- ]
1974
- );
1975
- return /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSearchContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Root, { onOpenChange: handleOpenChange, ...props, children }) });
2019
+ return /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSearchContext.Provider, { value: search, children: /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Root, { open, onOpenChange: handleOpenChange, ...props, children }) });
1976
2020
  };
2021
+ DropdownMenu.displayName = "DropdownMenu";
1977
2022
  var DropdownMenuTrigger = DropdownMenuPrimitive__namespace.Trigger;
1978
2023
  var DropdownMenuGroup = DropdownMenuPrimitive__namespace.Group;
1979
2024
  var DropdownMenuPortal = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Portal, { container: usePortalContainer(), children });
@@ -2022,11 +2067,16 @@ var DropdownMenuSub = ({
2022
2067
  return /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Sub, { ...props, children });
2023
2068
  };
2024
2069
  var MENU_ITEM_SELECTOR = '[role="menuitem"]:not([data-disabled]),[role="menuitemcheckbox"]:not([data-disabled]),[role="menuitemradio"]:not([data-disabled])';
2025
- var DropdownMenuContent = React15__namespace.forwardRef(({ className, sideOffset = 4, onKeyDown, children, ...props }, ref) => {
2070
+ var DropdownMenuContent = React15__namespace.forwardRef(({ className, sideOffset = 4, onKeyDown, onFocus, children, ...props }, ref) => {
2026
2071
  const ctx = useDropdownMenuSearch();
2027
2072
  const setListId = ctx?.setListId;
2028
- const searching = !!ctx && ctx.query.trim().length > 0;
2073
+ const searching = isSearchActive(ctx);
2029
2074
  const resultCount = ctx?.matchCount ?? 0;
2075
+ const openFocusHandledRef = React15__namespace.useRef(false);
2076
+ const searchVisible = ctx?.visible ?? false;
2077
+ React15__namespace.useEffect(() => {
2078
+ if (!searchVisible) openFocusHandledRef.current = false;
2079
+ }, [searchVisible]);
2030
2080
  const composedContentRef = React15__namespace.useCallback(
2031
2081
  (node) => {
2032
2082
  assignRefs(node, ref);
@@ -2040,6 +2090,13 @@ var DropdownMenuContent = React15__namespace.forwardRef(({ className, sideOffset
2040
2090
  ref: composedContentRef,
2041
2091
  sideOffset,
2042
2092
  className: cn(styles22__default.default["dropdown-menu-content"], className),
2093
+ onFocus: (event) => {
2094
+ onFocus?.(event);
2095
+ if (openFocusHandledRef.current) return;
2096
+ openFocusHandledRef.current = true;
2097
+ if (event.target !== event.currentTarget || !ctx?.enabled || !ctx.visible) return;
2098
+ ctx.requestFocus();
2099
+ },
2043
2100
  onKeyDown: (event) => {
2044
2101
  onKeyDown?.(event);
2045
2102
  if (!ctx?.enabled) return;
@@ -2057,8 +2114,7 @@ var DropdownMenuContent = React15__namespace.forwardRef(({ className, sideOffset
2057
2114
  }
2058
2115
  }
2059
2116
  if (event.defaultPrevented) return;
2060
- const isPrintable = event.key.length === 1 && !event.metaKey && !event.ctrlKey && !event.altKey && /\S/.test(event.key);
2061
- if (!isPrintable) return;
2117
+ if (!isPrintableKey(event)) return;
2062
2118
  const target = event.target;
2063
2119
  if (target?.closest?.("[data-dropdown-search]")) return;
2064
2120
  event.preventDefault();
@@ -2071,28 +2127,20 @@ var DropdownMenuContent = React15__namespace.forwardRef(({ className, sideOffset
2071
2127
  },
2072
2128
  ...props,
2073
2129
  children: [
2074
- ctx?.enabled ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles22__default.default["dropdown-menu-sr-status"], role: "status", "aria-live": "polite", children: searching && resultCount > 0 ? `${resultCount} result${resultCount === 1 ? "" : "s"} available` : null }) : null,
2130
+ ctx?.enabled ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles22__default.default["dropdown-menu-sr-status"], role: "status", "aria-live": "polite", children: searching && resultCount > 0 ? formatResultCount(resultCount) : null }) : null,
2075
2131
  children
2076
2132
  ]
2077
2133
  }
2078
2134
  ) });
2079
2135
  });
2080
2136
  DropdownMenuContent.displayName = DropdownMenuPrimitive__namespace.Content.displayName;
2081
- function assignRefs(node, ...refs) {
2082
- refs.forEach((ref) => {
2083
- if (typeof ref === "function") ref(node);
2084
- else if (ref) ref.current = node;
2085
- });
2086
- }
2087
2137
  var DropdownMenuSearch = React15__namespace.forwardRef(
2088
2138
  ({
2089
2139
  className,
2090
2140
  placeholder = "Search...",
2091
2141
  icon,
2092
- /* Render the input immediately instead of revealing on first keypress */
2093
2142
  alwaysVisible = false,
2094
2143
  onKeyDown,
2095
- /* Pulled out of props so the placeholder fallback below isn't overwritten by the spread */
2096
2144
  "aria-label": ariaLabel,
2097
2145
  ...props
2098
2146
  }, forwardedRef) => {
@@ -2100,32 +2148,15 @@ var DropdownMenuSearch = React15__namespace.forwardRef(
2100
2148
  if (!ctx) {
2101
2149
  throw new Error("DropdownMenuSearch must be used within a DropdownMenu");
2102
2150
  }
2103
- const { setEnabled, reveal, visible, focusSignal } = ctx;
2104
- const inputRef = React15__namespace.useRef(null);
2105
- React15__namespace.useEffect(() => {
2106
- setEnabled(true);
2107
- return () => setEnabled(false);
2108
- }, [setEnabled]);
2109
- React15__namespace.useEffect(() => {
2110
- if (!visible) return;
2111
- const el = inputRef.current;
2112
- if (!el) return;
2113
- el.focus();
2114
- const end = el.value.length;
2115
- el.setSelectionRange(end, end);
2116
- }, [visible, focusSignal]);
2117
- React15__namespace.useEffect(() => {
2118
- if (alwaysVisible && !visible) reveal("");
2119
- }, [alwaysVisible, visible, reveal]);
2120
- if (!alwaysVisible && !visible) return null;
2151
+ const { ref, isRendered } = useSearchInput(ctx, alwaysVisible, forwardedRef);
2152
+ if (!isRendered) return null;
2121
2153
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles22__default.default["dropdown-menu-search"], children: [
2122
2154
  /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: styles22__default.default["dropdown-menu-item-icon"], children: icon ?? /* @__PURE__ */ jsxRuntime.jsx(SearchIcon2, { className: styles22__default.default["icon-size"] }) }),
2123
2155
  /* @__PURE__ */ jsxRuntime.jsx(
2124
2156
  "input",
2125
2157
  {
2126
- ref: (node) => {
2127
- assignRefs(node, inputRef, forwardedRef);
2128
- },
2158
+ ...props,
2159
+ ref,
2129
2160
  "data-dropdown-search": "",
2130
2161
  className: cn(styles22__default.default["dropdown-menu-search-input"], className),
2131
2162
  value: ctx.query,
@@ -2137,19 +2168,19 @@ var DropdownMenuSearch = React15__namespace.forwardRef(
2137
2168
  onChange: (event) => ctx.setQuery(event.target.value),
2138
2169
  onKeyDown: (event) => {
2139
2170
  onKeyDown?.(event);
2140
- if (event.key === "ArrowDown" || event.key === "ArrowUp") {
2171
+ if (event.key === "Enter" && !isSearchActive(ctx)) return;
2172
+ if (event.key === "ArrowDown" || event.key === "ArrowUp" || event.key === "Enter") {
2141
2173
  const menu = event.currentTarget.closest('[role="menu"]');
2142
2174
  const items = menu ? Array.from(menu.querySelectorAll(MENU_ITEM_SELECTOR)) : [];
2143
- if (items.length) {
2144
- event.preventDefault();
2145
- (event.key === "ArrowUp" ? items[items.length - 1] : items[0]).focus();
2146
- }
2175
+ if (!items.length || event.defaultPrevented) return;
2176
+ event.preventDefault();
2177
+ if (event.key === "Enter") items[0].click();
2178
+ else (event.key === "ArrowUp" ? items[items.length - 1] : items[0]).focus();
2147
2179
  return;
2148
2180
  }
2149
- if (["Enter", "Escape", "Tab"].includes(event.key)) return;
2181
+ if (["Escape", "Tab"].includes(event.key)) return;
2150
2182
  event.stopPropagation();
2151
- },
2152
- ...props
2183
+ }
2153
2184
  }
2154
2185
  )
2155
2186
  ] });
@@ -2163,15 +2194,14 @@ var DropdownMenuEmpty = ({
2163
2194
  }) => {
2164
2195
  const ctx = useDropdownMenuSearch();
2165
2196
  if (!ctx) return null;
2166
- const query = ctx.query.trim();
2167
- const isEmpty = !!query && ctx.matchCount === 0;
2197
+ const isEmpty = isSearchEmpty(ctx);
2168
2198
  return /* @__PURE__ */ jsxRuntime.jsx(
2169
2199
  "div",
2170
2200
  {
2201
+ ...props,
2171
2202
  role: "status",
2172
2203
  "aria-live": "polite",
2173
2204
  className: isEmpty ? cn(styles22__default.default["dropdown-menu-empty"], className) : void 0,
2174
- ...props,
2175
2205
  children: isEmpty ? children : null
2176
2206
  }
2177
2207
  );
@@ -2186,7 +2216,7 @@ var ItemBreadcrumb = () => {
2186
2216
  ] }, index)) });
2187
2217
  };
2188
2218
  var DropdownMenuItem = React15__namespace.forwardRef(({ className, inset, variant = "neutral", textValue, children, ...props }, ref) => {
2189
- const visible = useFilterableItem(textValue, children);
2219
+ const visible = useFilterableItem(useDropdownMenuSearch(), textValue, children);
2190
2220
  if (!visible) return null;
2191
2221
  return /* @__PURE__ */ jsxRuntime.jsxs(
2192
2222
  DropdownMenuPrimitive__namespace.Item,
@@ -2210,7 +2240,7 @@ var DropdownMenuItem = React15__namespace.forwardRef(({ className, inset, varian
2210
2240
  });
2211
2241
  DropdownMenuItem.displayName = DropdownMenuPrimitive__namespace.Item.displayName;
2212
2242
  var DropdownMenuCheckboxItem = React15__namespace.forwardRef(({ className, children, checked, textValue, ...props }, ref) => {
2213
- const visible = useFilterableItem(textValue, children);
2243
+ const visible = useFilterableItem(useDropdownMenuSearch(), textValue, children);
2214
2244
  if (!visible) return null;
2215
2245
  return /* @__PURE__ */ jsxRuntime.jsxs(
2216
2246
  DropdownMenuPrimitive__namespace.CheckboxItem,
@@ -2230,7 +2260,7 @@ var DropdownMenuCheckboxItem = React15__namespace.forwardRef(({ className, child
2230
2260
  });
2231
2261
  DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive__namespace.CheckboxItem.displayName;
2232
2262
  var DropdownMenuRadioItem = React15__namespace.forwardRef(({ className, children, textValue, ...props }, ref) => {
2233
- const visible = useFilterableItem(textValue, children);
2263
+ const visible = useFilterableItem(useDropdownMenuSearch(), textValue, children);
2234
2264
  if (!visible) return null;
2235
2265
  return /* @__PURE__ */ jsxRuntime.jsxs(
2236
2266
  DropdownMenuPrimitive__namespace.RadioItem,
@@ -2319,6 +2349,10 @@ var FilterDropdown = ({
2319
2349
  const filteredOptions = options.filter(
2320
2350
  (option) => option.value && option.value.trim() !== "" && option.label && option.label.trim() !== ""
2321
2351
  );
2352
+ const clearAll = (className) => (
2353
+ // An empty textValue keeps this out of search results, so Enter can't clear every filter
2354
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, { textValue: "", onSelect: onClearAll, className, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: buttonVariants({ variant: "link", size: "sm" }), children: "Clear all" }) })
2355
+ );
2322
2356
  return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
2323
2357
  /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, disabled, children: /* @__PURE__ */ jsxRuntime.jsxs(
2324
2358
  Button,
@@ -2342,14 +2376,16 @@ var FilterDropdown = ({
2342
2376
  className: cn(styles24__default.default["dropdown-menu-content"], contentClassName),
2343
2377
  children: [
2344
2378
  searchable && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2345
- /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSearch, { placeholder: searchPlaceholder }),
2379
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSearch, { alwaysVisible: true, placeholder: searchPlaceholder, "aria-label": label }),
2346
2380
  /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuEmpty, { children: emptyPlaceholder })
2347
2381
  ] }),
2348
- /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuLabel, { children: [
2349
- "Filters",
2350
- hasSelectedFilters && /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "link", size: "sm", onClick: onClearAll, children: "Clear all" })
2382
+ !searchable && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2383
+ /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuLabel, { className: styles24__default.default["filters-header"], children: [
2384
+ "Filters",
2385
+ hasSelectedFilters && clearAll(styles24__default.default["clear-all-inline"])
2386
+ ] }),
2387
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {})
2351
2388
  ] }),
2352
- /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
2353
2389
  filteredOptions.map((option) => {
2354
2390
  const isSelected = selectedFilters.includes(option.value);
2355
2391
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -2362,7 +2398,11 @@ var FilterDropdown = ({
2362
2398
  },
2363
2399
  option.value
2364
2400
  );
2365
- })
2401
+ }),
2402
+ searchable && hasSelectedFilters && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles24__default.default["clear-all-footer"], children: [
2403
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
2404
+ clearAll(styles24__default.default["clear-all"])
2405
+ ] })
2366
2406
  ]
2367
2407
  }
2368
2408
  )
@@ -2710,8 +2750,59 @@ var NotFound = ({
2710
2750
  var CheckIcon3 = LucideIcons.Check;
2711
2751
  var ChevronDownIcon2 = LucideIcons.ChevronDown;
2712
2752
  var ChevronUpIcon = LucideIcons.ChevronUp;
2713
- var Select = SelectPrimitive__namespace.Root;
2714
- var SelectGroup = SelectPrimitive__namespace.Group;
2753
+ var SearchIcon3 = LucideIcons.Search;
2754
+ var SEARCH_INPUT_SELECTOR = "[data-select-search]";
2755
+ var NAVIGABLE_OPTION_SELECTOR = '[role="option"]:not([data-disabled]):not([hidden])';
2756
+ var RADIX_HANDLED_SEARCH_KEYS = ["ArrowDown", "ArrowUp", "Escape", "Tab"];
2757
+ var SelectSearchContext = React15__namespace.createContext(null);
2758
+ var useSelectSearch = () => React15__namespace.useContext(SelectSearchContext);
2759
+ var useIsSearching2 = () => isSearchActive(useSelectSearch());
2760
+ var SelectGroupMatchContext = React15__namespace.createContext(null);
2761
+ var Select = ({
2762
+ open,
2763
+ onOpenChange,
2764
+ ...props
2765
+ }) => {
2766
+ const search = useListSearchState(open);
2767
+ const { resetForOpen } = search;
2768
+ const interactedRef = React15__namespace.useRef(false);
2769
+ const markInteracted = React15__namespace.useCallback(() => {
2770
+ interactedRef.current = true;
2771
+ }, []);
2772
+ const interactedSinceOpen = React15__namespace.useCallback(() => interactedRef.current, []);
2773
+ React15__namespace.useEffect(() => {
2774
+ if (open) interactedRef.current = false;
2775
+ }, [open]);
2776
+ const handleOpenChange = React15__namespace.useCallback(
2777
+ (nextOpen) => {
2778
+ if (nextOpen) {
2779
+ resetForOpen();
2780
+ interactedRef.current = false;
2781
+ }
2782
+ onOpenChange?.(nextOpen);
2783
+ },
2784
+ [onOpenChange, resetForOpen]
2785
+ );
2786
+ const value = React15__namespace.useMemo(
2787
+ () => ({ ...search, markInteracted, interactedSinceOpen }),
2788
+ [search, markInteracted, interactedSinceOpen]
2789
+ );
2790
+ return /* @__PURE__ */ jsxRuntime.jsx(SelectSearchContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Root, { open, onOpenChange: handleOpenChange, ...props }) });
2791
+ };
2792
+ Select.displayName = "Select";
2793
+ var SelectGroup = React15__namespace.forwardRef(({ hidden, ...props }, ref) => {
2794
+ const searching = useIsSearching2();
2795
+ const registry = useMatchRegistry();
2796
+ return /* @__PURE__ */ jsxRuntime.jsx(SelectGroupMatchContext.Provider, { value: registry, children: /* @__PURE__ */ jsxRuntime.jsx(
2797
+ SelectPrimitive__namespace.Group,
2798
+ {
2799
+ ref,
2800
+ ...props,
2801
+ hidden: hidden || searching && registry.matchCount === 0 || void 0
2802
+ }
2803
+ ) });
2804
+ });
2805
+ SelectGroup.displayName = SelectPrimitive__namespace.Group.displayName;
2715
2806
  var SelectValue = SelectPrimitive__namespace.Value;
2716
2807
  var SelectTrigger = React15__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(SelectPrimitive__namespace.Trigger, { ref, className: cn(styles35__default.default["select-trigger"], className), ...props, children: [
2717
2808
  children,
@@ -2744,50 +2835,217 @@ var selectContentElevationVariants = generateElevationVariants(
2744
2835
  "select-content",
2745
2836
  ELEVATION.OVERLAY
2746
2837
  );
2747
- var SelectContent = React15__namespace.forwardRef(({ className, children, position = "popper", elevation = ELEVATION.OVERLAY, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(SelectPortal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
2748
- SelectPrimitive__namespace.Content,
2749
- {
2750
- ref,
2751
- className: cn(
2752
- styles35__default.default["select-content"],
2753
- position === "popper" && styles35__default.default["select-content--popper"],
2754
- selectContentElevationVariants({ elevation }),
2755
- className
2756
- ),
2757
- position,
2758
- ...props,
2759
- children: [
2760
- /* @__PURE__ */ jsxRuntime.jsx(SelectScrollUpButton, {}),
2838
+ var SelectContent = React15__namespace.forwardRef(
2839
+ ({
2840
+ className,
2841
+ children,
2842
+ position = "popper",
2843
+ elevation = ELEVATION.OVERLAY,
2844
+ onKeyDown,
2845
+ onKeyDownCapture,
2846
+ onPointerMoveCapture,
2847
+ onFocus,
2848
+ ...props
2849
+ }, ref) => {
2850
+ const ctx = useSelectSearch();
2851
+ const setListId = ctx?.setListId;
2852
+ const searching = isSearchActive(ctx);
2853
+ const resultCount = ctx?.matchCount ?? 0;
2854
+ const composedContentRef = React15__namespace.useCallback(
2855
+ (node) => {
2856
+ assignRefs(node, ref);
2857
+ setListId?.(node?.id || void 0);
2858
+ },
2859
+ [ref, setListId]
2860
+ );
2861
+ const handleFocus = (event) => {
2862
+ onFocus?.(event);
2863
+ if (!ctx?.enabled || !ctx.visible || ctx.interactedSinceOpen()) return;
2864
+ if (event.target.closest(SEARCH_INPUT_SELECTOR)) return;
2865
+ ctx.requestFocus();
2866
+ };
2867
+ const handleKeyDown = (event) => {
2868
+ onKeyDown?.(event);
2869
+ if (!ctx?.enabled || event.defaultPrevented) return;
2870
+ const target = event.target;
2871
+ if (target?.closest(SEARCH_INPUT_SELECTOR)) return;
2872
+ if (event.key === "ArrowUp" && ctx.visible) {
2873
+ const firstOption = event.currentTarget.querySelector(NAVIGABLE_OPTION_SELECTOR);
2874
+ if (firstOption && firstOption === target?.closest(NAVIGABLE_OPTION_SELECTOR)) {
2875
+ event.preventDefault();
2876
+ ctx.requestFocus();
2877
+ return;
2878
+ }
2879
+ }
2880
+ if (event.key === "Backspace" && ctx.visible && ctx.query) {
2881
+ event.preventDefault();
2882
+ ctx.setQuery(ctx.query.slice(0, -1));
2883
+ ctx.requestFocus();
2884
+ return;
2885
+ }
2886
+ if (!isPrintableKey(event)) return;
2887
+ event.preventDefault();
2888
+ if (!ctx.visible) {
2889
+ ctx.reveal(event.key);
2890
+ } else {
2891
+ ctx.setQuery(ctx.query + event.key);
2892
+ ctx.requestFocus();
2893
+ }
2894
+ };
2895
+ return /* @__PURE__ */ jsxRuntime.jsx(SelectPortal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
2896
+ SelectPrimitive__namespace.Content,
2897
+ {
2898
+ ref: composedContentRef,
2899
+ className: cn(
2900
+ styles35__default.default["select-content"],
2901
+ position === "popper" && styles35__default.default["select-content--popper"],
2902
+ selectContentElevationVariants({ elevation }),
2903
+ className
2904
+ ),
2905
+ position,
2906
+ onFocus: handleFocus,
2907
+ onKeyDown: handleKeyDown,
2908
+ onKeyDownCapture: (event) => {
2909
+ onKeyDownCapture?.(event);
2910
+ ctx?.markInteracted();
2911
+ },
2912
+ onPointerMoveCapture: (event) => {
2913
+ onPointerMoveCapture?.(event);
2914
+ ctx?.markInteracted();
2915
+ },
2916
+ ...props,
2917
+ children: [
2918
+ ctx?.enabled ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles35__default.default["select-sr-status"], role: "status", "aria-live": "polite", children: searching && resultCount > 0 ? formatResultCount(resultCount) : null }) : null,
2919
+ /* @__PURE__ */ jsxRuntime.jsx(SelectScrollUpButton, {}),
2920
+ /* @__PURE__ */ jsxRuntime.jsx(
2921
+ SelectPrimitive__namespace.Viewport,
2922
+ {
2923
+ className: cn(
2924
+ styles35__default.default["select-viewport"],
2925
+ position === "popper" && styles35__default.default["select-viewport--popper"]
2926
+ ),
2927
+ children
2928
+ }
2929
+ ),
2930
+ /* @__PURE__ */ jsxRuntime.jsx(SelectScrollDownButton, {})
2931
+ ]
2932
+ }
2933
+ ) });
2934
+ }
2935
+ );
2936
+ SelectContent.displayName = SelectPrimitive__namespace.Content.displayName;
2937
+ var SelectSearch = React15__namespace.forwardRef(
2938
+ ({
2939
+ className,
2940
+ placeholder = "Search...",
2941
+ icon,
2942
+ alwaysVisible = true,
2943
+ onKeyDown,
2944
+ "aria-label": ariaLabel,
2945
+ ...props
2946
+ }, forwardedRef) => {
2947
+ const ctx = useSelectSearch();
2948
+ if (!ctx) {
2949
+ throw new Error("SelectSearch must be used within a Select");
2950
+ }
2951
+ const { ref, isRendered } = useSearchInput(ctx, alwaysVisible, forwardedRef);
2952
+ if (!isRendered) return null;
2953
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles35__default.default["select-search"], children: [
2954
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: styles35__default.default["select-search-icon"], children: icon ?? /* @__PURE__ */ jsxRuntime.jsx(SearchIcon3, { className: cn(styles35__default.default["select-icon"], styles35__default.default["select-icon--sm"]) }) }),
2761
2955
  /* @__PURE__ */ jsxRuntime.jsx(
2762
- SelectPrimitive__namespace.Viewport,
2956
+ "input",
2763
2957
  {
2764
- className: cn(
2765
- styles35__default.default["select-viewport"],
2766
- position === "popper" && styles35__default.default["select-viewport--popper"]
2767
- ),
2768
- children
2958
+ ...props,
2959
+ ref,
2960
+ "data-select-search": "",
2961
+ className: cn(styles35__default.default["select-search-input"], className),
2962
+ value: ctx.query,
2963
+ placeholder,
2964
+ "aria-label": ariaLabel ?? placeholder,
2965
+ role: "searchbox",
2966
+ "aria-controls": ctx.listId,
2967
+ "aria-autocomplete": "list",
2968
+ onChange: (event) => ctx.setQuery(event.target.value),
2969
+ onKeyDown: (event) => {
2970
+ onKeyDown?.(event);
2971
+ if (event.key === "Enter" && !event.defaultPrevented && isSearchActive(ctx)) {
2972
+ event.preventDefault();
2973
+ event.stopPropagation();
2974
+ const firstOption = event.currentTarget.closest('[role="listbox"]')?.querySelector(NAVIGABLE_OPTION_SELECTOR);
2975
+ firstOption?.dispatchEvent(
2976
+ new KeyboardEvent("keydown", { key: "Enter", bubbles: true })
2977
+ );
2978
+ return;
2979
+ }
2980
+ if (!RADIX_HANDLED_SEARCH_KEYS.includes(event.key)) event.stopPropagation();
2981
+ }
2769
2982
  }
2770
- ),
2771
- /* @__PURE__ */ jsxRuntime.jsx(SelectScrollDownButton, {})
2772
- ]
2983
+ )
2984
+ ] });
2773
2985
  }
2774
- ) }));
2775
- SelectContent.displayName = SelectPrimitive__namespace.Content.displayName;
2776
- var SelectLabel = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Label, { ref, className: cn(styles35__default.default["select-label"], className), ...props }));
2986
+ );
2987
+ SelectSearch.displayName = "SelectSearch";
2988
+ var SelectEmpty = ({ className, children, ...props }) => {
2989
+ const ctx = useSelectSearch();
2990
+ if (!ctx) return null;
2991
+ const isEmpty = isSearchEmpty(ctx);
2992
+ return /* @__PURE__ */ jsxRuntime.jsx(
2993
+ "div",
2994
+ {
2995
+ ...props,
2996
+ role: "status",
2997
+ "aria-live": "polite",
2998
+ className: isEmpty ? cn(styles35__default.default["select-empty"], className) : void 0,
2999
+ children: isEmpty ? children : null
3000
+ }
3001
+ );
3002
+ };
3003
+ SelectEmpty.displayName = "SelectEmpty";
3004
+ var SelectLabel = React15__namespace.forwardRef(({ className, hidden, ...props }, ref) => {
3005
+ const searching = useIsSearching2();
3006
+ return /* @__PURE__ */ jsxRuntime.jsx(
3007
+ SelectPrimitive__namespace.Label,
3008
+ {
3009
+ ref,
3010
+ className: cn(styles35__default.default["select-label"], className),
3011
+ ...props,
3012
+ hidden: hidden || searching || void 0
3013
+ }
3014
+ );
3015
+ });
2777
3016
  SelectLabel.displayName = SelectPrimitive__namespace.Label.displayName;
2778
- var SelectItem = React15__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(SelectPrimitive__namespace.Item, { ref, className: cn(styles35__default.default["select-item"], className), ...props, children: [
2779
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles35__default.default["select-item-indicator"], children: /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.ItemIndicator, { children: /* @__PURE__ */ jsxRuntime.jsx(CheckIcon3, { className: styles35__default.default["select-icon"] }) }) }),
2780
- /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.ItemText, { children })
2781
- ] }));
3017
+ var SelectItem = React15__namespace.forwardRef(({ className, children, textValue, hidden, ...props }, ref) => {
3018
+ const search = useSelectSearch();
3019
+ const group = React15__namespace.useContext(SelectGroupMatchContext);
3020
+ const matches = useFilterableItem(search, textValue, children, group);
3021
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3022
+ SelectPrimitive__namespace.Item,
3023
+ {
3024
+ ref,
3025
+ className: cn(styles35__default.default["select-item"], className),
3026
+ ...props,
3027
+ textValue,
3028
+ hidden: hidden || !matches || void 0,
3029
+ children: [
3030
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles35__default.default["select-item-indicator"], children: /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.ItemIndicator, { children: /* @__PURE__ */ jsxRuntime.jsx(CheckIcon3, { className: styles35__default.default["select-icon"] }) }) }),
3031
+ /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.ItemText, { children })
3032
+ ]
3033
+ }
3034
+ );
3035
+ });
2782
3036
  SelectItem.displayName = SelectPrimitive__namespace.Item.displayName;
2783
- var SelectSeparator = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
2784
- SelectPrimitive__namespace.Separator,
2785
- {
2786
- ref,
2787
- className: cn(styles35__default.default["select-separator"], className),
2788
- ...props
2789
- }
2790
- ));
3037
+ var SelectSeparator = React15__namespace.forwardRef(({ className, ...props }, ref) => {
3038
+ const searching = useIsSearching2();
3039
+ if (searching) return null;
3040
+ return /* @__PURE__ */ jsxRuntime.jsx(
3041
+ SelectPrimitive__namespace.Separator,
3042
+ {
3043
+ ref,
3044
+ className: cn(styles35__default.default["select-separator"], className),
3045
+ ...props
3046
+ }
3047
+ );
3048
+ });
2791
3049
  SelectSeparator.displayName = SelectPrimitive__namespace.Separator.displayName;
2792
3050
  var ChevronLeftIcon2 = LucideIcons.ChevronLeft;
2793
3051
  var ChevronRightIcon3 = LucideIcons.ChevronRight;
@@ -3235,11 +3493,13 @@ var RadioDropdown = ({
3235
3493
  ] }) }),
3236
3494
  /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "end", className: styles41__default.default["dropdown-menu-content"], children: [
3237
3495
  searchable && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3238
- /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSearch, { placeholder: searchPlaceholder }),
3496
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSearch, { alwaysVisible: true, placeholder: searchPlaceholder, "aria-label": label }),
3239
3497
  /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuEmpty, { children: emptyPlaceholder })
3240
3498
  ] }),
3241
- /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuLabel, { children: label }),
3242
- /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
3499
+ !searchable && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3500
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuLabel, { children: label }),
3501
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {})
3502
+ ] }),
3243
3503
  /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuRadioGroup, { value: selectedValue, onValueChange: onSelect, children: filteredOptions.map((option) => {
3244
3504
  const hasCount = option.count !== void 0;
3245
3505
  return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuRadioItem, { value: option.value, children: [
@@ -3296,7 +3556,7 @@ var ScrollBar = React15__namespace.forwardRef(({ className, orientation = "verti
3296
3556
  }
3297
3557
  ));
3298
3558
  ScrollBar.displayName = ScrollAreaPrimitive__namespace.ScrollAreaScrollbar.displayName;
3299
- var SearchIcon3 = LucideIcons.Search;
3559
+ var SearchIcon4 = LucideIcons.Search;
3300
3560
  var SearchBar = ({
3301
3561
  searchQuery,
3302
3562
  setSearchQuery,
@@ -3316,7 +3576,7 @@ var SearchBar = ({
3316
3576
  value: searchQuery,
3317
3577
  onChange: handleChange,
3318
3578
  className: styles44__default.default["input"],
3319
- prefix: /* @__PURE__ */ jsxRuntime.jsx(SearchIcon3, { className: styles44__default.default["search-icon"] }),
3579
+ prefix: /* @__PURE__ */ jsxRuntime.jsx(SearchIcon4, { className: styles44__default.default["search-icon"] }),
3320
3580
  suffix: searchQuery && /* @__PURE__ */ jsxRuntime.jsx(
3321
3581
  IconButton,
3322
3582
  {
@@ -4529,11 +4789,13 @@ exports.SectionHeading = SectionHeading;
4529
4789
  exports.SegmentedControls = SegmentedControls;
4530
4790
  exports.Select = Select;
4531
4791
  exports.SelectContent = SelectContent;
4792
+ exports.SelectEmpty = SelectEmpty;
4532
4793
  exports.SelectGroup = SelectGroup;
4533
4794
  exports.SelectItem = SelectItem;
4534
4795
  exports.SelectLabel = SelectLabel;
4535
4796
  exports.SelectScrollDownButton = SelectScrollDownButton;
4536
4797
  exports.SelectScrollUpButton = SelectScrollUpButton;
4798
+ exports.SelectSearch = SelectSearch;
4537
4799
  exports.SelectSeparator = SelectSeparator;
4538
4800
  exports.SelectTrigger = SelectTrigger;
4539
4801
  exports.SelectValue = SelectValue;