2 lines
19 KiB
JavaScript
2 lines
19 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.treeselect=function(e,t,n,r,i,l,o,s,a){"use strict";function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=c(t),u=c(r);function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function f(e,t,n){return t&&d(e.prototype,t),n&&d(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function y(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,t){return v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},v(e,t)}function m(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&v(e,t)}function b(e){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b(e)}function g(e,t){if(t&&("object"===b(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return y(e)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function E(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(){return O=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},O.apply(this,arguments)}function S(){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(e){return!1}}var C=function(e){m(l,e);var t,r,i=(t=l,r=S(),function(){var e,n=k(t);if(r){var i=k(this).constructor;e=Reflect.construct(n,arguments,i)}else e=n.apply(this,arguments);return g(this,e)});function l(){return h(this,l),i.apply(this,arguments)}return f(l,[{key:"renderElement",value:function(){var e=n.classNames("p-treeselect-panel p-component",this.props.panelClassName);return p.default.createElement(o.CSSTransition,{nodeRef:this.props.forwardRef,classNames:"p-connected-overlay",in:this.props.in,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.props.onEnter,onEntering:this.props.onEntering,onEntered:this.props.onEntered,onExit:this.props.onExit,onExited:this.props.onExited},p.default.createElement("div",{ref:this.props.forwardRef,className:e,style:this.props.panelStyle,onClick:this.props.onClick},this.props.header,p.default.createElement("div",{className:"p-treeselect-items-wrapper",style:{maxHeight:this.props.scrollHeight||"auto"}},this.props.children),this.props.footer))}},{key:"render",value:function(){var e=this.renderElement();return p.default.createElement(s.Portal,{element:e,appendTo:this.props.appendTo})}}]),l}(t.Component),w=p.default.forwardRef((function(e,t){return p.default.createElement(C,O({forwardRef:t},e))}));function N(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=x(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}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 l,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,l=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw l}}}}function x(e,t){if(e){if("string"==typeof e)return I(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?I(e,t):void 0}}function I(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function L(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function V(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?L(Object(n),!0).forEach((function(t){E(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):L(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function j(){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(e){return!1}}var F=function(e){m(d,e);var o,s,c=(o=d,s=j(),function(){var e,t=k(o);if(s){var n=k(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return g(this,e)});function d(e){var n;return h(this,d),(n=c.call(this,e)).state={focused:!1,overlayVisible:!1,expandedKeys:{}},n.props.onFilterValueChange||(n.state.filterValue=""),n.onClick=n.onClick.bind(y(n)),n.onInputFocus=n.onInputFocus.bind(y(n)),n.onInputBlur=n.onInputBlur.bind(y(n)),n.onInputKeyDown=n.onInputKeyDown.bind(y(n)),n.onFilterInputChange=n.onFilterInputChange.bind(y(n)),n.onFilterInputKeyDown=n.onFilterInputKeyDown.bind(y(n)),n.onOverlayClick=n.onOverlayClick.bind(y(n)),n.onOverlayEnter=n.onOverlayEnter.bind(y(n)),n.onOverlayEntered=n.onOverlayEntered.bind(y(n)),n.onOverlayExit=n.onOverlayExit.bind(y(n)),n.onOverlayExited=n.onOverlayExited.bind(y(n)),n.onSelectionChange=n.onSelectionChange.bind(y(n)),n.onNodeSelect=n.onNodeSelect.bind(y(n)),n.onNodeUnselect=n.onNodeUnselect.bind(y(n)),n.onNodeToggle=n.onNodeToggle.bind(y(n)),n.onFilterValueChange=n.onFilterValueChange.bind(y(n)),n.hide=n.hide.bind(y(n)),n.show=n.show.bind(y(n)),n.overlayRef=t.createRef(),n}return f(d,[{key:"getFilterValue",value:function(){return this.props.onFilterValueChange?this.props.filterValue:this.state.filterValue}},{key:"getSelectedNodes",value:function(){var e=[];if(n.ObjectUtils.isNotEmpty(this.props.value)&&this.props.options){var t="single"===this.props.selectionMode?E({},"".concat(this.props.value),!0):V({},this.props.value);this.findSelectedNodes(null,t,e)}return e}},{key:"getLabel",value:function(){var e=this.getSelectedNodes();return e.length?e.map((function(e){return e.label})).join(", "):this.props.placeholder}},{key:"isValueEmpty",value:function(){return!this.props.value||0===Object.keys(this.props.value).length}},{key:"hasNoOptions",value:function(){return!this.props.options||0===this.props.options.length}},{key:"show",value:function(){this.setState({overlayVisible:!0})}},{key:"hide",value:function(){this.setState({overlayVisible:!1})}},{key:"onInputFocus",value:function(){this.setState({focused:!0})}},{key:"onInputBlur",value:function(){this.setState({focused:!1})}},{key:"onClick",value:function(e){this.props.disabled||this.overlayRef&&this.overlayRef.current&&this.overlayRef.current.contains(e.target)||n.DomHandler.hasClass(e.target,"p-treeselect-close")||(this.focusInput.focus(),this.state.overlayVisible?this.hide():this.show())}},{key:"onSelectionChange",value:function(e){this.props.onChange&&(this.selfChange=!0,this.props.onChange({originalEvent:e.originalEvent,value:e.value,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:e.value}}))}},{key:"onNodeSelect",value:function(e){this.props.onNodeSelect&&this.props.onNodeSelect(e),"single"===this.props.selectionMode&&this.hide()}},{key:"onNodeUnselect",value:function(e){this.props.onNodeUnselect&&this.props.onNodeUnselect(e)}},{key:"onNodeToggle",value:function(e){this.setState({expandedKeys:e.value})}},{key:"onFilterValueChange",value:function(e){this.setState({filterValue:e.value})}},{key:"onOverlayClick",value:function(e){i.OverlayService.emit("overlay-click",{originalEvent:e,target:this.container})}},{key:"onInputKeyDown",value:function(e){switch(e.which){case 40:!this.state.overlayVisible&&e.altKey&&this.show();break;case 32:this.state.overlayVisible||(this.show(),e.preventDefault());break;case 13:case 27:this.state.overlayVisible&&(this.hide(),e.preventDefault());break;case 9:this.hide()}}},{key:"onFilterInputKeyDown",value:function(e){13===e.which&&e.preventDefault()}},{key:"onFilterInputChange",value:function(e){var t=e.target.value;this.props.onFilterValueChange?this.props.onFilterValueChange({originalEvent:e,value:t}):this.setState({filterValue:t})}},{key:"resetFilter",value:function(){this.setState({filterValue:""})}},{key:"onOverlayEnter",value:function(){n.ZIndexUtils.set("overlay",this.overlayRef.current,u.default.autoZIndex,u.default.zIndex.overlay),this.alignOverlay(),this.scrollInView()}},{key:"onOverlayEntered",value:function(){this.bindDocumentClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.props.filter&&this.props.filterInputAutoFocus&&this.filterInput.focus(),this.props.onShow&&this.props.onShow()}},{key:"onOverlayExit",value:function(){this.unbindDocumentClickListener(),this.unbindScrollListener(),this.unbindResizeListener()}},{key:"onOverlayExited",value:function(){this.props.filter&&this.props.resetFilterOnHide&&this.resetFilter(),n.ZIndexUtils.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"alignOverlay",value:function(){n.DomHandler.alignOverlay(this.overlayRef.current,this.trigger.parentElement,this.props.appendTo||u.default.appendTo)}},{key:"scrollInView",value:function(){var e=n.DomHandler.findSingle(this.overlayRef.current,".p-treenode-content.p-highlight");e&&e.scrollIntoView({block:"nearest",inline:"start"})}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.state.overlayVisible&&e.isOutsideClicked(t)&&e.hide()},document.addEventListener("click",this.documentClickListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new n.ConnectedOverlayScrollHandler(this.container,(function(){e.state.overlayVisible&&e.hide()}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"bindResizeListener",value:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.state.overlayVisible&&!n.DomHandler.isTouchDevice()&&e.hide()},window.addEventListener("resize",this.resizeListener))}},{key:"unbindResizeListener",value:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)}},{key:"isOutsideClicked",value:function(e){return this.container&&!(this.container.isSameNode(e.target)||this.container.contains(e.target)||this.overlayRef&&this.overlayRef.current.contains(e.target))}},{key:"findSelectedNodes",value:function(e,t,n){if(e){if(this.isSelected(e,t)&&(n.push(e),delete t[e.key]),Object.keys(t).length&&e.children){var r,i=N(e.children);try{for(i.s();!(r=i.n()).done;){this.findSelectedNodes(r.value,t,n)}}catch(e){i.e(e)}finally{i.f()}}}else{var l,o=N(this.props.options);try{for(o.s();!(l=o.n()).done;){this.findSelectedNodes(l.value,t,n)}}catch(e){o.e(e)}finally{o.f()}}}},{key:"isSelected",value:function(e,t){return"checkbox"===this.props.selectionMode?t[e.key]&&t[e.key].checked:t[e.key]}},{key:"updateTreeState",value:function(){var e="single"===this.props.selectionMode?E({},"".concat(this.props.value),!0):V({},this.props.value);this.setState({expandedKeys:{}}),e&&this.props.options&&this.updateTreeBranchState(null,null,e)}},{key:"updateTreeBranchState",value:function(e,t,n){if(e){if(this.isSelected(e,n)&&(this.expandPath(t),delete n[e.key]),Object.keys(n).length&&e.children){var r,i=N(e.children);try{for(i.s();!(r=i.n()).done;){var l=r.value;t.push(e.key),this.updateTreeBranchState(l,t,n)}}catch(e){i.e(e)}finally{i.f()}}}else{var o,s=N(this.props.options);try{for(s.s();!(o=s.n()).done;){this.updateTreeBranchState(o.value,[],n)}}catch(e){s.e(e)}finally{s.f()}}}},{key:"expandPath",value:function(e){if(e.length>0){var t,n=V({},this.state.expandedKeys||{}),r=N(e);try{for(r.s();!(t=r.n()).done;){n[t.value]=!0}}catch(e){r.e(e)}finally{r.f()}this.setState({expandedKeys:n})}}},{key:"componentDidMount",value:function(){this.updateTreeState()}},{key:"componentDidUpdate",value:function(e,t){this.state.overlayVisible&&((this.props.filter||t.expandedKeys!==this.state.expandedKeys)&&this.alignOverlay(),e.value!==this.props.value&&(this.selfChange||this.updateTreeState(),this.scrollInView(),this.selfChange=!1)),e.options!==this.props.options&&this.updateTreeState()}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),n.ZIndexUtils.clear(this.overlayRef.current)}},{key:"renderKeyboardHelper",value:function(){var e=this;return p.default.createElement("div",{className:"p-hidden-accessible"},p.default.createElement("input",{ref:function(t){return e.focusInput=t},role:"listbox",id:this.props.inputId,type:"text",readOnly:!0,"aria-haspopup":"true","aria-expanded":this.state.overlayVisible,onFocus:this.onInputFocus,onBlur:this.onInputBlur,onKeyDown:this.onInputKeyDown,disabled:this.props.disabled,tabIndex:this.props.tabIndex,"aria-label":this.props.ariaLabel,"aria-labelledby":this.props.ariaLabelledBy}))}},{key:"renderLabel",value:function(e){var t=this.isValueEmpty(),r=n.classNames("p-treeselect-label",{"p-placeholder":this.getLabel()===this.props.placeholder,"p-treeselect-label-empty":!this.props.placeholder&&t}),i=null;if(this.props.valueTemplate)i=n.ObjectUtils.getJSXElement(this.props.valueTemplate,e,this.props);else if("comma"===this.props.display)i=this.getLabel()||"empty";else if("chip"===this.props.display){var l=this.getSelectedNodes();i=p.default.createElement(p.default.Fragment,null,l&&l.map((function(e,t){return p.default.createElement("div",{className:"p-treeselect-token",key:"".concat(e.key,"_").concat(t)},p.default.createElement("span",{className:"p-treeselect-token-label"},e.label))})),t&&(this.props.placeholder||"empty"))}return p.default.createElement("div",{className:"p-treeselect-label-container"},p.default.createElement("div",{className:r},i))}},{key:"renderDropdownIcon",value:function(){var e=this,t=n.classNames("p-treeselect-trigger-icon p-clickable",this.props.dropdownIcon);return p.default.createElement("div",{ref:function(t){return e.trigger=t},className:"p-treeselect-trigger",role:"button","aria-haspopup":"listbox","aria-expanded":this.state.overlayVisible},p.default.createElement("span",{className:t}))}},{key:"renderContent",value:function(){var e=this.getFilterValue();return p.default.createElement(p.default.Fragment,null,p.default.createElement(l.Tree,{value:this.props.options,selectionMode:this.props.selectionMode,selectionKeys:this.props.value,metaKeySelection:this.props.metaKeySelection,onSelectionChange:this.onSelectionChange,onSelect:this.onNodeSelect,onUnselect:this.onNodeUnselect,expandedKeys:this.state.expandedKeys,onToggle:this.onNodeToggle,onExpand:this.props.onNodeExpand,onCollapse:this.props.onNodeCollapse,filter:this.props.filter,filterValue:e,filterBy:this.props.filterBy,filterMode:this.props.filterMode,filterPlaceholder:this.props.filterPlaceholder,filterLocale:this.props.filterLocale,showHeader:!1,onFilterValueChange:this.onFilterValueChange}),this.hasNoOptions()&&p.default.createElement("div",{className:"p-treeselect-empty-message"},this.props.emptyMessage||r.localeOption("emptyMessage")))}},{key:"renderFilterElement",value:function(){var e=this;if(this.props.filter){var t=this.getFilterValue();return t=n.ObjectUtils.isNotEmpty(t)?t:"",p.default.createElement("div",{className:"p-treeselect-filter-container"},p.default.createElement("input",{ref:function(t){return e.filterInput=t},type:"text",value:t,autoComplete:"off",className:"p-treeselect-filter p-inputtext p-component",placeholder:this.props.filterPlaceholder,onKeyDown:this.onFilterInputKeyDown,onChange:this.onFilterInputChange,disabled:this.props.disabled}),p.default.createElement("span",{className:"p-treeselect-filter-icon pi pi-search"}))}return null}},{key:"renderHeader",value:function(){var e=this.renderFilterElement(),t=p.default.createElement("button",{type:"button",className:"p-treeselect-close p-link",onClick:this.hide},p.default.createElement("span",{className:"p-treeselect-close-icon pi pi-times"}),p.default.createElement(a.Ripple,null)),r=p.default.createElement("div",{className:"p-treeselect-header"},e,t);return this.props.header?n.ObjectUtils.getJSXElement(this.props.header,{className:"p-treeselect-header",filterElement:e,closeElement:t,closeElementClassName:"p-treeselect-close p-link",closeIconClassName:"p-treeselect-close-icon pi pi-times",onCloseClick:this.hide,element:r,props:this.props}):r}},{key:"render",value:function(){var e=this,t=n.classNames("p-treeselect p-component p-inputwrapper",{"p-treeselect-chip":"chip"===this.props.display,"p-disabled":this.props.disabled,"p-focus":this.state.focused,"p-inputwrapper-filled":!this.isValueEmpty(),"p-inputwrapper-focus":this.state.focused||this.state.overlayVisible},this.props.className),r=this.getSelectedNodes(),i=this.renderKeyboardHelper(),l=this.renderLabel(r),o=this.renderDropdownIcon(),s=this.renderContent(),a=this.renderHeader(),c=n.ObjectUtils.getJSXElement(this.props.footer,this.props);return p.default.createElement("div",{id:this.props.id,ref:function(t){return e.container=t},className:t,style:this.props.style,onClick:this.onClick},i,l,o,p.default.createElement(w,{ref:this.overlayRef,appendTo:this.props.appendTo,panelStyle:this.props.panelStyle,panelClassName:this.props.panelClassName,scrollHeight:this.props.scrollHeight,onClick:this.onOverlayClick,header:a,footer:c,transitionOptions:this.props.transitionOptions,in:this.state.overlayVisible,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited},s))}}]),d}(t.Component);return E(F,"defaultProps",{id:null,value:null,name:null,style:null,className:null,disabled:!1,options:null,scrollHeight:"400px",placeholder:null,tabIndex:null,inputId:null,ariaLabel:null,ariaLabelledBy:null,selectionMode:"single",panelStyle:null,panelClassName:null,appendTo:null,emptyMessage:null,display:"comma",metaKeySelection:!0,valueTemplate:null,panelHeaderTemplate:null,panelFooterTemplate:null,transitionOptions:null,dropdownIcon:"pi pi-chevron-down",filter:!1,filterValue:null,filterBy:"label",filterMode:"lenient",filterPlaceholder:null,filterLocale:void 0,filterInputAutoFocus:!0,resetFilterOnHide:!1,onShow:null,onHide:null,onChange:null,onNodeSelect:null,onNodeUnselect:null,onNodeExpand:null,onNodeCollapse:null,onFilterValueChange:null}),e.TreeSelect=F,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.api,primereact.overlayservice,primereact.tree,primereact.csstransition,primereact.portal,primereact.ripple);
|