@purpurds/autocomplete 6.1.3 → 6.2.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/LICENSE.txt +3 -3
- package/dist/autocomplete.cjs.js +1 -1
- package/dist/autocomplete.cjs.js.map +1 -1
- package/dist/autocomplete.es.js +3 -1
- package/dist/autocomplete.es.js.map +1 -1
- package/dist/useAutocomplete.d.ts.map +1 -1
- package/package.json +31 -17
- package/src/useAutocomplete.ts +5 -1
package/dist/LICENSE.txt
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
Name: @purpurds/icon
|
|
2
|
-
Version: 6.1.
|
|
2
|
+
Version: 6.1.4
|
|
3
3
|
License: AGPL-3.0-only
|
|
4
4
|
Private: false
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
Name: @purpurds/listbox
|
|
9
|
-
Version: 6.1.
|
|
9
|
+
Version: 6.1.4
|
|
10
10
|
License: AGPL-3.0-only
|
|
11
11
|
Private: false
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
Name: @purpurds/text-field
|
|
16
|
-
Version: 6.1.
|
|
16
|
+
Version: 6.1.4
|
|
17
17
|
License: AGPL-3.0-only
|
|
18
18
|
Private: false
|
|
19
19
|
|
package/dist/autocomplete.cjs.js
CHANGED
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
Copyright (c) 2018 Jed Watson.
|
|
55
55
|
Licensed under the MIT License (MIT), see
|
|
56
56
|
http://jedwatson.github.io/classnames
|
|
57
|
-
*/(function(r){(function(){var a={}.hasOwnProperty;function n(){for(var e="",t=0;t<arguments.length;t++){var u=arguments[t];u&&(e=o(e,i.call(this,u)))}return e}function i(e){if(typeof e=="string"||typeof e=="number")return this&&this[e]||e;if(typeof e!="object")return"";if(Array.isArray(e))return n.apply(this,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var u in e)a.call(e,u)&&e[u]&&(t=o(t,this&&this[u]||u));return t}function o(e,t){return t?e?e+" "+t:e+t:e}r.exports?(n.default=n,r.exports=n):window.classNames=n})()})(Je);var nn=Je.exports;const un=tn(nn),an={"purpur-autocomplete":"_purpur-autocomplete_1u8x6_1","purpur-autocomplete__listbox":"_purpur-autocomplete__listbox_1u8x6_4","purpur-autocomplete__chevron-button":"_purpur-autocomplete__chevron-button_1u8x6_9","purpur-autocomplete__chevron-icon":"_purpur-autocomplete__chevron-icon_1u8x6_15","purpur-autocomplete__chevron-icon--up":"_purpur-autocomplete__chevron-icon--up_1u8x6_19"},on=r=>f.useRef(r),sn=(r,a)=>{const n=f.useCallback(i=>{r&&!r.contains(i.target)&&a()},[a,r]);f.useEffect(()=>(document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}),[n])},Qe=({combobox:r,highlightFirstOption:a,defaultInputValue:n,inputValue:i,filterOption:o,id:e,listboxLabel:t,listboxMaxHeight:u,onInputBlur:m,onInputChange:y,onInputFocus:w,onInputKeyDown:A,onInputMouseDown:S,openOnFocus:_,noOptionsText:$,onSelect:N,options:j,selectedOption:p,["data-testid"]:g})=>{const[R,M]=f.useState(((typeof i=="string"?i:n)||(p==null?void 0:p.label))??""),B=typeof i=="string"?i:R,[d,O]=f.useState(a?j[0]:void 0),I=f.useRef(null),K=on(null),L=f.useRef(null),T=f.useRef({}),[b,se]=f.useState(!1);function Q(s){return g?`${g}-${s}`:void 0}const Y=()=>{se(!1),O(void 0)};sn(K.current,Y);const D=({eventType:s})=>{se(!0),p&&requestAnimationFrame(()=>{O({...p,isSetByClickEvent:s==="CLICK"}),re(T.current[p.id])})},rr=s=>{if(o)return j.filter(h=>o(s,h));if(!s)return j;const c=s.toUpperCase().split(" ")||[];return j.filter(h=>c.every(q=>(h.value||h.label).toUpperCase().includes(q)))},le=s=>p&&(p==null?void 0:p.label)===s?j:rr(s),C=le(B),ee=s=>{y==null||y(s),M(s)},re=s=>{var c;if(s){const h=s.getBoundingClientRect(),q=((c=L.current)==null?void 0:c.getBoundingClientRect())||{top:0,bottom:0};(h.top<q.top||h.bottom>q.bottom)&&s.scrollIntoView({block:"nearest"})}},pe=s=>{var c;s&&((c=I.current)==null||c.focus(),ee(s.label),N==null||N(s)),Y()},tr=s=>{const c=a&&!d?0:C.findIndex(q=>q&&(d==null?void 0:d.id)===q.id),h=C.length;return s==="ArrowDown"?C[(c??-1)+1]||C[0]:C[(c??h)-1]||C[h-1]},z=b&&(!!C.length||!!$),nr=s=>{!z&&D({eventType:"KEYBOARD"});const c=tr(s);O(c),c&&re(T.current[c.id])},ur=s=>{switch(A==null||A(s),s.key){case"ArrowUp":case"ArrowDown":s.preventDefault(),nr(s.key);break;case"Enter":{const c=d||(a?j[0]:void 0);z&&pe(c),!z&&D({eventType:"KEYBOARD"});break}case"Escape":case"Tab":Y();break}},ar=s=>{const c=le(s.target.value);ee(s.target.value),O(void 0),!z&&D({eventType:"KEYBOARD"}),a&&c[0]&&re(T.current[c[0].id])},ir=s=>{S==null||S(s),z?Y():D({eventType:"CLICK"})},or=s=>{var c;w==null||w(s),!b&&_&&D({eventType:"KEYBOARD"}),(c=I.current)==null||c.select()},sr=s=>{m==null||m(s),r&&setTimeout(()=>{var c,h;!((c=I.current)!=null&&c.contains(document.activeElement))&&!((h=L.current)!=null&&h.contains(document.activeElement))&&ee(p?p.label:"")})},lr={maxHeight:typeof u=="number"?`${u}px`:u},ce={"aria-label":t,"aria-expanded":z,"data-testid":Q("listbox"),id:`${e}-listbox`,ref:L,onMouseLeave:()=>O(void 0),style:u?lr:void 0},de=s=>`${e}-listbox-item-${s.id}`,pr=(s,c)=>{const h=()=>s.id!==(d==null?void 0:d.id)&&O({...s,isSetByClickEvent:!0}),q=(s.id===(d==null?void 0:d.id)||!!a&&!d&&c===0)&&!(d!=null&&d.isSetByClickEvent);return{"data-testid":Q(`listbox-item-${s.id}`),id:de(s),key:s.id,onMouseMove:h,onMouseUp:()=>pe(s),ref:te=>te&&(T.current[s.id]=te),tabIndex:-1,selected:s.id===(p==null?void 0:p.id),disabled:s.disabled,highlighted:q,hovered:s.id===(d==null?void 0:d.id)&&!!(d!=null&&d.isSetByClickEvent)}},cr={"aria-activedescendant":d?de(d):void 0,"aria-autocomplete":"list","aria-controls":ce.id,"data-testid":Q("input"),autoComplete:"off",id:`${e}-input`,onChange:ar,onMouseDown:ir,onFocus:or,onKeyDown:ur,onBlur:sr,ref:I,role:"combobox",value:B};return{id:e,inputProps:cr,internalRef:K,optionsToShow:C,showListbox:z,noOptionsText:$,combobox:r,getListBoxItemProps:pr,listboxProps:ce}},J=un.bind(an),X="purpur-autocomplete",ln=({className:r,renderInput:a,renderOption:n,...i},o)=>{const{id:e,inputProps:t,internalRef:u,optionsToShow:m,showListbox:y,noOptionsText:w,combobox:A,getListBoxItemProps:S,listboxProps:_}=Qe(i),$=(p,g)=>{const{key:R,...M}=S(p,g);return l.jsx(W.Item,{...M,children:n?n==null?void 0:n(p):p.label},R)},N=p=>{u.current=p,typeof o=="function"?o(p):o&&(o.current=p)},j=()=>{const p=a(t);if(A&&w&&p&&rn(p)){const R=l.jsxs(l.Fragment,{children:[p.props.endAdornment,l.jsx("button",{"data-testid":"chevron button",type:"button",className:J(`${X}__chevron-button`),onClick:()=>{t.onFocus(void 0),t.onMouseDown(void 0)},"aria-hidden":"true",children:l.jsx(Ae,{size:"sm",className:J(`${X}__chevron-icon`,{[`${X}__chevron-icon--up`]:y})})})]});return f.cloneElement(p,{endAdornment:R})}return p};return l.jsxs("div",{id:e,ref:N,className:J([r,X]),children:[j(),y&&l.jsx(W,{..._,className:J(`${X}__listbox`),children:m.length?m.filter(p=>!!p).map($):l.jsx(W.Item,{noninteractive:!0,children:w})})]})},er=f.forwardRef(ln);er.displayName="Autocomplete";exports.Autocomplete=er;exports.useAutocomplete=Qe;
|
|
57
|
+
*/(function(r){(function(){var a={}.hasOwnProperty;function n(){for(var e="",t=0;t<arguments.length;t++){var u=arguments[t];u&&(e=o(e,i.call(this,u)))}return e}function i(e){if(typeof e=="string"||typeof e=="number")return this&&this[e]||e;if(typeof e!="object")return"";if(Array.isArray(e))return n.apply(this,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var t="";for(var u in e)a.call(e,u)&&e[u]&&(t=o(t,this&&this[u]||u));return t}function o(e,t){return t?e?e+" "+t:e+t:e}r.exports?(n.default=n,r.exports=n):window.classNames=n})()})(Je);var nn=Je.exports;const un=tn(nn),an={"purpur-autocomplete":"_purpur-autocomplete_1u8x6_1","purpur-autocomplete__listbox":"_purpur-autocomplete__listbox_1u8x6_4","purpur-autocomplete__chevron-button":"_purpur-autocomplete__chevron-button_1u8x6_9","purpur-autocomplete__chevron-icon":"_purpur-autocomplete__chevron-icon_1u8x6_15","purpur-autocomplete__chevron-icon--up":"_purpur-autocomplete__chevron-icon--up_1u8x6_19"},on=r=>f.useRef(r),sn=(r,a)=>{const n=f.useCallback(i=>{r&&!r.contains(i.target)&&a()},[a,r]);f.useEffect(()=>(document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}),[n])},Qe=({combobox:r,highlightFirstOption:a,defaultInputValue:n,inputValue:i,filterOption:o,id:e,listboxLabel:t,listboxMaxHeight:u,onInputBlur:m,onInputChange:y,onInputFocus:w,onInputKeyDown:A,onInputMouseDown:S,openOnFocus:_,noOptionsText:$,onSelect:N,options:j,selectedOption:p,["data-testid"]:g})=>{const[R,M]=f.useState(((typeof i=="string"?i:n)||(p==null?void 0:p.label))??""),B=typeof i=="string"?i:R,[d,O]=f.useState(a?j[0]:void 0),I=f.useRef(null),K=on(null),L=f.useRef(null),T=f.useRef({}),[b,se]=f.useState(!1);function Q(s){return g?`${g}-${s}`:void 0}const Y=()=>{se(!1),O(void 0)};sn(K.current,Y);const D=({eventType:s})=>{se(!0),p&&requestAnimationFrame(()=>{O({...p,isSetByClickEvent:s==="CLICK"}),re(T.current[p.id])})},rr=s=>{if(o)return j.filter(h=>o(s,h));if(!s)return j;const c=s.toUpperCase().split(" ")||[];return j.filter(h=>c.every(q=>(h.value||h.label).toUpperCase().includes(q)))},le=s=>p&&(p==null?void 0:p.label)===s?j:rr(s),C=le(B),ee=s=>{y==null||y(s),M(s)},re=s=>{var c;if(s){const h=s.getBoundingClientRect(),q=((c=L.current)==null?void 0:c.getBoundingClientRect())||{top:0,bottom:0};(h.top<q.top||h.bottom>q.bottom)&&s.scrollIntoView({block:"nearest"})}},pe=s=>{var c;s&&((c=I.current)==null||c.focus(),ee(s.label),N==null||N(s)),Y()},tr=s=>{const c=a&&!d?0:C.findIndex(q=>q&&(d==null?void 0:d.id)===q.id),h=C.length;return s==="ArrowDown"?C[(c??-1)+1]||C[0]:C[(c??h)-1]||C[h-1]},z=b&&(!!C.length||!!$),nr=s=>{!z&&D({eventType:"KEYBOARD"});const c=tr(s);O(c),c&&re(T.current[c.id])},ur=s=>{switch(A==null||A(s),s.key){case"ArrowUp":case"ArrowDown":s.preventDefault(),nr(s.key);break;case"Enter":{const c=d||(a?j[0]:void 0);z&&pe(c),!z&&D({eventType:"KEYBOARD"});break}case"Escape":case"Tab":Y();break}},ar=s=>{const c=le(s.target.value);ee(s.target.value),O(void 0),!z&&D({eventType:"KEYBOARD"}),a&&c[0]&&re(T.current[c[0].id])},ir=s=>{S==null||S(s),z?Y():D({eventType:"CLICK"})},or=s=>{var c;w==null||w(s),!b&&_&&D({eventType:"KEYBOARD"}),(c=I.current)==null||c.select()},sr=s=>{m==null||m(s),r&&setTimeout(()=>{var c,h;!((c=I.current)!=null&&c.contains(document.activeElement))&&!((h=L.current)!=null&&h.contains(document.activeElement))&&ee(p?p.label:"")})},lr={maxHeight:typeof u=="number"?`${u}px`:u},ce={"aria-label":t,"aria-expanded":z,"data-testid":Q("listbox"),id:`${e}-listbox`,ref:L,onMouseLeave:()=>O(void 0),style:u?lr:void 0},de=s=>`${e}-listbox-item-${s.id}`,pr=(s,c)=>{const h=()=>s.id!==(d==null?void 0:d.id)&&O({...s,isSetByClickEvent:!0}),q=(s.id===(d==null?void 0:d.id)||!!a&&!d&&c===0)&&!(d!=null&&d.isSetByClickEvent);return{"data-testid":Q(`listbox-item-${s.id}`),id:de(s),key:s.id,onMouseMove:h,onMouseUp:()=>pe(s),ref:te=>{te&&(T.current[s.id]=te)},tabIndex:-1,selected:s.id===(p==null?void 0:p.id),disabled:s.disabled,highlighted:q,hovered:s.id===(d==null?void 0:d.id)&&!!(d!=null&&d.isSetByClickEvent)}},cr={"aria-activedescendant":d?de(d):void 0,"aria-autocomplete":"list","aria-controls":ce.id,"data-testid":Q("input"),autoComplete:"off",id:`${e}-input`,onChange:ar,onMouseDown:ir,onFocus:or,onKeyDown:ur,onBlur:sr,ref:I,role:"combobox",value:B};return{id:e,inputProps:cr,internalRef:K,optionsToShow:C,showListbox:z,noOptionsText:$,combobox:r,getListBoxItemProps:pr,listboxProps:ce}},J=un.bind(an),X="purpur-autocomplete",ln=({className:r,renderInput:a,renderOption:n,...i},o)=>{const{id:e,inputProps:t,internalRef:u,optionsToShow:m,showListbox:y,noOptionsText:w,combobox:A,getListBoxItemProps:S,listboxProps:_}=Qe(i),$=(p,g)=>{const{key:R,...M}=S(p,g);return l.jsx(W.Item,{...M,children:n?n==null?void 0:n(p):p.label},R)},N=p=>{u.current=p,typeof o=="function"?o(p):o&&(o.current=p)},j=()=>{const p=a(t);if(A&&w&&p&&rn(p)){const R=l.jsxs(l.Fragment,{children:[p.props.endAdornment,l.jsx("button",{"data-testid":"chevron button",type:"button",className:J(`${X}__chevron-button`),onClick:()=>{t.onFocus(void 0),t.onMouseDown(void 0)},"aria-hidden":"true",children:l.jsx(Ae,{size:"sm",className:J(`${X}__chevron-icon`,{[`${X}__chevron-icon--up`]:y})})})]});return f.cloneElement(p,{endAdornment:R})}return p};return l.jsxs("div",{id:e,ref:N,className:J([r,X]),children:[j(),y&&l.jsx(W,{..._,className:J(`${X}__listbox`),children:m.length?m.filter(p=>!!p).map($):l.jsx(W.Item,{noninteractive:!0,children:w})})]})},er=f.forwardRef(ln);er.displayName="Autocomplete";exports.Autocomplete=er;exports.useAutocomplete=Qe;
|
|
58
58
|
//# sourceMappingURL=autocomplete.cjs.js.map
|