react-animated-select 0.7.7 → 0.8.0
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/base.css +1 -0
- package/dist/chip.cjs +1 -0
- package/dist/chip.css +1 -0
- package/dist/chip.js +94 -0
- package/dist/chipGeometry.cjs +1 -0
- package/dist/chipGeometry.js +64 -0
- package/dist/dropdown.cjs +1 -0
- package/dist/dropdown.js +70 -0
- package/dist/dropdownPosition.cjs +1 -0
- package/dist/dropdownPosition.js +87 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +28 -1
- package/dist/index.js +13 -0
- package/dist/liveRegion.cjs +1 -0
- package/dist/liveRegion.js +42 -0
- package/dist/model.cjs +1 -0
- package/dist/model.js +138 -0
- package/dist/motion.cjs +1 -0
- package/dist/motion.js +120 -0
- package/dist/optionList.cjs +1 -0
- package/dist/optionList.js +105 -0
- package/dist/paging.cjs +1 -0
- package/dist/paging.js +47 -0
- package/dist/select.cjs +1 -0
- package/dist/select.js +165 -0
- package/dist/state.cjs +1 -0
- package/dist/state.js +50 -0
- package/dist/style.css +4 -0
- package/dist/theme.css +1 -0
- package/dist/trigger.cjs +1 -0
- package/dist/trigger.js +94 -0
- package/dist/useChipLayout.cjs +1 -0
- package/dist/useChipLayout.js +78 -0
- package/dist/useSelect.cjs +1 -0
- package/dist/useSelect.js +100 -0
- package/dist/useSelectBehavior.cjs +1 -0
- package/dist/useSelectBehavior.js +109 -0
- package/dist/useSelectModel.cjs +1 -0
- package/dist/useSelectModel.js +59 -0
- package/dist/utils.cjs +1 -0
- package/dist/utils.js +99 -0
- package/index.d.ts +28 -1
- package/package.json +4 -4
- package/dist/index.css +0 -1
- package/dist/index.es.js +0 -1299
package/dist/base.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer rac.base,rac.theme;@property --rac-list-max-height{syntax: "<length>"; inherits: true; initial-value: 250px;}@layer rac.base{:root{--rac-row: 2em}.rac-select,.rac-options{--rac-duration-fast: calc(var(--rac-duration) * .5)}@media(prefers-reduced-motion:reduce){.rac-select,.rac-options{--rac-duration: 1ms !important}.rac-dots i{animation:none}}.rac-select{position:relative;display:flex;align-items:center;box-sizing:border-box;min-width:0;max-width:100%;cursor:pointer}.rac-select:not([aria-haspopup]){cursor:default}.rac-select[aria-busy=true]{cursor:progress}.rac-select[aria-disabled=true]{cursor:not-allowed}.rac-select[aria-disabled=true][aria-busy=true]{cursor:wait}.rac-value{flex:1;min-width:0;min-height:var(--rac-row);display:flex;flex-wrap:wrap;align-items:center}.rac-title{min-width:0;max-width:calc(100% - .25px);overflow-x:clip;white-space:nowrap;text-overflow:ellipsis}.rac-dots{display:inline-flex;gap:.17em;margin-inline-start:.25em}.rac-dots i{width:.25em;height:.25em;border-radius:50%;background:currentColor;animation:rac-blink 1.4s infinite both}.rac-dots i:nth-child(2){animation-delay:.2s}.rac-dots i:nth-child(3){animation-delay:.4s}.rac-clear,.rac-arrow{display:grid;place-items:center;align-self:center}.rac-clear{padding:0;border:0;background:none;color:inherit;font:inherit;cursor:pointer}.rac-arrow,.rac-group-arrow{transition:rotate var(--rac-duration) var(--rac-ease)}.rac-select:not([data-placement=top],[aria-expanded=true]) .rac-arrow,.rac-select[data-placement=top][aria-expanded=true] .rac-arrow{rotate:180deg}.rac-icon{height:1em}.rac-input{position:absolute;inset:0;box-sizing:border-box;width:100%;height:100%;margin:0;padding:0;border:0;opacity:0;pointer-events:none}.rac-live{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}@media(any-pointer:coarse){.rac-clear{position:relative}.rac-arrow{pointer-events:none}.rac-clear:before{content:"";position:absolute;inset:min(0px,50% - 12px)}}.rac-options{box-sizing:border-box;z-index:2147483647;overflow:clip}.rac-options{transition:opacity var(--rac-duration) var(--rac-ease),visibility 0s}.rac-options[data-offscreen]{opacity:0;visibility:hidden;transition-delay:0s,var(--rac-duration)}.rac-list{max-height:var(--rac-list-max-height);overflow-x:hidden;overflow-y:auto;scrollbar-gutter:stable;scroll-behavior:smooth}.rac-option{display:flex;justify-content:space-between;align-items:center;overflow-wrap:anywhere;cursor:pointer}.rac-option[aria-disabled=true]{cursor:not-allowed}.rac-option[data-error]{cursor:default}.rac-option[data-loading]{justify-content:start;align-items:baseline;cursor:wait}.rac-check{position:relative;display:flex;justify-content:center;align-items:center}.rac-check[data-default]{width:1em;height:1em;border:1px solid}.rac-checkmark{position:absolute;width:auto;height:1em;opacity:0;scale:0;transition:opacity var(--rac-duration) var(--rac-ease),scale var(--rac-duration) var(--rac-ease)}.rac-option[aria-selected=true] .rac-checkmark{opacity:1;scale:1}.rac-group{display:flex;justify-content:space-between;align-items:center;cursor:pointer}.rac-group[data-disabled]{cursor:not-allowed}.rac-group-arrow{display:grid}.rac-group[data-open]>.rac-group-arrow{rotate:180deg}@keyframes rac-blink{0%{opacity:.2}20%{opacity:1}to{opacity:.2}}}
|
package/dist/chip.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),s=require("react"),E=require("./state.cjs"),l=require("./utils.cjs"),S=require("./motion.cjs"),W=require("./trigger.cjs"),X=require("./chipGeometry.cjs"),R=require("./useChipLayout.cjs");;/* empty css */const $={position:"absolute",visibility:"hidden",pointerEvents:"none"},D=1,M=2,z=600,F=10,V=30,J=s.memo(function({element:e,deleting:r,locked:i,chipStore:t,delGroup:p}){const{selectRef:a,deleteInline:h,deleteAlways:f,icons:v,texts:C,valueAsOption:j,renderOption:P}=s.useContext(E.SelectConfigContext),u=!!v.remove,{setVisibility:b,setDeleting:m,removeOption:g}=s.useContext(E.SelectActionsContext),c=s.useRef({longPressTimer:null,longPress:!1,x:0,y:0}),I=s.useSyncExternalStore(t.subscribe,()=>{const{hoverId:n,swipedId:x}=t.get();return(n===e.id?D:0)|(x===e.id?M:0)},()=>0),k=!!(I&D),d=!!(I&M),L=s.useCallback(n=>{const{clientX:x,clientY:N}=n.touches[0];Object.assign(c.current,{x,y:N,longPress:!1}),clearTimeout(c.current.longPressTimer),u&&(c.current.longPressTimer=setTimeout(()=>{m(!0),c.current.longPress=!0,a.current?.focus(),b(!1),window.navigator.vibrate?.(50)},z))},[u,m,b,a]),G=s.useCallback(n=>{const{clientX:x,clientY:N}=n.touches[0],O=c.current.x-x;Math.hypot(O,c.current.y-N)>F&&clearTimeout(c.current.longPressTimer),O>V&&!d?t.set({hoverId:null,swipedId:e.id}):O<-V&&d&&t.set({swipedId:null})},[e.id,d,t]),q=s.useCallback(n=>{clearTimeout(c.current.longPressTimer),c.current.longPress&&n.cancelable&&n.preventDefault(),c.current.longPress=!1},[]),Y=s.useCallback(()=>t.set({hoverId:e.id,swipedId:null}),[e.id,t]),_=s.useCallback(()=>{t.get().hoverId===e.id&&t.set({hoverId:null})},[e.id,t]);s.useEffect(()=>()=>clearTimeout(c.current.longPressTimer),[]);const y=j?l.optionContent(e,P,!0):null,B=y?o.jsx("div",{className:"rac-option-jsx",children:y}):o.jsx("span",{className:"rac-chip-text",children:e.name||C.emptyOption}),w=s.useCallback(n=>{t.set({swipedId:null}),l.refocus(n,a),g(e.id),l.stopEvent(n)},[e.id,g,t,a]),H=s.useCallback(n=>{l.stopEvent(n),r&&w(n)},[r,w]),U=u&&(f||!i&&(k||d||r));return o.jsxs("div",{className:l.withClass("rac-chip",y&&e.className),style:y?e.style:void 0,...!i&&{onTouchStart:L,onTouchMove:G,onTouchEnd:q,onTouchCancel:q,onMouseEnter:Y,onMouseLeave:_,onClick:H},children:[B,o.jsx(S.Collapse,{"aria-label":`${C.remove} ${e.name??""}`.trim(),group:h&&!f&&!r?p:void 0,onMouseDown:l.stopEvent,onClick:w,className:"rac-chip-del",disabled:i,tabIndex:-1,type:"button",in:U,as:"button",axis:"x",children:l.renderIcon(v.remove)})]})}),K=s.memo(function({element:e,chipStore:r,settle:i,...t}){const p=s.useSyncExternalStore(r.subscribe,()=>r.get().breaks.includes(e.id),()=>!1);return o.jsxs(s.Fragment,{children:[o.jsx(S.Collapse,{className:"rac-chip-slot",onEntered:i,onExited:i,unmountOnExit:!1,"data-id":e.id,axis:"x",fade:!0,children:o.jsx(J,{element:e,chipStore:r,...t})}),p&&o.jsx("div",{className:"rac-spacer"})]})});class Q extends s.Component{getSnapshotBeforeUpdate(e){const r=e.look!==this.props.look;return(r||e.chips!==this.props.chips)&&this.props.take(r),null}componentDidUpdate(){}render(){return null}}const A=s.memo(function(){const{selectedText:e,icons:r}=s.useContext(E.SelectConfigContext),{selectedIDs:i,deleting:t,active:p}=s.useContext(E.SelectStateContext),a=i.length>0&&!e,h=a?i:X.NONE,{chipStore:f,delGroup:v,valueRef:C,delIconRef:j,probe:P,settle:u,held:b,snapshot:m,look:g,wait:c}=R.default(h),I=R.useChipKeys(h);return o.jsxs("div",{className:"rac-value",ref:C,children:[o.jsx(Q,{chips:h,look:g,take:m}),o.jsx(W.Title,{hidden:a,settle:u}),o.jsx(S.Presence,{hold:b,wait:c,children:I.map(([k,d])=>o.jsx(K,{element:d,deleting:t,locked:!p,chipStore:f,delGroup:v,settle:u},k))}),P&&o.jsx("button",{type:"button",className:"rac-chip-del",tabIndex:-1,"aria-hidden":"true",ref:j,style:$,children:l.renderIcon(r.remove)})]})}),Z={Value:A};exports.ChipsValue=A;exports.chips=Z;
|
package/dist/chip.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer rac.base,rac.theme;@layer rac.base{.rac-chip-slot{display:flex;align-items:center;max-width:100%}.rac-chip-text,.rac-chip>.rac-option-jsx{min-width:0;overflow-x:clip}.rac-chip-text{text-overflow:ellipsis}.rac-chip{position:relative;display:inline-flex;flex-shrink:0;align-items:center;box-sizing:border-box;max-width:inherit;white-space:nowrap;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent;touch-action:pan-y}.rac-chip-del{position:absolute;flex-shrink:0;inset-inline-end:0;height:100%;display:grid;align-items:center;padding:0;border:0;background:none;color:inherit;font:inherit;cursor:pointer}.rac-chip-del:disabled{cursor:inherit}.rac-select:is([data-deleting],[data-inline-delete]) .rac-chip-del{position:relative}@media(any-pointer:coarse){.rac-chip-del:before{content:"";position:absolute;inset:min(0px,50% - 12px)}}.rac-spacer{flex-basis:100%;height:0;margin-inline-end:1px}}@layer rac.theme{.rac-chip{min-height:calc(var(--rac-row) - .5em);margin-block:.25em;margin-inline-end:.5em;padding-inline:.25em;border-radius:calc(var(--rac-radius) / 2);line-height:normal;background-color:var(--rac-tint-2);transition:background-color var(--rac-duration-fast) var(--rac-ease)}@media(hover:hover){.rac-chip:hover{background-color:var(--rac-tint-3)}}.rac-select[data-deleting] .rac-chip{background-color:color-mix(in srgb,var(--rac-danger) 15%,var(--rac-bg));animation:rac-shake .3s infinite}@media(prefers-reduced-motion:reduce){.rac-select[data-deleting] .rac-chip{animation:none}}.rac-chip-del{border-start-end-radius:inherit;border-end-end-radius:inherit;background-color:color-mix(in srgb,var(--rac-danger) 30%,var(--rac-bg));transition:color var(--rac-duration) var(--rac-ease),background-color var(--rac-duration) var(--rac-ease)}.rac-chip-del:hover{color:var(--rac-danger)}.rac-select:is([data-deleting],[data-inline-delete]) .rac-chip-del{background-color:transparent}@keyframes rac-shake{0%{transform:rotate(0)}25%{transform:rotate(-1deg)}75%{transform:rotate(1deg)}to{transform:rotate(0)}}}
|
package/dist/chip.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as R, jsx as r } from "react/jsx-runtime";
|
|
3
|
+
import { memo as M, useContext as T, Component as F, useSyncExternalStore as j, Fragment as J, useRef as K, useCallback as l, useEffect as q } from "react";
|
|
4
|
+
import { SelectConfigContext as Y, SelectStateContext as Q, SelectActionsContext as Z } from "./state.js";
|
|
5
|
+
import { renderIcon as _, optionContent as ee, refocus as se, stopEvent as D, withClass as te } from "./utils.js";
|
|
6
|
+
import { Presence as oe, Collapse as B } from "./motion.js";
|
|
7
|
+
import { Title as ne } from "./trigger.js";
|
|
8
|
+
import { NONE as re } from "./chipGeometry.js";
|
|
9
|
+
import ie, { useChipKeys as ce } from "./useChipLayout.js";
|
|
10
|
+
import './chip.css';/* empty css */
|
|
11
|
+
const le = { position: "absolute", visibility: "hidden", pointerEvents: "none" }, L = 1, S = 2, ae = 600, de = 10, V = 30, ue = /* @__PURE__ */ M(function({ element: e, deleting: o, locked: i, chipStore: s, delGroup: u }) {
|
|
12
|
+
const { selectRef: c, deleteInline: p, deleteAlways: h, icons: m, texts: v, valueAsOption: y, renderOption: P } = T(Y), a = !!m.remove, { setVisibility: b, setDeleting: x, removeOption: g } = T(Z), n = K({ longPressTimer: null, longPress: !1, x: 0, y: 0 }), I = j(s.subscribe, () => {
|
|
13
|
+
const { hoverId: t, swipedId: f } = s.get();
|
|
14
|
+
return (t === e.id ? L : 0) | (f === e.id ? S : 0);
|
|
15
|
+
}, () => 0), w = !!(I & L), d = !!(I & S), G = l((t) => {
|
|
16
|
+
const { clientX: f, clientY: k } = t.touches[0];
|
|
17
|
+
Object.assign(n.current, { x: f, y: k, longPress: !1 }), clearTimeout(n.current.longPressTimer), a && (n.current.longPressTimer = setTimeout(() => {
|
|
18
|
+
x(!0), n.current.longPress = !0, c.current?.focus(), b(!1), window.navigator.vibrate?.(50);
|
|
19
|
+
}, ae));
|
|
20
|
+
}, [a, x, b, c]), H = l((t) => {
|
|
21
|
+
const { clientX: f, clientY: k } = t.touches[0], O = n.current.x - f;
|
|
22
|
+
Math.hypot(O, n.current.y - k) > de && clearTimeout(n.current.longPressTimer), O > V && !d ? s.set({ hoverId: null, swipedId: e.id }) : O < -V && d && s.set({ swipedId: null });
|
|
23
|
+
}, [e.id, d, s]), A = l((t) => {
|
|
24
|
+
clearTimeout(n.current.longPressTimer), n.current.longPress && t.cancelable && t.preventDefault(), n.current.longPress = !1;
|
|
25
|
+
}, []), U = l(() => s.set({ hoverId: e.id, swipedId: null }), [e.id, s]), W = l(() => {
|
|
26
|
+
s.get().hoverId === e.id && s.set({ hoverId: null });
|
|
27
|
+
}, [e.id, s]);
|
|
28
|
+
q(() => () => clearTimeout(n.current.longPressTimer), []);
|
|
29
|
+
const C = y ? ee(e, P, !0) : null, X = C ? /* @__PURE__ */ r("div", { className: "rac-option-jsx", children: C }) : /* @__PURE__ */ r("span", { className: "rac-chip-text", children: e.name || v.emptyOption }), N = l((t) => {
|
|
30
|
+
s.set({ swipedId: null }), se(t, c), g(e.id), D(t);
|
|
31
|
+
}, [e.id, g, s, c]), $ = l((t) => {
|
|
32
|
+
D(t), o && N(t);
|
|
33
|
+
}, [o, N]), z = a && (h || !i && (w || d || o));
|
|
34
|
+
return /* @__PURE__ */ R(
|
|
35
|
+
"div",
|
|
36
|
+
{
|
|
37
|
+
className: te("rac-chip", C && e.className),
|
|
38
|
+
style: C ? e.style : void 0,
|
|
39
|
+
...!i && { onTouchStart: G, onTouchMove: H, onTouchEnd: A, onTouchCancel: A, onMouseEnter: U, onMouseLeave: W, onClick: $ },
|
|
40
|
+
children: [
|
|
41
|
+
X,
|
|
42
|
+
/* @__PURE__ */ r(
|
|
43
|
+
B,
|
|
44
|
+
{
|
|
45
|
+
"aria-label": `${v.remove} ${e.name ?? ""}`.trim(),
|
|
46
|
+
group: p && !h && !o ? u : void 0,
|
|
47
|
+
onMouseDown: D,
|
|
48
|
+
onClick: N,
|
|
49
|
+
className: "rac-chip-del",
|
|
50
|
+
disabled: i,
|
|
51
|
+
tabIndex: -1,
|
|
52
|
+
type: "button",
|
|
53
|
+
in: z,
|
|
54
|
+
as: "button",
|
|
55
|
+
axis: "x",
|
|
56
|
+
children: _(m.remove)
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}), pe = /* @__PURE__ */ M(function({ element: e, chipStore: o, settle: i, ...s }) {
|
|
63
|
+
const u = j(o.subscribe, () => o.get().breaks.includes(e.id), () => !1);
|
|
64
|
+
return /* @__PURE__ */ R(J, { children: [
|
|
65
|
+
/* @__PURE__ */ r(B, { className: "rac-chip-slot", onEntered: i, onExited: i, unmountOnExit: !1, "data-id": e.id, axis: "x", fade: !0, children: /* @__PURE__ */ r(ue, { element: e, chipStore: o, ...s }) }),
|
|
66
|
+
u && /* @__PURE__ */ r("div", { className: "rac-spacer" })
|
|
67
|
+
] });
|
|
68
|
+
});
|
|
69
|
+
class fe extends F {
|
|
70
|
+
getSnapshotBeforeUpdate(e) {
|
|
71
|
+
const o = e.look !== this.props.look;
|
|
72
|
+
return (o || e.chips !== this.props.chips) && this.props.take(o), null;
|
|
73
|
+
}
|
|
74
|
+
componentDidUpdate() {
|
|
75
|
+
}
|
|
76
|
+
render() {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const he = /* @__PURE__ */ M(function() {
|
|
81
|
+
const { selectedText: e, icons: o } = T(Y), { selectedIDs: i, deleting: s, active: u } = T(Q), c = i.length > 0 && !e, p = c ? i : re, { chipStore: h, delGroup: m, valueRef: v, delIconRef: y, probe: P, settle: a, held: b, snapshot: x, look: g, wait: n } = ie(p), I = ce(p);
|
|
82
|
+
return /* @__PURE__ */ R("div", { className: "rac-value", ref: v, children: [
|
|
83
|
+
/* @__PURE__ */ r(fe, { chips: p, look: g, take: x }),
|
|
84
|
+
/* @__PURE__ */ r(ne, { hidden: c, settle: a }),
|
|
85
|
+
/* @__PURE__ */ r(oe, { hold: b, wait: n, children: I.map(
|
|
86
|
+
([w, d]) => /* @__PURE__ */ r(pe, { element: d, deleting: s, locked: !u, chipStore: h, delGroup: m, settle: a }, w)
|
|
87
|
+
) }),
|
|
88
|
+
P && /* @__PURE__ */ r("button", { type: "button", className: "rac-chip-del", tabIndex: -1, "aria-hidden": "true", ref: y, style: le, children: _(o.remove) })
|
|
89
|
+
] });
|
|
90
|
+
}), ye = { Value: he };
|
|
91
|
+
export {
|
|
92
|
+
he as ChipsValue,
|
|
93
|
+
ye as chips
|
|
94
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="rac-chip-slot",g="rac-flip",p="rac-resize",E=[],x={overflow:"hidden",textOverflow:"clip",boxSizing:"border-box",minWidth:"0px",maxWidth:"none",minHeight:"0px",maxHeight:"none"},h=e=>Array.from(e.children).filter(n=>n.classList.contains(y)),m=e=>e.firstElementChild?.firstElementChild,O=(e,n)=>!!e?.getAnimations?.().some(t=>t.constructor===Animation&&n(t)),w=(e,n)=>O(e,t=>t.playState==="running"&&n(t)),S=e=>h(e).some(n=>w(m(n),t=>t.id===p)),T=e=>Array.from(e.children).some(n=>w(n,t=>t.id!==g))||S(e),$=(e,n)=>e.length===n.length&&e.every((t,i)=>t===n[i]),I=e=>{const n=[];let t=-1/0;for(const i of e){const s=i.getBoundingClientRect();s.top>=t-1&&(n.push([]),t=s.bottom),n.at(-1).push(i),t=Math.max(t,s.bottom)}return n},z=(e,n,t,i,s)=>{const o=e.cloneNode(!0),{height:a,paddingInlineEnd:l}=getComputedStyle(e),C=s?"":`height: ${a}; min-height: 0;`;o.style.cssText=`visibility: hidden; pointer-events: none; ${C} padding-inline-end: calc(${l} + ${t}px)`,o.querySelectorAll(`:scope > :not(.${y})`).forEach(r=>r.remove()),i&&h(o).forEach(r=>i.has(r.dataset.id)||r.remove()),t&&o.querySelectorAll(".rac-chip-del").forEach(r=>r.remove());const f=h(o);f.forEach(r=>s?.has(r.dataset.id)&&Object.assign(m(r)?.style??{},{minWidth:s.get(r.dataset.id),boxSizing:"border-box"}));const u=new Map(f.map((r,c)=>[r.dataset.id,c]));n?.slice(1).forEach((r,c)=>{const L=Math.min(...r.map(d=>u.get(d)??1/0)),b=Math.max(...n[c].map(d=>u.get(d)??-1).filter(d=>d<L));b>=0&&f[b].after(Object.assign(document.createElement("div"),{className:"rac-spacer"}))}),e.style.position="absolute",e.after(o),o.getAnimations?.({subtree:!0}).forEach(r=>r.effect?.getComputedTiming().endTime<1/0&&r.finish());const M=I(f).map(r=>r.map(c=>c.dataset.id)),R=o.offsetHeight;return o.remove(),e.style.position="",{rows:M,fit:R}},A=(e,n)=>{const t=n?n.slice(0,-1).map(s=>s.at(-1)):E,{breaks:i}=e.get();return $(i,t)?i:t},W=(e,n,t,i)=>A(e,i&&t.length?z(n,null,i,new Set(t.map(s=>s.id))).rows:null),v=(e,n,t)=>{const{rows:i,fit:s}=z(n,t.rows,t.reserve,null,t.floor);Object.assign(t,{rows:i,fit:t.floor?s:null}),e.set({held:!0,breaks:A(e,i)})},N=(e,n)=>new Map(h(e).map(t=>{const{left:i,top:s}=t.getBoundingClientRect(),o=n&&m(t);return[t,{left:i,top:s,label:o?B(o):null}]})),k=(e,n,t,i)=>{if(!e.animate)return;e.getAnimations().forEach(l=>l.id===g&&l.cancel());const s=e.getBoundingClientRect(),o=n.left-s.left,a=n.top-s.top;(Math.abs(o)>.5||Math.abs(a)>.5)&&e.animate([{transform:`translate(${o}px, ${a}px)`},{transform:"none"}],{id:g,duration:t,easing:i})},B=e=>{const n=getComputedStyle(e),t=(...i)=>`${i.reduce((s,o)=>s+parseFloat(n[o]),0)}px`;return n.boxSizing==="border-box"?{width:n.width,height:n.height}:{width:t("width","paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"),height:t("height","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth")}},j=e=>{const n=[];e.forEach(({label:i},s)=>{const o=i&&s.isConnected&&m(s);!o?.animate||O(s,a=>a.id!==g)||(o.getAnimations().forEach(a=>a.id===p&&a.cancel()),n.push({id:s.dataset.id,el:o,from:i}))});const t=(i,s)=>Math.abs(parseFloat(i)-parseFloat(s))>.5;return n.map(i=>({...i,to:B(i.el)})).filter(({from:i,to:s})=>t(i.width,s.width)||t(i.height,s.height))},F=(e,n,t,i)=>e.forEach(({el:s,from:o,to:a})=>{s.animate([{...x,...o},{...x,...a}],{id:p,duration:n,easing:t}).onfinish=i});exports.NONE=E;exports.flip=k;exports.freeze=v;exports.isBusy=T;exports.isResizing=S;exports.resize=F;exports.resizesOf=j;exports.restBreaks=W;exports.slotsOf=h;exports.snapOf=N;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const y = "rac-chip-slot", f = "rac-flip", p = "rac-resize", R = [], x = { overflow: "hidden", textOverflow: "clip", boxSizing: "border-box", minWidth: "0px", maxWidth: "none", minHeight: "0px", maxHeight: "none" }, m = (e) => Array.from(e.children).filter((n) => n.classList.contains(y)), g = (e) => e.firstElementChild?.firstElementChild, w = (e, n) => !!e?.getAnimations?.().some((t) => t.constructor === Animation && n(t)), E = (e, n) => w(e, (t) => t.playState === "running" && n(t)), $ = (e) => m(e).some((n) => E(g(n), (t) => t.id === p)), T = (e) => Array.from(e.children).some((n) => E(n, (t) => t.id !== f)) || $(e), B = (e, n) => e.length === n.length && e.every((t, i) => t === n[i]), I = (e) => {
|
|
3
|
+
const n = [];
|
|
4
|
+
let t = -1 / 0;
|
|
5
|
+
for (const i of e) {
|
|
6
|
+
const o = i.getBoundingClientRect();
|
|
7
|
+
o.top >= t - 1 && (n.push([]), t = o.bottom), n.at(-1).push(i), t = Math.max(t, o.bottom);
|
|
8
|
+
}
|
|
9
|
+
return n;
|
|
10
|
+
}, O = (e, n, t, i, o) => {
|
|
11
|
+
const s = e.cloneNode(!0), { height: a, paddingInlineEnd: h } = getComputedStyle(e), C = o ? "" : `height: ${a}; min-height: 0;`;
|
|
12
|
+
s.style.cssText = `visibility: hidden; pointer-events: none; ${C} padding-inline-end: calc(${h} + ${t}px)`, s.querySelectorAll(`:scope > :not(.${y})`).forEach((r) => r.remove()), i && m(s).forEach((r) => i.has(r.dataset.id) || r.remove()), t && s.querySelectorAll(".rac-chip-del").forEach((r) => r.remove());
|
|
13
|
+
const l = m(s);
|
|
14
|
+
l.forEach((r) => o?.has(r.dataset.id) && Object.assign(g(r)?.style ?? {}, { minWidth: o.get(r.dataset.id), boxSizing: "border-box" }));
|
|
15
|
+
const b = new Map(l.map((r, c) => [r.dataset.id, c]));
|
|
16
|
+
n?.slice(1).forEach((r, c) => {
|
|
17
|
+
const M = Math.min(...r.map((d) => b.get(d) ?? 1 / 0)), u = Math.max(...n[c].map((d) => b.get(d) ?? -1).filter((d) => d < M));
|
|
18
|
+
u >= 0 && l[u].after(Object.assign(document.createElement("div"), { className: "rac-spacer" }));
|
|
19
|
+
}), e.style.position = "absolute", e.after(s), s.getAnimations?.({ subtree: !0 }).forEach((r) => r.effect?.getComputedTiming().endTime < 1 / 0 && r.finish());
|
|
20
|
+
const z = I(l).map((r) => r.map((c) => c.dataset.id)), L = s.offsetHeight;
|
|
21
|
+
return s.remove(), e.style.position = "", { rows: z, fit: L };
|
|
22
|
+
}, S = (e, n) => {
|
|
23
|
+
const t = n ? n.slice(0, -1).map((o) => o.at(-1)) : R, { breaks: i } = e.get();
|
|
24
|
+
return B(i, t) ? i : t;
|
|
25
|
+
}, W = (e, n, t, i) => S(e, i && t.length ? O(n, null, i, new Set(t.map((o) => o.id))).rows : null), v = (e, n, t) => {
|
|
26
|
+
const { rows: i, fit: o } = O(n, t.rows, t.reserve, null, t.floor);
|
|
27
|
+
Object.assign(t, { rows: i, fit: t.floor ? o : null }), e.set({ held: !0, breaks: S(e, i) });
|
|
28
|
+
}, k = (e, n) => new Map(m(e).map((t) => {
|
|
29
|
+
const { left: i, top: o } = t.getBoundingClientRect(), s = n && g(t);
|
|
30
|
+
return [t, { left: i, top: o, label: s ? A(s) : null }];
|
|
31
|
+
})), F = (e, n, t, i) => {
|
|
32
|
+
if (!e.animate) return;
|
|
33
|
+
e.getAnimations().forEach((h) => h.id === f && h.cancel());
|
|
34
|
+
const o = e.getBoundingClientRect(), s = n.left - o.left, a = n.top - o.top;
|
|
35
|
+
(Math.abs(s) > 0.5 || Math.abs(a) > 0.5) && e.animate([{ transform: `translate(${s}px, ${a}px)` }, { transform: "none" }], { id: f, duration: t, easing: i });
|
|
36
|
+
}, A = (e) => {
|
|
37
|
+
const n = getComputedStyle(e), t = (...i) => `${i.reduce((o, s) => o + parseFloat(n[s]), 0)}px`;
|
|
38
|
+
return n.boxSizing === "border-box" ? { width: n.width, height: n.height } : {
|
|
39
|
+
width: t("width", "paddingLeft", "paddingRight", "borderLeftWidth", "borderRightWidth"),
|
|
40
|
+
height: t("height", "paddingTop", "paddingBottom", "borderTopWidth", "borderBottomWidth")
|
|
41
|
+
};
|
|
42
|
+
}, N = (e) => {
|
|
43
|
+
const n = [];
|
|
44
|
+
e.forEach(({ label: i }, o) => {
|
|
45
|
+
const s = i && o.isConnected && g(o);
|
|
46
|
+
!s?.animate || w(o, (a) => a.id !== f) || (s.getAnimations().forEach((a) => a.id === p && a.cancel()), n.push({ id: o.dataset.id, el: s, from: i }));
|
|
47
|
+
});
|
|
48
|
+
const t = (i, o) => Math.abs(parseFloat(i) - parseFloat(o)) > 0.5;
|
|
49
|
+
return n.map((i) => ({ ...i, to: A(i.el) })).filter(({ from: i, to: o }) => t(i.width, o.width) || t(i.height, o.height));
|
|
50
|
+
}, j = (e, n, t, i) => e.forEach(({ el: o, from: s, to: a }) => {
|
|
51
|
+
o.animate([{ ...x, ...s }, { ...x, ...a }], { id: p, duration: n, easing: t }).onfinish = i;
|
|
52
|
+
});
|
|
53
|
+
export {
|
|
54
|
+
R as NONE,
|
|
55
|
+
F as flip,
|
|
56
|
+
v as freeze,
|
|
57
|
+
T as isBusy,
|
|
58
|
+
$ as isResizing,
|
|
59
|
+
j as resize,
|
|
60
|
+
N as resizesOf,
|
|
61
|
+
W as restBreaks,
|
|
62
|
+
m as slotsOf,
|
|
63
|
+
k as snapOf
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime"),t=require("react"),a=require("./state.cjs"),d=require("./utils.cjs"),I=require("react-dom"),L=require("./motion.cjs"),T=require("./optionList.cjs"),_=require("./dropdownPosition.cjs"),$=(e={})=>Object.fromEntries(Object.entries(e).filter(([r])=>r.startsWith("--"))),A=e=>(typeof e=="function"?e():e)||document.body,V=()=>()=>{};function g({more:e,ref:r}){const{texts:i}=t.useContext(a.SelectConfigContext),{loading:u,error:o}=t.useContext(a.SelectStateContext);return!o&&!u&&!e?null:n.jsxs("div",{ref:r,className:"rac-option","data-error":d.flag(o),"data-loading":d.flag(!o),children:[n.jsx("span",{className:"rac-option-text",children:o?i.error:u?i.loading:i.loadingMore}),!o&&d.dots]})}const W=t.memo(function(){const{selectRef:r,selectId:i,multiple:u,offset:o,duration:x,easing:j,animateOpacity:y,keepMounted:w,optionsClassName:R,style:q,container:v,texts:h,popup:E,ext:m}=t.useContext(a.SelectConfigContext),{visibility:O,normalizedOptions:D}=t.useContext(a.SelectStateContext),{setListReady:F}=t.useContext(a.SelectActionsContext),s=O&&D.length>0,C=t.useSyncExternalStore(V,()=>!0,()=>!1),[S,b]=t.useState(!1);s&&C&&!S&&b(!0);const[l,c]=t.useState(null),M=t.useCallback(()=>c(p=>p||"out"),[]),f=t.useRef(null),[N,P]=_.default({selectRef:r,panelRef:f,open:S,frozen:!s||l==="out",offset:o,onFlip:M}),k=()=>{if(l==="out"&&s){P(f.current),c("in");return}c(null),b(!1)},z=()=>{c(null),F(!0)};return!C||!E?null:I.createPortal(n.jsx(L.Collapse,{axis:"y",fade:y,in:s&&l!=="out",duration:l?x/2:void 0,nodeRef:f,unmountOnExit:!w&&!(l&&s),onEntered:z,onExited:k,onMouseDown:p=>p.preventDefault(),className:d.withClass("rac-options",R),style:{...$(q),"--rac-duration":`${x}ms`,"--rac-ease":j,pointerEvents:s?"auto":"none",position:"absolute"},children:n.jsxs("div",{className:"rac-list","aria-multiselectable":u,id:`${i}-listbox`,"aria-label":h.list,role:"listbox",tabIndex:"-1",ref:N,children:[n.jsx(T.default,{}),m.Footer?n.jsx(m.Footer,{}):n.jsx(g,{})]})}),A(v))});exports.StatusRow=g;exports.default=W;
|
package/dist/dropdown.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as i, jsxs as C } from "react/jsx-runtime";
|
|
3
|
+
import { memo as A, useContext as l, useSyncExternalStore as T, useState as g, useCallback as V, useRef as W } from "react";
|
|
4
|
+
import { SelectConfigContext as S, SelectStateContext as w, SelectActionsContext as q } from "./state.js";
|
|
5
|
+
import { withClass as B, dots as G, flag as y } from "./utils.js";
|
|
6
|
+
import { createPortal as H } from "react-dom";
|
|
7
|
+
import { Collapse as J } from "./motion.js";
|
|
8
|
+
import K from "./optionList.js";
|
|
9
|
+
import Q from "./dropdownPosition.js";
|
|
10
|
+
const U = (t = {}) => Object.fromEntries(Object.entries(t).filter(([n]) => n.startsWith("--"))), X = (t) => (typeof t == "function" ? t() : t) || document.body, Y = () => () => {
|
|
11
|
+
};
|
|
12
|
+
function Z({ more: t, ref: n }) {
|
|
13
|
+
const { texts: s } = l(S), { loading: a, error: o } = l(w);
|
|
14
|
+
return !o && !a && !t ? null : /* @__PURE__ */ C("div", { ref: n, className: "rac-option", "data-error": y(o), "data-loading": y(!o), children: [
|
|
15
|
+
/* @__PURE__ */ i("span", { className: "rac-option-text", children: o ? s.error : a ? s.loading : s.loadingMore }),
|
|
16
|
+
!o && G
|
|
17
|
+
] });
|
|
18
|
+
}
|
|
19
|
+
const lt = /* @__PURE__ */ A(function() {
|
|
20
|
+
const { selectRef: n, selectId: s, multiple: a, offset: o, duration: f, easing: h, animateOpacity: R, keepMounted: v, optionsClassName: E, style: O, container: D, texts: F, popup: N, ext: d } = l(S), { visibility: j, normalizedOptions: M } = l(w), { setListReady: k } = l(q), e = j && M.length > 0, m = T(Y, () => !0, () => !1), [x, b] = g(!1);
|
|
21
|
+
e && m && !x && b(!0);
|
|
22
|
+
const [r, c] = g(null), z = V(() => c((p) => p || "out"), []), u = W(null), [I, L] = Q({ selectRef: n, panelRef: u, open: x, frozen: !e || r === "out", offset: o, onFlip: z }), P = () => {
|
|
23
|
+
if (r === "out" && e) {
|
|
24
|
+
L(u.current), c("in");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
c(null), b(!1);
|
|
28
|
+
}, $ = () => {
|
|
29
|
+
c(null), k(!0);
|
|
30
|
+
};
|
|
31
|
+
return !m || !N ? null : H(
|
|
32
|
+
/* @__PURE__ */ i(
|
|
33
|
+
J,
|
|
34
|
+
{
|
|
35
|
+
axis: "y",
|
|
36
|
+
fade: R,
|
|
37
|
+
in: e && r !== "out",
|
|
38
|
+
duration: r ? f / 2 : void 0,
|
|
39
|
+
nodeRef: u,
|
|
40
|
+
unmountOnExit: !v && !(r && e),
|
|
41
|
+
onEntered: $,
|
|
42
|
+
onExited: P,
|
|
43
|
+
onMouseDown: (p) => p.preventDefault(),
|
|
44
|
+
className: B("rac-options", E),
|
|
45
|
+
style: { ...U(O), "--rac-duration": `${f}ms`, "--rac-ease": h, pointerEvents: e ? "auto" : "none", position: "absolute" },
|
|
46
|
+
children: /* @__PURE__ */ C(
|
|
47
|
+
"div",
|
|
48
|
+
{
|
|
49
|
+
className: "rac-list",
|
|
50
|
+
"aria-multiselectable": a,
|
|
51
|
+
id: `${s}-listbox`,
|
|
52
|
+
"aria-label": F.list,
|
|
53
|
+
role: "listbox",
|
|
54
|
+
tabIndex: "-1",
|
|
55
|
+
ref: I,
|
|
56
|
+
children: [
|
|
57
|
+
/* @__PURE__ */ i(K, {}),
|
|
58
|
+
d.Footer ? /* @__PURE__ */ i(d.Footer, {}) : /* @__PURE__ */ i(Z, {})
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
X(D)
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
export {
|
|
68
|
+
Z as StatusRow,
|
|
69
|
+
lt as default
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("react"),A=(o,r,a)=>{Math.abs(a)>.5&&(o.style[r]=`${parseFloat(o.style[r])+a}px`)},P=(o,r,a,x)=>{const d=o.getBoundingClientRect(),f=getComputedStyle(o);A(o,"left",r.left-d.left+parseFloat(f.marginLeft)),a?A(o,"bottom",d.bottom+parseFloat(f.marginBottom)-r.top+x):A(o,"top",r.bottom+x-d.top+parseFloat(f.marginTop))},T=(o,r)=>{o&&o.dataset.placement!==(r?"top":"bottom")&&(o.dataset.placement=r?"top":"bottom")},F=()=>typeof IntersectionObserver<"u",j=(o,r,a=window.innerHeight-o.bottom)=>a<r&&o.top>a,Y=({selectRef:o,panelRef:r,open:a,frozen:x,offset:d,onFlip:f})=>{const h=g.useRef(0),M=g.useRef(x),$=g.useRef(f);g.useLayoutEffect(()=>{M.current=x,$.current=f});const E=g.useCallback(t=>[o.current,r.current].forEach(i=>T(i,t)),[o,r]),w=g.useCallback(t=>{const i=o.current;if(!i||!t)return;t.scrollHeight&&(h.current=t.scrollHeight);const s=i.getBoundingClientRect(),c=t.dataset.placement,n=h.current,l=c==="top"?s.top-d>=n:window.innerHeight-s.bottom-d>=n;let u=c&&(M.current||l)?c==="top":j(s,n);c&&u!==(c==="top")&&($.current?.(),u=c==="top"),E(u),t.style.width=`${s.width}px`,t.style.left=`${s.left+window.scrollX}px`,t.style.top=u?"auto":`${s.bottom+window.scrollY+d}px`,t.style.bottom=u?`${window.innerHeight-s.top-window.scrollY+d}px`:"auto",P(t,s,u,d)},[o,d,E]),q=g.useCallback(t=>{t&&w(t.parentElement)},[w]),z=g.useCallback(t=>{t?.removeAttribute("data-placement"),w(t)},[w]);return g.useEffect(()=>{const t=o.current;if(a||!t||!F())return;h.current||=parseFloat(getComputedStyle(t).getPropertyValue("--rac-list-max-height"))||250;const i={fits:!0,lower:!1},s=(n,l,u)=>{const v=new IntersectionObserver(([{boundingClientRect:H,rootBounds:C}])=>{C&&(u(H,C),E(!i.fits&&i.lower))},{rootMargin:n,threshold:l});return v.observe(t),v},c=[s(`0px 0px ${-h.current}px 0px`,[0,1],(n,l)=>{i.fits=n.bottom<=l.bottom}),s("0px 0px -50% 0px",[0,.5,1],(n,l)=>{i.lower=n.top+n.bottom>2*l.bottom})];return()=>c.forEach(n=>n.disconnect())},[a,o,E]),g.useLayoutEffect(()=>{const t=o.current;if(!a||!t)return;const i=t.ownerDocument,s=r.current;let c=0,n=0,l="",u=null;const v=()=>{const e=t.getBoundingClientRect(),m=r.current?.getBoundingClientRect()??e,b=j(e,h.current),y=h.current+d;return[e.left-m.left,b?e.top-m.bottom:e.bottom-m.top,e.width,window.innerHeight,r.current?.scrollHeight,b,e.top>=y,window.innerHeight-e.bottom>=y].join()},H=()=>{if(u?.disconnect(),!F())return;const e=t.getBoundingClientRect(),{clientWidth:m,clientHeight:b}=i.documentElement,y=[e.top,m-e.right,b-e.bottom,e.left].map(O=>`${-Math.floor(O)}px`).join(" ");let S=!1;u=new IntersectionObserver(([O])=>{S&&O.intersectionRatio<1&&p(),S=O.intersectionRatio===1},{root:i,rootMargin:y,threshold:1}),u.observe(t)},C=()=>v()===l?!1:(w(r.current),l=v(),!0),I=()=>{if(c=0,C())n=0;else if(++n>1)return H();c=requestAnimationFrame(I)},p=()=>{n=0,c||=requestAnimationFrame(I)};r.current?.removeAttribute("data-offscreen"),w(r.current),l=v(),H(),window.addEventListener("scroll",p,{capture:!0,passive:!0}),window.addEventListener("resize",p);const k=typeof ResizeObserver<"u"&&new ResizeObserver(p);k&&[t,r.current].forEach(e=>e&&k.observe(e));const D=({target:e})=>!t.contains(e)&&!r.current?.contains(e),B=typeof MutationObserver<"u"&&new MutationObserver(e=>{e.some(D)&&C()&&p()});B&&B.observe(i.body,{subtree:!0,childList:!0,attributes:!0,characterData:!0});const L=F()&&new IntersectionObserver(([{isIntersecting:e,boundingClientRect:m,rootBounds:b}])=>{const y=!e&&!!b&&m.bottom>b.top&&m.top<b.bottom&&m.right>b.left&&m.left<b.right;r.current?.toggleAttribute("data-offscreen",y)});return L&&L.observe(t),()=>{cancelAnimationFrame(c),window.removeEventListener("scroll",p,{capture:!0}),window.removeEventListener("resize",p);for(const e of[k,B,L,u])e&&e.disconnect();s?.removeAttribute("data-placement")}},[a,w,d,o,r]),[q,z]};exports.default=Y;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef as L, useLayoutEffect as j, useCallback as O, useEffect as T } from "react";
|
|
3
|
+
const $ = (o, r, d) => {
|
|
4
|
+
Math.abs(d) > 0.5 && (o.style[r] = `${parseFloat(o.style[r]) + d}px`);
|
|
5
|
+
}, U = (o, r, d, x) => {
|
|
6
|
+
const a = o.getBoundingClientRect(), g = getComputedStyle(o);
|
|
7
|
+
$(o, "left", r.left - a.left + parseFloat(g.marginLeft)), d ? $(o, "bottom", a.bottom + parseFloat(g.marginBottom) - r.top + x) : $(o, "top", r.bottom + x - a.top + parseFloat(g.marginTop));
|
|
8
|
+
}, V = (o, r) => {
|
|
9
|
+
o && o.dataset.placement !== (r ? "top" : "bottom") && (o.dataset.placement = r ? "top" : "bottom");
|
|
10
|
+
}, k = () => typeof IntersectionObserver < "u", q = (o, r, d = window.innerHeight - o.bottom) => d < r && o.top > d, X = ({ selectRef: o, panelRef: r, open: d, frozen: x, offset: a, onFlip: g }) => {
|
|
11
|
+
const h = L(0), I = L(x), M = L(g);
|
|
12
|
+
j(() => {
|
|
13
|
+
I.current = x, M.current = g;
|
|
14
|
+
});
|
|
15
|
+
const E = O((t) => [o.current, r.current].forEach((i) => V(i, t)), [o, r]), w = O((t) => {
|
|
16
|
+
const i = o.current;
|
|
17
|
+
if (!i || !t) return;
|
|
18
|
+
t.scrollHeight && (h.current = t.scrollHeight);
|
|
19
|
+
const s = i.getBoundingClientRect(), c = t.dataset.placement, n = h.current, m = c === "top" ? s.top - a >= n : window.innerHeight - s.bottom - a >= n;
|
|
20
|
+
let u = c && (I.current || m) ? c === "top" : q(s, n);
|
|
21
|
+
c && u !== (c === "top") && (M.current?.(), u = c === "top"), E(u), t.style.width = `${s.width}px`, t.style.left = `${s.left + window.scrollX}px`, t.style.top = u ? "auto" : `${s.bottom + window.scrollY + a}px`, t.style.bottom = u ? `${window.innerHeight - s.top - window.scrollY + a}px` : "auto", U(t, s, u, a);
|
|
22
|
+
}, [o, a, E]), P = O((t) => {
|
|
23
|
+
t && w(t.parentElement);
|
|
24
|
+
}, [w]), S = O((t) => {
|
|
25
|
+
t?.removeAttribute("data-placement"), w(t);
|
|
26
|
+
}, [w]);
|
|
27
|
+
return T(() => {
|
|
28
|
+
const t = o.current;
|
|
29
|
+
if (d || !t || !k()) return;
|
|
30
|
+
h.current ||= parseFloat(getComputedStyle(t).getPropertyValue("--rac-list-max-height")) || 250;
|
|
31
|
+
const i = { fits: !0, lower: !1 }, s = (n, m, u) => {
|
|
32
|
+
const f = new IntersectionObserver(([{ boundingClientRect: C, rootBounds: y }]) => {
|
|
33
|
+
y && (u(C, y), E(!i.fits && i.lower));
|
|
34
|
+
}, { rootMargin: n, threshold: m });
|
|
35
|
+
return f.observe(t), f;
|
|
36
|
+
}, c = [
|
|
37
|
+
s(`0px 0px ${-h.current}px 0px`, [0, 1], (n, m) => {
|
|
38
|
+
i.fits = n.bottom <= m.bottom;
|
|
39
|
+
}),
|
|
40
|
+
s("0px 0px -50% 0px", [0, 0.5, 1], (n, m) => {
|
|
41
|
+
i.lower = n.top + n.bottom > 2 * m.bottom;
|
|
42
|
+
})
|
|
43
|
+
];
|
|
44
|
+
return () => c.forEach((n) => n.disconnect());
|
|
45
|
+
}, [d, o, E]), j(() => {
|
|
46
|
+
const t = o.current;
|
|
47
|
+
if (!d || !t) return;
|
|
48
|
+
const i = t.ownerDocument, s = r.current;
|
|
49
|
+
let c = 0, n = 0, m = "", u = null;
|
|
50
|
+
const f = () => {
|
|
51
|
+
const e = t.getBoundingClientRect(), l = r.current?.getBoundingClientRect() ?? e, b = q(e, h.current), v = h.current + a;
|
|
52
|
+
return [e.left - l.left, b ? e.top - l.bottom : e.bottom - l.top, e.width, window.innerHeight, r.current?.scrollHeight, b, e.top >= v, window.innerHeight - e.bottom >= v].join();
|
|
53
|
+
}, C = () => {
|
|
54
|
+
if (u?.disconnect(), !k()) return;
|
|
55
|
+
const e = t.getBoundingClientRect(), { clientWidth: l, clientHeight: b } = i.documentElement, v = [e.top, l - e.right, b - e.bottom, e.left].map((H) => `${-Math.floor(H)}px`).join(" ");
|
|
56
|
+
let D = !1;
|
|
57
|
+
u = new IntersectionObserver(([H]) => {
|
|
58
|
+
D && H.intersectionRatio < 1 && p(), D = H.intersectionRatio === 1;
|
|
59
|
+
}, { root: i, rootMargin: v, threshold: 1 }), u.observe(t);
|
|
60
|
+
}, y = () => f() === m ? !1 : (w(r.current), m = f(), !0), z = () => {
|
|
61
|
+
if (c = 0, y()) n = 0;
|
|
62
|
+
else if (++n > 1) return C();
|
|
63
|
+
c = requestAnimationFrame(z);
|
|
64
|
+
}, p = () => {
|
|
65
|
+
n = 0, c ||= requestAnimationFrame(z);
|
|
66
|
+
};
|
|
67
|
+
r.current?.removeAttribute("data-offscreen"), w(r.current), m = f(), C(), window.addEventListener("scroll", p, { capture: !0, passive: !0 }), window.addEventListener("resize", p);
|
|
68
|
+
const B = typeof ResizeObserver < "u" && new ResizeObserver(p);
|
|
69
|
+
B && [t, r.current].forEach((e) => e && B.observe(e));
|
|
70
|
+
const Y = ({ target: e }) => !t.contains(e) && !r.current?.contains(e), A = typeof MutationObserver < "u" && new MutationObserver((e) => {
|
|
71
|
+
e.some(Y) && y() && p();
|
|
72
|
+
});
|
|
73
|
+
A && A.observe(i.body, { subtree: !0, childList: !0, attributes: !0, characterData: !0 });
|
|
74
|
+
const F = k() && new IntersectionObserver(([{ isIntersecting: e, boundingClientRect: l, rootBounds: b }]) => {
|
|
75
|
+
const v = !e && !!b && l.bottom > b.top && l.top < b.bottom && l.right > b.left && l.left < b.right;
|
|
76
|
+
r.current?.toggleAttribute("data-offscreen", v);
|
|
77
|
+
});
|
|
78
|
+
return F && F.observe(t), () => {
|
|
79
|
+
cancelAnimationFrame(c), window.removeEventListener("scroll", p, { capture: !0 }), window.removeEventListener("resize", p);
|
|
80
|
+
for (const e of [B, A, F, u]) e && e.disconnect();
|
|
81
|
+
s?.removeAttribute("data-placement");
|
|
82
|
+
};
|
|
83
|
+
}, [d, w, a, o, r]), [P, S];
|
|
84
|
+
};
|
|
85
|
+
export {
|
|
86
|
+
X as default
|
|
87
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),o=require("react"),Re=require("react-dom"),Y=o.createContext(null),ne=o.createContext(null),se=o.createContext(null),kt=(e,t)=>{const n=typeof t=="function"?t(e):t;return n===e?e:Object.keys(n).some(r=>!Object.is(n[r],e[r]))?{...e,...n}:e},at=e=>{let t=e;const n=new Set;return{get:()=>t,set:s=>{Object.keys(s).every(r=>Object.is(s[r],t[r]))||(t={...t,...s},n.forEach(r=>r()))},subscribe:s=>(n.add(s),()=>n.delete(s))}},Be=e=>{const t=o.useRef(e);o.useInsertionEffect(()=>{t.current=e});const[n]=o.useState(()=>Object.fromEntries(Object.keys(e).map(s=>[s,(...r)=>t.current[s](...r)])));return n},ct=(e,t)=>{const[n,s]=o.useState(e);return n===e||t(n,e)?n:(s(e),e)},jt=(e,t)=>e===t||!!e&&!!t&&Object.keys(e).length===Object.keys(t).length&&Object.keys(e).every(n=>Object.is(e[n],t[n])),ye=(e,t,n=0)=>{if(Object.is(e,t))return!0;if(n>12||typeof e!="object"||typeof t!="object"||e===null||t===null||Array.isArray(e)!==Array.isArray(t))return!1;if(e.$$typeof||t.$$typeof)return e.$$typeof===t.$$typeof&&e.type===t.type&&e.key===t.key&&ye(e.props,t.props,n+1);const s=Object.keys(e);return s.length===Object.keys(t).length&&s.every(r=>Object.hasOwn(t,r)&&ye(e[r],t[r],n+1))},Tt=new Set(["style","texts","icons","attrs"]),Mt=(e,t)=>{const n=Object.keys(t);return n.length===Object.keys(e).length&&n.every(s=>Tt.has(s)?jt(e[s],t[s]):Object.is(e[s],t[s]))},It=e=>ct(e,Mt),$e=e=>ct(e,ye),he={XMark:({className:e="",...t})=>E.jsx("svg",{className:e,viewBox:"0 0 320 512",fill:"currentColor","aria-hidden":"true",height:"1em",width:"1em",...t,children:E.jsx("path",{d:"M310.6 361.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L160 301.3 54.6 406.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L114.7 256 9.4 150.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 210.7 265.4 105.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L205.3 256l105.3 105.4z"})}),ArrowUp:({className:e="",...t})=>E.jsx("svg",{className:e,viewBox:"0 0 448 512",fill:"currentColor","aria-hidden":"true",height:"1em",width:"1em",...t,children:E.jsx("path",{d:"M34.9 289.5l175.9-175.8c9.4-9.4 24.6-9.4 33.9 0L420.1 289.5c15.1 15.1 4.4 41-17 41H51.9c-21.4 0-32.1-25.9-17-41z"})}),Checkmark:({className:e="",...t})=>E.jsx("svg",{className:e,viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",height:"1em",width:"1em",...t,children:E.jsx("path",{d:"M20.285 6.708a1 1 0 0 0-1.414-1.416l-9.192 9.192-4.243-4.244a1 1 0 1 0-1.414 1.416l5 5a1 1 0 0 0 1.414 0l9.849-9.948z"})})},ie=(e,t)=>{if(!e)return null;const n=(s={})=>({...t,...s,style:{...t?.style,...s?.style}});if(typeof e=="string")return E.jsx("img",{src:e,...n(),className:ae("rac-icon",t?.className),alt:""});if(o.isValidElement(e))return o.cloneElement(e,n(e.props));if(typeof e=="function"||typeof e=="object"&&e.$$typeof){const s=e;return E.jsx(s,{...n()})}return null},Ee=(e,t)=>`${e}-${String(t).replace(/[^A-Za-z0-9-]/gu,n=>`_${n.codePointAt(0).toString(36)}_`)}`,X=e=>e?"":void 0,ae=(e,t)=>t?`${e} ${t}`:e,Fe=(e,t,n)=>e.jsx||(t&&"original"in e?t(e.original,{selected:n,disabled:!!e.disabled}):null),Pe=E.jsxs("span",{className:"rac-dots","aria-hidden":"true",children:[E.jsx("i",{}),E.jsx("i",{}),E.jsx("i",{})]}),Rt=(()=>{try{return process.env.NODE_ENV!=="production"}catch{return!1}})(),We=new Set,ee=(e,t)=>{!Rt||We.has(e)||(We.add(e),console.warn(`[react-animated-select] ${t}`))},Z=e=>{e?.stopPropagation(),e?.preventDefault()},lt=(e,t)=>{e?.currentTarget.contains(document.activeElement)&&t.current?.focus()},$t={index:-1,fallback:-1,ready:!1},xe=({index:e,fallback:t})=>e===-1?t:e,At=10,Lt=500,Nt=new Set(["ArrowDown","ArrowUp","PageDown","PageUp","Home","End"]),Dt=(e,t)=>o.useMemo(()=>{const n=new Set(e.map(r=>r.group).filter(Boolean)),s=r=>!!r&&!r.disabled&&!r.loading&&(r.groupHeader?n.has(r.name):!r.group||t.has(r.group));return{reach:s,list:e.flatMap((r,i)=>s(r)?[i]:[])}},[e,t]),Bt=(e,t,n,s)=>{const r=e.length-1;if(r<0)return-1;if(n==="Home")return e[0];if(n==="End")return e[r];const i=n==="ArrowUp"||n==="PageUp"?-1:1,a=e.indexOf(t);if(a===-1)return e[i>0?0:r];const c=a+i*(n.startsWith("Page")?At:1);return c>=0&&c<=r?e[c]:n.startsWith("Page")||s?e[c<0?0:r]:e[(c+e.length)%e.length]},Ft=(e,t,n,s)=>{const r=[...s].every(u=>u===s[0]),i=r?s[0]:s,a=t.filter(u=>"original"in e[u]),c=Math.max(a.indexOf(n)+(r?1:0),0);for(let u=0;u<a.length;u++){const y=a[(c+u)%a.length];if(String(e[y].name).toLowerCase().startsWith(i))return y}return-1};function Pt({props:e,state:t,setState:n,normalizedOptions:s,expandedGroups:r,selected:i,selectedIDs:a,visibility:c,setVisibility:u,modelActions:y,loadMoreOnce:f,highlightStore:O}){const{disabled:d,multiple:l,hasMore:x,loadButton:w,loadOffset:g,loadAhead:p,icons:v,onFocus:$,onBlur:M,onKeyDown:H}=e,{selectOption:T,clear:h,removeOption:j}=y,{deleting:L}=t,{reach:B,list:I}=Dt(s,r),F=o.useRef({lastWindowFocusTime:0,justFocused:!1,focusTimeout:null,query:"",queryTimeout:null}),b=o.useMemo(()=>{const m=new Set(l?a.map(C=>C.id):i?[i.id]:[]),S=m.size?s.findIndex(C=>m.has(C.id)&&B(C)):-1;return S!==-1?S:I.find(C=>!s[C].groupHeader)??I[0]??-1},[s,i,a,l,B,I]),N=m=>{!w&&c&&x&&m>=s.length-p&&f()};o.useLayoutEffect(()=>{const{index:m}=O.get();O.set({fallback:b,index:m!==-1&&B(s[m])?m:-1}),N(xe(O.get()))}),o.useEffect(()=>{const m=F.current,S=()=>m.lastWindowFocusTime=Date.now();return window.addEventListener("focus",S),()=>{window.removeEventListener("focus",S),clearTimeout(m.focusTimeout),clearTimeout(m.queryTimeout)}},[]);const k=m=>{O.set({index:m}),N(m)},P=(m,S)=>{const C=F.current;clearTimeout(C.queryTimeout),C.queryTimeout=setTimeout(()=>C.query="",Lt),C.query+=m.toLowerCase();const R=Ft(s,I,S,C.query);R!==-1&&k(R),c||u(!0)};return Be({highlight:k,handleListScroll:m=>{if(w)return;const{scrollTop:S,scrollHeight:C,clientHeight:R}=m.currentTarget;C-S<=R+g&&f()},handleBlur:m=>{const S=m.relatedTarget?.closest(".rac-options");m.currentTarget.contains(m.relatedTarget)||S||(M?.(m),L&&n({deleting:!1}),c&&u(!1))},handleFocus:m=>{const S=m.currentTarget.contains(m.relatedTarget);S||$?.(m),!(S||m.target!==m.currentTarget||c||d||L||document.hidden||Date.now()-F.current.lastWindowFocusTime<100)&&(clearTimeout(F.current.focusTimeout),F.current.focusTimeout=setTimeout(()=>F.current.justFocused=!1,200),F.current.justFocused=!0,u(!0))},toggleVisibility:m=>{if(L){Z(m),n({deleting:!1});return}d||F.current.justFocused||u(!c)},handleKeyDown:m=>{if(H?.(m),m.defaultPrevented||d||m.nativeEvent?.isComposing)return;const{key:S}=m;if(m.target!==m.currentTarget&&(S==="Enter"||S.length===1))return;const C=xe(O.get());if(S.length===1&&!m.ctrlKey&&!m.metaKey&&!m.altKey&&(S!==" "||F.current.query)){m.preventDefault(),P(S,C);return}if(Nt.has(S)){m.preventDefault(),(c||S==="Home"||S==="End")&&k(Bt(I,C,S,!w&&x)),c||u(!0);return}switch(S){case"Enter":case" ":m.preventDefault(),c?C!==-1&&s[C]&&(k(C),T(s[C],m)):u(!0);break;case"Escape":if(L)n({deleting:!1});else if(c)u(!1);else break;Z(m);break;case"Tab":c&&u(!1);break;case"Backspace":case"Delete":{const R=a.at(-1);if(l&&S==="Backspace"&&v.remove&&R)j(R.id);else if(v.clear&&(i||R))h();else break;m.preventDefault();break}}}})}const Ht=["group","disabled","options","items","children"],He=["name","label","id","value"],pe=e=>e!=null&&e!=="",ut=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),Oe=e=>ut(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),Vt=e=>{try{const t=String(e);return t.startsWith("[object ")?null:t}catch{return null}},Ve=(e,t=!1)=>{if(t&&typeof e.group=="string")return e.group;const n=He.find(i=>pe(e[i]));if(n)return String(e[n]);const s=!Oe(e)&&Vt(e);if(s)return s;const r=Object.entries(e).find(([i,a])=>!Ht.includes(i)&&pe(a));return r?String(r[1]):null},zt=e=>Oe(e)&&("options"in e||"group"in e&&!He.some(t=>t in e)),Ge=(e,t,n,s,r,{emptyOption:i,invalidOption:a,disabledOption:c})=>{const u=`${n}-${t}`;if(e==null||e==="")return{id:u,userId:null,name:i,raw:e,disabled:!0,type:"normal",group:s,groupDisabled:r};if(typeof e=="function")return{id:u,userId:null,name:a,raw:e,disabled:!0,invalid:!0,type:"normal",group:s};if(ut(e)){const y=r||e.disabled===!0,f=e.value!==void 0?e.value:e.id!==void 0?e.id:e,O=Ve(e)||(y?c:i);return{id:u,userId:e.id??e.value??e.name??e.label,name:O,raw:f,original:e,disabled:y||O===i,type:typeof f=="boolean"?"boolean":"normal",group:s||e.group||null,groupDisabled:r}}return{id:u,userId:e,name:String(e),raw:e,original:e,disabled:r,type:typeof e=="boolean"?"boolean":"normal",group:s}},qt=({options:e,jsxOptions:t,childrenFirst:n,hasMore:s,loadButton:r,loadPending:i,loadingTitle:a,emptyOption:c,invalidOption:u,disabledOption:y,emptyGroup:f})=>{const O={emptyOption:c,invalidOption:u,disabledOption:y},d=new Map,l=[],x=new Set,w=h=>{let j=h;for(let L=1;x.has(j);L++)j=`${h}~${L}`;return x.add(j),j},g=t.map((h,j)=>{if(h.isGroupMarker)return{...h,type:"group-marker"};const L=!h.label&&!pe(h.userId)&&!pe(h.value)&&!h.hasJsx;return{...h,id:w(`jsx-${h.id}`),index:j,userId:h.userId,raw:h.value,original:h.value,name:h.label||(pe(h.value)?String(h.value):c),disabled:!!h.disabled||L,type:typeof h.value=="boolean"?"boolean":"normal",group:h.group||null}});let p=0;const v=(h,j=null,L=!1,B="0")=>{Array.isArray(h)||(h=[h]),h.forEach((I,F)=>{const b=`${B}-${F}`;if(zt(I)){const N=Ve(I,!0)||f;d.has(N)||d.set(N,{disabled:!!I.disabled,items:[]}),I.options?v(I.options,N,L||!!I.disabled,b):l.push({id:`empty-${N}-${b}`,name:N,group:N,isPlaceholder:!0,type:"group-marker",index:p++})}else Oe(I)&&!He.some(N=>N in I)&&!I.group?Object.values(I).forEach((N,k)=>l.push({...Ge(N,`${b}-${k}`,"default",j,L,O),index:p++})):l.push({...Ge(I,b,"default",j,L,O),index:p++})})};v(e);const $=n?[...g,...l]:[...l,...g],M=[],H=new Set;$.forEach(h=>{if(!h.group){M.push({type:"item",data:h});return}H.has(h.group)||(H.add(h.group),M.push({type:"group",name:h.group})),d.has(h.group)||d.set(h.group,{items:[]});const j=d.get(h.group);h.isGroupMarker?(j.className=h.className,j.style=h.style,h.disabled&&(j.disabled=!0)):h.isPlaceholder||j.items.push(h)});const T=[];return M.forEach(h=>{if(h.type==="item"){T.push(h.data);return}const j=d.get(h.name);T.push({className:j?.className||"",id:`group-header-${h.name}`,disabled:!!j?.disabled,style:j?.style||{},groupHeader:!0,name:h.name,type:"group"}),j?.items.forEach(L=>T.push(L))}),s&&r&&T.push({id:"special-load-more-id",name:a,loadMore:!0,loading:i,type:"special"}),T},Wt=e=>{const t=()=>null;return t.racKind="define",t.racRender=e,t.displayName=`defineOption(${e.name||"anonymous"})`,t},Ke={selected:null,selectedIDs:[]},le=e=>{try{return JSON.stringify(e)}catch{return}},dt=(e,t)=>e===t||e!==e&&t!==t,ve=e=>typeof e=="object"&&e!==null,Gt=(e,t)=>dt(e,t)||ve(e)&&ve(t)&&le(e)!==void 0&&le(e)===le(t),_e=(e,t,n,s)=>{if(e==null||Array.isArray(e)&&e.length===0)return Ke;const r=s.length?new Map(t.map(f=>[f.id,f])):null,i=r?[...s.map(f=>r.get(f)).filter(Boolean),...t]:t,a=new Set,c=new Map,u=f=>"original"in f&&!a.has(f.id),y=f=>{const O=ve(f);let d=i.find(p=>u(p)&&dt(p.original,f));const l=O?le(f):void 0;if(!d&&l!==void 0&&(d=i.find(p=>u(p)&&ve(p.original)&&le(p.original)===l)),d)return a.add(d.id),d;const x=String(O?f.id||f.value||l||"object":f),w=(c.get(x)??-1)+1;c.set(x,w);const g=`virtual-${x}-${w}`;return O?{id:g,name:Ve(f)||String(f.id||"Selected Object"),raw:f.value??f.id??f,original:f,userId:f.id??f.value??null,virtual:!0}:{id:g,name:String(f),raw:f,original:f,userId:f,virtual:!0}};return n?{selected:null,selectedIDs:(Array.isArray(e)?e:[e]).map(y)}:{selected:y(Array.isArray(e)?e[0]:e),selectedIDs:Ke.selectedIDs}},Ue={x:["width","marginLeft","marginRight","paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"],y:["height","marginTop","marginBottom","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth"]},Kt={x:{minWidth:"0px",maxWidth:"none"},y:{minHeight:"0px",maxHeight:"none"}},ft=o.createContext(null);let Ae=null;const _t=()=>Ae??=(queueMicrotask(()=>{Ae=null}),{});function te({as:e="div",axis:t="y",fade:n=!1,in:s,unmountOnExit:r=!0,easing:i,duration:a,group:c,nodeRef:u,onEntered:y,onExited:f,...O}){const d=o.useContext(Y),l=o.useContext(ft),x=s===void 0&&!!l,w=x?l.present:!!s,g=a??(d?.duration??300)/(x&&l.swap?2:1),p=i??d?.easing??"ease",v=o.useRef(null),$=u??v,M=o.useRef(null),H=o.useRef(!1),T=o.useRef({restart:()=>{}}),[h]=o.useState(()=>x&&l.appear?!w:w),j=o.useRef(h),[L,B]=o.useState(!w);w&&L&&B(!1);const I=o.useEffectEvent(()=>{if(c?.delete(T.current),w){M.current?.cancel(),M.current=null,y?.();return}f?.(),x&&l.onExited(),r&&(M.current=null,B(!0))});if(o.useLayoutEffect(()=>{const b=$.current;if(!b)return;const N=n?[...Ue[t],"opacity"]:Ue[t],k={overflow:"hidden",textOverflow:"clip",...Kt[t]},P={...Object.fromEntries(N.map(A=>[A,A==="opacity"?0:"0px"])),...k},m=()=>{const{overflow:A}=b.style;b.style.overflow="hidden";const V=getComputedStyle(b),K={...Object.fromEntries(N.map(z=>[z,V[z]])),...k};return b.style.overflow=A,K},S=(A,V)=>{const K=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,z=M.current=b.animate([A,V],{duration:K?0:g,easing:p,fill:j.current?"backwards":"both"});if(z.onfinish=()=>{M.current===z&&H.current&&I()},T.current.frames=[A,V],!c)return;const q=z.timeline?.currentTime;q!=null&&(z.startTime=q,z.currentTime=0),T.current.batch=_t(),c.add(T.current)},C=()=>{const[A,V]=T.current.frames,K=M.current.effect.getComputedTiming().progress??0,z=q=>parseFloat(A[q])+(parseFloat(V[q])-parseFloat(A[q]))*K;return{...Object.fromEntries(N.map(q=>[q,q==="opacity"?z(q):`${z(q)}px`])),...k}};if(T.current.restart=A=>{const V=M.current;if(V?.playState!=="running"||!A&&T.current.batch===Ae)return;const K=C();V.cancel(),S(K,j.current?m():P)},j.current===w){!w&&!M.current&&b.animate&&(M.current=b.animate([P,P],{fill:"forwards"}));return}j.current=w;const R=M.current;if(R?.playState==="running"){if(!c){R.reverse();return}T.current.restart(!0)}else{if(R?.cancel(),!b.animate){I();return}w?S(P,m()):S(m(),P)}c?.forEach(A=>A!==T.current&&A.restart())},[w,t,n,g,p,$,c]),o.useLayoutEffect(()=>{const b=T.current;return H.current=!0,M.current?.playState==="running"&&c?.add(b),()=>{H.current=!1,c?.delete(b)}},[c]),L&&r)return null;const F=e;return E.jsx(F,{ref:$,...O})}const Ut=({id:e,present:t,appear:n,swap:s,onExited:r,children:i})=>{const a=o.useMemo(()=>({present:t,appear:n,swap:s,onExited:()=>r(e)}),[e,t,n,s,r]);return E.jsx(ft.Provider,{value:a,children:i})},Ye=(e,t,n,s=!0)=>{const r=o.Children.toArray(t).filter(o.isValidElement),i=new Set(r.map(d=>d.key)),a=new Map(e.map(d=>[d.key,d])),c=r.map(d=>({key:d.key,el:d,present:!0,appear:a.get(d.key)?.appear??s}));let u=0;const y=new Set;e.forEach(d=>{if(i.has(d.key))d.present&&(u=c.findIndex(l=>l.key===d.key)+1);else if(!d.pending){const l=d.present?{...d,present:!1,swap:!1}:d;d.present&&y.add(l),c.splice(u++,0,l)}});const f=d=>d.present&&(a.get(d.key)?.pending??!a.has(d.key)),O=n&&(y.size>0||e.some(d=>d.pending))&&c.some(d=>!d.present)&&c.some(f);return{children:t,list:O?c.map(d=>y.has(d)?{...d,swap:!0}:f(d)?{...d,pending:!0,swap:!0}:d):c}},Xe=e=>e.some(t=>!t.present)?e:e.map(t=>t.pending?{...t,pending:!1}:t);function Le({children:e,hold:t=!1,wait:n=!1}){const[s,r]=o.useState(()=>({...Ye([],e,n,!1),hold:t}));let i=s;i.children!==e&&(i={...i,...Ye(i.list,e,n)}),i.hold!==t&&(i={...i,hold:t,list:t?i.list:Xe(i.list.filter(c=>c.present))}),i!==s&&r(i);const a=o.useCallback(c=>r(u=>!u.hold&&u.list.some(y=>y.key===c&&!y.present)?{...u,list:Xe(u.list.filter(y=>y.key!==c))}:u),[]);return s.list.map(({key:c,el:u,present:y,appear:f,pending:O,swap:d=!1})=>!O&&E.jsx(Ut,{id:c,present:y,appear:f,swap:d,onExited:a,children:u},c))}const pt="rac-chip-slot",we="rac-flip",ze="rac-resize",qe=[],Je={overflow:"hidden",textOverflow:"clip",boxSizing:"border-box",minWidth:"0px",maxWidth:"none",minHeight:"0px",maxHeight:"none"},gt="(prefers-reduced-motion: reduce)",fe=()=>!!window.matchMedia?.(gt).matches,Yt=e=>{const t=window.matchMedia?.(gt);return t?.addEventListener("change",e),()=>t?.removeEventListener("change",e)},ge=e=>Array.from(e.children).filter(t=>t.classList.contains(pt)),Se=e=>e.firstElementChild?.firstElementChild,ht=(e,t)=>!!e?.getAnimations?.().some(n=>n.constructor===Animation&&t(n)),mt=(e,t)=>ht(e,n=>n.playState==="running"&&t(n)),bt=e=>ge(e).some(t=>mt(Se(t),n=>n.id===ze)),Ce=e=>Array.from(e.children).some(t=>mt(t,n=>n.id!==we))||bt(e),Xt=(e,t)=>e.length===t.length&&e.every((n,s)=>n===t[s]),Jt=e=>{const t=[];let n=-1/0;for(const s of e){const r=s.getBoundingClientRect();r.top>=n-1&&(t.push([]),n=r.bottom),t.at(-1).push(s),n=Math.max(n,r.bottom)}return t},yt=(e,t,n,s,r)=>{const i=e.cloneNode(!0),{height:a,paddingInlineEnd:c}=getComputedStyle(e),u=r?"":`height: ${a}; min-height: 0;`;i.style.cssText=`visibility: hidden; pointer-events: none; ${u} padding-inline-end: calc(${c} + ${n}px)`,i.querySelectorAll(`:scope > :not(.${pt})`).forEach(l=>l.remove()),s&&ge(i).forEach(l=>s.has(l.dataset.id)||l.remove()),n&&i.querySelectorAll(".rac-chip-del").forEach(l=>l.remove());const y=ge(i);y.forEach(l=>r?.has(l.dataset.id)&&Object.assign(Se(l)?.style??{},{minWidth:r.get(l.dataset.id),boxSizing:"border-box"}));const f=new Map(y.map((l,x)=>[l.dataset.id,x]));t?.slice(1).forEach((l,x)=>{const w=Math.min(...l.map(p=>f.get(p)??1/0)),g=Math.max(...t[x].map(p=>f.get(p)??-1).filter(p=>p<w));g>=0&&y[g].after(Object.assign(document.createElement("div"),{className:"rac-spacer"}))}),e.style.position="absolute",e.after(i),i.getAnimations?.({subtree:!0}).forEach(l=>l.effect?.getComputedTiming().endTime<1/0&&l.finish());const O=Jt(y).map(l=>l.map(x=>x.dataset.id)),d=i.offsetHeight;return i.remove(),e.style.position="",{rows:O,fit:d}},xt=(e,t)=>{const n=t?t.slice(0,-1).map(r=>r.at(-1)):qe,{breaks:s}=e.get();return Xt(s,n)?s:n},Ze=(e,t,n,s)=>xt(e,s&&n.length?yt(t,null,s,new Set(n.map(r=>r.id))).rows:null),me=(e,t,n)=>{const{rows:s,fit:r}=yt(t,n.rows,n.reserve,null,n.floor);Object.assign(n,{rows:s,fit:n.floor?r:null}),e.set({held:!0,breaks:xt(e,s)})},Zt=(e,t)=>new Map(ge(e).map(n=>{const{left:s,top:r}=n.getBoundingClientRect(),i=t&&Se(n);return[n,{left:s,top:r,label:i?vt(i):null}]})),Qe=(e,t,n,s)=>{if(!e.animate)return;e.getAnimations().forEach(c=>c.id===we&&c.cancel());const r=e.getBoundingClientRect(),i=t.left-r.left,a=t.top-r.top;(Math.abs(i)>.5||Math.abs(a)>.5)&&e.animate([{transform:`translate(${i}px, ${a}px)`},{transform:"none"}],{id:we,duration:n,easing:s})},vt=e=>{const t=getComputedStyle(e),n=(...s)=>`${s.reduce((r,i)=>r+parseFloat(t[i]),0)}px`;return t.boxSizing==="border-box"?{width:t.width,height:t.height}:{width:n("width","paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"),height:n("height","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth")}},Qt=e=>{const t=[];e.forEach(({label:s},r)=>{const i=s&&r.isConnected&&Se(r);!i?.animate||ht(r,a=>a.id!==we)||(i.getAnimations().forEach(a=>a.id===ze&&a.cancel()),t.push({id:r.dataset.id,el:i,from:s}))});const n=(s,r)=>Math.abs(parseFloat(s)-parseFloat(r))>.5;return t.map(s=>({...s,to:vt(s.el)})).filter(({from:s,to:r})=>n(s.width,r.width)||n(s.height,r.height))},en=(e,t,n,s)=>e.forEach(({el:r,from:i,to:a})=>{r.animate([{...Je,...i},{...Je,...a}],{id:ze,duration:t,easing:n}).onfinish=s}),ke=(e,t,n,s,r,i)=>{if(!e||n===t.value)return;const a=getComputedStyle(e),c=t.anim?a.height:t.root;t.anim?.cancel(),i&&Object.assign(i.style,{height:`${n}px`,boxSizing:"border-box"}),t.root=a.height,i&&Object.assign(i.style,{height:"",boxSizing:""});const u=!t.value||c===t.root||!e.animate||fe();if(t.value=n,t.anim=null,u)return;const y={overflow:"hidden",alignItems:"flex-start"},f=t.anim=e.animate([{...y,height:c},{...y,height:t.root}],{duration:s,easing:r});f.onfinish=()=>{t.anim===f&&(t.anim=null)}},tn=.25,nn={hoverId:null,swipedId:null,held:!1,breaks:qe};function sn(e){const{selectRef:t,duration:n,easing:s,multiple:r,deleteInline:i,deleteAlways:a,icons:c,valueAsOption:u,renderOption:y}=o.useContext(Y),{selectedIDs:f,deleting:O,visibility:d,active:l}=o.useContext(se),{setDeleting:x,setVisibility:w}=o.useContext(ne),[g,p]=o.useState(0),[v]=o.useState(()=>at(nn)),[$]=o.useState(()=>new Set),M=o.useSyncExternalStore(v.subscribe,()=>v.get().held,()=>!1),H=o.useSyncExternalStore(v.subscribe,()=>v.get().breaks,()=>qe),T=o.useSyncExternalStore(Yt,fe,()=>!1),h=o.useRef({rows:null,reserve:0,chips:e,swap:!1,duration:n,easing:s}),j=o.useRef(null),L=o.useRef({value:0,root:"",anim:null}),B=o.useRef(null),I=o.useRef(null),F=i&&!a&&!O&&!!c.remove,b=F?g+tn:0,N=r&&F&&!g&&e.length>0,k=u?y?2:1:0,P=o.useEffectEvent((C,R)=>{const A=B.current,V=h.current;if(!A)return;const K=bt(A);if(K&&R)return;C&&v.get().held&&me(v,A,V);const z=V.swap?V.duration/2:V.duration;K?V.fit!=null&&ke(t.current,L.current,V.fit,z,V.easing,A):(R||L.current.value)&&ke(t.current,L.current,A.offsetHeight,z,V.easing),v.get().held||v.set({breaks:Ze(v,A,V.chips,V.reserve)})});o.useLayoutEffect(()=>{Object.assign(h.current,{duration:n,easing:s})},[n,s]),o.useLayoutEffect(()=>{const C=h.current,R=B.current,A=C.chips!==e;Object.assign(C,{chips:e,reserve:b}),A&&R&&Ce(R)&&me(v,R,C),P(!A)},[e,b,v]),o.useLayoutEffect(()=>{const C=()=>P(!0,!0),R=typeof ResizeObserver>"u"?null:new ResizeObserver(C);return R?R.observe(B.current):C(),document.fonts?.addEventListener("loadingdone",C),()=>{R?.disconnect(),document.fonts?.removeEventListener("loadingdone",C)}},[]);const m=o.useCallback(()=>{const C=B.current;if(!C||!v.get().held||Ce(C))return;const R=h.current,A=ge(C),V=A.map(z=>z.getBoundingClientRect()),K=Ze(v,C,R.chips,R.reserve);Object.assign(R,{rows:null,floor:null,fit:null}),Re.flushSync(()=>v.set({held:!1,breaks:K})),R.swap=Ce(C),R.swap&&Re.flushSync(()=>me(v,C,R)),fe()||A.forEach((z,q)=>z.isConnected&&Qe(z,V[q],R.swap?n/2:n,s))},[v,n,s]),S=o.useCallback(C=>{B.current&&(j.current=Zt(B.current,C))},[]);return o.useLayoutEffect(()=>{const C=B.current,R=h.current;if(!C||!j.current||!n||fe())return;const A=Qt(j.current);A.length&&(R.floor=new Map(A.map(({id:V,from:K})=>[V,K.width])),me(v,C,R),ke(t.current,L.current,R.fit,n,s,C),en(A,n,s,()=>{m(),P(!1,!0)}))},[k,v,n,s,t,m]),o.useLayoutEffect(()=>{const C=j.current;!C||H!==v.get().breaks||(j.current=null,fe()||C.forEach((R,A)=>A.isConnected&&Qe(A,R,n,s)))},[H,e,k,v,n,s]),o.useEffect(()=>()=>L.current.anim?.cancel(),[]),o.useEffect(()=>{O&&d&&w(!1),O&&(!f.length||!l)&&x(!1),v.set({hoverId:null,...!l&&{swipedId:null}})},[f.length,O,d,l,x,w,v]),o.useLayoutEffect(()=>{const C=I.current;if(!N||!C)return;const R=getComputedStyle(C);p(C.getBoundingClientRect().width+parseFloat(R.marginLeft)+parseFloat(R.marginRight))},[N]),{chipStore:v,delGroup:$,valueRef:B,delIconRef:I,probe:N,settle:m,held:M,snapshot:S,look:k,wait:n>0&&!T}}const et=1,tt=2,rn=600,on=10,nt=30,an=o.memo(function({element:t,deleting:n,locked:s,chipStore:r,delGroup:i}){const{selectRef:a,deleteInline:c,deleteAlways:u,icons:y,texts:f,valueAsOption:O,renderOption:d}=o.useContext(Y),l=!!y.remove,{setVisibility:x,setDeleting:w,removeOption:g}=o.useContext(ne),p=o.useRef({longPressTimer:null,longPress:!1,x:0,y:0}),v=o.useSyncExternalStore(r.subscribe,()=>{const{hoverId:k,swipedId:P}=r.get();return(k===t.id?et:0)|(P===t.id?tt:0)},()=>0),$=!!(v&et),M=!!(v&tt),H=o.useCallback(k=>{const{clientX:P,clientY:m}=k.touches[0];Object.assign(p.current,{x:P,y:m,longPress:!1}),clearTimeout(p.current.longPressTimer),l&&(p.current.longPressTimer=setTimeout(()=>{w(!0),p.current.longPress=!0,a.current?.focus(),x(!1),window.navigator.vibrate?.(50)},rn))},[l,w,x,a]),T=o.useCallback(k=>{const{clientX:P,clientY:m}=k.touches[0],S=p.current.x-P;Math.hypot(S,p.current.y-m)>on&&clearTimeout(p.current.longPressTimer),S>nt&&!M?r.set({hoverId:null,swipedId:t.id}):S<-nt&&M&&r.set({swipedId:null})},[t.id,M,r]),h=o.useCallback(k=>{clearTimeout(p.current.longPressTimer),p.current.longPress&&k.cancelable&&k.preventDefault(),p.current.longPress=!1},[]),j=o.useCallback(()=>r.set({hoverId:t.id,swipedId:null}),[t.id,r]),L=o.useCallback(()=>{r.get().hoverId===t.id&&r.set({hoverId:null})},[t.id,r]);o.useEffect(()=>()=>clearTimeout(p.current.longPressTimer),[]);const B=O?Fe(t,d,!0):null,I=B?E.jsx("div",{className:"rac-option-jsx",children:B}):E.jsx("span",{className:"rac-chip-text",children:t.name||f.emptyOption}),F=o.useCallback(k=>{r.set({swipedId:null}),lt(k,a),g(t.id),Z(k)},[t.id,g,r,a]),b=o.useCallback(k=>{Z(k),n&&F(k)},[n,F]),N=l&&(u||!s&&($||M||n));return E.jsxs("div",{className:ae("rac-chip",B&&t.className),style:B?t.style:void 0,...!s&&{onTouchStart:H,onTouchMove:T,onTouchEnd:h,onTouchCancel:h,onMouseEnter:j,onMouseLeave:L,onClick:b},children:[I,E.jsx(te,{"aria-label":`${f.remove} ${t.name??""}`.trim(),group:c&&!u&&!n?i:void 0,onMouseDown:Z,onClick:F,className:"rac-chip-del",disabled:s,tabIndex:-1,type:"button",in:N,as:"button",axis:"x",children:ie(y.remove)})]})}),cn=o.memo(function({element:t,chipStore:n,settle:s,...r}){const i=o.useSyncExternalStore(n.subscribe,()=>n.get().breaks.includes(t.id),()=>!1);return E.jsxs(o.Fragment,{children:[E.jsx(te,{className:"rac-chip-slot",onEntered:s,onExited:s,unmountOnExit:!1,"data-id":t.id,axis:"x",fade:!0,children:E.jsx(an,{element:t,chipStore:n,...r})}),i&&E.jsx("div",{className:"rac-spacer"})]})}),ln={position:"absolute",visibility:"hidden",pointerEvents:"none"},wt=[],un=()=>{},dn=e=>e==null?"":typeof e=="object"?le(e)??"":String(e),fn=o.memo(function(){const{selectRef:t,multiple:n,name:s,form:r,required:i}=o.useContext(Y),{selected:a,selectedIDs:c,disabled:u,fieldsetDisabled:y}=o.useContext(se),{reset:f,markInvalid:O}=o.useContext(ne),d=o.useRef(null);o.useEffect(()=>{const p=d.current?.getRootNode();let v;const $=M=>{M.target===d.current?.form&&(clearTimeout(v),v=setTimeout(()=>M.defaultPrevented||f()))};return p?.addEventListener("reset",$,!0),()=>{clearTimeout(v),p?.removeEventListener("reset",$,!0)}},[f]);const l=n?c:a?[a]:wt,x=!i&&(!s||n&&!l.length),w=x||!l.length?[""]:l.map(p=>dn(p.original)),g=()=>t.current?.focus();return w.map((p,v)=>E.jsx("input",{className:"rac-input",ref:v?void 0:d,name:x?void 0:s,form:r,value:p,hidden:x,required:i&&!v,disabled:u&&!y,tabIndex:-1,"aria-hidden":"true",autoComplete:"off",onChange:un,onInvalid:O,onFocus:g},v))});class pn extends o.Component{getSnapshotBeforeUpdate(t){const n=t.look!==this.props.look;return(n||t.chips!==this.props.chips)&&this.props.take(n),null}componentDidUpdate(){}render(){return null}}const st=(e,t)=>{const n=new Set(e.map(a=>a.id)),s=new Map(t.map(([a,c])=>[c.id,a])),r=t.filter(([,a])=>!n.has(a.id)),i=new Set(t.map(([a])=>a));return e.map(a=>{if(s.has(a.id))return[s.get(a.id),a];const c=r.findIndex(([,y])=>Gt(y.original,a.original));if(c>=0)return[r.splice(c,1)[0][0],a];let u=a.id;for(;i.has(u);)u+="~";return i.add(u),[u,a]})},gn=e=>{const[t,n]=o.useState(()=>({chips:e,keyed:st(e,[])}));if(t.chips===e)return t.keyed;const s=st(e,t.keyed);return n({chips:e,keyed:s}),s},hn=o.memo(function(){const{selectedText:t,icons:n,valueAsOption:s,renderOption:r}=o.useContext(Y),{selectedIDs:i,title:a,valueOption:c,hasActualValue:u,loading:y,error:f,deleting:O,active:d}=o.useContext(se),l=i.length>0&&!t,x=l?i:wt,{chipStore:w,delGroup:g,valueRef:p,delIconRef:v,probe:$,settle:M,held:H,snapshot:T,look:h,wait:j}=sn(x),L=gn(x),[B]=o.useState(()=>new Set),I=s&&c?Fe(c,r,!0):null,F=y&&!f&&!u,b=`${I?c.id:a}${F?"-loading":""}`,N=c?.type==="boolean"?String(c.raw):void 0;return E.jsxs("div",{className:"rac-value",ref:p,children:[E.jsx(pn,{chips:x,look:h,take:T}),E.jsx(Le,{children:!l&&E.jsxs(te,{axis:"x",fade:!0,group:B,className:ae("rac-title",I&&c.className),style:I?c.style:void 0,"data-bool":N,onEntered:M,onExited:M,children:[I?E.jsx("div",{className:"rac-option-jsx",children:I}):a,F&&Pe]},b)}),E.jsx(Le,{hold:H,wait:j,children:L.map(([k,P])=>E.jsx(cn,{element:P,deleting:O,locked:!d,chipStore:w,delGroup:g,settle:M},k))}),$&&E.jsx("button",{type:"button",className:"rac-chip-del",tabIndex:-1,"aria-hidden":"true",ref:v,style:ln,children:ie(n.remove)})]})}),mn=o.memo(function(){const{selectRef:t,selectId:n,highlightStore:s,className:r,style:i,duration:a,easing:c,deleteInline:u,icons:y,texts:f,placeholder:O,id:d,required:l,popup:x,attrs:w}=o.useContext(Y),{visibility:g,active:p,hasActualValue:v,deleting:$,loading:M,loadPending:H,error:T,invalid:h,normalizedOptions:j}=o.useContext(se),{handleBlur:L,handleFocus:B,handleKeyDown:I,toggleVisibility:F,clear:b}=o.useContext(ne),N=o.useSyncExternalStore(s.subscribe,()=>{const S=g?j[xe(s.get())]:null;return S?Ee(n,S.id):void 0},()=>{}),k=!!y.clear&&v&&p&&!$,P=!!y.arrow&&p&&!$&&x,m=x?{role:"combobox","aria-haspopup":"listbox","aria-controls":`${n}-listbox`,"aria-expanded":g,"aria-activedescendant":N,"aria-required":l||void 0}:{role:"group"};return E.jsxs("div",{...w,id:d,ref:t,style:{"--rac-duration":`${a}ms`,"--rac-ease":c,...i},className:ae("rac-select",r),...p&&{onKeyDown:I,onFocus:B,onClick:F,onBlur:L},...m,"aria-disabled":!p,tabIndex:p?0:-1,"aria-busy":M||H||void 0,"aria-label":w["aria-label"]??(w["aria-labelledby"]?void 0:O),"aria-invalid":h||w["aria-invalid"],"aria-describedby":[w["aria-describedby"],T&&`${n}-error`].filter(Boolean).join(" ")||void 0,"data-inline-delete":X(u),"data-empty":X(!v),"data-deleting":X($),"data-error":X(T),"data-invalid":X(h),children:[E.jsx(hn,{}),E.jsxs(Le,{children:[k&&E.jsx(te,{as:"button",type:"button",axis:"x",className:"rac-clear",tabIndex:-1,"aria-label":f.clear,onMouseDown:Z,onClick:S=>{lt(S,t),b(S)},children:ie(y.clear)},"clear"),P&&E.jsx(te,{axis:"x",className:"rac-arrow","aria-hidden":"true",children:ie(y.arrow)},"arrow")]}),E.jsx(fn,{})]})}),je=0,bn=1,rt=2,Et=e=>{const{highlightStore:t}=o.useContext(Y),n=o.useRef(null),s=o.useSyncExternalStore(t.subscribe,()=>{const r=t.get();return xe(r)!==e?je:r.ready?rt:bn},()=>je);return o.useLayoutEffect(()=>{s===rt&&n.current?.scrollIntoView?.({block:"nearest"})},[s]),[n,s!==je]},Ot=(e,t)=>`${Ee(e,t.id)}_l`,yn=o.memo(function({option:t,index:n,open:s,hasChildren:r}){const{selectId:i,icons:a,texts:c}=o.useContext(Y),{selectOption:u,highlight:y}=o.useContext(ne),[f,O]=Et(n),d=r&&!t.disabled;return E.jsxs("div",{className:ae("rac-group",t.className),onMouseEnter:()=>d&&y(n),onClick:l=>u(t,l),"aria-label":d?`${t.name}, ${s?c.groupOpen:c.groupClosed}`:void 0,"aria-disabled":!d||void 0,"data-highlighted":X(O),"data-disabled":X(t.disabled),id:Ee(i,t.id),"data-open":X(s),"aria-selected":"false",style:t.style,role:"option",ref:f,children:[E.jsx("span",{className:"rac-group-text",id:Ot(i,t),children:t.name}),E.jsx(te,{axis:"x",in:r&&!t.disabled,className:"rac-group-arrow","aria-hidden":"true",children:ie(a.arrow)})]})}),xn=o.memo(function({option:t,index:n,isSelected:s,showCheckbox:r}){const{selectId:i,icons:a,renderOption:c}=o.useContext(Y),{selectOption:u,highlight:y}=o.useContext(ne),[f,O]=Et(n),d=!t.disabled&&!t.loading,l=Fe(t,c,s);return E.jsxs("div",{className:ae("rac-option",t.className),onMouseEnter:()=>d&&y(n),onClick:x=>!t.loading&&u(t,x),"aria-disabled":t.disabled||t.loading,"data-invalid":X(t.invalid),"data-bool":typeof t.raw=="boolean"?String(t.raw):void 0,"data-highlighted":X(O),"data-loading":X(t.loading),id:Ee(i,t.id),"aria-selected":s,style:t.style,role:"option",ref:f,children:[l?E.jsx("div",{className:"rac-option-jsx",children:l}):E.jsx("span",{className:"rac-option-text",children:t.name}),t.loading&&Pe,r&&E.jsxs("div",{className:"rac-check","data-default":X(!a.checkbox),children:[ie(a.check,{className:"rac-checkmark"}),ie(a.checkbox,{className:"rac-check-icon"})]})]})}),vn=o.memo(function(){const{selectId:t,multiple:n}=o.useContext(Y),{normalizedOptions:s,selected:r,selectedIDs:i,expandedGroups:a}=o.useContext(se),c=r?.id;return o.useMemo(()=>{const u=new Set(i.map(g=>g.id)),y=s.reduce((g,p)=>(p.group&&(g[p.group]=(g[p.group]||0)+1),g),{}),f=[];let O=[],d=null,l=null;const x=()=>{d!==null&&O.length&&f.push(E.jsx(te,{axis:"y",in:a.has(d),className:"rac-group-items",role:"group","aria-labelledby":l,children:O},`slide-${d}`)),O=[]},w=(g,p)=>E.jsx(xn,{isSelected:u.has(g.id)||c===g.id,showCheckbox:n&&!g.disabled&&"original"in g,option:g,index:p},g.id);return s.forEach((g,p)=>{g.groupHeader?(x(),d=g.name,l=Ot(t,g),f.push(E.jsx(yn,{hasChildren:y[g.name]>0,open:a.has(g.name),option:g,index:p},g.id))):g.group?O.push(w(g,p)):(x(),d=null,f.push(w(g,p)))}),x(),f},[s,c,i,a,n,t])}),wn=(e,t,n,s)=>{const r=e.getBoundingClientRect(),i=getComputedStyle(e),a=r.left-parseFloat(i.marginLeft)-t.left,c=n?r.bottom+parseFloat(i.marginBottom)-t.top+s:r.top-parseFloat(i.marginTop)-t.bottom-s;Math.abs(a)>.5&&(e.style.left=`${t.left-a}px`),Math.abs(c)>.5&&(e.style[n?"bottom":"top"]=`${parseFloat(e.style[n?"bottom":"top"])+(n?c:-c)}px`)},En=(e,t)=>{e&&e.dataset.placement!==(t?"top":"bottom")&&(e.dataset.placement=t?"top":"bottom")},Te=()=>typeof IntersectionObserver<"u",ot=(e,t,n=window.innerHeight-e.bottom)=>n<t&&e.top>n,On=({selectRef:e,panelRef:t,open:n,frozen:s,offset:r,onFlip:i})=>{const a=o.useRef(0),c=o.useRef(s),u=o.useRef(i);o.useLayoutEffect(()=>{c.current=s,u.current=i});const y=o.useCallback(l=>[e.current,t.current].forEach(x=>En(x,l)),[e,t]),f=o.useCallback(l=>{const x=e.current;if(!x||!l)return;l.scrollHeight&&(a.current=l.scrollHeight);const w=x.getBoundingClientRect(),g=l.dataset.placement,p=a.current,v=g==="top"?w.top-r>=p:window.innerHeight-w.bottom-r>=p;let $=g&&(c.current||v)?g==="top":ot(w,p);g&&$!==(g==="top")&&(u.current?.(),$=g==="top"),y($),l.style.width=`${w.width}px`,l.style.left=`${w.left+window.scrollX}px`,l.style.top=$?"auto":`${w.bottom+window.scrollY+r}px`,l.style.bottom=$?`${window.innerHeight-w.top-window.scrollY+r}px`:"auto",wn(l,w,$,r)},[e,r,y]),O=o.useCallback(l=>{l&&f(l.parentElement)},[f]),d=o.useCallback(l=>{l?.removeAttribute("data-placement"),f(l)},[f]);return o.useEffect(()=>{const l=e.current;if(n||!l||!Te())return;a.current||=parseFloat(getComputedStyle(l).getPropertyValue("--rac-list-max-height"))||250;const x={fits:!0,lower:!1},w=(p,v,$)=>{const M=new IntersectionObserver(([{boundingClientRect:H,rootBounds:T}])=>{T&&($(H,T),y(!x.fits&&x.lower))},{rootMargin:p,threshold:v});return M.observe(l),M},g=[w(`0px 0px ${-a.current}px 0px`,[0,1],(p,v)=>{x.fits=p.bottom<=v.bottom}),w("0px 0px -50% 0px",[0,.5,1],(p,v)=>{x.lower=p.top+p.bottom>2*v.bottom})];return()=>g.forEach(p=>p.disconnect())},[n,e,y]),o.useLayoutEffect(()=>{const l=e.current;if(!n||!l)return;const x=l.ownerDocument,w=t.current;let g=0,p=0,v="",$=null;const M=()=>{const b=l.getBoundingClientRect(),N=t.current?.getBoundingClientRect()??b,k=ot(b,a.current),P=a.current+r;return[b.left-N.left,k?b.top-N.bottom:b.bottom-N.top,b.width,window.innerHeight,t.current?.scrollHeight,k,b.top>=P,window.innerHeight-b.bottom>=P].join()},H=()=>{if($?.disconnect(),!Te())return;const b=l.getBoundingClientRect(),{clientWidth:N,clientHeight:k}=x.documentElement,P=[b.top,N-b.right,k-b.bottom,b.left].map(S=>`${-Math.floor(S)}px`).join(" ");let m=!1;$=new IntersectionObserver(([S])=>{m&&S.intersectionRatio<1&&j(),m=S.intersectionRatio===1},{root:x,rootMargin:P,threshold:1}),$.observe(l)},T=()=>M()===v?!1:(f(t.current),v=M(),!0),h=()=>{if(g=0,T())p=0;else if(++p>1)return H();g=requestAnimationFrame(h)},j=()=>{p=0,g||=requestAnimationFrame(h)};t.current?.removeAttribute("data-offscreen"),f(t.current),v=M(),H(),window.addEventListener("scroll",j,{capture:!0,passive:!0}),window.addEventListener("resize",j);const L=typeof ResizeObserver<"u"&&new ResizeObserver(j);L&&[l,t.current].forEach(b=>b&&L.observe(b));const B=({target:b})=>!l.contains(b)&&!t.current?.contains(b),I=typeof MutationObserver<"u"&&new MutationObserver(b=>{b.some(B)&&T()&&j()});I&&I.observe(x.body,{subtree:!0,childList:!0,attributes:!0,characterData:!0});const F=Te()&&new IntersectionObserver(([{isIntersecting:b,boundingClientRect:N,rootBounds:k}])=>{const P=!b&&!!k&&N.bottom>k.top&&N.top<k.bottom&&N.right>k.left&&N.left<k.right;t.current?.toggleAttribute("data-offscreen",P)});return F&&F.observe(l),()=>{cancelAnimationFrame(g),window.removeEventListener("scroll",j,{capture:!0}),window.removeEventListener("resize",j);for(const b of[L,I,F,$])b&&b.disconnect();w?.removeAttribute("data-placement")}},[n,f,r,e,t]),[O,d]},Sn=(e={})=>Object.fromEntries(Object.entries(e).filter(([t])=>t.startsWith("--"))),Cn=e=>(typeof e=="function"?e():e)||document.body,kn=()=>()=>{},jn=o.memo(function(){const{selectRef:t,selectId:n,multiple:s,offset:r,duration:i,easing:a,animateOpacity:c,keepMounted:u,optionsClassName:y,style:f,container:O,hasMore:d,loadButton:l,texts:x,popup:w}=o.useContext(Y),{visibility:g,normalizedOptions:p,loading:v,error:$}=o.useContext(se),{handleListScroll:M,setListReady:H}=o.useContext(ne),T=g&&p.length>0,h=o.useSyncExternalStore(kn,()=>!0,()=>!1),[j,L]=o.useState(!1);T&&h&&!j&&L(!0);const[B,I]=o.useState(null),F=o.useCallback(()=>I(S=>S||"out"),[]),b=o.useRef(null),[N,k]=On({selectRef:t,panelRef:b,open:j,frozen:!T||B==="out",offset:r,onFlip:F}),P=()=>{if(B==="out"&&T){k(b.current),I("in");return}I(null),L(!1)},m=()=>{I(null),H(!0)};return!h||!w?null:Re.createPortal(E.jsx(te,{axis:"y",fade:c,in:T&&B!=="out",duration:B?i/2:void 0,nodeRef:b,unmountOnExit:!u&&!(B&&T),onEntered:m,onExited:P,onMouseDown:S=>S.preventDefault(),className:ae("rac-options",y),style:{...Sn(f),"--rac-duration":`${i}ms`,"--rac-ease":a,pointerEvents:T?"auto":"none",position:"absolute"},children:E.jsxs("div",{onScroll:M,className:"rac-list","aria-multiselectable":s,id:`${n}-listbox`,"aria-label":x.list,role:"listbox",tabIndex:"-1",ref:N,children:[E.jsx(vn,{}),$?E.jsx("div",{className:"rac-option","data-error":"",children:E.jsx("span",{className:"rac-option-text",children:x.error})}):(v||!l&&d)&&E.jsxs("div",{className:"rac-option","data-loading":"",children:[E.jsx("span",{className:"rac-option-text",children:v?x.loading:x.loadingMore}),Pe]})]})}),Cn(O))}),Tn=250,Mn=5e3,In=[],Rn=()=>()=>{},ce=(e,t)=>typeof e=="function"?e(t):String(e??"").replace(/\{(n|label)\}/g,()=>t),$n=(e,t,n,s)=>{const r=[];if(e.picked.length&&!t.picked.length)r.push(ce(n.cleared));else if(s){const i=new Set(t.picked.map(u=>u.id)),a=new Set(e.picked.map(u=>u.id)),c=e.picked.filter(u=>!i.has(u.id));c.length&&r.push(ce(n.removed,c.map(u=>u.name).join(", "))),t.picked.some(u=>!a.has(u.id))&&r.push(ce(n.selected,t.picked.length))}return t.open&&e.count&&t.count>e.count&&r.push(ce(n.loaded,t.count-e.count)),t.error&&!e.error&&r.push(ce(n.error)),r.filter(Boolean).join(". ")},An=o.memo(function(){const{selectRef:t,selectId:n,multiple:s,texts:r}=o.useContext(Y),{selected:i,selectedIDs:a,normalizedOptions:c,visibility:u,deleting:y,error:f}=o.useContext(se),O=o.useSyncExternalStore(Rn,()=>!0,()=>!1),[d,l]=o.useState(""),x=o.useRef({base:null,timer:0,wipe:0,latest:null}),w=o.useMemo(()=>c.reduce((g,p)=>"original"in p?g+1:g,0),[c]);return o.useEffect(()=>{const g=s?a:i?[i]:In;x.current.latest={snap:{picked:g,count:w,open:u,error:!!f},texts:r,multiple:s,deleting:y}}),o.useEffect(()=>{const g=x.current,{snap:p,deleting:v}=g.latest;if(!g.base||!g.timer&&!v&&!t.current?.contains(document.activeElement)){g.base=p;return}clearTimeout(g.timer),g.timer=setTimeout(()=>{g.timer=0;const{snap:$,texts:M,multiple:H}=g.latest,T=$n(g.base,$,M,H);g.base=$,T&&(l(h=>h===T?`${T} `:T),clearTimeout(g.wipe),g.wipe=setTimeout(()=>l(""),Mn))},Tn)},[i,a,w,f,t]),o.useEffect(()=>{const g=x.current;return()=>{clearTimeout(g.timer),clearTimeout(g.wipe)}},[]),O?E.jsxs("div",{className:"rac-live",children:[E.jsx("div",{"aria-live":"polite","aria-atomic":"true",children:d}),f&&E.jsx("div",{id:`${n}-error`,children:ce(r.error)})]}):null}),Ne=[];function Ln({props:e,jsxOptions:t,state:n,setState:s,setVisibility:r,loadMoreOnce:i}){const{onChange:a,disabled:c,loading:u,error:y,multiple:f,childrenFirst:O,groupsClosed:d,hasMore:l,loadButton:x,placeholder:w,selectedText:g,texts:p}=e,{disabledOption:v,emptyOption:$,invalidOption:M,emptyGroup:H}=p,{loadPending:T,internalValue:h,toggledGroups:j,picked:L}=n,B=$e(e.options),I=$e(e.value),F=I!==void 0,b=F?I:h,N=T?p.loadingMore:p.loadMore,k=o.useMemo(()=>qt({options:B,jsxOptions:t,childrenFirst:O,hasMore:l,loadButton:x,loadPending:T,loadingTitle:N,emptyOption:$,invalidOption:M,disabledOption:v,emptyGroup:H}),[B,t,O,l,x,T,N,$,M,v,H]),P=o.useMemo(()=>new Set(k.filter(D=>D.groupHeader&&!D.disabled&&d===j.has(D.name)).map(D=>D.name)),[k,j,d]),{selected:m,selectedIDs:S}=o.useMemo(()=>_e(b,k,f,L),[b,k,f,L]),C=k.length>0,R=!c&&C,A=b!=null&&!(Array.isArray(b)&&!b.length)&&!(Oe(b)&&!Object.keys(b).length),V=A&&g?null:m,K=o.useMemo(()=>A&&g?g:m?m.name:y?p.error:u?p.loading:c?p.disabled:C?w:p.empty,[y,u,c,A,g,m,C,w,p]),z=D=>s(G=>{const _=new Set(G.toggledGroups);return _.has(D)?_.delete(D):_.add(D),{toggledGroups:_}}),q=(D,G,_)=>{s(F?{picked:_}:{internalValue:D,picked:_}),a?.(D,G)},ue=D=>q(D.map(G=>G.original),D.map(G=>G.userId),D.map(G=>G.id)),de=Be({toggleGroup:z,selectOption:(D,G)=>{if(D.groupHeader){Z(G),D.disabled||z(D.name);return}if(D.disabled||D.loadMore){Z(G),D.loadMore&&!D.loading&&i();return}if(f){Z(G);const _=S.some(re=>re.id===D.id);ue(_?S.filter(re=>re.id!==D.id):[...S,D]);return}m?.id!==D.id&&q(D.original,D.userId,[D.id]),r(!1)},clear:D=>{Z(D),q(f?[]:null,f?[]:null,Ne)},removeOption:D=>ue(S.filter(G=>G.id!==D)),reset:()=>{s({deleting:!1,invalid:!1}),r(!1);const D=f?[]:null,G=e.defaultValue??D,{selected:_,selectedIDs:re}=_e(G,k,f,Ne),W=f?re:_?[_]:[],U=f?S:m?[m]:[];ye(b??D,G)&&W.length===U.length&&W.every((Q,oe)=>Q.id===U[oe].id)||q(G,f?W.map(Q=>Q.userId):_?.userId??null,W.map(Q=>Q.id))}});return{normalizedOptions:k,expandedGroups:P,selected:m,selectedIDs:S,hasOptions:C,active:R,hasActualValue:A,title:K,valueOption:V,actions:de}}const Nn=e=>({internalVisibility:!1,deleting:!1,loadPending:!1,toggledGroups:new Set,internalValue:e.defaultValue,picked:Ne,fieldsetDisabled:!1,invalid:!1});function Dn(e,t){const[n,s]=o.useReducer(kt,e,Nn),{internalVisibility:r,deleting:i,loadPending:a,fieldsetDisabled:c}=n,u=o.useMemo(()=>c&&!e.disabled?{...e,disabled:!0}:e,[e,c]),{ref:y,open:f,onOpenChange:O,popup:d,hasMore:l,loadMore:x,loadButton:w,error:g,disabled:p,loading:v,required:$,texts:M}=u,H=o.useId(),T=o.useMemo(()=>H.replace(/:/g,""),[H]),h=o.useRef(null);o.useImperativeHandle(y,()=>h.current),o.useLayoutEffect(()=>{const W=h.current?.querySelector(".rac-input");if(!W)return;const U=()=>s({fieldsetDisabled:!e.disabled&&W.matches(":disabled")});U();const Q=new MutationObserver(U);for(let oe=W.parentElement;oe;oe=oe.parentElement)oe.tagName==="FIELDSET"&&Q.observe(oe,{attributeFilter:["disabled"]});return()=>Q.disconnect()},[e.disabled]);const[j]=o.useState(()=>at($t)),L=f!==void 0,B=L?!!f:r,I=o.useRef(!1),F=o.useRef(!1),b=Be({setVisibility:W=>{W===B||W&&!d||(L||s({internalVisibility:W}),O?.(W))},loadMoreOnce:()=>{if(!l||I.current)return;if(!x)return ee("no loadMore","`hasMore` is set, but there is no `loadMore` to call.");I.current=!0,s({loadPending:!0});const W=()=>s({loadPending:!1});try{x()?.then?.(W,W)}catch(U){I.current=!1,W(),(globalThis.reportError??console.error)(U)}},setListReady:W=>j.set({ready:W}),setDeleting:W=>s({deleting:W}),markInvalid:()=>s({invalid:!0})}),N=Ln({props:u,jsxOptions:t,state:n,setState:s,setVisibility:b.setVisibility,loadMoreOnce:b.loadMoreOnce}),{normalizedOptions:k,expandedGroups:P,selected:m,selectedIDs:S,hasOptions:C,active:R,hasActualValue:A,title:V,valueOption:K,actions:z}=N,q=R&&B&&d,ue=Pt({props:u,state:n,setState:s,normalizedOptions:k,expandedGroups:P,selected:m,selectedIDs:S,visibility:q,highlightStore:j,setVisibility:b.setVisibility,loadMoreOnce:b.loadMoreOnce,modelActions:z});o.useEffect(()=>{s({loadPending:!1})},[k.length,l,w]),o.useEffect(()=>{a||(I.current=!1)},[a]),o.useEffect(()=>{q&&h.current&&document.activeElement!==h.current&&h.current.focus(),q||j.set({index:-1,ready:!1})},[q,j]),o.useEffect(()=>{F.current&&!R&&b.setVisibility(!1),F.current=R},[R,b]);const de=o.useRef(null),D=u.value!==void 0;o.useEffect(()=>{const W={value:D,open:L};for(const U in W)de.current&&de.current[U]!==W[U]&&ee(`switch ${U}`,`\`${U}\` switched between controlled and uncontrolled (\`undefined\`) after mount. Pick one mode for the lifetime of the Select, like a React input${U==="value"?"; clear a controlled value with `null` or `[]`":""}.`);de.current=W},[D,L]),o.useLayoutEffect(()=>{h.current?.querySelector(".rac-input")?.setCustomValidity($&&!A&&M.required||"")},[$,A,M.required]);const G=n.invalid&&$&&!A&&!p,_=o.useMemo(()=>({...b,...z,...ue}),[b,z,ue]),re=o.useMemo(()=>({visibility:q,deleting:i,loadPending:a,expandedGroups:P,selectedIDs:S,normalizedOptions:k,selected:m,hasOptions:C,active:R,hasActualValue:A,title:V,valueOption:K,disabled:p,fieldsetDisabled:c,invalid:G,loading:v,error:g}),[q,i,a,P,S,k,m,C,R,A,V,K,p,c,G,v,g]);return{selectId:T,selectRef:h,highlightStore:j,state:re,actions:_}}const Bn={},J=e=>e!=null&&e!=="",De=e=>e?typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(De).join(" ").replace(/\s+/g," ").trim():o.isValidElement(e)?De(e.props.children):"":"",Fn=({name:e,label:t,id:n,value:s,className:r,style:i,children:a,disabled:c,group:u},y,f)=>{const O=De(a),d=s!==void 0?s:O;return a!=null&&!O&&!J(t)&&!J(e)&&!J(n)&&!J(s)&&ee("no text","<Option> has content but no text to show in the title or chips. Add a `label` (or `value`), or enable `valueAsOption`."),{id:J(n)?String(n):y,userId:J(n)?n:d,value:d,label:J(t)?String(t):J(e)?String(e):O||(J(n)?String(n):""),jsx:a,hasJsx:a!=null,className:r,style:i,disabled:!!c,group:u||f||null}},Pn=({name:e,label:t,value:n,id:s,disabled:r,className:i="",style:a=Bn},c)=>{const u=e??t??s??n;return{disabled:!!r,isGroupMarker:!0,group:J(u)?String(u):c,className:i,style:a}},Hn=e=>`<${typeof e=="string"?e:e?.displayName||e?.name||"Component"}>`,be=(e,t,n=null,s="o",r=[])=>(o.Children.toArray(e).forEach(i=>{if(!o.isValidElement(i)){ee("text",`Text inside <Select> or <OptGroup> is ignored ("${String(i).slice(0,30)}"). Wrap it in <Option>.`);return}const a=`${s}-${String(i.key).slice(1).replace(/[:$]/g,u=>u===":"?"-":"k").replace(/[^\p{L}\p{N}-]/gu,"")}`,c=i.type?.racKind;if(i.type===o.Fragment)be(i.props.children,t,n,a,r);else if(c==="option")r.push(Fn(i.props,a,n));else if(c==="define")be(i.type.racRender(i.props),t,n,a,r);else if(c==="group"){const u=Pn(i.props,t);r.push(u),be(i.props.children,t,u.group,a,r)}else{const u=Hn(i.type);ee(`child ${u}`,`${u} inside <Select> is ignored: only <Option/>, <OptGroup/> and defineOption() components are read. Put custom content inside <Option>, or wrap the component with defineOption().`)}}),r),Vn=new Set(["ref","options","value","defaultValue","onChange","children","loadMore","open","onOpenChange","onFocus","onBlur","onKeyDown","childrenFirst","groupsClosed","disabled","loading","error"]),zn=/^(aria|data)-/,Me={options:[],value:void 0,defaultValue:void 0,onChange:void 0,multiple:!1,childrenFirst:!1,groupsClosed:!1,disabled:!1,loading:!1,error:!1,open:void 0,onOpenChange:void 0,popup:!0,onFocus:void 0,onBlur:void 0,onKeyDown:void 0,id:void 0,name:void 0,form:void 0,required:!1,hasMore:!1,loadMore:void 0,loadButton:!1,loadOffset:100,loadAhead:3,placeholder:"Choose option",selectedText:void 0,texts:{empty:"No options",disabled:"Disabled",loading:"Loading",error:"Failed to load",clear:"Clear selection",remove:"Remove",loadMore:"Load more",loadingMore:"Loading",emptyOption:"Empty option",invalidOption:"Invalid option",disabledOption:"Disabled option",emptyGroup:"Empty group",groupOpen:"expanded",groupClosed:"collapsed",list:"Options",required:void 0,removed:"Removed {label}",cleared:"Selection cleared",selected:"{n} selected",loaded:"{n} more options loaded"},renderOption:void 0,valueAsOption:!1,icons:{arrow:he.ArrowUp,clear:he.XMark,remove:he.XMark,check:he.Checkmark,checkbox:void 0},deleteInline:!1,deleteAlways:!1,className:"",optionsClassName:"",style:{},container:void 0,duration:300,easing:"ease",offset:1,animateOpacity:!0,keepMounted:!1},it={visibility:"open",setVisibility:"onOpenChange",ownBehavior:"open without onOpenChange",onOpen:"onOpenChange",onClose:"onOpenChange",unmount:"keepMounted (inverted)",showDelete:"deleteAlways",OpenIcon:"icons.arrow",ClearIcon:"icons.clear",DelIcon:"icons.remove",Checkmark:"icons.check",Checkbox:"icons.checkbox",emptyText:"texts.empty",disabledText:"texts.disabled",loadingText:"texts.loading",errorText:"texts.error",clearText:"texts.clear",removeText:"texts.remove",loadButtonText:"texts.loadMore",loadMoreText:"texts.loadingMore",emptyOption:"texts.emptyOption",invalidOption:"texts.invalidOption",disabledOption:"texts.disabledOption"},Ie=(e,t)=>{const n={...e};for(const s in t)t[s]!==void 0&&(n[s]=t[s]);return n};function qn(e){for(const d in e)d in it&&ee(`renamed ${d}`,`The \`${d}\` prop was removed. Use \`${it[d]}\`.`);e.value!==void 0&&!e.onChange&&ee("read-only value","`value` is set without `onChange`, so the Select is read-only. Pass `onChange`, or `defaultValue` instead of `value`.");const t=Ie(Me,e);t.texts=Ie(Me.texts,e.texts),t.icons=Ie(Me.icons,e.icons);const n=t.texts.emptyGroup,s=$e(o.useMemo(()=>be(t.children,n),[t.children,n])),{selectId:r,selectRef:i,highlightStore:a,state:c,actions:u}=Dn(t,s),y={},f={};for(const d in t)Vn.has(d)||((zn.test(d)?f:y)[d]=t[d]);const O=It({...y,attrs:f,selectId:r,selectRef:i,highlightStore:a});return E.jsx(Y.Provider,{value:O,children:E.jsx(ne.Provider,{value:u,children:E.jsxs(se.Provider,{value:c,children:[E.jsx(mn,{}),E.jsx(jn,{}),E.jsx(An,{})]})})})}function St(){return ee("option outside","<Option/> was rendered outside <Select>, or inside a component that <Select> cannot read. Use it as a direct child, or wrap the component with defineOption()."),null}St.racKind="option";function Ct(){return null}Ct.racKind="group";exports.OptGroup=Ct;exports.Option=St;exports.Select=qn;exports.defineOption=Wt;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./select.cjs"),i=require("./model.cjs"),t=require("./chip.cjs"),n=require("./paging.cjs");exports.OptGroup=e.OptGroup;exports.Option=e.Option;exports.Select=e.Select;exports.defineOption=i.defineOption;exports.chips=t.chips;exports.paging=n.paging;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {FC, FunctionComponent, ReactNode, CSSProperties, ElementType, Ref, FocusEvent, AriaAttributes} from 'react'
|
|
1
|
+
import {FC, FunctionComponent, ReactNode, CSSProperties, ElementType, Ref, FocusEvent, KeyboardEvent, AriaAttributes} from 'react'
|
|
2
|
+
|
|
3
|
+
/** Live region message: a template with {label} / {n}, or a function for plural forms. */
|
|
4
|
+
export type LiveText = string | ((value: string | number) => string)
|
|
2
5
|
|
|
3
6
|
export interface SelectTexts {
|
|
4
7
|
empty: string
|
|
@@ -13,7 +16,21 @@ export interface SelectTexts {
|
|
|
13
16
|
invalidOption: string
|
|
14
17
|
disabledOption: string
|
|
15
18
|
emptyGroup: string
|
|
19
|
+
/** State word in a group header's accessible name. Default `'expanded'`. */
|
|
20
|
+
groupOpen: string
|
|
21
|
+
/** State word in a group header's accessible name. Default `'collapsed'`. */
|
|
22
|
+
groupClosed: string
|
|
16
23
|
list: string
|
|
24
|
+
/** Validation bubble text of an empty required Select; default: the browser's own. */
|
|
25
|
+
required?: string
|
|
26
|
+
/** Default `'Removed {label}'`. */
|
|
27
|
+
removed?: LiveText
|
|
28
|
+
/** Default `'Selection cleared'`. */
|
|
29
|
+
cleared?: LiveText
|
|
30
|
+
/** Default `'{n} selected'`. */
|
|
31
|
+
selected?: LiveText
|
|
32
|
+
/** Default `'{n} more options loaded'`. */
|
|
33
|
+
loaded?: LiveText
|
|
17
34
|
}
|
|
18
35
|
|
|
19
36
|
export type SelectIcon = ElementType | string | ReactNode | null | false
|
|
@@ -32,9 +49,13 @@ export interface SelectProps extends AriaAttributes {
|
|
|
32
49
|
ref?: Ref<HTMLDivElement>
|
|
33
50
|
children?: ReactNode
|
|
34
51
|
|
|
52
|
+
/** A dictionary's values are the options, keys ignored; a key named name/label/id/value makes it one option, options/group a group. Array items take no className/style (use <Option/>). */
|
|
35
53
|
options?: any[] | Record<string, any>
|
|
54
|
+
/** undefined = uncontrolled; keep one mode, clear a controlled Select with null / [] (a switch warns in dev). */
|
|
36
55
|
value?: any
|
|
56
|
+
/** Initial value of an uncontrolled Select; also the target of form.reset(), in both modes, with or without name. */
|
|
37
57
|
defaultValue?: any
|
|
58
|
+
/** value: an array item as given (an object stays the whole object), an <Option/> as its `value`; a controlled value must have the shape of its source. */
|
|
38
59
|
onChange?: (value: any, ids: any) => void
|
|
39
60
|
multiple?: boolean
|
|
40
61
|
childrenFirst?: boolean
|
|
@@ -46,11 +67,17 @@ export interface SelectProps extends AriaAttributes {
|
|
|
46
67
|
|
|
47
68
|
open?: boolean
|
|
48
69
|
onOpenChange?: (open: boolean) => void
|
|
70
|
+
/** false: no panel, a tag list: role="group" without the combobox ARIA, never opens, no arrow; chip deletion and clear keep working. Default true. */
|
|
71
|
+
popup?: boolean
|
|
49
72
|
onFocus?: (e: FocusEvent<HTMLDivElement>) => void
|
|
50
73
|
onBlur?: (e: FocusEvent<HTMLDivElement>) => void
|
|
74
|
+
/** Runs before the Select handles a key; event.preventDefault() makes the Select skip it. */
|
|
75
|
+
onKeyDown?: (event: KeyboardEvent<HTMLDivElement>) => void
|
|
51
76
|
|
|
52
77
|
id?: string
|
|
53
78
|
name?: string
|
|
79
|
+
/** Id of the owner <form>, like <select form="id">: submits and resets with it even when placed outside. */
|
|
80
|
+
form?: string
|
|
54
81
|
required?: boolean
|
|
55
82
|
|
|
56
83
|
hasMore?: boolean
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { OptGroup as p, Option as r, Select as t } from "./select.js";
|
|
3
|
+
import { defineOption as f } from "./model.js";
|
|
4
|
+
import { chips as m } from "./chip.js";
|
|
5
|
+
import { paging as c } from "./paging.js";
|
|
6
|
+
export {
|
|
7
|
+
p as OptGroup,
|
|
8
|
+
r as Option,
|
|
9
|
+
t as Select,
|
|
10
|
+
m as chips,
|
|
11
|
+
f as defineOption,
|
|
12
|
+
c as paging
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("react/jsx-runtime"),E=require("./state.cjs"),r=require("react"),M=250,N=5e3,O=[],q=()=>()=>{},o=(i,t)=>typeof i=="function"?i(t):String(i??"").replace(/\{(n|label)\}/g,()=>t),I=(i,t,c,a)=>{const s=[];if(i.picked.length&&!t.picked.length)s.push(o(c.cleared));else if(a){const l=new Set(t.picked.map(n=>n.id)),d=new Set(i.picked.map(n=>n.id)),u=i.picked.filter(n=>!l.has(n.id));u.length&&s.push(o(c.removed,u.map(n=>n.name).join(", "))),t.picked.some(n=>!d.has(n.id))&&s.push(o(c.selected,t.picked.length))}return t.open&&i.count&&t.count>i.count&&s.push(o(c.loaded,t.count-i.count)),t.error&&!i.error&&s.push(o(c.error)),s.filter(Boolean).join(". ")},B=r.memo(function(){const{selectRef:t,selectId:c,multiple:a,texts:s}=r.useContext(E.SelectConfigContext),{selected:l,selectedIDs:d,normalizedOptions:u,visibility:n,deleting:k,error:m}=r.useContext(E.SelectStateContext),b=r.useSyncExternalStore(q,()=>!0,()=>!1),[j,v]=r.useState(""),f=r.useRef({base:null,timer:0,wipe:0,latest:null}),S=r.useMemo(()=>u.reduce((e,g)=>"original"in g?e+1:e,0),[u]);return r.useEffect(()=>{const e=a?d:l?[l]:O;f.current.latest={snap:{picked:e,count:S,open:n,error:!!m},texts:s,multiple:a,deleting:k}}),r.useEffect(()=>{const e=f.current,{snap:g,deleting:T}=e.latest;if(!e.base||!e.timer&&!T&&!t.current?.contains(document.activeElement)){e.base=g;return}clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=0;const{snap:x,texts:C,multiple:R}=e.latest,p=I(e.base,x,C,R);e.base=x,p&&(v(y=>y===p?`${p} `:p),clearTimeout(e.wipe),e.wipe=setTimeout(()=>v(""),N))},M)},[l,d,S,m,t]),r.useEffect(()=>{const e=f.current;return()=>{clearTimeout(e.timer),clearTimeout(e.wipe)}},[]),b?h.jsxs("div",{className:"rac-live",children:[h.jsx("div",{"aria-live":"polite","aria-atomic":"true",children:j}),m&&h.jsx("div",{id:`${c}-error`,children:o(s.error)})]}):null});exports.default=B;
|