@foxford/ui 2.58.0 → 2.59.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/components/Accordion/Accordion.js +1 -1
- package/components/Accordion/Accordion.mjs +1 -1
- package/components/Dropdown/Dropdown.js +1 -1
- package/components/Dropdown/Dropdown.mjs +1 -1
- package/components/Input/Input.js +1 -1
- package/components/Input/Input.mjs +1 -1
- package/components/Textarea/Textarea.js +1 -1
- package/components/Textarea/Textarea.mjs +1 -1
- package/external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.js +1 -1
- package/external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.js.map +1 -1
- package/external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.mjs +1 -1
- package/external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.mjs.map +1 -1
- package/external/.pnpm/{nanoid@5.0.7 → nanoid@5.0.9}/node_modules/nanoid/index.browser.js +1 -1
- package/external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.js.map +1 -0
- package/external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.mjs +2 -0
- package/external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.mjs.map +1 -0
- package/external/.pnpm/{nanoid@5.0.7 → nanoid@5.0.9}/node_modules/nanoid/url-alphabet/index.js.map +1 -1
- package/external/.pnpm/{nanoid@5.0.7 → nanoid@5.0.9}/node_modules/nanoid/url-alphabet/index.mjs.map +1 -1
- package/external/.pnpm/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.js +1 -1
- package/external/.pnpm/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.js.map +1 -1
- package/external/.pnpm/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.mjs +1 -1
- package/external/.pnpm/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.mjs.map +1 -1
- package/package.json +1 -1
- package/external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.js.map +0 -1
- package/external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.mjs +0 -2
- package/external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.mjs.map +0 -1
- /package/external/.pnpm/{nanoid@5.0.7 → nanoid@5.0.9}/node_modules/nanoid/url-alphabet/index.js +0 -0
- /package/external/.pnpm/{nanoid@5.0.7 → nanoid@5.0.9}/node_modules/nanoid/url-alphabet/index.mjs +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var React=require('react');var index_browser=require('../../external/.pnpm/nanoid@5.0.
|
|
1
|
+
'use strict';var React=require('react');var index_browser=require('../../external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.js');var withMergedProps=require('../../hocs/withMergedProps.js');var constants=require('./constants.js');var style=require('./style.js');var require$$0=require('react/jsx-runtime');var Icon=require('../Icon/Icon.js');var Skeleton=require('../Skeleton/Skeleton.js');var Text=require('../Text/Text.js');const Accordion=withMergedProps.withMergedProps(React.forwardRef(((e,r)=>{const{size:s="m",iconProps:t={},titleProps:i={},subtitleProps:n={},defaultExpanded:o=!1,sizeXXS:a,sizeXS:d,sizeS:c,sizeM:l,sizeL:p,sizeXL:u,expanded:x,onExpandedChange:$,children:S,icon:h,imgSrc:q,title:j,subtitle:y,addon:b,loading:m,headingAs:z,disabled:g,...v}=e;const E={size:s,sizeXXS:a,sizeXS:d,sizeS:c,sizeM:l,sizeL:p,sizeXL:u};const I=React.isValidElement(b)&&typeof b.props=='object'&&b.props!==null?b.props:{};const[T,w]=React.useState(x??o);const[R,f]=React.useState(x??T);const k=React.useMemo((()=>index_browser.nanoid()),[]);const L=React.useMemo((()=>index_browser.nanoid()),[]);return React.useLayoutEffect((()=>{x!==void 0&&w(x)}),[x]),React.useLayoutEffect((()=>{T&&f(!0)}),[T]),require$$0.jsxs(style.Root,{...v,...E,expanded:T,ref:r,children:[require$$0.jsx(style.Heading,{as:z,children:require$$0.jsxs(style.Button,{id:k,type:"button","aria-controls":L,"aria-expanded":R,"aria-disabled":R&&(g||x!==void 0&&!$),expanded:T,disabled:g,loading:m,palette:v.palette,onClick:()=>{const e=!T;x===void 0&&w(e),$&&$(e)},children:[h&&!m&&require$$0.jsx(style.Spacer,{children:require$$0.jsx(Icon.Icon,{preset:"brand",name:typeof h=='string'?h:void 0,icon:typeof h!='string'?h:void 0,sizes:constants.SIZES_ICON,...E,...t})}),q&&require$$0.jsx(style.Media,{src:m?void 0:q,children:m&&require$$0.jsx(Skeleton.Skeleton,{as:"span",width:"100%",height:"100%",borderRadius:"inherit"})}),b&&require$$0.jsx(style.Spacer,{stretch:!0,children:React.isValidElement(b)?React.cloneElement(b,{...E,...I}):typeof b=='function'?b(E):b}),require$$0.jsxs(style.Content,{children:[m?require$$0.jsx(Skeleton.Skeleton,{as:"span",borderRadius:4,children:require$$0.jsx(Text.Text,{as:"span",appearance:"subheading-compact",sizes:constants.SIZES_TITLE,...E,...i})}):require$$0.jsx(Text.Text,{as:"span",appearance:"subheading-compact",wordBreak:"break-word",color:"inherit",sizes:constants.SIZES_TITLE,...E,...i,children:j}),y&&!m&&require$$0.jsx(Text.Text,{as:"span",appearance:"body",wordBreak:"break-word",color:"content-onmain-tertiary",marginTop:j?'0.2em':void 0,sizes:constants.SIZES_SUBTITLE,...E,...n,children:y})]}),require$$0.jsx(style.IconAnimated,{...E,preset:"brand",name:"chevronDown",sizes:constants.SIZES_ICON,up:T})]})}),require$$0.jsx(style.Panel,{id:L,role:"region","aria-labelledby":k,hidden:!R,onTransitionEnd:e=>{e.propertyName!=='opacity'||T||f(!1)},children:require$$0.jsx(style.Details,{children:S})})]})})),{displayName:'Accordion',sizes:constants.SIZES});exports.Accordion=Accordion;
|
|
2
2
|
//# sourceMappingURL=Accordion.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{forwardRef,isValidElement,useState,useMemo,useLayoutEffect,cloneElement}from'react';import{nanoid}from'../../external/.pnpm/nanoid@5.0.
|
|
1
|
+
import{forwardRef,isValidElement,useState,useMemo,useLayoutEffect,cloneElement}from'react';import{nanoid}from'../../external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.mjs';import{withMergedProps}from'../../hocs/withMergedProps.mjs';import{SIZES,SIZES_ICON,SIZES_TITLE,SIZES_SUBTITLE}from'./constants.mjs';import{Root,Heading,Button,Spacer,Media,Content,IconAnimated,Panel,Details}from'./style.mjs';import{jsxs,jsx}from'react/jsx-runtime';import{Icon}from'../Icon/Icon.mjs';import{Skeleton}from'../Skeleton/Skeleton.mjs';import{Text}from'../Text/Text.mjs';const Accordion=withMergedProps(forwardRef(((e,o)=>{const{size:n="m",iconProps:s={},titleProps:i={},subtitleProps:t={},defaultExpanded:r=!1,sizeXXS:a,sizeXS:d,sizeS:c,sizeM:p,sizeL:l,sizeXL:m,expanded:S,onExpandedChange:x,children:h,icon:u,imgSrc:j,title:f,subtitle:E,addon:I,loading:z,headingAs:b,disabled:T,...g}=e;const y={size:n,sizeXXS:a,sizeXS:d,sizeS:c,sizeM:p,sizeL:l,sizeXL:m};const w=isValidElement(I)&&typeof I.props=='object'&&I.props!==null?I.props:{};const[L,k]=useState(S??r);const[M,Z]=useState(S??L);const _=useMemo((()=>nanoid()),[]);const v=useMemo((()=>nanoid()),[]);return useLayoutEffect((()=>{S!==void 0&&k(S)}),[S]),useLayoutEffect((()=>{L&&Z(!0)}),[L]),jsxs(Root,{...g,...y,expanded:L,ref:o,children:[jsx(Heading,{as:b,children:jsxs(Button,{id:_,type:"button","aria-controls":v,"aria-expanded":M,"aria-disabled":M&&(T||S!==void 0&&!x),expanded:L,disabled:T,loading:z,palette:g.palette,onClick:()=>{const e=!L;S===void 0&&k(e),x&&x(e)},children:[u&&!z&&jsx(Spacer,{children:jsx(Icon,{preset:"brand",name:typeof u=='string'?u:void 0,icon:typeof u!='string'?u:void 0,sizes:SIZES_ICON,...y,...s})}),j&&jsx(Media,{src:z?void 0:j,children:z&&jsx(Skeleton,{as:"span",width:"100%",height:"100%",borderRadius:"inherit"})}),I&&jsx(Spacer,{stretch:!0,children:isValidElement(I)?cloneElement(I,{...y,...w}):typeof I=='function'?I(y):I}),jsxs(Content,{children:[z?jsx(Skeleton,{as:"span",borderRadius:4,children:jsx(Text,{as:"span",appearance:"subheading-compact",sizes:SIZES_TITLE,...y,...i})}):jsx(Text,{as:"span",appearance:"subheading-compact",wordBreak:"break-word",color:"inherit",sizes:SIZES_TITLE,...y,...i,children:f}),E&&!z&&jsx(Text,{as:"span",appearance:"body",wordBreak:"break-word",color:"content-onmain-tertiary",marginTop:f?'0.2em':void 0,sizes:SIZES_SUBTITLE,...y,...t,children:E})]}),jsx(IconAnimated,{...y,preset:"brand",name:"chevronDown",sizes:SIZES_ICON,up:L})]})}),jsx(Panel,{id:v,role:"region","aria-labelledby":_,hidden:!M,onTransitionEnd:e=>{e.propertyName!=='opacity'||L||Z(!1)},children:jsx(Details,{children:h})})]})})),{displayName:'Accordion',sizes:SIZES});export{Accordion};
|
|
2
2
|
//# sourceMappingURL=Accordion.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var React=require('react');var fuse=require('../../external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.js');var index_browser=require('../../external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.js');var withMergedProps=require('../../hocs/withMergedProps.js');var useScrollMonitor=require('../../hooks/useScrollMonitor.js');var dom=require('../../shared/utils/dom.js');var constants$1=require('../../shared/constants.js');var DropdownMenu=require('./DropdownMenu.js');var constants=require('./constants.js');var utils=require('./utils.js');var style=require('./style.js');var require$$0=require('react/jsx-runtime');var FormInputLabel=require('../FormInputLabel/FormInputLabel.js');var FormInput=require('../FormInput/FormInput.js');var Chip=require('../Chip/Chip.js');var IconButton=require('../IconButton/IconButton.js');var MenuList=require('../MenuList/MenuList.js');var ListItem=require('../ListItem/ListItem.js');var InputCheckbox=require('../InputCheckbox/InputCheckbox.js');var MenuDivider=require('../MenuDivider/MenuDivider.js');const Dropdown=withMergedProps.withMergedProps(React.forwardRef(((e,t)=>{const{size:o="m",name:r="fox-dropdown",labelPosition:n="dynamic",searchable:s=!0,primary:a=!0,optionsMultiToggle:i=!0,loading:c=!1,iconProps:l={},menuProps:u={},loadingIconProps:d={},optionsEmptyIconProps:p={},autoFocus:b,disableAutoScrollToSelectedOption:g,closeMenuOnScroll:m,scrollMonitorTarget:v,contrast:f,selectedOption:x,defaultSelectedOption:k,icon:h,inputMode:C,loadingMessage:I,loadingIcon:y,maxLength:$,multiple:w,clearable:q,onCloseMenu:D,onOpenMenu:M,onSelectOption:S,options:R,groupSelectedOptions:j,optionsMultiToggleCaption:L,optionsEmptyMessage:P,optionsEmptyIcon:E,palette:T,placeholder:F,readOnly:B,required:z,status:O,sizeXXS:K,sizeXS:X,sizeS:_,sizeM:H,sizeL:N,sizeXL:Z,form:A,...U}=e;const G={size:o,sizeXXS:K,sizeXS:X,sizeS:_,sizeM:H,sizeL:N,sizeXL:Z};const J={sizes:constants.SIZES_ICON,color:U.disabled?'content-disabled':'content-onmain-tertiary'};const Q=React.useMemo((()=>U.id??`${r}-${index_browser.nanoid()}`),[r,U.id]);const V=React.useMemo((()=>index_browser.nanoid()),[]);const W=React.useMemo((()=>index_browser.nanoid()),[]);const Y=React.useMemo((()=>{const e=new fuse.default(R,{threshold:.4,ignoreLocation:!0,keys:[constants.FuseSearchKeys.text,constants.FuseSearchKeys.label,constants.FuseSearchKeys.tags]});return t=>t.length===0?R:e.search(t).map((e=>e.item))}),[R]);const[ee,te]=React.useState((()=>utils.getDropdownSelectedOption(x!==void 0?x:k,w)));const[oe,re]=React.useState((()=>utils.getDropdownInputText(ee,w)));const[ne,se]=React.useState(!1);const[ae,ie]=React.useState((()=>Y(oe)));const[ce,le]=React.useState(!1);const ue=w?utils.groupDropdownOptions(R,ee):[[],[]];const de=ce&&!U.disabled;const pe=oe===utils.getDropdownInputText(ee);const be=z&&ee.length===0;const ge=Boolean(de||oe||ne);const me=ue[0].length>0&&ue[1].length===0;const ve=ue[0].length>0&&ue[1].length>0;const fe=React.useRef(null);const[xe,ke]=React.useState(null);const he=React.useRef(null);const Ce=React.useRef(null);const Ie=React.useRef(null);const ye=React.useRef(oe);const $e=React.useRef(de);return useScrollMonitor.useScrollMonitor({target:v,onScrollStart:()=>{m&&de&&(fe.current?.focus(),le(!1))}}),React.useEffect((()=>(oe===ye.current?ie(Y(oe)):(ye.current=oe,Ie.current=setTimeout((()=>{ie(Y(oe))}),150)),()=>{Ie.current&&clearTimeout(Ie.current)})),[Y,oe]),React.useLayoutEffect((()=>{x!==void 0&&(w||re(utils.getDropdownInputText(x)),te(utils.getDropdownSelectedOption(x,w)))}),[w,x]),React.useEffect((()=>{de!==$e.current&&(de&&M&&M(),!de&&D&&D(),$e.current=de)}),[de,D,M]),React.useEffect((()=>{if(!w&&!g&&de&&xe&&Ce.current){const e=xe.getBoundingClientRect();const t=Ce.current.getBoundingClientRect();(t.top<e.top||t.bottom>e.bottom)&&setTimeout((()=>{xe&&Ce.current&&xe.scrollTo(0,Ce.current.offsetTop)}),0)}}),[w,g,de,xe]),require$$0.jsx(FormInputLabel.FormInputLabel,{...U,...G,ref:t,id:Q,labelId:V,labelPosition:n,active:ge,onColored:f,primary:a,error:O==='error',success:O==='success',focus:ne,icon:[h,require$$0.jsx(style.ChevronIcon,{up:de},'chevron')],iconProps:{...G,...J,...l},palette:{color:U.disabled?T.labelColorDisabled:T.labelColor,backgroundColor:U.disabled?T.backgroundColorDisabled:T.backgroundColor,backgroundColorHover:U.disabled?T.backgroundColorDisabled:T.backgroundColorHover,borderColor:U.disabled?T.borderColorDisabled:T.borderColor},onClick:e=>{U.onClick&&U.onClick(e),U.disabled||(fe.current?.focus(),de?xe&&e.target instanceof Node&&!xe.contains(e.target)&&le(!1):(le(!0),s&&!w&&pe&&(re(''),ie(Y('')))))},onPointerDown:e=>{U.onPointerDown&&U.onPointerDown(e),e.target!==fe.current&&e.target instanceof Node&&(e.currentTarget.contains(e.target)||u.renderInPortal&&de&&xe&&xe.contains(e.target))&&e.preventDefault()},onFocus:e=>{U.onFocus&&U.onFocus(e),se(!0),fe.current&&e.target===fe.current&&s&&!w&&pe&&!de&&(re(''),ie(Y('')))},onBlur:e=>{U.onBlur&&U.onBlur(e),e.currentTarget.contains(e.relatedTarget)||u.renderInPortal&&de&&xe&&xe.contains(e.relatedTarget)||(se(!1),re(utils.getDropdownInputText(ee,w)),le(!1))},input:require$$0.jsxs(require$$0.Fragment,{children:[be&&!s&&!B&&require$$0.jsx(style.InputMimic,{required:!0,type:"text",inputMode:"none",form:A,tabIndex:-1,onFocus:()=>{fe.current?.focus()}}),require$$0.jsx(FormInput.FormInput,{ref:fe,role:"combobox","aria-controls":W,"aria-expanded":de,"aria-labelledby":U.label?V:void 0,type:"text",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",form:A,autoFocus:b,inputMode:s?C:'none',maxLength:$,placeholder:F,readOnly:B||!s,required:be,disabled:U.disabled,value:oe,palette:{color:T.color,colorDisabled:T.colorDisabled,placeholderColor:T.placeholderColor,placeholderColorDisabled:T.placeholderColorDisabled},onClick:e=>{de&&e.currentTarget.selectionStart!==e.currentTarget.selectionEnd&&e.stopPropagation()},onChange:e=>{re(e.currentTarget.value),le(!0)},onKeyDown:e=>{if(constants$1.keyboardKeys.Enter.validate(e.key)&&(re(utils.getDropdownInputText(ee,w)),le(!1)),!constants$1.keyboardKeys.Space.validate(e.key)||de&&e.currentTarget.selectionStart!==0||(e.preventDefault(),s&&!w&&pe&&!de&&(re(''),ie(Y(''))),le((e=>!e))),constants$1.keyboardKeys.Esc.validate(e.key)&&le(!1),constants$1.keyboardKeys.Tab.validate(e.key)&&de&&(e.preventDefault(),le(!1)),constants$1.keyboardKeys.ArrowDown.validate(e.key)&&de&&he.current)if(e.preventDefault(),!w&&Ce.current){const e=[...he.current.children];const t=e.findIndex((e=>e.contains(Ce.current)));const o=e[t+1]??e[0];o instanceof HTMLElement&&dom.focusFirstFocusable(o)}else dom.focusFirstFocusable(he.current);if(constants$1.keyboardKeys.ArrowUp.validate(e.key)&&de&&he.current)if(e.preventDefault(),!w&&Ce.current){const e=[...he.current.children];const t=e.findIndex((e=>e.contains(Ce.current)));const o=e[t-1]??e[e.length-1];o instanceof HTMLElement&&dom.focusFirstFocusable(o)}else dom.focusLastFocusable(he.current)}}),ee.map((e=>require$$0.jsx("input",{type:"hidden",name:r,value:e.value,form:A,disabled:U.disabled},e.value)))]}),addon:require$$0.jsxs(require$$0.Fragment,{children:[w&&ee.length>0&&require$$0.jsx(Chip.Chip,{size:"xs",active:!0,black:!0,marginLeft:12,disabled:U.disabled,cursor:U.disabled?'not-allowed':void 0,text:ee.length,textProps:{appearance:'caption',size:'xs'},palette:U.disabled?{color:'content-disabled',colorHover:'content-disabled',backgroundColor:'bg-disabled-small',backgroundColorHover:'bg-disabled-small'}:void 0,onPointerDown:e=>{e.preventDefault()},discardButtonProps:{square:!0,contrast:!U.disabled,onClick:e=>{e.stopPropagation(),B||(x===void 0&&te([]),S&&S(w?[]:null),fe.current?.focus(),le(!0))}}}),!w&&q&&ee.length>0&&require$$0.jsx(IconButton.IconButton,{icon:"close",size:"l",square:!0,marginLeft:12,disabled:U.disabled,onClick:e=>{e.stopPropagation(),B||(pe&&(re(''),ie(Y(''))),x===void 0&&te([]),S&&S(w?[]:null),fe.current?.focus(),le(!0))}})]}),dropdown:require$$0.jsx(DropdownMenu.DropdownMenu,{...u,setRef:ke,open:de,popperReferenceId:Q,secondary:!f,elevated:f,disableAutoFocus:!0,palette:{backgroundColor:T.menuBackgroundColor,borderColor:T.menuBorderColor},empty:ae.length===0,loading:c,loadingMessage:I,loadingIcon:y,loadingIconProps:{...G,...J,...d},emptyMessage:P,emptyIcon:E,emptyIconProps:{...G,...J,...p},onKeyDown:e=>{constants$1.keyboardKeys.Tab.validate(e.key)&&(e.preventDefault(),fe.current?.focus(),le(!1)),constants$1.keyboardKeys.Enter.validate(e.key)&&(fe.current?.focus(),re(utils.getDropdownInputText(ee,w)),le(!1)),constants$1.keyboardKeys.Esc.validate(e.key)&&(fe.current?.focus(),le(!1)),constants$1.keyboardKeys.Backspace.validate(e.key)&&!B&&(w||!w&&q)&&(x===void 0&&te([]),S&&S(w?[]:null))},children:require$$0.jsx(MenuList.MenuList,w?{ref:he,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,"aria-multiselectable":!0,children:oe.length===0?require$$0.jsxs(require$$0.Fragment,{children:[i&&require$$0.jsx(ListItem.ListItem,{...G,text:L,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",name:r,checked:me,indeterminate:ve,error:(me||ve)&&O==='error',success:(me||ve)&&O==='success',onChange:()=>{if(!B){const e=me||ve?[]:[...R];x===void 0&&te(e),S&&S(e)}}})}),i&&require$$0.jsx(MenuDivider.MenuDivider,{}),j&&ue[0].map((e=>{const t=e.status??O;const o=t==='error';const n=t==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,active:!0,text:e.text,danger:o,success:n,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),fe.current?.focus()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!0,name:r,value:e.value,checked:!0,error:o,success:n,onChange:e=>{if(!B){const t=ee.filter((t=>t.value!==e.currentTarget.value));x===void 0&&te(t),S&&S(t)}}})})})),j&&ue[0].length>0&&ue[1].length>0&&require$$0.jsx(MenuDivider.MenuDivider,{}),j&&ue[1].map((e=>React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),fe.current?.focus()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!1,name:r,value:e.value,checked:!1,onChange:()=>{if(!B){const t=[...ee,e];x===void 0&&te(t),S&&S(t)}}})}))),!j&&R.map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;const o=e.status??O;const n=t&&o==='error';const s=t&&o==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:t,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":t,name:r,value:e.value,checked:t,error:n,success:s,onChange:o=>{if(!B){const r=t?ee.filter((e=>e.value!==o.currentTarget.value)):[...ee,e];x===void 0&&te(r),S&&S(r)}}})})}))]}):require$$0.jsx(require$$0.Fragment,{children:ae.map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;const o=e.status??O;const n=t&&o==='error';const s=t&&o==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:t,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":t,name:r,value:e.value,checked:t,error:n,success:s,onChange:o=>{if(!B){const r=t?ee.filter((e=>e.value!==o.currentTarget.value)):[...ee,e];x===void 0&&te(r),S&&S(r)}}})})}))})}:{ref:he,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,children:(s?ae:R).map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;return React.createElement(ListItem.ListItem,{...G,role:"option","aria-selected":t,ref:t?Ce:void 0,key:e.value,text:e.text,active:t,danger:t&&O==='error',success:t&&O==='success',disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:t=>{if(t.stopPropagation(),!B){const t={...e};x===void 0&&(re(utils.getDropdownInputText(t)),te(utils.getDropdownSelectedOption(t))),S&&S(t),fe.current?.focus(),le(!1)}}})}))})})})})),{sizes:constants.SIZES,displayName:"Dropdown"});exports.COMPONENT_NAME="Dropdown",exports.Dropdown=Dropdown;
|
|
1
|
+
'use strict';var React=require('react');var fuse=require('../../external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.js');var index_browser=require('../../external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.js');var withMergedProps=require('../../hocs/withMergedProps.js');var useScrollMonitor=require('../../hooks/useScrollMonitor.js');var dom=require('../../shared/utils/dom.js');var constants$1=require('../../shared/constants.js');var DropdownMenu=require('./DropdownMenu.js');var constants=require('./constants.js');var utils=require('./utils.js');var style=require('./style.js');var require$$0=require('react/jsx-runtime');var FormInputLabel=require('../FormInputLabel/FormInputLabel.js');var FormInput=require('../FormInput/FormInput.js');var Chip=require('../Chip/Chip.js');var IconButton=require('../IconButton/IconButton.js');var MenuList=require('../MenuList/MenuList.js');var ListItem=require('../ListItem/ListItem.js');var InputCheckbox=require('../InputCheckbox/InputCheckbox.js');var MenuDivider=require('../MenuDivider/MenuDivider.js');const Dropdown=withMergedProps.withMergedProps(React.forwardRef(((e,t)=>{const{size:o="m",name:r="fox-dropdown",labelPosition:n="dynamic",searchable:s=!0,primary:a=!0,optionsMultiToggle:i=!0,loading:c=!1,iconProps:l={},menuProps:u={},loadingIconProps:d={},optionsEmptyIconProps:p={},autoFocus:b,disableAutoScrollToSelectedOption:g,closeMenuOnScroll:m,scrollMonitorTarget:v,contrast:f,selectedOption:x,defaultSelectedOption:k,icon:h,inputMode:C,loadingMessage:I,loadingIcon:y,maxLength:$,multiple:w,clearable:q,onCloseMenu:D,onOpenMenu:M,onSelectOption:S,options:R,groupSelectedOptions:j,optionsMultiToggleCaption:L,optionsEmptyMessage:P,optionsEmptyIcon:E,palette:T,placeholder:F,readOnly:B,required:z,status:O,sizeXXS:K,sizeXS:X,sizeS:_,sizeM:H,sizeL:N,sizeXL:Z,form:A,...U}=e;const G={size:o,sizeXXS:K,sizeXS:X,sizeS:_,sizeM:H,sizeL:N,sizeXL:Z};const J={sizes:constants.SIZES_ICON,color:U.disabled?'content-disabled':'content-onmain-tertiary'};const Q=React.useMemo((()=>U.id??`${r}-${index_browser.nanoid()}`),[r,U.id]);const V=React.useMemo((()=>index_browser.nanoid()),[]);const W=React.useMemo((()=>index_browser.nanoid()),[]);const Y=React.useMemo((()=>{const e=new fuse.default(R,{threshold:.4,ignoreLocation:!0,keys:[constants.FuseSearchKeys.text,constants.FuseSearchKeys.label,constants.FuseSearchKeys.tags]});return t=>t.length===0?R:e.search(t).map((e=>e.item))}),[R]);const[ee,te]=React.useState((()=>utils.getDropdownSelectedOption(x!==void 0?x:k,w)));const[oe,re]=React.useState((()=>utils.getDropdownInputText(ee,w)));const[ne,se]=React.useState(!1);const[ae,ie]=React.useState((()=>Y(oe)));const[ce,le]=React.useState(!1);const ue=w?utils.groupDropdownOptions(R,ee):[[],[]];const de=ce&&!U.disabled;const pe=oe===utils.getDropdownInputText(ee);const be=z&&ee.length===0;const ge=Boolean(de||oe||ne);const me=ue[0].length>0&&ue[1].length===0;const ve=ue[0].length>0&&ue[1].length>0;const fe=React.useRef(null);const[xe,ke]=React.useState(null);const he=React.useRef(null);const Ce=React.useRef(null);const Ie=React.useRef(null);const ye=React.useRef(oe);const $e=React.useRef(de);return useScrollMonitor.useScrollMonitor({target:v,onScrollStart:()=>{m&&de&&(fe.current?.focus(),le(!1))}}),React.useEffect((()=>(oe===ye.current?ie(Y(oe)):(ye.current=oe,Ie.current=setTimeout((()=>{ie(Y(oe))}),150)),()=>{Ie.current&&clearTimeout(Ie.current)})),[Y,oe]),React.useLayoutEffect((()=>{x!==void 0&&(w||re(utils.getDropdownInputText(x)),te(utils.getDropdownSelectedOption(x,w)))}),[w,x]),React.useEffect((()=>{de!==$e.current&&(de&&M&&M(),!de&&D&&D(),$e.current=de)}),[de,D,M]),React.useEffect((()=>{if(!w&&!g&&de&&xe&&Ce.current){const e=xe.getBoundingClientRect();const t=Ce.current.getBoundingClientRect();(t.top<e.top||t.bottom>e.bottom)&&setTimeout((()=>{xe&&Ce.current&&xe.scrollTo(0,Ce.current.offsetTop)}),0)}}),[w,g,de,xe]),require$$0.jsx(FormInputLabel.FormInputLabel,{...U,...G,ref:t,id:Q,labelId:V,labelPosition:n,active:ge,onColored:f,primary:a,error:O==='error',success:O==='success',focus:ne,icon:[h,require$$0.jsx(style.ChevronIcon,{up:de},'chevron')],iconProps:{...G,...J,...l},palette:{color:U.disabled?T.labelColorDisabled:T.labelColor,backgroundColor:U.disabled?T.backgroundColorDisabled:T.backgroundColor,backgroundColorHover:U.disabled?T.backgroundColorDisabled:T.backgroundColorHover,borderColor:U.disabled?T.borderColorDisabled:T.borderColor},onClick:e=>{U.onClick&&U.onClick(e),U.disabled||(fe.current?.focus(),de?xe&&e.target instanceof Node&&!xe.contains(e.target)&&le(!1):(le(!0),s&&!w&&pe&&(re(''),ie(Y('')))))},onPointerDown:e=>{U.onPointerDown&&U.onPointerDown(e),e.target!==fe.current&&e.target instanceof Node&&(e.currentTarget.contains(e.target)||u.renderInPortal&&de&&xe&&xe.contains(e.target))&&e.preventDefault()},onFocus:e=>{U.onFocus&&U.onFocus(e),se(!0),fe.current&&e.target===fe.current&&s&&!w&&pe&&!de&&(re(''),ie(Y('')))},onBlur:e=>{U.onBlur&&U.onBlur(e),e.currentTarget.contains(e.relatedTarget)||u.renderInPortal&&de&&xe&&xe.contains(e.relatedTarget)||(se(!1),re(utils.getDropdownInputText(ee,w)),le(!1))},input:require$$0.jsxs(require$$0.Fragment,{children:[be&&!s&&!B&&require$$0.jsx(style.InputMimic,{required:!0,type:"text",inputMode:"none",form:A,tabIndex:-1,onFocus:()=>{fe.current?.focus()}}),require$$0.jsx(FormInput.FormInput,{ref:fe,role:"combobox","aria-controls":W,"aria-expanded":de,"aria-labelledby":U.label?V:void 0,type:"text",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",form:A,autoFocus:b,inputMode:s?C:'none',maxLength:$,placeholder:F,readOnly:B||!s,required:be,disabled:U.disabled,value:oe,palette:{color:T.color,colorDisabled:T.colorDisabled,placeholderColor:T.placeholderColor,placeholderColorDisabled:T.placeholderColorDisabled},onClick:e=>{de&&e.currentTarget.selectionStart!==e.currentTarget.selectionEnd&&e.stopPropagation()},onChange:e=>{re(e.currentTarget.value),le(!0)},onKeyDown:e=>{if(constants$1.keyboardKeys.Enter.validate(e.key)&&(re(utils.getDropdownInputText(ee,w)),le(!1)),!constants$1.keyboardKeys.Space.validate(e.key)||de&&e.currentTarget.selectionStart!==0||(e.preventDefault(),s&&!w&&pe&&!de&&(re(''),ie(Y(''))),le((e=>!e))),constants$1.keyboardKeys.Esc.validate(e.key)&&le(!1),constants$1.keyboardKeys.Tab.validate(e.key)&&de&&(e.preventDefault(),le(!1)),constants$1.keyboardKeys.ArrowDown.validate(e.key)&&de&&he.current)if(e.preventDefault(),!w&&Ce.current){const e=[...he.current.children];const t=e.findIndex((e=>e.contains(Ce.current)));const o=e[t+1]??e[0];o instanceof HTMLElement&&dom.focusFirstFocusable(o)}else dom.focusFirstFocusable(he.current);if(constants$1.keyboardKeys.ArrowUp.validate(e.key)&&de&&he.current)if(e.preventDefault(),!w&&Ce.current){const e=[...he.current.children];const t=e.findIndex((e=>e.contains(Ce.current)));const o=e[t-1]??e[e.length-1];o instanceof HTMLElement&&dom.focusFirstFocusable(o)}else dom.focusLastFocusable(he.current)}}),ee.map((e=>require$$0.jsx("input",{type:"hidden",name:r,value:e.value,form:A,disabled:U.disabled},e.value)))]}),addon:require$$0.jsxs(require$$0.Fragment,{children:[w&&ee.length>0&&require$$0.jsx(Chip.Chip,{size:"xs",active:!0,black:!0,marginLeft:12,disabled:U.disabled,cursor:U.disabled?'not-allowed':void 0,text:ee.length,textProps:{appearance:'caption',size:'xs'},palette:U.disabled?{color:'content-disabled',colorHover:'content-disabled',backgroundColor:'bg-disabled-small',backgroundColorHover:'bg-disabled-small'}:void 0,onPointerDown:e=>{e.preventDefault()},discardButtonProps:{square:!0,contrast:!U.disabled,onClick:e=>{e.stopPropagation(),B||(x===void 0&&te([]),S&&S(w?[]:null),fe.current?.focus(),le(!0))}}}),!w&&q&&ee.length>0&&require$$0.jsx(IconButton.IconButton,{icon:"close",size:"l",square:!0,marginLeft:12,disabled:U.disabled,onClick:e=>{e.stopPropagation(),B||(pe&&(re(''),ie(Y(''))),x===void 0&&te([]),S&&S(w?[]:null),fe.current?.focus(),le(!0))}})]}),dropdown:require$$0.jsx(DropdownMenu.DropdownMenu,{...u,setRef:ke,open:de,popperReferenceId:Q,secondary:!f,elevated:f,disableAutoFocus:!0,palette:{backgroundColor:T.menuBackgroundColor,borderColor:T.menuBorderColor},empty:ae.length===0,loading:c,loadingMessage:I,loadingIcon:y,loadingIconProps:{...G,...J,...d},emptyMessage:P,emptyIcon:E,emptyIconProps:{...G,...J,...p},onKeyDown:e=>{constants$1.keyboardKeys.Tab.validate(e.key)&&(e.preventDefault(),fe.current?.focus(),le(!1)),constants$1.keyboardKeys.Enter.validate(e.key)&&(fe.current?.focus(),re(utils.getDropdownInputText(ee,w)),le(!1)),constants$1.keyboardKeys.Esc.validate(e.key)&&(fe.current?.focus(),le(!1)),constants$1.keyboardKeys.Backspace.validate(e.key)&&!B&&(w||!w&&q)&&(x===void 0&&te([]),S&&S(w?[]:null))},children:require$$0.jsx(MenuList.MenuList,w?{ref:he,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,"aria-multiselectable":!0,children:oe.length===0?require$$0.jsxs(require$$0.Fragment,{children:[i&&require$$0.jsx(ListItem.ListItem,{...G,text:L,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",name:r,checked:me,indeterminate:ve,error:(me||ve)&&O==='error',success:(me||ve)&&O==='success',onChange:()=>{if(!B){const e=me||ve?[]:[...R];x===void 0&&te(e),S&&S(e)}}})}),i&&require$$0.jsx(MenuDivider.MenuDivider,{}),j&&ue[0].map((e=>{const t=e.status??O;const o=t==='error';const n=t==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,active:!0,text:e.text,danger:o,success:n,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),fe.current?.focus()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!0,name:r,value:e.value,checked:!0,error:o,success:n,onChange:e=>{if(!B){const t=ee.filter((t=>t.value!==e.currentTarget.value));x===void 0&&te(t),S&&S(t)}}})})})),j&&ue[0].length>0&&ue[1].length>0&&require$$0.jsx(MenuDivider.MenuDivider,{}),j&&ue[1].map((e=>React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),fe.current?.focus()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!1,name:r,value:e.value,checked:!1,onChange:()=>{if(!B){const t=[...ee,e];x===void 0&&te(t),S&&S(t)}}})}))),!j&&R.map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;const o=e.status??O;const n=t&&o==='error';const s=t&&o==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:t,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":t,name:r,value:e.value,checked:t,error:n,success:s,onChange:o=>{if(!B){const r=t?ee.filter((e=>e.value!==o.currentTarget.value)):[...ee,e];x===void 0&&te(r),S&&S(r)}}})})}))]}):require$$0.jsx(require$$0.Fragment,{children:ae.map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;const o=e.status??O;const n=t&&o==='error';const s=t&&o==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:t,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":t,name:r,value:e.value,checked:t,error:n,success:s,onChange:o=>{if(!B){const r=t?ee.filter((e=>e.value!==o.currentTarget.value)):[...ee,e];x===void 0&&te(r),S&&S(r)}}})})}))})}:{ref:he,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,children:(s?ae:R).map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;return React.createElement(ListItem.ListItem,{...G,role:"option","aria-selected":t,ref:t?Ce:void 0,key:e.value,text:e.text,active:t,danger:t&&O==='error',success:t&&O==='success',disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:t=>{if(t.stopPropagation(),!B){const t={...e};x===void 0&&(re(utils.getDropdownInputText(t)),te(utils.getDropdownSelectedOption(t))),S&&S(t),fe.current?.focus(),le(!1)}}})}))})})})})),{sizes:constants.SIZES,displayName:"Dropdown"});exports.COMPONENT_NAME="Dropdown",exports.Dropdown=Dropdown;
|
|
2
2
|
//# sourceMappingURL=Dropdown.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{forwardRef,useMemo,useState,useRef,useEffect,useLayoutEffect,createElement}from'react';import Fuse from'../../external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.mjs';import{nanoid}from'../../external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.mjs';import{withMergedProps}from'../../hocs/withMergedProps.mjs';import{useScrollMonitor}from'../../hooks/useScrollMonitor.mjs';import{focusFirstFocusable,focusLastFocusable}from'../../shared/utils/dom.mjs';import{keyboardKeys}from'../../shared/constants.mjs';import{DropdownMenu}from'./DropdownMenu.mjs';import{SIZES,SIZES_ICON,FuseSearchKeys,SIZES_CHECKBOX}from'./constants.mjs';import{getDropdownSelectedOption,getDropdownInputText,groupDropdownOptions}from'./utils.mjs';import{ChevronIcon,InputMimic}from'./style.mjs';import{jsx,jsxs,Fragment}from'react/jsx-runtime';import{FormInputLabel}from'../FormInputLabel/FormInputLabel.mjs';import{FormInput}from'../FormInput/FormInput.mjs';import{Chip}from'../Chip/Chip.mjs';import{IconButton}from'../IconButton/IconButton.mjs';import{MenuList}from'../MenuList/MenuList.mjs';import{ListItem}from'../ListItem/ListItem.mjs';import{InputCheckbox}from'../InputCheckbox/InputCheckbox.mjs';import{MenuDivider}from'../MenuDivider/MenuDivider.mjs';const COMPONENT_NAME='Dropdown';const Dropdown=withMergedProps(forwardRef(((e,o)=>{const{size:t="m",name:r="fox-dropdown",labelPosition:n="dynamic",searchable:s=!0,primary:a=!0,optionsMultiToggle:l=!0,loading:i=!1,iconProps:c={},menuProps:d={},loadingIconProps:u={},optionsEmptyIconProps:p={},autoFocus:m,disableAutoScrollToSelectedOption:b,closeMenuOnScroll:f,scrollMonitorTarget:g,contrast:v,selectedOption:x,defaultSelectedOption:k,icon:C,inputMode:h,loadingMessage:I,loadingIcon:y,maxLength:S,multiple:w,clearable:D,onCloseMenu:M,onOpenMenu:j,onSelectOption:E,options:P,groupSelectedOptions:F,optionsMultiToggleCaption:T,optionsEmptyMessage:L,optionsEmptyIcon:O,palette:B,placeholder:z,readOnly:K,required:R,status:X,sizeXXS:H,sizeXS:_,sizeS:N,sizeM:Z,sizeL:A,sizeXL:q,form:$,...U}=e;const G={size:t,sizeXXS:H,sizeXS:_,sizeS:N,sizeM:Z,sizeL:A,sizeXL:q};const J={sizes:SIZES_ICON,color:U.disabled?'content-disabled':'content-onmain-tertiary'};const Q=useMemo((()=>U.id??`${r}-${nanoid()}`),[r,U.id]);const V=useMemo((()=>nanoid()),[]);const W=useMemo((()=>nanoid()),[]);const Y=useMemo((()=>{const e=new Fuse(P,{threshold:.4,ignoreLocation:!0,keys:[FuseSearchKeys.text,FuseSearchKeys.label,FuseSearchKeys.tags]});return o=>o.length===0?P:e.search(o).map((e=>e.item))}),[P]);const[ee,oe]=useState((()=>getDropdownSelectedOption(x!==void 0?x:k,w)));const[te,re]=useState((()=>getDropdownInputText(ee,w)));const[ne,se]=useState(!1);const[ae,le]=useState((()=>Y(te)));const[ie,ce]=useState(!1);const de=w?groupDropdownOptions(P,ee):[[],[]];const ue=ie&&!U.disabled;const pe=te===getDropdownInputText(ee);const me=R&&ee.length===0;const be=Boolean(ue||te||ne);const fe=de[0].length>0&&de[1].length===0;const ge=de[0].length>0&&de[1].length>0;const ve=useRef(null);const[xe,ke]=useState(null);const Ce=useRef(null);const he=useRef(null);const Ie=useRef(null);const ye=useRef(te);const Se=useRef(ue);return useScrollMonitor({target:g,onScrollStart:()=>{f&&ue&&(ve.current?.focus(),ce(!1))}}),useEffect((()=>(te===ye.current?le(Y(te)):(ye.current=te,Ie.current=setTimeout((()=>{le(Y(te))}),150)),()=>{Ie.current&&clearTimeout(Ie.current)})),[Y,te]),useLayoutEffect((()=>{x!==void 0&&(w||re(getDropdownInputText(x)),oe(getDropdownSelectedOption(x,w)))}),[w,x]),useEffect((()=>{ue!==Se.current&&(ue&&j&&j(),!ue&&M&&M(),Se.current=ue)}),[ue,M,j]),useEffect((()=>{if(!w&&!b&&ue&&xe&&he.current){const e=xe.getBoundingClientRect();const o=he.current.getBoundingClientRect();(o.top<e.top||o.bottom>e.bottom)&&setTimeout((()=>{xe&&he.current&&xe.scrollTo(0,he.current.offsetTop)}),0)}}),[w,b,ue,xe]),jsx(FormInputLabel,{...U,...G,ref:o,id:Q,labelId:V,labelPosition:n,active:be,onColored:v,primary:a,error:X==='error',success:X==='success',focus:ne,icon:[C,jsx(ChevronIcon,{up:ue},'chevron')],iconProps:{...G,...J,...c},palette:{color:U.disabled?B.labelColorDisabled:B.labelColor,backgroundColor:U.disabled?B.backgroundColorDisabled:B.backgroundColor,backgroundColorHover:U.disabled?B.backgroundColorDisabled:B.backgroundColorHover,borderColor:U.disabled?B.borderColorDisabled:B.borderColor},onClick:e=>{U.onClick&&U.onClick(e),U.disabled||(ve.current?.focus(),ue?xe&&e.target instanceof Node&&!xe.contains(e.target)&&ce(!1):(ce(!0),s&&!w&&pe&&(re(''),le(Y('')))))},onPointerDown:e=>{U.onPointerDown&&U.onPointerDown(e),e.target!==ve.current&&e.target instanceof Node&&(e.currentTarget.contains(e.target)||d.renderInPortal&&ue&&xe&&xe.contains(e.target))&&e.preventDefault()},onFocus:e=>{U.onFocus&&U.onFocus(e),se(!0),ve.current&&e.target===ve.current&&s&&!w&&pe&&!ue&&(re(''),le(Y('')))},onBlur:e=>{U.onBlur&&U.onBlur(e),e.currentTarget.contains(e.relatedTarget)||d.renderInPortal&&ue&&xe&&xe.contains(e.relatedTarget)||(se(!1),re(getDropdownInputText(ee,w)),ce(!1))},input:jsxs(Fragment,{children:[me&&!s&&!K&&jsx(InputMimic,{required:!0,type:"text",inputMode:"none",form:$,tabIndex:-1,onFocus:()=>{ve.current?.focus()}}),jsx(FormInput,{ref:ve,role:"combobox","aria-controls":W,"aria-expanded":ue,"aria-labelledby":U.label?V:void 0,type:"text",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",form:$,autoFocus:m,inputMode:s?h:'none',maxLength:S,placeholder:z,readOnly:K||!s,required:me,disabled:U.disabled,value:te,palette:{color:B.color,colorDisabled:B.colorDisabled,placeholderColor:B.placeholderColor,placeholderColorDisabled:B.placeholderColorDisabled},onClick:e=>{ue&&e.currentTarget.selectionStart!==e.currentTarget.selectionEnd&&e.stopPropagation()},onChange:e=>{re(e.currentTarget.value),ce(!0)},onKeyDown:e=>{if(keyboardKeys.Enter.validate(e.key)&&(re(getDropdownInputText(ee,w)),ce(!1)),!keyboardKeys.Space.validate(e.key)||ue&&e.currentTarget.selectionStart!==0||(e.preventDefault(),s&&!w&&pe&&!ue&&(re(''),le(Y(''))),ce((e=>!e))),keyboardKeys.Esc.validate(e.key)&&ce(!1),keyboardKeys.Tab.validate(e.key)&&ue&&(e.preventDefault(),ce(!1)),keyboardKeys.ArrowDown.validate(e.key)&&ue&&Ce.current)if(e.preventDefault(),!w&&he.current){const e=[...Ce.current.children];const o=e.findIndex((e=>e.contains(he.current)));const t=e[o+1]??e[0];t instanceof HTMLElement&&focusFirstFocusable(t)}else focusFirstFocusable(Ce.current);if(keyboardKeys.ArrowUp.validate(e.key)&&ue&&Ce.current)if(e.preventDefault(),!w&&he.current){const e=[...Ce.current.children];const o=e.findIndex((e=>e.contains(he.current)));const t=e[o-1]??e[e.length-1];t instanceof HTMLElement&&focusFirstFocusable(t)}else focusLastFocusable(Ce.current)}}),ee.map((e=>jsx("input",{type:"hidden",name:r,value:e.value,form:$,disabled:U.disabled},e.value)))]}),addon:jsxs(Fragment,{children:[w&&ee.length>0&&jsx(Chip,{size:"xs",active:!0,black:!0,marginLeft:12,disabled:U.disabled,cursor:U.disabled?'not-allowed':void 0,text:ee.length,textProps:{appearance:'caption',size:'xs'},palette:U.disabled?{color:'content-disabled',colorHover:'content-disabled',backgroundColor:'bg-disabled-small',backgroundColorHover:'bg-disabled-small'}:void 0,onPointerDown:e=>{e.preventDefault()},discardButtonProps:{square:!0,contrast:!U.disabled,onClick:e=>{e.stopPropagation(),K||(x===void 0&&oe([]),E&&E(w?[]:null),ve.current?.focus(),ce(!0))}}}),!w&&D&&ee.length>0&&jsx(IconButton,{icon:"close",size:"l",square:!0,marginLeft:12,disabled:U.disabled,onClick:e=>{e.stopPropagation(),K||(pe&&(re(''),le(Y(''))),x===void 0&&oe([]),E&&E(w?[]:null),ve.current?.focus(),ce(!0))}})]}),dropdown:jsx(DropdownMenu,{...d,setRef:ke,open:ue,popperReferenceId:Q,secondary:!v,elevated:v,disableAutoFocus:!0,palette:{backgroundColor:B.menuBackgroundColor,borderColor:B.menuBorderColor},empty:ae.length===0,loading:i,loadingMessage:I,loadingIcon:y,loadingIconProps:{...G,...J,...u},emptyMessage:L,emptyIcon:O,emptyIconProps:{...G,...J,...p},onKeyDown:e=>{keyboardKeys.Tab.validate(e.key)&&(e.preventDefault(),ve.current?.focus(),ce(!1)),keyboardKeys.Enter.validate(e.key)&&(ve.current?.focus(),re(getDropdownInputText(ee,w)),ce(!1)),keyboardKeys.Esc.validate(e.key)&&(ve.current?.focus(),ce(!1)),keyboardKeys.Backspace.validate(e.key)&&!K&&(w||!w&&D)&&(x===void 0&&oe([]),E&&E(w?[]:null))},children:jsx(MenuList,w?{ref:Ce,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,"aria-multiselectable":!0,children:te.length===0?jsxs(Fragment,{children:[l&&jsx(ListItem,{...G,text:T,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",name:r,checked:fe,indeterminate:ge,error:(fe||ge)&&X==='error',success:(fe||ge)&&X==='success',onChange:()=>{if(!K){const e=fe||ge?[]:[...P];x===void 0&&oe(e),E&&E(e)}}})}),l&&jsx(MenuDivider,{}),F&&de[0].map((e=>{const o=e.status??X;const t=o==='error';const n=o==='success';return createElement(ListItem,{...G,key:e.value,active:!0,text:e.text,danger:t,success:n,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ve.current?.focus()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!0,name:r,value:e.value,checked:!0,error:t,success:n,onChange:e=>{if(!K){const o=ee.filter((o=>o.value!==e.currentTarget.value));x===void 0&&oe(o),E&&E(o)}}})})})),F&&de[0].length>0&&de[1].length>0&&jsx(MenuDivider,{}),F&&de[1].map((e=>createElement(ListItem,{...G,key:e.value,text:e.text,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ve.current?.focus()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!1,name:r,value:e.value,checked:!1,onChange:()=>{if(!K){const o=[...ee,e];x===void 0&&oe(o),E&&E(o)}}})}))),!F&&P.map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;const t=e.status??X;const n=o&&t==='error';const s=o&&t==='success';return createElement(ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:o,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":o,name:r,value:e.value,checked:o,error:n,success:s,onChange:t=>{if(!K){const r=o?ee.filter((e=>e.value!==t.currentTarget.value)):[...ee,e];x===void 0&&oe(r),E&&E(r)}}})})}))]}):jsx(Fragment,{children:ae.map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;const t=e.status??X;const n=o&&t==='error';const s=o&&t==='success';return createElement(ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:o,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":o,name:r,value:e.value,checked:o,error:n,success:s,onChange:t=>{if(!K){const r=o?ee.filter((e=>e.value!==t.currentTarget.value)):[...ee,e];x===void 0&&oe(r),E&&E(r)}}})})}))})}:{ref:Ce,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,children:(s?ae:P).map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;return createElement(ListItem,{...G,role:"option","aria-selected":o,ref:o?he:void 0,key:e.value,text:e.text,active:o,danger:o&&X==='error',success:o&&X==='success',disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:o=>{if(o.stopPropagation(),!K){const o={...e};x===void 0&&(re(getDropdownInputText(o)),oe(getDropdownSelectedOption(o))),E&&E(o),ve.current?.focus(),ce(!1)}}})}))})})})})),{sizes:SIZES,displayName:"Dropdown"});export{COMPONENT_NAME,Dropdown};
|
|
1
|
+
import{forwardRef,useMemo,useState,useRef,useEffect,useLayoutEffect,createElement}from'react';import Fuse from'../../external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.mjs';import{nanoid}from'../../external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.mjs';import{withMergedProps}from'../../hocs/withMergedProps.mjs';import{useScrollMonitor}from'../../hooks/useScrollMonitor.mjs';import{focusFirstFocusable,focusLastFocusable}from'../../shared/utils/dom.mjs';import{keyboardKeys}from'../../shared/constants.mjs';import{DropdownMenu}from'./DropdownMenu.mjs';import{SIZES,SIZES_ICON,FuseSearchKeys,SIZES_CHECKBOX}from'./constants.mjs';import{getDropdownSelectedOption,getDropdownInputText,groupDropdownOptions}from'./utils.mjs';import{ChevronIcon,InputMimic}from'./style.mjs';import{jsx,jsxs,Fragment}from'react/jsx-runtime';import{FormInputLabel}from'../FormInputLabel/FormInputLabel.mjs';import{FormInput}from'../FormInput/FormInput.mjs';import{Chip}from'../Chip/Chip.mjs';import{IconButton}from'../IconButton/IconButton.mjs';import{MenuList}from'../MenuList/MenuList.mjs';import{ListItem}from'../ListItem/ListItem.mjs';import{InputCheckbox}from'../InputCheckbox/InputCheckbox.mjs';import{MenuDivider}from'../MenuDivider/MenuDivider.mjs';const COMPONENT_NAME='Dropdown';const Dropdown=withMergedProps(forwardRef(((e,o)=>{const{size:t="m",name:r="fox-dropdown",labelPosition:n="dynamic",searchable:s=!0,primary:a=!0,optionsMultiToggle:l=!0,loading:i=!1,iconProps:c={},menuProps:d={},loadingIconProps:u={},optionsEmptyIconProps:p={},autoFocus:m,disableAutoScrollToSelectedOption:b,closeMenuOnScroll:f,scrollMonitorTarget:g,contrast:v,selectedOption:x,defaultSelectedOption:k,icon:C,inputMode:h,loadingMessage:I,loadingIcon:y,maxLength:S,multiple:w,clearable:D,onCloseMenu:M,onOpenMenu:j,onSelectOption:E,options:P,groupSelectedOptions:F,optionsMultiToggleCaption:T,optionsEmptyMessage:L,optionsEmptyIcon:O,palette:B,placeholder:z,readOnly:K,required:R,status:X,sizeXXS:H,sizeXS:_,sizeS:N,sizeM:Z,sizeL:A,sizeXL:q,form:$,...U}=e;const G={size:t,sizeXXS:H,sizeXS:_,sizeS:N,sizeM:Z,sizeL:A,sizeXL:q};const J={sizes:SIZES_ICON,color:U.disabled?'content-disabled':'content-onmain-tertiary'};const Q=useMemo((()=>U.id??`${r}-${nanoid()}`),[r,U.id]);const V=useMemo((()=>nanoid()),[]);const W=useMemo((()=>nanoid()),[]);const Y=useMemo((()=>{const e=new Fuse(P,{threshold:.4,ignoreLocation:!0,keys:[FuseSearchKeys.text,FuseSearchKeys.label,FuseSearchKeys.tags]});return o=>o.length===0?P:e.search(o).map((e=>e.item))}),[P]);const[ee,oe]=useState((()=>getDropdownSelectedOption(x!==void 0?x:k,w)));const[te,re]=useState((()=>getDropdownInputText(ee,w)));const[ne,se]=useState(!1);const[ae,le]=useState((()=>Y(te)));const[ie,ce]=useState(!1);const de=w?groupDropdownOptions(P,ee):[[],[]];const ue=ie&&!U.disabled;const pe=te===getDropdownInputText(ee);const me=R&&ee.length===0;const be=Boolean(ue||te||ne);const fe=de[0].length>0&&de[1].length===0;const ge=de[0].length>0&&de[1].length>0;const ve=useRef(null);const[xe,ke]=useState(null);const Ce=useRef(null);const he=useRef(null);const Ie=useRef(null);const ye=useRef(te);const Se=useRef(ue);return useScrollMonitor({target:g,onScrollStart:()=>{f&&ue&&(ve.current?.focus(),ce(!1))}}),useEffect((()=>(te===ye.current?le(Y(te)):(ye.current=te,Ie.current=setTimeout((()=>{le(Y(te))}),150)),()=>{Ie.current&&clearTimeout(Ie.current)})),[Y,te]),useLayoutEffect((()=>{x!==void 0&&(w||re(getDropdownInputText(x)),oe(getDropdownSelectedOption(x,w)))}),[w,x]),useEffect((()=>{ue!==Se.current&&(ue&&j&&j(),!ue&&M&&M(),Se.current=ue)}),[ue,M,j]),useEffect((()=>{if(!w&&!b&&ue&&xe&&he.current){const e=xe.getBoundingClientRect();const o=he.current.getBoundingClientRect();(o.top<e.top||o.bottom>e.bottom)&&setTimeout((()=>{xe&&he.current&&xe.scrollTo(0,he.current.offsetTop)}),0)}}),[w,b,ue,xe]),jsx(FormInputLabel,{...U,...G,ref:o,id:Q,labelId:V,labelPosition:n,active:be,onColored:v,primary:a,error:X==='error',success:X==='success',focus:ne,icon:[C,jsx(ChevronIcon,{up:ue},'chevron')],iconProps:{...G,...J,...c},palette:{color:U.disabled?B.labelColorDisabled:B.labelColor,backgroundColor:U.disabled?B.backgroundColorDisabled:B.backgroundColor,backgroundColorHover:U.disabled?B.backgroundColorDisabled:B.backgroundColorHover,borderColor:U.disabled?B.borderColorDisabled:B.borderColor},onClick:e=>{U.onClick&&U.onClick(e),U.disabled||(ve.current?.focus(),ue?xe&&e.target instanceof Node&&!xe.contains(e.target)&&ce(!1):(ce(!0),s&&!w&&pe&&(re(''),le(Y('')))))},onPointerDown:e=>{U.onPointerDown&&U.onPointerDown(e),e.target!==ve.current&&e.target instanceof Node&&(e.currentTarget.contains(e.target)||d.renderInPortal&&ue&&xe&&xe.contains(e.target))&&e.preventDefault()},onFocus:e=>{U.onFocus&&U.onFocus(e),se(!0),ve.current&&e.target===ve.current&&s&&!w&&pe&&!ue&&(re(''),le(Y('')))},onBlur:e=>{U.onBlur&&U.onBlur(e),e.currentTarget.contains(e.relatedTarget)||d.renderInPortal&&ue&&xe&&xe.contains(e.relatedTarget)||(se(!1),re(getDropdownInputText(ee,w)),ce(!1))},input:jsxs(Fragment,{children:[me&&!s&&!K&&jsx(InputMimic,{required:!0,type:"text",inputMode:"none",form:$,tabIndex:-1,onFocus:()=>{ve.current?.focus()}}),jsx(FormInput,{ref:ve,role:"combobox","aria-controls":W,"aria-expanded":ue,"aria-labelledby":U.label?V:void 0,type:"text",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",form:$,autoFocus:m,inputMode:s?h:'none',maxLength:S,placeholder:z,readOnly:K||!s,required:me,disabled:U.disabled,value:te,palette:{color:B.color,colorDisabled:B.colorDisabled,placeholderColor:B.placeholderColor,placeholderColorDisabled:B.placeholderColorDisabled},onClick:e=>{ue&&e.currentTarget.selectionStart!==e.currentTarget.selectionEnd&&e.stopPropagation()},onChange:e=>{re(e.currentTarget.value),ce(!0)},onKeyDown:e=>{if(keyboardKeys.Enter.validate(e.key)&&(re(getDropdownInputText(ee,w)),ce(!1)),!keyboardKeys.Space.validate(e.key)||ue&&e.currentTarget.selectionStart!==0||(e.preventDefault(),s&&!w&&pe&&!ue&&(re(''),le(Y(''))),ce((e=>!e))),keyboardKeys.Esc.validate(e.key)&&ce(!1),keyboardKeys.Tab.validate(e.key)&&ue&&(e.preventDefault(),ce(!1)),keyboardKeys.ArrowDown.validate(e.key)&&ue&&Ce.current)if(e.preventDefault(),!w&&he.current){const e=[...Ce.current.children];const o=e.findIndex((e=>e.contains(he.current)));const t=e[o+1]??e[0];t instanceof HTMLElement&&focusFirstFocusable(t)}else focusFirstFocusable(Ce.current);if(keyboardKeys.ArrowUp.validate(e.key)&&ue&&Ce.current)if(e.preventDefault(),!w&&he.current){const e=[...Ce.current.children];const o=e.findIndex((e=>e.contains(he.current)));const t=e[o-1]??e[e.length-1];t instanceof HTMLElement&&focusFirstFocusable(t)}else focusLastFocusable(Ce.current)}}),ee.map((e=>jsx("input",{type:"hidden",name:r,value:e.value,form:$,disabled:U.disabled},e.value)))]}),addon:jsxs(Fragment,{children:[w&&ee.length>0&&jsx(Chip,{size:"xs",active:!0,black:!0,marginLeft:12,disabled:U.disabled,cursor:U.disabled?'not-allowed':void 0,text:ee.length,textProps:{appearance:'caption',size:'xs'},palette:U.disabled?{color:'content-disabled',colorHover:'content-disabled',backgroundColor:'bg-disabled-small',backgroundColorHover:'bg-disabled-small'}:void 0,onPointerDown:e=>{e.preventDefault()},discardButtonProps:{square:!0,contrast:!U.disabled,onClick:e=>{e.stopPropagation(),K||(x===void 0&&oe([]),E&&E(w?[]:null),ve.current?.focus(),ce(!0))}}}),!w&&D&&ee.length>0&&jsx(IconButton,{icon:"close",size:"l",square:!0,marginLeft:12,disabled:U.disabled,onClick:e=>{e.stopPropagation(),K||(pe&&(re(''),le(Y(''))),x===void 0&&oe([]),E&&E(w?[]:null),ve.current?.focus(),ce(!0))}})]}),dropdown:jsx(DropdownMenu,{...d,setRef:ke,open:ue,popperReferenceId:Q,secondary:!v,elevated:v,disableAutoFocus:!0,palette:{backgroundColor:B.menuBackgroundColor,borderColor:B.menuBorderColor},empty:ae.length===0,loading:i,loadingMessage:I,loadingIcon:y,loadingIconProps:{...G,...J,...u},emptyMessage:L,emptyIcon:O,emptyIconProps:{...G,...J,...p},onKeyDown:e=>{keyboardKeys.Tab.validate(e.key)&&(e.preventDefault(),ve.current?.focus(),ce(!1)),keyboardKeys.Enter.validate(e.key)&&(ve.current?.focus(),re(getDropdownInputText(ee,w)),ce(!1)),keyboardKeys.Esc.validate(e.key)&&(ve.current?.focus(),ce(!1)),keyboardKeys.Backspace.validate(e.key)&&!K&&(w||!w&&D)&&(x===void 0&&oe([]),E&&E(w?[]:null))},children:jsx(MenuList,w?{ref:Ce,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,"aria-multiselectable":!0,children:te.length===0?jsxs(Fragment,{children:[l&&jsx(ListItem,{...G,text:T,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",name:r,checked:fe,indeterminate:ge,error:(fe||ge)&&X==='error',success:(fe||ge)&&X==='success',onChange:()=>{if(!K){const e=fe||ge?[]:[...P];x===void 0&&oe(e),E&&E(e)}}})}),l&&jsx(MenuDivider,{}),F&&de[0].map((e=>{const o=e.status??X;const t=o==='error';const n=o==='success';return createElement(ListItem,{...G,key:e.value,active:!0,text:e.text,danger:t,success:n,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ve.current?.focus()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!0,name:r,value:e.value,checked:!0,error:t,success:n,onChange:e=>{if(!K){const o=ee.filter((o=>o.value!==e.currentTarget.value));x===void 0&&oe(o),E&&E(o)}}})})})),F&&de[0].length>0&&de[1].length>0&&jsx(MenuDivider,{}),F&&de[1].map((e=>createElement(ListItem,{...G,key:e.value,text:e.text,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ve.current?.focus()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!1,name:r,value:e.value,checked:!1,onChange:()=>{if(!K){const o=[...ee,e];x===void 0&&oe(o),E&&E(o)}}})}))),!F&&P.map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;const t=e.status??X;const n=o&&t==='error';const s=o&&t==='success';return createElement(ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:o,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":o,name:r,value:e.value,checked:o,error:n,success:s,onChange:t=>{if(!K){const r=o?ee.filter((e=>e.value!==t.currentTarget.value)):[...ee,e];x===void 0&&oe(r),E&&E(r)}}})})}))]}):jsx(Fragment,{children:ae.map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;const t=e.status??X;const n=o&&t==='error';const s=o&&t==='success';return createElement(ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:o,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":o,name:r,value:e.value,checked:o,error:n,success:s,onChange:t=>{if(!K){const r=o?ee.filter((e=>e.value!==t.currentTarget.value)):[...ee,e];x===void 0&&oe(r),E&&E(r)}}})})}))})}:{ref:Ce,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,children:(s?ae:P).map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;return createElement(ListItem,{...G,role:"option","aria-selected":o,ref:o?he:void 0,key:e.value,text:e.text,active:o,danger:o&&X==='error',success:o&&X==='success',disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:o=>{if(o.stopPropagation(),!K){const o={...e};x===void 0&&(re(getDropdownInputText(o)),oe(getDropdownSelectedOption(o))),E&&E(o),ve.current?.focus(),ce(!1)}}})}))})})})})),{sizes:SIZES,displayName:"Dropdown"});export{COMPONENT_NAME,Dropdown};
|
|
2
2
|
//# sourceMappingURL=Dropdown.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var React=require('react');var styled=require('styled-components');var index_browser=require('../../external/.pnpm/nanoid@5.0.
|
|
1
|
+
'use strict';var React=require('react');var styled=require('styled-components');var index_browser=require('../../external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.js');var withMergedProps=require('../../hocs/withMergedProps.js');var constants$1=require('./constants.js');var style=require('./style.js');var require$$0=require('react/jsx-runtime');var Input_Phone=require('../Input.Phone/Input.Phone.js');var constants=require('../FormInputLabel/constants.js');var FormInputLabel=require('../FormInputLabel/FormInputLabel.js');var FormInput=require('../FormInput/FormInput.js');var IconButton=require('../IconButton/IconButton.js');const Input=Object.assign(withMergedProps.withMergedProps(React.forwardRef(((e,r)=>{const t=styled.useTheme();const{size:o="m",rounded:n=!0,primary:a=!0,color:i="mineShaft",placeholderColor:s="silver",width:l=t.defaultInputControlsWidth,type:c="text",labelPosition:u="dynamic",iconProps:m={},controls:d={},addonButtonProps:g={},preset:p,className:b,style:f,sizeXXS:h,sizeXS:S,sizeS:X,sizeM:v,sizeL:L,sizeXL:C,sizeUnits:y,sizes:I,margin:R,marginXXS:B,marginXS:w,marginS:k,marginM:T,marginL:z,marginXL:M,marginTop:x,marginTopXXS:P,marginTopXS:$,marginTopS:F,marginTopM:q,marginTopL:j,marginTopXL:D,marginRight:E,marginRightXXS:O,marginRightXS:N,marginRightS:_,marginRightM:A,marginRightL:H,marginRightXL:Z,marginBottom:U,marginBottomXXS:V,marginBottomXS:W,marginBottomS:G,marginBottomM:J,marginBottomL:K,marginBottomXL:Q,marginLeft:Y,marginLeftXXS:ee,marginLeftXS:re,marginLeftS:te,marginLeftM:oe,marginLeftL:ne,marginLeftXL:ae,palette:ie,widthXXS:se,widthXS:le,widthS:ce,widthM:ue,widthL:me,widthXL:de,error:ge,success:pe,label:be,icon:fe,text:he,secondary:Se,contrast:Xe,onColored:ve,fluid:Le,disabled:Ce,inline:ye,inputRef:Ie,...Re}=e;const Be={size:o,sizeXXS:h,sizeXS:S,sizeS:X,sizeM:v,sizeL:L,sizeXL:C};const{icon:we,buttonProps:ke={}}=d.additional??{};const[Te,ze=(ke.onClick?void 0:we)]=Array.isArray(fe)?fe:[fe];const Me=g.icon??we;const xe=Boolean(Re.mask&&Re.alwaysShowMask);const Pe={color:ie.controlsColor,colorHover:ie.controlsColorHover,colorActive:ie.controlsColorActive,colorDisabled:ie.controlsColorDisabled,backgroundColor:ie.controlsBackgroundColor,backgroundColorHover:ie.controlsBackgroundColorHover,backgroundColorActive:ie.controlsBackgroundColorActive,backgroundColorDisabled:ie.controlsBackgroundColorDisabled};const $e=React.useRef(null);React.useImperativeHandle(r,(()=>$e.current),[]);const Fe=React.useRef(null);const qe=React.useRef(null);const je=React.useRef(null);const De=React.useMemo((()=>index_browser.nanoid()),[]);const[Ee,Oe]=React.useState((()=>{if(xe)return!0;const e=Re.value??Re.defaultValue;return typeof e=='string'&&e.length>0||typeof e=='number'}));const[Ne,_e]=React.useState((()=>{if(c!=='number'||Re.min===void 0)return!1;const{value:e=1/0,defaultValue:r=1/0}=Re;const t=typeof e=='number'?e:parseFloat(e);const o=typeof r=='number'?r:parseFloat(r);const n=typeof Re.min=='number'?Re.min:parseFloat(Re.min);return Math.min(t,o)<=n}));const[Ae,He]=React.useState((()=>{if(c!=='number'||Re.max===void 0)return!1;const{value:e=-1/0,defaultValue:r=-1/0}=Re;const t=typeof e=='number'?e:parseFloat(e);const o=typeof r=='number'?r:parseFloat(r);const n=typeof Re.max=='number'?Re.max:parseFloat(Re.max);return Math.max(t,o)>=n}));return React.useLayoutEffect((()=>{xe?Oe(!0):Re.value!==void 0&&Re.value!==null&&$e.current&&$e.current!==document.activeElement&&Oe(typeof Re.value=='string'&&Re.value.length>0||typeof Re.value=='number')}),[xe,Re.value]),p!=='brand'?require$$0.jsx(style.Root,{...Re,inputRef:Ie??(e=>{$e.current=e}),className:b,style:f,size:typeof o=='number'?o:void 0,rounded:n,color:i,placeholderColor:s,width:l,widthXXS:se,widthXS:le,widthS:ce,widthM:ue,widthL:me,widthXL:de,error:ge,type:c,fluid:Le,disabled:Ce}):require$$0.jsx(FormInputLabel.FormInputLabel,{...Be,className:b,style:f,sizeUnits:y,sizes:I,margin:R,marginXXS:B,marginXS:w,marginS:k,marginM:T,marginL:z,marginXL:M,marginTop:x,marginTopXXS:P,marginTopXS:$,marginTopS:F,marginTopM:q,marginTopL:j,marginTopXL:D,marginRight:E,marginRightXXS:O,marginRightXS:N,marginRightS:_,marginRightM:A,marginRightL:H,marginRightXL:Z,marginBottom:U,marginBottomXXS:V,marginBottomXS:W,marginBottomS:G,marginBottomM:J,marginBottomL:K,marginBottomXL:Q,marginLeft:Y,marginLeftXXS:ee,marginLeftXS:re,marginLeftS:te,marginLeftM:oe,marginLeftL:ne,marginLeftXL:ae,error:ge,success:pe,label:be,labelId:De,labelPosition:u,icon:[Te,ze],text:he,primary:a,secondary:Se,contrast:Xe,onColored:ve,disabled:Ce,inline:ye,active:Ee,palette:{color:Ce?ie.colorDisabled:ie.color,backgroundColor:Ce?ie.backgroundColorDisabled:ie.backgroundColor,backgroundColorHover:Ce?ie.backgroundColorDisabled:ie.backgroundColorHover,borderColor:Ce?ie.borderColorDisabled:ie.borderColor},iconProps:{color:Ce?'content-disabled':'content-onmain-tertiary',sizes:constants$1.SIZES_ICON,...Be,...m},onClick:()=>{$e.current&&$e.current.focus()},onFocus:e=>{e.target!==e.currentTarget&&Oe(!0)},onPointerDown:e=>{e.target!==$e.current&&e.target instanceof Node&&!Fe.current?.contains(e.target)&&!qe.current?.contains(e.target)&&!je.current?.contains(e.target)&&e.preventDefault()},onBlur:e=>{xe||!$e.current||e.currentTarget.contains(e.relatedTarget)||Oe(Boolean($e.current.value))},input:require$$0.jsx(FormInput.FormInput,{...Re,"aria-labelledby":be?De:void 0,ref:$e,type:c,disabled:Ce,palette:{color:ie.inputColor,placeholderColor:ie.inputPlaceholderColor,colorDisabled:ie.inputColorDisabled,placeholderColorDisabled:ie.inputPlaceholderColorDisabled},onChange:e=>{if(Re.onChange&&Re.onChange(e),c==='number'){const r=parseFloat(e.currentTarget.value);const t=r<=parseFloat(e.currentTarget.min);const o=r>=parseFloat(e.currentTarget.max);_e(t),He(o),(t||o)&&e.currentTarget.focus()}}}),addon:(g.onClick||ke.onClick)&&Me?require$$0.jsx(IconButton.IconButton,{ref:Fe,sizes:constants$1.SIZES_CONTROL,palette:Pe,...Be,...ke,...g,icon:Me,disabled:Ce||g.disabled||ke.disabled,marginLeft:12,onClick:e=>{e.stopPropagation(),Re.readOnly||(g.onClick&&g.onClick(e),ke.onClick&&ke.onClick(e))}}):void 0,controls:c==='number'?require$$0.jsxs(require$$0.Fragment,{children:[require$$0.jsx(IconButton.IconButton,{...Be,ref:qe,icon:"minus",sizes:constants$1.SIZES_CONTROL,palette:Pe,disabled:Ce||Ne,marginLeft:12,onClick:e=>{if(e.stopPropagation(),!Re.readOnly)try{if($e.current){Oe(!0);const e=$e.current.value;if($e.current.stepDown(),e!==$e.current.value){const e=new Event('input',{bubbles:!0});$e.current.dispatchEvent(e)}}}catch(e){console.error(e)}}}),require$$0.jsx(style.IconButtonSeparated,{...Be,ref:je,icon:"plus",sizes:constants$1.SIZES_CONTROL,palette:Pe,disabled:Ce||Ae,onClick:e=>{if(e.stopPropagation(),!Re.readOnly)try{if($e.current){Oe(!0);const e=$e.current.value;if($e.current.stepUp(),e!==$e.current.value){const e=new Event('input',{bubbles:!0});$e.current.dispatchEvent(e)}}}catch(e){console.error(e)}}})]}):void 0})})),{sizes:constants.SIZES,displayName:"Input"}),{Phone:Input_Phone.InputPhone});exports.COMPONENT_NAME="Input",exports.Input=Input;
|
|
2
2
|
//# sourceMappingURL=Input.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{forwardRef,useRef,useImperativeHandle,useMemo,useState,useLayoutEffect}from'react';import{useTheme}from'styled-components';import{nanoid}from'../../external/.pnpm/nanoid@5.0.
|
|
1
|
+
import{forwardRef,useRef,useImperativeHandle,useMemo,useState,useLayoutEffect}from'react';import{useTheme}from'styled-components';import{nanoid}from'../../external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.mjs';import{withMergedProps}from'../../hocs/withMergedProps.mjs';import{SIZES_ICON,SIZES_CONTROL}from'./constants.mjs';import{Root,IconButtonSeparated}from'./style.mjs';import{jsx,jsxs,Fragment}from'react/jsx-runtime';import{InputPhone}from'../Input.Phone/Input.Phone.mjs';import{SIZES}from'../FormInputLabel/constants.mjs';import{FormInputLabel}from'../FormInputLabel/FormInputLabel.mjs';import{FormInput}from'../FormInput/FormInput.mjs';import{IconButton}from'../IconButton/IconButton.mjs';const COMPONENT_NAME='Input';const Input=Object.assign(withMergedProps(forwardRef(((o,r)=>{const t=useTheme();const{size:e="m",rounded:n=!0,primary:a=!0,color:i="mineShaft",placeholderColor:s="silver",width:l=t.defaultInputControlsWidth,type:m="text",labelPosition:c="dynamic",iconProps:u={},controls:d={},addonButtonProps:g={},preset:p,className:f,style:b,sizeXXS:S,sizeXS:h,sizeS:X,sizeM:L,sizeL:C,sizeXL:v,sizeUnits:I,sizes:y,margin:B,marginXXS:R,marginXS:T,marginS:k,marginM:w,marginL:M,marginXL:z,marginTop:x,marginTopXXS:P,marginTopXS:F,marginTopS:j,marginTopM:E,marginTopL:O,marginTopXL:N,marginRight:D,marginRightXXS:_,marginRightXS:A,marginRightS:H,marginRightM:Z,marginRightL:U,marginRightXL:V,marginBottom:W,marginBottomXXS:q,marginBottomXS:G,marginBottomS:J,marginBottomM:K,marginBottomL:Q,marginBottomXL:Y,marginLeft:$,marginLeftXXS:oo,marginLeftXS:ro,marginLeftS:to,marginLeftM:eo,marginLeftL:no,marginLeftXL:ao,palette:io,widthXXS:so,widthXS:lo,widthS:mo,widthM:co,widthL:uo,widthXL:go,error:po,success:fo,label:bo,icon:So,text:ho,secondary:Xo,contrast:Lo,onColored:Co,fluid:vo,disabled:Io,inline:yo,inputRef:Bo,...Ro}=o;const To={size:e,sizeXXS:S,sizeXS:h,sizeS:X,sizeM:L,sizeL:C,sizeXL:v};const{icon:ko,buttonProps:wo={}}=d.additional??{};const[Mo,zo=(wo.onClick?void 0:ko)]=Array.isArray(So)?So:[So];const xo=g.icon??ko;const Po=Boolean(Ro.mask&&Ro.alwaysShowMask);const Fo={color:io.controlsColor,colorHover:io.controlsColorHover,colorActive:io.controlsColorActive,colorDisabled:io.controlsColorDisabled,backgroundColor:io.controlsBackgroundColor,backgroundColorHover:io.controlsBackgroundColorHover,backgroundColorActive:io.controlsBackgroundColorActive,backgroundColorDisabled:io.controlsBackgroundColorDisabled};const jo=useRef(null);useImperativeHandle(r,(()=>jo.current),[]);const Eo=useRef(null);const Oo=useRef(null);const No=useRef(null);const Do=useMemo((()=>nanoid()),[]);const[_o,Ao]=useState((()=>{if(Po)return!0;const o=Ro.value??Ro.defaultValue;return typeof o=='string'&&o.length>0||typeof o=='number'}));const[Ho,Zo]=useState((()=>{if(m!=='number'||Ro.min===void 0)return!1;const{value:o=1/0,defaultValue:r=1/0}=Ro;const t=typeof o=='number'?o:parseFloat(o);const e=typeof r=='number'?r:parseFloat(r);const n=typeof Ro.min=='number'?Ro.min:parseFloat(Ro.min);return Math.min(t,e)<=n}));const[Uo,Vo]=useState((()=>{if(m!=='number'||Ro.max===void 0)return!1;const{value:o=-1/0,defaultValue:r=-1/0}=Ro;const t=typeof o=='number'?o:parseFloat(o);const e=typeof r=='number'?r:parseFloat(r);const n=typeof Ro.max=='number'?Ro.max:parseFloat(Ro.max);return Math.max(t,e)>=n}));return useLayoutEffect((()=>{Po?Ao(!0):Ro.value!==void 0&&Ro.value!==null&&jo.current&&jo.current!==document.activeElement&&Ao(typeof Ro.value=='string'&&Ro.value.length>0||typeof Ro.value=='number')}),[Po,Ro.value]),p!=='brand'?jsx(Root,{...Ro,inputRef:Bo??(o=>{jo.current=o}),className:f,style:b,size:typeof e=='number'?e:void 0,rounded:n,color:i,placeholderColor:s,width:l,widthXXS:so,widthXS:lo,widthS:mo,widthM:co,widthL:uo,widthXL:go,error:po,type:m,fluid:vo,disabled:Io}):jsx(FormInputLabel,{...To,className:f,style:b,sizeUnits:I,sizes:y,margin:B,marginXXS:R,marginXS:T,marginS:k,marginM:w,marginL:M,marginXL:z,marginTop:x,marginTopXXS:P,marginTopXS:F,marginTopS:j,marginTopM:E,marginTopL:O,marginTopXL:N,marginRight:D,marginRightXXS:_,marginRightXS:A,marginRightS:H,marginRightM:Z,marginRightL:U,marginRightXL:V,marginBottom:W,marginBottomXXS:q,marginBottomXS:G,marginBottomS:J,marginBottomM:K,marginBottomL:Q,marginBottomXL:Y,marginLeft:$,marginLeftXXS:oo,marginLeftXS:ro,marginLeftS:to,marginLeftM:eo,marginLeftL:no,marginLeftXL:ao,error:po,success:fo,label:bo,labelId:Do,labelPosition:c,icon:[Mo,zo],text:ho,primary:a,secondary:Xo,contrast:Lo,onColored:Co,disabled:Io,inline:yo,active:_o,palette:{color:Io?io.colorDisabled:io.color,backgroundColor:Io?io.backgroundColorDisabled:io.backgroundColor,backgroundColorHover:Io?io.backgroundColorDisabled:io.backgroundColorHover,borderColor:Io?io.borderColorDisabled:io.borderColor},iconProps:{color:Io?'content-disabled':'content-onmain-tertiary',sizes:SIZES_ICON,...To,...u},onClick:()=>{jo.current&&jo.current.focus()},onFocus:o=>{o.target!==o.currentTarget&&Ao(!0)},onPointerDown:o=>{o.target!==jo.current&&o.target instanceof Node&&!Eo.current?.contains(o.target)&&!Oo.current?.contains(o.target)&&!No.current?.contains(o.target)&&o.preventDefault()},onBlur:o=>{Po||!jo.current||o.currentTarget.contains(o.relatedTarget)||Ao(Boolean(jo.current.value))},input:jsx(FormInput,{...Ro,"aria-labelledby":bo?Do:void 0,ref:jo,type:m,disabled:Io,palette:{color:io.inputColor,placeholderColor:io.inputPlaceholderColor,colorDisabled:io.inputColorDisabled,placeholderColorDisabled:io.inputPlaceholderColorDisabled},onChange:o=>{if(Ro.onChange&&Ro.onChange(o),m==='number'){const r=parseFloat(o.currentTarget.value);const t=r<=parseFloat(o.currentTarget.min);const e=r>=parseFloat(o.currentTarget.max);Zo(t),Vo(e),(t||e)&&o.currentTarget.focus()}}}),addon:(g.onClick||wo.onClick)&&xo?jsx(IconButton,{ref:Eo,sizes:SIZES_CONTROL,palette:Fo,...To,...wo,...g,icon:xo,disabled:Io||g.disabled||wo.disabled,marginLeft:12,onClick:o=>{o.stopPropagation(),Ro.readOnly||(g.onClick&&g.onClick(o),wo.onClick&&wo.onClick(o))}}):void 0,controls:m==='number'?jsxs(Fragment,{children:[jsx(IconButton,{...To,ref:Oo,icon:"minus",sizes:SIZES_CONTROL,palette:Fo,disabled:Io||Ho,marginLeft:12,onClick:o=>{if(o.stopPropagation(),!Ro.readOnly)try{if(jo.current){Ao(!0);const o=jo.current.value;if(jo.current.stepDown(),o!==jo.current.value){const o=new Event('input',{bubbles:!0});jo.current.dispatchEvent(o)}}}catch(o){console.error(o)}}}),jsx(IconButtonSeparated,{...To,ref:No,icon:"plus",sizes:SIZES_CONTROL,palette:Fo,disabled:Io||Uo,onClick:o=>{if(o.stopPropagation(),!Ro.readOnly)try{if(jo.current){Ao(!0);const o=jo.current.value;if(jo.current.stepUp(),o!==jo.current.value){const o=new Event('input',{bubbles:!0});jo.current.dispatchEvent(o)}}}catch(o){console.error(o)}}})]}):void 0})})),{sizes:SIZES,displayName:"Input"}),{Phone:InputPhone});export{COMPONENT_NAME,Input};
|
|
2
2
|
//# sourceMappingURL=Input.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var React=require('react');var styled=require('styled-components');var index_browser=require('../../external/.pnpm/nanoid@5.0.
|
|
1
|
+
'use strict';var React=require('react');var styled=require('styled-components');var index_browser=require('../../external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.js');var withMergedProps=require('../../hocs/withMergedProps.js');var useResizable=require('../../hooks/useResizable.js');var misc=require('../../shared/utils/misc.js');var constants=require('./constants.js');var style=require('./style.js');var require$$0=require('react/jsx-runtime');var FormInputLabel=require('../FormInputLabel/FormInputLabel.js');var index=require('../../external/.pnpm/@foxford_icon-pack@0.11.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@foxford/icon-pack/icons/ResizeHandle/index.js');const Textarea=withMergedProps.withMergedProps(React.forwardRef(((e,r)=>{const t=styled.useTheme();const{size:a="m",rows:i=2,maxRows:n=30,labelPosition:o="dynamic",primary:s=!0,width:l=t.defaultInputControlsWidth,autosize:c=!0,rounded:m=!0,color:d="mineShaft",placeholderColor:g="silver",autoRows:u,resize:h,contrast:p,inline:X,secondary:b,success:L,error:S,sizeXXS:f,sizeXS:R,sizeS:w,sizeM:z,sizeL:v,sizeXL:x,sizes:M,sizeUnits:T,margin:C,marginXXS:y,marginXS:$,marginS:q,marginM:j,marginL:B,marginXL:I,marginTop:k,marginTopXXS:D,marginTopXS:F,marginTopS:_,marginTopM:N,marginTopL:E,marginTopXL:H,marginRight:P,marginRightXXS:A,marginRightXS:O,marginRightS:U,marginRightM:W,marginRightL:Z,marginRightXL:G,marginBottom:K,marginBottomXXS:V,marginBottomXS:J,marginBottomS:Q,marginBottomM:Y,marginBottomL:ee,marginBottomXL:re,marginLeft:te,marginLeftXXS:ae,marginLeftXS:ie,marginLeftS:ne,marginLeftM:oe,marginLeftL:se,marginLeftXL:le,widthXXS:ce,widthXS:me,widthS:de,widthM:ge,widthL:ue,widthXL:he,preset:pe,palette:Xe,label:be,fluid:Le,className:Se,style:fe,disabled:Re,...we}=e;const ze=React.useRef(null);const ve=React.useRef(null);const xe=React.useRef(null);React.useImperativeHandle(r,(()=>ze.current),[]);const[Me,Te,Ce]=useResizable.useResizable({target:xe,direction:h});const ye=React.useMemo((()=>index_browser.nanoid()),[]);const[$e,qe]=React.useState((()=>{const e=we.value??we.defaultValue;return typeof e=='string'&&e.length>0}));const[je,Be]=React.useState((()=>Math.min(i,n)));const Ie=pe==='brand'&&u||pe!=='brand'&&c?je:Math.min(i,n);const ke=h==='horizontal'?'ew-resize':h==='vertical'?'ns-resize':'nwse-resize';const De=React.useCallback((()=>{if(!ze.current)return;if(pe==='brand'){if(!ve.current)return;ve.current.value=ze.current.value;const e=Math.max(Math.round(ve.current.scrollHeight/ve.current.clientHeight),i);return void Be(Math.min(e,n))}const e=getComputedStyle(ze.current);const r=parseFloat(e.lineHeight);const t=Math.max(Math.round((ze.current.scrollHeight-parseFloat(e.paddingTop)-parseFloat(e.paddingBottom))/(Number.isNaN(r)?parseFloat(e.fontSize)*1.2:r)),i);Be((e=>t>e?Math.min(t,n):ze.current&&!ze.current.value?i:e))}),[pe,i,n]);return React.useLayoutEffect((()=>{pe==='brand'&&typeof we.value=='string'&&ze.current&&ze.current!==document.activeElement&&qe(we.value.length>0)}),[pe,we.value]),React.useEffect((()=>{const e=misc.createThrottledCallback(De,200);return(pe==='brand'&&u||pe!=='brand'&&c)&&(De(),window.addEventListener('resize',e)),()=>{window.removeEventListener('resize',e)}}),[pe,u,c,De]),pe!=='brand'?require$$0.jsx(style.Root,{...we,ref:ze,className:Se,style:fe,onChange:e=>{c&&De(),we.onChange&&we.onChange(e)},rows:Ie,color:d,rounded:m,placeholderColor:g,disabled:Re,error:S,fluid:Le,width:l,widthXXS:ce,widthXS:me,widthS:de,widthM:ge,widthL:ue,widthXL:he}):require$$0.jsx(FormInputLabel.FormInputLabel,{ref:xe,size:a,sizeXXS:f,sizeXS:R,sizeS:w,sizeM:z,sizeL:v,sizeXL:x,sizes:M,sizeUnits:T,margin:C,marginXXS:y,marginXS:$,marginS:q,marginM:j,marginL:B,marginXL:I,marginTop:k,marginTopXXS:D,marginTopXS:F,marginTopS:_,marginTopM:N,marginTopL:E,marginTopXL:H,marginRight:P,marginRightXXS:A,marginRightXS:O,marginRightS:U,marginRightM:W,marginRightL:Z,marginRightXL:G,marginBottom:K,marginBottomXXS:V,marginBottomXS:J,marginBottomS:Q,marginBottomM:Y,marginBottomL:ee,marginBottomXL:re,marginLeft:te,marginLeftXXS:ae,marginLeftXS:ie,marginLeftS:ne,marginLeftM:oe,marginLeftL:se,marginLeftXL:le,className:Se,style:fe,contrast:p,error:S,inline:X,label:be,labelId:ye,labelPosition:o,disabled:Re,active:$e,primary:s,secondary:b,success:L,palette:{color:Re?Xe.colorDisabled:Xe.color,backgroundColor:Re?Xe.backgroundColorDisabled:Xe.backgroundColor,backgroundColorHover:Re?Xe.backgroundColorDisabled:Xe.backgroundColorHover,borderColor:Re?Xe.borderColorDisabled:Xe.borderColor},onClick:()=>{ze.current&&ze.current.focus()},onFocus:()=>{qe(!0)},onPointerDown:e=>{e.target!==ze.current&&e.target instanceof Node&&e.preventDefault()},onBlur:e=>{ze.current&&!e.currentTarget.contains(e.relatedTarget)&&qe(Boolean(ze.current.value))},overflow:"hidden",inputPosition:"stretch",input:require$$0.jsxs(require$$0.Fragment,{children:[u&&require$$0.jsx(style.TextareaMimic,{ref:ve,rows:1}),require$$0.jsx(style.Textarea,{...we,ref:ze,"aria-labelledby":be?ye:void 0,disabled:Re,onChange:e=>{u&&De(),we.onChange&&we.onChange(e)},rows:Ie,palette:{color:Xe.color,colorDisabled:Xe.colorDisabled,placeholderColor:Xe.placeholderColor,placeholderColorDisabled:Xe.placeholderColorDisabled}})]}),addon:h?require$$0.jsxs(require$$0.Fragment,{children:[Me&&require$$0.jsx(style.ResizeGlobals,{cursor:ke}),require$$0.jsx(style.ResizeIcon,{size:"l",icon:require$$0.jsx(index.ResizeHandle,{}),color:"border-onmain-default-small",tabIndex:0,onPointerDown:Te,onKeyDown:Ce,cursor:ke})]}):void 0})})),{displayName:"Textarea",sizes:e=>e.label?constants.SIZES_WITH_LABEL:constants.SIZES});exports.COMPONENT_NAME="Textarea",exports.Textarea=Textarea;
|
|
2
2
|
//# sourceMappingURL=Textarea.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{forwardRef,useRef,useImperativeHandle,useMemo,useState,useCallback,useLayoutEffect,useEffect}from'react';import{useTheme}from'styled-components';import{nanoid}from'../../external/.pnpm/nanoid@5.0.
|
|
1
|
+
import{forwardRef,useRef,useImperativeHandle,useMemo,useState,useCallback,useLayoutEffect,useEffect}from'react';import{useTheme}from'styled-components';import{nanoid}from'../../external/.pnpm/nanoid@5.0.9/node_modules/nanoid/index.browser.mjs';import{withMergedProps}from'../../hocs/withMergedProps.mjs';import{useResizable}from'../../hooks/useResizable.mjs';import{createThrottledCallback}from'../../shared/utils/misc.mjs';import{SIZES_WITH_LABEL,SIZES}from'./constants.mjs';import{Root,TextareaMimic,Textarea as Textarea$1,ResizeGlobals,ResizeIcon}from'./style.mjs';import{jsx,jsxs,Fragment}from'react/jsx-runtime';import{FormInputLabel}from'../FormInputLabel/FormInputLabel.mjs';import{ResizeHandle as ResizeHandle_2}from'../../external/.pnpm/@foxford_icon-pack@0.11.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@foxford/icon-pack/icons/ResizeHandle/index.mjs';const COMPONENT_NAME='Textarea';const Textarea=withMergedProps(forwardRef(((e,r)=>{const o=useTheme();const{size:t="m",rows:a=2,maxRows:n=30,labelPosition:i="dynamic",primary:s=!0,width:m=o.defaultInputControlsWidth,autosize:l=!0,rounded:d=!0,color:c="mineShaft",placeholderColor:g="silver",autoRows:u,resize:h,contrast:p,inline:f,secondary:S,success:X,error:L,sizeXXS:b,sizeXS:z,sizeS:w,sizeM:R,sizeL:T,sizeXL:M,sizes:x,sizeUnits:C,margin:v,marginXXS:j,marginXS:B,marginS:y,marginM:E,marginL:I,marginXL:_,marginTop:k,marginTopXXS:H,marginTopXS:N,marginTopS:D,marginTopM:F,marginTopL:P,marginTopXL:A,marginRight:O,marginRightXXS:Z,marginRightXS:W,marginRightS:G,marginRightM:U,marginRightL:$,marginRightXL:K,marginBottom:V,marginBottomXXS:q,marginBottomXS:J,marginBottomS:Q,marginBottomM:Y,marginBottomL:ee,marginBottomXL:re,marginLeft:oe,marginLeftXXS:te,marginLeftXS:ae,marginLeftS:ne,marginLeftM:ie,marginLeftL:se,marginLeftXL:me,widthXXS:le,widthXS:de,widthS:ce,widthM:ge,widthL:ue,widthXL:he,preset:pe,palette:fe,label:Se,fluid:Xe,className:Le,style:be,disabled:ze,...we}=e;const Re=useRef(null);const Te=useRef(null);const Me=useRef(null);useImperativeHandle(r,(()=>Re.current),[]);const[xe,Ce,ve]=useResizable({target:Me,direction:h});const je=useMemo((()=>nanoid()),[]);const[Be,ye]=useState((()=>{const e=we.value??we.defaultValue;return typeof e=='string'&&e.length>0}));const[Ee,Ie]=useState((()=>Math.min(a,n)));const _e=pe==='brand'&&u||pe!=='brand'&&l?Ee:Math.min(a,n);const ke=h==='horizontal'?'ew-resize':h==='vertical'?'ns-resize':'nwse-resize';const He=useCallback((()=>{if(!Re.current)return;if(pe==='brand'){if(!Te.current)return;Te.current.value=Re.current.value;const e=Math.max(Math.round(Te.current.scrollHeight/Te.current.clientHeight),a);return void Ie(Math.min(e,n))}const e=getComputedStyle(Re.current);const r=parseFloat(e.lineHeight);const o=Math.max(Math.round((Re.current.scrollHeight-parseFloat(e.paddingTop)-parseFloat(e.paddingBottom))/(Number.isNaN(r)?parseFloat(e.fontSize)*1.2:r)),a);Ie((e=>o>e?Math.min(o,n):Re.current&&!Re.current.value?a:e))}),[pe,a,n]);return useLayoutEffect((()=>{pe==='brand'&&typeof we.value=='string'&&Re.current&&Re.current!==document.activeElement&&ye(we.value.length>0)}),[pe,we.value]),useEffect((()=>{const e=createThrottledCallback(He,200);return(pe==='brand'&&u||pe!=='brand'&&l)&&(He(),window.addEventListener('resize',e)),()=>{window.removeEventListener('resize',e)}}),[pe,u,l,He]),pe!=='brand'?jsx(Root,{...we,ref:Re,className:Le,style:be,onChange:e=>{l&&He(),we.onChange&&we.onChange(e)},rows:_e,color:c,rounded:d,placeholderColor:g,disabled:ze,error:L,fluid:Xe,width:m,widthXXS:le,widthXS:de,widthS:ce,widthM:ge,widthL:ue,widthXL:he}):jsx(FormInputLabel,{ref:Me,size:t,sizeXXS:b,sizeXS:z,sizeS:w,sizeM:R,sizeL:T,sizeXL:M,sizes:x,sizeUnits:C,margin:v,marginXXS:j,marginXS:B,marginS:y,marginM:E,marginL:I,marginXL:_,marginTop:k,marginTopXXS:H,marginTopXS:N,marginTopS:D,marginTopM:F,marginTopL:P,marginTopXL:A,marginRight:O,marginRightXXS:Z,marginRightXS:W,marginRightS:G,marginRightM:U,marginRightL:$,marginRightXL:K,marginBottom:V,marginBottomXXS:q,marginBottomXS:J,marginBottomS:Q,marginBottomM:Y,marginBottomL:ee,marginBottomXL:re,marginLeft:oe,marginLeftXXS:te,marginLeftXS:ae,marginLeftS:ne,marginLeftM:ie,marginLeftL:se,marginLeftXL:me,className:Le,style:be,contrast:p,error:L,inline:f,label:Se,labelId:je,labelPosition:i,disabled:ze,active:Be,primary:s,secondary:S,success:X,palette:{color:ze?fe.colorDisabled:fe.color,backgroundColor:ze?fe.backgroundColorDisabled:fe.backgroundColor,backgroundColorHover:ze?fe.backgroundColorDisabled:fe.backgroundColorHover,borderColor:ze?fe.borderColorDisabled:fe.borderColor},onClick:()=>{Re.current&&Re.current.focus()},onFocus:()=>{ye(!0)},onPointerDown:e=>{e.target!==Re.current&&e.target instanceof Node&&e.preventDefault()},onBlur:e=>{Re.current&&!e.currentTarget.contains(e.relatedTarget)&&ye(Boolean(Re.current.value))},overflow:"hidden",inputPosition:"stretch",input:jsxs(Fragment,{children:[u&&jsx(TextareaMimic,{ref:Te,rows:1}),jsx(Textarea$1,{...we,ref:Re,"aria-labelledby":Se?je:void 0,disabled:ze,onChange:e=>{u&&He(),we.onChange&&we.onChange(e)},rows:_e,palette:{color:fe.color,colorDisabled:fe.colorDisabled,placeholderColor:fe.placeholderColor,placeholderColorDisabled:fe.placeholderColorDisabled}})]}),addon:h?jsxs(Fragment,{children:[xe&&jsx(ResizeGlobals,{cursor:ke}),jsx(ResizeIcon,{size:"l",icon:jsx(ResizeHandle_2,{}),color:"border-onmain-default-small",tabIndex:0,onPointerDown:Ce,onKeyDown:ve,cursor:ke})]}):void 0})})),{displayName:"Textarea",sizes:e=>e.label?SIZES_WITH_LABEL:SIZES});export{COMPONENT_NAME,Textarea};
|
|
2
2
|
//# sourceMappingURL=Textarea.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';function isArray(e){return Array.isArray?Array.isArray(e):getTag(e)==='[object Array]'}function isString(e){return typeof e=='string'}function isNumber(e){return typeof e=='number'}function isObject(e){return typeof e=='object'}function isDefined(e){return e!==void 0&&e!==null}function isBlank(e){return!e.trim().length}function getTag(e){return e==null?e===void 0?'[object Undefined]':'[object Null]':{}.toString.call(e)}Object.defineProperty(exports,'__esModule',{value:!0});const MISSING_KEY_PROPERTY=e=>`Missing ${e} property in key`;const INVALID_KEY_WEIGHT_VALUE=e=>`Property 'weight' in key '${e}' must be a positive integer`;const hasOwn={}.hasOwnProperty;class KeyStore{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let s=createKey(e);this._keys.push(s),this._keyMap[s.id]=s,t+=s.weight})),this._keys.forEach((e=>{e.weight/=t}))}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function createKey(e){let t=null;let s=null;let n=null;let i=1;let r=null;if(isString(e)||isArray(e))n=e,t=createKeyPath(e),s=createKeyId(e);else{if(!hasOwn.call(e,'name'))throw new Error(MISSING_KEY_PROPERTY('name'));const c=e.name;if(n=c,hasOwn.call(e,'weight')&&(i=e.weight,i<=0))throw new Error(INVALID_KEY_WEIGHT_VALUE(c));t=createKeyPath(c),s=createKeyId(c),r=e.getFn}return{path:t,id:s,weight:i,src:n,getFn:r}}function createKeyPath(e){return isArray(e)?e:e.split('.')}function createKeyId(e){return isArray(e)?e.join('.'):e}var Config={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,useExtendedSearch:!1,getFn:(e,t)=>{let s=[];let n=!1;const deepGet=(e,t,i)=>{if(isDefined(e))if(t[i]){const r=e[t[i]];if(!isDefined(r))return;if(i===t.length-1&&(isString(r)||isNumber(r)||(e=>e===!0||e===!1||(e=>isObject(e)&&e!==null)(e)&&getTag(e)=='[object Boolean]')(r)))s.push((e=>e==null?'':(e=>{if(typeof e=='string')return e;let t=e+'';return t=='0'&&1/e==-1/0?'-0':t})(e))(r));else if(isArray(r)){n=!0;for(let e=0,s=r.length;e<s;e+=1)deepGet(r[e],t,i+1)}else t.length&&deepGet(r,t,i+1)}else s.push(e)};return deepGet(e,isString(t)?t.split('.'):t,0),n?s:s[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};const SPACE=/[^ ]+/g;class FuseIndex{constructor({getFn:e=Config.getFn,fieldNormWeight:t=Config.fieldNormWeight}={}){this.norm=((e=1,t=3)=>{const s=new Map;const n=Math.pow(10,t);return{get(t){const i=t.match(SPACE).length;if(s.has(i))return s.get(i);const r=1/Math.pow(i,.5*e);const c=parseFloat(Math.round(r*n)/n);return s.set(i,c),c},clear(){s.clear()}}})(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach(((e,t)=>{this._keysMap[e.id]=t}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,isString(this.docs[0])?this.docs.forEach(((e,t)=>{this._addString(e,t)})):this.docs.forEach(((e,t)=>{this._addObject(e,t)})),this.norm.clear())}add(e){const t=this.size();isString(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,s=this.size();t<s;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!isDefined(e)||isBlank(e))return;let s={v:e,i:t,n:this.norm.get(e)};this.records.push(s)}_addObject(e,t){let s={i:t,$:{}};this.keys.forEach(((t,n)=>{let i=t.getFn?t.getFn(e):this.getFn(e,t.path);if(isDefined(i))if(isArray(i)){let e=[];const t=[{nestedArrIndex:-1,value:i}];for(;t.length;){const{nestedArrIndex:s,value:n}=t.pop();if(isDefined(n))if(isString(n)&&!isBlank(n)){let t={v:n,i:s,n:this.norm.get(n)};e.push(t)}else isArray(n)&&n.forEach(((e,s)=>{t.push({nestedArrIndex:s,value:e})}))}s.$[n]=e}else if(isString(i)&&!isBlank(i)){let e={v:i,n:this.norm.get(i)};s.$[n]=e}})),this.records.push(s)}toJSON(){return{keys:this.keys,records:this.records}}}function createIndex(e,t,{getFn:s=Config.getFn,fieldNormWeight:n=Config.fieldNormWeight}={}){const i=new FuseIndex({getFn:s,fieldNormWeight:n});return i.setKeys(e.map(createKey)),i.setSources(t),i.create(),i}function computeScore$1(e,{errors:t=0,currentLocation:s=0,expectedLocation:n=0,distance:i=Config.distance,ignoreLocation:r=Config.ignoreLocation}={}){const c=t/e.length;if(r)return c;const o=Math.abs(n-s);return i?c+o/i:o?1:c}function createPatternAlphabet(e){let t={};for(let s=0,n=e.length;s<n;s+=1){const i=e.charAt(s);t[i]=(t[i]||0)|1<<n-s-1}return t}class BitapSearch{constructor(e,{location:t=Config.location,threshold:s=Config.threshold,distance:n=Config.distance,includeMatches:i=Config.includeMatches,findAllMatches:r=Config.findAllMatches,minMatchCharLength:c=Config.minMatchCharLength,isCaseSensitive:o=Config.isCaseSensitive,ignoreLocation:a=Config.ignoreLocation}={}){if(this.options={location:t,threshold:s,distance:n,includeMatches:i,findAllMatches:r,minMatchCharLength:c,isCaseSensitive:o,ignoreLocation:a},this.pattern=o?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const addChunk=(e,t)=>{this.chunks.push({pattern:e,alphabet:createPatternAlphabet(e),startIndex:t})};const h=this.pattern.length;if(h>32){let e=0;const t=h%32;const s=h-t;for(;e<s;)addChunk(this.pattern.substr(e,32),e),e+=32;if(t){const e=h-32;addChunk(this.pattern.substr(e),e)}}else addChunk(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,includeMatches:s}=this.options;if(t||(e=e.toLowerCase()),this.pattern===e){let t={isMatch:!0,score:0};return s&&(t.indices=[[0,e.length-1]]),t}const{location:n,distance:i,threshold:r,findAllMatches:c,minMatchCharLength:o,ignoreLocation:a}=this.options;let h=[];let l=0;let u=!1;this.chunks.forEach((({pattern:t,alphabet:d,startIndex:g})=>{const{isMatch:f,score:p,indices:M}=((e,t,s,{location:n=Config.location,distance:i=Config.distance,threshold:r=Config.threshold,findAllMatches:c=Config.findAllMatches,minMatchCharLength:o=Config.minMatchCharLength,includeMatches:a=Config.includeMatches,ignoreLocation:h=Config.ignoreLocation}={})=>{if(t.length>32)throw new Error("Pattern length exceeds max of 32.");const l=t.length;const u=e.length;const d=Math.max(0,Math.min(n,u));let g=r;let f=d;const p=o>1||a;const M=p?Array(u):[];let m;for(;(m=e.indexOf(t,f))>-1;){let e=computeScore$1(t,{currentLocation:m,expectedLocation:d,distance:i,ignoreLocation:h});if(g=Math.min(e,g),f=m+l,p){let e=0;for(;e<l;)M[m+e]=1,e+=1}}f=-1;let x=[];let y=1;let C=l+u;const S=1<<l-1;for(let n=0;n<l;n+=1){let r=0;let o=C;for(;r<o;)computeScore$1(t,{errors:n,currentLocation:d+o,expectedLocation:d,distance:i,ignoreLocation:h})<=g?r=o:C=o,o=Math.floor((C-r)/2+r);C=o;let a=Math.max(1,d-o+1);let m=c?u:Math.min(d+o,u)+l;let L=Array(m+2);L[m+1]=(1<<n)-1;for(let r=m;r>=a;r-=1){let c=r-1;let o=s[e.charAt(c)];if(p&&(M[c]=+!!o),L[r]=(L[r+1]<<1|1)&o,n&&(L[r]|=(x[r+1]|x[r])<<1|1|x[r+1]),L[r]&S&&(y=computeScore$1(t,{errors:n,currentLocation:c,expectedLocation:d,distance:i,ignoreLocation:h}),y<=g)){if(g=y,f=c,f<=d)break;a=Math.max(1,2*d-f)}}if(computeScore$1(t,{errors:n+1,currentLocation:d,expectedLocation:d,distance:i,ignoreLocation:h})>g)break;x=L}const L={isMatch:f>=0,score:Math.max(.001,y)};if(p){const e=((e=[],t=Config.minMatchCharLength)=>{let s=[];let n=-1;let i=-1;let r=0;for(let c=e.length;r<c;r+=1){let c=e[r];c&&n===-1?n=r:c||n===-1||(i=r-1,i-n+1>=t&&s.push([n,i]),n=-1)}return e[r-1]&&r-n>=t&&s.push([n,r-1]),s})(M,o);e.length?a&&(L.indices=e):L.isMatch=!1}return L})(e,t,d,{location:n+g,distance:i,threshold:r,findAllMatches:c,minMatchCharLength:o,includeMatches:s,ignoreLocation:a});f&&(u=!0),l+=p,f&&M&&(h=[...h,...M])}));let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&s&&(d.indices=h),d}}class BaseMatch{constructor(e){this.pattern=e}static isMultiMatch(e){return getMatch(e,this.multiRegex)}static isSingleMatch(e){return getMatch(e,this.singleRegex)}search(){}}function getMatch(e,t){const s=e.match(t);return s?s[1]:null}class FuzzyMatch extends BaseMatch{constructor(e,{location:t=Config.location,threshold:s=Config.threshold,distance:n=Config.distance,includeMatches:i=Config.includeMatches,findAllMatches:r=Config.findAllMatches,minMatchCharLength:c=Config.minMatchCharLength,isCaseSensitive:o=Config.isCaseSensitive,ignoreLocation:a=Config.ignoreLocation}={}){super(e),this._bitapSearch=new BitapSearch(e,{location:t,threshold:s,distance:n,includeMatches:i,findAllMatches:r,minMatchCharLength:c,isCaseSensitive:o,ignoreLocation:a})}static get type(){return'fuzzy'}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class IncludeMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'include'}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0;let s;const n=[];const i=this.pattern.length;for(;(s=e.indexOf(this.pattern,t))>-1;)t=s+i,n.push([s,t-1]);const r=!!n.length;return{isMatch:r,score:r?0:1,indices:n}}}const searchers=[class ExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'exact'}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},IncludeMatch,class PrefixExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'prefix-exact'}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},class InversePrefixExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'inverse-prefix-exact'}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class InverseSuffixExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'inverse-suffix-exact'}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class SuffixExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'suffix-exact'}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}},class InverseExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'inverse-exact'}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const t=e.indexOf(this.pattern)===-1;return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},FuzzyMatch];const searchersLen=searchers.length;const SPACE_RE=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;const MultiMatchSet=new Set([FuzzyMatch.type,IncludeMatch.type]);const registeredSearchers=[];function createSearcher(e,t){for(let s=0,n=registeredSearchers.length;s<n;s+=1){let n=registeredSearchers[s];if(n.condition(e,t))return new n(e,t)}return new BitapSearch(e,t)}const LogicalOperator_AND='$and';const isExpression=e=>!(!e.$and&&!e.$or);const convertToExplicit=e=>({[LogicalOperator_AND]:Object.keys(e).map((t=>({[t]:e[t]})))});function parse(e,t,{auto:s=!0}={}){const next=e=>{let n=Object.keys(e);const i=(e=>!!e.$path)(e);if(!i&&n.length>1&&!isExpression(e))return next(convertToExplicit(e));if((e=>!isArray(e)&&isObject(e)&&!isExpression(e))(e)){const r=i?e.$path:n[0];const c=i?e.$val:e[r];if(!isString(c))throw new Error((e=>`Invalid value for key ${e}`)(r));const o={keyId:createKeyId(r),pattern:c};return s&&(o.searcher=createSearcher(c,t)),o}let r={children:[],operator:n[0]};return n.forEach((t=>{const s=e[t];isArray(s)&&s.forEach((e=>{r.children.push(next(e))}))})),r};return isExpression(e)||(e=convertToExplicit(e)),next(e)}function transformMatches(e,t){const s=e.matches;t.matches=[],isDefined(s)&&s.forEach((e=>{if(!isDefined(e.indices)||!e.indices.length)return;const{indices:s,value:n}=e;let i={indices:s,value:n};e.key&&(i.key=e.key.src),e.idx>-1&&(i.refIndex=e.idx),t.matches.push(i)}))}function transformScore(e,t){t.score=e.score}class Fuse{constructor(e,t={},s){this.options={...Config,...t},this._keyStore=new KeyStore(this.options.keys),this.setCollection(e,s)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof FuseIndex))throw new Error("Incorrect 'index' type");this._myIndex=t||createIndex(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){isDefined(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let s=0,n=this._docs.length;s<n;s+=1){const i=this._docs[s];e(i,s)&&(this.removeAt(s),s-=1,n-=1,t.push(i))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:s,includeScore:n,shouldSort:i,sortFn:r,ignoreFieldNorm:c}=this.options;let o=isString(e)?isString(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return((e,{ignoreFieldNorm:t=Config.ignoreFieldNorm})=>{e.forEach((e=>{let s=1;e.matches.forEach((({key:e,norm:n,score:i})=>{const r=e?e.weight:null;s*=Math.pow(i===0&&r?Number.EPSILON:i,(r||1)*(t?1:n))})),e.score=s}))})(o,{ignoreFieldNorm:c}),i&&o.sort(r),isNumber(t)&&t>-1&&(o=o.slice(0,t)),((e,t,{includeMatches:s=Config.includeMatches,includeScore:n=Config.includeScore}={})=>{const i=[];return s&&i.push(transformMatches),n&&i.push(transformScore),e.map((e=>{const{idx:s}=e;const n={item:t[s],refIndex:s};return i.length&&i.forEach((t=>{t(e,n)})),n}))})(o,this._docs,{includeMatches:s,includeScore:n})}_searchStringList(e){const t=createSearcher(e,this.options);const{records:s}=this._myIndex;const n=[];return s.forEach((({v:e,i:s,n:i})=>{if(!isDefined(e))return;const{isMatch:r,score:c,indices:o}=t.searchIn(e);r&&n.push({item:e,idx:s,matches:[{score:c,value:e,norm:i,indices:o}]})})),n}_searchLogical(e){const t=parse(e,this.options);const evaluate=(e,t,s)=>{if(!e.children){const{keyId:n,searcher:i}=e;const r=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(t,n),searcher:i});return r&&r.length?[{idx:s,item:t,matches:r}]:[]}const n=[];for(let i=0,r=e.children.length;i<r;i+=1){const r=evaluate(e.children[i],t,s);if(r.length)n.push(...r);else if(e.operator==="$and")return[]}return n};const s={};const n=[];return this._myIndex.records.forEach((({$:e,i})=>{if(isDefined(e)){let r=evaluate(t,e,i);r.length&&(s[i]||(s[i]={idx:i,item:e,matches:[]},n.push(s[i])),r.forEach((({matches:e})=>{s[i].matches.push(...e)})))}})),n}_searchObjectList(e){const t=createSearcher(e,this.options);const{keys:s,records:n}=this._myIndex;const i=[];return n.forEach((({$:e,i:n})=>{if(!isDefined(e))return;let r=[];s.forEach(((s,n)=>{r.push(...this._findMatches({key:s,value:e[n],searcher:t}))})),r.length&&i.push({idx:n,item:e,matches:r})})),i}_findMatches({key:e,value:t,searcher:s}){if(!isDefined(t))return[];let n=[];if(isArray(t))t.forEach((({v:t,i,n:r})=>{if(!isDefined(t))return;const{isMatch:c,score:o,indices:a}=s.searchIn(t);c&&n.push({score:o,key:e,value:t,idx:i,norm:r,indices:a})}));else{const{v:i,n:r}=t;const{isMatch:c,score:o,indices:a}=s.searchIn(i);c&&n.push({score:o,key:e,value:i,norm:r,indices:a})}return n}}Fuse.version='7.0.0',Fuse.createIndex=createIndex,Fuse.parseIndex=(e,{getFn:t=Config.getFn,fieldNormWeight:s=Config.fieldNormWeight}={})=>{const{keys:n,records:i}=e;const r=new FuseIndex({getFn:t,fieldNormWeight:s});return r.setKeys(n),r.setIndexRecords(i),r},Fuse.config=Config,Fuse.parseQuery=parse,registeredSearchers.push(class ExtendedSearch{constructor(e,{isCaseSensitive:t=Config.isCaseSensitive,includeMatches:s=Config.includeMatches,minMatchCharLength:n=Config.minMatchCharLength,ignoreLocation:i=Config.ignoreLocation,findAllMatches:r=Config.findAllMatches,location:c=Config.location,threshold:o=Config.threshold,distance:a=Config.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:s,minMatchCharLength:n,findAllMatches:r,ignoreLocation:i,location:c,threshold:o,distance:a},this.pattern=t?e:e.toLowerCase(),this.query=((e,t={})=>this.pattern.split("|").map((e=>{let s=e.trim().split(SPACE_RE).filter((e=>e&&!!e.trim()));let n=[];for(let e=0,i=s.length;e<i;e+=1){const i=s[e];let r=!1;let c=-1;for(;!r&&++c<searchersLen;){const e=searchers[c];let s=e.isMultiMatch(i);s&&(n.push(new e(s,t)),r=!0)}if(!r)for(c=-1;++c<searchersLen;){const e=searchers[c];let s=e.isSingleMatch(i);if(s){n.push(new e(s,t));break}}}return n})))(0,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const t=this.query;if(!t)return{isMatch:!1,score:1};const{includeMatches:s,isCaseSensitive:n}=this.options;e=n?e:e.toLowerCase();let i=0;let r=[];let c=0;for(let n=0,o=t.length;n<o;n+=1){const o=t[n];r.length=0,i=0;for(let t=0,n=o.length;t<n;t+=1){const n=o[t];const{isMatch:a,indices:h,score:l}=n.search(e);if(!a){c=0,i=0,r.length=0;break}i+=1,c+=l,s&&(MultiMatchSet.has(n.constructor.type)?r=[...r,...h]:r.push(h))}if(i){let e={isMatch:!0,score:c/i};return s&&(e.indices=r),e}}return{isMatch:!1,score:1}}}),exports.default=Fuse;
|
|
1
|
+
'use strict';function isArray(e){return Array.isArray?Array.isArray(e):getTag(e)==='[object Array]'}function isString(e){return typeof e=='string'}function isNumber(e){return typeof e=='number'}function isObject(e){return typeof e=='object'}function isDefined(e){return e!==void 0&&e!==null}function isBlank(e){return!e.trim().length}function getTag(e){return e==null?e===void 0?'[object Undefined]':'[object Null]':{}.toString.call(e)}Object.defineProperty(exports,'__esModule',{value:!0});const hasOwn={}.hasOwnProperty;class KeyStore{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let s=createKey(e);this._keys.push(s),this._keyMap[s.id]=s,t+=s.weight})),this._keys.forEach((e=>{e.weight/=t}))}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function createKey(e){let t=null;let s=null;let n=null;let i=1;let r=null;if(isString(e)||isArray(e))n=e,t=createKeyPath(e),s=createKeyId(e);else{if(!hasOwn.call(e,'name'))throw new Error("Missing name property in key");const c=e.name;if(n=c,hasOwn.call(e,'weight')&&(i=e.weight,i<=0))throw new Error((e=>`Property 'weight' in key '${e}' must be a positive integer`)(c));t=createKeyPath(c),s=createKeyId(c),r=e.getFn}return{path:t,id:s,weight:i,src:n,getFn:r}}function createKeyPath(e){return isArray(e)?e:e.split('.')}function createKeyId(e){return isArray(e)?e.join('.'):e}var Config={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,useExtendedSearch:!1,getFn:(e,t)=>{let s=[];let n=!1;const deepGet=(e,t,i)=>{if(isDefined(e))if(t[i]){const r=e[t[i]];if(!isDefined(r))return;if(i===t.length-1&&(isString(r)||isNumber(r)||(e=>e===!0||e===!1||(e=>isObject(e)&&e!==null)(e)&&getTag(e)=='[object Boolean]')(r)))s.push((e=>e==null?'':(e=>{if(typeof e=='string')return e;let t=e+'';return t=='0'&&1/e==-1/0?'-0':t})(e))(r));else if(isArray(r)){n=!0;for(let e=0,s=r.length;e<s;e+=1)deepGet(r[e],t,i+1)}else t.length&&deepGet(r,t,i+1)}else s.push(e)};return deepGet(e,isString(t)?t.split('.'):t,0),n?s:s[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};const SPACE=/[^ ]+/g;class FuseIndex{constructor({getFn:e=Config.getFn,fieldNormWeight:t=Config.fieldNormWeight}={}){this.norm=((e=1,t=3)=>{const s=new Map;const n=Math.pow(10,t);return{get(t){const i=t.match(SPACE).length;if(s.has(i))return s.get(i);const r=1/Math.pow(i,.5*e);const c=parseFloat(Math.round(r*n)/n);return s.set(i,c),c},clear(){s.clear()}}})(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach(((e,t)=>{this._keysMap[e.id]=t}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,isString(this.docs[0])?this.docs.forEach(((e,t)=>{this._addString(e,t)})):this.docs.forEach(((e,t)=>{this._addObject(e,t)})),this.norm.clear())}add(e){const t=this.size();isString(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,s=this.size();t<s;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!isDefined(e)||isBlank(e))return;let s={v:e,i:t,n:this.norm.get(e)};this.records.push(s)}_addObject(e,t){let s={i:t,$:{}};this.keys.forEach(((t,n)=>{let i=t.getFn?t.getFn(e):this.getFn(e,t.path);if(isDefined(i))if(isArray(i)){let e=[];const t=[{nestedArrIndex:-1,value:i}];for(;t.length;){const{nestedArrIndex:s,value:n}=t.pop();if(isDefined(n))if(isString(n)&&!isBlank(n)){let t={v:n,i:s,n:this.norm.get(n)};e.push(t)}else isArray(n)&&n.forEach(((e,s)=>{t.push({nestedArrIndex:s,value:e})}))}s.$[n]=e}else if(isString(i)&&!isBlank(i)){let e={v:i,n:this.norm.get(i)};s.$[n]=e}})),this.records.push(s)}toJSON(){return{keys:this.keys,records:this.records}}}function createIndex(e,t,{getFn:s=Config.getFn,fieldNormWeight:n=Config.fieldNormWeight}={}){const i=new FuseIndex({getFn:s,fieldNormWeight:n});return i.setKeys(e.map(createKey)),i.setSources(t),i.create(),i}function computeScore$1(e,{errors:t=0,currentLocation:s=0,expectedLocation:n=0,distance:i=Config.distance,ignoreLocation:r=Config.ignoreLocation}={}){const c=t/e.length;if(r)return c;const o=Math.abs(n-s);return i?c+o/i:o?1:c}function createPatternAlphabet(e){let t={};for(let s=0,n=e.length;s<n;s+=1){const i=e.charAt(s);t[i]=(t[i]||0)|1<<n-s-1}return t}class BitapSearch{constructor(e,{location:t=Config.location,threshold:s=Config.threshold,distance:n=Config.distance,includeMatches:i=Config.includeMatches,findAllMatches:r=Config.findAllMatches,minMatchCharLength:c=Config.minMatchCharLength,isCaseSensitive:o=Config.isCaseSensitive,ignoreLocation:a=Config.ignoreLocation}={}){if(this.options={location:t,threshold:s,distance:n,includeMatches:i,findAllMatches:r,minMatchCharLength:c,isCaseSensitive:o,ignoreLocation:a},this.pattern=o?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const addChunk=(e,t)=>{this.chunks.push({pattern:e,alphabet:createPatternAlphabet(e),startIndex:t})};const h=this.pattern.length;if(h>32){let e=0;const t=h%32;const s=h-t;for(;e<s;)addChunk(this.pattern.substr(e,32),e),e+=32;if(t){const e=h-32;addChunk(this.pattern.substr(e),e)}}else addChunk(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,includeMatches:s}=this.options;if(t||(e=e.toLowerCase()),this.pattern===e){let t={isMatch:!0,score:0};return s&&(t.indices=[[0,e.length-1]]),t}const{location:n,distance:i,threshold:r,findAllMatches:c,minMatchCharLength:o,ignoreLocation:a}=this.options;let h=[];let l=0;let u=!1;this.chunks.forEach((({pattern:t,alphabet:d,startIndex:g})=>{const{isMatch:f,score:p,indices:M}=((e,t,s,{location:n=Config.location,distance:i=Config.distance,threshold:r=Config.threshold,findAllMatches:c=Config.findAllMatches,minMatchCharLength:o=Config.minMatchCharLength,includeMatches:a=Config.includeMatches,ignoreLocation:h=Config.ignoreLocation}={})=>{if(t.length>32)throw new Error("Pattern length exceeds max of 32.");const l=t.length;const u=e.length;const d=Math.max(0,Math.min(n,u));let g=r;let f=d;const p=o>1||a;const M=p?Array(u):[];let m;for(;(m=e.indexOf(t,f))>-1;){let e=computeScore$1(t,{currentLocation:m,expectedLocation:d,distance:i,ignoreLocation:h});if(g=Math.min(e,g),f=m+l,p){let e=0;for(;e<l;)M[m+e]=1,e+=1}}f=-1;let x=[];let y=1;let C=l+u;const S=1<<l-1;for(let n=0;n<l;n+=1){let r=0;let o=C;for(;r<o;)computeScore$1(t,{errors:n,currentLocation:d+o,expectedLocation:d,distance:i,ignoreLocation:h})<=g?r=o:C=o,o=Math.floor((C-r)/2+r);C=o;let a=Math.max(1,d-o+1);let m=c?u:Math.min(d+o,u)+l;let L=Array(m+2);L[m+1]=(1<<n)-1;for(let r=m;r>=a;r-=1){let c=r-1;let o=s[e.charAt(c)];if(p&&(M[c]=+!!o),L[r]=(L[r+1]<<1|1)&o,n&&(L[r]|=(x[r+1]|x[r])<<1|1|x[r+1]),L[r]&S&&(y=computeScore$1(t,{errors:n,currentLocation:c,expectedLocation:d,distance:i,ignoreLocation:h}),y<=g)){if(g=y,f=c,f<=d)break;a=Math.max(1,2*d-f)}}if(computeScore$1(t,{errors:n+1,currentLocation:d,expectedLocation:d,distance:i,ignoreLocation:h})>g)break;x=L}const L={isMatch:f>=0,score:Math.max(.001,y)};if(p){const e=((e=[],t=Config.minMatchCharLength)=>{let s=[];let n=-1;let i=-1;let r=0;for(let c=e.length;r<c;r+=1){let c=e[r];c&&n===-1?n=r:c||n===-1||(i=r-1,i-n+1>=t&&s.push([n,i]),n=-1)}return e[r-1]&&r-n>=t&&s.push([n,r-1]),s})(M,o);e.length?a&&(L.indices=e):L.isMatch=!1}return L})(e,t,d,{location:n+g,distance:i,threshold:r,findAllMatches:c,minMatchCharLength:o,includeMatches:s,ignoreLocation:a});f&&(u=!0),l+=p,f&&M&&(h=[...h,...M])}));let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&s&&(d.indices=h),d}}class BaseMatch{constructor(e){this.pattern=e}static isMultiMatch(e){return getMatch(e,this.multiRegex)}static isSingleMatch(e){return getMatch(e,this.singleRegex)}search(){}}function getMatch(e,t){const s=e.match(t);return s?s[1]:null}class FuzzyMatch extends BaseMatch{constructor(e,{location:t=Config.location,threshold:s=Config.threshold,distance:n=Config.distance,includeMatches:i=Config.includeMatches,findAllMatches:r=Config.findAllMatches,minMatchCharLength:c=Config.minMatchCharLength,isCaseSensitive:o=Config.isCaseSensitive,ignoreLocation:a=Config.ignoreLocation}={}){super(e),this._bitapSearch=new BitapSearch(e,{location:t,threshold:s,distance:n,includeMatches:i,findAllMatches:r,minMatchCharLength:c,isCaseSensitive:o,ignoreLocation:a})}static get type(){return'fuzzy'}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class IncludeMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'include'}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0;let s;const n=[];const i=this.pattern.length;for(;(s=e.indexOf(this.pattern,t))>-1;)t=s+i,n.push([s,t-1]);const r=!!n.length;return{isMatch:r,score:r?0:1,indices:n}}}const searchers=[class ExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'exact'}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},IncludeMatch,class PrefixExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'prefix-exact'}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},class InversePrefixExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'inverse-prefix-exact'}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class InverseSuffixExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'inverse-suffix-exact'}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class SuffixExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'suffix-exact'}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}},class InverseExactMatch extends BaseMatch{constructor(e){super(e)}static get type(){return'inverse-exact'}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const t=e.indexOf(this.pattern)===-1;return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},FuzzyMatch];const searchersLen=searchers.length;const SPACE_RE=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;const MultiMatchSet=new Set([FuzzyMatch.type,IncludeMatch.type]);const registeredSearchers=[];function createSearcher(e,t){for(let s=0,n=registeredSearchers.length;s<n;s+=1){let n=registeredSearchers[s];if(n.condition(e,t))return new n(e,t)}return new BitapSearch(e,t)}const LogicalOperator_AND='$and';const isExpression=e=>!(!e.$and&&!e.$or);const convertToExplicit=e=>({[LogicalOperator_AND]:Object.keys(e).map((t=>({[t]:e[t]})))});function parse(e,t,{auto:s=!0}={}){const next=e=>{let n=Object.keys(e);const i=(e=>!!e.$path)(e);if(!i&&n.length>1&&!isExpression(e))return next(convertToExplicit(e));if((e=>!isArray(e)&&isObject(e)&&!isExpression(e))(e)){const r=i?e.$path:n[0];const c=i?e.$val:e[r];if(!isString(c))throw new Error((e=>`Invalid value for key ${e}`)(r));const o={keyId:createKeyId(r),pattern:c};return s&&(o.searcher=createSearcher(c,t)),o}let r={children:[],operator:n[0]};return n.forEach((t=>{const s=e[t];isArray(s)&&s.forEach((e=>{r.children.push(next(e))}))})),r};return isExpression(e)||(e=convertToExplicit(e)),next(e)}function transformMatches(e,t){const s=e.matches;t.matches=[],isDefined(s)&&s.forEach((e=>{if(!isDefined(e.indices)||!e.indices.length)return;const{indices:s,value:n}=e;let i={indices:s,value:n};e.key&&(i.key=e.key.src),e.idx>-1&&(i.refIndex=e.idx),t.matches.push(i)}))}function transformScore(e,t){t.score=e.score}class Fuse{constructor(e,t={},s){this.options={...Config,...t},this._keyStore=new KeyStore(this.options.keys),this.setCollection(e,s)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof FuseIndex))throw new Error("Incorrect 'index' type");this._myIndex=t||createIndex(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){isDefined(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let s=0,n=this._docs.length;s<n;s+=1){const i=this._docs[s];e(i,s)&&(this.removeAt(s),s-=1,n-=1,t.push(i))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:s,includeScore:n,shouldSort:i,sortFn:r,ignoreFieldNorm:c}=this.options;let o=isString(e)?isString(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return((e,{ignoreFieldNorm:t=Config.ignoreFieldNorm})=>{e.forEach((e=>{let s=1;e.matches.forEach((({key:e,norm:n,score:i})=>{const r=e?e.weight:null;s*=Math.pow(i===0&&r?Number.EPSILON:i,(r||1)*(t?1:n))})),e.score=s}))})(o,{ignoreFieldNorm:c}),i&&o.sort(r),isNumber(t)&&t>-1&&(o=o.slice(0,t)),((e,t,{includeMatches:s=Config.includeMatches,includeScore:n=Config.includeScore}={})=>{const i=[];return s&&i.push(transformMatches),n&&i.push(transformScore),e.map((e=>{const{idx:s}=e;const n={item:t[s],refIndex:s};return i.length&&i.forEach((t=>{t(e,n)})),n}))})(o,this._docs,{includeMatches:s,includeScore:n})}_searchStringList(e){const t=createSearcher(e,this.options);const{records:s}=this._myIndex;const n=[];return s.forEach((({v:e,i:s,n:i})=>{if(!isDefined(e))return;const{isMatch:r,score:c,indices:o}=t.searchIn(e);r&&n.push({item:e,idx:s,matches:[{score:c,value:e,norm:i,indices:o}]})})),n}_searchLogical(e){const t=parse(e,this.options);const evaluate=(e,t,s)=>{if(!e.children){const{keyId:n,searcher:i}=e;const r=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(t,n),searcher:i});return r&&r.length?[{idx:s,item:t,matches:r}]:[]}const n=[];for(let i=0,r=e.children.length;i<r;i+=1){const r=evaluate(e.children[i],t,s);if(r.length)n.push(...r);else if(e.operator==="$and")return[]}return n};const s={};const n=[];return this._myIndex.records.forEach((({$:e,i})=>{if(isDefined(e)){let r=evaluate(t,e,i);r.length&&(s[i]||(s[i]={idx:i,item:e,matches:[]},n.push(s[i])),r.forEach((({matches:e})=>{s[i].matches.push(...e)})))}})),n}_searchObjectList(e){const t=createSearcher(e,this.options);const{keys:s,records:n}=this._myIndex;const i=[];return n.forEach((({$:e,i:n})=>{if(!isDefined(e))return;let r=[];s.forEach(((s,n)=>{r.push(...this._findMatches({key:s,value:e[n],searcher:t}))})),r.length&&i.push({idx:n,item:e,matches:r})})),i}_findMatches({key:e,value:t,searcher:s}){if(!isDefined(t))return[];let n=[];if(isArray(t))t.forEach((({v:t,i,n:r})=>{if(!isDefined(t))return;const{isMatch:c,score:o,indices:a}=s.searchIn(t);c&&n.push({score:o,key:e,value:t,idx:i,norm:r,indices:a})}));else{const{v:i,n:r}=t;const{isMatch:c,score:o,indices:a}=s.searchIn(i);c&&n.push({score:o,key:e,value:i,norm:r,indices:a})}return n}}Fuse.version='7.0.0',Fuse.createIndex=createIndex,Fuse.parseIndex=(e,{getFn:t=Config.getFn,fieldNormWeight:s=Config.fieldNormWeight}={})=>{const{keys:n,records:i}=e;const r=new FuseIndex({getFn:t,fieldNormWeight:s});return r.setKeys(n),r.setIndexRecords(i),r},Fuse.config=Config,Fuse.parseQuery=parse,registeredSearchers.push(class ExtendedSearch{constructor(e,{isCaseSensitive:t=Config.isCaseSensitive,includeMatches:s=Config.includeMatches,minMatchCharLength:n=Config.minMatchCharLength,ignoreLocation:i=Config.ignoreLocation,findAllMatches:r=Config.findAllMatches,location:c=Config.location,threshold:o=Config.threshold,distance:a=Config.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:s,minMatchCharLength:n,findAllMatches:r,ignoreLocation:i,location:c,threshold:o,distance:a},this.pattern=t?e:e.toLowerCase(),this.query=((e,t={})=>this.pattern.split("|").map((e=>{let s=e.trim().split(SPACE_RE).filter((e=>e&&!!e.trim()));let n=[];for(let e=0,i=s.length;e<i;e+=1){const i=s[e];let r=!1;let c=-1;for(;!r&&++c<searchersLen;){const e=searchers[c];let s=e.isMultiMatch(i);s&&(n.push(new e(s,t)),r=!0)}if(!r)for(c=-1;++c<searchersLen;){const e=searchers[c];let s=e.isSingleMatch(i);if(s){n.push(new e(s,t));break}}}return n})))(0,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const t=this.query;if(!t)return{isMatch:!1,score:1};const{includeMatches:s,isCaseSensitive:n}=this.options;e=n?e:e.toLowerCase();let i=0;let r=[];let c=0;for(let n=0,o=t.length;n<o;n+=1){const o=t[n];r.length=0,i=0;for(let t=0,n=o.length;t<n;t+=1){const n=o[t];const{isMatch:a,indices:h,score:l}=n.search(e);if(!a){c=0,i=0,r.length=0;break}i+=1,c+=l,s&&(MultiMatchSet.has(n.constructor.type)?r=[...r,...h]:r.push(h))}if(i){let e={isMatch:!0,score:c/i};return s&&(e.indices=r),e}}return{isMatch:!1,score:1}}}),exports.default=Fuse;
|
|
2
2
|
//# sourceMappingURL=fuse.js.map
|