Spaces:
Runtime error
Runtime error
File size: 79,295 Bytes
077865a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 | import { i as __toESM, r as __exportAll, t as require_react } from "./react-DMmEJb6B.js";
import { t as require_jsx_runtime } from "./react_jsx-runtime.js";
import { C as getWindow, E as isHTMLElement, f as useStableCallback, l as mergeProps, n as EMPTY_ARRAY, p as useRefWithInit, r as EMPTY_OBJECT, s as useMergedRefs, t as useRenderElement, u as useIsoLayoutEffect } from "./useRenderElement-3Cwvu1gO.js";
import { t as useButton } from "./useButton-CBy-cFDk.js";
import { a as fieldValidityMapping, i as useFieldRootContext, n as useLabelableId, r as useLabelableContext, t as useRegisterFieldControl } from "./useRegisterFieldControl-CPlvTQh-.js";
import { t as useFormContext } from "./FormContext-D8skpAva.js";
import { _ as useBaseUiId, g as ownerDocument, h as windowResize, l as none, n as cancelOpen, s as itemPress, t as createChangeEventDetails } from "./createBaseUIEventDetails-CJxlTiBH.js";
import { $ as addEventListener, A as useStore, F as useDismiss, I as useClick, K as DROPDOWN_COLLISION_AVOIDANCE, L as FloatingFocusManager, Mt as getFloatingFocusElement, N as createSelector, Ot as isVirtualClick, P as platform, Tt as rectToClientRect, W as FloatingPortal, Wt as isWebKit, Z as useValueAsRef, _ as FOCUSABLE_POPUP_PROPS, a as useAnchoredPopupScrollLock, c as useAnchorPositioning, d as inertValue, et as popupStateMapping, f as getDisabledMountTransitionStyles, h as useFloatingRootContext, i as useOnFirstRender, it as useOpenChangeComplete, k as Store, lt as useTimeout, m as useToolbarRootContext, n as useOpenInteractionType, nt as triggerOpenStateMapping, o as usePositioner, ot as transitionStatusMapping, p as COMPOSITE_KEYS, rt as useTransitionStatus, s as InternalBackdrop, st as useAnimationFrame, t as usePreviousValue, tt as pressableTriggerOpenStateMapping, u as useDirection } from "./usePreviousValue-rDCHxn0g.js";
import { n as contains, r as getTarget } from "./shadowDom-kQ51Rhp9.js";
import { t as useControlled } from "./useControlled-B7gU8wdF.js";
import { a as useListNavigation, i as useTypeahead, n as getPseudoElementBounds, o as IndexGuessBehavior, r as CompositeList, s as useCompositeListItem, t as Separator } from "./Separator-CTGaP8Tv.js";
import { n as visuallyHidden, r as visuallyHiddenInput, t as useValueChanged } from "./useValueChanged-C6oHa1CC.js";
//#region ../node_modules/@base-ui/react/esm/utils/useRegisteredLabelId.js
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
var import_jsx_runtime = require_jsx_runtime();
function useRegisteredLabelId(idProp, setLabelId) {
const id = useBaseUiId(idProp);
useIsoLayoutEffect(() => {
setLabelId(id);
return () => {
setLabelId(void 0);
};
}, [id, setLabelId]);
return id;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/internals/labelable-provider/useLabel.js
function useLabel(params = {}) {
const { id: idProp, fallbackControlId, native = false, setLabelId: setLabelIdProp, focusControl: focusControlProp } = params;
const { controlId: contextControlId, setLabelId: setContextLabelId } = useLabelableContext();
const id = useRegisteredLabelId(idProp, useStableCallback((nextLabelId) => {
setContextLabelId(nextLabelId);
setLabelIdProp?.(nextLabelId);
}));
const resolvedControlId = contextControlId ?? fallbackControlId;
function focusControl(event) {
if (focusControlProp) {
focusControlProp(event, resolvedControlId);
return;
}
if (!resolvedControlId) return;
const controlElement = ownerDocument(event.currentTarget).getElementById(resolvedControlId);
if (isHTMLElement(controlElement)) focusElementWithVisible(controlElement);
}
function handleInteraction(event) {
if (getTarget(event.nativeEvent)?.closest("button,input,select,textarea")) return;
if (!event.defaultPrevented && event.detail > 1) event.preventDefault();
if (native) return;
focusControl(event);
}
return native ? {
id,
htmlFor: resolvedControlId ?? void 0,
onMouseDown: handleInteraction
} : {
id,
onClick: handleInteraction,
onPointerDown(event) {
event.preventDefault();
}
};
}
function focusElementWithVisible(element) {
element.focus({ focusVisible: true });
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/root/SelectRootContext.js
var SelectRootContext = /* @__PURE__ */ import_react.createContext(null);
SelectRootContext.displayName = "SelectRootContext";
var SelectFloatingContext = /* @__PURE__ */ import_react.createContext(null);
SelectFloatingContext.displayName = "SelectFloatingContext";
function useSelectRootContext() {
const context = import_react.useContext(SelectRootContext);
if (context === null) throw new Error("Base UI: SelectRootContext is missing. Select parts must be placed within <Select.Root>.");
return context;
}
function useSelectFloatingContext() {
const context = import_react.useContext(SelectFloatingContext);
if (context === null) throw new Error("Base UI: SelectFloatingContext is missing. Select parts must be placed within <Select.Root>.");
return context;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/internals/itemEquality.js
var defaultItemEquality = (itemValue, selectedValue) => Object.is(itemValue, selectedValue);
function compareItemEquality(itemValue, selectedValue, comparer) {
if (itemValue == null || selectedValue == null) return Object.is(itemValue, selectedValue);
return comparer(itemValue, selectedValue);
}
function selectedValueIncludes(selectedValues, itemValue, comparer) {
if (!selectedValues || selectedValues.length === 0) return false;
return selectedValues.some((selectedValue) => {
if (selectedValue === void 0) return false;
return compareItemEquality(itemValue, selectedValue, comparer);
});
}
function findItemIndex(itemValues, selectedValue, comparer) {
if (!itemValues || itemValues.length === 0) return -1;
return itemValues.findIndex((itemValue) => {
if (itemValue === void 0) return false;
return compareItemEquality(itemValue, selectedValue, comparer);
});
}
function removeItem(selectedValues, itemValue, comparer) {
return selectedValues.filter((selectedValue) => !compareItemEquality(itemValue, selectedValue, comparer));
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/internals/serializeValue.js
function serializeValue(value) {
if (value == null) return "";
if (typeof value === "string") return value;
try {
return JSON.stringify(value);
} catch {
return String(value);
}
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/internals/resolveValueLabel.js
function isGroupedItems(items) {
return items != null && items.length > 0 && typeof items[0] === "object" && items[0] != null && "items" in items[0];
}
/**
* Checks if the items array contains an item with a null value that has a non-null label.
*/
function hasNullItemLabel(items) {
if (!Array.isArray(items)) return items != null && "null" in items;
const arrayItems = items;
if (isGroupedItems(arrayItems)) {
for (const group of arrayItems) for (const item of group.items) if (item && item.value == null && item.label != null) return true;
return false;
}
for (const item of arrayItems) if (item && item.value == null && item.label != null) return true;
return false;
}
function stringifyAsLabel(item, itemToStringLabel) {
if (itemToStringLabel && item != null) return itemToStringLabel(item) ?? "";
if (item && typeof item === "object") {
if ("label" in item && item.label != null) return String(item.label);
if ("value" in item) return String(item.value);
}
return serializeValue(item);
}
function stringifyAsValue(item, itemToStringValue) {
if (itemToStringValue && item != null) return itemToStringValue(item) ?? "";
if (item && typeof item === "object" && "value" in item && "label" in item) return serializeValue(item.value);
return serializeValue(item);
}
function resolveSelectedLabel(value, items, itemToStringLabel) {
function fallback() {
return stringifyAsLabel(value, itemToStringLabel);
}
if (itemToStringLabel && value != null) return itemToStringLabel(value);
if (value && typeof value === "object" && "label" in value && value.label != null) return value.label;
if (items && !Array.isArray(items)) return items[value] ?? fallback();
if (Array.isArray(items)) {
const arrayItems = items;
const flatItems = isGroupedItems(arrayItems) ? arrayItems.flatMap((group) => group.items) : arrayItems;
if (value == null || typeof value !== "object") {
const match = flatItems.find((item) => item.value === value);
if (match && match.label != null) return match.label;
return fallback();
}
if ("value" in value) {
const match = flatItems.find((item) => item && item.value === value.value);
if (match && match.label != null) return match.label;
}
}
return fallback();
}
function resolveMultipleLabels(values, items, itemToStringLabel) {
return values.reduce((acc, value, index) => {
if (index > 0) acc.push(", ");
acc.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: resolveSelectedLabel(value, items, itemToStringLabel) }, index));
return acc;
}, []);
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/store.js
var selectors = {
id: createSelector((state) => state.id),
labelId: createSelector((state) => state.labelId),
modal: createSelector((state) => state.modal),
multiple: createSelector((state) => state.multiple),
items: createSelector((state) => state.items),
itemToStringLabel: createSelector((state) => state.itemToStringLabel),
itemToStringValue: createSelector((state) => state.itemToStringValue),
isItemEqualToValue: createSelector((state) => state.isItemEqualToValue),
value: createSelector((state) => state.value),
hasSelectedValue: createSelector((state) => {
const { value, multiple, itemToStringValue } = state;
if (value == null) return false;
if (multiple && Array.isArray(value)) return value.length > 0;
return stringifyAsValue(value, itemToStringValue) !== "";
}),
hasNullItemLabel: createSelector((state, enabled) => {
return enabled ? hasNullItemLabel(state.items) : false;
}),
open: createSelector((state) => state.open),
mounted: createSelector((state) => state.mounted),
forceMount: createSelector((state) => state.forceMount),
transitionStatus: createSelector((state) => state.transitionStatus),
openMethod: createSelector((state) => state.openMethod),
activeIndex: createSelector((state) => state.activeIndex),
selectedIndex: createSelector((state) => state.selectedIndex),
isActive: createSelector((state, index) => state.activeIndex === index),
isSelected: createSelector((state, index, itemValue) => {
const comparer = state.isItemEqualToValue;
const storeValue = state.value;
if (state.multiple) return Array.isArray(storeValue) && storeValue.some((selectedItem) => compareItemEquality(itemValue, selectedItem, comparer));
if (state.selectedIndex === index && state.selectedIndex !== null) return true;
return compareItemEquality(itemValue, storeValue, comparer);
}),
isSelectedByFocus: createSelector((state, index) => {
return state.selectedIndex === index;
}),
popupProps: createSelector((state) => state.popupProps),
triggerProps: createSelector((state) => state.triggerProps),
triggerElement: createSelector((state) => state.triggerElement),
positionerElement: createSelector((state) => state.positionerElement),
listElement: createSelector((state) => state.listElement),
popupSide: createSelector((state) => state.popupSide),
scrollUpArrowVisible: createSelector((state) => state.scrollUpArrowVisible),
scrollDownArrowVisible: createSelector((state) => state.scrollDownArrowVisible),
hasScrollArrows: createSelector((state) => state.hasScrollArrows)
};
//#endregion
//#region ../node_modules/@base-ui/react/esm/internals/clamp.js
function clamp(val, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) {
return Math.max(min, Math.min(val, max));
}
function getMaxScrollOffset(scrollSize, clientSize) {
return Math.max(0, scrollSize - clientSize);
}
function normalizeScrollOffset(value, max) {
if (max <= 0) return 0;
const clamped = clamp(value, 0, max);
const startDistance = clamped;
const endDistance = max - clamped;
const withinStartTolerance = startDistance <= 1;
const withinEndTolerance = endDistance <= 1;
if (withinStartTolerance && withinEndTolerance) return startDistance <= endDistance ? 0 : max;
if (withinStartTolerance) return 0;
if (withinEndTolerance) return max;
return clamped;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/root/SelectRoot.js
/**
* Groups all parts of the select.
* Doesn't render its own HTML element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
function SelectRoot(props) {
const { id, value: valueProp, defaultValue = null, onValueChange, open: openProp, defaultOpen = false, onOpenChange, name: nameProp, form, autoComplete, disabled: disabledProp = false, readOnly = false, required = false, modal = true, actionsRef, inputRef, onOpenChangeComplete, items, multiple = false, itemToStringLabel, itemToStringValue, isItemEqualToValue = defaultItemEquality, highlightItemOnHover = true, children } = props;
const { clearErrors } = useFormContext();
const { setDirty, setTouched, setFocused, shouldValidateOnChange, validityData, setFilled, name: fieldName, disabled: fieldDisabled, validation, validationMode } = useFieldRootContext();
const generatedId = useLabelableId({ id });
const disabled = fieldDisabled || disabledProp;
const name = fieldName ?? nameProp;
const [value, setValueUnwrapped] = useControlled({
controlled: valueProp,
default: multiple ? defaultValue ?? EMPTY_ARRAY : defaultValue,
name: "Select",
state: "value"
});
const [open, setOpenUnwrapped] = useControlled({
controlled: openProp,
default: defaultOpen,
name: "Select",
state: "open"
});
const listRef = import_react.useRef([]);
const labelsRef = import_react.useRef([]);
const popupRef = import_react.useRef(null);
const scrollHandlerRef = import_react.useRef(null);
const scrollArrowsMountedCountRef = import_react.useRef(0);
const valueRef = import_react.useRef(null);
const valuesRef = import_react.useRef([]);
const typingRef = import_react.useRef(false);
const keyboardActiveRef = import_react.useRef(false);
const firstItemTextRef = import_react.useRef(null);
const selectedItemTextRef = import_react.useRef(null);
const selectionRef = import_react.useRef({
allowSelectedMouseUp: false,
allowUnselectedMouseUp: false,
dragY: 0
});
const alignItemWithTriggerActiveRef = import_react.useRef(false);
const { mounted, setMounted, transitionStatus } = useTransitionStatus(open);
const { openMethod, triggerProps: interactionTypeProps } = useOpenInteractionType(open);
const store = useRefWithInit(() => new Store({
id: generatedId,
labelId: void 0,
modal,
multiple,
itemToStringLabel,
itemToStringValue,
isItemEqualToValue,
value,
open,
mounted,
transitionStatus,
items,
forceMount: false,
openMethod: null,
activeIndex: null,
selectedIndex: null,
popupProps: {},
triggerProps: {},
triggerElement: null,
positionerElement: null,
listElement: null,
popupSide: null,
scrollUpArrowVisible: false,
scrollDownArrowVisible: false,
hasScrollArrows: false
})).current;
const activeIndex = useStore(store, selectors.activeIndex);
const selectedIndex = useStore(store, selectors.selectedIndex);
const triggerElement = useStore(store, selectors.triggerElement);
const positionerElement = useStore(store, selectors.positionerElement);
const previousOpenMethod = usePreviousValue(openMethod);
const renderedOpenMethod = openMethod ?? previousOpenMethod;
const serializedValue = import_react.useMemo(() => {
if (multiple && Array.isArray(value) && value.length === 0) return "";
return stringifyAsValue(value, itemToStringValue);
}, [
multiple,
value,
itemToStringValue
]);
const fieldStringValue = import_react.useMemo(() => {
if (multiple && Array.isArray(value)) return value.map((currentValue) => stringifyAsValue(currentValue, itemToStringValue));
return stringifyAsValue(value, itemToStringValue);
}, [
multiple,
value,
itemToStringValue
]);
useRegisterFieldControl(useValueAsRef(store.state.triggerElement), generatedId, value, useStableCallback(() => fieldStringValue));
const initialValueRef = import_react.useRef(value);
const hasSelectedValue = multiple ? Array.isArray(value) && value.length > 0 : value != null;
useIsoLayoutEffect(() => {
if (value !== initialValueRef.current) store.set("forceMount", true);
}, [store, value]);
useIsoLayoutEffect(() => {
setFilled(hasSelectedValue);
}, [hasSelectedValue, setFilled]);
useIsoLayoutEffect(function syncSelectedIndex() {
const registry = valuesRef.current;
let nextIndex;
if (multiple) {
const currentValue = Array.isArray(value) ? value : [];
if (currentValue.length === 0) nextIndex = null;
else {
const lastValue = currentValue[currentValue.length - 1];
const lastIndex = findItemIndex(registry, lastValue, isItemEqualToValue);
nextIndex = lastIndex === -1 ? null : lastIndex;
}
} else {
const index = findItemIndex(registry, value, isItemEqualToValue);
nextIndex = index === -1 ? null : index;
}
if (nextIndex === null) selectedItemTextRef.current = null;
if (open) return;
store.set("selectedIndex", nextIndex);
}, [
hasSelectedValue,
multiple,
open,
value,
valuesRef,
isItemEqualToValue,
store,
selectedItemTextRef
]);
useValueChanged(value, () => {
clearErrors(name);
setDirty(value !== validityData.initialValue);
if (shouldValidateOnChange()) validation.commit(value);
else validation.commit(value, true);
});
const setOpen = useStableCallback((nextOpen, eventDetails) => {
onOpenChange?.(nextOpen, eventDetails);
if (eventDetails.isCanceled) return;
setOpenUnwrapped(nextOpen);
if (!nextOpen && (eventDetails.reason === "focus-out" || eventDetails.reason === "outside-press")) {
setTouched(true);
setFocused(false);
if (validationMode === "onBlur") validation.commit(value);
}
if (!nextOpen && store.state.activeIndex !== null) {
const activeOption = listRef.current[store.state.activeIndex];
queueMicrotask(() => {
activeOption?.setAttribute("tabindex", "-1");
});
}
});
const handleUnmount = useStableCallback(() => {
setMounted(false);
store.update({
activeIndex: null,
openMethod: null
});
onOpenChangeComplete?.(false);
});
useOpenChangeComplete({
enabled: !actionsRef,
open,
ref: popupRef,
onComplete() {
if (!open) handleUnmount();
}
});
import_react.useImperativeHandle(actionsRef, () => ({ unmount: handleUnmount }), [handleUnmount]);
const setValue = useStableCallback((nextValue, eventDetails) => {
onValueChange?.(nextValue, eventDetails);
if (eventDetails.isCanceled) return;
setValueUnwrapped(nextValue);
});
const handleScrollArrowVisibility = useStableCallback(() => {
const scroller = store.state.listElement || popupRef.current;
if (!scroller) return;
const maxScrollTop = getMaxScrollOffset(scroller.scrollHeight, scroller.clientHeight);
const scrollTop = normalizeScrollOffset(scroller.scrollTop, maxScrollTop);
const shouldShowUp = scrollTop > 0;
const shouldShowDown = scrollTop < maxScrollTop;
if (store.state.scrollUpArrowVisible !== shouldShowUp) store.set("scrollUpArrowVisible", shouldShowUp);
if (store.state.scrollDownArrowVisible !== shouldShowDown) store.set("scrollDownArrowVisible", shouldShowDown);
});
const floatingContext = useFloatingRootContext({
open,
onOpenChange: setOpen,
elements: {
reference: triggerElement,
floating: positionerElement
}
});
const click = useClick(floatingContext, {
enabled: !readOnly && !disabled,
event: "mousedown"
});
const dismiss = useDismiss(floatingContext);
const listNavigation = useListNavigation(floatingContext, {
enabled: !readOnly && !disabled,
listRef,
activeIndex,
selectedIndex,
disabledIndices: EMPTY_ARRAY,
onNavigate(nextActiveIndex) {
if (nextActiveIndex === null && !open) return;
store.set("activeIndex", nextActiveIndex);
},
focusItemOnHover: highlightItemOnHover
});
const typeahead = useTypeahead(floatingContext, {
enabled: !readOnly && !disabled && (open || !multiple),
listRef: labelsRef,
activeIndex,
selectedIndex,
onMatch(index) {
if (open) store.set("activeIndex", index);
else setValue(valuesRef.current[index], createChangeEventDetails("none"));
},
onTyping(typing) {
typingRef.current = typing;
}
});
const mergedTriggerProps = import_react.useMemo(() => {
const triggerInteractionProps = mergeProps(typeahead.reference, listNavigation.reference, dismiss.reference, click.reference, interactionTypeProps);
if (generatedId) triggerInteractionProps.id = generatedId;
return triggerInteractionProps;
}, [
click.reference,
typeahead.reference,
listNavigation.reference,
dismiss.reference,
interactionTypeProps,
generatedId
]);
const popupProps = import_react.useMemo(() => mergeProps(FOCUSABLE_POPUP_PROPS, typeahead.floating, listNavigation.floating, dismiss.floating), [
typeahead.floating,
listNavigation.floating,
dismiss.floating
]);
const itemProps = listNavigation.item ?? EMPTY_OBJECT;
useOnFirstRender(() => {
store.update({
popupProps,
triggerProps: mergedTriggerProps
});
});
useIsoLayoutEffect(() => {
store.update({
id: generatedId,
modal,
multiple,
value,
open,
mounted,
transitionStatus,
popupProps,
triggerProps: mergedTriggerProps,
items,
itemToStringLabel,
itemToStringValue,
isItemEqualToValue,
openMethod: renderedOpenMethod
});
}, [
store,
generatedId,
modal,
multiple,
value,
open,
mounted,
transitionStatus,
popupProps,
mergedTriggerProps,
items,
itemToStringLabel,
itemToStringValue,
isItemEqualToValue,
renderedOpenMethod
]);
const contextValue = import_react.useMemo(() => ({
store,
name,
required,
disabled,
readOnly,
multiple,
highlightItemOnHover,
setValue,
setOpen,
listRef,
popupRef,
scrollHandlerRef,
handleScrollArrowVisibility,
scrollArrowsMountedCountRef,
itemProps,
events: floatingContext.context.events,
valueRef,
valuesRef,
labelsRef,
typingRef,
selectionRef,
firstItemTextRef,
selectedItemTextRef,
validation,
onOpenChangeComplete,
keyboardActiveRef,
alignItemWithTriggerActiveRef,
initialValueRef
}), [
store,
name,
required,
disabled,
readOnly,
multiple,
highlightItemOnHover,
setValue,
setOpen,
itemProps,
floatingContext.context.events,
validation,
onOpenChangeComplete,
handleScrollArrowVisibility
]);
const ref = useMergedRefs(inputRef, validation.inputRef);
const hasMultipleSelection = multiple && Array.isArray(value) && value.length > 0;
const hiddenInputName = multiple ? void 0 : name;
const hiddenInputs = import_react.useMemo(() => {
if (!multiple || !Array.isArray(value) || !name) return null;
return value.map((v) => {
const currentSerializedValue = stringifyAsValue(v, itemToStringValue);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
type: "hidden",
form,
name,
value: currentSerializedValue
}, currentSerializedValue);
});
}, [
multiple,
value,
form,
name,
itemToStringValue
]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectRootContext.Provider, {
value: contextValue,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SelectFloatingContext.Provider, {
value: floatingContext,
children: [
children,
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
...validation.getInputValidationProps({
onFocus() {
store.state.triggerElement?.focus({ focusVisible: true });
},
onChange(event) {
if (event.nativeEvent.defaultPrevented || disabled || readOnly) {
event.preventBaseUIHandler?.();
return;
}
const nextValue = event.currentTarget.value;
const details = createChangeEventDetails(none, event.nativeEvent);
function handleChange() {
if (multiple) return;
const matchingValue = valuesRef.current.find((v) => {
if (stringifyAsValue(v, itemToStringValue).toLowerCase() === nextValue.toLowerCase()) return true;
if (stringifyAsLabel(v, itemToStringLabel).toLowerCase() === nextValue.toLowerCase()) return true;
return false;
});
if (matchingValue != null) {
setDirty(matchingValue !== validityData.initialValue);
setValue(matchingValue, details);
if (shouldValidateOnChange()) validation.commit(matchingValue);
}
}
store.set("forceMount", true);
queueMicrotask(handleChange);
}
}),
id: generatedId && hiddenInputName == null ? `${generatedId}-hidden-input` : void 0,
form,
name: hiddenInputName,
autoComplete,
value: serializedValue,
disabled,
required: required && !hasMultipleSelection,
readOnly,
ref,
style: name ? visuallyHiddenInput : visuallyHidden,
tabIndex: -1,
"aria-hidden": true,
suppressHydrationWarning: true
}),
hiddenInputs
]
})
});
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/utils/resolveAriaLabelledBy.js
function getDefaultLabelId(id) {
return id == null ? void 0 : `${id}-label`;
}
function resolveAriaLabelledBy(fieldLabelId, localLabelId) {
return fieldLabelId ?? localLabelId;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/label/SelectLabel.js
/**
* An accessible label that is automatically associated with the select trigger.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectLabel = /* @__PURE__ */ import_react.forwardRef(function SelectLabel(componentProps, forwardedRef) {
const { render, className, style, ...elementProps } = componentProps;
const elementPropsWithoutId = elementProps;
delete elementPropsWithoutId.id;
const fieldRootContext = useFieldRootContext();
const { store } = useSelectRootContext();
const triggerElement = useStore(store, selectors.triggerElement);
const rootId = useStore(store, selectors.id);
const labelProps = useLabel({
id: getDefaultLabelId(rootId),
fallbackControlId: triggerElement?.id ?? rootId,
setLabelId(nextLabelId) {
store.set("labelId", nextLabelId);
}
});
return useRenderElement("div", componentProps, {
ref: forwardedRef,
state: fieldRootContext.state,
props: [labelProps, elementProps],
stateAttributesMapping: fieldValidityMapping
});
});
SelectLabel.displayName = "SelectLabel";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/trigger/SelectTrigger.js
var BOUNDARY_OFFSET = 2;
var SELECTED_DELAY = 400;
var stateAttributesMapping$4 = {
...pressableTriggerOpenStateMapping,
...fieldValidityMapping,
popupSide: (side) => side ? { "data-popup-side": side } : null,
value: () => null
};
/**
* A button that opens the select popup.
* Renders a `<button>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectTrigger = /* @__PURE__ */ import_react.forwardRef(function SelectTrigger(componentProps, forwardedRef) {
const { render, className, id: idProp, disabled: disabledProp = false, nativeButton = true, style, ...elementProps } = componentProps;
const { setTouched, setFocused, validationMode, state: fieldState, disabled: fieldDisabled } = useFieldRootContext();
const { labelId: fieldLabelId } = useLabelableContext();
const { store, setOpen, selectionRef, validation, readOnly, required, alignItemWithTriggerActiveRef, disabled: selectDisabled, keyboardActiveRef } = useSelectRootContext();
const disabled = fieldDisabled || selectDisabled || disabledProp;
const open = useStore(store, selectors.open);
const mounted = useStore(store, selectors.mounted);
const value = useStore(store, selectors.value);
const triggerProps = useStore(store, selectors.triggerProps);
const positionerElement = useStore(store, selectors.positionerElement);
const listElement = useStore(store, selectors.listElement);
const popupSideValue = useStore(store, selectors.popupSide);
const rootId = useStore(store, selectors.id);
const selectLabelId = useStore(store, selectors.labelId);
const hasSelectedValue = useStore(store, selectors.hasSelectedValue);
const popupSide = mounted && positionerElement ? popupSideValue : null;
const id = idProp ?? rootId;
const ariaLabelledBy = resolveAriaLabelledBy(fieldLabelId, selectLabelId);
useLabelableId({ id });
const positionerRef = useValueAsRef(positionerElement);
const triggerRef = import_react.useRef(null);
const { getButtonProps, buttonRef } = useButton({
disabled,
native: nativeButton
});
const mergedRef = useMergedRefs(forwardedRef, triggerRef, buttonRef, useStableCallback((element) => {
store.set("triggerElement", element);
}));
const timeoutFocus = useTimeout();
const timeoutMouseDown = useTimeout();
const selectedDelayTimeout = useTimeout();
import_react.useEffect(() => {
if (open) {
selectedDelayTimeout.start(SELECTED_DELAY, () => {
selectionRef.current.allowUnselectedMouseUp = true;
selectionRef.current.allowSelectedMouseUp = true;
});
return () => {
selectedDelayTimeout.clear();
};
}
selectionRef.current = {
allowSelectedMouseUp: false,
allowUnselectedMouseUp: false,
dragY: 0
};
timeoutMouseDown.clear();
}, [
open,
selectionRef,
timeoutMouseDown,
selectedDelayTimeout
]);
const props = mergeProps(triggerProps, {
id,
role: "combobox",
"aria-expanded": open ? "true" : "false",
"aria-haspopup": "listbox",
"aria-controls": open ? listElement?.id ?? getFloatingFocusElement(positionerElement)?.id : void 0,
"aria-labelledby": ariaLabelledBy,
"aria-readonly": readOnly || void 0,
"aria-required": required || void 0,
tabIndex: disabled ? -1 : 0,
ref: mergedRef,
onFocus(event) {
setFocused(true);
if (open && alignItemWithTriggerActiveRef.current) setOpen(false, createChangeEventDetails(none, event.nativeEvent));
timeoutFocus.start(0, () => {
store.set("forceMount", true);
});
},
onBlur(event) {
if (contains(positionerElement, event.relatedTarget)) return;
setTouched(true);
setFocused(false);
if (validationMode === "onBlur") validation.commit(value);
},
onPointerMove() {
keyboardActiveRef.current = false;
},
onKeyDown() {
keyboardActiveRef.current = true;
},
onMouseDown(event) {
if (open) return;
const doc = ownerDocument(event.currentTarget);
function handleMouseUp(mouseEvent) {
if (!triggerRef.current) return;
const mouseUpTarget = mouseEvent.target;
if (contains(triggerRef.current, mouseUpTarget) || contains(positionerRef.current, mouseUpTarget) || mouseUpTarget === triggerRef.current) return;
const bounds = getPseudoElementBounds(triggerRef.current);
if (mouseEvent.clientX >= bounds.left - BOUNDARY_OFFSET && mouseEvent.clientX <= bounds.right + BOUNDARY_OFFSET && mouseEvent.clientY >= bounds.top - BOUNDARY_OFFSET && mouseEvent.clientY <= bounds.bottom + BOUNDARY_OFFSET) return;
setOpen(false, createChangeEventDetails(cancelOpen, mouseEvent));
}
timeoutMouseDown.start(0, () => {
doc.addEventListener("mouseup", handleMouseUp, { once: true });
});
}
}, validation.getValidationProps, elementProps, getButtonProps);
props.role = "combobox";
const state = {
...fieldState,
open,
disabled,
value,
readOnly,
popupSide,
placeholder: !hasSelectedValue
};
return useRenderElement("button", componentProps, {
ref: [forwardedRef, triggerRef],
state,
stateAttributesMapping: stateAttributesMapping$4,
props
});
});
SelectTrigger.displayName = "SelectTrigger";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/value/SelectValue.js
var stateAttributesMapping$3 = { value: () => null };
/**
* A text label of the currently selected item.
* Renders a `<span>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectValue = /* @__PURE__ */ import_react.forwardRef(function SelectValue(componentProps, forwardedRef) {
const { className, render, children: childrenProp, placeholder, style, ...elementProps } = componentProps;
const { store, valueRef } = useSelectRootContext();
const value = useStore(store, selectors.value);
const items = useStore(store, selectors.items);
const itemToStringLabel = useStore(store, selectors.itemToStringLabel);
const hasSelectedValue = useStore(store, selectors.hasSelectedValue);
const shouldCheckNullItemLabel = !hasSelectedValue && placeholder != null && childrenProp == null;
const hasNullLabel = useStore(store, selectors.hasNullItemLabel, shouldCheckNullItemLabel);
const state = {
value,
placeholder: !hasSelectedValue
};
let children = null;
if (typeof childrenProp === "function") children = childrenProp(value);
else if (childrenProp != null) children = childrenProp;
else if (!hasSelectedValue && placeholder != null && !hasNullLabel) children = placeholder;
else if (Array.isArray(value)) children = resolveMultipleLabels(value, items, itemToStringLabel);
else children = resolveSelectedLabel(value, items, itemToStringLabel);
return useRenderElement("span", componentProps, {
state,
ref: [forwardedRef, valueRef],
props: [{ children }, elementProps],
stateAttributesMapping: stateAttributesMapping$3
});
});
SelectValue.displayName = "SelectValue";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/icon/SelectIcon.js
/**
* An icon that indicates that the trigger button opens a select popup.
* Renders a `<span>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectIcon = /* @__PURE__ */ import_react.forwardRef(function SelectIcon(componentProps, forwardedRef) {
const { render, className, style, ...elementProps } = componentProps;
const { store } = useSelectRootContext();
return useRenderElement("span", componentProps, {
state: { open: useStore(store, selectors.open) },
ref: forwardedRef,
props: [{
"aria-hidden": true,
children: "▼"
}, elementProps],
stateAttributesMapping: triggerOpenStateMapping
});
});
SelectIcon.displayName = "SelectIcon";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/portal/SelectPortalContext.js
var SelectPortalContext = /* @__PURE__ */ import_react.createContext(void 0);
SelectPortalContext.displayName = "SelectPortalContext";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/portal/SelectPortal.js
/**
* A portal element that moves the popup to a different part of the DOM.
* By default, the portal element is appended to `<body>`.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectPortal = /* @__PURE__ */ import_react.forwardRef(function SelectPortal(portalProps, forwardedRef) {
const { store } = useSelectRootContext();
const mounted = useStore(store, selectors.mounted);
const forceMount = useStore(store, selectors.forceMount);
if (!(mounted || forceMount)) return null;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectPortalContext.Provider, {
value: true,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FloatingPortal, {
ref: forwardedRef,
...portalProps
})
});
});
SelectPortal.displayName = "SelectPortal";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/backdrop/SelectBackdrop.js
var stateAttributesMapping$2 = {
...popupStateMapping,
...transitionStatusMapping
};
/**
* An overlay displayed beneath the menu popup.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectBackdrop = /* @__PURE__ */ import_react.forwardRef(function SelectBackdrop(componentProps, forwardedRef) {
const { render, className, style, ...elementProps } = componentProps;
const { store } = useSelectRootContext();
const open = useStore(store, selectors.open);
const mounted = useStore(store, selectors.mounted);
return useRenderElement("div", componentProps, {
state: {
open,
transitionStatus: useStore(store, selectors.transitionStatus)
},
ref: forwardedRef,
props: [{
role: "presentation",
hidden: !mounted,
style: {
userSelect: "none",
WebkitUserSelect: "none"
}
}, elementProps],
stateAttributesMapping: stateAttributesMapping$2
});
});
SelectBackdrop.displayName = "SelectBackdrop";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/positioner/SelectPositionerContext.js
var SelectPositionerContext = /* @__PURE__ */ import_react.createContext(void 0);
SelectPositionerContext.displayName = "SelectPositionerContext";
function useSelectPositionerContext() {
const context = import_react.useContext(SelectPositionerContext);
if (!context) throw new Error("Base UI: SelectPositionerContext is missing. SelectPositioner parts must be placed within <Select.Positioner>.");
return context;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/popup/utils.js
function clearStyles(element, originalStyles) {
if (element) Object.assign(element.style, originalStyles);
}
var LIST_FUNCTIONAL_STYLES = {
position: "relative",
maxHeight: "100%",
overflowX: "hidden",
overflowY: "auto"
};
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/positioner/SelectPositioner.js
var FIXED = { position: "fixed" };
/**
* Positions the select popup.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectPositioner = /* @__PURE__ */ import_react.forwardRef(function SelectPositioner(componentProps, forwardedRef) {
const { anchor, positionMethod = "absolute", className, render, side = "bottom", align = "center", sideOffset = 0, alignOffset = 0, collisionBoundary = "clipping-ancestors", collisionPadding, arrowPadding = 5, sticky = false, disableAnchorTracking, alignItemWithTrigger = true, collisionAvoidance = DROPDOWN_COLLISION_AVOIDANCE, style, ...elementProps } = componentProps;
const { store, listRef, labelsRef, alignItemWithTriggerActiveRef, selectedItemTextRef, valuesRef, initialValueRef, popupRef, setValue } = useSelectRootContext();
const floatingRootContext = useSelectFloatingContext();
const open = useStore(store, selectors.open);
const mounted = useStore(store, selectors.mounted);
const modal = useStore(store, selectors.modal);
const value = useStore(store, selectors.value);
const openMethod = useStore(store, selectors.openMethod);
const positionerElement = useStore(store, selectors.positionerElement);
const triggerElement = useStore(store, selectors.triggerElement);
const isItemEqualToValue = useStore(store, selectors.isItemEqualToValue);
const transitionStatus = useStore(store, selectors.transitionStatus);
const scrollUpArrowRef = import_react.useRef(null);
const scrollDownArrowRef = import_react.useRef(null);
const [controlledAlignItemWithTrigger, setControlledAlignItemWithTrigger] = import_react.useState(alignItemWithTrigger);
const alignItemWithTriggerActive = mounted && controlledAlignItemWithTrigger && openMethod !== "touch";
if (!mounted && controlledAlignItemWithTrigger !== alignItemWithTrigger) setControlledAlignItemWithTrigger(alignItemWithTrigger);
useIsoLayoutEffect(() => {
if (!mounted) {
if (selectors.scrollUpArrowVisible(store.state)) store.set("scrollUpArrowVisible", false);
if (selectors.scrollDownArrowVisible(store.state)) store.set("scrollDownArrowVisible", false);
}
}, [store, mounted]);
import_react.useImperativeHandle(alignItemWithTriggerActiveRef, () => alignItemWithTriggerActive);
useAnchoredPopupScrollLock((alignItemWithTriggerActive || modal) && open, openMethod === "touch", positionerElement, triggerElement);
const positioning = useAnchorPositioning({
anchor,
floatingRootContext,
positionMethod,
mounted,
side,
sideOffset,
align,
alignOffset,
arrowPadding,
collisionBoundary,
collisionPadding,
sticky,
disableAnchorTracking: disableAnchorTracking ?? alignItemWithTriggerActive,
collisionAvoidance,
keepMounted: true
});
const renderedSide = alignItemWithTriggerActive ? "none" : positioning.side;
const positionerStyles = alignItemWithTriggerActive ? FIXED : positioning.positionerStyles;
const state = {
open,
side: renderedSide,
align: positioning.align,
anchorHidden: positioning.anchorHidden
};
useIsoLayoutEffect(() => {
store.set("popupSide", positioning.side);
}, [store, positioning.side]);
const element = usePositioner(componentProps, state, {
styles: positionerStyles,
transitionStatus,
props: elementProps,
refs: [forwardedRef, useStableCallback((element) => {
store.set("positionerElement", element);
})],
hidden: !mounted,
inert: !open
});
const prevMapSizeRef = import_react.useRef(0);
const onMapChange = useStableCallback((map) => {
if (map.size === 0 && prevMapSizeRef.current === 0) return;
if (valuesRef.current.length === 0) return;
const prevSize = prevMapSizeRef.current;
prevMapSizeRef.current = map.size;
if (map.size === prevSize) return;
const eventDetails = createChangeEventDetails(none);
if (prevSize !== 0 && !store.state.multiple && value !== null) {
if (findItemIndex(valuesRef.current, value, isItemEqualToValue) === -1) {
const initialSelectedValue = initialValueRef.current;
const nextValue = initialSelectedValue != null && findItemIndex(valuesRef.current, initialSelectedValue, isItemEqualToValue) !== -1 ? initialSelectedValue : null;
setValue(nextValue, eventDetails);
if (nextValue === null) {
store.set("selectedIndex", null);
selectedItemTextRef.current = null;
}
}
}
if (prevSize !== 0 && store.state.multiple && Array.isArray(value)) {
const hasVisibleItem = (selectedItemValue) => findItemIndex(valuesRef.current, selectedItemValue, isItemEqualToValue) !== -1;
const nextValue = value.filter((selectedItemValue) => hasVisibleItem(selectedItemValue));
if (nextValue.length !== value.length || nextValue.some((selectedItemValue) => !selectedValueIncludes(value, selectedItemValue, isItemEqualToValue))) {
setValue(nextValue, eventDetails);
if (nextValue.length === 0) {
store.set("selectedIndex", null);
selectedItemTextRef.current = null;
}
}
}
if (open && alignItemWithTriggerActive) {
store.update({
scrollUpArrowVisible: false,
scrollDownArrowVisible: false
});
const stylesToClear = { height: "" };
clearStyles(positionerElement, stylesToClear);
clearStyles(popupRef.current, stylesToClear);
}
});
const contextValue = import_react.useMemo(() => ({
...positioning,
side: renderedSide,
alignItemWithTriggerActive,
setControlledAlignItemWithTrigger,
scrollUpArrowRef,
scrollDownArrowRef
}), [
positioning,
renderedSide,
alignItemWithTriggerActive,
setControlledAlignItemWithTrigger
]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CompositeList, {
elementsRef: listRef,
labelsRef,
onMapChange,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(SelectPositionerContext.Provider, {
value: contextValue,
children: [mounted && modal && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InternalBackdrop, {
inert: inertValue(!open),
cutout: triggerElement
}), element]
})
});
});
SelectPositioner.displayName = "SelectPositioner";
//#endregion
//#region ../node_modules/@base-ui/react/esm/utils/styles.js
var DISABLE_SCROLLBAR_CLASS_NAME = "base-ui-disable-scrollbar";
var styleDisableScrollbar = {
className: DISABLE_SCROLLBAR_CLASS_NAME,
getElement(nonce) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", {
nonce,
href: DISABLE_SCROLLBAR_CLASS_NAME,
precedence: "base-ui:low",
children: `.${DISABLE_SCROLLBAR_CLASS_NAME}{scrollbar-width:none}.${DISABLE_SCROLLBAR_CLASS_NAME}::-webkit-scrollbar{display:none}`
});
}
};
styleDisableScrollbar.getElement.displayName = "styleDisableScrollbar.getElement";
//#endregion
//#region ../node_modules/@base-ui/react/esm/internals/csp-context/CSPContext.js
/**
* @internal
*/
var CSPContext = /* @__PURE__ */ import_react.createContext(void 0);
CSPContext.displayName = "CSPContext";
var DEFAULT_CSP_CONTEXT_VALUE = { disableStyleElements: false };
/**
* @internal
*/
function useCSPContext() {
return import_react.useContext(CSPContext) ?? DEFAULT_CSP_CONTEXT_VALUE;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/popup/SelectPopup.js
var stateAttributesMapping$1 = {
...popupStateMapping,
...transitionStatusMapping
};
/**
* A container for the select list.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectPopup = /* @__PURE__ */ import_react.forwardRef(function SelectPopup(componentProps, forwardedRef) {
const { render, className, style, finalFocus, ...elementProps } = componentProps;
const { store, popupRef, onOpenChangeComplete, setOpen, valueRef, firstItemTextRef, selectedItemTextRef, keyboardActiveRef, multiple, handleScrollArrowVisibility, scrollHandlerRef, listRef, highlightItemOnHover } = useSelectRootContext();
const { side, align, alignItemWithTriggerActive, isPositioned, setControlledAlignItemWithTrigger, scrollDownArrowRef, scrollUpArrowRef } = useSelectPositionerContext();
const insideToolbar = useToolbarRootContext(true) != null;
const floatingRootContext = useSelectFloatingContext();
const direction = useDirection();
const { nonce, disableStyleElements } = useCSPContext();
const id = useStore(store, selectors.id);
const open = useStore(store, selectors.open);
const mounted = useStore(store, selectors.mounted);
const popupProps = useStore(store, selectors.popupProps);
const transitionStatus = useStore(store, selectors.transitionStatus);
const triggerElement = useStore(store, selectors.triggerElement);
const positionerElement = useStore(store, selectors.positionerElement);
const listElement = useStore(store, selectors.listElement);
const reachedMaxHeightRef = import_react.useRef(false);
const initialPlacedRef = import_react.useRef(false);
const originalPositionerStylesRef = import_react.useRef({});
const scrollArrowFrame = useAnimationFrame();
const handleScroll = useStableCallback((scroller) => {
if (!positionerElement || !popupRef.current || !initialPlacedRef.current) return;
if (reachedMaxHeightRef.current || !alignItemWithTriggerActive) {
handleScrollArrowVisibility();
return;
}
const isTopPositioned = positionerElement.style.top === "0px";
const isBottomPositioned = positionerElement.style.bottom === "0px";
if (!isTopPositioned && !isBottomPositioned) {
handleScrollArrowVisibility();
return;
}
const scale = getScale(positionerElement);
const currentHeight = normalizeSize(positionerElement.getBoundingClientRect().height, "y", scale);
const doc = ownerDocument(positionerElement);
const positionerStyles = getComputedStyle(positionerElement);
const marginTop = parseFloat(positionerStyles.marginTop);
const marginBottom = parseFloat(positionerStyles.marginBottom);
const maxPopupHeight = getMaxPopupHeight(getComputedStyle(popupRef.current));
const maxAvailableHeight = Math.min(doc.documentElement.clientHeight - marginTop - marginBottom, maxPopupHeight);
const scrollTop = scroller.scrollTop;
const maxScrollTop = getMaxScrollTop(scroller);
let nextPositionerHeight = 0;
let nextScrollTop = null;
let setReachedMax = false;
let scrollToMax = false;
const setHeight = (height) => {
positionerElement.style.height = `${height}px`;
};
const handleSmallDiff = (diff, targetScrollTop) => {
const heightDelta = clamp(diff, 0, maxAvailableHeight - currentHeight);
if (heightDelta > 0) setHeight(currentHeight + heightDelta);
scroller.scrollTop = targetScrollTop;
if (maxAvailableHeight - (currentHeight + heightDelta) <= 1) reachedMaxHeightRef.current = true;
handleScrollArrowVisibility();
};
const diff = isTopPositioned ? maxScrollTop - scrollTop : scrollTop;
const nextHeight = Math.min(currentHeight + diff, maxAvailableHeight);
nextPositionerHeight = nextHeight;
if (diff <= 1) {
handleSmallDiff(diff, isTopPositioned ? maxScrollTop : 0);
return;
}
if (maxAvailableHeight - nextHeight > 1) if (isTopPositioned) scrollToMax = true;
else nextScrollTop = 0;
else {
setReachedMax = true;
if (isBottomPositioned && scrollTop < maxScrollTop) nextScrollTop = scrollTop - (diff - (currentHeight + diff - maxAvailableHeight));
}
nextPositionerHeight = Math.ceil(nextPositionerHeight);
if (nextPositionerHeight !== 0) setHeight(nextPositionerHeight);
if (scrollToMax || nextScrollTop != null) {
const nextMaxScrollTop = getMaxScrollTop(scroller);
const target = scrollToMax ? nextMaxScrollTop : clamp(nextScrollTop, 0, nextMaxScrollTop);
if (Math.abs(scroller.scrollTop - target) > 1) scroller.scrollTop = target;
}
if (setReachedMax || nextPositionerHeight >= maxAvailableHeight - 1) reachedMaxHeightRef.current = true;
handleScrollArrowVisibility();
});
import_react.useImperativeHandle(scrollHandlerRef, () => handleScroll, [handleScroll]);
useOpenChangeComplete({
open,
ref: popupRef,
onComplete() {
if (open) onOpenChangeComplete?.(true);
}
});
const state = {
open,
transitionStatus,
side,
align
};
useIsoLayoutEffect(() => {
if (!positionerElement || !popupRef.current || Object.keys(originalPositionerStylesRef.current).length) return;
originalPositionerStylesRef.current = {
top: positionerElement.style.top || "0",
left: positionerElement.style.left || "0",
right: positionerElement.style.right,
height: positionerElement.style.height,
bottom: positionerElement.style.bottom,
minHeight: positionerElement.style.minHeight,
maxHeight: positionerElement.style.maxHeight,
marginTop: positionerElement.style.marginTop,
marginBottom: positionerElement.style.marginBottom
};
}, [popupRef, positionerElement]);
useIsoLayoutEffect(() => {
if (open || alignItemWithTriggerActive) return;
initialPlacedRef.current = false;
reachedMaxHeightRef.current = false;
clearStyles(positionerElement, originalPositionerStylesRef.current);
}, [
open,
alignItemWithTriggerActive,
positionerElement,
popupRef
]);
useIsoLayoutEffect(() => {
const popupElement = popupRef.current;
if (!open || !triggerElement || !positionerElement || !popupElement || alignItemWithTriggerActive && !isPositioned || store.state.transitionStatus === "ending") return;
if (!alignItemWithTriggerActive) {
initialPlacedRef.current = true;
scrollArrowFrame.request(handleScrollArrowVisibility);
popupElement.style.removeProperty("--transform-origin");
return;
}
const restoreTransformStyles = unsetTransformStyles(popupElement);
popupElement.style.removeProperty("--transform-origin");
try {
let textElement = selectedItemTextRef.current;
if (!textElement?.isConnected) textElement = !selectors.hasSelectedValue(store.state) && firstItemTextRef.current?.isConnected ? firstItemTextRef.current : null;
const valueElement = valueRef.current;
const positionerStyles = getComputedStyle(positionerElement);
const popupStyles = getComputedStyle(popupElement);
const doc = ownerDocument(triggerElement);
const win = getWindow(positionerElement);
const scale = getScale(triggerElement);
const triggerRect = normalizeRect(triggerElement.getBoundingClientRect(), scale);
const positionerRect = normalizeRect(positionerElement.getBoundingClientRect(), scale);
const triggerHeight = triggerRect.height;
const scroller = listElement || popupElement;
const scrollHeight = scroller.scrollHeight;
const borderBottom = parseFloat(popupStyles.borderBottomWidth);
const marginTop = parseFloat(positionerStyles.marginTop) || 10;
const marginBottom = parseFloat(positionerStyles.marginBottom) || 10;
const minHeight = parseFloat(positionerStyles.minHeight) || 100;
const maxPopupHeight = getMaxPopupHeight(popupStyles);
const paddingLeft = 5;
const paddingRight = 5;
const triggerCollisionThreshold = 20;
const viewportHeight = doc.documentElement.clientHeight - marginTop - marginBottom;
const viewportWidth = doc.documentElement.clientWidth;
const availableSpaceBeneathTrigger = viewportHeight - triggerRect.bottom + triggerHeight;
let textRect;
let alignedLeft = direction === "rtl" ? triggerRect.right - positionerRect.width : triggerRect.left;
let offsetY = 0;
if (textElement && valueElement) {
const valueRect = normalizeRect(valueElement.getBoundingClientRect(), scale);
textRect = normalizeRect(textElement.getBoundingClientRect(), scale);
alignedLeft = positionerRect.left + (direction === "rtl" ? valueRect.right - textRect.right : valueRect.left - textRect.left);
const valueCenterFromTriggerTop = valueRect.top - triggerRect.top + valueRect.height / 2;
offsetY = textRect.top - positionerRect.top + textRect.height / 2 - valueCenterFromTriggerTop;
}
const idealHeight = availableSpaceBeneathTrigger + offsetY + marginBottom + borderBottom;
let height = Math.min(viewportHeight, idealHeight);
const maxHeight = viewportHeight - marginTop - marginBottom;
const scrollTop = idealHeight - height;
const maxRight = viewportWidth - paddingRight;
positionerElement.style.left = `${clamp(alignedLeft, paddingLeft, maxRight - positionerRect.width)}px`;
positionerElement.style.height = `${height}px`;
positionerElement.style.maxHeight = "auto";
positionerElement.style.marginTop = `${marginTop}px`;
positionerElement.style.marginBottom = `${marginBottom}px`;
popupElement.style.height = "100%";
const maxScrollTop = getMaxScrollTop(scroller);
const isTopPositioned = scrollTop >= maxScrollTop - 1;
if (isTopPositioned) height = Math.min(viewportHeight, positionerRect.height) - (scrollTop - maxScrollTop);
const fallbackToAlignPopupToTrigger = triggerRect.top < triggerCollisionThreshold || triggerRect.bottom > viewportHeight - triggerCollisionThreshold || Math.ceil(height) + 1 < Math.min(scrollHeight, minHeight);
const isPinchZoomed = (win.visualViewport?.scale ?? 1) !== 1 && isWebKit;
if (fallbackToAlignPopupToTrigger || isPinchZoomed) {
initialPlacedRef.current = true;
clearStyles(positionerElement, originalPositionerStylesRef.current);
setControlledAlignItemWithTrigger(false);
return;
}
const initialHeight = Math.max(minHeight, height);
if (isTopPositioned) {
const topOffset = Math.max(0, viewportHeight - idealHeight);
positionerElement.style.top = positionerRect.height >= maxHeight ? "0" : `${topOffset}px`;
positionerElement.style.height = `${height}px`;
scroller.scrollTop = getMaxScrollTop(scroller);
} else {
positionerElement.style.bottom = "0";
scroller.scrollTop = scrollTop;
}
if (textRect) {
const popupTop = positionerRect.top;
const popupHeight = positionerRect.height;
const textCenterY = textRect.top + textRect.height / 2;
const clampedY = clamp(popupHeight > 0 ? (textCenterY - popupTop) / popupHeight * 100 : 50, 0, 100);
popupElement.style.setProperty("--transform-origin", `50% ${clampedY}%`);
}
if (initialHeight === viewportHeight || height >= maxPopupHeight) reachedMaxHeightRef.current = true;
handleScrollArrowVisibility();
if (highlightItemOnHover && store.state.selectedIndex === null && store.state.activeIndex === null && listRef.current[0] != null) store.set("activeIndex", 0);
initialPlacedRef.current = true;
} finally {
restoreTransformStyles();
}
}, [
store,
open,
positionerElement,
triggerElement,
valueRef,
firstItemTextRef,
selectedItemTextRef,
popupRef,
handleScrollArrowVisibility,
alignItemWithTriggerActive,
setControlledAlignItemWithTrigger,
scrollArrowFrame,
scrollDownArrowRef,
scrollUpArrowRef,
listElement,
listRef,
highlightItemOnHover,
direction,
isPositioned
]);
import_react.useEffect(() => {
if (!alignItemWithTriggerActive || !positionerElement || !open) return;
const win = getWindow(positionerElement);
function handleResize(event) {
setOpen(false, createChangeEventDetails(windowResize, event));
}
return addEventListener(win, "resize", handleResize);
}, [
setOpen,
alignItemWithTriggerActive,
positionerElement,
open
]);
const defaultProps = {
...listElement ? {
role: "presentation",
"aria-orientation": void 0
} : {
role: "listbox",
"aria-multiselectable": multiple || void 0,
id: `${id}-list`
},
onKeyDown(event) {
keyboardActiveRef.current = true;
if (insideToolbar && COMPOSITE_KEYS.has(event.key)) event.stopPropagation();
},
onMouseMove() {
keyboardActiveRef.current = false;
},
onScroll(event) {
if (listElement) return;
handleScroll(event.currentTarget);
},
...alignItemWithTriggerActive && { style: listElement ? { height: "100%" } : LIST_FUNCTIONAL_STYLES }
};
const element = useRenderElement("div", componentProps, {
ref: [forwardedRef, popupRef],
state,
stateAttributesMapping: stateAttributesMapping$1,
props: [
popupProps,
defaultProps,
getDisabledMountTransitionStyles(transitionStatus),
{ className: !listElement && alignItemWithTriggerActive ? styleDisableScrollbar.className : void 0 },
elementProps
]
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [!disableStyleElements && styleDisableScrollbar.getElement(nonce), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FloatingFocusManager, {
context: floatingRootContext,
modal: false,
disabled: !mounted,
returnFocus: finalFocus,
restoreFocus: true,
children: element
})] });
});
SelectPopup.displayName = "SelectPopup";
function getMaxPopupHeight(popupStyles) {
const maxHeightStyle = popupStyles.maxHeight || "";
return maxHeightStyle.endsWith("px") ? parseFloat(maxHeightStyle) || Infinity : Infinity;
}
function getMaxScrollTop(scroller) {
return getMaxScrollOffset(scroller.scrollHeight, scroller.clientHeight);
}
function getScale(element) {
return platform.getScale(element);
}
function normalizeSize(size, axis, scale) {
return size / scale[axis];
}
function normalizeRect(rect, scale) {
return rectToClientRect({
x: normalizeSize(rect.x, "x", scale),
y: normalizeSize(rect.y, "y", scale),
width: normalizeSize(rect.width, "x", scale),
height: normalizeSize(rect.height, "y", scale)
});
}
var TRANSFORM_STYLE_RESETS = [
["transform", "none"],
["scale", "1"],
["translate", "0 0"]
];
function unsetTransformStyles(popupElement) {
const { style } = popupElement;
const originalStyles = {};
for (const [property, value] of TRANSFORM_STYLE_RESETS) {
originalStyles[property] = style.getPropertyValue(property);
style.setProperty(property, value, "important");
}
return () => {
for (const [property] of TRANSFORM_STYLE_RESETS) {
const originalValue = originalStyles[property];
if (originalValue) style.setProperty(property, originalValue);
else style.removeProperty(property);
}
};
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/list/SelectList.js
/**
* A container for the select items.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectList = /* @__PURE__ */ import_react.forwardRef(function SelectList(componentProps, forwardedRef) {
const { render, className, style, ...elementProps } = componentProps;
const { store, scrollHandlerRef } = useSelectRootContext();
const { alignItemWithTriggerActive } = useSelectPositionerContext();
const hasScrollArrows = useStore(store, selectors.hasScrollArrows);
const openMethod = useStore(store, selectors.openMethod);
const multiple = useStore(store, selectors.multiple);
const defaultProps = {
id: `${useStore(store, selectors.id)}-list`,
role: "listbox",
"aria-multiselectable": multiple || void 0,
onScroll(event) {
scrollHandlerRef.current?.(event.currentTarget);
},
...alignItemWithTriggerActive && { style: LIST_FUNCTIONAL_STYLES },
className: hasScrollArrows && openMethod !== "touch" ? styleDisableScrollbar.className : void 0
};
return useRenderElement("div", componentProps, {
ref: [forwardedRef, useStableCallback((element) => {
store.set("listElement", element);
})],
props: [defaultProps, elementProps]
});
});
SelectList.displayName = "SelectList";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/item/SelectItemContext.js
var SelectItemContext = /* @__PURE__ */ import_react.createContext(void 0);
SelectItemContext.displayName = "SelectItemContext";
function useSelectItemContext() {
const context = import_react.useContext(SelectItemContext);
if (!context) throw new Error("Base UI: SelectItemContext is missing. SelectItem parts must be placed within <Select.Item>.");
return context;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/item/SelectItem.js
/**
* An individual option in the select popup.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectItem = /* @__PURE__ */ import_react.memo(/* @__PURE__ */ import_react.forwardRef(function SelectItem(componentProps, forwardedRef) {
const { render, className, style, value: itemValue = null, label, disabled = false, nativeButton = false, ...elementProps } = componentProps;
const textRef = import_react.useRef(null);
const listItem = useCompositeListItem({
label,
textRef,
indexGuessBehavior: IndexGuessBehavior.GuessFromOrder
});
const { store, itemProps, setOpen, setValue, selectionRef, typingRef, valuesRef, multiple, selectedItemTextRef } = useSelectRootContext();
const highlighted = useStore(store, selectors.isActive, listItem.index);
const selected = useStore(store, selectors.isSelected, listItem.index, itemValue);
const selectedByFocus = useStore(store, selectors.isSelectedByFocus, listItem.index);
const isItemEqualToValue = useStore(store, selectors.isItemEqualToValue);
const index = listItem.index;
const hasRegistered = index !== -1;
const itemRef = import_react.useRef(null);
useIsoLayoutEffect(() => {
if (!hasRegistered) return;
const values = valuesRef.current;
values[index] = itemValue;
return () => {
delete values[index];
};
}, [
hasRegistered,
index,
itemValue,
valuesRef
]);
useIsoLayoutEffect(() => {
if (!hasRegistered) return;
const selectedValue = store.state.value;
let selectedCandidate = selectedValue;
if (multiple && Array.isArray(selectedValue) && selectedValue.length > 0) selectedCandidate = selectedValue[selectedValue.length - 1];
if (selectedCandidate !== void 0 && compareItemEquality(itemValue, selectedCandidate, isItemEqualToValue)) {
store.set("selectedIndex", index);
if (textRef.current) selectedItemTextRef.current = textRef.current;
}
}, [
hasRegistered,
index,
multiple,
isItemEqualToValue,
store,
itemValue,
selectedItemTextRef
]);
const lastKeyRef = import_react.useRef(null);
const pointerTypeRef = import_react.useRef("mouse");
const allowMouseSelectionRef = import_react.useRef(false);
const { getButtonProps, buttonRef } = useButton({
disabled,
focusableWhenDisabled: true,
native: nativeButton,
composite: true
});
const state = {
disabled,
selected,
highlighted
};
function commitSelection(event) {
const selectedValue = store.state.value;
if (multiple) {
const currentValue = Array.isArray(selectedValue) ? selectedValue : [];
setValue(selected ? removeItem(currentValue, itemValue, isItemEqualToValue) : [...currentValue, itemValue], createChangeEventDetails(itemPress, event));
} else {
setValue(itemValue, createChangeEventDetails(itemPress, event));
setOpen(false, createChangeEventDetails(itemPress, event));
}
}
function resetDragMovement() {
selectionRef.current.dragY = 0;
}
const defaultProps = {
role: "option",
"aria-selected": selected,
tabIndex: highlighted ? 0 : -1,
onKeyDown(event) {
lastKeyRef.current = event.key;
store.set("activeIndex", index);
if (event.key === " " && typingRef.current) event.preventDefault();
},
onClick(event) {
const isMouseClick = event.type === "click" && pointerTypeRef.current !== "touch";
const clickPointerType = event.nativeEvent.pointerType;
const isVirtualMouseClick = isMouseClick && isVirtualClick(event.nativeEvent) && (clickPointerType !== void 0 || highlighted);
const isInvalidMouseClick = isMouseClick && !isVirtualMouseClick && !allowMouseSelectionRef.current;
allowMouseSelectionRef.current = false;
if (event.type === "keydown" && lastKeyRef.current === null) return;
if (disabled || event.type === "keydown" && lastKeyRef.current === " " && typingRef.current || isInvalidMouseClick) return;
lastKeyRef.current = null;
commitSelection(event.nativeEvent);
},
onPointerEnter(event) {
pointerTypeRef.current = event.pointerType;
},
onPointerMove(event) {
if (event.pointerType === "mouse" && event.buttons === 1) {
const selection = selectionRef.current;
selection.dragY += event.movementY;
if (selection.dragY ** 2 >= 64) selection.allowUnselectedMouseUp = true;
}
},
onPointerDown(event) {
pointerTypeRef.current = event.pointerType;
allowMouseSelectionRef.current = true;
resetDragMovement();
},
onMouseUp() {
resetDragMovement();
if (disabled || pointerTypeRef.current === "touch") return;
if (allowMouseSelectionRef.current) return;
const disallowSelectedMouseUp = !selectionRef.current.allowSelectedMouseUp && selected;
const disallowUnselectedMouseUp = !selectionRef.current.allowUnselectedMouseUp && !selected;
if (disallowSelectedMouseUp || disallowUnselectedMouseUp) return;
allowMouseSelectionRef.current = true;
itemRef.current?.click();
allowMouseSelectionRef.current = false;
}
};
const element = useRenderElement("div", componentProps, {
ref: [
buttonRef,
forwardedRef,
listItem.ref,
itemRef
],
state,
props: [
itemProps,
defaultProps,
elementProps,
getButtonProps
]
});
const contextValue = import_react.useMemo(() => ({
selected,
index,
textRef,
selectedByFocus,
hasRegistered
}), [
selected,
index,
textRef,
selectedByFocus,
hasRegistered
]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItemContext.Provider, {
value: contextValue,
children: element
});
}));
SelectItem.displayName = "SelectItem";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/item-indicator/SelectItemIndicator.js
/**
* Indicates whether the select item is selected.
* Renders a `<span>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectItemIndicator = /* @__PURE__ */ import_react.forwardRef(function SelectItemIndicator(componentProps, forwardedRef) {
const keepMounted = componentProps.keepMounted ?? false;
const { selected } = useSelectItemContext();
if (!(keepMounted || selected)) return null;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Inner, {
...componentProps,
ref: forwardedRef
});
});
SelectItemIndicator.displayName = "SelectItemIndicator";
var Inner = /* @__PURE__ */ import_react.memo(/* @__PURE__ */ import_react.forwardRef((componentProps, forwardedRef) => {
const { render, className, style, keepMounted, ...elementProps } = componentProps;
const { selected } = useSelectItemContext();
const indicatorRef = import_react.useRef(null);
const { transitionStatus, setMounted } = useTransitionStatus(selected);
const element = useRenderElement("span", componentProps, {
ref: [forwardedRef, indicatorRef],
state: {
selected,
transitionStatus
},
props: [{
"aria-hidden": true,
children: "✔️"
}, elementProps],
stateAttributesMapping: transitionStatusMapping
});
useOpenChangeComplete({
open: selected,
ref: indicatorRef,
onComplete() {
if (!selected) setMounted(false);
}
});
return element;
}));
Inner.displayName = "Inner";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/item-text/SelectItemText.js
/**
* A text label of the select item.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectItemText = /* @__PURE__ */ import_react.memo(/* @__PURE__ */ import_react.forwardRef(function SelectItemText(componentProps, forwardedRef) {
const { index, textRef, selectedByFocus, hasRegistered } = useSelectItemContext();
const { firstItemTextRef, selectedItemTextRef } = useSelectRootContext();
const { render, className, style, ...elementProps } = componentProps;
return useRenderElement("div", componentProps, {
ref: [
import_react.useCallback((node) => {
if (!node) return;
if (hasRegistered && index === 0) firstItemTextRef.current = node;
if (hasRegistered && selectedByFocus) selectedItemTextRef.current = node;
}, [
firstItemTextRef,
selectedItemTextRef,
index,
selectedByFocus,
hasRegistered
]),
forwardedRef,
textRef
],
props: elementProps
});
}));
SelectItemText.displayName = "SelectItemText";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/arrow/SelectArrow.js
var stateAttributesMapping = {
...popupStateMapping,
...transitionStatusMapping
};
/**
* Displays an element positioned against the select popup anchor.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectArrow = /* @__PURE__ */ import_react.forwardRef(function SelectArrow(componentProps, forwardedRef) {
const { render, className, style, ...elementProps } = componentProps;
const { store } = useSelectRootContext();
const { side, align, arrowRef, arrowStyles, arrowUncentered, alignItemWithTriggerActive } = useSelectPositionerContext();
const element = useRenderElement("div", componentProps, {
state: {
open: useStore(store, selectors.open, true),
side,
align,
uncentered: arrowUncentered
},
ref: [arrowRef, forwardedRef],
props: [{
style: arrowStyles,
"aria-hidden": true
}, elementProps],
stateAttributesMapping
});
if (alignItemWithTriggerActive) return null;
return element;
});
SelectArrow.displayName = "SelectArrow";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/scroll-arrow/SelectScrollArrow.js
/**
* @internal
*/
var SelectScrollArrow = /* @__PURE__ */ import_react.forwardRef(function SelectScrollArrow(componentProps, forwardedRef) {
const { render, className, style, direction, keepMounted = false, ...elementProps } = componentProps;
const isUp = direction === "up";
const { store, popupRef, listRef, handleScrollArrowVisibility, scrollArrowsMountedCountRef } = useSelectRootContext();
const { side, scrollDownArrowRef, scrollUpArrowRef } = useSelectPositionerContext();
const stateVisible = useStore(store, isUp ? selectors.scrollUpArrowVisible : selectors.scrollDownArrowVisible);
const openMethod = useStore(store, selectors.openMethod);
const visible = stateVisible && openMethod !== "touch";
const timeout = useTimeout();
const scrollArrowRef = isUp ? scrollUpArrowRef : scrollDownArrowRef;
const { transitionStatus, setMounted } = useTransitionStatus(visible);
useIsoLayoutEffect(() => {
scrollArrowsMountedCountRef.current += 1;
if (!store.state.hasScrollArrows) store.set("hasScrollArrows", true);
return () => {
scrollArrowsMountedCountRef.current = Math.max(0, scrollArrowsMountedCountRef.current - 1);
if (scrollArrowsMountedCountRef.current === 0 && store.state.hasScrollArrows) store.set("hasScrollArrows", false);
};
}, [store, scrollArrowsMountedCountRef]);
useOpenChangeComplete({
open: visible,
ref: scrollArrowRef,
onComplete() {
if (!visible) setMounted(false);
}
});
const element = useRenderElement("div", componentProps, {
ref: [forwardedRef, scrollArrowRef],
state: {
direction,
visible,
side,
transitionStatus
},
props: [{
"aria-hidden": true,
children: isUp ? "▲" : "▼",
style: { position: "absolute" },
onMouseMove(event) {
if (event.movementX === 0 && event.movementY === 0 || timeout.isStarted()) return;
store.set("activeIndex", null);
function scrollNextItem() {
const scroller = store.state.listElement ?? popupRef.current;
if (!scroller) return;
store.set("activeIndex", null);
handleScrollArrowVisibility();
const maxScrollTop = getMaxScrollOffset(scroller.scrollHeight, scroller.clientHeight);
const scrollTop = normalizeScrollOffset(scroller.scrollTop, maxScrollTop);
const isScrolledToEdge = scrollTop === (isUp ? 0 : maxScrollTop);
const items = listRef.current;
if (scrollTop !== scroller.scrollTop) scroller.scrollTop = scrollTop;
if (items.length === 0) store.set(isUp ? "scrollUpArrowVisible" : "scrollDownArrowVisible", !isScrolledToEdge);
if (isScrolledToEdge) {
timeout.clear();
return;
}
if (items.length > 0) {
const scrollArrowHeight = scrollArrowRef.current?.offsetHeight || 0;
scroller.scrollTop = getTargetScrollTop(items, isUp, scrollTop, scroller.clientHeight, scrollArrowHeight, maxScrollTop);
}
timeout.start(40, scrollNextItem);
}
timeout.start(40, scrollNextItem);
},
onMouseLeave() {
timeout.clear();
}
}, elementProps]
});
if (!(visible || keepMounted)) return null;
return element;
});
SelectScrollArrow.displayName = "SelectScrollArrow";
function getTargetScrollTop(items, isUp, scrollTop, clientHeight, scrollArrowHeight, maxScrollTop) {
if (isUp) {
let firstVisibleIndex = 0;
const visibleTop = scrollTop + scrollArrowHeight - 1;
for (let i = 0; i < items.length; i += 1) {
const item = items[i];
if (item && item.offsetTop >= visibleTop) {
firstVisibleIndex = i;
break;
}
}
const targetIndex = Math.max(0, firstVisibleIndex - 1);
const targetItem = items[targetIndex];
return targetIndex < firstVisibleIndex && targetItem ? normalizeScrollOffset(targetItem.offsetTop - scrollArrowHeight, maxScrollTop) : 0;
}
let lastVisibleIndex = items.length - 1;
const visibleBottom = scrollTop + clientHeight - scrollArrowHeight + 1;
for (let i = 0; i < items.length; i += 1) {
const item = items[i];
if (item && item.offsetTop + item.offsetHeight > visibleBottom) {
lastVisibleIndex = Math.max(0, i - 1);
break;
}
}
const targetIndex = Math.min(items.length - 1, lastVisibleIndex + 1);
const targetItem = items[targetIndex];
return targetIndex > lastVisibleIndex && targetItem ? normalizeScrollOffset(targetItem.offsetTop + targetItem.offsetHeight - clientHeight + scrollArrowHeight, maxScrollTop) : maxScrollTop;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/scroll-down-arrow/SelectScrollDownArrow.js
/**
* An element that scrolls the select popup down when hovered. Does not render when using touch input.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectScrollDownArrow = /* @__PURE__ */ import_react.forwardRef(function SelectScrollDownArrow(props, forwardedRef) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectScrollArrow, {
...props,
ref: forwardedRef,
direction: "down"
});
});
SelectScrollDownArrow.displayName = "SelectScrollDownArrow";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/scroll-up-arrow/SelectScrollUpArrow.js
/**
* An element that scrolls the select popup up when hovered. Does not render when using touch input.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectScrollUpArrow = /* @__PURE__ */ import_react.forwardRef(function SelectScrollUpArrow(props, forwardedRef) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectScrollArrow, {
...props,
ref: forwardedRef,
direction: "up"
});
});
SelectScrollUpArrow.displayName = "SelectScrollUpArrow";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/group/SelectGroupContext.js
var SelectGroupContext = /* @__PURE__ */ import_react.createContext(void 0);
SelectGroupContext.displayName = "SelectGroupContext";
function useSelectGroupContext() {
const context = import_react.useContext(SelectGroupContext);
if (context === void 0) throw new Error("Base UI: SelectGroupContext is missing. SelectGroup parts must be placed within <Select.Group>.");
return context;
}
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/group/SelectGroup.js
/**
* Groups related select items with the corresponding label.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectGroup = /* @__PURE__ */ import_react.forwardRef(function SelectGroup(componentProps, forwardedRef) {
const { render, className, style, ...elementProps } = componentProps;
const [labelId, setLabelId] = import_react.useState();
const contextValue = import_react.useMemo(() => ({
labelId,
setLabelId
}), [labelId, setLabelId]);
const element = useRenderElement("div", componentProps, {
ref: forwardedRef,
props: [{
role: "group",
"aria-labelledby": labelId
}, elementProps]
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectGroupContext.Provider, {
value: contextValue,
children: element
});
});
SelectGroup.displayName = "SelectGroup";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/group-label/SelectGroupLabel.js
/**
* An accessible label that is automatically associated with its parent group.
* Renders a `<div>` element.
*
* Documentation: [Base UI Select](https://base-ui.com/react/components/select)
*/
var SelectGroupLabel = /* @__PURE__ */ import_react.forwardRef(function SelectGroupLabel(componentProps, forwardedRef) {
const { render, className, style, id: idProp, ...elementProps } = componentProps;
const { setLabelId } = useSelectGroupContext();
const id = useBaseUiId(idProp);
useIsoLayoutEffect(() => {
setLabelId(id);
}, [id, setLabelId]);
return useRenderElement("div", componentProps, {
ref: forwardedRef,
props: [{ id }, elementProps]
});
});
SelectGroupLabel.displayName = "SelectGroupLabel";
//#endregion
//#region ../node_modules/@base-ui/react/esm/select/index.parts.js
var index_parts_exports = /* @__PURE__ */ __exportAll({
Arrow: () => SelectArrow,
Backdrop: () => SelectBackdrop,
Group: () => SelectGroup,
GroupLabel: () => SelectGroupLabel,
Icon: () => SelectIcon,
Item: () => SelectItem,
ItemIndicator: () => SelectItemIndicator,
ItemText: () => SelectItemText,
Label: () => SelectLabel,
List: () => SelectList,
Popup: () => SelectPopup,
Portal: () => SelectPortal,
Positioner: () => SelectPositioner,
Root: () => SelectRoot,
ScrollDownArrow: () => SelectScrollDownArrow,
ScrollUpArrow: () => SelectScrollUpArrow,
Separator: () => Separator,
Trigger: () => SelectTrigger,
Value: () => SelectValue
});
//#endregion
export { index_parts_exports as Select };
//# sourceMappingURL=@base-ui_react_select.js.map |