@purpurds/autocomplete 5.4.1 → 5.4.3

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 CHANGED
@@ -33,13 +33,13 @@ SOFTWARE.
33
33
  ---
34
34
 
35
35
  Name: @purpurds/icon
36
- Version: 5.4.0
36
+ Version: 5.4.2
37
37
  License: AGPL-3.0-only
38
38
  Private: false
39
39
 
40
40
  ---
41
41
 
42
42
  Name: @purpurds/paragraph
43
- Version: 5.4.0
43
+ Version: 5.4.2
44
44
  License: AGPL-3.0-only
45
45
  Private: false
@@ -10,5 +10,5 @@
10
10
  Copyright (c) 2018 Jed Watson.
11
11
  Licensed under the MIT License (MIT), see
12
12
  http://jedwatson.github.io/classnames
13
- */(function(e){(function(){var o={}.hasOwnProperty;function n(){for(var r="",t=0;t<arguments.length;t++){var s=arguments[t];s&&(r=i(r,l(s)))}return r}function l(r){if(typeof r=="string"||typeof r=="number")return r;if(typeof r!="object")return"";if(Array.isArray(r))return n.apply(null,r);if(r.toString!==Object.prototype.toString&&!r.toString.toString().includes("[native code]"))return r.toString();var t="";for(var s in r)o.call(r,s)&&r[s]&&(t=i(t,s));return t}function i(r,t){return t?r?r+" "+t:r+t:r}e.exports?(n.default=n,e.exports=n):window.classNames=n})()})(er);var Nr=er.exports;const Pr=Sr(Nr),I={"purpur-paragraph":"_purpur-paragraph_1rh57_1","purpur-paragraph--disabled":"_purpur-paragraph--disabled_1rh57_7","purpur-paragraph--hyphens":"_purpur-paragraph--hyphens_1rh57_10","purpur-paragraph--negative":"_purpur-paragraph--negative_1rh57_13","purpur-paragraph--paragraph-100":"_purpur-paragraph--paragraph-100_1rh57_16","purpur-paragraph--paragraph-100-medium":"_purpur-paragraph--paragraph-100-medium_1rh57_22","purpur-paragraph--paragraph-100-bold":"_purpur-paragraph--paragraph-100-bold_1rh57_29","purpur-paragraph--paragraph-200":"_purpur-paragraph--paragraph-200_1rh57_36","purpur-paragraph--preamble-100":"_purpur-paragraph--preamble-100_1rh57_42","purpur-paragraph--preamble-200":"_purpur-paragraph--preamble-200_1rh57_48","purpur-paragraph--additional-100":"_purpur-paragraph--additional-100_1rh57_54","purpur-paragraph--additional-100-medium":"_purpur-paragraph--additional-100-medium_1rh57_60","purpur-paragraph--overline-100":"_purpur-paragraph--overline-100_1rh57_67","purpur-paragraph--overline-200":"_purpur-paragraph--overline-200_1rh57_75"},jr={PARAGRAPH100:"paragraph-100",PARAGRAPH100MEDIUM:"paragraph-100-medium",PARAGRAPH100BOLD:"paragraph-100-bold",PARAGRAPH200:"paragraph-200",PREAMBLE100:"preamble-100",PREAMBLE200:"preamble-200",ADDITIONAL100:"additional-100",ADDITIONAL100MEDIUM:"additional-100-medium",OVERLINE100:"overline-100",OVERLINE200:"overline-200"},L="purpur-paragraph",Cr=({["data-testid"]:e,children:o,className:n="",disabled:l,enableHyphenation:i=!1,negative:r=!1,variant:t=jr.PARAGRAPH100,...s})=>{const b=Pr([n,I[L],I[`${L}--${t}`],{[I[`${L}--hyphens`]]:i,[I[`${L}--disabled`]]:l,[I[`${L}--negative`]]:r}]);return _.jsx("p",{...s,className:b,"data-testid":e,children:o})},Br={"purpur-listbox":"_purpur-listbox_qhoi7_1","purpur-listbox-item":"_purpur-listbox-item_qhoi7_15","purpur-listbox-item--hovered":"_purpur-listbox-item--hovered_qhoi7_29","purpur-listbox-item--highlighted":"_purpur-listbox-item--highlighted_qhoi7_37","purpur-listbox-item--noninteractive":"_purpur-listbox-item--noninteractive_qhoi7_41","purpur-listbox-item--disabled":"_purpur-listbox-item--disabled_qhoi7_44","purpur-listbox-item__icon":"_purpur-listbox-item__icon_qhoi7_51"},Dr=e=>d.useRef(e),kr=(e,o)=>{const n=d.useCallback(l=>{e&&!e.contains(l.target)&&o()},[o,e]);d.useEffect(()=>(document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}),[n])},tr=({highlightFirstOption:e,defaultInputValue:o,inputValue:n,filterOption:l,id:i,listboxLabel:r,listboxMaxHeight:t,onInputChange:s,openOnFocus:b,noOptionsText:A,onSelect:R,options:v,selectedOption:c,["data-testid"]:E})=>{const[j,f]=d.useState((typeof n=="string"?n:o)||(c==null?void 0:c.label)),S=typeof n=="string"?n:j,[u,x]=d.useState(e?v[0]:void 0),C=d.useRef(null),T=Dr(null),O=d.useRef(null),N=d.useRef({}),[V,K]=d.useState(!1);function B(a){return E?`${E}-${a}`:void 0}const P=()=>{K(!1),x(void 0)};kr(T.current,P);const $=({eventType:a})=>{K(!0),c&&requestAnimationFrame(()=>{x({...c,isSetByClickEvent:a==="CLICK"}),D(N.current[c.id])})},sr=a=>{if(l)return v.filter(m=>l(a,m));if(!a)return v;const p=a.toUpperCase().split(" ")||[];return v.filter(m=>p.every(h=>(m.value||m.label).toUpperCase().includes(h)))},H=a=>c&&(c==null?void 0:c.label)===a?v:sr(a),g=H(S),U=a=>{s==null||s(a),f(a)},D=a=>{var p;if(a){const m=a.getBoundingClientRect(),h=((p=O.current)==null?void 0:p.getBoundingClientRect())||{top:0,bottom:0};(m.top<h.top||m.bottom>h.bottom)&&a.scrollIntoView({block:"nearest"})}},G=a=>{var p;a&&((p=C.current)==null||p.focus(),U(a.label),R==null||R(a)),P()},or=a=>{const p=e&&!u?0:g.findIndex(h=>h&&(u==null?void 0:u.id)===h.id),m=g.length;return a==="ArrowDown"?g[(p??-1)+1]||g[0]:g[(p??m)-1]||g[m-1]},y=V&&(!!g.length||!!A),ur=a=>{!y&&$({eventType:"KEYBOARD"});const p=or(a);x(p),p&&D(N.current[p.id])},ir=a=>{switch(a.key){case"ArrowUp":case"ArrowDown":a.preventDefault(),ur(a.key);break;case"Enter":{const p=u||(e?v[0]:void 0);y&&G(p),!y&&$({eventType:"KEYBOARD"});break}case"Escape":case"Tab":P();break}},pr=a=>{const p=H(a.target.value);U(a.target.value),x(void 0),!y&&$({eventType:"KEYBOARD"}),e&&p[0]&&D(N.current[p[0].id])},lr=()=>{y?P():$({eventType:"CLICK"})},cr=()=>{var a;!V&&b&&$({eventType:"KEYBOARD"}),(a=C.current)==null||a.select()},dr={maxHeight:typeof t=="number"?`${t}px`:t},Y={"aria-label":r,"aria-expanded":y,"data-testid":B("listbox"),id:`${i}-listbox`,ref:O,onMouseLeave:()=>x(void 0),style:t?dr:void 0},z=a=>`${i}-listbox-item-${a.id}`,mr=(a,p)=>{const m=()=>a.id!==(u==null?void 0:u.id)&&x({...a,isSetByClickEvent:!0}),h=(a.id===(u==null?void 0:u.id)||!!e&&!u&&p===0)&&!(u!=null&&u.isSetByClickEvent);return{"data-testid":B(`listbox-item-${a.id}`),id:z(a),key:a.id,onMouseMove:m,onMouseUp:()=>G(a),ref:k=>k&&(N.current[a.id]=k),tabIndex:-1,selected:a.id===(c==null?void 0:c.id),disabled:a.disabled,highlighted:h,hovered:a.id===(u==null?void 0:u.id)&&!!(u!=null&&u.isSetByClickEvent)}},fr={"aria-activedescendant":u?z(u):void 0,"aria-autocomplete":"list","aria-controls":Y.id,"aria-expanded":y,"data-testid":B("input"),autoComplete:"off",id:`${i}-input`,onChange:pr,onMouseDown:lr,onFocus:cr,onKeyDown:ir,ref:C,role:"combobox",value:S};return{id:i,inputProps:fr,internalRef:T,optionsToShow:g,showListbox:y,noOptionsText:A,getListBoxItemProps:mr,listboxProps:Y}},M=X.bind(Br),w="purpur-listbox",ar=d.forwardRef(({children:e,...o},n)=>_.jsx("ul",{...o,ref:n,className:M(w,o.className),role:"listbox",children:d.Children.toArray(e).filter(Mr)}));ar.displayName="ListBox";const q=d.forwardRef((e,o)=>{const{disabled:n,highlighted:l,hovered:i,selected:r,children:t,noninteractive:s,...b}=e,A=M(`${w}-item`,b.className,{[`${w}-item--highlighted`]:l,[`${w}-item--selected`]:r,[`${w}-item--hovered`]:i,[`${w}-item--disabled`]:n,[`${w}-item--noninteractive`]:s});return _.jsxs("li",{...b,ref:o,className:A,"aria-selected":!!r,role:"option","aria-disabled":!!n,children:[typeof t=="string"?_.jsx(Cr,{children:t}):t,r&&_.jsx(Er,{svg:wr,size:"xs",className:M(`${w}-item__icon`)})]})});q.displayName="ListBoxItem";function Mr(e){return d.isValidElement(e)&&(e==null?void 0:e.type)===q}const qr=ar,Z=q,J=X.bind(hr),Q="purpur-autocomplete",Tr=({className:e,renderInput:o,renderOption:n,...l},i)=>{const{id:r,inputProps:t,internalRef:s,optionsToShow:b,showListbox:A,noOptionsText:R,getListBoxItemProps:v,listboxProps:c}=tr(l),E=(f,S)=>{const{key:u,...x}=v(f,S);return _.jsx(Z,{...x,children:n?n==null?void 0:n(f):f.label},u)},j=f=>{s.current=f,typeof i=="function"?i(f):i&&(i.current=f)};return _.jsxs("div",{id:r,ref:j,className:J([e,Q]),children:[o(t),A&&_.jsx(qr,{...c,className:J(`${Q}__listbox`),children:b.length?b.filter(f=>!!f).map(E):_.jsx(Z,{noninteractive:!0,children:R})})]})},nr=d.forwardRef(Tr);nr.displayName="Autocomplete";exports.Autocomplete=nr;exports.useAutocomplete=tr;
13
+ */(function(e){(function(){var o={}.hasOwnProperty;function n(){for(var r="",t=0;t<arguments.length;t++){var s=arguments[t];s&&(r=i(r,l(s)))}return r}function l(r){if(typeof r=="string"||typeof r=="number")return r;if(typeof r!="object")return"";if(Array.isArray(r))return n.apply(null,r);if(r.toString!==Object.prototype.toString&&!r.toString.toString().includes("[native code]"))return r.toString();var t="";for(var s in r)o.call(r,s)&&r[s]&&(t=i(t,s));return t}function i(r,t){return t?r?r+" "+t:r+t:r}e.exports?(n.default=n,e.exports=n):window.classNames=n})()})(er);var Nr=er.exports;const Pr=Sr(Nr),I={"purpur-paragraph":"_purpur-paragraph_1rh57_1","purpur-paragraph--disabled":"_purpur-paragraph--disabled_1rh57_7","purpur-paragraph--hyphens":"_purpur-paragraph--hyphens_1rh57_10","purpur-paragraph--negative":"_purpur-paragraph--negative_1rh57_13","purpur-paragraph--paragraph-100":"_purpur-paragraph--paragraph-100_1rh57_16","purpur-paragraph--paragraph-100-medium":"_purpur-paragraph--paragraph-100-medium_1rh57_22","purpur-paragraph--paragraph-100-bold":"_purpur-paragraph--paragraph-100-bold_1rh57_29","purpur-paragraph--paragraph-200":"_purpur-paragraph--paragraph-200_1rh57_36","purpur-paragraph--preamble-100":"_purpur-paragraph--preamble-100_1rh57_42","purpur-paragraph--preamble-200":"_purpur-paragraph--preamble-200_1rh57_48","purpur-paragraph--additional-100":"_purpur-paragraph--additional-100_1rh57_54","purpur-paragraph--additional-100-medium":"_purpur-paragraph--additional-100-medium_1rh57_60","purpur-paragraph--overline-100":"_purpur-paragraph--overline-100_1rh57_67","purpur-paragraph--overline-200":"_purpur-paragraph--overline-200_1rh57_75"},jr={PARAGRAPH100:"paragraph-100",PARAGRAPH100MEDIUM:"paragraph-100-medium",PARAGRAPH100BOLD:"paragraph-100-bold",PARAGRAPH200:"paragraph-200",PREAMBLE100:"preamble-100",PREAMBLE200:"preamble-200",ADDITIONAL100:"additional-100",ADDITIONAL100MEDIUM:"additional-100-medium",OVERLINE100:"overline-100",OVERLINE200:"overline-200"},L="purpur-paragraph",Cr=({["data-testid"]:e,children:o,className:n="",disabled:l,enableHyphenation:i=!1,negative:r=!1,variant:t=jr.PARAGRAPH100,...s})=>{const b=Pr([n,I[L],I[`${L}--${t}`],{[I[`${L}--hyphens`]]:i,[I[`${L}--disabled`]]:l,[I[`${L}--negative`]]:r}]);return _.jsx("p",{...s,className:b,"data-testid":e,children:o})},Br={"purpur-listbox":"_purpur-listbox_qhoi7_1","purpur-listbox-item":"_purpur-listbox-item_qhoi7_15","purpur-listbox-item--hovered":"_purpur-listbox-item--hovered_qhoi7_29","purpur-listbox-item--highlighted":"_purpur-listbox-item--highlighted_qhoi7_37","purpur-listbox-item--noninteractive":"_purpur-listbox-item--noninteractive_qhoi7_41","purpur-listbox-item--disabled":"_purpur-listbox-item--disabled_qhoi7_44","purpur-listbox-item__icon":"_purpur-listbox-item__icon_qhoi7_51"},Dr=e=>d.useRef(e),kr=(e,o)=>{const n=d.useCallback(l=>{e&&!e.contains(l.target)&&o()},[o,e]);d.useEffect(()=>(document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n)}),[n])},tr=({highlightFirstOption:e,defaultInputValue:o,inputValue:n,filterOption:l,id:i,listboxLabel:r,listboxMaxHeight:t,onInputChange:s,openOnFocus:b,noOptionsText:A,onSelect:R,options:v,selectedOption:c,["data-testid"]:E})=>{const[j,f]=d.useState((typeof n=="string"?n:o)||(c==null?void 0:c.label)),S=typeof n=="string"?n:j,[u,x]=d.useState(e?v[0]:void 0),C=d.useRef(null),T=Dr(null),O=d.useRef(null),N=d.useRef({}),[V,K]=d.useState(!1);function B(a){return E?`${E}-${a}`:void 0}const P=()=>{K(!1),x(void 0)};kr(T.current,P);const $=({eventType:a})=>{K(!0),c&&requestAnimationFrame(()=>{x({...c,isSetByClickEvent:a==="CLICK"}),D(N.current[c.id])})},sr=a=>{if(l)return v.filter(m=>l(a,m));if(!a)return v;const p=a.toUpperCase().split(" ")||[];return v.filter(m=>p.every(h=>(m.value||m.label).toUpperCase().includes(h)))},H=a=>c&&(c==null?void 0:c.label)===a?v:sr(a),g=H(S),U=a=>{s==null||s(a),f(a)},D=a=>{var p;if(a){const m=a.getBoundingClientRect(),h=((p=O.current)==null?void 0:p.getBoundingClientRect())||{top:0,bottom:0};(m.top<h.top||m.bottom>h.bottom)&&a.scrollIntoView({block:"nearest"})}},G=a=>{var p;a&&((p=C.current)==null||p.focus(),U(a.label),R==null||R(a)),P()},or=a=>{const p=e&&!u?0:g.findIndex(h=>h&&(u==null?void 0:u.id)===h.id),m=g.length;return a==="ArrowDown"?g[(p??-1)+1]||g[0]:g[(p??m)-1]||g[m-1]},w=V&&(!!g.length||!!A),ur=a=>{!w&&$({eventType:"KEYBOARD"});const p=or(a);x(p),p&&D(N.current[p.id])},ir=a=>{switch(a.key){case"ArrowUp":case"ArrowDown":a.preventDefault(),ur(a.key);break;case"Enter":{const p=u||(e?v[0]:void 0);w&&G(p),!w&&$({eventType:"KEYBOARD"});break}case"Escape":case"Tab":P();break}},pr=a=>{const p=H(a.target.value);U(a.target.value),x(void 0),!w&&$({eventType:"KEYBOARD"}),e&&p[0]&&D(N.current[p[0].id])},lr=()=>{w?P():$({eventType:"CLICK"})},cr=()=>{var a;!V&&b&&$({eventType:"KEYBOARD"}),(a=C.current)==null||a.select()},dr={maxHeight:typeof t=="number"?`${t}px`:t},Y={"aria-label":r,"aria-expanded":w,"data-testid":B("listbox"),id:`${i}-listbox`,ref:O,onMouseLeave:()=>x(void 0),style:t?dr:void 0},z=a=>`${i}-listbox-item-${a.id}`,mr=(a,p)=>{const m=()=>a.id!==(u==null?void 0:u.id)&&x({...a,isSetByClickEvent:!0}),h=(a.id===(u==null?void 0:u.id)||!!e&&!u&&p===0)&&!(u!=null&&u.isSetByClickEvent);return{"data-testid":B(`listbox-item-${a.id}`),id:z(a),key:a.id,onMouseMove:m,onMouseUp:()=>G(a),ref:k=>k&&(N.current[a.id]=k),tabIndex:-1,selected:a.id===(c==null?void 0:c.id),disabled:a.disabled,highlighted:h,hovered:a.id===(u==null?void 0:u.id)&&!!(u!=null&&u.isSetByClickEvent)}},fr={"aria-activedescendant":u?z(u):void 0,"aria-autocomplete":"list","aria-controls":Y.id,"data-testid":B("input"),autoComplete:"off",id:`${i}-input`,onChange:pr,onMouseDown:lr,onFocus:cr,onKeyDown:ir,ref:C,role:"combobox",value:S};return{id:i,inputProps:fr,internalRef:T,optionsToShow:g,showListbox:w,noOptionsText:A,getListBoxItemProps:mr,listboxProps:Y}},M=X.bind(Br),y="purpur-listbox",ar=d.forwardRef(({children:e,...o},n)=>_.jsx("ul",{...o,ref:n,className:M(y,o.className),role:"listbox",children:d.Children.toArray(e).filter(Mr)}));ar.displayName="ListBox";const q=d.forwardRef((e,o)=>{const{disabled:n,highlighted:l,hovered:i,selected:r,children:t,noninteractive:s,...b}=e,A=M(`${y}-item`,b.className,{[`${y}-item--highlighted`]:l,[`${y}-item--selected`]:r,[`${y}-item--hovered`]:i,[`${y}-item--disabled`]:n,[`${y}-item--noninteractive`]:s});return _.jsxs("li",{...b,ref:o,className:A,"aria-selected":!!r,role:"option","aria-disabled":!!n,children:[typeof t=="string"?_.jsx(Cr,{children:t}):t,r&&_.jsx(Er,{svg:wr,size:"xs",className:M(`${y}-item__icon`)})]})});q.displayName="ListBoxItem";function Mr(e){return d.isValidElement(e)&&(e==null?void 0:e.type)===q}const qr=ar,Z=q,J=X.bind(hr),Q="purpur-autocomplete",Tr=({className:e,renderInput:o,renderOption:n,...l},i)=>{const{id:r,inputProps:t,internalRef:s,optionsToShow:b,showListbox:A,noOptionsText:R,getListBoxItemProps:v,listboxProps:c}=tr(l),E=(f,S)=>{const{key:u,...x}=v(f,S);return _.jsx(Z,{...x,children:n?n==null?void 0:n(f):f.label},u)},j=f=>{s.current=f,typeof i=="function"?i(f):i&&(i.current=f)};return _.jsxs("div",{id:r,ref:j,className:J([e,Q]),children:[o(t),A&&_.jsx(qr,{...c,className:J(`${Q}__listbox`),children:b.length?b.filter(f=>!!f).map(E):_.jsx(Z,{noninteractive:!0,children:R})})]})},nr=d.forwardRef(Tr);nr.displayName="Autocomplete";exports.Autocomplete=nr;exports.useAutocomplete=tr;
14
14
  //# sourceMappingURL=autocomplete.cjs.js.map