@viasat/beam-react 2.14.0 → 2.16.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/chunks/combobox.--djB8BC.js +4 -0
- package/chunks/combobox.9scnST_n.js +1 -0
- package/lib/Autocomplete/useAutocompleteDropdown.cjs.js +1 -1
- package/lib/Autocomplete/useAutocompleteDropdown.es.js +80 -72
- package/lib/Select/useSelectDropdown.cjs.js +1 -1
- package/lib/Select/useSelectDropdown.es.js +40 -38
- package/lib/wip/Search/useSearchDropdown.cjs.js +1 -1
- package/lib/wip/Search/useSearchDropdown.es.js +49 -42
- package/package.json +6 -6
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const o = "var(--bm-combobox-dropdown-max-items, 8)", e = "var(--bm-comp-actionlist-size-height, 2.5rem)", c = "var(--bm-sem-space-50, 0.5rem)", t = "var(--bm-sem-space-100, 1rem)", a = (m) => `min(calc(${m}px - ${t}), calc(${o} * ${e} + 2 * ${c}))`;
|
|
2
|
+
export {
|
|
3
|
+
a as g
|
|
4
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const o="var(--bm-combobox-dropdown-max-items, 8)",e="var(--bm-comp-actionlist-size-height, 2.5rem)",t="var(--bm-sem-space-50, 0.5rem)",c="var(--bm-sem-space-100, 1rem)",s=m=>`min(calc(${m}px - ${c}), calc(${o} * ${e} + 2 * ${t}))`;exports.getDropdownMaxHeight=s;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("../../chunks/constants.hwjHOsvT.js"),ne=require("../../chunks/dom.zgzOBFUw.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("../../chunks/constants.hwjHOsvT.js"),ne=require("../../chunks/dom.zgzOBFUw.js"),u=require("@floating-ui/react"),t=require("react"),se=require("../../chunks/combobox.9scnST_n.js"),oe=`${te.prefix}combobox__field__chevron`,re=u.flip({crossAxis:!1,mainAxis:!0,flipAlignment:!1}),ce=U=>{const{disabled:O,readOnly:F,lastSelectedOptionIndex:i,fieldRef:p}=U,[s,$]=t.useState(!1),r=t.useRef(null),P=t.useRef(s);P.current=s;const C=u.useFloatingNodeId(),[b,z]=t.useState(null),[g,m]=t.useState(!0),[D,E]=t.useState(!1),I=t.useRef(!1),V=t.useCallback(e=>{b!==e&&(D?(E(!1),i===void 0&&m(!0)):m(!0),z(e))},[b,D,i]),f=t.useCallback((e,n,o)=>{var l;const c=i===void 0&&((l=r.current)==null?void 0:l.value)==="";!e&&o==="click"&&n instanceof MouseEvent&&!c&&!(n.target instanceof HTMLElement&&n.target.classList.contains(oe))||($(e),e&&o==="click"&&(n instanceof MouseEvent||n instanceof PointerEvent)&&(E(!0),m(!1)))},[i,r]),{context:d,refs:a,floatingStyles:S}=u.useFloating({placement:"bottom-start",middleware:[{name:"overrideReference",fn:async e=>{const n=ne.getElementScrollBoundingClientRect(p.current),o=n?{...e.rects,reference:n}:e.rects,c=await re.fn({...e,rects:o}),l=typeof c.reset=="object"?c.reset.placement:void 0;return l?{reset:{placement:l,rects:o}}:n?{reset:{rects:o}}:{}}},u.size({apply({elements:e,rects:n,availableHeight:o}){Object.assign(e.floating.style,{width:`${n.reference.width}px`,maxHeight:se.getDropdownMaxHeight(o)})}})],whileElementsMounted:u.autoUpdate,open:s,onOpenChange:f,nodeId:C});r.current=a.domReference.current;const y=t.useCallback(e=>{I.current=!0,e.target!==r.current&&e.preventDefault()},[r]),k=t.useCallback(e=>{I.current=!1,e.target!==r.current&&e.preventDefault()},[r]),v=t.useRef([]),G=t.useRef([]),J=u.useClick(d,{enabled:!O&&!F,keyboardHandlers:!1}),Q=u.useRole(d,{role:"listbox"}),W=u.useDismiss(d,{outsidePress:!1}),x=v.current.length===0?null:b??null,M=t.useRef(i??null),X=t.useMemo(()=>s?M.current:(M.current=i??null,v.current.length===0?null:i??null),[i,s]),Y=u.useListNavigation(d,{enabled:!O&&!F,listRef:v,activeIndex:x,selectedIndex:X,onNavigate:V,focusItemOnHover:!1,focusItemOnOpen:"auto",openOnArrowKeyDown:!0,nested:!1,loop:!0,virtual:!0,scrollItemIntoView:!0}),{getReferenceProps:h,getFloatingProps:A,getItemProps:K}=u.useInteractions([Q,W,Y]),{getReferenceProps:_}=u.useInteractions([J]),[q,Z]=t.useState(s);t.useEffect(()=>Z(s),[s]);const R=s?"open":"closed",w=t.useCallback(e=>{var l;if(!s)return;const n=e.type==="focus"?e.target:e.relatedTarget,o=a.floating.current,c=p.current;if(o!=null&&o.contains(n)||c!=null&&c.contains(n)||I.current){e.preventDefault(),e.stopPropagation(),(l=r.current)==null||l.focus();return}f(!1,e.nativeEvent,"focus-out")},[p,s,r,a.floating,f]),H=t.useRef(s);t.useEffect(()=>{var e;H.current&&!s&&((e=r.current)==null||e.focus()),H.current=s},[s,r]);const T=t.useCallback((e={})=>({ref:a.setReference,...h({...e})}),[a.setReference,h]),N=t.useCallback((e={})=>({ref:p,onKeyDownCapture:n=>{var L;const o=P.current,c=r.current,l=c==null?void 0:c.getAttribute("aria-activedescendant"),B=l?document.getElementById(l):null;if(n.key==="Enter"&&o){if(n.preventDefault(),n.stopPropagation(),g&&B){const ee=new KeyboardEvent("keydown",n.nativeEvent);B.dispatchEvent(ee)}return}(L=e.onKeyDownCapture)==null||L.call(e,n)},onFocusCapture:w,onBlurCapture:w,..._({...e,onMouseDownCapture:y,onMouseUpCapture:k,onPointerDownCapture:y,onPointerUpCapture:k})}),[p,w,_,y,k,r,g]),j=t.useMemo(()=>({isMounted:q,status:R,getFloatingProps:A,getItemProps:K,floatingStyles:S,setOpen:f,nodeId:C,context:d,labelsRef:G,elementsRef:v,setFloating:a.setFloating,activeIndex:g?x:null}),[q,R,A,K,S,f,C,d,a.setFloating,x,g]);return t.useMemo(()=>({getFieldProps:N,getInputProps:T,dropdownProps:j,refs:a,open:s,setOpen:f,status:R,setDisplayActiveIndex:m}),[j,N,T,s,a,f,R])};exports.useAutocompleteDropdown=ce;
|
|
@@ -1,51 +1,59 @@
|
|
|
1
1
|
import { p as re } from "../../chunks/constants.CKKGf1-i.js";
|
|
2
2
|
import { g as ce } from "../../chunks/dom.DGM-dxLe.js";
|
|
3
|
-
import {
|
|
4
|
-
import { useState as g, useRef as u, useCallback as f, useMemo as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
D
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
import { flip as ie, useFloatingNodeId as le, useFloating as ae, autoUpdate as ue, size as fe, useClick as de, useRole as pe, useDismiss as ge, useListNavigation as me, useInteractions as V } from "@floating-ui/react";
|
|
4
|
+
import { useState as g, useRef as u, useCallback as f, useMemo as P, useEffect as q } from "react";
|
|
5
|
+
import { g as ve } from "../../chunks/combobox.--djB8BC.js";
|
|
6
|
+
const Ie = `${re}combobox__field__chevron`, xe = ie({ crossAxis: !1, mainAxis: !0, flipAlignment: !1 }), ke = (G) => {
|
|
7
|
+
const { disabled: b, readOnly: D, lastSelectedOptionIndex: l, fieldRef: p } = G, [n, J] = g(!1), s = u(null), E = u(n);
|
|
8
|
+
E.current = n;
|
|
9
|
+
const y = le(), [w, Q] = g(null), [m, v] = g(!0), [h, A] = g(!1), C = u(!1), W = f((e) => {
|
|
10
|
+
w !== e && (h ? (A(!1), l === void 0 && v(!0)) : v(!0), Q(e));
|
|
11
|
+
}, [w, h, l]), a = f((e, t, o) => {
|
|
12
|
+
var c;
|
|
13
|
+
const r = l === void 0 && ((c = s.current) == null ? void 0 : c.value) === "";
|
|
14
|
+
!e && o === "click" && t instanceof MouseEvent && !r && !(t.target instanceof HTMLElement && t.target.classList.contains(Ie)) || (J(e), e && o === "click" && (t instanceof MouseEvent || t instanceof PointerEvent) && (A(!0), v(!1)));
|
|
15
|
+
}, [l, s]), { context: d, refs: i, floatingStyles: M } = ae({
|
|
15
16
|
placement: "bottom-start",
|
|
16
17
|
middleware: [
|
|
18
|
+
// Floating UI does not re-run flip() after a middleware returns `reset` with
|
|
19
|
+
// overridden rects, so we manually invoke flip inside this custom middleware
|
|
20
|
+
// to ensure the dropdown flips correctly when the reference rect is replaced.
|
|
17
21
|
{
|
|
18
22
|
name: "overrideReference",
|
|
19
|
-
fn: (
|
|
20
|
-
|
|
21
|
-
rects
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
fn: async (e) => {
|
|
24
|
+
const t = ce(p.current), o = t ? {
|
|
25
|
+
...e.rects,
|
|
26
|
+
reference: t
|
|
27
|
+
} : e.rects, r = await xe.fn({ ...e, rects: o }), c = typeof r.reset == "object" ? r.reset.placement : void 0;
|
|
28
|
+
return c ? {
|
|
29
|
+
reset: {
|
|
30
|
+
placement: c,
|
|
31
|
+
rects: o
|
|
24
32
|
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
33
|
+
} : t ? { reset: { rects: o } } : {};
|
|
34
|
+
}
|
|
27
35
|
},
|
|
28
|
-
ue(),
|
|
29
36
|
fe({
|
|
30
|
-
apply({ elements: e, rects:
|
|
37
|
+
apply({ elements: e, rects: t, availableHeight: o }) {
|
|
31
38
|
Object.assign(e.floating.style, {
|
|
32
|
-
width: `${
|
|
39
|
+
width: `${t.reference.width}px`,
|
|
40
|
+
maxHeight: ve(o)
|
|
33
41
|
});
|
|
34
42
|
}
|
|
35
43
|
})
|
|
36
44
|
],
|
|
37
|
-
whileElementsMounted:
|
|
38
|
-
open:
|
|
45
|
+
whileElementsMounted: ue,
|
|
46
|
+
open: n,
|
|
39
47
|
onOpenChange: a,
|
|
40
48
|
nodeId: y
|
|
41
49
|
});
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
}, [
|
|
46
|
-
|
|
47
|
-
}, [
|
|
48
|
-
enabled: !
|
|
50
|
+
s.current = i.domReference.current;
|
|
51
|
+
const R = f((e) => {
|
|
52
|
+
C.current = !0, e.target !== s.current && e.preventDefault();
|
|
53
|
+
}, [s]), O = f((e) => {
|
|
54
|
+
C.current = !1, e.target !== s.current && e.preventDefault();
|
|
55
|
+
}, [s]), I = u([]), X = u([]), Y = de(d, { enabled: !b && !D, keyboardHandlers: !1 }), Z = pe(d, { role: "listbox" }), ee = ge(d, { outsidePress: !1 }), F = I.current.length === 0 ? null : w ?? null, S = u(l ?? null), te = P(() => n ? S.current : (S.current = l ?? null, I.current.length === 0 ? null : l ?? null), [l, n]), ne = me(d, {
|
|
56
|
+
enabled: !b && !D,
|
|
49
57
|
listRef: I,
|
|
50
58
|
activeIndex: F,
|
|
51
59
|
selectedIndex: te,
|
|
@@ -57,95 +65,95 @@ const ve = `${re}combobox__field__chevron`, Oe = (G) => {
|
|
|
57
65
|
loop: !0,
|
|
58
66
|
virtual: !0,
|
|
59
67
|
scrollItemIntoView: !0
|
|
60
|
-
}), { getReferenceProps: K, getFloatingProps: _, getItemProps:
|
|
68
|
+
}), { getReferenceProps: K, getFloatingProps: _, getItemProps: H } = V([
|
|
61
69
|
Z,
|
|
62
70
|
ee,
|
|
63
71
|
ne
|
|
64
|
-
]), { getReferenceProps:
|
|
65
|
-
q(() => oe(
|
|
66
|
-
const
|
|
72
|
+
]), { getReferenceProps: N } = V([Y]), [T, oe] = g(n);
|
|
73
|
+
q(() => oe(n), [n]);
|
|
74
|
+
const x = n ? "open" : "closed", k = f(
|
|
67
75
|
(e) => {
|
|
68
|
-
var
|
|
69
|
-
if (!
|
|
76
|
+
var c;
|
|
77
|
+
if (!n)
|
|
70
78
|
return;
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
e.preventDefault(), e.stopPropagation(), (
|
|
79
|
+
const t = e.type === "focus" ? e.target : e.relatedTarget, o = i.floating.current, r = p.current;
|
|
80
|
+
if (o != null && o.contains(t) || r != null && r.contains(t) || C.current) {
|
|
81
|
+
e.preventDefault(), e.stopPropagation(), (c = s.current) == null || c.focus();
|
|
74
82
|
return;
|
|
75
83
|
}
|
|
76
84
|
a(!1, e.nativeEvent, "focus-out");
|
|
77
85
|
},
|
|
78
|
-
[p,
|
|
79
|
-
),
|
|
86
|
+
[p, n, s, i.floating, a]
|
|
87
|
+
), B = u(n);
|
|
80
88
|
q(() => {
|
|
81
89
|
var e;
|
|
82
|
-
|
|
83
|
-
}, [
|
|
90
|
+
B.current && !n && ((e = s.current) == null || e.focus()), B.current = n;
|
|
91
|
+
}, [n, s]);
|
|
84
92
|
const L = f(
|
|
85
93
|
(e = {}) => ({
|
|
86
|
-
ref:
|
|
94
|
+
ref: i.setReference,
|
|
87
95
|
...K({
|
|
88
96
|
...e
|
|
89
97
|
})
|
|
90
98
|
}),
|
|
91
|
-
[
|
|
99
|
+
[i.setReference, K]
|
|
92
100
|
), U = f(
|
|
93
101
|
(e = {}) => ({
|
|
94
102
|
ref: p,
|
|
95
|
-
onKeyDownCapture: (
|
|
103
|
+
onKeyDownCapture: (t) => {
|
|
96
104
|
var z;
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
if (
|
|
100
|
-
const se = new KeyboardEvent("keydown",
|
|
101
|
-
|
|
105
|
+
const o = E.current, r = s.current, c = r == null ? void 0 : r.getAttribute("aria-activedescendant"), $ = c ? document.getElementById(c) : null;
|
|
106
|
+
if (t.key === "Enter" && o) {
|
|
107
|
+
if (t.preventDefault(), t.stopPropagation(), m && $) {
|
|
108
|
+
const se = new KeyboardEvent("keydown", t.nativeEvent);
|
|
109
|
+
$.dispatchEvent(se);
|
|
102
110
|
}
|
|
103
111
|
return;
|
|
104
112
|
}
|
|
105
|
-
(z = e.onKeyDownCapture) == null || z.call(e,
|
|
113
|
+
(z = e.onKeyDownCapture) == null || z.call(e, t);
|
|
106
114
|
},
|
|
107
115
|
onFocusCapture: k,
|
|
108
116
|
onBlurCapture: k,
|
|
109
|
-
...
|
|
117
|
+
...N({
|
|
110
118
|
...e,
|
|
111
|
-
onMouseDownCapture:
|
|
112
|
-
onMouseUpCapture:
|
|
113
|
-
onPointerDownCapture:
|
|
114
|
-
onPointerUpCapture:
|
|
119
|
+
onMouseDownCapture: R,
|
|
120
|
+
onMouseUpCapture: O,
|
|
121
|
+
onPointerDownCapture: R,
|
|
122
|
+
onPointerUpCapture: O
|
|
115
123
|
})
|
|
116
124
|
}),
|
|
117
|
-
[p, k,
|
|
118
|
-
),
|
|
125
|
+
[p, k, N, R, O, s, m]
|
|
126
|
+
), j = P(
|
|
119
127
|
() => ({
|
|
120
|
-
isMounted:
|
|
121
|
-
status:
|
|
128
|
+
isMounted: T,
|
|
129
|
+
status: x,
|
|
122
130
|
getFloatingProps: _,
|
|
123
|
-
getItemProps:
|
|
131
|
+
getItemProps: H,
|
|
124
132
|
floatingStyles: M,
|
|
125
133
|
setOpen: a,
|
|
126
134
|
nodeId: y,
|
|
127
135
|
context: d,
|
|
128
136
|
labelsRef: X,
|
|
129
137
|
elementsRef: I,
|
|
130
|
-
setFloating:
|
|
138
|
+
setFloating: i.setFloating,
|
|
131
139
|
activeIndex: m ? F : null
|
|
132
140
|
}),
|
|
133
|
-
[
|
|
141
|
+
[T, x, _, H, M, a, y, d, i.setFloating, F, m]
|
|
134
142
|
);
|
|
135
|
-
return
|
|
143
|
+
return P(
|
|
136
144
|
() => ({
|
|
137
145
|
getFieldProps: U,
|
|
138
146
|
getInputProps: L,
|
|
139
|
-
dropdownProps:
|
|
140
|
-
refs:
|
|
141
|
-
open:
|
|
147
|
+
dropdownProps: j,
|
|
148
|
+
refs: i,
|
|
149
|
+
open: n,
|
|
142
150
|
setOpen: a,
|
|
143
|
-
status:
|
|
151
|
+
status: x,
|
|
144
152
|
setDisplayActiveIndex: v
|
|
145
153
|
}),
|
|
146
|
-
[
|
|
154
|
+
[j, U, L, n, i, a, x]
|
|
147
155
|
);
|
|
148
156
|
};
|
|
149
157
|
export {
|
|
150
|
-
|
|
158
|
+
ke as useAutocompleteDropdown
|
|
151
159
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@floating-ui/react"),t=require("react"),Q=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@floating-ui/react"),t=require("react"),Q=require("../../chunks/combobox.9scnST_n.js"),W=j=>{const{disabled:v,readOnly:m,lastSelectedOptionIndex:i}=j,[n,B]=t.useState(!1),x=t.useRef(n);x.current=n;const I=c.useFloatingNodeId(),[R,z]=t.useState(null),[d,y]=t.useState(!0),[w,S]=t.useState(!1),k=t.useCallback(e=>{R!==e&&(w?(S(!1),i===void 0&&y(!0)):y(!0),z(e))},[R,w,i]),l=t.useCallback((e,o,a)=>{B(e),e&&a==="click"&&o instanceof PointerEvent&&(S(!0),y(!1))},[]),{context:u,refs:s,floatingStyles:O}=c.useFloating({placement:"bottom-start",middleware:[c.flip(),c.size({apply({rects:e,elements:o,availableHeight:a}){Object.assign(o.floating.style,{width:`${e.reference.width}px`,maxHeight:Q.getDropdownMaxHeight(a)})}})],whileElementsMounted:c.autoUpdate,open:n,onOpenChange:l,nodeId:I}),f=t.useRef([]),h=t.useRef([]),L=c.useClick(u,{enabled:!v&&!m,keyboardHandlers:!0}),U=c.useRole(u,{role:"listbox"}),V=c.useDismiss(u),g=f.current.length===0?null:R??null,C=t.useRef(i??null),D=t.useMemo(()=>n?C.current:(C.current=i??null,f.current.length===0?null:i??null),[i,n]),_=c.useListNavigation(u,{enabled:!v&&!m,listRef:f,activeIndex:g,selectedIndex:D,onNavigate:k,focusItemOnHover:!1,focusItemOnOpen:"auto",openOnArrowKeyDown:!0,nested:!1,loop:!0,virtual:!0,scrollItemIntoView:!0}),$=c.useTypeahead(u,{enabled:!v&&!m,listRef:h,activeIndex:g,selectedIndex:D,onMatch:k}),{getReferenceProps:F,getFloatingProps:E,getItemProps:M}=c.useInteractions([L,U,V,_,$]),[P,G]=t.useState(n);t.useEffect(()=>G(n),[n]);const p=n?"open":"closed",b=t.useCallback(e=>{if(!n)return;const o=e.type==="focus"?e.target:e.relatedTarget,a=s.floating.current,r=s.domReference.current;if(a!=null&&a.contains(o)||r!=null&&r.contains(o)){e.preventDefault(),e.stopPropagation(),r==null||r.focus();return}l(!1,e.nativeEvent,"focus-out")},[n,s.domReference,s.floating,l]),A=t.useRef(n);t.useEffect(()=>{var e;A.current&&!n&&((e=s.domReference.current)==null||e.focus()),A.current=n},[n,s.domReference]);const K=t.useCallback((e={})=>({ref:s.setReference,...F({...e,onKeyDownCapture:o=>{var q;const a=x.current,r=s.domReference.current,H=r==null?void 0:r.getAttribute("aria-activedescendant"),N=H?document.getElementById(H):null;if((o.key==="Enter"||o.key===" ")&&a){if(o.preventDefault(),o.stopPropagation(),d&&N){const J=new KeyboardEvent("keydown",o.nativeEvent);N.dispatchEvent(J)}return}(q=e.onKeyDownCapture)==null||q.call(e,o)},onFocusCapture:b,onBlurCapture:b})}),[s.setReference,s.domReference,F,b,d]),T=t.useMemo(()=>({isMounted:P,status:p,getFloatingProps:E,getItemProps:M,floatingStyles:O,setOpen:l,nodeId:I,context:u,labelsRef:h,elementsRef:f,setFloating:s.setFloating,activeIndex:d?g:null}),[P,p,E,M,O,l,I,u,s.setFloating,g,d]);return t.useMemo(()=>({getFieldProps:K,dropdownProps:T,refs:s,open:n,setOpen:l,status:p}),[T,K,n,s,l,p])};exports.useSelectDropdown=W;
|
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import { useFloatingNodeId as Y, useFloating as Z, autoUpdate as ee, flip as te, size as ne, useClick as oe, useRole as se, useDismiss as ce, useListNavigation as re, useTypeahead as
|
|
2
|
-
import { useState as i, useRef as u, useCallback as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { useFloatingNodeId as Y, useFloating as Z, autoUpdate as ee, flip as te, size as ne, useClick as oe, useRole as se, useDismiss as ce, useListNavigation as re, useTypeahead as ae, useInteractions as le } from "@floating-ui/react";
|
|
2
|
+
import { useState as i, useRef as u, useCallback as m, useMemo as h, useEffect as L } from "react";
|
|
3
|
+
import { g as ie } from "../../chunks/combobox.--djB8BC.js";
|
|
4
|
+
const ge = (U) => {
|
|
5
|
+
const { disabled: v, readOnly: I, lastSelectedOptionIndex: l } = U, [t, V] = i(!1), O = u(t);
|
|
6
|
+
O.current = t;
|
|
7
|
+
const y = Y(), [x, _] = i(null), [d, R] = i(!0), [b, k] = i(!1), F = m((e) => {
|
|
8
|
+
x !== e && (b ? (k(!1), l === void 0 && R(!0)) : R(!0), _(e));
|
|
9
|
+
}, [x, b, l]), r = m((e, o, c) => {
|
|
10
|
+
V(e), e && c === "click" && o instanceof PointerEvent && (k(!0), R(!1));
|
|
11
|
+
}, []), { context: a, refs: n, floatingStyles: C } = Z({
|
|
11
12
|
placement: "bottom-start",
|
|
12
13
|
middleware: [
|
|
13
14
|
te(),
|
|
14
15
|
ne({
|
|
15
|
-
apply({ rects: e, elements: o }) {
|
|
16
|
+
apply({ rects: e, elements: o, availableHeight: c }) {
|
|
16
17
|
Object.assign(o.floating.style, {
|
|
17
|
-
width: `${e.reference.width}px
|
|
18
|
+
width: `${e.reference.width}px`,
|
|
19
|
+
maxHeight: ie(c)
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
})
|
|
21
23
|
],
|
|
22
24
|
whileElementsMounted: ee,
|
|
23
25
|
open: t,
|
|
24
|
-
onOpenChange:
|
|
26
|
+
onOpenChange: r,
|
|
25
27
|
nodeId: y
|
|
26
|
-
}), f = u([]), D = u([]), $ = oe(
|
|
27
|
-
enabled: !
|
|
28
|
+
}), f = u([]), D = u([]), $ = oe(a, { enabled: !v && !I, keyboardHandlers: !0 }), q = se(a, { role: "listbox" }), G = ce(a), p = f.current.length === 0 ? null : x ?? null, E = u(l ?? null), S = h(() => t ? E.current : (E.current = l ?? null, f.current.length === 0 ? null : l ?? null), [l, t]), J = re(a, {
|
|
29
|
+
enabled: !v && !I,
|
|
28
30
|
listRef: f,
|
|
29
31
|
activeIndex: p,
|
|
30
32
|
selectedIndex: S,
|
|
@@ -36,13 +38,13 @@ const fe = (U) => {
|
|
|
36
38
|
loop: !0,
|
|
37
39
|
virtual: !0,
|
|
38
40
|
scrollItemIntoView: !0
|
|
39
|
-
}), Q =
|
|
40
|
-
enabled: !
|
|
41
|
+
}), Q = ae(a, {
|
|
42
|
+
enabled: !v && !I,
|
|
41
43
|
listRef: D,
|
|
42
44
|
activeIndex: p,
|
|
43
45
|
selectedIndex: S,
|
|
44
46
|
onMatch: F
|
|
45
|
-
}), { getReferenceProps: A, getFloatingProps: P, getItemProps: K } =
|
|
47
|
+
}), { getReferenceProps: A, getFloatingProps: P, getItemProps: K } = le([
|
|
46
48
|
$,
|
|
47
49
|
q,
|
|
48
50
|
G,
|
|
@@ -50,32 +52,32 @@ const fe = (U) => {
|
|
|
50
52
|
Q
|
|
51
53
|
]), [M, W] = i(t);
|
|
52
54
|
L(() => W(t), [t]);
|
|
53
|
-
const g = t ? "open" : "closed", w =
|
|
55
|
+
const g = t ? "open" : "closed", w = m(
|
|
54
56
|
(e) => {
|
|
55
57
|
if (!t)
|
|
56
58
|
return;
|
|
57
|
-
const o = e.type === "focus" ? e.target : e.relatedTarget,
|
|
58
|
-
if (
|
|
59
|
+
const o = e.type === "focus" ? e.target : e.relatedTarget, c = n.floating.current, s = n.domReference.current;
|
|
60
|
+
if (c != null && c.contains(o) || s != null && s.contains(o)) {
|
|
59
61
|
e.preventDefault(), e.stopPropagation(), s == null || s.focus();
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
|
-
|
|
64
|
+
r(!1, e.nativeEvent, "focus-out");
|
|
63
65
|
},
|
|
64
|
-
[t, n.domReference, n.floating,
|
|
65
|
-
),
|
|
66
|
+
[t, n.domReference, n.floating, r]
|
|
67
|
+
), H = u(t);
|
|
66
68
|
L(() => {
|
|
67
69
|
var e;
|
|
68
|
-
|
|
70
|
+
H.current && !t && ((e = n.domReference.current) == null || e.focus()), H.current = t;
|
|
69
71
|
}, [t, n.domReference]);
|
|
70
|
-
const
|
|
72
|
+
const N = m(
|
|
71
73
|
(e = {}) => ({
|
|
72
74
|
ref: n.setReference,
|
|
73
75
|
...A({
|
|
74
76
|
...e,
|
|
75
77
|
onKeyDownCapture: (o) => {
|
|
76
78
|
var z;
|
|
77
|
-
const
|
|
78
|
-
if ((o.key === "Enter" || o.key === " ") &&
|
|
79
|
+
const c = O.current, s = n.domReference.current, B = s == null ? void 0 : s.getAttribute("aria-activedescendant"), j = B ? document.getElementById(B) : null;
|
|
80
|
+
if ((o.key === "Enter" || o.key === " ") && c) {
|
|
79
81
|
if (o.preventDefault(), o.stopPropagation(), d && j) {
|
|
80
82
|
const X = new KeyboardEvent("keydown", o.nativeEvent);
|
|
81
83
|
j.dispatchEvent(X);
|
|
@@ -89,35 +91,35 @@ const fe = (U) => {
|
|
|
89
91
|
})
|
|
90
92
|
}),
|
|
91
93
|
[n.setReference, n.domReference, A, w, d]
|
|
92
|
-
),
|
|
94
|
+
), T = h(
|
|
93
95
|
() => ({
|
|
94
96
|
isMounted: M,
|
|
95
97
|
status: g,
|
|
96
98
|
getFloatingProps: P,
|
|
97
99
|
getItemProps: K,
|
|
98
100
|
floatingStyles: C,
|
|
99
|
-
setOpen:
|
|
101
|
+
setOpen: r,
|
|
100
102
|
nodeId: y,
|
|
101
|
-
context:
|
|
103
|
+
context: a,
|
|
102
104
|
labelsRef: D,
|
|
103
105
|
elementsRef: f,
|
|
104
106
|
setFloating: n.setFloating,
|
|
105
107
|
activeIndex: d ? p : null
|
|
106
108
|
}),
|
|
107
|
-
[M, g, P, K, C,
|
|
109
|
+
[M, g, P, K, C, r, y, a, n.setFloating, p, d]
|
|
108
110
|
);
|
|
109
|
-
return
|
|
111
|
+
return h(
|
|
110
112
|
() => ({
|
|
111
|
-
getFieldProps:
|
|
112
|
-
dropdownProps:
|
|
113
|
+
getFieldProps: N,
|
|
114
|
+
dropdownProps: T,
|
|
113
115
|
refs: n,
|
|
114
116
|
open: t,
|
|
115
|
-
setOpen:
|
|
117
|
+
setOpen: r,
|
|
116
118
|
status: g
|
|
117
119
|
}),
|
|
118
|
-
[
|
|
120
|
+
[T, N, t, n, r, g]
|
|
119
121
|
);
|
|
120
122
|
};
|
|
121
123
|
export {
|
|
122
|
-
|
|
124
|
+
ge as useSelectDropdown
|
|
123
125
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@floating-ui/react"),o=require("react"),H=require("../../FloatingUI/useTyping.cjs.js"),_=require("../../FloatingUI/useBlur.cjs.js"),N=h=>{const{disabled:r,readOnly:l,enabled:e=!0}=h,[n,i]=o.useState(!1),d=o.useRef(n);d.current=n;const[f,g]=o.useState(null);o.useEffect(()=>n?void 0:g(null),[n]);const{context:c,refs:a,floatingStyles:p}=s.useFloating({placement:"bottom-start",middleware:[s.flip(),s.size({apply({elements:t,rects:u,availableHeight:S}){Object.assign(t.floating.style,{width:`${u.reference.width}px`}),S<t.floating.scrollHeight?Object.assign(t.floating.style,{maxHeight:`${S}px`,overflowY:"auto"}):Object.assign(t.floating.style,{maxHeight:""})}})],whileElementsMounted:s.autoUpdate,open:n,onOpenChange:i}),b=o.useRef([]),x=o.useRef([]),k=s.useClick(c,{enabled:!n&&e&&!r&&!l,toggle:!1,stickIfOpen:!1,keyboardHandlers:!1}),E=s.useRole(c,{enabled:e,role:"listbox"}),M=H.default(c,{enabled:!n&&e&&!r&&!l,event:"keyboard"}),j=s.useFocus(c,{enabled:!n&&e&&!r&&!l,visibleOnly:!0}),q=s.useDismiss(c,{enabled:n&&e&&!r&&!l,escapeKey:!0,outsidePress:!0,referencePress:!1}),C=_.useBlur(c,{enabled:e&&!r&&!l}),D=s.useListNavigation(c,{enabled:e&&!r&&!l,listRef:b,activeIndex:f,onNavigate:g,focusItemOnHover:!1,focusItemOnOpen:"auto",openOnArrowKeyDown:!0,nested:!1,loop:!0,virtual:!0,scrollItemIntoView:!0}),{getReferenceProps:m,getFloatingProps:y,getItemProps:R}=s.useInteractions([E,M,D]),{getReferenceProps:I}=s.useInteractions([k,j,q,C]),{isMounted:v,styles:O}=s.useTransitionStyles(c,{duration:50});o.useEffect(()=>{if(!e||r||l||d.current)return;const t=a.domReference.current,u=document.activeElement;t&&u&&t.contains(u)&&i(!0)},[e,r,l,i,a.domReference]);const P=o.useCallback((t={})=>e?m(t):t,[m,e]),w=o.useCallback((t={})=>e?{ref:a.setReference,...I(t)}:t,[e,a.setReference,I]),F=o.useMemo(()=>({isMounted:v,getFloatingProps:y,getItemProps:R,floatingStyles:{...p,...O},setOpen:i,labelsRef:x,elementsRef:b,setFloating:a.setFloating,activeIndex:f,open:n}),[v,y,R,p,O,a.setFloating,f,n]);return o.useMemo(()=>({getFieldProps:w,getInputProps:P,dropdownProps:F,refs:a}),[F,w,P,a])};exports.useSearchDropdown=N;
|
|
@@ -1,35 +1,42 @@
|
|
|
1
|
-
import { useFloating as
|
|
2
|
-
import { useState as
|
|
1
|
+
import { useFloating as $, autoUpdate as z, flip as B, size as L, useClick as U, useRole as V, useFocus as Y, useDismiss as q, useListNavigation as G, useInteractions as F, useTransitionStyles as J } from "@floating-ui/react";
|
|
2
|
+
import { useState as h, useRef as u, useEffect as k, useCallback as S, useMemo as E } from "react";
|
|
3
3
|
import Q from "../../FloatingUI/useTyping.es.js";
|
|
4
4
|
import { useBlur as W } from "../../FloatingUI/useBlur.es.js";
|
|
5
|
-
const
|
|
6
|
-
const { disabled: n, readOnly: o, enabled: e = !0 } =
|
|
7
|
-
f.current =
|
|
8
|
-
const [a, d] =
|
|
9
|
-
|
|
10
|
-
const { context: r, refs: l, floatingStyles:
|
|
5
|
+
const te = (H) => {
|
|
6
|
+
const { disabled: n, readOnly: o, enabled: e = !0 } = H, [s, i] = h(!1), f = u(s);
|
|
7
|
+
f.current = s;
|
|
8
|
+
const [a, d] = h(null);
|
|
9
|
+
k(() => s ? void 0 : d(null), [s]);
|
|
10
|
+
const { context: r, refs: l, floatingStyles: g } = $({
|
|
11
11
|
placement: "bottom-start",
|
|
12
12
|
middleware: [
|
|
13
13
|
B(),
|
|
14
|
+
// Search does not cap the dropdown to a fixed number of items like Select
|
|
15
|
+
// and Autocomplete — it shows all results and only constrains to viewport.
|
|
14
16
|
L({
|
|
15
|
-
apply({ elements:
|
|
16
|
-
Object.assign(
|
|
17
|
-
width: `${
|
|
17
|
+
apply({ elements: t, rects: c, availableHeight: x }) {
|
|
18
|
+
Object.assign(t.floating.style, {
|
|
19
|
+
width: `${c.reference.width}px`
|
|
20
|
+
}), x < t.floating.scrollHeight ? Object.assign(t.floating.style, {
|
|
21
|
+
maxHeight: `${x}px`,
|
|
22
|
+
overflowY: "auto"
|
|
23
|
+
}) : Object.assign(t.floating.style, {
|
|
24
|
+
maxHeight: ""
|
|
18
25
|
});
|
|
19
26
|
}
|
|
20
27
|
})
|
|
21
28
|
],
|
|
22
29
|
whileElementsMounted: z,
|
|
23
|
-
open:
|
|
24
|
-
onOpenChange:
|
|
25
|
-
}),
|
|
26
|
-
enabled: !
|
|
30
|
+
open: s,
|
|
31
|
+
onOpenChange: i
|
|
32
|
+
}), p = u([]), j = u([]), C = U(r, {
|
|
33
|
+
enabled: !s && e && !n && !o,
|
|
27
34
|
toggle: !1,
|
|
28
35
|
stickIfOpen: !1,
|
|
29
36
|
keyboardHandlers: !1
|
|
30
|
-
}),
|
|
37
|
+
}), D = V(r, { enabled: e, role: "listbox" }), M = Q(r, { enabled: !s && e && !n && !o, event: "keyboard" }), N = Y(r, { enabled: !s && e && !n && !o, visibleOnly: !0 }), A = q(r, { enabled: s && e && !n && !o, escapeKey: !0, outsidePress: !0, referencePress: !1 }), K = W(r, { enabled: e && !n && !o }), T = G(r, {
|
|
31
38
|
enabled: e && !n && !o,
|
|
32
|
-
listRef:
|
|
39
|
+
listRef: p,
|
|
33
40
|
activeIndex: a,
|
|
34
41
|
onNavigate: d,
|
|
35
42
|
focusItemOnHover: !1,
|
|
@@ -40,53 +47,53 @@ const ee = (E) => {
|
|
|
40
47
|
virtual: !0,
|
|
41
48
|
scrollItemIntoView: !0
|
|
42
49
|
}), { getReferenceProps: m, getFloatingProps: b, getItemProps: y } = F([
|
|
50
|
+
D,
|
|
43
51
|
M,
|
|
44
|
-
N,
|
|
45
52
|
T
|
|
46
|
-
]), { getReferenceProps: R } = F([
|
|
47
|
-
|
|
53
|
+
]), { getReferenceProps: R } = F([C, N, A, K]), { isMounted: v, styles: O } = J(r, { duration: 50 });
|
|
54
|
+
k(() => {
|
|
48
55
|
if (!e || n || o || f.current)
|
|
49
56
|
return;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
}, [e, n, o,
|
|
53
|
-
const
|
|
54
|
-
(
|
|
57
|
+
const t = l.domReference.current, c = document.activeElement;
|
|
58
|
+
t && c && t.contains(c) && i(!0);
|
|
59
|
+
}, [e, n, o, i, l.domReference]);
|
|
60
|
+
const I = S(
|
|
61
|
+
(t = {}) => e ? m(t) : t,
|
|
55
62
|
[m, e]
|
|
56
|
-
),
|
|
57
|
-
(
|
|
63
|
+
), P = S(
|
|
64
|
+
(t = {}) => e ? {
|
|
58
65
|
ref: l.setReference,
|
|
59
|
-
...R(
|
|
60
|
-
} :
|
|
66
|
+
...R(t)
|
|
67
|
+
} : t,
|
|
61
68
|
[e, l.setReference, R]
|
|
62
|
-
), w =
|
|
69
|
+
), w = E(
|
|
63
70
|
() => ({
|
|
64
71
|
isMounted: v,
|
|
65
72
|
getFloatingProps: b,
|
|
66
73
|
getItemProps: y,
|
|
67
74
|
floatingStyles: {
|
|
68
|
-
...
|
|
69
|
-
...
|
|
75
|
+
...g,
|
|
76
|
+
...O
|
|
70
77
|
},
|
|
71
|
-
setOpen:
|
|
72
|
-
labelsRef:
|
|
73
|
-
elementsRef:
|
|
78
|
+
setOpen: i,
|
|
79
|
+
labelsRef: j,
|
|
80
|
+
elementsRef: p,
|
|
74
81
|
setFloating: l.setFloating,
|
|
75
82
|
activeIndex: a,
|
|
76
|
-
open:
|
|
83
|
+
open: s
|
|
77
84
|
}),
|
|
78
|
-
[v, b, y,
|
|
85
|
+
[v, b, y, g, O, l.setFloating, a, s]
|
|
79
86
|
);
|
|
80
|
-
return
|
|
87
|
+
return E(
|
|
81
88
|
() => ({
|
|
82
|
-
getFieldProps:
|
|
83
|
-
getInputProps:
|
|
89
|
+
getFieldProps: P,
|
|
90
|
+
getInputProps: I,
|
|
84
91
|
dropdownProps: w,
|
|
85
92
|
refs: l
|
|
86
93
|
}),
|
|
87
|
-
[w,
|
|
94
|
+
[w, P, I, l]
|
|
88
95
|
);
|
|
89
96
|
};
|
|
90
97
|
export {
|
|
91
|
-
|
|
98
|
+
te as useSearchDropdown
|
|
92
99
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viasat/beam-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0",
|
|
4
4
|
"description": "React component library for the Beam design system",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Viasat",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@viasat/beam-fonts": "2.
|
|
63
|
-
"@viasat/beam-shared": "2.
|
|
64
|
-
"@viasat/beam-styles": "2.
|
|
65
|
-
"@viasat/beam-tokens": "2.
|
|
66
|
-
"@viasat/beam-icons": "2.
|
|
62
|
+
"@viasat/beam-fonts": "2.16.0",
|
|
63
|
+
"@viasat/beam-shared": "2.16.0",
|
|
64
|
+
"@viasat/beam-styles": "2.16.0",
|
|
65
|
+
"@viasat/beam-tokens": "2.16.0",
|
|
66
|
+
"@viasat/beam-icons": "2.16.0",
|
|
67
67
|
"clsx": "^1.2.1",
|
|
68
68
|
"@floating-ui/react": "^0.26.18",
|
|
69
69
|
"@stepperize/react": "^5.1.5",
|