UNPKG

alinea

Version:
361 lines (355 loc) 19.9 kB
import { c as c2, f as f2, s as s2, s2 as s3, u as u4, y as y2 } from "./chunk-2STBQ2Y4.js"; import { Fe, Me, R, R2, Re, be, c, d, f, i, m, n as n2, re, u as u5, x2 as x, xe, ye } from "./chunk-WLKPH7JA.js"; import { A, F, _ as _2, h, j as j2 } from "./chunk-HSIHEWFC.js"; import { T, j, l, p as p2 } from "./chunk-ORDS5C6Z.js"; import { I, K as K2, Q, U, a, u as u3 } from "./chunk-SOTBYUJY.js"; import { r as r2 } from "./chunk-2NTSADJL.js"; import { $6179b936705e76d3$export$ae780daf29e6d456, $f7dceffc5ad7768b$export$4e328f61c538687f, K, L, O, _, e, n, o, o2, o3, p, r, s2 as s, u, u2, w, y } from "./chunk-VUACWPFC.js"; // node_modules/@headlessui/react/dist/components/listbox/listbox.js import A2, { Fragment as xe2, createContext as ae, createRef as De, useCallback as se, useContext as pe, useEffect as _e, useMemo as k, useReducer as Ie, useRef as ue, useState as Ce } from "react"; import { flushSync as U2 } from "react-dom"; // node_modules/@headlessui/react/dist/hooks/use-by-comparator.js import { useCallback as n3 } from "react"; function l2(e2, r4) { return e2 !== null && r4 !== null && typeof e2 == "object" && typeof r4 == "object" && "id" in e2 && "id" in r4 ? e2.id === r4.id : e2 === r4; } function u6(e2 = l2) { return n3((r4, t) => { if (typeof e2 == "string") { let o4 = e2; return (r4 == null ? void 0 : r4[o4]) === (t == null ? void 0 : t[o4]); } return e2(r4, t); }, [e2]); } // node_modules/@headlessui/react/dist/internal/frozen.js import r3, { useState as u7 } from "react"; function l3(o4, e2) { let [n4, t] = u7(e2); return !o4 && n4 !== e2 && t(e2), o4 ? n4 : e2; } // node_modules/@headlessui/react/dist/components/listbox/listbox.js var gt = ((o4) => (o4[o4.Open = 0] = "Open", o4[o4.Closed = 1] = "Closed", o4))(gt || {}); var Lt = ((o4) => (o4[o4.Single = 0] = "Single", o4[o4.Multi = 1] = "Multi", o4))(Lt || {}); var St = ((o4) => (o4[o4.Pointer = 0] = "Pointer", o4[o4.Other = 1] = "Other", o4))(St || {}); var Et = ((n4) => (n4[n4.OpenListbox = 0] = "OpenListbox", n4[n4.CloseListbox = 1] = "CloseListbox", n4[n4.GoToOption = 2] = "GoToOption", n4[n4.Search = 3] = "Search", n4[n4.ClearSearch = 4] = "ClearSearch", n4[n4.RegisterOption = 5] = "RegisterOption", n4[n4.UnregisterOption = 6] = "UnregisterOption", n4[n4.SetButtonElement = 7] = "SetButtonElement", n4[n4.SetOptionsElement = 8] = "SetOptionsElement", n4))(Et || {}); function be2(e2, i2 = (o4) => o4) { let o4 = e2.activeOptionIndex !== null ? e2.options[e2.activeOptionIndex] : null, r4 = _2(i2(e2.options.slice()), (m2) => m2.dataRef.current.domRef.current), a2 = o4 ? r4.indexOf(o4) : null; return a2 === -1 && (a2 = null), { options: r4, activeOptionIndex: a2 }; } var Pt = { [1](e2) { return e2.dataRef.current.disabled || e2.listboxState === 1 ? e2 : { ...e2, activeOptionIndex: null, listboxState: 1, __demoMode: false }; }, [0](e2) { if (e2.dataRef.current.disabled || e2.listboxState === 0) return e2; let i2 = e2.activeOptionIndex, { isSelected: o4 } = e2.dataRef.current, r4 = e2.options.findIndex((a2) => o4(a2.dataRef.current.value)); return r4 !== -1 && (i2 = r4), { ...e2, listboxState: 0, activeOptionIndex: i2, __demoMode: false }; }, [2](e2, i2) { var m2, x2, d2, p3, n4; if (e2.dataRef.current.disabled || e2.listboxState === 1) return e2; let o4 = { ...e2, searchQuery: "", activationTrigger: (m2 = i2.trigger) != null ? m2 : 1, __demoMode: false }; if (i2.focus === c2.Nothing) return { ...o4, activeOptionIndex: null }; if (i2.focus === c2.Specific) return { ...o4, activeOptionIndex: e2.options.findIndex((u8) => u8.id === i2.id) }; if (i2.focus === c2.Previous) { let u8 = e2.activeOptionIndex; if (u8 !== null) { let P = e2.options[u8].dataRef.current.domRef, t = f2(i2, { resolveItems: () => e2.options, resolveActiveIndex: () => e2.activeOptionIndex, resolveId: (s4) => s4.id, resolveDisabled: (s4) => s4.dataRef.current.disabled }); if (t !== null) { let s4 = e2.options[t].dataRef.current.domRef; if (((x2 = P.current) == null ? void 0 : x2.previousElementSibling) === s4.current || ((d2 = s4.current) == null ? void 0 : d2.previousElementSibling) === null) return { ...o4, activeOptionIndex: t }; } } } else if (i2.focus === c2.Next) { let u8 = e2.activeOptionIndex; if (u8 !== null) { let P = e2.options[u8].dataRef.current.domRef, t = f2(i2, { resolveItems: () => e2.options, resolveActiveIndex: () => e2.activeOptionIndex, resolveId: (s4) => s4.id, resolveDisabled: (s4) => s4.dataRef.current.disabled }); if (t !== null) { let s4 = e2.options[t].dataRef.current.domRef; if (((p3 = P.current) == null ? void 0 : p3.nextElementSibling) === s4.current || ((n4 = s4.current) == null ? void 0 : n4.nextElementSibling) === null) return { ...o4, activeOptionIndex: t }; } } } let r4 = be2(e2), a2 = f2(i2, { resolveItems: () => r4.options, resolveActiveIndex: () => r4.activeOptionIndex, resolveId: (u8) => u8.id, resolveDisabled: (u8) => u8.dataRef.current.disabled }); return { ...o4, ...r4, activeOptionIndex: a2 }; }, [3]: (e2, i2) => { if (e2.dataRef.current.disabled || e2.listboxState === 1) return e2; let r4 = e2.searchQuery !== "" ? 0 : 1, a2 = e2.searchQuery + i2.value.toLowerCase(), x2 = (e2.activeOptionIndex !== null ? e2.options.slice(e2.activeOptionIndex + r4).concat(e2.options.slice(0, e2.activeOptionIndex + r4)) : e2.options).find((p3) => { var n4; return !p3.dataRef.current.disabled && ((n4 = p3.dataRef.current.textValue) == null ? void 0 : n4.startsWith(a2)); }), d2 = x2 ? e2.options.indexOf(x2) : -1; return d2 === -1 || d2 === e2.activeOptionIndex ? { ...e2, searchQuery: a2 } : { ...e2, searchQuery: a2, activeOptionIndex: d2, activationTrigger: 1 }; }, [4](e2) { return e2.dataRef.current.disabled || e2.listboxState === 1 || e2.searchQuery === "" ? e2 : { ...e2, searchQuery: "" }; }, [5]: (e2, i2) => { let o4 = { id: i2.id, dataRef: i2.dataRef }, r4 = be2(e2, (a2) => [...a2, o4]); return e2.activeOptionIndex === null && e2.dataRef.current.isSelected(i2.dataRef.current.value) && (r4.activeOptionIndex = r4.options.indexOf(o4)), { ...e2, ...r4 }; }, [6]: (e2, i2) => { let o4 = be2(e2, (r4) => { let a2 = r4.findIndex((m2) => m2.id === i2.id); return a2 !== -1 && r4.splice(a2, 1), r4; }); return { ...e2, ...o4, activationTrigger: 1 }; }, [7]: (e2, i2) => e2.buttonElement === i2.element ? e2 : { ...e2, buttonElement: i2.element }, [8]: (e2, i2) => e2.optionsElement === i2.element ? e2 : { ...e2, optionsElement: i2.element } }; var Te = ae(null); Te.displayName = "ListboxActionsContext"; function Z(e2) { let i2 = pe(Te); if (i2 === null) { let o4 = new Error(`<${e2} /> is missing a parent <Listbox /> component.`); throw Error.captureStackTrace && Error.captureStackTrace(o4, Z), o4; } return i2; } var ee = ae(null); ee.displayName = "ListboxDataContext"; function Q2(e2) { let i2 = pe(ee); if (i2 === null) { let o4 = new Error(`<${e2} /> is missing a parent <Listbox /> component.`); throw Error.captureStackTrace && Error.captureStackTrace(o4, Q2), o4; } return i2; } function Rt(e2, i2) { return u2(i2.type, Pt, e2, i2); } var At = xe2; function ht(e2, i2) { var me; let o4 = a(), { value: r4, defaultValue: a2, form: m2, name: x2, onChange: d2, by: p3, invalid: n4 = false, disabled: u8 = o4 || false, horizontal: P = false, multiple: t = false, __demoMode: s4 = false, ...F2 } = e2; const M = P ? "horizontal" : "vertical"; let h2 = y(i2), D = l(a2), [O2 = t ? [] : void 0, g] = T(r4, d2, D), [R3, y3] = Ie(Rt, { dataRef: De(), listboxState: s4 ? 0 : 1, options: [], searchQuery: "", activeOptionIndex: null, activationTrigger: 1, optionsVisible: false, buttonElement: null, optionsElement: null, __demoMode: s4 }), B = ue({ static: false, hold: false }), w2 = ue(/* @__PURE__ */ new Map()), _3 = u6(p3), b = se((f3) => u2(c3.mode, { [1]: () => O2.some((S) => _3(S, f3)), [0]: () => _3(O2, f3) }), [O2]), c3 = k(() => ({ ...R3, value: O2, disabled: u8, invalid: n4, mode: t ? 1 : 0, orientation: M, compare: _3, isSelected: b, optionsPropsRef: B, listRef: w2 }), [O2, u8, n4, t, R3, w2]); n(() => { R3.dataRef.current = c3; }, [c3]); let N = c3.listboxState === 0; R(N, [c3.buttonElement, c3.optionsElement], (f3, S) => { var C; y3({ type: 1 }), A(S, h.Loose) || (f3.preventDefault(), (C = c3.buttonElement) == null || C.focus()); }); let L2 = k(() => ({ open: c3.listboxState === 0, disabled: u8, invalid: n4, value: O2 }), [c3, u8, O2, n4]), H = o2((f3) => { let S = c3.options.find((C) => C.id === f3); S && K3(S.dataRef.current.value); }), te = o2(() => { if (c3.activeOptionIndex !== null) { let { dataRef: f3, id: S } = c3.options[c3.activeOptionIndex]; K3(f3.current.value), y3({ type: 2, focus: c2.Specific, id: S }); } }), oe = o2(() => y3({ type: 0 })), X = o2(() => y3({ type: 1 })), J = p(), ne = o2((f3, S, C) => { J.dispose(), J.microTask(() => f3 === c2.Specific ? y3({ type: 2, focus: c2.Specific, id: S, trigger: C }) : y3({ type: 2, focus: f3, trigger: C })); }), ie = o2((f3, S) => (y3({ type: 5, id: f3, dataRef: S }), () => y3({ type: 6, id: f3 }))), K3 = o2((f3) => u2(c3.mode, { [0]() { return g == null ? void 0 : g(f3); }, [1]() { let S = c3.value.slice(), C = S.findIndex((Re2) => _3(Re2, f3)); return C === -1 ? S.push(f3) : S.splice(C, 1), g == null ? void 0 : g(S); } })), re2 = o2((f3) => y3({ type: 3, value: f3 })), $ = o2(() => y3({ type: 4 })), q = o2((f3) => { y3({ type: 7, element: f3 }); }), l4 = o2((f3) => { y3({ type: 8, element: f3 }); }), I2 = k(() => ({ onChange: K3, registerOption: ie, goToOption: ne, closeListbox: X, openListbox: oe, selectActiveOption: te, selectOption: H, search: re2, clearSearch: $, setButtonElement: q, setOptionsElement: l4 }), []), [G, le] = K2({ inherit: true }), Se = { ref: h2 }, Ee = se(() => { if (D !== void 0) return g == null ? void 0 : g(D); }, [g, D]), Pe = L(); return A2.createElement(le, { value: G, props: { htmlFor: (me = c3.buttonElement) == null ? void 0 : me.id }, slot: { open: c3.listboxState === 0, disabled: u8 } }, A2.createElement(Me, null, A2.createElement(Te.Provider, { value: I2 }, A2.createElement(ee.Provider, { value: c3 }, A2.createElement(c, { value: u2(c3.listboxState, { [0]: i.Open, [1]: i.Closed }) }, x2 != null && O2 != null && A2.createElement(j, { disabled: u8, data: { [x2]: O2 }, form: m2, onReset: Ee }), Pe({ ourProps: Se, theirProps: F2, slot: L2, defaultTag: At, name: "Listbox" })))))); } var Dt = "button"; function _t(e2, i2) { var N; let o4 = Q2("Listbox.Button"), r4 = Z("Listbox.Button"), a2 = r(), m2 = u3(), { id: x2 = m2 || `headlessui-listbox-button-${a2}`, disabled: d2 = o4.disabled || false, autoFocus: p3 = false, ...n4 } = e2, u8 = y(i2, ye(), r4.setButtonElement), P = Fe(), t = o2((L2) => { switch (L2.key) { case o3.Enter: p2(L2.currentTarget); break; case o3.Space: case o3.ArrowDown: L2.preventDefault(), U2(() => r4.openListbox()), o4.value || r4.goToOption(c2.First); break; case o3.ArrowUp: L2.preventDefault(), U2(() => r4.openListbox()), o4.value || r4.goToOption(c2.Last); break; } }), s4 = o2((L2) => { switch (L2.key) { case o3.Space: L2.preventDefault(); break; } }), F2 = o2((L2) => { var H; if (r2(L2.currentTarget)) return L2.preventDefault(); o4.listboxState === 0 ? (U2(() => r4.closeListbox()), (H = o4.buttonElement) == null || H.focus({ preventScroll: true })) : (L2.preventDefault(), r4.openListbox()); }), M = o2((L2) => L2.preventDefault()), h2 = I([x2]), D = U(), { isFocusVisible: O2, focusProps: g } = $f7dceffc5ad7768b$export$4e328f61c538687f({ autoFocus: p3 }), { isHovered: R3, hoverProps: y3 } = $6179b936705e76d3$export$ae780daf29e6d456({ isDisabled: d2 }), { pressed: B, pressProps: w2 } = w({ disabled: d2 }), _3 = k(() => ({ open: o4.listboxState === 0, active: B || o4.listboxState === 0, disabled: d2, invalid: o4.invalid, value: o4.value, hover: R3, focus: O2, autofocus: p3 }), [o4.listboxState, o4.value, d2, R3, O2, B, o4.invalid, p3]), b = _(P(), { ref: u8, id: x2, type: e(e2, o4.buttonElement), "aria-haspopup": "listbox", "aria-controls": (N = o4.optionsElement) == null ? void 0 : N.id, "aria-expanded": o4.listboxState === 0, "aria-labelledby": h2, "aria-describedby": D, disabled: d2 || void 0, autoFocus: p3, onKeyDown: t, onKeyUp: s4, onKeyPress: M, onClick: F2 }, g, y3, w2); return L()({ ourProps: b, theirProps: n4, slot: _3, defaultTag: Dt, name: "Listbox.Button" }); } var Le = ae(false); var It = "div"; var Ct = O.RenderStrategy | O.Static; function Ft(e2, i2) { var $, q; let o4 = r(), { id: r4 = `headlessui-listbox-options-${o4}`, anchor: a2, portal: m2 = false, modal: x2 = true, transition: d2 = false, ...p3 } = e2, n4 = xe(a2), [u8, P] = Ce(null); n4 && (m2 = true); let t = Q2("Listbox.Options"), s4 = Z("Listbox.Options"), F2 = n2(t.optionsElement), M = u5(), [h2, D] = x(d2, u8, M !== null ? (M & i.Open) === i.Open : t.listboxState === 0); m(h2, t.buttonElement, s4.closeListbox); let O2 = t.__demoMode ? false : x2 && t.listboxState === 0; f(O2, F2); let g = t.__demoMode ? false : x2 && t.listboxState === 0; y2(g, { allowed: se(() => [t.buttonElement, t.optionsElement], [t.buttonElement, t.optionsElement]) }); let R3 = t.listboxState !== 0, B = s2(R3, t.buttonElement) ? false : h2, w2 = h2 && t.listboxState === 1, _3 = l3(w2, t.value), b = o2((l4) => t.compare(_3, l4)), c3 = k(() => { var I2; if (n4 == null || !((I2 = n4 == null ? void 0 : n4.to) != null && I2.includes("selection"))) return null; let l4 = t.options.findIndex((G) => b(G.dataRef.current.value)); return l4 === -1 && (l4 = 0), l4; }, [n4, t.options]), N = (() => { if (n4 == null) return; if (c3 === null) return { ...n4, inner: void 0 }; let l4 = Array.from(t.listRef.current.values()); return { ...n4, inner: { listRef: { current: l4 }, index: c3 } }; })(), [L2, H] = Re(N), te = be(), oe = y(i2, n4 ? L2 : null, s4.setOptionsElement, P), X = p(); _e(() => { var I2; let l4 = t.optionsElement; l4 && t.listboxState === 0 && l4 !== ((I2 = u(l4)) == null ? void 0 : I2.activeElement) && (l4 == null || l4.focus({ preventScroll: true })); }, [t.listboxState, t.optionsElement]); let J = o2((l4) => { var I2, G; switch (X.dispose(), l4.key) { case o3.Space: if (t.searchQuery !== "") return l4.preventDefault(), l4.stopPropagation(), s4.search(l4.key); case o3.Enter: if (l4.preventDefault(), l4.stopPropagation(), t.activeOptionIndex !== null) { let { dataRef: le } = t.options[t.activeOptionIndex]; s4.onChange(le.current.value); } t.mode === 0 && (U2(() => s4.closeListbox()), (I2 = t.buttonElement) == null || I2.focus({ preventScroll: true })); break; case u2(t.orientation, { vertical: o3.ArrowDown, horizontal: o3.ArrowRight }): return l4.preventDefault(), l4.stopPropagation(), s4.goToOption(c2.Next); case u2(t.orientation, { vertical: o3.ArrowUp, horizontal: o3.ArrowLeft }): return l4.preventDefault(), l4.stopPropagation(), s4.goToOption(c2.Previous); case o3.Home: case o3.PageUp: return l4.preventDefault(), l4.stopPropagation(), s4.goToOption(c2.First); case o3.End: case o3.PageDown: return l4.preventDefault(), l4.stopPropagation(), s4.goToOption(c2.Last); case o3.Escape: l4.preventDefault(), l4.stopPropagation(), U2(() => s4.closeListbox()), (G = t.buttonElement) == null || G.focus({ preventScroll: true }); return; case o3.Tab: l4.preventDefault(), l4.stopPropagation(), U2(() => s4.closeListbox()), j2(t.buttonElement, l4.shiftKey ? F.Previous : F.Next); break; default: l4.key.length === 1 && (s4.search(l4.key), X.setTimeout(() => s4.clearSearch(), 350)); break; } }), ne = ($ = t.buttonElement) == null ? void 0 : $.id, ie = k(() => ({ open: t.listboxState === 0 }), [t.listboxState]), K3 = _(n4 ? te() : {}, { id: r4, ref: oe, "aria-activedescendant": t.activeOptionIndex === null || (q = t.options[t.activeOptionIndex]) == null ? void 0 : q.id, "aria-multiselectable": t.mode === 1 ? true : void 0, "aria-labelledby": ne, "aria-orientation": t.orientation, onKeyDown: J, role: "listbox", tabIndex: t.listboxState === 0 ? 0 : void 0, style: { ...p3.style, ...H, "--button-width": d(t.buttonElement, true).width }, ...R2(D) }), re2 = L(); return A2.createElement(re, { enabled: m2 ? e2.static || h2 : false }, A2.createElement(ee.Provider, { value: t.mode === 1 ? t : { ...t, isSelected: b } }, re2({ ourProps: K3, theirProps: p3, slot: ie, defaultTag: It, features: Ct, visible: B, name: "Listbox.Options" }))); } var Mt = "div"; function Bt(e2, i2) { let o4 = r(), { id: r4 = `headlessui-listbox-option-${o4}`, disabled: a2 = false, value: m2, ...x2 } = e2, d2 = pe(Le) === true, p3 = Q2("Listbox.Option"), n4 = Z("Listbox.Option"), u8 = p3.activeOptionIndex !== null ? p3.options[p3.activeOptionIndex].id === r4 : false, P = p3.isSelected(m2), t = ue(null), s4 = s3(t), F2 = s({ disabled: a2, value: m2, domRef: t, get textValue() { return s4(); } }), M = y(i2, t, (b) => { b ? p3.listRef.current.set(r4, b) : p3.listRef.current.delete(r4); }); n(() => { if (!p3.__demoMode && p3.listboxState === 0 && u8 && p3.activationTrigger !== 0) return o().requestAnimationFrame(() => { var b, c3; (c3 = (b = t.current) == null ? void 0 : b.scrollIntoView) == null || c3.call(b, { block: "nearest" }); }); }, [t, u8, p3.__demoMode, p3.listboxState, p3.activationTrigger, p3.activeOptionIndex]), n(() => { if (!d2) return n4.registerOption(r4, F2); }, [F2, r4, d2]); let h2 = o2((b) => { var c3; if (a2) return b.preventDefault(); n4.onChange(m2), p3.mode === 0 && (U2(() => n4.closeListbox()), (c3 = p3.buttonElement) == null || c3.focus({ preventScroll: true })); }), D = o2(() => { if (a2) return n4.goToOption(c2.Nothing); n4.goToOption(c2.Specific, r4); }), O2 = u4(), g = o2((b) => { O2.update(b), !a2 && (u8 || n4.goToOption(c2.Specific, r4, 0)); }), R3 = o2((b) => { O2.wasMoved(b) && (a2 || u8 || n4.goToOption(c2.Specific, r4, 0)); }), y3 = o2((b) => { O2.wasMoved(b) && (a2 || u8 && n4.goToOption(c2.Nothing)); }), B = k(() => ({ active: u8, focus: u8, selected: P, disabled: a2, selectedOption: P && d2 }), [u8, P, a2, d2]), w2 = d2 ? {} : { id: r4, ref: M, role: "option", tabIndex: a2 === true ? void 0 : -1, "aria-disabled": a2 === true ? true : void 0, "aria-selected": P, disabled: void 0, onClick: h2, onFocus: D, onPointerEnter: g, onMouseEnter: g, onPointerMove: R3, onMouseMove: R3, onPointerLeave: y3, onMouseLeave: y3 }, _3 = L(); return !P && d2 ? null : _3({ ourProps: w2, theirProps: x2, slot: B, defaultTag: Mt, name: "Listbox.Option" }); } var wt = xe2; function kt(e2, i2) { let { options: o4, placeholder: r4, ...a2 } = e2, x2 = { ref: y(i2) }, d2 = Q2("ListboxSelectedOption"), p3 = k(() => ({}), []), n4 = d2.value === void 0 || d2.value === null || d2.mode === 1 && Array.isArray(d2.value) && d2.value.length === 0, u8 = L(); return A2.createElement(Le.Provider, { value: true }, u8({ ourProps: x2, theirProps: { ...a2, children: A2.createElement(A2.Fragment, null, r4 && n4 ? r4 : o4) }, slot: p3, defaultTag: wt, name: "ListboxSelectedOption" })); } var Ut = K(ht); var Nt = K(_t); var Ht = Q; var Gt = K(Ft); var Vt = K(Bt); var Kt = K(kt); var Mo = Object.assign(Ut, { Button: Nt, Label: Ht, Options: Gt, Option: Vt, SelectedOption: Kt }); export { Mo };