2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.listbox=function(t,e,n,o,r,i,l,a){"use strict";function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var p=s(e);function u(){return u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},u.apply(this,arguments)}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function f(t){if(Array.isArray(t))return c(t)}function h(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function d(t,e){if(t){if("string"==typeof t)return c(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(t,e):void 0}}function v(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function y(t){return f(t)||h(t)||d(t)||v()}function b(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function m(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function O(t,e,n){return e&&m(t.prototype,e),n&&m(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function g(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function k(t,e){return k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},k(t,e)}function E(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&k(t,e)}function S(t){return S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},S(t)}function j(t,e){if(e&&("object"===S(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return g(t)}function C(t){return C=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},C(t)}function w(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function x(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}var D=function(t){E(l,t);var e,n,i=(e=l,n=x(),function(){var t,o=C(e);if(n){var r=C(this).constructor;t=Reflect.construct(o,arguments,r)}else t=o.apply(this,arguments);return j(this,t)});function l(t){var e;return b(this,l),(e=i.call(this,t)).onClick=e.onClick.bind(g(e)),e.onTouchEnd=e.onTouchEnd.bind(g(e)),e.onKeyDown=e.onKeyDown.bind(g(e)),e}return O(l,[{key:"onClick",value:function(t){this.props.onClick&&this.props.onClick({originalEvent:t,option:this.props.option}),t.preventDefault()}},{key:"onTouchEnd",value:function(t){this.props.onTouchEnd&&this.props.onTouchEnd({originalEvent:t,option:this.props.option})}},{key:"onKeyDown",value:function(t){var e=t.currentTarget;switch(t.which){case 40:var n=this.findNextItem(e);n&&n.focus(),t.preventDefault();break;case 38:var o=this.findPrevItem(e);o&&o.focus(),t.preventDefault();break;case 13:this.onClick(t),t.preventDefault()}}},{key:"findNextItem",value:function(t){var e=t.nextElementSibling;return e?o.DomHandler.hasClass(e,"p-disabled")||o.DomHandler.hasClass(e,"p-listbox-item-group")?this.findNextItem(e):e:null}},{key:"findPrevItem",value:function(t){var e=t.previousElementSibling;return e?o.DomHandler.hasClass(e,"p-disabled")||o.DomHandler.hasClass(e,"p-listbox-item-group")?this.findPrevItem(e):e:null}},{key:"render",value:function(){var t=o.classNames("p-listbox-item",{"p-highlight":this.props.selected,"p-disabled":this.props.disabled},this.props.option.className),e=this.props.template?o.ObjectUtils.getJSXElement(this.props.template,this.props.option):this.props.label;return p.default.createElement("li",{className:t,onClick:this.onClick,onTouchEnd:this.onTouchEnd,onKeyDown:this.onKeyDown,tabIndex:this.props.tabIndex,"aria-label":this.props.label,key:this.props.label,role:"option","aria-selected":this.props.selected},e,p.default.createElement(r.Ripple,null))}}]),l}(e.Component);function T(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}w(D,"defaultProps",{option:null,label:null,selected:!1,disabled:!1,tabIndex:null,onClick:null,onTouchEnd:null,template:null});var F=function(t){E(r,t);var e,n,o=(e=r,n=T(),function(){var t,o=C(e);if(n){var r=C(this).constructor;t=Reflect.construct(o,arguments,r)}else t=o.apply(this,arguments);return j(this,t)});function r(t){var e;return b(this,r),(e=o.call(this,t)).onFilter=e.onFilter.bind(g(e)),e}return O(r,[{key:"onFilter",value:function(t){this.props.onFilter&&this.props.onFilter({originalEvent:t,value:t.target.value})}},{key:"render",value:function(){return p.default.createElement("div",{className:"p-listbox-header"},p.default.createElement("div",{className:"p-listbox-filter-container"},p.default.createElement(i.InputText,{type:"text",value:this.props.filter,onChange:this.onFilter,className:"p-listbox-filter",disabled:this.props.disabled,placeholder:this.props.filterPlaceholder}),p.default.createElement("span",{className:"p-listbox-filter-icon pi pi-search"})))}}]),r}(e.Component);function L(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=P(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,l=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return l=t.done,t},e:function(t){a=!0,i=t},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw i}}}}function P(t,e){if(t){if("string"==typeof t)return V(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?V(t,e):void 0}}function V(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function I(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function R(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?I(Object(n),!0).forEach((function(e){w(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):I(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function K(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}w(F,"defaultProps",{filter:null,filterPlaceholder:null,disabled:!1,onFilter:null});var N=function(t){E(s,t);var e,r,i=(e=s,r=K(),function(){var t,n=C(e);if(r){var o=C(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return j(this,t)});function s(t){var e;return b(this,s),(e=i.call(this,t)).state={},e.props.onFilterValueChange||(e.state.filterValue=""),e.onFilter=e.onFilter.bind(g(e)),e.onOptionSelect=e.onOptionSelect.bind(g(e)),e.onOptionTouchEnd=e.onOptionTouchEnd.bind(g(e)),e}return O(s,[{key:"componentDidMount",value:function(){this.props.tooltip&&this.renderTooltip()}},{key:"componentDidUpdate",value:function(t){t.tooltip===this.props.tooltip&&t.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(R({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip())}},{key:"componentWillUnmount",value:function(){this.tooltip&&(this.tooltip.destroy(),this.tooltip=null)}},{key:"renderTooltip",value:function(){this.tooltip=l.tip({target:this.element,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"getFilterValue",value:function(){return(this.props.onFilterValueChange?this.props.filterValue:this.state.filterValue)||""}},{key:"onOptionSelect",value:function(t){var e=t.option;this.props.disabled||this.isOptionDisabled(e)||(this.props.multiple?this.onOptionSelectMultiple(t.originalEvent,e):this.onOptionSelectSingle(t.originalEvent,e),this.optionTouched=!1)}},{key:"onOptionTouchEnd",value:function(){this.props.disabled||(this.optionTouched=!0)}},{key:"onOptionSelectSingle",value:function(t,e){var n=this.isSelected(e),o=!1,r=null;!this.optionTouched&&this.props.metaKeySelection?n?(t.metaKey||t.ctrlKey)&&(r=null,o=!0):(r=this.getOptionValue(e),o=!0):(r=n?null:this.getOptionValue(e),o=!0);o&&this.updateModel(t,r)}},{key:"onOptionSelectMultiple",value:function(t,e){var n=this.isSelected(e),o=!1,r=null;if(!this.optionTouched&&this.props.metaKeySelection){var i=t.metaKey||t.ctrlKey;n?(r=i?this.removeOption(e):[this.getOptionValue(e)],o=!0):(r=[].concat(y(r=i&&this.props.value||[]),[this.getOptionValue(e)]),o=!0)}else r=n?this.removeOption(e):[].concat(y(this.props.value||[]),[this.getOptionValue(e)]),o=!0;o&&this.props.onChange({originalEvent:t,value:r,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:r}})}},{key:"onFilter",value:function(t){var e=t.value;this.props.onFilterValueChange?this.props.onFilterValueChange({originalEvent:t.originalEvent,value:e}):this.setState({filterValue:e})}},{key:"updateModel",value:function(t,e){this.props.onChange&&this.props.onChange({originalEvent:t,value:e,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:e}})}},{key:"removeOption",value:function(t){var e=this;return this.props.value.filter((function(n){return!o.ObjectUtils.equals(n,e.getOptionValue(t),e.props.dataKey)}))}},{key:"isSelected",value:function(t){var e=!1,n=this.getOptionValue(t);if(this.props.multiple){if(this.props.value){var r,i=L(this.props.value);try{for(i.s();!(r=i.n()).done;){if(o.ObjectUtils.equals(r.value,n,this.props.dataKey)){e=!0;break}}}catch(t){i.e(t)}finally{i.f()}}}else e=o.ObjectUtils.equals(this.props.value,n,this.props.dataKey);return e}},{key:"filter",value:function(t){var e=this.getFilterValue().trim().toLocaleLowerCase(this.props.filterLocale);return this.getOptionLabel(t).toLocaleLowerCase(this.props.filterLocale).indexOf(e)>-1}},{key:"hasFilter",value:function(){var t=this.getFilterValue();return t&&t.trim().length>0}},{key:"getOptionLabel",value:function(t){return this.props.optionLabel?o.ObjectUtils.resolveFieldData(t,this.props.optionLabel):t&&void 0!==t.label?t.label:t}},{key:"getOptionValue",value:function(t){return this.props.optionValue?o.ObjectUtils.resolveFieldData(t,this.props.optionValue):t&&void 0!==t.value?t.value:t}},{key:"getOptionRenderKey",value:function(t){return this.props.dataKey?o.ObjectUtils.resolveFieldData(t,this.props.dataKey):this.getOptionLabel(t)}},{key:"isOptionDisabled",value:function(t){return this.props.optionDisabled?o.ObjectUtils.isFunction(this.props.optionDisabled)?this.props.optionDisabled(t):o.ObjectUtils.resolveFieldData(t,this.props.optionDisabled):!(!t||void 0===t.disabled)&&t.disabled}},{key:"getOptionGroupRenderKey",value:function(t){return o.ObjectUtils.resolveFieldData(t,this.props.optionGroupLabel)}},{key:"getOptionGroupLabel",value:function(t){return o.ObjectUtils.resolveFieldData(t,this.props.optionGroupLabel)}},{key:"getOptionGroupChildren",value:function(t){return o.ObjectUtils.resolveFieldData(t,this.props.optionGroupChildren)}},{key:"getVisibleOptions",value:function(){if(this.hasFilter()){var t=this.getFilterValue().trim().toLocaleLowerCase(this.props.filterLocale),e=this.props.filterBy?this.props.filterBy.split(","):[this.props.optionLabel||"label"];if(this.props.optionGroupLabel){var o,r=[],i=L(this.props.options);try{for(i.s();!(o=i.n()).done;){var l=o.value,a=n.FilterService.filter(this.getOptionGroupChildren(l),e,t,this.props.filterMatchMode,this.props.filterLocale);a&&a.length&&r.push(R(R({},l),{items:a}))}}catch(t){i.e(t)}finally{i.f()}return r}return n.FilterService.filter(this.props.options,e,t,this.props.filterMatchMode,this.props.filterLocale)}return this.props.options}},{key:"renderGroupChildren",value:function(t){var e=this;return this.getOptionGroupChildren(t).map((function(t,n){var o=e.getOptionLabel(t),r=n+"_"+e.getOptionRenderKey(t),i=e.isOptionDisabled(t),l=i?null:e.props.tabIndex||0;return p.default.createElement(D,{key:r,label:o,option:t,template:e.props.itemTemplate,selected:e.isSelected(t),onClick:e.onOptionSelect,onTouchEnd:e.onOptionTouchEnd,tabIndex:l,disabled:i})}))}},{key:"renderItem",value:function(t,e){if(this.props.optionGroupLabel){var n=this.props.optionGroupTemplate?o.ObjectUtils.getJSXElement(this.props.optionGroupTemplate,t,e):this.getOptionGroupLabel(t),r=this.renderGroupChildren(t),i=e+"_"+this.getOptionGroupRenderKey(t);return p.default.createElement(p.default.Fragment,{key:i},p.default.createElement("li",{className:"p-listbox-item-group"},n),r)}var l=this.getOptionLabel(t),a=e+"_"+this.getOptionRenderKey(t),s=this.isOptionDisabled(t),u=s?null:this.props.tabIndex||0;return p.default.createElement(D,{key:a,label:l,option:t,template:this.props.itemTemplate,selected:this.isSelected(t),onClick:this.onOptionSelect,onTouchEnd:this.onOptionTouchEnd,tabIndex:u,disabled:s})}},{key:"renderItems",value:function(t){var e=this;return t&&t.length?t.map((function(t,n){return e.renderItem(t,n)})):null}},{key:"renderList",value:function(t){var e=this;if(this.props.virtualScrollerOptions){var n=R(R({},this.props.virtualScrollerOptions),{items:t,onLazyLoad:function(t){return e.props.virtualScrollerOptions.onLazyLoad(R(R({},t),{filter:e.getFilterValue()}))},itemTemplate:function(t,n){return t&&e.renderItem(t,n.index)},contentTemplate:function(t){var n=o.classNames("p-listbox-list",t.className);return p.default.createElement("ul",{ref:t.contentRef,className:n,role:"listbox","aria-multiselectable":e.props.multiple},t.children)}});return p.default.createElement(a.VirtualScroller,u({ref:function(t){return e.virtualScrollerRef=t}},n))}var r=this.renderItems(t);return p.default.createElement("ul",{className:"p-listbox-list",role:"listbox","aria-multiselectable":this.props.multiple},r)}},{key:"render",value:function(){var t,e=this,n=o.classNames("p-listbox p-component",{"p-disabled":this.props.disabled},this.props.className),r=o.classNames("p-listbox-list-wrapper",this.props.listClassName),i=this.getVisibleOptions(),l=this.renderList(i);return this.props.filter&&(t=p.default.createElement(F,{filter:this.getFilterValue(),onFilter:this.onFilter,disabled:this.props.disabled,filterPlaceholder:this.props.filterPlaceholder})),p.default.createElement("div",{ref:function(t){return e.element=t},id:this.props.id,className:n,style:this.props.style},t,p.default.createElement("div",{ref:function(t){return e.wrapper=t},className:r,style:this.props.listStyle},l))}}]),s}(e.Component);return w(N,"defaultProps",{id:null,value:null,options:null,optionLabel:null,optionValue:null,optionDisabled:null,optionGroupLabel:null,optionGroupChildren:null,optionGroupTemplate:null,itemTemplate:null,style:null,listStyle:null,listClassName:null,className:null,virtualScrollerOptions:null,disabled:null,dataKey:null,multiple:!1,metaKeySelection:!1,filter:!1,filterBy:null,filterValue:null,filterMatchMode:"contains",filterPlaceholder:null,filterLocale:void 0,tabIndex:0,tooltip:null,tooltipOptions:null,ariaLabelledBy:null,onChange:null,onFilterValueChange:null}),t.ListBox=N,Object.defineProperty(t,"__esModule",{value:!0}),t}({},React,primereact.api,primereact.utils,primereact.ripple,primereact.inputtext,primereact.tooltip,primereact.virtualscroller);
|