react-animated-select 0.7.5 → 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 -1096
package/dist/model.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=["group","disabled","options","items","children"],K=["name","label","id","value"],E=e=>e!=null&&e!=="",V=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),P=e=>V(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),R=e=>{try{const r=String(e);return r.startsWith("[object ")?null:r}catch{return null}},J=(e,r=!1)=>{if(r&&typeof e.group=="string")return e.group;const p=K.find(u=>E(e[u]));if(p)return String(e[p]);const l=!P(e)&&R(e);if(l)return l;const i=Object.entries(e).find(([u,b])=>!z.includes(u)&&E(b));return i?String(i[1]):null},C=e=>P(e)&&("options"in e||"group"in e&&!K.some(r=>r in e)),k=(e,r,p,l,i,{emptyOption:u,invalidOption:b,disabledOption:$})=>{const a=`${p}-${r}`;if(e==null||e==="")return{id:a,userId:null,name:u,raw:e,disabled:!0,type:"normal",group:l,groupDisabled:i};if(typeof e=="function")return{id:a,userId:null,name:b,raw:e,disabled:!0,invalid:!0,type:"normal",group:l};if(V(e)){const o=i||e.disabled===!0,s=e.value!==void 0?e.value:e.id!==void 0?e.id:e,y=J(e)||(o?$:u);return{id:a,userId:e.id??e.value??e.name??e.label,name:y,raw:s,original:e,disabled:o||y===u,type:typeof s=="boolean"?"boolean":"normal",group:l||e.group||null,groupDisabled:i}}return{id:a,userId:e,name:String(e),raw:e,original:e,disabled:i,type:typeof e=="boolean"?"boolean":"normal",group:l}},D=({options:e,jsxOptions:r,childrenFirst:p,tail:l,emptyOption:i,invalidOption:u,disabledOption:b,emptyGroup:$})=>{const a={emptyOption:i,invalidOption:u,disabledOption:b},o=new Map,s=[],y=new Set,h=n=>{let t=n;for(let f=1;y.has(t);f++)t=`${n}~${f}`;return y.add(t),t},O=r.map((n,t)=>{if(n.isGroupMarker)return{...n,type:"group-marker"};const f=!n.label&&!E(n.userId)&&!E(n.value)&&!n.hasJsx;return{...n,id:h(`jsx-${n.id}`),index:t,userId:n.userId,raw:n.value,original:n.value,name:n.label||(E(n.value)?String(n.value):i),disabled:!!n.disabled||f,type:typeof n.value=="boolean"?"boolean":"normal",group:n.group||null}});let S=0;const x=(n,t=null,f=!1,G="0")=>{Array.isArray(n)||(n=[n]),n.forEach((d,Y)=>{const j=`${G}-${Y}`;if(C(d)){const g=J(d,!0)||$;o.has(g)||o.set(g,{disabled:!!d.disabled,items:[]}),d.options?x(d.options,g,f||!!d.disabled,j):s.push({id:`empty-${g}-${j}`,name:g,group:g,isPlaceholder:!0,type:"group-marker",index:S++})}else P(d)&&!K.some(g=>g in d)&&!d.group?Object.values(d).forEach((g,_)=>s.push({...k(g,`${j}-${_}`,"default",t,f,a),index:S++})):s.push({...k(d,j,"default",t,f,a),index:S++})})};x(e);const N=p?[...O,...s]:[...s,...O],c=[],L=new Set;N.forEach(n=>{if(!n.group){c.push({type:"item",data:n});return}L.has(n.group)||(L.add(n.group),c.push({type:"group",name:n.group})),o.has(n.group)||o.set(n.group,{items:[]});const t=o.get(n.group);n.isGroupMarker?(t.className=n.className,t.style=n.style,n.disabled&&(t.disabled=!0)):n.isPlaceholder||t.items.push(n)});const A=[];return c.forEach(n=>{if(n.type==="item"){A.push(n.data);return}const t=o.get(n.name);A.push({className:t?.className||"",id:`group-header-${n.name}`,disabled:!!t?.disabled,style:t?.style||{},groupHeader:!0,name:n.name,type:"group"}),t?.items.forEach(f=>A.push(f))}),l&&A.push(l),A},H=e=>{const r=()=>null;return r.racKind="define",r.racRender=e,r.displayName=`defineOption(${e.name||"anonymous"})`,r},T={selected:null,selectedIDs:[]},m=e=>{try{return JSON.stringify(e)}catch{return}},B=(e,r)=>e===r||e!==e&&r!==r,M=e=>typeof e=="object"&&e!==null,W=(e,r)=>B(e,r)||M(e)&&M(r)&&m(e)!==void 0&&m(e)===m(r),q=(e,r,p,l)=>{if(e==null||Array.isArray(e)&&e.length===0)return T;const i=l.length?new Map(r.map(s=>[s.id,s])):null,u=i?[...l.map(s=>i.get(s)).filter(Boolean),...r]:r,b=new Set,$=new Map,a=s=>"original"in s&&!b.has(s.id),o=s=>{const y=M(s);let h=u.find(c=>a(c)&&B(c.original,s));const O=y?m(s):void 0;if(!h&&O!==void 0&&(h=u.find(c=>a(c)&&M(c.original)&&m(c.original)===O)),h)return b.add(h.id),h;const S=String(y?s.id||s.value||O||"object":s),x=($.get(S)??-1)+1;$.set(S,x);const N=`virtual-${S}-${x}`;return y?{id:N,name:J(s)||String(s.id||"Selected Object"),raw:s.value??s.id??s,original:s,userId:s.id??s.value??null,virtual:!0}:{id:N,name:String(s),raw:s,original:s,userId:s,virtual:!0}};return p?{selected:null,selectedIDs:(Array.isArray(e)?e:[e]).map(o)}:{selected:o(Array.isArray(e)?e[0]:e),selectedIDs:T.selectedIDs}};exports.defineOption=H;exports.getLabel=J;exports.isPlain=P;exports.normalizeOptions=D;exports.resolveSelection=q;exports.sameValue=W;exports.toJSON=m;
|
package/dist/model.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const R = ["group", "disabled", "options", "items", "children"], K = ["name", "label", "id", "value"], N = (e) => e != null && e !== "", G = (e) => e !== null && typeof e == "object" && !Array.isArray(e), k = (e) => G(e) && [Object.prototype, null].includes(Object.getPrototypeOf(e)), z = (e) => {
|
|
3
|
+
try {
|
|
4
|
+
const r = String(e);
|
|
5
|
+
return r.startsWith("[object ") ? null : r;
|
|
6
|
+
} catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
}, J = (e, r = !1) => {
|
|
10
|
+
if (r && typeof e.group == "string") return e.group;
|
|
11
|
+
const p = K.find((u) => N(e[u]));
|
|
12
|
+
if (p) return String(e[p]);
|
|
13
|
+
const l = !k(e) && z(e);
|
|
14
|
+
if (l) return l;
|
|
15
|
+
const i = Object.entries(e).find(([u, h]) => !R.includes(u) && N(h));
|
|
16
|
+
return i ? String(i[1]) : null;
|
|
17
|
+
}, C = (e) => k(e) && ("options" in e || "group" in e && !K.some((r) => r in e)), P = (e, r, p, l, i, { emptyOption: u, invalidOption: h, disabledOption: $ }) => {
|
|
18
|
+
const a = `${p}-${r}`;
|
|
19
|
+
if (e == null || e === "")
|
|
20
|
+
return { id: a, userId: null, name: u, raw: e, disabled: !0, type: "normal", group: l, groupDisabled: i };
|
|
21
|
+
if (typeof e == "function")
|
|
22
|
+
return { id: a, userId: null, name: h, raw: e, disabled: !0, invalid: !0, type: "normal", group: l };
|
|
23
|
+
if (G(e)) {
|
|
24
|
+
const d = i || e.disabled === !0, s = e.value !== void 0 ? e.value : e.id !== void 0 ? e.id : e, y = J(e) || (d ? $ : u);
|
|
25
|
+
return {
|
|
26
|
+
id: a,
|
|
27
|
+
userId: e.id ?? e.value ?? e.name ?? e.label,
|
|
28
|
+
name: y,
|
|
29
|
+
raw: s,
|
|
30
|
+
original: e,
|
|
31
|
+
disabled: d || y === u,
|
|
32
|
+
type: typeof s == "boolean" ? "boolean" : "normal",
|
|
33
|
+
group: l || e.group || null,
|
|
34
|
+
groupDisabled: i
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return { id: a, userId: e, name: String(e), raw: e, original: e, disabled: i, type: typeof e == "boolean" ? "boolean" : "normal", group: l };
|
|
38
|
+
}, D = ({
|
|
39
|
+
options: e,
|
|
40
|
+
jsxOptions: r,
|
|
41
|
+
childrenFirst: p,
|
|
42
|
+
tail: l,
|
|
43
|
+
emptyOption: i,
|
|
44
|
+
invalidOption: u,
|
|
45
|
+
disabledOption: h,
|
|
46
|
+
emptyGroup: $
|
|
47
|
+
}) => {
|
|
48
|
+
const a = { emptyOption: i, invalidOption: u, disabledOption: h }, d = /* @__PURE__ */ new Map(), s = [], y = /* @__PURE__ */ new Set(), b = (n) => {
|
|
49
|
+
let t = n;
|
|
50
|
+
for (let f = 1; y.has(t); f++) t = `${n}~${f}`;
|
|
51
|
+
return y.add(t), t;
|
|
52
|
+
}, x = r.map((n, t) => {
|
|
53
|
+
if (n.isGroupMarker) return { ...n, type: "group-marker" };
|
|
54
|
+
const f = !n.label && !N(n.userId) && !N(n.value) && !n.hasJsx;
|
|
55
|
+
return {
|
|
56
|
+
...n,
|
|
57
|
+
id: b(`jsx-${n.id}`),
|
|
58
|
+
index: t,
|
|
59
|
+
userId: n.userId,
|
|
60
|
+
raw: n.value,
|
|
61
|
+
original: n.value,
|
|
62
|
+
name: n.label || (N(n.value) ? String(n.value) : i),
|
|
63
|
+
disabled: !!n.disabled || f,
|
|
64
|
+
type: typeof n.value == "boolean" ? "boolean" : "normal",
|
|
65
|
+
group: n.group || null
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
let S = 0;
|
|
69
|
+
const A = (n, t = null, f = !1, V = "0") => {
|
|
70
|
+
Array.isArray(n) || (n = [n]), n.forEach((o, Y) => {
|
|
71
|
+
const j = `${V}-${Y}`;
|
|
72
|
+
if (C(o)) {
|
|
73
|
+
const g = J(o, !0) || $;
|
|
74
|
+
d.has(g) || d.set(g, { disabled: !!o.disabled, items: [] }), o.options ? A(o.options, g, f || !!o.disabled, j) : s.push({ id: `empty-${g}-${j}`, name: g, group: g, isPlaceholder: !0, type: "group-marker", index: S++ });
|
|
75
|
+
} else k(o) && !K.some((g) => g in o) && !o.group ? Object.values(o).forEach((g, _) => s.push({ ...P(g, `${j}-${_}`, "default", t, f, a), index: S++ })) : s.push({ ...P(o, j, "default", t, f, a), index: S++ });
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
A(e);
|
|
79
|
+
const m = p ? [...x, ...s] : [...s, ...x], c = [], L = /* @__PURE__ */ new Set();
|
|
80
|
+
m.forEach((n) => {
|
|
81
|
+
if (!n.group) {
|
|
82
|
+
c.push({ type: "item", data: n });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
L.has(n.group) || (L.add(n.group), c.push({ type: "group", name: n.group })), d.has(n.group) || d.set(n.group, { items: [] });
|
|
86
|
+
const t = d.get(n.group);
|
|
87
|
+
n.isGroupMarker ? (t.className = n.className, t.style = n.style, n.disabled && (t.disabled = !0)) : n.isPlaceholder || t.items.push(n);
|
|
88
|
+
});
|
|
89
|
+
const E = [];
|
|
90
|
+
return c.forEach((n) => {
|
|
91
|
+
if (n.type === "item") {
|
|
92
|
+
E.push(n.data);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const t = d.get(n.name);
|
|
96
|
+
E.push({
|
|
97
|
+
className: t?.className || "",
|
|
98
|
+
id: `group-header-${n.name}`,
|
|
99
|
+
disabled: !!t?.disabled,
|
|
100
|
+
style: t?.style || {},
|
|
101
|
+
groupHeader: !0,
|
|
102
|
+
name: n.name,
|
|
103
|
+
type: "group"
|
|
104
|
+
}), t?.items.forEach((f) => E.push(f));
|
|
105
|
+
}), l && E.push(l), E;
|
|
106
|
+
}, H = (e) => {
|
|
107
|
+
const r = () => null;
|
|
108
|
+
return r.racKind = "define", r.racRender = e, r.displayName = `defineOption(${e.name || "anonymous"})`, r;
|
|
109
|
+
}, B = { selected: null, selectedIDs: [] }, O = (e) => {
|
|
110
|
+
try {
|
|
111
|
+
return JSON.stringify(e);
|
|
112
|
+
} catch {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}, T = (e, r) => e === r || e !== e && r !== r, M = (e) => typeof e == "object" && e !== null, W = (e, r) => T(e, r) || M(e) && M(r) && O(e) !== void 0 && O(e) === O(r), q = (e, r, p, l) => {
|
|
116
|
+
if (e == null || Array.isArray(e) && e.length === 0) return B;
|
|
117
|
+
const i = l.length ? new Map(r.map((s) => [s.id, s])) : null, u = i ? [...l.map((s) => i.get(s)).filter(Boolean), ...r] : r, h = /* @__PURE__ */ new Set(), $ = /* @__PURE__ */ new Map(), a = (s) => "original" in s && !h.has(s.id), d = (s) => {
|
|
118
|
+
const y = M(s);
|
|
119
|
+
let b = u.find((c) => a(c) && T(c.original, s));
|
|
120
|
+
const x = y ? O(s) : void 0;
|
|
121
|
+
if (!b && x !== void 0 && (b = u.find((c) => a(c) && M(c.original) && O(c.original) === x)), b)
|
|
122
|
+
return h.add(b.id), b;
|
|
123
|
+
const S = String(y ? s.id || s.value || x || "object" : s), A = ($.get(S) ?? -1) + 1;
|
|
124
|
+
$.set(S, A);
|
|
125
|
+
const m = `virtual-${S}-${A}`;
|
|
126
|
+
return y ? { id: m, name: J(s) || String(s.id || "Selected Object"), raw: s.value ?? s.id ?? s, original: s, userId: s.id ?? s.value ?? null, virtual: !0 } : { id: m, name: String(s), raw: s, original: s, userId: s, virtual: !0 };
|
|
127
|
+
};
|
|
128
|
+
return p ? { selected: null, selectedIDs: (Array.isArray(e) ? e : [e]).map(d) } : { selected: d(Array.isArray(e) ? e[0] : e), selectedIDs: B.selectedIDs };
|
|
129
|
+
};
|
|
130
|
+
export {
|
|
131
|
+
H as defineOption,
|
|
132
|
+
J as getLabel,
|
|
133
|
+
k as isPlain,
|
|
134
|
+
D as normalizeOptions,
|
|
135
|
+
q as resolveSelection,
|
|
136
|
+
W as sameValue,
|
|
137
|
+
O as toJSON
|
|
138
|
+
};
|
package/dist/motion.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("react/jsx-runtime"),r=require("react"),Q=require("./state.cjs"),G={x:["width","marginLeft","marginRight","paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"],y:["height","marginTop","marginBottom","paddingTop","paddingBottom","borderTopWidth","borderBottomWidth"]},U={x:{minWidth:"0px",maxWidth:"none"},y:{minHeight:"0px",maxHeight:"none"}},$=r.createContext(null);let B=null;const Y=()=>B??=(queueMicrotask(()=>{B=null}),{});function Z({as:c="div",axis:n="y",fade:g=!1,in:f,unmountOnExit:i=!0,easing:s,duration:x,group:t,nodeRef:u,onEntered:l,onExited:S,...C}){const e=r.useContext(Q.SelectConfigContext),y=r.useContext($),R=f===void 0&&!!y,h=R?y.present:!!f,I=x??(e?.duration??300)/(R&&y.swap?2:1),O=s??e?.easing??"ease",D=r.useRef(null),T=u??D,d=r.useRef(null),j=r.useRef(!1),w=r.useRef({restart:()=>{}}),[J]=r.useState(()=>R&&y.appear?!h:h),E=r.useRef(J),[A,H]=r.useState(!h);h&&A&&H(!1);const z=r.useEffectEvent(()=>{if(t?.delete(w.current),h){d.current?.cancel(),d.current=null,l?.();return}S?.(),R&&y.onExited(),i&&(d.current=null,H(!0))});if(r.useLayoutEffect(()=>{const a=T.current;if(!a)return;const L=g?[...G[n],"opacity"]:G[n],M={overflow:"hidden",textOverflow:"clip",...U[n]},v={...Object.fromEntries(L.map(o=>[o,o==="opacity"?0:"0px"])),...M},P=()=>{const{overflow:o}=a.style;a.style.overflow="hidden";const b=getComputedStyle(a),k={...Object.fromEntries(L.map(p=>[p,b[p]])),...M};return a.style.overflow=o,k},W=(o,b)=>{const k=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,p=d.current=a.animate([o,b],{duration:k?0:I,easing:O,fill:E.current?"backwards":"both"});if(p.onfinish=()=>{d.current===p&&j.current&&z()},w.current.frames=[o,b],!t)return;const m=p.timeline?.currentTime;m!=null&&(p.startTime=m,p.currentTime=0),w.current.batch=Y(),t.add(w.current)},N=()=>{const[o,b]=w.current.frames,k=d.current.effect.getComputedTiming().progress??0,p=m=>parseFloat(o[m])+(parseFloat(b[m])-parseFloat(o[m]))*k;return{...Object.fromEntries(L.map(m=>[m,m==="opacity"?p(m):`${p(m)}px`])),...M}};if(w.current.restart=o=>{const b=d.current;if(b?.playState!=="running"||!o&&w.current.batch===B)return;const k=N();b.cancel(),W(k,E.current?P():v)},E.current===h){!h&&d.current?.effect?.target!==a&&a.animate&&(d.current=a.animate([v,v],{fill:"forwards"}));return}E.current=h;const q=d.current;if(q?.playState==="running"){if(!t){q.reverse();return}w.current.restart(!0)}else{if(q?.cancel(),!a.animate){z();return}h?W(v,P()):W(P(),v)}t?.forEach(o=>o!==w.current&&o.restart())},[h,i,n,g,I,O,T,t]),r.useLayoutEffect(()=>{const a=w.current;return j.current=!0,d.current?.playState==="running"&&t?.add(a),()=>{j.current=!1,t?.delete(a)}},[t]),A&&i)return null;const K=c;return F.jsx(K,{ref:T,...C})}const _=({id:c,present:n,appear:g,swap:f,onExited:i,children:s})=>{const x=r.useMemo(()=>({present:n,appear:g,swap:f,onExited:()=>i(c)}),[c,n,g,f,i]);return F.jsx($.Provider,{value:x,children:s})},V=(c,n,g,f=!0)=>{const i=r.Children.toArray(n).filter(r.isValidElement),s=new Set(i.map(e=>e.key)),x=new Map(c.map(e=>[e.key,e])),t=i.map(e=>({key:e.key,el:e,present:!0,appear:x.get(e.key)?.appear??f}));let u=0;const l=new Set;c.forEach(e=>{if(s.has(e.key))e.present&&(u=t.findIndex(y=>y.key===e.key)+1);else if(!e.pending){const y=e.present?{...e,present:!1,swap:!1}:e;e.present&&l.add(y),t.splice(u++,0,y)}});const S=e=>e.present&&(x.get(e.key)?.pending??!x.has(e.key)),C=g&&(l.size>0||c.some(e=>e.pending))&&t.some(e=>!e.present)&&t.some(S);return{children:n,list:C?t.map(e=>l.has(e)?{...e,swap:!0}:S(e)?{...e,pending:!0,swap:!0}:e):t}},X=c=>c.some(n=>!n.present)?c:c.map(n=>n.pending?{...n,pending:!1}:n);function ee({children:c,hold:n=!1,wait:g=!1}){const[f,i]=r.useState(()=>({...V([],c,g,!1),hold:n}));let s=f;s.children!==c&&(s={...s,...V(s.list,c,g)}),s.hold!==n&&(s={...s,hold:n,list:n?s.list:X(s.list.filter(t=>t.present))}),s!==f&&i(s);const x=r.useCallback(t=>i(u=>!u.hold&&u.list.some(l=>l.key===t&&!l.present)?{...u,list:X(u.list.filter(l=>l.key!==t))}:u),[]);return f.list.map(({key:t,el:u,present:l,appear:S,pending:C,swap:e=!1})=>!C&&F.jsx(_,{id:t,present:l,appear:S,swap:e,onExited:x,children:u},t))}exports.Collapse=Z;exports.Presence=ee;
|
package/dist/motion.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as A } from "react/jsx-runtime";
|
|
3
|
+
import { useState as F, useCallback as Y, useContext as V, createContext as Z, useRef as S, useEffectEvent as _, useLayoutEffect as X, Children as ee, isValidElement as te, useMemo as ne } from "react";
|
|
4
|
+
import { SelectConfigContext as re } from "./state.js";
|
|
5
|
+
const $ = {
|
|
6
|
+
x: ["width", "marginLeft", "marginRight", "paddingLeft", "paddingRight", "borderLeftWidth", "borderRightWidth"],
|
|
7
|
+
y: ["height", "marginTop", "marginBottom", "paddingTop", "paddingBottom", "borderTopWidth", "borderBottomWidth"]
|
|
8
|
+
}, se = { x: { minWidth: "0px", maxWidth: "none" }, y: { minHeight: "0px", maxHeight: "none" } }, K = /* @__PURE__ */ Z(null);
|
|
9
|
+
let I = null;
|
|
10
|
+
const oe = () => I ??= (queueMicrotask(() => {
|
|
11
|
+
I = null;
|
|
12
|
+
}), {});
|
|
13
|
+
function ue({
|
|
14
|
+
as: s = "div",
|
|
15
|
+
axis: n = "y",
|
|
16
|
+
fade: m = !1,
|
|
17
|
+
in: f,
|
|
18
|
+
unmountOnExit: a = !0,
|
|
19
|
+
easing: r,
|
|
20
|
+
duration: w,
|
|
21
|
+
group: t,
|
|
22
|
+
nodeRef: i,
|
|
23
|
+
onEntered: l,
|
|
24
|
+
onExited: k,
|
|
25
|
+
...v
|
|
26
|
+
}) {
|
|
27
|
+
const e = V(re), g = V(K), E = f === void 0 && !!g, h = E ? g.present : !!f, H = w ?? (e?.duration ?? 300) / (E && g.swap ? 2 : 1), O = r ?? e?.easing ?? "ease", N = S(null), R = i ?? N, u = S(null), W = S(!1), y = S({ restart: () => {
|
|
28
|
+
} }), [Q] = F(() => E && g.appear ? !h : h), T = S(Q), [q, z] = F(!h);
|
|
29
|
+
h && q && z(!1);
|
|
30
|
+
const G = _(() => {
|
|
31
|
+
if (t?.delete(y.current), h) {
|
|
32
|
+
u.current?.cancel(), u.current = null, l?.();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
k?.(), E && g.onExited(), a && (u.current = null, z(!0));
|
|
36
|
+
});
|
|
37
|
+
return X(() => {
|
|
38
|
+
const c = R.current;
|
|
39
|
+
if (!c) return;
|
|
40
|
+
const L = m ? [...$[n], "opacity"] : $[n], M = { overflow: "hidden", textOverflow: "clip", ...se[n] }, C = { ...Object.fromEntries(L.map((o) => [o, o === "opacity" ? 0 : "0px"])), ...M }, j = () => {
|
|
41
|
+
const { overflow: o } = c.style;
|
|
42
|
+
c.style.overflow = "hidden";
|
|
43
|
+
const b = getComputedStyle(c), x = { ...Object.fromEntries(L.map((d) => [d, b[d]])), ...M };
|
|
44
|
+
return c.style.overflow = o, x;
|
|
45
|
+
}, B = (o, b) => {
|
|
46
|
+
const x = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches, d = u.current = c.animate([o, b], { duration: x ? 0 : H, easing: O, fill: T.current ? "backwards" : "both" });
|
|
47
|
+
if (d.onfinish = () => {
|
|
48
|
+
u.current === d && W.current && G();
|
|
49
|
+
}, y.current.frames = [o, b], !t) return;
|
|
50
|
+
const p = d.timeline?.currentTime;
|
|
51
|
+
p != null && (d.startTime = p, d.currentTime = 0), y.current.batch = oe(), t.add(y.current);
|
|
52
|
+
}, U = () => {
|
|
53
|
+
const [o, b] = y.current.frames, x = u.current.effect.getComputedTiming().progress ?? 0, d = (p) => parseFloat(o[p]) + (parseFloat(b[p]) - parseFloat(o[p])) * x;
|
|
54
|
+
return { ...Object.fromEntries(L.map((p) => [p, p === "opacity" ? d(p) : `${d(p)}px`])), ...M };
|
|
55
|
+
};
|
|
56
|
+
if (y.current.restart = (o) => {
|
|
57
|
+
const b = u.current;
|
|
58
|
+
if (b?.playState !== "running" || !o && y.current.batch === I) return;
|
|
59
|
+
const x = U();
|
|
60
|
+
b.cancel(), B(x, T.current ? j() : C);
|
|
61
|
+
}, T.current === h) {
|
|
62
|
+
!h && u.current?.effect?.target !== c && c.animate && (u.current = c.animate([C, C], { fill: "forwards" }));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
T.current = h;
|
|
66
|
+
const P = u.current;
|
|
67
|
+
if (P?.playState === "running") {
|
|
68
|
+
if (!t) {
|
|
69
|
+
P.reverse();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
y.current.restart(!0);
|
|
73
|
+
} else {
|
|
74
|
+
if (P?.cancel(), !c.animate) {
|
|
75
|
+
G();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
h ? B(C, j()) : B(j(), C);
|
|
79
|
+
}
|
|
80
|
+
t?.forEach((o) => o !== y.current && o.restart());
|
|
81
|
+
}, [h, a, n, m, H, O, R, t]), X(() => {
|
|
82
|
+
const c = y.current;
|
|
83
|
+
return W.current = !0, u.current?.playState === "running" && t?.add(c), () => {
|
|
84
|
+
W.current = !1, t?.delete(c);
|
|
85
|
+
};
|
|
86
|
+
}, [t]), q && a ? null : /* @__PURE__ */ A(s, { ref: R, ...v });
|
|
87
|
+
}
|
|
88
|
+
const ce = ({ id: s, present: n, appear: m, swap: f, onExited: a, children: r }) => {
|
|
89
|
+
const w = ne(() => ({ present: n, appear: m, swap: f, onExited: () => a(s) }), [s, n, m, f, a]);
|
|
90
|
+
return /* @__PURE__ */ A(K.Provider, { value: w, children: r });
|
|
91
|
+
}, D = (s, n, m, f = !0) => {
|
|
92
|
+
const a = ee.toArray(n).filter(te), r = new Set(a.map((e) => e.key)), w = new Map(s.map((e) => [e.key, e])), t = a.map((e) => ({ key: e.key, el: e, present: !0, appear: w.get(e.key)?.appear ?? f }));
|
|
93
|
+
let i = 0;
|
|
94
|
+
const l = /* @__PURE__ */ new Set();
|
|
95
|
+
s.forEach((e) => {
|
|
96
|
+
if (r.has(e.key))
|
|
97
|
+
e.present && (i = t.findIndex((g) => g.key === e.key) + 1);
|
|
98
|
+
else if (!e.pending) {
|
|
99
|
+
const g = e.present ? { ...e, present: !1, swap: !1 } : e;
|
|
100
|
+
e.present && l.add(g), t.splice(i++, 0, g);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const k = (e) => e.present && (w.get(e.key)?.pending ?? !w.has(e.key)), v = m && (l.size > 0 || s.some((e) => e.pending)) && t.some((e) => !e.present) && t.some(k);
|
|
104
|
+
return { children: n, list: v ? t.map((e) => l.has(e) ? { ...e, swap: !0 } : k(e) ? { ...e, pending: !0, swap: !0 } : e) : t };
|
|
105
|
+
}, J = (s) => s.some((n) => !n.present) ? s : s.map((n) => n.pending ? { ...n, pending: !1 } : n);
|
|
106
|
+
function de({ children: s, hold: n = !1, wait: m = !1 }) {
|
|
107
|
+
const [f, a] = F(() => ({ ...D([], s, m, !1), hold: n }));
|
|
108
|
+
let r = f;
|
|
109
|
+
r.children !== s && (r = { ...r, ...D(r.list, s, m) }), r.hold !== n && (r = { ...r, hold: n, list: n ? r.list : J(r.list.filter((t) => t.present)) }), r !== f && a(r);
|
|
110
|
+
const w = Y((t) => a(
|
|
111
|
+
(i) => !i.hold && i.list.some((l) => l.key === t && !l.present) ? { ...i, list: J(i.list.filter((l) => l.key !== t)) } : i
|
|
112
|
+
), []);
|
|
113
|
+
return f.list.map(
|
|
114
|
+
({ key: t, el: i, present: l, appear: k, pending: v, swap: e = !1 }) => !v && /* @__PURE__ */ A(ce, { id: t, present: l, appear: k, swap: e, onExited: w, children: i }, t)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
ue as Collapse,
|
|
119
|
+
de as Presence
|
|
120
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react/jsx-runtime"),x=require("./state.cjs"),a=require("react"),H=require("./useSelectBehavior.cjs"),t=require("./utils.cjs"),p=require("./motion.cjs"),N=0,O=1,j=2,k=C=>{const{highlightStore:e}=a.useContext(x.SelectConfigContext),r=a.useRef(null),l=a.useSyncExternalStore(e.subscribe,()=>{const i=e.get();return H.effectiveHighlight(i)!==C?N:i.ready?j:O},()=>N);return a.useLayoutEffect(()=>{l===j&&r.current?.scrollIntoView?.({block:"nearest"})},[l]),[r,l!==N]},y=(C,e)=>`${t.optionDomId(C,e.id)}_l`,w=a.memo(function({option:e,index:r,open:l,hasChildren:i}){const{selectId:h,icons:d,texts:m}=a.useContext(x.SelectConfigContext),{selectOption:b,highlight:I}=a.useContext(x.SelectActionsContext),[u,g]=k(r),c=i&&!e.disabled;return n.jsxs("div",{className:t.withClass("rac-group",e.className),onMouseEnter:()=>c&&I(r),onClick:f=>b(e,f),"aria-label":c?`${e.name}, ${l?m.groupOpen:m.groupClosed}`:void 0,"aria-disabled":!c||void 0,"data-highlighted":t.flag(g),"data-disabled":t.flag(e.disabled),id:t.optionDomId(h,e.id),"data-open":t.flag(l),"aria-selected":"false",style:e.style,role:"option",ref:u,children:[n.jsx("span",{className:"rac-group-text",id:y(h,e),children:e.name}),n.jsx(p.Collapse,{axis:"x",in:i&&!e.disabled,className:"rac-group-arrow","aria-hidden":"true",children:t.renderIcon(d.arrow)})]})}),E=a.memo(function({option:e,index:r,isSelected:l,showCheckbox:i}){const{selectId:h,icons:d,renderOption:m}=a.useContext(x.SelectConfigContext),{selectOption:b,highlight:I}=a.useContext(x.SelectActionsContext),[u,g]=k(r),c=!e.disabled&&!e.loading,f=t.optionContent(e,m,l);return n.jsxs("div",{className:t.withClass("rac-option",e.className),onMouseEnter:()=>c&&I(r),onClick:S=>!e.loading&&b(e,S),"aria-disabled":e.disabled||e.loading,"data-invalid":t.flag(e.invalid),"data-bool":typeof e.raw=="boolean"?String(e.raw):void 0,"data-highlighted":t.flag(g),"data-loading":t.flag(e.loading),id:t.optionDomId(h,e.id),"aria-selected":l,style:e.style,role:"option",ref:u,children:[f?n.jsx("div",{className:"rac-option-jsx",children:f}):n.jsx("span",{className:"rac-option-text",children:e.name}),e.loading&&t.dots,i&&n.jsxs("div",{className:"rac-check","data-default":t.flag(!d.checkbox),children:[t.renderIcon(d.check,{className:"rac-checkmark"}),t.renderIcon(d.checkbox,{className:"rac-check-icon"})]})]})}),G=a.memo(function(){const{selectId:e,multiple:r}=a.useContext(x.SelectConfigContext),{normalizedOptions:l,selected:i,selectedIDs:h,expandedGroups:d}=a.useContext(x.SelectStateContext),m=i?.id;return a.useMemo(()=>{const b=new Set(h.map(s=>s.id)),I=l.reduce((s,o)=>(o.group&&(s[o.group]=(s[o.group]||0)+1),s),{}),u=[];let g=[],c=null,f=null;const S=()=>{c!==null&&g.length&&u.push(n.jsx(p.Collapse,{axis:"y",in:d.has(c),className:"rac-group-items",role:"group","aria-labelledby":f,children:g},`slide-${c}`)),g=[]},v=(s,o)=>n.jsx(E,{isSelected:b.has(s.id)||m===s.id,showCheckbox:r&&!s.disabled&&"original"in s,option:s,index:o},s.id);return l.forEach((s,o)=>{s.groupHeader?(S(),c=s.name,f=y(e,s),u.push(n.jsx(w,{hasChildren:I[s.name]>0,open:d.has(s.name),option:s,index:o},s.id))):s.group?g.push(v(s,o)):(S(),c=null,u.push(v(s,o)))}),S(),u},[l,m,h,d,r,e])});exports.default=G;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as m, jsxs as v } from "react/jsx-runtime";
|
|
3
|
+
import { SelectConfigContext as x, SelectStateContext as $, SelectActionsContext as E } from "./state.js";
|
|
4
|
+
import { memo as H, useContext as f, useMemo as j, useRef as M, useSyncExternalStore as A, useLayoutEffect as R } from "react";
|
|
5
|
+
import { effectiveHighlight as T } from "./useSelectBehavior.js";
|
|
6
|
+
import { optionDomId as y, flag as g, withClass as w, renderIcon as k, optionContent as _, dots as z } from "./utils.js";
|
|
7
|
+
import { Collapse as G } from "./motion.js";
|
|
8
|
+
const C = 0, V = 1, S = 2, L = (b) => {
|
|
9
|
+
const { highlightStore: e } = f(x), l = M(null), a = A(e.subscribe, () => {
|
|
10
|
+
const r = e.get();
|
|
11
|
+
return T(r) !== b ? C : r.ready ? S : V;
|
|
12
|
+
}, () => C);
|
|
13
|
+
return R(() => {
|
|
14
|
+
a === S && l.current?.scrollIntoView?.({ block: "nearest" });
|
|
15
|
+
}, [a]), [l, a !== C];
|
|
16
|
+
}, D = (b, e) => `${y(b, e.id)}_l`, Y = /* @__PURE__ */ H(function({ option: e, index: l, open: a, hasChildren: r }) {
|
|
17
|
+
const { selectId: o, icons: c, texts: u } = f(x), { selectOption: I, highlight: p } = f(E), [i, n] = L(l), t = r && !e.disabled;
|
|
18
|
+
return /* @__PURE__ */ v(
|
|
19
|
+
"div",
|
|
20
|
+
{
|
|
21
|
+
className: w("rac-group", e.className),
|
|
22
|
+
onMouseEnter: () => t && p(l),
|
|
23
|
+
onClick: (h) => I(e, h),
|
|
24
|
+
"aria-label": t ? `${e.name}, ${a ? u.groupOpen : u.groupClosed}` : void 0,
|
|
25
|
+
"aria-disabled": !t || void 0,
|
|
26
|
+
"data-highlighted": g(n),
|
|
27
|
+
"data-disabled": g(e.disabled),
|
|
28
|
+
id: y(o, e.id),
|
|
29
|
+
"data-open": g(a),
|
|
30
|
+
"aria-selected": "false",
|
|
31
|
+
style: e.style,
|
|
32
|
+
role: "option",
|
|
33
|
+
ref: i,
|
|
34
|
+
children: [
|
|
35
|
+
/* @__PURE__ */ m("span", { className: "rac-group-text", id: D(o, e), children: e.name }),
|
|
36
|
+
/* @__PURE__ */ m(G, { axis: "x", in: r && !e.disabled, className: "rac-group-arrow", "aria-hidden": "true", children: k(c.arrow) })
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
}), q = /* @__PURE__ */ H(function({ option: e, index: l, isSelected: a, showCheckbox: r }) {
|
|
41
|
+
const { selectId: o, icons: c, renderOption: u } = f(x), { selectOption: I, highlight: p } = f(E), [i, n] = L(l), t = !e.disabled && !e.loading, h = _(e, u, a);
|
|
42
|
+
return /* @__PURE__ */ v(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
className: w("rac-option", e.className),
|
|
46
|
+
onMouseEnter: () => t && p(l),
|
|
47
|
+
onClick: (N) => !e.loading && I(e, N),
|
|
48
|
+
"aria-disabled": e.disabled || e.loading,
|
|
49
|
+
"data-invalid": g(e.invalid),
|
|
50
|
+
"data-bool": typeof e.raw == "boolean" ? String(e.raw) : void 0,
|
|
51
|
+
"data-highlighted": g(n),
|
|
52
|
+
"data-loading": g(e.loading),
|
|
53
|
+
id: y(o, e.id),
|
|
54
|
+
"aria-selected": a,
|
|
55
|
+
style: e.style,
|
|
56
|
+
role: "option",
|
|
57
|
+
ref: i,
|
|
58
|
+
children: [
|
|
59
|
+
h ? /* @__PURE__ */ m("div", { className: "rac-option-jsx", children: h }) : /* @__PURE__ */ m("span", { className: "rac-option-text", children: e.name }),
|
|
60
|
+
e.loading && z,
|
|
61
|
+
r && /* @__PURE__ */ v("div", { className: "rac-check", "data-default": g(!c.checkbox), children: [
|
|
62
|
+
k(c.check, { className: "rac-checkmark" }),
|
|
63
|
+
k(c.checkbox, { className: "rac-check-icon" })
|
|
64
|
+
] })
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
}), U = /* @__PURE__ */ H(function() {
|
|
69
|
+
const { selectId: e, multiple: l } = f(x), { normalizedOptions: a, selected: r, selectedIDs: o, expandedGroups: c } = f($), u = r?.id;
|
|
70
|
+
return j(() => {
|
|
71
|
+
const I = new Set(o.map((s) => s.id)), p = a.reduce((s, d) => (d.group && (s[d.group] = (s[d.group] || 0) + 1), s), {}), i = [];
|
|
72
|
+
let n = [], t = null, h = null;
|
|
73
|
+
const N = () => {
|
|
74
|
+
t !== null && n.length && i.push(
|
|
75
|
+
/* @__PURE__ */ m(G, { axis: "y", in: c.has(t), className: "rac-group-items", role: "group", "aria-labelledby": h, children: n }, `slide-${t}`)
|
|
76
|
+
), n = [];
|
|
77
|
+
}, O = (s, d) => /* @__PURE__ */ m(
|
|
78
|
+
q,
|
|
79
|
+
{
|
|
80
|
+
isSelected: I.has(s.id) || u === s.id,
|
|
81
|
+
showCheckbox: l && !s.disabled && "original" in s,
|
|
82
|
+
option: s,
|
|
83
|
+
index: d
|
|
84
|
+
},
|
|
85
|
+
s.id
|
|
86
|
+
);
|
|
87
|
+
return a.forEach((s, d) => {
|
|
88
|
+
s.groupHeader ? (N(), t = s.name, h = D(e, s), i.push(
|
|
89
|
+
/* @__PURE__ */ m(
|
|
90
|
+
Y,
|
|
91
|
+
{
|
|
92
|
+
hasChildren: p[s.name] > 0,
|
|
93
|
+
open: c.has(s.name),
|
|
94
|
+
option: s,
|
|
95
|
+
index: d
|
|
96
|
+
},
|
|
97
|
+
s.id
|
|
98
|
+
)
|
|
99
|
+
)) : s.group ? n.push(O(s, d)) : (N(), t = null, i.push(O(s, d)));
|
|
100
|
+
}), N(), i;
|
|
101
|
+
}, [a, u, o, c, l, e]);
|
|
102
|
+
});
|
|
103
|
+
export {
|
|
104
|
+
U as default
|
|
105
|
+
};
|
package/dist/paging.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),e=require("react"),p=require("./state.cjs"),A=require("./useSelectBehavior.cjs"),H=require("./dropdown.cjs"),I=require("./utils.cjs"),L=({props:{hasMore:d,loadMore:n},lock:t,setPending:s})=>{if(!d||t.current)return;if(!n)return I.warnOnce("no loadMore","`hasMore` is set, but there is no `loadMore` to call.");t.current=!0,s(!0);const o=()=>s(!1);try{n()?.then?.(o,o)}catch(g){t.current=!1,o(),(globalThis.reportError??console.error)(g)}},P=({hasMore:d,loadButton:n,loadPending:t,moreText:s,pendingText:o})=>d&&n?{id:"special-load-more-id",name:t?o:s,loadMore:!0,loading:t,type:"special"}:null,q=e.memo(function(){const{highlightStore:n,hasMore:t,loadButton:s,loadOffset:o,loadAhead:g}=e.useContext(p.SelectConfigContext),{visibility:i,normalizedOptions:E,loadPending:M}=e.useContext(p.SelectStateContext),{loadMoreOnce:c}=e.useContext(p.SelectActionsContext),m=e.useRef(null),l=!s&&t,u=E.length,[h,O]=e.useState(u);!M&&h!==u&&O(u);const b=e.useSyncExternalStore(n.subscribe,()=>{const a=A.effectiveHighlight(n.get());return a>=u-g?a:null},()=>null);return e.useLayoutEffect(()=>{l&&b!==null&&i&&c()},[l,b,i,u,c]),e.useEffect(()=>{const a=m.current,r=l&&i&&a?.parentElement;if(!r||typeof IntersectionObserver>"u")return;let f=!1;const x=Number(o),v=Number.isFinite(x)?x:0,w=v-(parseFloat(getComputedStyle(r).paddingBottom)||0),S=new IntersectionObserver(F=>{const{isIntersecting:B,boundingClientRect:R,rootBounds:C}=F.at(-1);f=B&&!!C&&R.bottom<=C.bottom+.5,f&&c()},{root:r,rootMargin:`0px 0px ${w}px 0px`,threshold:[0,1]});S.observe(a);const y=()=>{f&&r.scrollHeight-r.scrollTop<=r.clientHeight+v&&c()};return r.addEventListener("scroll",y,{passive:!0}),()=>{S.disconnect(),r.removeEventListener("scroll",y)}},[l,i,o,h,c]),j.jsx(H.StatusRow,{ref:m,more:l})}),T={Footer:q,request:L,row:P};exports.PagingFooter=q;exports.paging=T;
|
package/dist/paging.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as B } from "react/jsx-runtime";
|
|
3
|
+
import { memo as H, useContext as p, useRef as I, useState as L, useSyncExternalStore as R, useLayoutEffect as N, useEffect as T } from "react";
|
|
4
|
+
import { SelectConfigContext as j, SelectStateContext as q, SelectActionsContext as z } from "./state.js";
|
|
5
|
+
import { effectiveHighlight as P } from "./useSelectBehavior.js";
|
|
6
|
+
import { StatusRow as $ } from "./dropdown.js";
|
|
7
|
+
import { warnOnce as D } from "./utils.js";
|
|
8
|
+
const G = ({ props: { hasMore: u, loadMore: r }, lock: e, setPending: n }) => {
|
|
9
|
+
if (!u || e.current) return;
|
|
10
|
+
if (!r) return D("no loadMore", "`hasMore` is set, but there is no `loadMore` to call.");
|
|
11
|
+
e.current = !0, n(!0);
|
|
12
|
+
const t = () => n(!1);
|
|
13
|
+
try {
|
|
14
|
+
r()?.then?.(t, t);
|
|
15
|
+
} catch (f) {
|
|
16
|
+
e.current = !1, t(), (globalThis.reportError ?? console.error)(f);
|
|
17
|
+
}
|
|
18
|
+
}, J = ({ hasMore: u, loadButton: r, loadPending: e, moreText: n, pendingText: t }) => u && r ? { id: "special-load-more-id", name: e ? t : n, loadMore: !0, loading: e, type: "special" } : null, K = /* @__PURE__ */ H(function() {
|
|
19
|
+
const { highlightStore: r, hasMore: e, loadButton: n, loadOffset: t, loadAhead: f } = p(j), { visibility: s, normalizedOptions: C, loadPending: E } = p(q), { loadMoreOnce: i } = p(z), d = I(null), c = !n && e, l = C.length, [g, M] = L(l);
|
|
20
|
+
!E && g !== l && M(l);
|
|
21
|
+
const h = R(r.subscribe, () => {
|
|
22
|
+
const a = P(r.get());
|
|
23
|
+
return a >= l - f ? a : null;
|
|
24
|
+
}, () => null);
|
|
25
|
+
return N(() => {
|
|
26
|
+
c && h !== null && s && i();
|
|
27
|
+
}, [c, h, s, l, i]), T(() => {
|
|
28
|
+
const a = d.current, o = c && s && a?.parentElement;
|
|
29
|
+
if (!o || typeof IntersectionObserver > "u") return;
|
|
30
|
+
let m = !1;
|
|
31
|
+
const b = Number(t), x = Number.isFinite(b) ? b : 0, O = x - (parseFloat(getComputedStyle(o).paddingBottom) || 0), v = new IntersectionObserver((w) => {
|
|
32
|
+
const { isIntersecting: F, boundingClientRect: A, rootBounds: y } = w.at(-1);
|
|
33
|
+
m = F && !!y && A.bottom <= y.bottom + 0.5, m && i();
|
|
34
|
+
}, { root: o, rootMargin: `0px 0px ${O}px 0px`, threshold: [0, 1] });
|
|
35
|
+
v.observe(a);
|
|
36
|
+
const S = () => {
|
|
37
|
+
m && o.scrollHeight - o.scrollTop <= o.clientHeight + x && i();
|
|
38
|
+
};
|
|
39
|
+
return o.addEventListener("scroll", S, { passive: !0 }), () => {
|
|
40
|
+
v.disconnect(), o.removeEventListener("scroll", S);
|
|
41
|
+
};
|
|
42
|
+
}, [c, s, t, g, i]), /* @__PURE__ */ B($, { ref: d, more: c });
|
|
43
|
+
}), Z = { Footer: K, request: G, row: J };
|
|
44
|
+
export {
|
|
45
|
+
K as PagingFooter,
|
|
46
|
+
Z as paging
|
|
47
|
+
};
|
package/dist/select.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),g=require("./state.cjs"),v=require("react"),M=require("./trigger.cjs"),T=require("./dropdown.cjs"),A=require("./liveRegion.cjs"),d=require("./utils.cjs"),q=require("./useSelect.cjs");;/* empty css */;/* empty css */const E={},l=e=>e!=null&&e!=="",w=e=>e?typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(w).join(" ").replace(/\s+/g," ").trim():v.isValidElement(e)?w(e.props.children):"":"",j=({name:e,label:o,id:t,value:s,className:a,style:n,children:i,disabled:c,group:r},h,x)=>{const u=w(i),O=s!==void 0?s:u;return i!=null&&!u&&!l(o)&&!l(e)&&!l(t)&&!l(s)&&d.warnOnce("no text","<Option> has content but no text to show in the title or chips. Add a `label` (or `value`), or enable `valueAsOption`."),{id:l(t)?String(t):h,userId:l(t)?t:O,value:O,label:l(o)?String(o):l(e)?String(e):u||(l(t)?String(t):""),jsx:i,hasJsx:i!=null,className:a,style:n,disabled:!!c,group:r||x||null}},D=({name:e,label:o,value:t,id:s,disabled:a,className:n="",style:i=E},c)=>{const r=e??o??s??t;return{disabled:!!a,isGroupMarker:!0,group:l(r)?String(r):c,className:n,style:i}},R=e=>`<${typeof e=="string"?e:e?.displayName||e?.name||"Component"}>`,m=(e,o,t=null,s="o",a=[])=>(v.Children.toArray(e).forEach(n=>{if(!v.isValidElement(n)){d.warnOnce("text",`Text inside <Select> or <OptGroup> is ignored ("${String(n).slice(0,30)}"). Wrap it in <Option>.`);return}const i=`${s}-${String(n.key).slice(1).replace(/[:$]/g,r=>r===":"?"-":"k").replace(/[^\p{L}\p{N}-]/gu,"")}`,c=n.type?.racKind;if(n.type===v.Fragment)m(n.props.children,o,t,i,a);else if(c==="option")a.push(j(n.props,i,t));else if(c==="define")m(n.type.racRender(n.props),o,t,i,a);else if(c==="group"){const r=D(n.props,o);a.push(r),m(n.props.children,o,r.group,i,a)}else{const r=R(n.type);d.warnOnce(`child ${r}`,`${r} inside <Select> is ignored: only <Option/>, <OptGroup/> and defineOption() components are read. Put custom content inside <Option>, or wrap the component with defineOption().`)}}),a),$=new Set(["ref","options","value","defaultValue","onChange","children","loadMore","open","onOpenChange","onFocus","onBlur","onKeyDown","childrenFirst","groupsClosed","disabled","loading","error","plugins"]),F=/^(aria|data)-/,y={options:[],value:void 0,defaultValue:void 0,onChange:void 0,multiple:!1,childrenFirst:!1,groupsClosed:!1,plugins:[],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:d.icons.ArrowUp,clear:d.icons.XMark,remove:d.icons.XMark,check:d.icons.Checkmark,checkbox:void 0},deleteInline:!1,deleteAlways:!1,className:"",optionsClassName:"",style:{},container:void 0,duration:300,easing:"ease",offset:1,animateOpacity:!0,keepMounted:!1},C={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"},S=(e,o)=>{const t={...e};for(const s in o)o[s]!==void 0&&(t[s]=o[s]);return t};function I(e){for(const p in e)p in C&&d.warnOnce(`renamed ${p}`,`The \`${p}\` prop was removed. Use \`${C[p]}\`.`);e.value!==void 0&&!e.onChange&&d.warnOnce("read-only value","`value` is set without `onChange`, so the Select is read-only. Pass `onChange`, or `defaultValue` instead of `value`.");const o=S(y,e);o.texts=S(y.texts,e.texts),o.icons=S(y.icons,e.icons);const t=o.texts.emptyGroup,s=g.useDeepStable(v.useMemo(()=>m(o.children,t),[o.children,t])),{selectId:a,selectRef:n,highlightStore:i,ext:c,state:r,actions:h}=q.default(o,s),x={},u={};for(const p in o)$.has(p)||((F.test(p)?u:x)[p]=o[p]);const O=g.useShallowStable({...x,attrs:u,selectId:a,selectRef:n,highlightStore:i,ext:c});return f.jsx(g.SelectConfigContext.Provider,{value:O,children:f.jsx(g.SelectActionsContext.Provider,{value:h,children:f.jsxs(g.SelectStateContext.Provider,{value:r,children:[f.jsx(M.default,{}),f.jsx(T.default,{}),f.jsx(A.default,{})]})})})}function b(){return d.warnOnce("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}b.racKind="option";function k(){return null}k.racKind="group";exports.OptGroup=k;exports.Option=b;exports.Select=I;
|
package/dist/select.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as f, jsxs as w } from "react/jsx-runtime";
|
|
3
|
+
import { useDeepStable as k, useShallowStable as T, SelectConfigContext as M, SelectActionsContext as A, SelectStateContext as D } from "./state.js";
|
|
4
|
+
import { useMemo as E, Children as R, isValidElement as b, Fragment as $ } from "react";
|
|
5
|
+
import L from "./trigger.js";
|
|
6
|
+
import F from "./dropdown.js";
|
|
7
|
+
import I from "./liveRegion.js";
|
|
8
|
+
import { warnOnce as u, icons as v } from "./utils.js";
|
|
9
|
+
import N from "./useSelect.js";
|
|
10
|
+
import './theme.css';import './base.css';/* empty css */
|
|
11
|
+
/* empty css */
|
|
12
|
+
const K = {}, l = (e) => e != null && e !== "", C = (e) => e ? typeof e == "string" || typeof e == "number" ? String(e) : Array.isArray(e) ? e.map(C).join(" ").replace(/\s+/g, " ").trim() : b(e) ? C(e.props.children) : "" : "", V = ({ name: e, label: o, id: t, value: s, className: a, style: n, children: i, disabled: p, group: r }, O, m) => {
|
|
13
|
+
const c = C(i), g = s !== void 0 ? s : c;
|
|
14
|
+
return i != null && !c && !l(o) && !l(e) && !l(t) && !l(s) && u("no text", "<Option> has content but no text to show in the title or chips. Add a `label` (or `value`), or enable `valueAsOption`."), {
|
|
15
|
+
id: l(t) ? String(t) : O,
|
|
16
|
+
userId: l(t) ? t : g,
|
|
17
|
+
value: g,
|
|
18
|
+
label: l(o) ? String(o) : l(e) ? String(e) : c || (l(t) ? String(t) : ""),
|
|
19
|
+
jsx: i,
|
|
20
|
+
hasJsx: i != null,
|
|
21
|
+
className: a,
|
|
22
|
+
style: n,
|
|
23
|
+
disabled: !!p,
|
|
24
|
+
group: r || m || null
|
|
25
|
+
};
|
|
26
|
+
}, j = ({ name: e, label: o, value: t, id: s, disabled: a, className: n = "", style: i = K }, p) => {
|
|
27
|
+
const r = e ?? o ?? s ?? t;
|
|
28
|
+
return { disabled: !!a, isGroupMarker: !0, group: l(r) ? String(r) : p, className: n, style: i };
|
|
29
|
+
}, B = (e) => `<${typeof e == "string" ? e : e?.displayName || e?.name || "Component"}>`, x = (e, o, t = null, s = "o", a = []) => (R.toArray(e).forEach((n) => {
|
|
30
|
+
if (!b(n)) {
|
|
31
|
+
u("text", `Text inside <Select> or <OptGroup> is ignored ("${String(n).slice(0, 30)}"). Wrap it in <Option>.`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const i = `${s}-${String(n.key).slice(1).replace(/[:$]/g, (r) => r === ":" ? "-" : "k").replace(/[^\p{L}\p{N}-]/gu, "")}`, p = n.type?.racKind;
|
|
35
|
+
if (n.type === $) x(n.props.children, o, t, i, a);
|
|
36
|
+
else if (p === "option") a.push(V(n.props, i, t));
|
|
37
|
+
else if (p === "define") x(n.type.racRender(n.props), o, t, i, a);
|
|
38
|
+
else if (p === "group") {
|
|
39
|
+
const r = j(n.props, o);
|
|
40
|
+
a.push(r), x(n.props.children, o, r.group, i, a);
|
|
41
|
+
} else {
|
|
42
|
+
const r = B(n.type);
|
|
43
|
+
u(`child ${r}`, `${r} inside <Select> is ignored: only <Option/>, <OptGroup/> and defineOption() components are read. Put custom content inside <Option>, or wrap the component with defineOption().`);
|
|
44
|
+
}
|
|
45
|
+
}), a), P = /* @__PURE__ */ new Set(["ref", "options", "value", "defaultValue", "onChange", "children", "loadMore", "open", "onOpenChange", "onFocus", "onBlur", "onKeyDown", "childrenFirst", "groupsClosed", "disabled", "loading", "error", "plugins"]), U = /^(aria|data)-/, h = {
|
|
46
|
+
options: [],
|
|
47
|
+
value: void 0,
|
|
48
|
+
defaultValue: void 0,
|
|
49
|
+
onChange: void 0,
|
|
50
|
+
multiple: !1,
|
|
51
|
+
childrenFirst: !1,
|
|
52
|
+
groupsClosed: !1,
|
|
53
|
+
plugins: [],
|
|
54
|
+
disabled: !1,
|
|
55
|
+
loading: !1,
|
|
56
|
+
error: !1,
|
|
57
|
+
open: void 0,
|
|
58
|
+
onOpenChange: void 0,
|
|
59
|
+
popup: !0,
|
|
60
|
+
onFocus: void 0,
|
|
61
|
+
onBlur: void 0,
|
|
62
|
+
onKeyDown: void 0,
|
|
63
|
+
id: void 0,
|
|
64
|
+
name: void 0,
|
|
65
|
+
form: void 0,
|
|
66
|
+
required: !1,
|
|
67
|
+
hasMore: !1,
|
|
68
|
+
loadMore: void 0,
|
|
69
|
+
loadButton: !1,
|
|
70
|
+
loadOffset: 100,
|
|
71
|
+
loadAhead: 3,
|
|
72
|
+
placeholder: "Choose option",
|
|
73
|
+
selectedText: void 0,
|
|
74
|
+
texts: {
|
|
75
|
+
empty: "No options",
|
|
76
|
+
disabled: "Disabled",
|
|
77
|
+
loading: "Loading",
|
|
78
|
+
error: "Failed to load",
|
|
79
|
+
clear: "Clear selection",
|
|
80
|
+
remove: "Remove",
|
|
81
|
+
loadMore: "Load more",
|
|
82
|
+
loadingMore: "Loading",
|
|
83
|
+
emptyOption: "Empty option",
|
|
84
|
+
invalidOption: "Invalid option",
|
|
85
|
+
disabledOption: "Disabled option",
|
|
86
|
+
emptyGroup: "Empty group",
|
|
87
|
+
groupOpen: "expanded",
|
|
88
|
+
groupClosed: "collapsed",
|
|
89
|
+
list: "Options",
|
|
90
|
+
required: void 0,
|
|
91
|
+
removed: "Removed {label}",
|
|
92
|
+
cleared: "Selection cleared",
|
|
93
|
+
selected: "{n} selected",
|
|
94
|
+
loaded: "{n} more options loaded"
|
|
95
|
+
},
|
|
96
|
+
renderOption: void 0,
|
|
97
|
+
valueAsOption: !1,
|
|
98
|
+
icons: { arrow: v.ArrowUp, clear: v.XMark, remove: v.XMark, check: v.Checkmark, checkbox: void 0 },
|
|
99
|
+
deleteInline: !1,
|
|
100
|
+
deleteAlways: !1,
|
|
101
|
+
className: "",
|
|
102
|
+
optionsClassName: "",
|
|
103
|
+
style: {},
|
|
104
|
+
container: void 0,
|
|
105
|
+
duration: 300,
|
|
106
|
+
easing: "ease",
|
|
107
|
+
offset: 1,
|
|
108
|
+
animateOpacity: !0,
|
|
109
|
+
keepMounted: !1
|
|
110
|
+
}, S = {
|
|
111
|
+
visibility: "open",
|
|
112
|
+
setVisibility: "onOpenChange",
|
|
113
|
+
ownBehavior: "open without onOpenChange",
|
|
114
|
+
onOpen: "onOpenChange",
|
|
115
|
+
onClose: "onOpenChange",
|
|
116
|
+
unmount: "keepMounted (inverted)",
|
|
117
|
+
showDelete: "deleteAlways",
|
|
118
|
+
OpenIcon: "icons.arrow",
|
|
119
|
+
ClearIcon: "icons.clear",
|
|
120
|
+
DelIcon: "icons.remove",
|
|
121
|
+
Checkmark: "icons.check",
|
|
122
|
+
Checkbox: "icons.checkbox",
|
|
123
|
+
emptyText: "texts.empty",
|
|
124
|
+
disabledText: "texts.disabled",
|
|
125
|
+
loadingText: "texts.loading",
|
|
126
|
+
errorText: "texts.error",
|
|
127
|
+
clearText: "texts.clear",
|
|
128
|
+
removeText: "texts.remove",
|
|
129
|
+
loadButtonText: "texts.loadMore",
|
|
130
|
+
loadMoreText: "texts.loadingMore",
|
|
131
|
+
emptyOption: "texts.emptyOption",
|
|
132
|
+
invalidOption: "texts.invalidOption",
|
|
133
|
+
disabledOption: "texts.disabledOption"
|
|
134
|
+
}, y = (e, o) => {
|
|
135
|
+
const t = { ...e };
|
|
136
|
+
for (const s in o) o[s] !== void 0 && (t[s] = o[s]);
|
|
137
|
+
return t;
|
|
138
|
+
};
|
|
139
|
+
function oe(e) {
|
|
140
|
+
for (const d in e) d in S && u(`renamed ${d}`, `The \`${d}\` prop was removed. Use \`${S[d]}\`.`);
|
|
141
|
+
e.value !== void 0 && !e.onChange && u("read-only value", "`value` is set without `onChange`, so the Select is read-only. Pass `onChange`, or `defaultValue` instead of `value`.");
|
|
142
|
+
const o = y(h, e);
|
|
143
|
+
o.texts = y(h.texts, e.texts), o.icons = y(h.icons, e.icons);
|
|
144
|
+
const t = o.texts.emptyGroup, s = k(E(() => x(o.children, t), [o.children, t])), { selectId: a, selectRef: n, highlightStore: i, ext: p, state: r, actions: O } = N(o, s), m = {}, c = {};
|
|
145
|
+
for (const d in o) P.has(d) || ((U.test(d) ? c : m)[d] = o[d]);
|
|
146
|
+
const g = T({ ...m, attrs: c, selectId: a, selectRef: n, highlightStore: i, ext: p });
|
|
147
|
+
return /* @__PURE__ */ f(M.Provider, { value: g, children: /* @__PURE__ */ f(A.Provider, { value: O, children: /* @__PURE__ */ w(D.Provider, { value: r, children: [
|
|
148
|
+
/* @__PURE__ */ f(L, {}),
|
|
149
|
+
/* @__PURE__ */ f(F, {}),
|
|
150
|
+
/* @__PURE__ */ f(I, {})
|
|
151
|
+
] }) }) });
|
|
152
|
+
}
|
|
153
|
+
function Y() {
|
|
154
|
+
return u("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;
|
|
155
|
+
}
|
|
156
|
+
Y.racKind = "option";
|
|
157
|
+
function _() {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
_.racKind = "group";
|
|
161
|
+
export {
|
|
162
|
+
_ as OptGroup,
|
|
163
|
+
Y as Option,
|
|
164
|
+
oe as Select
|
|
165
|
+
};
|
package/dist/state.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),u=o.createContext(null),i=o.createContext(null),S=o.createContext(null),a=(e,t)=>{const c=typeof t=="function"?t(e):t;return c===e?e:Object.keys(c).some(n=>!Object.is(c[n],e[n]))?{...e,...c}:e},f=e=>{let t=e;const c=new Set;return{get:()=>t,set:s=>{Object.keys(s).every(n=>Object.is(s[n],t[n]))||(t={...t,...s},c.forEach(n=>n()))},subscribe:s=>(c.add(s),()=>c.delete(s))}},y=e=>{const t=o.useRef(e);o.useInsertionEffect(()=>{t.current=e});const[c]=o.useState(()=>Object.fromEntries(Object.keys(e).map(s=>[s,(...n)=>t.current[s](...n)])));return c},l=(e,t)=>{const[c,s]=o.useState(e);return c===e||t(c,e)?c:(s(e),e)},j=(e,t)=>e===t||!!e&&!!t&&Object.keys(e).length===Object.keys(t).length&&Object.keys(e).every(c=>Object.is(e[c],t[c])),r=(e,t,c=0)=>{if(Object.is(e,t))return!0;if(c>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&&r(e.props,t.props,c+1);const s=Object.keys(e);return s.length===Object.keys(t).length&&s.every(n=>Object.hasOwn(t,n)&&r(e[n],t[n],c+1))},O=new Set(["style","texts","icons","attrs"]),b=(e,t)=>{const c=Object.keys(t);return c.length===Object.keys(e).length&&c.every(s=>O.has(s)?j(e[s],t[s]):Object.is(e[s],t[s]))},p=e=>l(e,b),g=e=>l(e,r);exports.SelectActionsContext=i;exports.SelectConfigContext=u;exports.SelectStateContext=S;exports.compactReducer=a;exports.createStore=f;exports.deepEqual=r;exports.useDeepStable=g;exports.useShallowStable=p;exports.useStableActions=y;
|