@bolid-ui/themes 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../theme.cjs"),n=require("../accessibility/helpers.cjs"),r=require("../utils/utils.cjs"),i=require("../components/index.cjs"),a=require("../components/multi-select-live-region.cjs"),o=require("../internal/dummy-input.cjs"),s=require("../internal/required-input.cjs"),c=require("./builtins.cjs"),l=require("./filters.cjs");let u=require("@bolid-ui/primitives"),d=require("classnames");d=e.__toESM(d,1);let f=require("react");f=e.__toESM(f,1);let p=require("react/jsx-runtime");var m={isPopoverActuallyOpen:!1,backspaceRemovesValue:!0,blurInputOnSelect:r.isTouchCapable(),classNames:{},closeMenuOnSelect:!0,closeMenuOnScroll:!1,components:{},triggerShouldRenderValue:!0,escapeClearsValue:!1,filterOption:l.createFilter(),formatGroupLabel:c.formatGroupLabel,disabled:!1,loading:!1,isMulti:!1,dir:`ltr`,isSearchable:!0,loadingMessage:()=>`Загрузка...`,menuIsOpen:!1,noOptionsMessage:()=>`Ничего не найдено`,openMenuOnFocus:!1,openMenuOnClick:!0,options:[],pageSize:5,placeholder:`Выберите...`,screenReaderStatus:({count:e})=>`${e} result${e===1?``:`s`} available`,tabIndex:0,tabSelectsValue:!0};function h(e,t,n){return{type:`option`,data:e,disabled:E(e),isSelected:O(e,t),label:w(e),value:T(e),index:n}}function g(e,t){return e.options.map((n,r)=>{if(typeof n==`object`&&n&&`options`in n){let i=n,a=i.options.map((e,n)=>h(e,t,n)).filter(t=>b(e,t));return a.length>0?{type:`group`,data:i,options:a,index:r}:void 0}let i=h(n,t,r);return b(e,i)?i:void 0}).filter(r.notNullish)}function _(e){return e.reduce((e,t)=>(t.type===`group`?e.push(...t.options.filter(e=>!e.disabled).map(e=>e.data)):t.disabled||e.push(t.data),e),[])}function v(e,t){return e.reduce((e,n)=>(n.type===`group`?e.push(...n.options.filter(e=>!e.disabled).map(e=>({data:e.data,id:`${t}-${n.index}-${e.index}`}))):n.disabled||e.push({data:n.data,id:`${t}-${n.index}`}),e),[])}function y(e,t){return _(g(e,t))}function b(e,t){let{inputValue:n=``}=e,{data:r,isSelected:i,label:a,value:o}=t;return(!A(e)||!i)&&k(e,{label:a,value:o,data:r},n)}function x(e,t){let{focusedValue:n,selectValue:r}=e,i=r.indexOf(n);if(i>-1){if(t.indexOf(n)>-1)return n;if(i<t.length)return t[i]}return null}function S(e,t){let{focusedOption:n,focusableOptionsWithIds:r}=e;if(n&&t.indexOf(n)>-1)return n;if(n&&r.length>0){let e=r.map(e=>e.data).indexOf(n);if(e>-1){if(t[e])return t[e];if(e>0&&t[e-1])return t[e-1]}}return t[0]}var C=(e,t)=>e.find(e=>e.data===t)?.id||null,w=e=>c.getOptionLabel(e),T=e=>c.getOptionValue(e);function E(e){return c.isOptionDisabled(e)}function D(e){return c.isOptionFixed(e)}function O(e,t){if(t.indexOf(e)>-1)return!0;let n=T(e);return t.some(e=>T(e)===n)}function k(e,t,n){return e.filterOption?e.filterOption(t,n):!0}var A=e=>{let{hideSelectedOptions:t,isMulti:n}=e;return t===void 0?n:t},j=1,M=class extends f.Component{static defaultProps=m;state={isPopoverActuallyOpen:!1,ariaSelection:null,focusedOption:null,focusedOptionId:null,focusableOptionsWithIds:[],focusedValue:null,inputIsHidden:!1,isFocused:!1,selectValue:[],clearFocusValueOnUpdate:!1,prevWasFocused:!1,inputIsHiddenAfterUpdate:void 0,prevProps:void 0,instancePrefix:``,isAppleDevice:!1};blockOptionHover=!1;isComposing=!1;commonProps;openAfterFocus=!1;scrollToFocusedOptionOnUpdate=!1;rootRef=null;getRootRef=e=>{this.rootRef=e};multiValueRef=null;getMultiValueRef=e=>{this.multiValueRef=e};focusedOptionRef=null;getFocusedOptionRef=e=>{this.focusedOptionRef=e};menuListRef=null;getMenuListRef=e=>{this.menuListRef=e};inputRef=null;getInputRef=e=>{this.inputRef=e};rootTriggerRef=null;getRootTriggerRef=e=>{this.rootTriggerRef=e};constructor(e){if(super(e),this.state.instancePrefix=`rt-multi-select-`+(this.props.instanceId||++j),this.state.selectValue=r.cleanValue(e.value),e.menuIsOpen&&this.state.selectValue.length){let e=this.getFocusableOptionsWithIds(),t=this.buildFocusableOptions(),n=t.indexOf(this.state.selectValue[0]);this.state.focusableOptionsWithIds=e,this.state.focusedOption=t[n],this.state.focusedOptionId=C(e,t[n])}}static getDerivedStateFromProps(e,t){let{prevProps:n,clearFocusValueOnUpdate:i,inputIsHiddenAfterUpdate:a,ariaSelection:o,isFocused:s,prevWasFocused:c,instancePrefix:l}=t,{options:u,value:d,menuIsOpen:f,inputValue:p,isMulti:m}=e,h=r.cleanValue(d),_={};if(n&&(d!==n.value||u!==n.options||f!==n.menuIsOpen||p!==n.inputValue)){let n=f?y(e,h):[],r=f?v(g(e,h),`${l}-option`):[],a=i?x(t,h):null,o=S(t,n);_={selectValue:h,focusedOption:o,focusedOptionId:C(r,o),focusableOptionsWithIds:r,focusedValue:a,clearFocusValueOnUpdate:!1}}let b=a!=null&&e!==n?{inputIsHidden:a,inputIsHiddenAfterUpdate:void 0}:{},w=o,T=s&&c;return s&&!T&&(w={value:r.valueTernary(m,h,h[0]||null),options:h,action:`initial-input-focus`},T=!c),o?.action===`initial-input-focus`&&(w=null),{..._,...b,prevProps:e,ariaSelection:w,prevWasFocused:T}}componentDidMount(){this.startListeningComposition(),this.props.closeMenuOnScroll&&document&&document.addEventListener&&document.addEventListener(`scroll`,this.onScroll,!0),this.props.autoFocus&&this.focusInput(),this.props.menuIsOpen&&this.state.focusedOption&&this.menuListRef&&this.focusedOptionRef&&r.scrollIntoView(this.menuListRef,this.focusedOptionRef),n.isAppleDevice()&&this.setState({isAppleDevice:!0})}componentDidUpdate(e){let{disabled:t,menuIsOpen:n}=this.props,{isFocused:i,isPopoverActuallyOpen:a}=this.state;n!==a&&this.rootTriggerRef?.click(),(i&&!t&&e.disabled||i&&n&&!e.menuIsOpen)&&this.focusInput(),i&&t&&!e.disabled?this.setState({isFocused:!1},this.onMenuClose):!i&&!t&&e.disabled&&this.inputRef===document.activeElement&&this.setState({isFocused:!0}),this.menuListRef&&this.focusedOptionRef&&this.scrollToFocusedOptionOnUpdate&&(r.scrollIntoView(this.menuListRef,this.focusedOptionRef),this.scrollToFocusedOptionOnUpdate=!1)}componentWillUnmount(){this.stopListeningComposition(),document.removeEventListener(`scroll`,this.onScroll,!0)}onMenuOpen(){this.props.menuIsOpen||this.rootTriggerRef?.click()}onMenuClose(){this.onInputChange(``,{action:`menu-close`,prevInputValue:this.props.inputValue}),this.props.menuIsOpen&&this.rootTriggerRef?.click()}onInputChange(e,t){this.props.onInputChange(e,t)}focusInput(){this.inputRef&&this.inputRef.focus()}blurInput(){this.inputRef&&this.inputRef.blur()}focus=this.focusInput;blur=this.blurInput;openMenu(e){let{selectValue:t,isFocused:n}=this.state,r=this.buildFocusableOptions(),i=e===`first`?0:r.length-1;if(!this.props.isMulti){let e=r.indexOf(t[0]);e>-1&&(i=e)}this.scrollToFocusedOptionOnUpdate=!(n&&this.menuListRef),this.setState({inputIsHiddenAfterUpdate:!1,focusedValue:null,focusedOption:r[i],focusedOptionId:this.getFocusedOptionId(r[i])},()=>{this.onMenuOpen()})}focusValue(e){let{selectValue:t,focusedValue:n}=this.state;if(!this.props.isMulti||this.props.disabled)return;this.setState({focusedOption:null});let r=t.indexOf(n);if(n||(r=-1),!t.length)return;let i=e=>!this.isOptionFixed(e)&&!this.isOptionDisabled(e),a=-1;switch(e){case`previous`:if(r===-1){for(let e=t.length-1;e>=0;e--)if(i(t[e])){a=e;break}}else{for(let e=r-1;e>=0;e--)if(i(t[e])){a=e;break}a===-1&&(a=r)}break;case`next`:if(r>-1){for(let e=r+1;e<t.length;e++)if(i(t[e])){a=e;break}}break}this.setState({focusedValue:t[a]})}focusOption(e=`first`){let{pageSize:t}=this.props,{focusedOption:n}=this.state,r=this.getFocusableOptions();if(!r.length)return;let i=0,a=r.indexOf(n);n||(a=-1),e===`up`?i=a>0?a-1:r.length-1:e===`down`?i=(a+1)%r.length:e===`pageup`?(i=a-t,i<0&&(i=0)):e===`pagedown`?(i=a+t,i>r.length-1&&(i=r.length-1)):e===`last`&&(i=r.length-1),this.scrollToFocusedOptionOnUpdate=!0,this.setState({focusedOption:r[i],focusedValue:null,focusedOptionId:this.getFocusedOptionId(r[i])})}onChange=(e,t)=>{let{onChange:n,name:r}=this.props;t.name=r,this.ariaOnChange(e,t),n(e,t)};setValue=(e,t,n)=>{let{closeMenuOnSelect:r,isMulti:i,inputValue:a}=this.props;this.onInputChange(``,{action:`set-value`,prevInputValue:a}),r&&(this.setState({inputIsHiddenAfterUpdate:!i}),this.onMenuClose()),this.setState({clearFocusValueOnUpdate:!0}),this.onChange(e,{action:t,option:n})};selectOption=e=>{let{blurInputOnSelect:t,isMulti:n,name:i}=this.props,{selectValue:a}=this.state,o=n&&this.isOptionSelected(e,a),s=this.isOptionDisabled(e);if(o){let t=this.getOptionValue(e);this.setValue(r.multiValueAsValue(a.filter(e=>this.getOptionValue(e)!==t)),`deselect-option`,e)}else if(!s)n?this.setValue(r.multiValueAsValue([...a,e]),`select-option`,e):this.setValue(r.singleValueAsValue(e),`select-option`);else{this.ariaOnChange(r.singleValueAsValue(e),{action:`select-option`,option:e,name:i});return}t&&this.blurInput()};removeValue=e=>{let{disabled:t,isMulti:n}=this.props,{selectValue:i}=this.state;if(t||this.isOptionFixed(e)||this.isOptionDisabled(e))return;let a=this.getOptionValue(e),o=i.filter(e=>this.getOptionValue(e)!==a),s=r.valueTernary(n,o,o[0]||null);this.onChange(s,{action:`remove-value`,removedValue:e}),this.focusInput()};clearValue=()=>{if(this.props.disabled)return;let{selectValue:e}=this.state,t=e.filter(e=>this.isOptionFixed(e)||this.isOptionDisabled(e)),n=e.filter(e=>!this.isOptionFixed(e)&&!this.isOptionDisabled(e));n.length!==0&&this.onChange(r.valueTernary(this.props.isMulti,t,null),{action:`clear`,removedValues:n})};popValue=()=>{let{disabled:e,isMulti:t}=this.props,{selectValue:n}=this.state;if(e)return;let i=-1;for(let e=n.length-1;e>=0;e--){let t=n[e];if(!this.isOptionFixed(t)&&!this.isOptionDisabled(t)){i=e;break}}if(i===-1)return;let a=n[i],o=n.filter((e,t)=>t!==i),s=r.valueTernary(t,o,o[0]||null);this.onChange(s,{action:`pop-value`,removedValue:a})};getFocusedOptionId=e=>C(this.state.focusableOptionsWithIds,e);getFocusableOptionsWithIds=()=>v(g(this.props,this.state.selectValue),this.getElementId(`option`));getValue=()=>this.state.selectValue;getCommonProps(){let{clearValue:e,getValue:t,selectOption:n,setValue:r,props:i}=this,{isMulti:a,dir:o,options:s}=i;return{clearValue:e,getValue:t,hasValue:this.hasValue(),isMulti:a,dir:o,options:s,selectOption:n,selectProps:i,setValue:r}}getOptionLabel=e=>w(e);getOptionValue=e=>T(e);getElementId=e=>`${this.state.instancePrefix}-${e}`;getComponents=()=>i.defaultComponents(this.props);buildCategorizedOptions=()=>g(this.props,this.state.selectValue);getCategorizedOptions=()=>this.buildCategorizedOptions();buildFocusableOptions=()=>_(this.buildCategorizedOptions());getFocusableOptions=()=>this.buildFocusableOptions();ariaOnChange=(e,t)=>{this.setState({ariaSelection:{value:e,...t}})};hasValue(){let{selectValue:e}=this.state;return e.length>0}hasOptions(){return!!this.getCategorizedOptions().length}isClearable(){let{isClearable:e,isMulti:t}=this.props;return e===void 0?t:e}isOptionDisabled(e){return E(e)}isOptionFixed(e){return D(e)}isOptionSelected(e,t){return O(e,t)}filterOption(e,t){return k(this.props,e,t)}formatOptionLabel(e,t){if(typeof this.props.formatOptionLabel==`function`){let{inputValue:n}=this.props,{selectValue:r}=this.state;return this.props.formatOptionLabel(e,{context:t,inputValue:n,selectValue:r})}else return this.getOptionLabel(e)}formatGroupLabel(e){return this.props.formatGroupLabel(e)}onTriggerMouseDown=e=>{if(e.defaultPrevented)return;let{openMenuOnClick:t}=this.props;this.state.isFocused?this.props.menuIsOpen?e.target.tagName!==`INPUT`&&e.target.tagName!==`TEXTAREA`&&this.onMenuClose():t&&this.openMenu(`first`):(t&&(this.openAfterFocus=!0),this.focusInput()),e.target.tagName!==`INPUT`&&e.target.tagName!==`TEXTAREA`&&e.preventDefault()};onDropdownIndicatorMouseDown=e=>{if(e&&e.type===`mousedown`&&e.button!==0||this.props.disabled)return;let{isMulti:t,menuIsOpen:n}=this.props;this.focusInput(),n?(this.setState({inputIsHiddenAfterUpdate:!t}),this.onMenuClose()):this.openMenu(`first`),e.preventDefault()};onClearIndicatorMouseDown=e=>{e&&e.type===`mousedown`&&e.button!==0||(this.clearValue(),e.preventDefault(),this.openAfterFocus=!1,e.type===`touchend`?this.focusInput():setTimeout(()=>this.focusInput()))};onScroll=e=>{typeof this.props.closeMenuOnScroll==`boolean`?e.target instanceof HTMLElement&&r.isDocumentElement(e.target)&&this.props.onMenuClose():typeof this.props.closeMenuOnScroll==`function`&&this.props.closeMenuOnScroll(e)&&this.props.onMenuClose()};startListeningComposition(){document&&document.addEventListener&&(document.addEventListener(`compositionstart`,this.onCompositionStart,!1),document.addEventListener(`compositionend`,this.onCompositionEnd,!1))}stopListeningComposition(){document&&document.removeEventListener&&(document.removeEventListener(`compositionstart`,this.onCompositionStart),document.removeEventListener(`compositionend`,this.onCompositionEnd))}onCompositionStart=()=>{this.isComposing=!0};onCompositionEnd=()=>{this.isComposing=!1};handleInputChange=e=>{let{inputValue:t}=this.props,n=e.currentTarget.value;this.setState({inputIsHiddenAfterUpdate:!1}),this.onInputChange(n,{action:`input-change`,prevInputValue:t}),this.props.menuIsOpen||this.onMenuOpen()};onInputFocus=e=>{this.props.onFocus&&this.props.onFocus(e),this.setState({inputIsHiddenAfterUpdate:!1,isFocused:!0}),(this.openAfterFocus||this.props.openMenuOnFocus)&&this.openMenu(`first`),this.openAfterFocus=!1};onInputBlur=e=>{let{inputValue:t}=this.props;if(this.menuListRef&&this.menuListRef.contains(document.activeElement)){this.inputRef.focus();return}this.props.onBlur&&this.props.onBlur(e),this.onInputChange(``,{action:`input-blur`,prevInputValue:t}),this.onMenuClose(),this.setState({focusedValue:null,isFocused:!1})};onOptionHover=e=>{if(this.blockOptionHover&&=!1,this.state.focusedOption===e)return;let t=this.getFocusableOptions().indexOf(e);this.setState({focusedOption:e,focusedOptionId:t>-1?this.getFocusedOptionId(e):null})};shouldHideSelectedOptions=()=>A(this.props);onValueInputFocus=e=>{e.preventDefault(),e.stopPropagation(),this.focus()};onKeyDown=e=>{let{isMulti:t,backspaceRemovesValue:n,escapeClearsValue:r,inputValue:i,isClearable:a,disabled:o,menuIsOpen:s,onKeyDown:c,tabSelectsValue:l,openMenuOnFocus:u}=this.props,{focusedOption:d,focusedValue:f,selectValue:p}=this.state;if(!o&&!(typeof c==`function`&&(c(e),e.defaultPrevented))){switch(this.blockOptionHover=!0,e.key){case`ArrowLeft`:if(!t||i)return;this.focusValue(`previous`);break;case`ArrowRight`:if(!t||i)return;this.focusValue(`next`);break;case`Delete`:case`Backspace`:if(i)return;if(f)this.removeValue(f);else{if(!n)return;t?this.popValue():a&&this.clearValue()}break;case`Tab`:if(this.isComposing||e.shiftKey||!s||!l||!d||u&&this.isOptionSelected(d,p))return;this.selectOption(d);break;case`Enter`:if(e.keyCode===229)break;if(f){this.removeValue(f);break}if(s){if(!d||this.isComposing)return;this.selectOption(d);break}this.openMenu(`first`);return;case`Escape`:s?(this.setState({inputIsHiddenAfterUpdate:!1}),this.onInputChange(``,{action:`menu-close`,prevInputValue:i}),this.onMenuClose()):a&&r&&this.clearValue();break;case` `:if(i)return;if(!s){this.openMenu(`first`);break}if(!d)return;this.selectOption(d);break;case`ArrowUp`:s?this.focusOption(`up`):this.openMenu(`last`);break;case`ArrowDown`:s?this.focusOption(`down`):this.openMenu(`first`);break;case`PageUp`:if(!s)return;this.focusOption(`pageup`);break;case`PageDown`:if(!s)return;this.focusOption(`pagedown`);break;case`Home`:if(!s)return;this.focusOption(`first`);break;case`End`:if(!s)return;this.focusOption(`last`);break;default:return}e.preventDefault()}};renderInput(){let{disabled:e,isSearchable:t,inputId:n,inputValue:i,tabIndex:a,form:s,menuIsOpen:c,required:l,placeholder:u,isMulti:d}=this.props,{Input:f}=this.getComponents(),{inputIsHidden:m,ariaSelection:h}=this.state,{commonProps:g}=this,_=n||this.getElementId(`input`),v={"aria-autocomplete":`list`,"aria-expanded":c,"aria-haspopup":!0,"aria-errormessage":this.props[`aria-errormessage`],"aria-invalid":this.props[`aria-invalid`],"aria-label":this.props[`aria-label`],"aria-labelledby":this.props[`aria-labelledby`],"aria-required":l,role:`combobox`,"aria-activedescendant":this.state.isAppleDevice?void 0:this.state.focusedOptionId||``,...c&&{"aria-controls":this.getElementId(`listbox`)},...!t&&{"aria-readonly":!0},...this.hasValue()?h?.action===`initial-input-focus`&&{"aria-describedby":this.getElementId(`live-region`)}:{"aria-describedby":this.getElementId(`placeholder`)}};return t?(0,p.jsx)(f,{...g,placeholder:d&&typeof u==`string`||!this.hasValue()&&typeof u==`string`?u:void 0,autoCapitalize:`none`,autoComplete:`off`,autoCorrect:`off`,id:_,innerRef:this.getInputRef,disabled:e,isHidden:m,onBlur:this.onInputBlur,onChange:this.handleInputChange,onFocus:this.onInputFocus,spellCheck:`false`,tabIndex:a,form:s,type:`text`,value:i,...v}):(0,p.jsx)(o.default,{id:_,innerRef:this.getInputRef,onBlur:this.onInputBlur,onChange:r.noop,onFocus:this.onInputFocus,disabled:e,tabIndex:a,inputMode:`none`,form:s,value:``,placeholder:d&&typeof u==`string`||!this.hasValue()&&typeof u==`string`?u:void 0,style:!d&&this.hasValue()?{width:`0px`}:{},...v})}renderPlaceholderOrValue(){let{MultiSelectOption:e,MultiSelectOptionContainer:t,MultiSelectOptionLabel:n,MultiSelectOptionRemove:r,MultiSelectSingleValue:i,MultiSelectCustomPlaceholder:a}=this.getComponents(),{commonProps:o}=this,{triggerShouldRenderValue:s,disabled:c,isMulti:l,inputValue:u,placeholder:d}=this.props,{selectValue:m,focusedValue:h,isFocused:g}=this.state;if((!this.hasValue()||!s)&&typeof d!=`string`)return u?null:(0,f.createElement)(a,{...o,key:`placeholder`,disabled:c,isFocused:g,innerProps:{id:this.getElementId(`placeholder`)}},d);if(l)return m.map((i,a)=>{let s=i===h,l=`${this.getOptionLabel(i)}-${this.getOptionValue(i)}`,u=this.isOptionDisabled(i),d=this.isOptionFixed(i);return(0,f.createElement)(e,{...o,components:{Container:t,Label:n,Remove:r},isFocused:s,disabled:c||u,isFixed:d,key:l,index:a,removeProps:{onClick:()=>this.removeValue(i),onTouchEnd:()=>this.removeValue(i),onMouseDown:e=>{e.preventDefault()}},data:i,innerProps:{ref:this.getMultiValueRef}},this.formatOptionLabel(i,`value`))});if(u)return null;let _=m[0];if(!_)return null;let v=this.isOptionDisabled(_);return(0,p.jsx)(i,{...o,data:_,disabled:c||v,children:this.formatOptionLabel(_,`value`)})}renderClearIndicator(){let{MultiSelectTriggerClearIndicator:e}=this.getComponents(),{commonProps:t}=this,{loading:n}=this.props,{isFocused:r}=this.state;if(!this.isClearable()||!e||!this.hasValue()||n)return null;let i={onMouseDown:this.onClearIndicatorMouseDown,"aria-hidden":!0};return(0,p.jsx)(e,{...t,innerProps:i,isFocused:r})}renderLoadingIndicator(){let{MultiSelectTriggerLoadingIndicator:e}=this.getComponents(),{commonProps:t}=this,{disabled:n,loading:r}=this.props,{isFocused:i}=this.state;if(!e||!r)return null;let a={"aria-hidden":!0};return(0,p.jsx)(e,{...t,innerProps:a,disabled:n,isFocused:i})}renderIndicatorSeparator(e){let{MultiSelectTriggerDropdownIndicator:t,MultiSelectTriggerSeparator:n}=this.getComponents(),{separator:r,separatorOnlyWithClear:i=!0}=this.props;if(r===!1||i&&!e||!t||!n)return null;let{commonProps:a}=this,{disabled:o}=this.props,{isFocused:s}=this.state;return(0,p.jsx)(n,{...a,disabled:o,isFocused:s})}renderDropdownIndicator(){let{MultiSelectTriggerDropdownIndicator:e}=this.getComponents();if(!e)return null;let{commonProps:t}=this,{disabled:n}=this.props,{isFocused:r}=this.state,i={onMouseDown:this.onDropdownIndicatorMouseDown,"aria-hidden":!0};return(0,p.jsx)(e,{...t,innerProps:i,disabled:n,isFocused:r})}renderMenu(){let{MultiSelectGroup:e,MultiSelectLabel:n,LoadingMessage:r,NoOptionsMessage:i,MultiSelectitem:a}=this.getComponents(),{commonProps:o}=this,{focusedOption:s}=this.state,{inputValue:c,loading:l,loadingMessage:m,dir:h,noOptionsMessage:g}=this.props,_=(e,t)=>{let{type:n,data:r,disabled:i,isSelected:c,label:l}=e,u=s===r,d=i?void 0:()=>this.onOptionHover(r),p=i?void 0:()=>this.selectOption(r),m=`${this.getElementId(`option`)}-${t}`,h={id:m,onClick:p,onMouseMove:d,onMouseOver:d,tabIndex:-1,role:`option`,"aria-selected":this.state.isAppleDevice?void 0:c};return(0,f.createElement)(a,{...o,innerProps:h,data:r,disabled:i,isSelected:c,key:m,label:l,type:n,isFocused:u,innerRef:u?this.getFocusedOptionRef:void 0},this.formatOptionLabel(e.data,`menu`))},v;if(this.hasOptions())v=this.getCategorizedOptions().map(t=>{if(t.type===`group`){let{data:r,options:i,index:a}=t,s=`${this.getElementId(`group`)}-${a}`,c=`${s}-heading`;return(0,f.createElement)(e,{...o,key:s,data:r,options:i.map(e=>e.data),MultiSelectLabel:n,multiSelectLabelProps:{id:c,data:t.data},label:this.formatGroupLabel(t.data)},t.options.map(e=>_(e,`${a}-${e.index}`)))}else if(t.type===`option`)return _(t,`${t.index}`)});else if(l){let e=m({inputValue:c});if(e===null)return null;v=(0,p.jsx)(r,{...o,children:e})}else{let e=g({inputValue:c});if(e===null)return null;v=(0,p.jsx)(i,{...o,children:e})}let{contentClassName:y,portal:b=!0,container:x,align:S=`start`,side:C,sideOffset:w=4,alignOffset:T,collisionPadding:E=10,avoidCollisions:D,sticky:O,hideWhenDetached:k,contentColor:A,radius:j}=this.props,M=(0,p.jsx)(t.Theme,{asChild:!0,accentColor:A,radius:j,children:(0,p.jsx)(u.Popover.Content,{dir:h,align:S,side:C,sideOffset:w,alignOffset:T,collisionPadding:E,avoidCollisions:D,sticky:O,hideWhenDetached:k,className:(0,d.default)(`rt-PopperContent`,`rt-MultiSelectContent`,y),style:{boxSizing:`border-box`,display:`flex`,flexDirection:`column`},onOpenAutoFocus:e=>e.preventDefault(),onCloseAutoFocus:e=>e.preventDefault(),onInteractOutside:e=>{let t=e.target;this.rootRef?.parentElement?.contains(t)&&e.preventDefault()},onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),this.focusInput()},children:(0,p.jsxs)(u.ScrollArea.Root,{type:`auto`,className:(0,d.default)(`rt-ScrollAreaRoot`),style:{maxHeight:`100%`},children:[(0,p.jsx)(u.ScrollArea.Viewport,{ref:this.getMenuListRef,className:(0,d.default)(`rt-ScrollAreaViewport`,`rt-MultiSelectViewport`),style:{position:`relative`,flex:1,overflowX:`hidden`,overflowY:`auto`},children:v}),(0,p.jsx)(u.ScrollArea.Scrollbar,{className:`rt-ScrollAreaScrollbar rt-r-size-1`,orientation:`vertical`,children:(0,p.jsx)(u.ScrollArea.Thumb,{className:`rt-ScrollAreaThumb`})})]})})});return b?(0,p.jsx)(u.Popover.Portal,{container:x,children:M}):M}renderFormField(){let{delimiter:e,disabled:t,isMulti:n,name:r,required:i}=this.props,{selectValue:a}=this.state;if(i&&!this.hasValue()&&!t)return(0,p.jsx)(s.default,{name:r,onFocus:this.onValueInputFocus});if(!(!r||t))return n?e?(0,p.jsx)(`input`,{name:r,type:`hidden`,value:a.map(e=>this.getOptionValue(e)).join(e)}):(0,p.jsx)(`div`,{children:a.length>0?a.map((e,t)=>(0,p.jsx)(`input`,{name:r,type:`hidden`,value:this.getOptionValue(e)},`i-${t}`)):(0,p.jsx)(`input`,{name:r,type:`hidden`,value:``})}):(0,p.jsx)(`input`,{name:r,type:`hidden`,value:a[0]?this.getOptionValue(a[0]):``})}renderLiveRegion(){let{commonProps:e}=this,{ariaSelection:t,focusedOption:n,focusedValue:r,isFocused:i,selectValue:o}=this.state,s=this.getFocusableOptions();return(0,p.jsx)(a.default,{...e,id:this.getElementId(`live-region`),ariaSelection:t,focusedOption:n,focusedValue:r,isFocused:i,selectValue:o,focusableOptions:s,isAppleDevice:this.state.isAppleDevice})}render(){let{MultiSelectInner:e,MultiSelectTriggerIndicatorsContainer:t,MultiSelectTrigger:n,MultiSelectValueContainer:r}=this.getComponents(),{className:i,id:a,disabled:o,menuIsOpen:s,color:c,radius:l}=this.props,{isFocused:d}=this.state,f=this.commonProps=this.getCommonProps(),m=this.renderClearIndicator();return(0,p.jsxs)(u.Popover.Root,{modal:!1,removeScroll:!0,onOpenChange:e=>{this.setState({isPopoverActuallyOpen:e}),e?this.props.onMenuOpen():this.props.onMenuClose()},children:[(0,p.jsxs)(n,{...f,className:i,innerProps:{id:a,onKeyDown:this.onKeyDown,ref:this.getRootRef,onMouseDown:this.onTriggerMouseDown,"data-accent-color":c,"data-radius":l},disabled:o,isFocused:d,menuIsOpen:s,children:[this.renderLiveRegion(),(0,p.jsxs)(e,{...f,innerProps:{},disabled:o,isFocused:d,menuIsOpen:s,children:[(0,p.jsxs)(r,{...f,disabled:o,children:[this.renderPlaceholderOrValue(),this.renderInput()]}),(0,p.jsxs)(t,{...f,disabled:o,children:[m,this.renderLoadingIndicator(),this.renderIndicatorSeparator(m),this.renderDropdownIndicator()]}),(0,p.jsx)(u.Popover.Trigger,{ref:this.getRootTriggerRef,tabIndex:-1,"aria-hidden":`true`,inert:!0,style:{position:`absolute`,opacity:0,pointerEvents:`none`,width:0,height:0,overflow:`hidden`,padding:0,margin:0,clipPath:`inset(50%)`,whiteSpace:`nowrap`,borderWidth:0}})]}),this.renderFormField()]}),this.renderMenu()]})}};exports.default=M;
|
|
1
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../theme.cjs"),n=require("../accessibility/helpers.cjs"),r=require("../utils/utils.cjs"),i=require("../components/index.cjs"),a=require("../components/multi-select-live-region.cjs"),o=require("../internal/dummy-input.cjs"),s=require("../internal/required-input.cjs"),c=require("./builtins.cjs"),l=require("./filters.cjs");let u=require("@bolid-ui/primitives"),d=require("classnames");d=e.__toESM(d,1);let f=require("react");f=e.__toESM(f,1);let p=require("react/jsx-runtime");var m={isPopoverActuallyOpen:!1,backspaceRemovesValue:!0,blurInputOnSelect:r.isTouchCapable(),classNames:{},closeMenuOnSelect:!0,closeMenuOnScroll:!1,components:{},triggerShouldRenderValue:!0,escapeClearsValue:!1,filterOption:l.createFilter(),formatGroupLabel:c.formatGroupLabel,disabled:!1,loading:!1,isMulti:!1,dir:`ltr`,isSearchable:!0,loadingMessage:()=>`Загрузка...`,menuIsOpen:!1,noOptionsMessage:()=>`Ничего не найдено`,openMenuOnFocus:!1,openMenuOnClick:!0,options:[],pageSize:5,placeholder:`Выберите...`,screenReaderStatus:({count:e})=>`${e} result${e===1?``:`s`} available`,tabIndex:0,tabSelectsValue:!0};function h(e,t,n){return{type:`option`,data:e,disabled:E(e),isSelected:O(e,t),label:w(e),value:T(e),index:n}}function g(e,t){return e.options.map((n,r)=>{if(typeof n==`object`&&n&&`options`in n){let i=n,a=i.options.map((e,n)=>h(e,t,n)).filter(t=>b(e,t));return a.length>0?{type:`group`,data:i,options:a,index:r}:void 0}let i=h(n,t,r);return b(e,i)?i:void 0}).filter(r.notNullish)}function _(e){return e.reduce((e,t)=>(t.type===`group`?e.push(...t.options.filter(e=>!e.disabled).map(e=>e.data)):t.disabled||e.push(t.data),e),[])}function v(e,t){return e.reduce((e,n)=>(n.type===`group`?e.push(...n.options.filter(e=>!e.disabled).map(e=>({data:e.data,id:`${t}-${n.index}-${e.index}`}))):n.disabled||e.push({data:n.data,id:`${t}-${n.index}`}),e),[])}function y(e,t){return _(g(e,t))}function b(e,t){let{inputValue:n=``}=e,{data:r,isSelected:i,label:a,value:o}=t;return(!A(e)||!i)&&k(e,{label:a,value:o,data:r},n)}function x(e,t){let{focusedValue:n,selectValue:r}=e,i=r.indexOf(n);if(i>-1){if(t.indexOf(n)>-1)return n;if(i<t.length)return t[i]}return null}function S(e,t){let{focusedOption:n,focusableOptionsWithIds:r}=e;if(n&&t.indexOf(n)>-1)return n;if(n&&r.length>0){let e=r.map(e=>e.data).indexOf(n);if(e>-1){if(t[e])return t[e];if(e>0&&t[e-1])return t[e-1]}}return t[0]}var C=(e,t)=>e.find(e=>e.data===t)?.id||null,w=e=>c.getOptionLabel(e),T=e=>c.getOptionValue(e);function E(e){return c.isOptionDisabled(e)}function D(e){return c.isOptionFixed(e)}function O(e,t){if(t.indexOf(e)>-1)return!0;let n=T(e);return t.some(e=>T(e)===n)}function k(e,t,n){return e.filterOption?e.filterOption(t,n):!0}var A=e=>{let{hideSelectedOptions:t,isMulti:n}=e;return t===void 0?n:t},j=1,M=class extends f.Component{static defaultProps=m;state={isPopoverActuallyOpen:!1,ariaSelection:null,focusedOption:null,focusedOptionId:null,focusableOptionsWithIds:[],focusedValue:null,inputIsHidden:!1,isFocused:!1,selectValue:[],clearFocusValueOnUpdate:!1,prevWasFocused:!1,inputIsHiddenAfterUpdate:void 0,prevProps:void 0,instancePrefix:``,isAppleDevice:!1};blockOptionHover=!1;isComposing=!1;commonProps;openAfterFocus=!1;scrollToFocusedOptionOnUpdate=!1;rootRef=null;getRootRef=e=>{this.rootRef=e};multiValueRef=null;getMultiValueRef=e=>{this.multiValueRef=e};focusedOptionRef=null;getFocusedOptionRef=e=>{this.focusedOptionRef=e};menuListRef=null;getMenuListRef=e=>{this.menuListRef=e};inputRef=null;getInputRef=e=>{this.inputRef=e};rootTriggerRef=null;getRootTriggerRef=e=>{this.rootTriggerRef=e};constructor(e){if(super(e),this.state.instancePrefix=`rt-multi-select-`+(this.props.instanceId||++j),this.state.selectValue=r.cleanValue(e.value),e.menuIsOpen&&this.state.selectValue.length){let e=this.getFocusableOptionsWithIds(),t=this.buildFocusableOptions(),n=t.indexOf(this.state.selectValue[0]);this.state.focusableOptionsWithIds=e,this.state.focusedOption=t[n],this.state.focusedOptionId=C(e,t[n])}}static getDerivedStateFromProps(e,t){let{prevProps:n,clearFocusValueOnUpdate:i,inputIsHiddenAfterUpdate:a,ariaSelection:o,isFocused:s,prevWasFocused:c,instancePrefix:l}=t,{options:u,value:d,menuIsOpen:f,inputValue:p,isMulti:m}=e,h=r.cleanValue(d),_={};if(n&&(d!==n.value||u!==n.options||f!==n.menuIsOpen||p!==n.inputValue)){let n=f?y(e,h):[],r=f?v(g(e,h),`${l}-option`):[],a=i?x(t,h):null,o=S(t,n);_={selectValue:h,focusedOption:o,focusedOptionId:C(r,o),focusableOptionsWithIds:r,focusedValue:a,clearFocusValueOnUpdate:!1}}let b=a!=null&&e!==n?{inputIsHidden:a,inputIsHiddenAfterUpdate:void 0}:{},w=o,T=s&&c;return s&&!T&&(w={value:r.valueTernary(m,h,h[0]||null),options:h,action:`initial-input-focus`},T=!c),o?.action===`initial-input-focus`&&(w=null),{..._,...b,prevProps:e,ariaSelection:w,prevWasFocused:T}}componentDidMount(){this.startListeningComposition(),this.props.closeMenuOnScroll&&document&&document.addEventListener&&document.addEventListener(`scroll`,this.onScroll,!0),this.props.autoFocus&&this.focusInput(),this.props.menuIsOpen&&this.state.focusedOption&&this.menuListRef&&this.focusedOptionRef&&r.scrollIntoView(this.menuListRef,this.focusedOptionRef),n.isAppleDevice()&&this.setState({isAppleDevice:!0})}componentDidUpdate(e){let{disabled:t,menuIsOpen:n}=this.props,{isFocused:i,isPopoverActuallyOpen:a}=this.state;n!==a&&this.rootTriggerRef?.click(),(i&&!t&&e.disabled||i&&n&&!e.menuIsOpen)&&this.focusInput(),i&&t&&!e.disabled?this.setState({isFocused:!1},this.onMenuClose):!i&&!t&&e.disabled&&this.inputRef===document.activeElement&&this.setState({isFocused:!0}),this.menuListRef&&this.focusedOptionRef&&this.scrollToFocusedOptionOnUpdate&&(r.scrollIntoView(this.menuListRef,this.focusedOptionRef),this.scrollToFocusedOptionOnUpdate=!1)}componentWillUnmount(){this.stopListeningComposition(),document.removeEventListener(`scroll`,this.onScroll,!0)}onMenuOpen(){this.props.menuIsOpen||this.rootTriggerRef?.click()}onMenuClose(){this.onInputChange(``,{action:`menu-close`,prevInputValue:this.props.inputValue}),this.props.menuIsOpen&&this.rootTriggerRef?.click()}onInputChange(e,t){this.props.onInputChange(e,t)}focusInput(){this.inputRef&&this.inputRef.focus()}blurInput(){this.inputRef&&this.inputRef.blur()}focus=this.focusInput;blur=this.blurInput;openMenu(e){let{selectValue:t,isFocused:n}=this.state,r=this.buildFocusableOptions(),i=e===`first`?0:r.length-1;if(!this.props.isMulti){let e=r.indexOf(t[0]);e>-1&&(i=e)}this.scrollToFocusedOptionOnUpdate=!(n&&this.menuListRef),this.setState({inputIsHiddenAfterUpdate:!1,focusedValue:null,focusedOption:r[i],focusedOptionId:this.getFocusedOptionId(r[i])},()=>{this.onMenuOpen()})}focusValue(e){let{selectValue:t,focusedValue:n}=this.state;if(!this.props.isMulti||this.props.disabled)return;this.setState({focusedOption:null});let r=t.indexOf(n);if(n||(r=-1),!t.length)return;let i=e=>!this.isOptionFixed(e)&&!this.isOptionDisabled(e),a=-1;switch(e){case`previous`:if(r===-1){for(let e=t.length-1;e>=0;e--)if(i(t[e])){a=e;break}}else{for(let e=r-1;e>=0;e--)if(i(t[e])){a=e;break}a===-1&&(a=r)}break;case`next`:if(r>-1){for(let e=r+1;e<t.length;e++)if(i(t[e])){a=e;break}}break}this.setState({focusedValue:t[a]})}focusOption(e=`first`){let{pageSize:t}=this.props,{focusedOption:n}=this.state,r=this.getFocusableOptions();if(!r.length)return;let i=0,a=r.indexOf(n);n||(a=-1),e===`up`?i=a>0?a-1:r.length-1:e===`down`?i=(a+1)%r.length:e===`pageup`?(i=a-t,i<0&&(i=0)):e===`pagedown`?(i=a+t,i>r.length-1&&(i=r.length-1)):e===`last`&&(i=r.length-1),this.scrollToFocusedOptionOnUpdate=!0,this.setState({focusedOption:r[i],focusedValue:null,focusedOptionId:this.getFocusedOptionId(r[i])})}onChange=(e,t)=>{let{onChange:n,name:r}=this.props;t.name=r,this.ariaOnChange(e,t),n(e,t)};setValue=(e,t,n)=>{let{closeMenuOnSelect:r,isMulti:i,inputValue:a}=this.props;this.onInputChange(``,{action:`set-value`,prevInputValue:a}),r&&(this.setState({inputIsHiddenAfterUpdate:!i}),this.onMenuClose()),this.setState({clearFocusValueOnUpdate:!0}),this.onChange(e,{action:t,option:n})};selectOption=e=>{let{blurInputOnSelect:t,isMulti:n,name:i}=this.props,{selectValue:a}=this.state,o=n&&this.isOptionSelected(e,a),s=this.isOptionDisabled(e);if(o){let t=this.getOptionValue(e);this.setValue(r.multiValueAsValue(a.filter(e=>this.getOptionValue(e)!==t)),`deselect-option`,e)}else if(!s)n?this.setValue(r.multiValueAsValue([...a,e]),`select-option`,e):this.setValue(r.singleValueAsValue(e),`select-option`);else{this.ariaOnChange(r.singleValueAsValue(e),{action:`select-option`,option:e,name:i});return}t&&this.blurInput()};removeValue=e=>{let{disabled:t,isMulti:n}=this.props,{selectValue:i}=this.state;if(t||this.isOptionFixed(e)||this.isOptionDisabled(e))return;let a=this.getOptionValue(e),o=i.filter(e=>this.getOptionValue(e)!==a),s=r.valueTernary(n,o,o[0]||null);this.onChange(s,{action:`remove-value`,removedValue:e}),this.focusInput()};clearValue=()=>{if(this.props.disabled)return;let{selectValue:e}=this.state,t=e.filter(e=>this.isOptionFixed(e)||this.isOptionDisabled(e)),n=e.filter(e=>!this.isOptionFixed(e)&&!this.isOptionDisabled(e));n.length!==0&&this.onChange(r.valueTernary(this.props.isMulti,t,null),{action:`clear`,removedValues:n})};popValue=()=>{let{disabled:e,isMulti:t}=this.props,{selectValue:n}=this.state;if(e)return;let i=-1;for(let e=n.length-1;e>=0;e--){let t=n[e];if(!this.isOptionFixed(t)&&!this.isOptionDisabled(t)){i=e;break}}if(i===-1)return;let a=n[i],o=n.filter((e,t)=>t!==i),s=r.valueTernary(t,o,o[0]||null);this.onChange(s,{action:`pop-value`,removedValue:a})};getFocusedOptionId=e=>C(this.state.focusableOptionsWithIds,e);getFocusableOptionsWithIds=()=>v(g(this.props,this.state.selectValue),this.getElementId(`option`));getValue=()=>this.state.selectValue;getCommonProps(){let{clearValue:e,getValue:t,selectOption:n,setValue:r,props:i}=this,{isMulti:a,dir:o,options:s}=i;return{clearValue:e,getValue:t,hasValue:this.hasValue(),isMulti:a,dir:o,options:s,selectOption:n,selectProps:i,setValue:r}}getOptionLabel=e=>w(e);getOptionValue=e=>T(e);getElementId=e=>`${this.state.instancePrefix}-${e}`;getComponents=()=>i.defaultComponents(this.props);buildCategorizedOptions=()=>g(this.props,this.state.selectValue);getCategorizedOptions=()=>this.buildCategorizedOptions();buildFocusableOptions=()=>_(this.buildCategorizedOptions());getFocusableOptions=()=>this.buildFocusableOptions();ariaOnChange=(e,t)=>{this.setState({ariaSelection:{value:e,...t}})};hasValue(){let{selectValue:e}=this.state;return e.length>0}hasOptions(){return!!this.getCategorizedOptions().length}isClearable(){let{isClearable:e,isMulti:t}=this.props;return e===void 0?t:e}isOptionDisabled(e){return E(e)}isOptionFixed(e){return D(e)}isOptionSelected(e,t){return O(e,t)}filterOption(e,t){return k(this.props,e,t)}formatOptionLabel(e,t){if(typeof this.props.formatOptionLabel==`function`){let{inputValue:n}=this.props,{selectValue:r}=this.state;return this.props.formatOptionLabel(e,{context:t,inputValue:n,selectValue:r})}else return this.getOptionLabel(e)}formatGroupLabel(e){return this.props.formatGroupLabel(e)}onTriggerMouseDown=e=>{if(e.defaultPrevented)return;let{openMenuOnClick:t}=this.props;this.state.isFocused?this.props.menuIsOpen?e.target.tagName!==`INPUT`&&e.target.tagName!==`TEXTAREA`&&this.onMenuClose():t&&this.openMenu(`first`):(t&&(this.openAfterFocus=!0),this.focusInput()),e.target.tagName!==`INPUT`&&e.target.tagName!==`TEXTAREA`&&e.preventDefault()};onDropdownIndicatorMouseDown=e=>{if(e&&e.type===`mousedown`&&e.button!==0||this.props.disabled)return;let{isMulti:t,menuIsOpen:n}=this.props;this.focusInput(),n?(this.setState({inputIsHiddenAfterUpdate:!t}),this.onMenuClose()):this.openMenu(`first`),e.preventDefault()};onClearIndicatorMouseDown=e=>{e&&e.type===`mousedown`&&e.button!==0||(this.clearValue(),e.preventDefault(),this.openAfterFocus=!1,e.type===`touchend`?this.focusInput():setTimeout(()=>this.focusInput()))};onScroll=e=>{typeof this.props.closeMenuOnScroll==`boolean`?e.target instanceof HTMLElement&&r.isDocumentElement(e.target)&&this.props.onMenuClose():typeof this.props.closeMenuOnScroll==`function`&&this.props.closeMenuOnScroll(e)&&this.props.onMenuClose()};startListeningComposition(){document&&document.addEventListener&&(document.addEventListener(`compositionstart`,this.onCompositionStart,!1),document.addEventListener(`compositionend`,this.onCompositionEnd,!1))}stopListeningComposition(){document&&document.removeEventListener&&(document.removeEventListener(`compositionstart`,this.onCompositionStart),document.removeEventListener(`compositionend`,this.onCompositionEnd))}onCompositionStart=()=>{this.isComposing=!0};onCompositionEnd=()=>{this.isComposing=!1};handleInputChange=e=>{let{inputValue:t}=this.props,n=e.currentTarget.value;this.setState({inputIsHiddenAfterUpdate:!1}),this.onInputChange(n,{action:`input-change`,prevInputValue:t}),this.props.menuIsOpen||this.onMenuOpen()};onInputFocus=e=>{this.props.onFocus&&this.props.onFocus(e),this.setState({inputIsHiddenAfterUpdate:!1,isFocused:!0}),(this.openAfterFocus||this.props.openMenuOnFocus)&&this.openMenu(`first`),this.openAfterFocus=!1};onInputBlur=e=>{let{inputValue:t}=this.props;if(this.menuListRef&&this.menuListRef.contains(document.activeElement)){this.inputRef.focus();return}this.props.onBlur&&this.props.onBlur(e),this.onInputChange(``,{action:`input-blur`,prevInputValue:t}),this.onMenuClose(),this.setState({focusedValue:null,isFocused:!1})};onOptionHover=e=>{if(this.blockOptionHover&&=!1,this.state.focusedOption===e)return;let t=this.getFocusableOptions().indexOf(e);this.setState({focusedOption:e,focusedOptionId:t>-1?this.getFocusedOptionId(e):null})};shouldHideSelectedOptions=()=>A(this.props);onValueInputFocus=e=>{e.preventDefault(),e.stopPropagation(),this.focus()};onKeyDown=e=>{let{isMulti:t,backspaceRemovesValue:n,escapeClearsValue:r,inputValue:i,isClearable:a,disabled:o,menuIsOpen:s,onKeyDown:c,tabSelectsValue:l,openMenuOnFocus:u}=this.props,{focusedOption:d,focusedValue:f,selectValue:p}=this.state;if(!o&&!(typeof c==`function`&&(c(e),e.defaultPrevented))){switch(this.blockOptionHover=!0,e.key){case`ArrowLeft`:if(!t||i)return;this.focusValue(`previous`);break;case`ArrowRight`:if(!t||i)return;this.focusValue(`next`);break;case`Delete`:case`Backspace`:if(i)return;if(f)this.removeValue(f);else{if(!n)return;t?this.popValue():a&&this.clearValue()}break;case`Tab`:if(this.isComposing||e.shiftKey||!s||!l||!d||u&&this.isOptionSelected(d,p))return;this.selectOption(d);break;case`Enter`:if(e.keyCode===229)break;if(f){this.removeValue(f);break}if(s){if(!d||this.isComposing)return;this.selectOption(d);break}this.openMenu(`first`);return;case`Escape`:s?(this.setState({inputIsHiddenAfterUpdate:!1}),this.onInputChange(``,{action:`menu-close`,prevInputValue:i}),this.onMenuClose()):a&&r&&this.clearValue();break;case` `:if(i)return;if(!s){this.openMenu(`first`);break}if(!d)return;this.selectOption(d);break;case`ArrowUp`:s?this.focusOption(`up`):this.openMenu(`last`);break;case`ArrowDown`:s?this.focusOption(`down`):this.openMenu(`first`);break;case`PageUp`:if(!s)return;this.focusOption(`pageup`);break;case`PageDown`:if(!s)return;this.focusOption(`pagedown`);break;case`Home`:if(!s)return;this.focusOption(`first`);break;case`End`:if(!s)return;this.focusOption(`last`);break;default:return}e.preventDefault()}};renderInput(){let{disabled:e,isSearchable:t,inputId:n,inputValue:i,tabIndex:a,form:s,menuIsOpen:c,required:l,placeholder:u,isMulti:d}=this.props,{Input:f}=this.getComponents(),{inputIsHidden:m,ariaSelection:h}=this.state,{commonProps:g}=this,_=n||this.getElementId(`input`),v={"aria-autocomplete":`list`,"aria-expanded":c,"aria-haspopup":!0,"aria-errormessage":this.props[`aria-errormessage`],"aria-invalid":this.props[`aria-invalid`],"aria-label":this.props[`aria-label`],"aria-labelledby":this.props[`aria-labelledby`],"aria-required":l,role:`combobox`,"aria-activedescendant":this.state.isAppleDevice?void 0:this.state.focusedOptionId||``,...c&&{"aria-controls":this.getElementId(`listbox`)},...!t&&{"aria-readonly":!0},...this.hasValue()?h?.action===`initial-input-focus`&&{"aria-describedby":this.getElementId(`live-region`)}:{"aria-describedby":this.getElementId(`placeholder`)}};return t?(0,p.jsx)(f,{...g,placeholder:d&&typeof u==`string`||!this.hasValue()&&typeof u==`string`?u:void 0,autoCapitalize:`none`,autoComplete:`off`,autoCorrect:`off`,id:_,innerRef:this.getInputRef,disabled:e,isHidden:m,onBlur:this.onInputBlur,onChange:this.handleInputChange,onFocus:this.onInputFocus,spellCheck:`false`,tabIndex:a,form:s,type:`text`,value:i,...v}):(0,p.jsx)(o.default,{id:_,innerRef:this.getInputRef,onBlur:this.onInputBlur,onChange:r.noop,onFocus:this.onInputFocus,disabled:e,tabIndex:a,inputMode:`none`,form:s,value:``,placeholder:d&&typeof u==`string`||!this.hasValue()&&typeof u==`string`?u:void 0,style:!d&&this.hasValue()?{width:`0px`}:{},...v})}renderPlaceholderOrValue(){let{MultiSelectOption:e,MultiSelectOptionContainer:t,MultiSelectOptionLabel:n,MultiSelectOptionRemove:r,MultiSelectSingleValue:i,MultiSelectCustomPlaceholder:a}=this.getComponents(),{commonProps:o}=this,{triggerShouldRenderValue:s,disabled:c,isMulti:l,inputValue:u,placeholder:d}=this.props,{selectValue:m,focusedValue:h,isFocused:g}=this.state;if((!this.hasValue()||!s)&&typeof d!=`string`)return u?null:(0,f.createElement)(a,{...o,key:`placeholder`,disabled:c,isFocused:g,innerProps:{id:this.getElementId(`placeholder`)}},d);if(l)return m.map((i,a)=>{let s=i===h,l=`${this.getOptionLabel(i)}-${this.getOptionValue(i)}`,u=this.isOptionDisabled(i),d=this.isOptionFixed(i);return(0,f.createElement)(e,{...o,components:{Container:t,Label:n,Remove:r},isFocused:s,disabled:c||u,isFixed:d,key:l,index:a,removeProps:{onClick:()=>this.removeValue(i),onTouchEnd:()=>this.removeValue(i),onMouseDown:e=>{e.preventDefault()}},data:i,innerProps:{ref:this.getMultiValueRef}},this.formatOptionLabel(i,`value`))});if(u)return null;let _=m[0];if(!_)return null;let v=this.isOptionDisabled(_);return(0,p.jsx)(i,{...o,data:_,disabled:c||v,children:this.formatOptionLabel(_,`value`)})}renderClearIndicator(){let{MultiSelectTriggerClearIndicator:e}=this.getComponents(),{commonProps:t}=this,{loading:n}=this.props,{isFocused:r}=this.state;if(!this.isClearable()||!e||!this.hasValue()||n)return null;let i={onMouseDown:this.onClearIndicatorMouseDown,"aria-hidden":!0};return(0,p.jsx)(e,{...t,innerProps:i,isFocused:r})}renderLoadingIndicator(){let{MultiSelectTriggerLoadingIndicator:e}=this.getComponents(),{commonProps:t}=this,{disabled:n,loading:r}=this.props,{isFocused:i}=this.state;if(!e||!r)return null;let a={"aria-hidden":!0};return(0,p.jsx)(e,{...t,innerProps:a,disabled:n,isFocused:i})}renderIndicatorSeparator(e){let{MultiSelectTriggerDropdownIndicator:t,MultiSelectTriggerSeparator:n}=this.getComponents(),{separator:r,separatorOnlyWithIndicator:i=!0}=this.props;if(r===!1||i&&!e||!t||!n)return null;let{commonProps:a}=this,{disabled:o}=this.props,{isFocused:s}=this.state;return(0,p.jsx)(n,{...a,disabled:o,isFocused:s})}renderDropdownIndicator(){let{MultiSelectTriggerDropdownIndicator:e}=this.getComponents();if(!e)return null;let{commonProps:t}=this,{disabled:n}=this.props,{isFocused:r}=this.state,i={onMouseDown:this.onDropdownIndicatorMouseDown,"aria-hidden":!0};return(0,p.jsx)(e,{...t,innerProps:i,disabled:n,isFocused:r})}renderMenu(){let{MultiSelectGroup:e,MultiSelectLabel:n,LoadingMessage:r,NoOptionsMessage:i,MultiSelectitem:a}=this.getComponents(),{commonProps:o}=this,{focusedOption:s}=this.state,{inputValue:c,loading:l,loadingMessage:m,dir:h,noOptionsMessage:g}=this.props,_=(e,t)=>{let{type:n,data:r,disabled:i,isSelected:c,label:l}=e,u=s===r,d=i?void 0:()=>this.onOptionHover(r),p=i?void 0:()=>this.selectOption(r),m=`${this.getElementId(`option`)}-${t}`,h={id:m,onClick:p,onMouseMove:d,onMouseOver:d,tabIndex:-1,role:`option`,"aria-selected":this.state.isAppleDevice?void 0:c};return(0,f.createElement)(a,{...o,innerProps:h,data:r,disabled:i,isSelected:c,key:m,label:l,type:n,isFocused:u,innerRef:u?this.getFocusedOptionRef:void 0},this.formatOptionLabel(e.data,`menu`))},v;if(this.hasOptions())v=this.getCategorizedOptions().map(t=>{if(t.type===`group`){let{data:r,options:i,index:a}=t,s=`${this.getElementId(`group`)}-${a}`,c=`${s}-heading`;return(0,f.createElement)(e,{...o,key:s,data:r,options:i.map(e=>e.data),MultiSelectLabel:n,multiSelectLabelProps:{id:c,data:t.data},label:this.formatGroupLabel(t.data)},t.options.map(e=>_(e,`${a}-${e.index}`)))}else if(t.type===`option`)return _(t,`${t.index}`)});else if(l){let e=m({inputValue:c});if(e===null)return null;v=(0,p.jsx)(r,{...o,children:e})}else{let e=g({inputValue:c});if(e===null)return null;v=(0,p.jsx)(i,{...o,children:e})}let{contentClassName:y,portal:b=!0,container:x,align:S=`start`,side:C,sideOffset:w=4,alignOffset:T,collisionPadding:E=10,avoidCollisions:D,sticky:O,hideWhenDetached:k,contentColor:A,radius:j}=this.props,M=(0,p.jsx)(t.Theme,{asChild:!0,accentColor:A,radius:j,children:(0,p.jsx)(u.Popover.Content,{dir:h,align:S,side:C,sideOffset:w,alignOffset:T,collisionPadding:E,avoidCollisions:D,sticky:O,hideWhenDetached:k,className:(0,d.default)(`rt-PopperContent`,`rt-MultiSelectContent`,y),style:{boxSizing:`border-box`,display:`flex`,flexDirection:`column`},onOpenAutoFocus:e=>e.preventDefault(),onCloseAutoFocus:e=>e.preventDefault(),onInteractOutside:e=>{let t=e.target;this.rootRef?.parentElement?.contains(t)&&e.preventDefault()},onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),this.focusInput()},children:(0,p.jsxs)(u.ScrollArea.Root,{type:`auto`,className:(0,d.default)(`rt-ScrollAreaRoot`),style:{maxHeight:`100%`},children:[(0,p.jsx)(u.ScrollArea.Viewport,{ref:this.getMenuListRef,className:(0,d.default)(`rt-ScrollAreaViewport`,`rt-MultiSelectViewport`),style:{position:`relative`,flex:1,overflowX:`hidden`,overflowY:`auto`},children:v}),(0,p.jsx)(u.ScrollArea.Scrollbar,{className:`rt-ScrollAreaScrollbar rt-r-size-1`,orientation:`vertical`,children:(0,p.jsx)(u.ScrollArea.Thumb,{className:`rt-ScrollAreaThumb`})})]})})});return b?(0,p.jsx)(u.Popover.Portal,{container:x,children:M}):M}renderFormField(){let{delimiter:e,disabled:t,isMulti:n,name:r,required:i}=this.props,{selectValue:a}=this.state;if(i&&!this.hasValue()&&!t)return(0,p.jsx)(s.default,{name:r,onFocus:this.onValueInputFocus});if(!(!r||t))return n?e?(0,p.jsx)(`input`,{name:r,type:`hidden`,value:a.map(e=>this.getOptionValue(e)).join(e)}):(0,p.jsx)(`div`,{children:a.length>0?a.map((e,t)=>(0,p.jsx)(`input`,{name:r,type:`hidden`,value:this.getOptionValue(e)},`i-${t}`)):(0,p.jsx)(`input`,{name:r,type:`hidden`,value:``})}):(0,p.jsx)(`input`,{name:r,type:`hidden`,value:a[0]?this.getOptionValue(a[0]):``})}renderLiveRegion(){let{commonProps:e}=this,{ariaSelection:t,focusedOption:n,focusedValue:r,isFocused:i,selectValue:o}=this.state,s=this.getFocusableOptions();return(0,p.jsx)(a.default,{...e,id:this.getElementId(`live-region`),ariaSelection:t,focusedOption:n,focusedValue:r,isFocused:i,selectValue:o,focusableOptions:s,isAppleDevice:this.state.isAppleDevice})}render(){let{MultiSelectInner:e,MultiSelectTriggerIndicatorsContainer:t,MultiSelectTrigger:n,MultiSelectValueContainer:r}=this.getComponents(),{className:i,id:a,disabled:o,menuIsOpen:s,color:c,radius:l}=this.props,{isFocused:d}=this.state,f=this.commonProps=this.getCommonProps(),m=this.renderClearIndicator(),h=this.renderLoadingIndicator();return(0,p.jsxs)(u.Popover.Root,{modal:!1,removeScroll:!0,onOpenChange:e=>{this.setState({isPopoverActuallyOpen:e}),e?this.props.onMenuOpen():this.props.onMenuClose()},children:[(0,p.jsxs)(n,{...f,className:i,innerProps:{id:a,onKeyDown:this.onKeyDown,ref:this.getRootRef,onMouseDown:this.onTriggerMouseDown,"data-accent-color":c,"data-radius":l},disabled:o,isFocused:d,menuIsOpen:s,children:[this.renderLiveRegion(),(0,p.jsxs)(e,{...f,innerProps:{},disabled:o,isFocused:d,menuIsOpen:s,children:[(0,p.jsxs)(r,{...f,disabled:o,children:[this.renderPlaceholderOrValue(),this.renderInput()]}),(0,p.jsxs)(t,{...f,disabled:o,children:[m,h,this.renderIndicatorSeparator(!!(m||h)),this.renderDropdownIndicator()]}),(0,p.jsx)(u.Popover.Trigger,{ref:this.getRootTriggerRef,tabIndex:-1,"aria-hidden":`true`,inert:!0,style:{position:`absolute`,opacity:0,pointerEvents:`none`,width:0,height:0,overflow:`hidden`,padding:0,margin:0,clipPath:`inset(50%)`,whiteSpace:`nowrap`,borderWidth:0}})]}),this.renderFormField()]}),this.renderMenu()]})}};exports.default=M;
|
|
@@ -81,8 +81,8 @@ export interface Props<IsMulti extends boolean> {
|
|
|
81
81
|
isClearable?: boolean;
|
|
82
82
|
/** Показывать разделитель между иконками управления. По умолчанию включён. */
|
|
83
83
|
separator?: boolean;
|
|
84
|
-
/** Показывать разделитель только при наличии
|
|
85
|
-
|
|
84
|
+
/** Показывать разделитель только при наличии индикатора (например, clear или loading). По умолчанию включено. */
|
|
85
|
+
separatorOnlyWithIndicator?: boolean;
|
|
86
86
|
/** Отключён ли select */
|
|
87
87
|
disabled: boolean;
|
|
88
88
|
/** Находится ли select в состоянии загрузки (async) */
|
|
@@ -448,7 +448,7 @@ export default class Select<IsMulti extends boolean = false> extends Component<M
|
|
|
448
448
|
renderPlaceholderOrValue(): JSX.Element | JSX.Element[] | null;
|
|
449
449
|
renderClearIndicator(): JSX.Element | null;
|
|
450
450
|
renderLoadingIndicator(): JSX.Element | null;
|
|
451
|
-
renderIndicatorSeparator(
|
|
451
|
+
renderIndicatorSeparator(hasIndicator: boolean): JSX.Element | null;
|
|
452
452
|
renderDropdownIndicator(): JSX.Element | null;
|
|
453
453
|
renderMenu(): JSX.Element | null;
|
|
454
454
|
renderFormField(): JSX.Element | undefined;
|
|
@@ -81,8 +81,8 @@ export interface Props<IsMulti extends boolean> {
|
|
|
81
81
|
isClearable?: boolean;
|
|
82
82
|
/** Показывать разделитель между иконками управления. По умолчанию включён. */
|
|
83
83
|
separator?: boolean;
|
|
84
|
-
/** Показывать разделитель только при наличии
|
|
85
|
-
|
|
84
|
+
/** Показывать разделитель только при наличии индикатора (например, clear или loading). По умолчанию включено. */
|
|
85
|
+
separatorOnlyWithIndicator?: boolean;
|
|
86
86
|
/** Отключён ли select */
|
|
87
87
|
disabled: boolean;
|
|
88
88
|
/** Находится ли select в состоянии загрузки (async) */
|
|
@@ -448,7 +448,7 @@ export default class Select<IsMulti extends boolean = false> extends Component<M
|
|
|
448
448
|
renderPlaceholderOrValue(): JSX.Element | JSX.Element[] | null;
|
|
449
449
|
renderClearIndicator(): JSX.Element | null;
|
|
450
450
|
renderLoadingIndicator(): JSX.Element | null;
|
|
451
|
-
renderIndicatorSeparator(
|
|
451
|
+
renderIndicatorSeparator(hasIndicator: boolean): JSX.Element | null;
|
|
452
452
|
renderDropdownIndicator(): JSX.Element | null;
|
|
453
453
|
renderMenu(): JSX.Element | null;
|
|
454
454
|
renderFormField(): JSX.Element | undefined;
|
|
@@ -699,7 +699,7 @@ var W = (e) => {
|
|
|
699
699
|
});
|
|
700
700
|
}
|
|
701
701
|
renderIndicatorSeparator(e) {
|
|
702
|
-
let { MultiSelectTriggerDropdownIndicator: t, MultiSelectTriggerSeparator: n } = this.getComponents(), { separator: r,
|
|
702
|
+
let { MultiSelectTriggerDropdownIndicator: t, MultiSelectTriggerSeparator: n } = this.getComponents(), { separator: r, separatorOnlyWithIndicator: i = !0 } = this.props;
|
|
703
703
|
if (r === !1 || i && !e || !t || !n) return null;
|
|
704
704
|
let { commonProps: a } = this, { disabled: o } = this.props, { isFocused: s } = this.state;
|
|
705
705
|
return /* @__PURE__ */ E(n, {
|
|
@@ -873,7 +873,7 @@ var W = (e) => {
|
|
|
873
873
|
});
|
|
874
874
|
}
|
|
875
875
|
render() {
|
|
876
|
-
let { MultiSelectInner: e, MultiSelectTriggerIndicatorsContainer: t, MultiSelectTrigger: n, MultiSelectValueContainer: r } = this.getComponents(), { className: i, id: a, disabled: o, menuIsOpen: s, color: c, radius: l } = this.props, { isFocused: u } = this.state, d = this.commonProps = this.getCommonProps(), f = this.renderClearIndicator();
|
|
876
|
+
let { MultiSelectInner: e, MultiSelectTriggerIndicatorsContainer: t, MultiSelectTrigger: n, MultiSelectValueContainer: r } = this.getComponents(), { className: i, id: a, disabled: o, menuIsOpen: s, color: c, radius: l } = this.props, { isFocused: u } = this.state, d = this.commonProps = this.getCommonProps(), f = this.renderClearIndicator(), p = this.renderLoadingIndicator();
|
|
877
877
|
return /* @__PURE__ */ D(x.Root, {
|
|
878
878
|
modal: !1,
|
|
879
879
|
removeScroll: !0,
|
|
@@ -913,8 +913,8 @@ var W = (e) => {
|
|
|
913
913
|
disabled: o,
|
|
914
914
|
children: [
|
|
915
915
|
f,
|
|
916
|
-
|
|
917
|
-
this.renderIndicatorSeparator(f),
|
|
916
|
+
p,
|
|
917
|
+
this.renderIndicatorSeparator(!!(f || p)),
|
|
918
918
|
this.renderDropdownIndicator()
|
|
919
919
|
]
|
|
920
920
|
}),
|
package/dist/styles.css
CHANGED
|
@@ -40206,7 +40206,7 @@
|
|
|
40206
40206
|
height: var(--space-4);
|
|
40207
40207
|
border-radius: 100%;
|
|
40208
40208
|
|
|
40209
|
-
@media (
|
|
40209
|
+
@media (width >= 768px) {
|
|
40210
40210
|
width: var(--space-5);
|
|
40211
40211
|
height: var(--space-5);
|
|
40212
40212
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolid-ui/themes",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Темы и стилизованные компоненты дизайн-системы Bolid UI для React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bolid-ui",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"classnames": "^2.5.1",
|
|
70
70
|
"react-hook-form": "7.76.1",
|
|
71
|
-
"@bolid-ui/
|
|
72
|
-
"@bolid-ui/
|
|
71
|
+
"@bolid-ui/primitives": "0.2.0",
|
|
72
|
+
"@bolid-ui/colors": "0.1.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"react": "^19.0.0",
|