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/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;
package/dist/state.js ADDED
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import { createContext as o, useState as l, useRef as i, useInsertionEffect as f } from "react";
3
+ const p = /* @__PURE__ */ o(null), b = /* @__PURE__ */ o(null), a = /* @__PURE__ */ o(null), g = (e, t) => {
4
+ const s = typeof t == "function" ? t(e) : t;
5
+ return s === e ? e : Object.keys(s).some((n) => !Object.is(s[n], e[n])) ? { ...e, ...s } : e;
6
+ }, h = (e) => {
7
+ let t = e;
8
+ const s = /* @__PURE__ */ new Set();
9
+ return {
10
+ get: () => t,
11
+ set: (c) => {
12
+ Object.keys(c).every((n) => Object.is(c[n], t[n])) || (t = { ...t, ...c }, s.forEach((n) => n()));
13
+ },
14
+ subscribe: (c) => (s.add(c), () => s.delete(c))
15
+ };
16
+ }, E = (e) => {
17
+ const t = i(e);
18
+ f(() => {
19
+ t.current = e;
20
+ });
21
+ const [s] = l(() => Object.fromEntries(
22
+ Object.keys(e).map((c) => [c, (...n) => t.current[c](...n)])
23
+ ));
24
+ return s;
25
+ }, u = (e, t) => {
26
+ const [s, c] = l(e);
27
+ return s === e || t(s, e) ? s : (c(e), e);
28
+ }, y = (e, t) => e === t || !!e && !!t && Object.keys(e).length === Object.keys(t).length && Object.keys(e).every((s) => Object.is(e[s], t[s])), r = (e, t, s = 0) => {
29
+ if (Object.is(e, t)) return !0;
30
+ if (s > 12 || typeof e != "object" || typeof t != "object" || e === null || t === null || Array.isArray(e) !== Array.isArray(t)) return !1;
31
+ if (e.$$typeof || t.$$typeof) return e.$$typeof === t.$$typeof && e.type === t.type && e.key === t.key && r(e.props, t.props, s + 1);
32
+ const c = Object.keys(e);
33
+ return c.length === Object.keys(t).length && c.every((n) => Object.hasOwn(t, n) && r(e[n], t[n], s + 1));
34
+ }, j = /* @__PURE__ */ new Set(["style", "texts", "icons", "attrs"]), O = (e, t) => {
35
+ const s = Object.keys(t);
36
+ return s.length === Object.keys(e).length && s.every(
37
+ (c) => j.has(c) ? y(e[c], t[c]) : Object.is(e[c], t[c])
38
+ );
39
+ }, $ = (e) => u(e, O), m = (e) => u(e, r);
40
+ export {
41
+ b as SelectActionsContext,
42
+ p as SelectConfigContext,
43
+ a as SelectStateContext,
44
+ g as compactReducer,
45
+ h as createStore,
46
+ r as deepEqual,
47
+ m as useDeepStable,
48
+ $ as useShallowStable,
49
+ E as useStableActions
50
+ };
package/dist/style.css ADDED
@@ -0,0 +1,4 @@
1
+ @layer rac.base, rac.theme;
2
+ @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}}}
3
+ @layer rac.base,rac.theme;@layer rac.theme{:root{--rac-bg: color-mix(in srgb, Canvas 98%, CanvasText 2%);--rac-fg: CanvasText;--rac-danger: #e7000b;--rac-success: #4caf50;--rac-radius: 0px}.rac-select,.rac-options{--rac-tint-1: color-mix(in srgb, var(--rac-fg) 5%, var(--rac-bg));--rac-tint-2: color-mix(in srgb, var(--rac-fg) 10%, var(--rac-bg));--rac-tint-3: color-mix(in srgb, var(--rac-fg) 20%, var(--rac-bg));--rac-muted: color-mix(in srgb, var(--rac-fg) 55%, var(--rac-bg))}.rac-select,.rac-options{border-radius:var(--rac-radius)}.rac-select{padding:0 .5em;border:2px solid var(--rac-bg);background-color:var(--rac-bg);color:var(--rac-fg);transition:background-color var(--rac-duration) var(--rac-ease),border-color var(--rac-duration) var(--rac-ease),opacity var(--rac-duration) var(--rac-ease)}.rac-select[aria-haspopup]:not([aria-disabled=true]):hover{background-color:var(--rac-tint-1)}.rac-select[aria-haspopup]:not([aria-disabled=true],[data-error],[data-invalid]):hover{border-color:var(--rac-tint-1)}.rac-select[aria-disabled=true]{opacity:.75}.rac-select:is([data-error],[data-invalid]){border-color:var(--rac-danger)}.rac-select[aria-busy=true]:after{content:"";position:absolute;inset:0;border-radius:inherit;background:linear-gradient(90deg,transparent,var(--rac-muted),transparent) 0 100% / 40% 2px no-repeat;animation:rac-busy 1.5s ease-in-out infinite;pointer-events:none}@media(prefers-reduced-motion:reduce){.rac-select[aria-busy=true]:after{animation:none;background-size:100% 2px}}:is(.rac-title,.rac-option)[data-bool=true]{color:var(--rac-success)}:is(.rac-title,.rac-option)[data-bool=false]{color:var(--rac-danger)}.rac-list{background-color:var(--rac-bg);color:var(--rac-fg);scrollbar-color:var(--rac-tint-2) var(--rac-tint-1);scrollbar-width:thin;scroll-padding-block:.5em}.rac-option{gap:.5em;padding:.5em;transition:background-color var(--rac-duration-fast) var(--rac-ease)}.rac-option[data-highlighted]{background-color:var(--rac-tint-2)}.rac-option[aria-selected=true]{background-color:var(--rac-tint-3)}.rac-option[aria-selected=true][data-highlighted]{background-color:color-mix(in srgb,var(--rac-fg) 30%,var(--rac-bg))}.rac-option[aria-disabled=true]{color:var(--rac-muted)}.rac-option[data-invalid]{color:var(--rac-danger)}.rac-option[data-loading]{gap:0;color:var(--rac-muted)}.rac-option[data-error]{color:var(--rac-danger)}.rac-check{margin-inline-end:.2em}.rac-check[data-default]{border-color:var(--rac-muted)}.rac-group{padding:.5em;font-size:1.25em;font-weight:700;transition:background-color var(--rac-duration-fast) var(--rac-ease)}.rac-group[data-highlighted]{background-color:var(--rac-tint-2)}.rac-group[data-disabled]{color:var(--rac-muted)}.rac-group-items{padding-inline-start:1em}@keyframes rac-busy{0%{background-position-x:-100%}to{background-position-x:200%}}}
4
+ @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/theme.css ADDED
@@ -0,0 +1 @@
1
+ @layer rac.base,rac.theme;@layer rac.theme{:root{--rac-bg: color-mix(in srgb, Canvas 98%, CanvasText 2%);--rac-fg: CanvasText;--rac-danger: #e7000b;--rac-success: #4caf50;--rac-radius: 0px}.rac-select,.rac-options{--rac-tint-1: color-mix(in srgb, var(--rac-fg) 5%, var(--rac-bg));--rac-tint-2: color-mix(in srgb, var(--rac-fg) 10%, var(--rac-bg));--rac-tint-3: color-mix(in srgb, var(--rac-fg) 20%, var(--rac-bg));--rac-muted: color-mix(in srgb, var(--rac-fg) 55%, var(--rac-bg))}.rac-select,.rac-options{border-radius:var(--rac-radius)}.rac-select{padding:0 .5em;border:2px solid var(--rac-bg);background-color:var(--rac-bg);color:var(--rac-fg);transition:background-color var(--rac-duration) var(--rac-ease),border-color var(--rac-duration) var(--rac-ease),opacity var(--rac-duration) var(--rac-ease)}.rac-select[aria-haspopup]:not([aria-disabled=true]):hover{background-color:var(--rac-tint-1)}.rac-select[aria-haspopup]:not([aria-disabled=true],[data-error],[data-invalid]):hover{border-color:var(--rac-tint-1)}.rac-select[aria-disabled=true]{opacity:.75}.rac-select:is([data-error],[data-invalid]){border-color:var(--rac-danger)}.rac-select[aria-busy=true]:after{content:"";position:absolute;inset:0;border-radius:inherit;background:linear-gradient(90deg,transparent,var(--rac-muted),transparent) 0 100% / 40% 2px no-repeat;animation:rac-busy 1.5s ease-in-out infinite;pointer-events:none}@media(prefers-reduced-motion:reduce){.rac-select[aria-busy=true]:after{animation:none;background-size:100% 2px}}:is(.rac-title,.rac-option)[data-bool=true]{color:var(--rac-success)}:is(.rac-title,.rac-option)[data-bool=false]{color:var(--rac-danger)}.rac-list{background-color:var(--rac-bg);color:var(--rac-fg);scrollbar-color:var(--rac-tint-2) var(--rac-tint-1);scrollbar-width:thin;scroll-padding-block:.5em}.rac-option{gap:.5em;padding:.5em;transition:background-color var(--rac-duration-fast) var(--rac-ease)}.rac-option[data-highlighted]{background-color:var(--rac-tint-2)}.rac-option[aria-selected=true]{background-color:var(--rac-tint-3)}.rac-option[aria-selected=true][data-highlighted]{background-color:color-mix(in srgb,var(--rac-fg) 30%,var(--rac-bg))}.rac-option[aria-disabled=true]{color:var(--rac-muted)}.rac-option[data-invalid]{color:var(--rac-danger)}.rac-option[data-loading]{gap:0;color:var(--rac-muted)}.rac-option[data-error]{color:var(--rac-danger)}.rac-check{margin-inline-end:.2em}.rac-check[data-default]{border-color:var(--rac-muted)}.rac-group{padding:.5em;font-size:1.25em;font-weight:700;transition:background-color var(--rac-duration-fast) var(--rac-ease)}.rac-group[data-highlighted]{background-color:var(--rac-tint-2)}.rac-group[data-disabled]{color:var(--rac-muted)}.rac-group-items{padding-inline-start:1em}@keyframes rac-busy{0%{background-position-x:-100%}to{background-position-x:200%}}}
@@ -0,0 +1 @@
1
+ "use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("react/jsx-runtime"),b=require("./state.cjs"),o=require("./utils.cjs"),e=require("react"),L=require("./useSelectBehavior.cjs"),z=require("./model.cjs"),R=require("./motion.cjs"),K=[],M=()=>{},_=h=>h==null?"":typeof h=="object"?z.toJSON(h)??"":String(h),G=e.memo(function(){const{selectRef:m,multiple:r,name:d,form:g,required:f}=e.useContext(b.SelectConfigContext),{selected:C,selectedIDs:S,disabled:p,fieldsetDisabled:s}=e.useContext(b.SelectStateContext),{reset:n,markInvalid:v}=e.useContext(b.SelectActionsContext),c=e.useRef(null);e.useEffect(()=>{const t=c.current?.getRootNode();let l;const y=w=>{w.target===c.current?.form&&(clearTimeout(l),l=setTimeout(()=>w.defaultPrevented||n()))};return t?.addEventListener("reset",y,!0),()=>{clearTimeout(l),t?.removeEventListener("reset",y,!0)}},[n]);const x=r?S:C?[C]:K,u=!f&&(!d||r&&!x.length),a=u||!x.length?[""]:x.map(t=>_(t.original)),j=()=>m.current?.focus();return a.map((t,l)=>i.jsx("input",{className:"rac-input",ref:l?void 0:c,name:u?void 0:d,form:g,value:t,hidden:u,required:f&&!l,disabled:p&&!s,tabIndex:-1,"aria-hidden":"true",autoComplete:"off",onChange:M,onInvalid:v,onFocus:j},l))}),O=e.memo(function({hidden:m,settle:r}){const{multiple:d,selectedText:g,valueAsOption:f,renderOption:C,texts:S}=e.useContext(b.SelectConfigContext),{selectedIDs:p,title:s,valueOption:n,hasActualValue:v,loading:c,error:x}=e.useContext(b.SelectStateContext),[u]=e.useState(()=>new Set),a=f&&n?o.optionContent(n,C,!0):null,j=c&&!x&&!v,t=d&&p.length>0&&!g,l=`${t?"picked":a?n.id:s}${j?"-loading":""}`,y=n?.type==="boolean"?String(n.raw):void 0;return i.jsx(R.Presence,{children:!m&&i.jsxs(R.Collapse,{axis:"x",fade:!0,group:u,className:o.withClass("rac-title",a&&n.className),style:a?n.style:void 0,"data-bool":y,onEntered:r,onExited:r,children:[a?i.jsx("div",{className:"rac-option-jsx",children:a}):t?p.map(w=>w.name||S.emptyOption).join(", "):s,j&&o.dots]},l)})}),J=e.memo(function(){const{selectRef:m,multiple:r,valueAsOption:d,duration:g,easing:f,ext:C}=e.useContext(b.SelectConfigContext),S=r?C.Value:void 0,p=e.useRef(null),[s,n]=e.useState(d);d&&!s&&n(!0);const v=e.useRef({duration:g,easing:f});return e.useLayoutEffect(()=>{v.current={duration:g,easing:f}},[g,f]),e.useLayoutEffect(()=>{const c=p.current;if(!s||r||!c||typeof ResizeObserver>"u")return;const x={value:0,root:"",anim:null},u=new ResizeObserver(()=>o.followHeight(m.current,x,c.offsetHeight,v.current.duration,v.current.easing));return u.observe(c),()=>{u.disconnect(),x.anim?.cancel()}},[s,r,m]),S?i.jsx(S,{}):i.jsx("div",{className:"rac-value",ref:p,children:i.jsx(O,{})})}),Q=e.memo(function(){const{selectRef:m,selectId:r,highlightStore:d,className:g,style:f,duration:C,easing:S,deleteInline:p,icons:s,texts:n,placeholder:v,id:c,required:x,popup:u,attrs:a}=e.useContext(b.SelectConfigContext),{visibility:j,active:t,hasActualValue:l,deleting:y,loading:w,loadPending:T,error:N,invalid:q,normalizedOptions:E}=e.useContext(b.SelectStateContext),{handleBlur:A,handleFocus:D,handleKeyDown:F,toggleVisibility:P,clear:V}=e.useContext(b.SelectActionsContext),k=e.useSyncExternalStore(d.subscribe,()=>{const I=j?E[L.effectiveHighlight(d.get())]:null;return I?o.optionDomId(r,I.id):void 0},()=>{}),$=!!s.clear&&l&&t&&!y,B=!!s.arrow&&t&&!y&&u,H=u?{role:"combobox","aria-haspopup":"listbox","aria-controls":`${r}-listbox`,"aria-expanded":j,"aria-activedescendant":k,"aria-required":x||void 0}:{role:"group"};return i.jsxs("div",{...a,id:c,ref:m,style:{"--rac-duration":`${C}ms`,"--rac-ease":S,...f},className:o.withClass("rac-select",g),...t&&{onKeyDown:F,onFocus:D,onClick:P,onBlur:A},...H,"aria-disabled":!t,tabIndex:t?0:-1,"aria-busy":w||T||void 0,"aria-label":a["aria-label"]??(a["aria-labelledby"]?void 0:v),"aria-invalid":q||a["aria-invalid"],"aria-describedby":[a["aria-describedby"],N&&`${r}-error`].filter(Boolean).join(" ")||void 0,"data-inline-delete":o.flag(p),"data-empty":o.flag(!l),"data-deleting":o.flag(y),"data-error":o.flag(N),"data-invalid":o.flag(q),children:[i.jsx(J,{}),i.jsxs(R.Presence,{children:[$&&i.jsx(R.Collapse,{as:"button",type:"button",axis:"x",className:"rac-clear",tabIndex:-1,"aria-label":n.clear,onMouseDown:o.stopEvent,onClick:I=>{o.refocus(I,m),V(I)},children:o.renderIcon(s.clear)},"clear"),B&&i.jsx(R.Collapse,{axis:"x",className:"rac-arrow","aria-hidden":"true",children:o.renderIcon(s.arrow)},"arrow")]}),i.jsx(G,{})]})});exports.Title=O;exports.default=Q;
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ import { jsxs as R, jsx as u } from "react/jsx-runtime";
3
+ import { SelectConfigContext as N, SelectStateContext as F, SelectActionsContext as k } from "./state.js";
4
+ import { optionDomId as W, flag as I, withClass as P, renderIcon as V, stopEvent as X, refocus as Y, optionContent as Z, dots as ee, followHeight as te } from "./utils.js";
5
+ import { memo as O, useContext as g, useSyncExternalStore as oe, useState as $, useRef as D, useLayoutEffect as j, useEffect as ne } from "react";
6
+ import { effectiveHighlight as re } from "./useSelectBehavior.js";
7
+ import { toJSON as ie } from "./model.js";
8
+ import { Presence as q, Collapse as E } from "./motion.js";
9
+ const ae = [], le = () => {
10
+ }, se = (b) => b == null ? "" : typeof b == "object" ? ie(b) ?? "" : String(b), ce = /* @__PURE__ */ O(function() {
11
+ const { selectRef: m, multiple: o, name: s, form: p, required: c } = g(N), { selected: h, selectedIDs: x, disabled: f, fieldsetDisabled: n } = g(F), { reset: t, markInvalid: v } = g(k), a = D(null);
12
+ ne(() => {
13
+ const e = a.current?.getRootNode();
14
+ let i;
15
+ const y = (C) => {
16
+ C.target === a.current?.form && (clearTimeout(i), i = setTimeout(() => C.defaultPrevented || t()));
17
+ };
18
+ return e?.addEventListener("reset", y, !0), () => {
19
+ clearTimeout(i), e?.removeEventListener("reset", y, !0);
20
+ };
21
+ }, [t]);
22
+ const d = o ? x : h ? [h] : ae, l = !c && (!s || o && !d.length), r = l || !d.length ? [""] : d.map((e) => se(e.original)), w = () => m.current?.focus();
23
+ return r.map(
24
+ (e, i) => /* @__PURE__ */ u("input", { className: "rac-input", ref: i ? void 0 : a, name: l ? void 0 : s, form: p, value: e, hidden: l, required: c && !i, disabled: f && !n, tabIndex: -1, "aria-hidden": "true", autoComplete: "off", onChange: le, onInvalid: v, onFocus: w }, i)
25
+ );
26
+ }), de = /* @__PURE__ */ O(function({ hidden: m, settle: o }) {
27
+ const { multiple: s, selectedText: p, valueAsOption: c, renderOption: h, texts: x } = g(N), { selectedIDs: f, title: n, valueOption: t, hasActualValue: v, loading: a, error: d } = g(F), [l] = $(() => /* @__PURE__ */ new Set()), r = c && t ? Z(t, h, !0) : null, w = a && !d && !v, e = s && f.length > 0 && !p, i = `${e ? "picked" : r ? t.id : n}${w ? "-loading" : ""}`, y = t?.type === "boolean" ? String(t.raw) : void 0;
28
+ return /* @__PURE__ */ u(q, { children: !m && /* @__PURE__ */ R(E, { axis: "x", fade: !0, group: l, className: P("rac-title", r && t.className), style: r ? t.style : void 0, "data-bool": y, onEntered: o, onExited: o, children: [
29
+ r ? /* @__PURE__ */ u("div", { className: "rac-option-jsx", children: r }) : e ? f.map((C) => C.name || x.emptyOption).join(", ") : n,
30
+ w && ee
31
+ ] }, i) });
32
+ }), ue = /* @__PURE__ */ O(function() {
33
+ const { selectRef: m, multiple: o, valueAsOption: s, duration: p, easing: c, ext: h } = g(N), x = o ? h.Value : void 0, f = D(null), [n, t] = $(s);
34
+ s && !n && t(!0);
35
+ const v = D({ duration: p, easing: c });
36
+ return j(() => {
37
+ v.current = { duration: p, easing: c };
38
+ }, [p, c]), j(() => {
39
+ const a = f.current;
40
+ if (!n || o || !a || typeof ResizeObserver > "u") return;
41
+ const d = { value: 0, root: "", anim: null }, l = new ResizeObserver(() => te(m.current, d, a.offsetHeight, v.current.duration, v.current.easing));
42
+ return l.observe(a), () => {
43
+ l.disconnect(), d.anim?.cancel();
44
+ };
45
+ }, [n, o, m]), x ? /* @__PURE__ */ u(x, {}) : /* @__PURE__ */ u("div", { className: "rac-value", ref: f, children: /* @__PURE__ */ u(de, {}) });
46
+ }), xe = /* @__PURE__ */ O(function() {
47
+ const { selectRef: m, selectId: o, highlightStore: s, className: p, style: c, duration: h, easing: x, deleteInline: f, icons: n, texts: t, placeholder: v, id: a, required: d, popup: l, attrs: r } = g(N), { visibility: w, active: e, hasActualValue: i, deleting: y, loading: C, loadPending: H, error: T, invalid: A, normalizedOptions: z } = g(F), { handleBlur: B, handleFocus: K, handleKeyDown: L, toggleVisibility: G, clear: J } = g(k), M = oe(s.subscribe, () => {
48
+ const S = w ? z[re(s.get())] : null;
49
+ return S ? W(o, S.id) : void 0;
50
+ }, () => {
51
+ }), _ = !!n.clear && i && e && !y, Q = !!n.arrow && e && !y && l, U = l ? { role: "combobox", "aria-haspopup": "listbox", "aria-controls": `${o}-listbox`, "aria-expanded": w, "aria-activedescendant": M, "aria-required": d || void 0 } : { role: "group" };
52
+ return /* @__PURE__ */ R(
53
+ "div",
54
+ {
55
+ ...r,
56
+ id: a,
57
+ ref: m,
58
+ style: { "--rac-duration": `${h}ms`, "--rac-ease": x, ...c },
59
+ className: P("rac-select", p),
60
+ ...e && {
61
+ onKeyDown: L,
62
+ onFocus: K,
63
+ onClick: G,
64
+ onBlur: B
65
+ },
66
+ ...U,
67
+ "aria-disabled": !e,
68
+ tabIndex: e ? 0 : -1,
69
+ "aria-busy": C || H || void 0,
70
+ "aria-label": r["aria-label"] ?? (r["aria-labelledby"] ? void 0 : v),
71
+ "aria-invalid": A || r["aria-invalid"],
72
+ "aria-describedby": [r["aria-describedby"], T && `${o}-error`].filter(Boolean).join(" ") || void 0,
73
+ "data-inline-delete": I(f),
74
+ "data-empty": I(!i),
75
+ "data-deleting": I(y),
76
+ "data-error": I(T),
77
+ "data-invalid": I(A),
78
+ children: [
79
+ /* @__PURE__ */ u(ue, {}),
80
+ /* @__PURE__ */ R(q, { children: [
81
+ _ && /* @__PURE__ */ u(E, { as: "button", type: "button", axis: "x", className: "rac-clear", tabIndex: -1, "aria-label": t.clear, onMouseDown: X, onClick: (S) => {
82
+ Y(S, m), J(S);
83
+ }, children: V(n.clear) }, "clear"),
84
+ Q && /* @__PURE__ */ u(E, { axis: "x", className: "rac-arrow", "aria-hidden": "true", children: V(n.arrow) }, "arrow")
85
+ ] }),
86
+ /* @__PURE__ */ u(ce, {})
87
+ ]
88
+ }
89
+ );
90
+ });
91
+ export {
92
+ de as Title,
93
+ xe as default
94
+ };
@@ -0,0 +1 @@
1
+ "use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("react"),F=require("react-dom"),R=require("./state.cjs"),g=require("./utils.cjs"),J=require("./model.cjs"),o=require("./chipGeometry.cjs"),Q=.25,U={hoverId:null,swipedId:null,held:!1,breaks:o.NONE},G=(i,a)=>{const u=new Set(i.map(l=>l.id)),c=new Map(a.map(([l,v])=>[v.id,l])),p=a.filter(([,l])=>!u.has(l.id)),E=new Set(a.map(([l])=>l));return i.map(l=>{if(c.has(l.id))return[c.get(l.id),l];const v=p.findIndex(([,k])=>J.sameValue(k.original,l.original));if(v>=0)return[p.splice(v,1)[0][0],l];let w=l.id;for(;E.has(w);)w+="~";return E.add(w),[w,l]})},X=i=>{const[a,u]=n.useState(()=>({chips:i,keyed:G(i,[])}));if(a.chips===i)return a.keyed;const c=G(i,a.keyed);return u({chips:i,keyed:c}),c};function Y(i){const{selectRef:a,duration:u,easing:c,deleteInline:p,deleteAlways:E,icons:l,valueAsOption:v,renderOption:w}=n.useContext(R.SelectConfigContext),{selectedIDs:k,deleting:C,visibility:B,active:L}=n.useContext(R.SelectStateContext),{setDeleting:q,setVisibility:H}=n.useContext(R.SelectActionsContext),[j,V]=n.useState(0),[s]=n.useState(()=>R.createStore(U)),[W]=n.useState(()=>new Set),A=n.useSyncExternalStore(s.subscribe,()=>s.get().held,()=>!1),O=n.useSyncExternalStore(s.subscribe,()=>s.get().breaks,()=>o.NONE),_=n.useSyncExternalStore(g.watchMotion,g.reducedMotion,()=>!1),S=n.useRef({rows:null,reserve:0,chips:i,swap:!1,duration:u,easing:c}),m=n.useRef(null),h=n.useRef({value:0,root:"",anim:null}),d=n.useRef(null),D=n.useRef(null),N=p&&!E&&!C&&!!l.remove,K=N?j+Q:0,z=N&&!j&&i.length>0,x=v?w?2:1:0,I=n.useEffectEvent((e,t)=>{const r=d.current,f=S.current;if(!r)return;const b=o.isResizing(r);if(b&&t)return;e&&s.get().held&&o.freeze(s,r,f);const y=f.swap?f.duration/2:f.duration;b?f.fit!=null&&g.followHeight(a.current,h.current,f.fit,y,f.easing,r):(t||h.current.value)&&g.followHeight(a.current,h.current,r.offsetHeight,y,f.easing),s.get().held||s.set({breaks:o.restBreaks(s,r,f.chips,f.reserve)})});n.useLayoutEffect(()=>{Object.assign(S.current,{duration:u,easing:c})},[u,c]),n.useLayoutEffect(()=>{const e=S.current,t=d.current,r=e.chips!==i;Object.assign(e,{chips:i,reserve:K}),r&&t&&o.isBusy(t)&&o.freeze(s,t,e),I(!r)},[i,K,s]),n.useLayoutEffect(()=>{const e=()=>I(!0,!0),t=typeof ResizeObserver>"u"?null:new ResizeObserver(e);return t?t.observe(d.current):e(),document.fonts?.addEventListener("loadingdone",e),()=>{t?.disconnect(),document.fonts?.removeEventListener("loadingdone",e)}},[]);const M=n.useCallback(()=>{const e=d.current;if(!e||!s.get().held||o.isBusy(e))return;const t=S.current,r=o.slotsOf(e),f=r.map(y=>y.getBoundingClientRect()),b=o.restBreaks(s,e,t.chips,t.reserve);Object.assign(t,{rows:null,floor:null,fit:null}),F.flushSync(()=>s.set({held:!1,breaks:b})),t.swap=o.isBusy(e),t.swap&&F.flushSync(()=>o.freeze(s,e,t)),g.reducedMotion()||r.forEach((y,T)=>y.isConnected&&o.flip(y,f[T],t.swap?u/2:u,c))},[s,u,c]),P=n.useCallback(e=>{d.current&&(m.current=o.snapOf(d.current,e))},[]);return n.useLayoutEffect(()=>{const e=d.current,t=S.current;if(!e||!m.current||!u||g.reducedMotion())return;const r=o.resizesOf(m.current);r.length&&(t.floor=new Map(r.map(({id:f,from:b})=>[f,b.width])),o.freeze(s,e,t),g.followHeight(a.current,h.current,t.fit,u,c,e),o.resize(r,u,c,()=>{M(),I(!1,!0)}))},[x,s,u,c,a,M]),n.useLayoutEffect(()=>{const e=m.current;!e||O!==s.get().breaks||(m.current=null,g.reducedMotion()||e.forEach((t,r)=>r.isConnected&&o.flip(r,t,u,c)))},[O,i,x,s,u,c]),n.useLayoutEffect(()=>{const e=d.current,t=S.current;!e||!h.current.value||o.isResizing(e)||g.followHeight(a.current,h.current,e.offsetHeight,t.swap?t.duration/2:t.duration,t.easing)},[O,A,a]),n.useEffect(()=>()=>h.current.anim?.cancel(),[]),n.useEffect(()=>{C&&B&&H(!1),C&&(!k.length||!L)&&q(!1),s.set({hoverId:null,...!L&&{swipedId:null}})},[k.length,C,B,L,q,H,s]),n.useLayoutEffect(()=>{const e=D.current;if(!z||!e)return;const t=getComputedStyle(e);V(e.getBoundingClientRect().width+parseFloat(t.marginLeft)+parseFloat(t.marginRight))},[z]),{chipStore:s,delGroup:W,valueRef:d,delIconRef:D,probe:z,settle:M,held:A,snapshot:P,look:x,wait:u>0&&!_}}exports.default=Y;exports.useChipKeys=X;
@@ -0,0 +1,78 @@
1
+ "use client";
2
+ import { useContext as j, useState as I, useSyncExternalStore as D, useRef as b, useEffectEvent as se, useLayoutEffect as g, useCallback as P, useEffect as Q } from "react";
3
+ import { flushSync as T } from "react-dom";
4
+ import { SelectConfigContext as oe, SelectStateContext as le, SelectActionsContext as ie, createStore as ce } from "./state.js";
5
+ import { watchMotion as ue, reducedMotion as R, followHeight as O } from "./utils.js";
6
+ import { sameValue as ae } from "./model.js";
7
+ import { NONE as _, isResizing as U, freeze as E, restBreaks as X, isBusy as H, slotsOf as fe, flip as Y, snapOf as de, resizesOf as ge, resize as he } from "./chipGeometry.js";
8
+ const me = 0.25, pe = { hoverId: null, swipedId: null, held: !1, breaks: _ }, Z = (i, c) => {
9
+ const s = new Set(i.map((o) => o.id)), l = new Map(c.map(([o, h]) => [h.id, o])), y = c.filter(([, o]) => !s.has(o.id)), k = new Set(c.map(([o]) => o));
10
+ return i.map((o) => {
11
+ if (l.has(o.id)) return [l.get(o.id), o];
12
+ const h = y.findIndex(([, S]) => ae(S.original, o.original));
13
+ if (h >= 0) return [y.splice(h, 1)[0][0], o];
14
+ let m = o.id;
15
+ for (; k.has(m); ) m += "~";
16
+ return k.add(m), [m, o];
17
+ });
18
+ }, Ce = (i) => {
19
+ const [c, s] = I(() => ({ chips: i, keyed: Z(i, []) }));
20
+ if (c.chips === i) return c.keyed;
21
+ const l = Z(i, c.keyed);
22
+ return s({ chips: i, keyed: l }), l;
23
+ };
24
+ function Re(i) {
25
+ const { selectRef: c, duration: s, easing: l, deleteInline: y, deleteAlways: k, icons: o, valueAsOption: h, renderOption: m } = j(oe), { selectedIDs: S, deleting: C, visibility: F, active: x } = j(le), { setDeleting: K, setVisibility: N } = j(ie), [V, $] = I(0), [n] = I(() => ce(pe)), [ee] = I(() => /* @__PURE__ */ new Set()), W = D(n.subscribe, () => n.get().held, () => !1), z = D(n.subscribe, () => n.get().breaks, () => _), te = D(ue, R, () => !1), p = b({ rows: null, reserve: 0, chips: i, swap: !1, duration: s, easing: l }), w = b(null), f = b({ value: 0, root: "", anim: null }), a = b(null), G = b(null), q = y && !k && !C && !!o.remove, J = q ? V + me : 0, L = q && !V && i.length > 0, A = h ? m ? 2 : 1 : 0, B = se((e, t) => {
26
+ const r = a.current, u = p.current;
27
+ if (!r) return;
28
+ const v = U(r);
29
+ if (v && t) return;
30
+ e && n.get().held && E(n, r, u);
31
+ const d = u.swap ? u.duration / 2 : u.duration;
32
+ v ? u.fit != null && O(c.current, f.current, u.fit, d, u.easing, r) : (t || f.current.value) && O(c.current, f.current, r.offsetHeight, d, u.easing), n.get().held || n.set({ breaks: X(n, r, u.chips, u.reserve) });
33
+ });
34
+ g(() => {
35
+ Object.assign(p.current, { duration: s, easing: l });
36
+ }, [s, l]), g(() => {
37
+ const e = p.current, t = a.current, r = e.chips !== i;
38
+ Object.assign(e, { chips: i, reserve: J }), r && t && H(t) && E(n, t, e), B(!r);
39
+ }, [i, J, n]), g(() => {
40
+ const e = () => B(!0, !0), t = typeof ResizeObserver > "u" ? null : new ResizeObserver(e);
41
+ return t ? t.observe(a.current) : e(), document.fonts?.addEventListener("loadingdone", e), () => {
42
+ t?.disconnect(), document.fonts?.removeEventListener("loadingdone", e);
43
+ };
44
+ }, []);
45
+ const M = P(() => {
46
+ const e = a.current;
47
+ if (!e || !n.get().held || H(e)) return;
48
+ const t = p.current, r = fe(e), u = r.map((d) => d.getBoundingClientRect()), v = X(n, e, t.chips, t.reserve);
49
+ Object.assign(t, { rows: null, floor: null, fit: null }), T(() => n.set({ held: !1, breaks: v })), t.swap = H(e), t.swap && T(() => E(n, e, t)), R() || r.forEach((d, re) => d.isConnected && Y(d, u[re], t.swap ? s / 2 : s, l));
50
+ }, [n, s, l]), ne = P((e) => {
51
+ a.current && (w.current = de(a.current, e));
52
+ }, []);
53
+ return g(() => {
54
+ const e = a.current, t = p.current;
55
+ if (!e || !w.current || !s || R()) return;
56
+ const r = ge(w.current);
57
+ r.length && (t.floor = new Map(r.map(({ id: u, from: v }) => [u, v.width])), E(n, e, t), O(c.current, f.current, t.fit, s, l, e), he(r, s, l, () => {
58
+ M(), B(!1, !0);
59
+ }));
60
+ }, [A, n, s, l, c, M]), g(() => {
61
+ const e = w.current;
62
+ !e || z !== n.get().breaks || (w.current = null, R() || e.forEach((t, r) => r.isConnected && Y(r, t, s, l)));
63
+ }, [z, i, A, n, s, l]), g(() => {
64
+ const e = a.current, t = p.current;
65
+ !e || !f.current.value || U(e) || O(c.current, f.current, e.offsetHeight, t.swap ? t.duration / 2 : t.duration, t.easing);
66
+ }, [z, W, c]), Q(() => () => f.current.anim?.cancel(), []), Q(() => {
67
+ C && F && N(!1), C && (!S.length || !x) && K(!1), n.set({ hoverId: null, ...!x && { swipedId: null } });
68
+ }, [S.length, C, F, x, K, N, n]), g(() => {
69
+ const e = G.current;
70
+ if (!L || !e) return;
71
+ const t = getComputedStyle(e);
72
+ $(e.getBoundingClientRect().width + parseFloat(t.marginLeft) + parseFloat(t.marginRight));
73
+ }, [L]), { chipStore: n, delGroup: ee, valueRef: a, delIconRef: G, probe: L, settle: M, held: W, snapshot: ne, look: A, wait: s > 0 && !te };
74
+ }
75
+ export {
76
+ Re as default,
77
+ Ce as useChipKeys
78
+ };
@@ -0,0 +1 @@
1
+ "use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react"),M=require("./state.cjs"),O=require("./utils.cjs"),J=require("./useSelectBehavior.cjs"),Q=require("./useSelectModel.cjs"),ne=[],se=t=>{const p=M.useShallowStable(Array.isArray(t)?t:ne);return e.useMemo(()=>p.reduce((l,n)=>{for(const o in n)o in l&&O.warnOnce(`plugin ${o}`,`Two plugins provide \`${o}\`; the last one wins. Pass each plugin once.`);return Object.assign(l,n)},{}),[p])},le=t=>({internalVisibility:!1,deleting:!1,loadPending:!1,toggledGroups:new Set,internalValue:t.defaultValue,picked:Q.NO_PICK,fieldsetDisabled:!1,invalid:!1});function ae(t,p){const[l,n]=e.useReducer(M.compactReducer,t,le),{internalVisibility:o,deleting:D,loadPending:m,fieldsetDisabled:v}=l,d=e.useMemo(()=>v&&!t.disabled?{...t,disabled:!0}:t,[t,v]),{ref:W,open:L,onOpenChange:X,popup:$,hasMore:Y,loadButton:Z,error:C,disabled:V,loading:w,required:q,texts:B}=d,N=e.useId(),P=e.useMemo(()=>N.replace(/:/g,""),[N]),a=e.useRef(null);e.useImperativeHandle(W,()=>a.current),e.useLayoutEffect(()=>{const i=a.current?.querySelector(".rac-input");if(!i)return;const s=()=>n({fieldsetDisabled:!t.disabled&&i.matches(":disabled")});s();const U=new MutationObserver(s);for(let h=i.parentElement;h;h=h.parentElement)h.tagName==="FIELDSET"&&U.observe(h,{attributeFilter:["disabled"]});return()=>U.disconnect()},[t.disabled]);const[f]=e.useState(()=>M.createStore(J.initialHighlight)),g=se(t.plugins);t.multiple&&(t.deleteInline||t.deleteAlways)&&!g.Value&&O.warnOnce("no chips","`deleteInline` and `deleteAlways` act on chips, which need the `chips` plugin: `plugins={[chips]}`."),(t.hasMore||t.loadButton||t.loadMore)&&!g.request&&O.warnOnce("no paging","`hasMore`, `loadMore` and `loadButton` need the `paging` plugin: `plugins={[paging]}`.");const y=L!==void 0,_=y?!!L:o,G=e.useRef(!1),T=e.useRef(!1),c=M.useStableActions({setVisibility:i=>{i===_||i&&!$||(y||n({internalVisibility:i}),X?.(i))},loadMoreOnce:()=>g.request?.({props:d,lock:G,setPending:i=>n({loadPending:i})}),setListReady:i=>f.set({ready:i}),setDeleting:i=>n({deleting:i}),markInvalid:()=>n({invalid:!0})}),ee=Q.default({props:d,jsxOptions:p,state:l,setState:n,ext:g,setVisibility:c.setVisibility,loadMoreOnce:c.loadMoreOnce}),{normalizedOptions:S,expandedGroups:E,selected:I,selectedIDs:k,hasOptions:j,active:r,hasActualValue:b,title:x,valueOption:F,actions:R}=ee,u=r&&_&&$,H=J.default({props:d,state:l,setState:n,normalizedOptions:S,expandedGroups:E,selected:I,selectedIDs:k,visibility:u,highlightStore:f,setVisibility:c.setVisibility,modelActions:R});e.useEffect(()=>{n({loadPending:!1})},[S.length,Y,Z]),e.useEffect(()=>{m||(G.current=!1)},[m]),e.useEffect(()=>{u&&a.current&&document.activeElement!==a.current&&a.current.focus(),u||f.set({index:-1,ready:!1})},[u,f]),e.useEffect(()=>{T.current&&!r&&c.setVisibility(!1),T.current=r},[r,c]);const A=e.useRef(null),z=d.value!==void 0;e.useEffect(()=>{const i={value:z,open:y};for(const s in i)A.current&&A.current[s]!==i[s]&&O.warnOnce(`switch ${s}`,`\`${s}\` switched between controlled and uncontrolled (\`undefined\`) after mount. Pick one mode for the lifetime of the Select, like a React input${s==="value"?"; clear a controlled value with `null` or `[]`":""}.`);A.current=i},[z,y]),e.useLayoutEffect(()=>{a.current?.querySelector(".rac-input")?.setCustomValidity(q&&!b&&B.required||"")},[q,b,B.required]);const K=l.invalid&&q&&!b&&!V,te=e.useMemo(()=>({...c,...R,...H}),[c,R,H]),ie=e.useMemo(()=>({visibility:u,deleting:D,loadPending:m,expandedGroups:E,selectedIDs:k,normalizedOptions:S,selected:I,hasOptions:j,active:r,hasActualValue:b,title:x,valueOption:F,disabled:V,fieldsetDisabled:v,invalid:K,loading:w,error:C}),[u,D,m,E,k,S,I,j,r,b,x,F,V,v,K,w,C]);return{selectId:P,selectRef:a,highlightStore:f,ext:g,state:ie,actions:te}}exports.default=ae;
@@ -0,0 +1,100 @@
1
+ "use client";
2
+ import { useReducer as ne, useMemo as b, useId as le, useRef as O, useImperativeHandle as se, useLayoutEffect as Q, useState as ae, useEffect as h } from "react";
3
+ import { compactReducer as re, createStore as ce, useStableActions as oe, useShallowStable as de } from "./state.js";
4
+ import { warnOnce as I } from "./utils.js";
5
+ import ue, { initialHighlight as fe } from "./useSelectBehavior.js";
6
+ import ge, { NO_PICK as pe } from "./useSelectModel.js";
7
+ const he = [], be = (e) => {
8
+ const m = de(Array.isArray(e) ? e : he);
9
+ return b(() => m.reduce((l, i) => {
10
+ for (const o in i) o in l && I(`plugin ${o}`, `Two plugins provide \`${o}\`; the last one wins. Pass each plugin once.`);
11
+ return Object.assign(l, i);
12
+ }, {}), [m]);
13
+ }, me = (e) => ({
14
+ internalVisibility: !1,
15
+ deleting: !1,
16
+ loadPending: !1,
17
+ toggledGroups: /* @__PURE__ */ new Set(),
18
+ internalValue: e.defaultValue,
19
+ picked: pe,
20
+ fieldsetDisabled: !1,
21
+ invalid: !1
22
+ });
23
+ function Ie(e, m) {
24
+ const [l, i] = ne(re, e, me), { internalVisibility: o, deleting: C, loadPending: v, fieldsetDisabled: y } = l, d = b(() => y && !e.disabled ? { ...e, disabled: !0 } : e, [e, y]), { ref: W, open: L, onOpenChange: X, popup: $, hasMore: Y, loadButton: Z, error: B, disabled: M, loading: N, required: k, texts: x } = d, G = le(), P = b(() => G.replace(/:/g, ""), [G]), s = O(null);
25
+ se(W, () => s.current), Q(() => {
26
+ const t = s.current?.querySelector(".rac-input");
27
+ if (!t) return;
28
+ const n = () => i({ fieldsetDisabled: !e.disabled && t.matches(":disabled") });
29
+ n();
30
+ const J = new MutationObserver(n);
31
+ for (let p = t.parentElement; p; p = p.parentElement) p.tagName === "FIELDSET" && J.observe(p, { attributeFilter: ["disabled"] });
32
+ return () => J.disconnect();
33
+ }, [e.disabled]);
34
+ const [u] = ae(() => ce(fe)), f = be(e.plugins);
35
+ e.multiple && (e.deleteInline || e.deleteAlways) && !f.Value && I("no chips", "`deleteInline` and `deleteAlways` act on chips, which need the `chips` plugin: `plugins={[chips]}`."), (e.hasMore || e.loadButton || e.loadMore) && !f.request && I("no paging", "`hasMore`, `loadMore` and `loadButton` need the `paging` plugin: `plugins={[paging]}`.");
36
+ const S = L !== void 0, F = S ? !!L : o, H = O(!1), T = O(!1), a = oe({
37
+ // [DOC: select-store]
38
+ setVisibility: (t) => {
39
+ t === F || t && !$ || (S || i({ internalVisibility: t }), X?.(t));
40
+ },
41
+ // [DOC: paging]
42
+ loadMoreOnce: () => f.request?.({ props: d, lock: H, setPending: (t) => i({ loadPending: t }) }),
43
+ setListReady: (t) => u.set({ ready: t }),
44
+ setDeleting: (t) => i({ deleting: t }),
45
+ // [DOC: form-field]
46
+ markInvalid: () => i({ invalid: !0 })
47
+ }), ee = ge({ props: d, jsxOptions: m, state: l, setState: i, ext: f, setVisibility: a.setVisibility, loadMoreOnce: a.loadMoreOnce }), { normalizedOptions: V, expandedGroups: q, selected: A, selectedIDs: E, hasOptions: _, active: r, hasActualValue: g, title: j, valueOption: w, actions: D } = ee, c = r && F && $, z = ue({
48
+ props: d,
49
+ state: l,
50
+ setState: i,
51
+ normalizedOptions: V,
52
+ expandedGroups: q,
53
+ selected: A,
54
+ selectedIDs: E,
55
+ visibility: c,
56
+ highlightStore: u,
57
+ setVisibility: a.setVisibility,
58
+ modelActions: D
59
+ });
60
+ h(() => {
61
+ i({ loadPending: !1 });
62
+ }, [V.length, Y, Z]), h(() => {
63
+ v || (H.current = !1);
64
+ }, [v]), h(() => {
65
+ c && s.current && document.activeElement !== s.current && s.current.focus(), c || u.set({ index: -1, ready: !1 });
66
+ }, [c, u]), h(() => {
67
+ T.current && !r && a.setVisibility(!1), T.current = r;
68
+ }, [r, a]);
69
+ const R = O(null), K = d.value !== void 0;
70
+ h(() => {
71
+ const t = { value: K, open: S };
72
+ for (const n in t) R.current && R.current[n] !== t[n] && I(`switch ${n}`, `\`${n}\` switched between controlled and uncontrolled (\`undefined\`) after mount. Pick one mode for the lifetime of the Select, like a React input${n === "value" ? "; clear a controlled value with `null` or `[]`" : ""}.`);
73
+ R.current = t;
74
+ }, [K, S]), Q(() => {
75
+ s.current?.querySelector(".rac-input")?.setCustomValidity(k && !g && x.required || "");
76
+ }, [k, g, x.required]);
77
+ const U = l.invalid && k && !g && !M, te = b(() => ({ ...a, ...D, ...z }), [a, D, z]), ie = b(() => ({
78
+ visibility: c,
79
+ deleting: C,
80
+ loadPending: v,
81
+ expandedGroups: q,
82
+ selectedIDs: E,
83
+ normalizedOptions: V,
84
+ selected: A,
85
+ hasOptions: _,
86
+ active: r,
87
+ hasActualValue: g,
88
+ title: j,
89
+ valueOption: w,
90
+ disabled: M,
91
+ fieldsetDisabled: y,
92
+ invalid: U,
93
+ loading: N,
94
+ error: B
95
+ }), [c, C, v, q, E, V, A, _, r, g, j, w, M, y, U, N, B]);
96
+ return { selectId: P, selectRef: s, highlightStore: u, ext: f, state: ie, actions: te };
97
+ }
98
+ export {
99
+ Ie as default
100
+ };
@@ -0,0 +1 @@
1
+ "use client";"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("react"),L=require("./state.cjs"),D=require("./utils.cjs"),S={index:-1,fallback:-1,ready:!1},F=({index:r,fallback:f})=>r===-1?f:r,U=10,C=500,V=new Set(["ArrowDown","ArrowUp","PageDown","PageUp","Home","End"]),_=(r,f)=>h.useMemo(()=>{const c=new Set(r.map(n=>n.group).filter(Boolean)),i=n=>!!n&&!n.disabled&&!n.loading&&(n.groupHeader?c.has(n.name):!n.group||f.has(n.group));return{reach:i,list:r.flatMap((n,o)=>i(n)?[o]:[])}},[r,f]),z=(r,f,c,i)=>{const n=r.length-1;if(n<0)return-1;if(c==="Home")return r[0];if(c==="End")return r[n];const o=c==="ArrowUp"||c==="PageUp"?-1:1,l=r.indexOf(f);if(l===-1)return r[o>0?0:n];const s=l+o*(c.startsWith("Page")?U:1);return s>=0&&s<=n?r[s]:c.startsWith("Page")||i?r[s<0?0:n]:r[(s+r.length)%r.length]},R=(r,f,c,i)=>{const n=[...i].every(u=>u===i[0]),o=n?i[0]:i,l=f.filter(u=>"original"in r[u]),s=Math.max(l.indexOf(c)+(n?1:0),0);for(let u=0;u<l.length;u++){const T=l[(s+u)%l.length];if(String(r[T].name).toLowerCase().startsWith(o))return T}return-1};function I({props:r,state:f,setState:c,normalizedOptions:i,expandedGroups:n,selected:o,selectedIDs:l,visibility:s,setVisibility:u,modelActions:T,highlightStore:w}){const{disabled:E,multiple:y,hasMore:P,loadButton:k,icons:x,onFocus:q,onBlur:M,onKeyDown:A}=r,{selectOption:B,clear:W,removeOption:p}=T,{deleting:v}=f,{reach:H,list:m}=_(i,n),d=h.useRef({lastWindowFocusTime:0,justFocused:!1,focusTimeout:null,query:"",queryTimeout:null}),j=h.useMemo(()=>{const e=new Set(y?l.map(a=>a.id):o?[o.id]:[]),t=e.size?i.findIndex(a=>e.has(a.id)&&H(a)):-1;return t!==-1?t:m.find(a=>!i[a].groupHeader)??m[0]??-1},[i,o,l,y,H,m]);h.useLayoutEffect(()=>{const{index:e}=w.get();w.set({fallback:j,index:e!==-1&&H(i[e])?e:-1})}),h.useEffect(()=>{const e=d.current,t=()=>e.lastWindowFocusTime=Date.now();return window.addEventListener("focus",t),()=>{window.removeEventListener("focus",t),clearTimeout(e.focusTimeout),clearTimeout(e.queryTimeout)}},[]);const b=e=>w.set({index:e}),K=(e,t)=>{const a=d.current;clearTimeout(a.queryTimeout),a.queryTimeout=setTimeout(()=>a.query="",C),a.query+=e.toLowerCase();const g=R(i,m,t,a.query);g!==-1&&b(g),s||u(!0)};return L.useStableActions({highlight:b,handleBlur:e=>{const t=e.relatedTarget?.closest(".rac-options");e.currentTarget.contains(e.relatedTarget)||t||(M?.(e),v&&c({deleting:!1}),s&&u(!1))},handleFocus:e=>{const t=e.currentTarget.contains(e.relatedTarget);t||q?.(e),!(t||e.target!==e.currentTarget||s||E||v||document.hidden||Date.now()-d.current.lastWindowFocusTime<100)&&(clearTimeout(d.current.focusTimeout),d.current.focusTimeout=setTimeout(()=>d.current.justFocused=!1,200),d.current.justFocused=!0,u(!0))},toggleVisibility:e=>{if(v){D.stopEvent(e),c({deleting:!1});return}E||d.current.justFocused||u(!s)},handleKeyDown:e=>{if(A?.(e),e.defaultPrevented||E||e.nativeEvent?.isComposing)return;const{key:t}=e;if(e.target!==e.currentTarget&&(t==="Enter"||t.length===1))return;const a=F(w.get());if(t.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(t!==" "||d.current.query)){e.preventDefault(),K(t,a);return}if(V.has(t)){e.preventDefault(),(s||t==="Home"||t==="End")&&b(z(m,a,t,!k&&P)),s||u(!0);return}switch(t){case"Enter":case" ":e.preventDefault(),s?a!==-1&&i[a]&&(b(a),B(i[a],e)):u(!0);break;case"Escape":if(v)c({deleting:!1});else if(s)u(!1);else break;D.stopEvent(e);break;case"Tab":s&&u(!1);break;case"Backspace":case"Delete":{const g=l.at(-1);if(y&&t==="Backspace"&&x.remove&&g)p(g.id);else if(x.clear&&(o||g))W();else break;e.preventDefault();break}}}})}exports.default=I;exports.effectiveHighlight=F;exports.initialHighlight=S;