@loadsmart/loadsmart-ui 5.13.0 → 5.13.2
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/components/Select/useSelect.helpers.d.ts +2 -1
- package/dist/components/Select/useSelect.test.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Select/useSelect.helpers.test.ts +63 -1
- package/src/components/Select/useSelect.helpers.ts +9 -2
- package/src/components/Select/useSelect.test.ts +207 -0
- package/src/components/Select/useSelect.ts +8 -2
- package/src/testing/SelectEvent/SelectEvent.ts +28 -42
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { SelectAdapter, SelectValue, Option, Adapters } from './Select.types';
|
|
1
|
+
import type { SelectAdapter, SelectValue, Option, Adapters, SelectProps } from './Select.types';
|
|
2
2
|
export declare function getAdapter(adapters: Adapters, type?: string): SelectAdapter<any>;
|
|
3
3
|
export declare function getValue(selection: SelectValue, multiple?: boolean): Option | Option[] | null;
|
|
4
|
+
export declare function toSelection(value: SelectProps['value']): Option[];
|
|
4
5
|
export declare function getDisplayValue(adapters: Adapters, selection: SelectValue, multiple?: boolean): string;
|
|
5
6
|
export declare function escapeRegExp(value: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -2046,7 +2046,7 @@
|
|
|
2046
2046
|
border-right-color: ${r.getToken("color-neutral-light")};
|
|
2047
2047
|
border-right-width: 1px;
|
|
2048
2048
|
border-right-style: solid;
|
|
2049
|
-
`,ri=t.forwardRef((function(n,r){const{className:o}=n,a=e.__rest(n,["className"]),{disabled:l,expanded:i,toggle:c}=t.useContext(wl);return d.default.createElement(ei,{className:o},d.default.createElement(ti,Object.assign({"data-testid":"select-trigger-search-field"},a,{ref:r,type:"search",disabled:l,onClick:function(){i||c()}})),d.default.createElement(ni,null),d.default.createElement(Wl.Handle,{"data-testid":"select-trigger-handle"}))}));function oi(e){return null==e?[]:Array.from(e.querySelectorAll("button")||[])}function ai(e){const{keys:n,onActivate:r,onDeactivate:o}=e,[a,l]=t.useState(!1),[i,c]=t.useState(-1),s=t.useRef(),[d,u]=t.useState([]);function g(){var e;c(-1),s.current&&(null===(e=s.current)||void 0===e||e.disconnect())}const p=t.useCallback((function(e){null!=e?(u(oi(e)),function(e){s.current=new MutationObserver((function(){u(oi(e))})),s.current.observe(e,{childList:!0})}(e)):g()}),[]);t.useEffect((function(){return function(){g()}}),[]),t.useEffect((function(){function e(e){const t=e,r=[...n||["TAB"]];if(!Dl(t).is(r)||Oe(d))return;t.preventDefault();const o=function(e,t,n){const r={Tab:e=>e.shiftKey?-1:1,ArrowUp:()=>-1,ArrowDown:()=>1},o=(r[Ml(e)]||function(){return 0})(e);return-1===t&&-1===o?(o+n)%n:(t+o+n)%n}(t,i,d.length);c(o),d[o].focus()}return a&&document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}),[a,n,i,d]);const h=t.useCallback((function(){l(!0),null==r||r()}),[r]),f=t.useCallback((function(){l(!1),null==o||o()}),[o]);return{containerRef:p,active:a,activate:h,deactivate:f}}function li(e,t){return e.then((e=>[null,e])).catch((e=>(t&&Object.assign(e,t),[e,void 0])))}const ii={getKey:e=>o.lodash_get(e,"value"),getLabel:e=>o.lodash_get(e,"label")};function ci(e,t){return null==t?ii:e[t]||ii}function si(e,t){const n=Array.from(e);if(Oe(n))return null;if(t){const e=[];for(const[,t]of n)e.push(t);return e}{const[[,e]]=n;return e}}function di(e,t,n){if(0==t.size)return"";if(n)return"";{const
|
|
2049
|
+
`,ri=t.forwardRef((function(n,r){const{className:o}=n,a=e.__rest(n,["className"]),{disabled:l,expanded:i,toggle:c}=t.useContext(wl);return d.default.createElement(ei,{className:o},d.default.createElement(ti,Object.assign({"data-testid":"select-trigger-search-field"},a,{ref:r,type:"search",disabled:l,onClick:function(){i||c()}})),d.default.createElement(ni,null),d.default.createElement(Wl.Handle,{"data-testid":"select-trigger-handle"}))}));function oi(e){return null==e?[]:Array.from(e.querySelectorAll("button")||[])}function ai(e){const{keys:n,onActivate:r,onDeactivate:o}=e,[a,l]=t.useState(!1),[i,c]=t.useState(-1),s=t.useRef(),[d,u]=t.useState([]);function g(){var e;c(-1),s.current&&(null===(e=s.current)||void 0===e||e.disconnect())}const p=t.useCallback((function(e){null!=e?(u(oi(e)),function(e){s.current=new MutationObserver((function(){u(oi(e))})),s.current.observe(e,{childList:!0})}(e)):g()}),[]);t.useEffect((function(){return function(){g()}}),[]),t.useEffect((function(){function e(e){const t=e,r=[...n||["TAB"]];if(!Dl(t).is(r)||Oe(d))return;t.preventDefault();const o=function(e,t,n){const r={Tab:e=>e.shiftKey?-1:1,ArrowUp:()=>-1,ArrowDown:()=>1},o=(r[Ml(e)]||function(){return 0})(e);return-1===t&&-1===o?(o+n)%n:(t+o+n)%n}(t,i,d.length);c(o),d[o].focus()}return a&&document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}),[a,n,i,d]);const h=t.useCallback((function(){l(!0),null==r||r()}),[r]),f=t.useCallback((function(){l(!1),null==o||o()}),[o]);return{containerRef:p,active:a,activate:h,deactivate:f}}function li(e,t){return e.then((e=>[null,e])).catch((e=>(t&&Object.assign(e,t),[e,void 0])))}const ii={getKey:e=>o.lodash_get(e,"value"),getLabel:e=>o.lodash_get(e,"label")};function ci(e,t){return null==t?ii:e[t]||ii}function si(e,t){const n=Array.from(e);if(Oe(n))return null;if(t){const e=[];for(const[,t]of n)e.push(t);return e}{const[[,e]]=n;return e}}function di(e,t,n){var r;if(0==t.size)return"";if(n)return"";{const o=si(t,n);return null!==(r=ci(e,o._type).getLabel(o))&&void 0!==r?r:""}}function ui(e){return String(e||"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function gi(e){e.target.select()}function pi(e,t,n){const r=new Map(t);return e.forEach((e=>{const t=ci(n,e._type);r.set(t.getKey(e),e)})),r}function hi(n){const{datasources:r,adapters:o}=n,[a,l]=t.useState(new Map),[i,c]=t.useState("idle"),s=t.useRef();function d(){null!=s.current&&clearTimeout(s.current)}const u=t.useCallback((function(t){function n(){var n,a;return e.__awaiter(this,void 0,void 0,(function*(){l(new Map),c("querying");try{for(var i,s=e.__asyncValues(function(t,n){return e.__asyncGenerator(this,arguments,(function*(){const r=new RegExp(ui(n),"i");for(const o of t){const[t,a]=yield e.__await(li(Promise.resolve(o.fetch({query:n,regex:r}))));if(!t){const t=(a||[]).map((e=>Object.assign(Object.assign({},e),{_type:o.type})));yield yield e.__await(t)}}}))}(r,t));!(i=yield s.next()).done;){const e=i.value;l((t=>pi(e,t,o)))}}catch(e){n={error:e}}finally{try{i&&!i.done&&(a=s.return)&&(yield a.call(s))}finally{if(n)throw n.error}}c("queried")}))}d(),c("pending-query"),s.current=setTimeout((()=>{n()}),750)}),[o,r]),g=t.useCallback((function(){c("idle"),l(new Map)}),[]),p=t.useCallback((function(){return Array.from(a.values())}),[a]),h=t.useCallback((function(){g(),u("")}),[g,u]),f=t.useCallback((function(e){return a.get(e)}),[a]);return t.useEffect((()=>()=>{d()}),[]),{get:p,fetch:u,clear:g,status:i,getOptionByKey:f,reset:h}}function fi(n){const r=xr(),{multiple:l,onQueryChange:i,onChange:c,onCreate:s,id:d,name:u,disabled:g=!1,onBlur:p,isValidNewOption:h=(e=>Boolean(e)),createOptionPosition:f="last"}=n,m=t.useMemo((()=>function(e){let t=[];var n;return t=t.concat(e.datasources||[]),t=t.concat((n=e.options)?[function(){return{type:"generic",adapter:ii,fetch:function({regex:e}){return n.filter((({label:t})=>e.test(t)))}}}]:[]),t.map((e=>e()))}(n)),[n.datasources,n.options]),b=t.useMemo((()=>function(e){return a.toArray(e).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.type]:t.adapter})),{})}(m)),[m]),w=Zl({selected:(v=n.value,a.toArray(v||[]).filter((e=>!Oe(e)))),multiple:l,adapters:b,onChange:t.useCallback((function(e){null==c||c({target:{id:d,name:u,value:si(e,l)}})}),[d,l,u,c])});var v;const $=t.useRef(),k=ai({keys:["ARROW_UP","ARROW_DOWN"],onDeactivate(){var e;null===(e=$.current)||void 0===e||e.focus()}}),[y,x]=t.useState(!1),[P,E]=t.useState(di(b,w.selected,l)),T=hi({datasources:m,adapters:b}),C=t.useMemo((()=>!P.length&&Oe(T.get())&&Oe(w.selected)&&o.isFunction(h)?!h(P):!h),[P,T,w.selected,h]),j=Yl(Object.assign(Object.assign({},n),{expandDisabled:C}));t.useEffect((()=>{y&&(T.fetch(P),j.expand())}),[P,y]);const O=t.useCallback((function(e){const t=ci(b,e._type),n=t.getKey(e);return{label:t.getLabel(e),value:n,checked:w.selected.has(n)}}),[b,w.selected]),_=t.useCallback((function(e){let t=T.getOptionByKey(e);return t||(t=w.selected.get(e)),t}),[T,w.selected]),z=t.useCallback((function(e){w.toggle(e)}),[w]),S=t.useCallback((function(){return{toggle:j.toggle,expanded:j.expanded,onBlur(e){E(l?"":di(b,w.selected,l)),T.reset(),null==p||p(e)},expandDisabled:C}}),[b,j.expanded,j.toggle,l,T,w.selected,p,C]),M=t.useCallback((function(){return{id:d,ref(e){null!=e&&($.current=e)},value:P,onChange(e){null==i||i(e),E(e.target.value),x(!0)},onFocus:gi}}),[d,P,i,j,T,w.selected]),D=t.useCallback((function(){return{onClick(){var e;E(""),w.clear(),T.reset(),null===(e=$.current)||void 0===e||e.focus()}}}),[T,w]),A=t.useCallback((function(){return{ref:k.containerRef,role:"listbox"}}),[k.containerRef]),N=t.useCallback((function({option:e}){const{value:t,checked:n,label:r}=O(e);return{role:"option","aria-selected":n,id:String(t),onClick:()=>(l||E(n?"":r),z(e),l),tabIndex:-1}}),[O,z,l]),F=t.useCallback((function(){return{onClick:function(){return function(){e.__awaiter(this,void 0,void 0,(function*(){if(!o.isFunction(s))return;const e=s(P);let t;var n;e&&(n=e,t=a.isObject(n)&&o.isFunction(n.then)?yield e:e),T.fetch(P),t&&z(t)}))}(),l},tabIndex:-1}}),[l,s,P,T,z]),R=t.useCallback((function(){const e=e=>O(e).label.toLocaleLowerCase()===P.toLocaleLowerCase();return o.isFunction(s)&&"queried"===T.status&&(o.isFunction(h)?h(P)&&!!a.isNil([...T.get(),...Array.from(w.selected.values())].find(e)):h)}),[O,h,s,T,P,w.selected]);return t.useEffect((function(){T.fetch("")}),[m]),t.useEffect((function(){(n.autoFocus||r)&&(j.expanded?k.activate():k.deactivate())}),[j.expanded]),t.useEffect((function(){l||E(di(b,w.selected,l))}),[b,l,w.selected]),{status:T.status,options:T.get(),value:si(w.selected,l),query:P,disabled:g,selectable:w,getMenuProps:A,getSelectableOption:O,getOption:_,getOptionProps:N,getTriggerProps:M,getClearProps:D,getDropdownProps:S,getCreatebleProps:F,isCreatable:R,createOptionPosition:f}}const mi=g.default.span`
|
|
2050
2050
|
/* highlightMatch splits the label into separate HTML elements, thus we need
|
|
2051
2051
|
to preserve white-spaces, otherwise the browser wouldn't render them. */
|
|
2052
2052
|
white-space: pre;
|