2 lines
31 KiB
JavaScript
2 lines
31 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/ripple");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=o(e);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function s(e){if(Array.isArray(e))return i(e)}function l(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function a(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 p(){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 d(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function h(e,t,n){return t&&c(e.prototype,t),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e,t){return f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},f(e,t)}function g(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&&f(e,t)}function y(e){return y="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},y(e)}function v(e,t){if(t&&("object"===y(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return u(e)}function b(e){return b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},b(e)}function m(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function D(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=S(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},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,s=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){l=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(l)throw i}}}}function S(e,t){if(e){if("string"==typeof e)return k(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)?k(e,t):void 0}}function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function C(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function E(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?C(Object(n),!0).forEach((function(t){m(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}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(e){return!1}}var N=function(o){g(a,e.Component);var i,s,l=(i=a,s=x(),function(){var e,t=b(i);if(s){var n=b(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return v(this,e)});function a(e){var t;return d(this,a),(t=l.call(this,e)).onClick=t.onClick.bind(u(t)),t.onDoubleClick=t.onDoubleClick.bind(u(t)),t.onRightClick=t.onRightClick.bind(u(t)),t.onTouchEnd=t.onTouchEnd.bind(u(t)),t.onTogglerClick=t.onTogglerClick.bind(u(t)),t.onNodeKeyDown=t.onNodeKeyDown.bind(u(t)),t.propagateUp=t.propagateUp.bind(u(t)),t.onDrop=t.onDrop.bind(u(t)),t.onDragOver=t.onDragOver.bind(u(t)),t.onDragEnter=t.onDragEnter.bind(u(t)),t.onDragLeave=t.onDragLeave.bind(u(t)),t.onDragStart=t.onDragStart.bind(u(t)),t.onDragEnd=t.onDragEnd.bind(u(t)),t.onDropPointDragOver=t.onDropPointDragOver.bind(u(t)),t.onDropPointDragEnter=t.onDropPointDragEnter.bind(u(t)),t.onDropPointDragLeave=t.onDropPointDragLeave.bind(u(t)),t}return h(a,[{key:"isLeaf",value:function(){return this.props.isNodeLeaf(this.props.node)}},{key:"expand",value:function(e){var t=this.props.expandedKeys?E({},this.props.expandedKeys):{};t[this.props.node.key]=!0,this.props.onToggle({originalEvent:e,value:t}),this.invokeToggleEvents(e,!0)}},{key:"collapse",value:function(e){var t=E({},this.props.expandedKeys);delete t[this.props.node.key],this.props.onToggle({originalEvent:e,value:t}),this.invokeToggleEvents(e,!1)}},{key:"onTogglerClick",value:function(e){this.props.disabled||(this.isExpanded()?this.collapse(e):this.expand(e))}},{key:"invokeToggleEvents",value:function(e,t){t?this.props.onExpand&&this.props.onExpand({originalEvent:e,node:this.props.node}):this.props.onCollapse&&this.props.onCollapse({originalEvent:e,node:this.props.node})}},{key:"isExpanded",value:function(){return!!this.props.expandedKeys&&void 0!==this.props.expandedKeys[this.props.node.key]||this.props.node.expanded}},{key:"onNodeKeyDown",value:function(e){if(!this.props.disabled){var n=e.target.parentElement;if(t.DomHandler.hasClass(n,"p-treenode"))switch(e.which){case 40:var o=n.children[1];if(o)this.focusNode(o.children[0]);else{var r=n.nextElementSibling;if(r)this.focusNode(r);else{var i=this.findNextSiblingOfAncestor(n);i&&this.focusNode(i)}}e.preventDefault();break;case 38:if(n.previousElementSibling)this.focusNode(this.findLastVisibleDescendant(n.previousElementSibling));else{var s=this.getParentNodeElement(n);s&&this.focusNode(s)}e.preventDefault();break;case 39:this.isExpanded()||this.expand(e),e.preventDefault();break;case 37:this.isExpanded()&&this.collapse(e),e.preventDefault();break;case 13:this.onClick(e),e.preventDefault()}}}},{key:"findNextSiblingOfAncestor",value:function(e){var t=this.getParentNodeElement(e);return t?t.nextElementSibling?t.nextElementSibling:this.findNextSiblingOfAncestor(t):null}},{key:"findLastVisibleDescendant",value:function(e){var t=e.children[1];return t?this.findLastVisibleDescendant(t.children[t.children.length-1]):e}},{key:"getParentNodeElement",value:function(e){var n=e.parentElement.parentElement;return t.DomHandler.hasClass(n,"p-treenode")?n:null}},{key:"focusNode",value:function(e){e.children[0].focus()}},{key:"onClick",value:function(e){if(this.props.onClick&&this.props.onClick({originalEvent:e,node:this.props.node}),!(e.target.className&&e.target.className.constructor===String&&0===e.target.className.indexOf("p-tree-toggler")||this.props.disabled)){if(this.props.selectionMode&&!1!==this.props.node.selectable){var t;if(this.isCheckboxSelectionMode()){var n=this.isChecked();t=this.props.selectionKeys?E({},this.props.selectionKeys):{},n?(this.props.propagateSelectionDown?this.propagateDown(this.props.node,!1,t):delete t[this.props.node.key],this.props.propagateSelectionUp&&this.props.onPropagateUp&&this.props.onPropagateUp({originalEvent:e,check:!1,selectionKeys:t}),this.props.onUnselect&&this.props.onUnselect({originalEvent:e,node:this.props.node})):(this.props.propagateSelectionDown?this.propagateDown(this.props.node,!0,t):t[this.props.node.key]={checked:!0},this.props.propagateSelectionUp&&this.props.onPropagateUp&&this.props.onPropagateUp({originalEvent:e,check:!0,selectionKeys:t}),this.props.onSelect&&this.props.onSelect({originalEvent:e,node:this.props.node}))}else{var o=this.isSelected();if(!this.nodeTouched&&this.props.metaKeySelection){var r=e.metaKey||e.ctrlKey;o&&r?(this.isSingleSelectionMode()?t=null:delete(t=E({},this.props.selectionKeys))[this.props.node.key],this.props.onUnselect&&this.props.onUnselect({originalEvent:e,node:this.props.node})):(this.isSingleSelectionMode()?t=this.props.node.key:this.isMultipleSelectionMode()&&((t=r&&this.props.selectionKeys?E({},this.props.selectionKeys):{})[this.props.node.key]=!0),this.props.onSelect&&this.props.onSelect({originalEvent:e,node:this.props.node}))}else this.isSingleSelectionMode()?o?(t=null,this.props.onUnselect&&this.props.onUnselect({originalEvent:e,node:this.props.node})):(t=this.props.node.key,this.props.onSelect&&this.props.onSelect({originalEvent:e,node:this.props.node})):o?(delete(t=E({},this.props.selectionKeys))[this.props.node.key],this.props.onUnselect&&this.props.onUnselect({originalEvent:e,node:this.props.node})):((t=this.props.selectionKeys?E({},this.props.selectionKeys):{})[this.props.node.key]=!0,this.props.onSelect&&this.props.onSelect({originalEvent:e,node:this.props.node}))}this.props.onSelectionChange&&this.props.onSelectionChange({originalEvent:e,value:t})}this.nodeTouched=!1}}},{key:"onDoubleClick",value:function(e){this.props.onDoubleClick&&this.props.onDoubleClick({originalEvent:e,node:this.props.node})}},{key:"onRightClick",value:function(e){this.props.disabled||(t.DomHandler.clearSelection(),this.props.onContextMenuSelectionChange&&this.props.onContextMenuSelectionChange({originalEvent:e,value:this.props.node.key}),this.props.onContextMenu&&this.props.onContextMenu({originalEvent:e,node:this.props.node}))}},{key:"propagateUp",value:function(e){var t,n=e.check,o=e.selectionKeys,r=0,i=!1,s=D(this.props.node.children);try{for(s.s();!(t=s.n()).done;){var l=t.value;o[l.key]&&o[l.key].checked?r++:o[l.key]&&o[l.key].partialChecked&&(i=!0)}}catch(e){s.e(e)}finally{s.f()}n&&r===this.props.node.children.length?o[this.props.node.key]={checked:!0,partialChecked:!1}:(n||delete o[this.props.node.key],i||r>0&&r!==this.props.node.children.length?o[this.props.node.key]={checked:!1,partialChecked:!0}:delete o[this.props.node.key]),this.props.propagateSelectionUp&&this.props.onPropagateUp&&this.props.onPropagateUp(e)}},{key:"propagateDown",value:function(e,t,n){if(t?n[e.key]={checked:!0,partialChecked:!1}:delete n[e.key],e.children&&e.children.length)for(var o=0;o<e.children.length;o++)this.propagateDown(e.children[o],t,n)}},{key:"isSelected",value:function(){return!(!this.props.selectionMode||!this.props.selectionKeys)&&(this.isSingleSelectionMode()?this.props.selectionKeys===this.props.node.key:void 0!==this.props.selectionKeys[this.props.node.key])}},{key:"isChecked",value:function(){return!!this.props.selectionKeys&&(this.props.selectionKeys[this.props.node.key]&&this.props.selectionKeys[this.props.node.key].checked)}},{key:"isPartialChecked",value:function(){return!!this.props.selectionKeys&&(this.props.selectionKeys[this.props.node.key]&&this.props.selectionKeys[this.props.node.key].partialChecked)}},{key:"isSingleSelectionMode",value:function(){return this.props.selectionMode&&"single"===this.props.selectionMode}},{key:"isMultipleSelectionMode",value:function(){return this.props.selectionMode&&"multiple"===this.props.selectionMode}},{key:"isCheckboxSelectionMode",value:function(){return this.props.selectionMode&&"checkbox"===this.props.selectionMode}},{key:"onTouchEnd",value:function(){this.nodeTouched=!0}},{key:"onDropPoint",value:function(e,n){e.preventDefault(),!1!==this.props.node.droppable&&(t.DomHandler.removeClass(e.target,"p-treenode-droppoint-active"),this.props.onDropPoint&&this.props.onDropPoint({originalEvent:e,path:this.props.path,index:this.props.index,position:n}))}},{key:"onDropPointDragOver",value:function(e){e.dataTransfer.types[1]===this.props.dragdropScope.toLocaleLowerCase()&&(e.dataTransfer.dropEffect="move",e.preventDefault())}},{key:"onDropPointDragEnter",value:function(e){e.dataTransfer.types[1]===this.props.dragdropScope.toLocaleLowerCase()&&t.DomHandler.addClass(e.target,"p-treenode-droppoint-active")}},{key:"onDropPointDragLeave",value:function(e){e.dataTransfer.types[1]===this.props.dragdropScope.toLocaleLowerCase()&&t.DomHandler.removeClass(e.target,"p-treenode-droppoint-active")}},{key:"onDrop",value:function(e){this.props.dragdropScope&&!1!==this.props.node.droppable&&(t.DomHandler.removeClass(this.contentElement,"p-treenode-dragover"),e.preventDefault(),e.stopPropagation(),this.props.onDrop&&this.props.onDrop({originalEvent:e,path:this.props.path,index:this.props.index}))}},{key:"onDragOver",value:function(e){e.dataTransfer.types[1]===this.props.dragdropScope.toLocaleLowerCase()&&!1!==this.props.node.droppable&&(e.dataTransfer.dropEffect="move",e.preventDefault(),e.stopPropagation())}},{key:"onDragEnter",value:function(e){e.dataTransfer.types[1]===this.props.dragdropScope.toLocaleLowerCase()&&!1!==this.props.node.droppable&&t.DomHandler.addClass(this.contentElement,"p-treenode-dragover")}},{key:"onDragLeave",value:function(e){if(e.dataTransfer.types[1]===this.props.dragdropScope.toLocaleLowerCase()&&!1!==this.props.node.droppable){var n=e.currentTarget.getBoundingClientRect();(e.nativeEvent.x>n.left+n.width||e.nativeEvent.x<n.left||e.nativeEvent.y>=Math.floor(n.top+n.height)||e.nativeEvent.y<n.top)&&t.DomHandler.removeClass(this.contentElement,"p-treenode-dragover")}}},{key:"onDragStart",value:function(e){e.dataTransfer.setData("text",this.props.dragdropScope),e.dataTransfer.setData(this.props.dragdropScope,this.props.dragdropScope),this.props.onDragStart&&this.props.onDragStart({originalEvent:e,path:this.props.path,index:this.props.index})}},{key:"onDragEnd",value:function(e){this.props.onDragEnd&&this.props.onDragEnd({originalEvent:e})}},{key:"renderLabel",value:function(){var e=r.default.createElement("span",{className:"p-treenode-label"},this.props.node.label);if(this.props.nodeTemplate){var n={onTogglerClick:this.onTogglerClick,className:"p-treenode-label",element:e,props:this.props,expanded:this.isExpanded()};e=t.ObjectUtils.getJSXElement(this.props.nodeTemplate,this.props.node,n)}return e}},{key:"renderCheckbox",value:function(){if(this.isCheckboxSelectionMode()&&!1!==this.props.node.selectable){var e=this.isChecked(),n=this.isPartialChecked(),o=t.classNames("p-checkbox-box",{"p-highlight":e,"p-indeterminate":n,"p-disabled":this.props.disabled}),i=t.classNames("p-checkbox-icon p-c",{"pi pi-check":e,"pi pi-minus":n});return r.default.createElement("div",{className:"p-checkbox p-component"},r.default.createElement("div",{className:o,role:"checkbox","aria-checked":e},r.default.createElement("span",{className:i})))}return null}},{key:"renderIcon",value:function(e){var n=this.props.node.icon||(e?this.props.node.expandedIcon:this.props.node.collapsedIcon);if(n){var o=t.classNames("p-treenode-icon",n);return r.default.createElement("span",{className:o})}return null}},{key:"renderToggler",value:function(e){var o=t.classNames("p-tree-toggler-icon pi pi-fw",{"pi-chevron-right":!e,"pi-chevron-down":e}),i=r.default.createElement("button",{type:"button",className:"p-tree-toggler p-link",tabIndex:-1,onClick:this.onTogglerClick},r.default.createElement("span",{className:o}),r.default.createElement(n.Ripple,null));this.props.togglerTemplate&&(i=t.ObjectUtils.getJSXElement(this.props.togglerTemplate,this.props.node,{onClick:this.onTogglerClick,containerClassName:"p-tree-toggler p-link",iconClassName:"p-tree-toggler-icon",element:i,props:this.props,expanded:e}));return i}},{key:"renderDropPoint",value:function(e){var t=this;return this.props.dragdropScope?r.default.createElement("li",{className:"p-treenode-droppoint",onDrop:function(n){return t.onDropPoint(n,e)},onDragOver:this.onDropPointDragOver,onDragEnter:this.onDropPointDragEnter,onDragLeave:this.onDropPointDragLeave}):null}},{key:"renderContent",value:function(){var e=this,n=this.isSelected(),o=this.isChecked(),i=t.classNames("p-treenode-content",this.props.node.className,{"p-treenode-selectable":this.props.selectionMode&&!1!==this.props.node.selectable,"p-highlight":this.isCheckboxSelectionMode()?o:n,"p-highlight-contextmenu":this.props.contextMenuSelectionKey&&this.props.contextMenuSelectionKey===this.props.node.key,"p-disabled":this.props.disabled}),s=this.isExpanded(),l=this.renderToggler(s),a=this.renderCheckbox(),p=this.renderIcon(s),d=this.renderLabel();return r.default.createElement("div",{ref:function(t){return e.contentElement=t},className:i,style:this.props.node.style,onClick:this.onClick,onDoubleClick:this.onDoubleClick,onContextMenu:this.onRightClick,onTouchEnd:this.onTouchEnd,draggable:this.props.dragdropScope&&!1!==this.props.node.draggable&&!this.props.disabled,onDrop:this.onDrop,onDragOver:this.onDragOver,onDragEnter:this.onDragEnter,onDragLeave:this.onDragLeave,onDragStart:this.onDragStart,onDragEnd:this.onDragEnd,tabIndex:this.props.disabled?void 0:0,onKeyDown:this.onNodeKeyDown,role:"treeitem","aria-posinset":this.props.index+1,"aria-expanded":this.isExpanded(),"aria-selected":o||n},l,a,p,d)}},{key:"renderChildren",value:function(){var e=this;return this.props.node.children&&this.props.node.children.length&&this.isExpanded()?r.default.createElement("ul",{className:"p-treenode-children",role:"group"},this.props.node.children.map((function(t,n){return r.default.createElement(a,{key:t.key||t.label,node:t,parent:e.props.node,index:n,last:n===e.props.node.children.length-1,path:e.props.path+"-"+n,disabled:e.props.disabled,selectionMode:e.props.selectionMode,selectionKeys:e.props.selectionKeys,onSelectionChange:e.props.onSelectionChange,metaKeySelection:e.props.metaKeySelection,propagateSelectionDown:e.props.propagateSelectionDown,propagateSelectionUp:e.props.propagateSelectionUp,contextMenuSelectionKey:e.props.contextMenuSelectionKey,onContextMenuSelectionChange:e.props.onContextMenuSelectionChange,onContextMenu:e.props.onContextMenu,onExpand:e.props.onExpand,onCollapse:e.props.onCollapse,onSelect:e.props.onSelect,onUnselect:e.props.onUnselect,expandedKeys:e.props.expandedKeys,onToggle:e.props.onToggle,onPropagateUp:e.propagateUp,nodeTemplate:e.props.nodeTemplate,togglerTemplate:e.props.togglerTemplate,isNodeLeaf:e.props.isNodeLeaf,dragdropScope:e.props.dragdropScope,onDragStart:e.props.onDragStart,onDragEnd:e.props.onDragEnd,onDrop:e.props.onDrop,onDropPoint:e.props.onDropPoint})}))):null}},{key:"renderNode",value:function(){var e=t.classNames("p-treenode",{"p-treenode-leaf":this.isLeaf()},this.props.node.className),n=this.renderContent(),o=this.renderChildren();return r.default.createElement("li",{className:e,style:this.props.node.style},n,o)}},{key:"render",value:function(){var e=this.renderNode();if(this.props.dragdropScope&&!this.props.disabled){var t=this.renderDropPoint(-1),n=this.props.last?this.renderDropPoint(1):null;return r.default.createElement(r.default.Fragment,null,t,e,n)}return e}}]),a}();function O(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function w(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?O(Object(n),!0).forEach((function(t){m(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):O(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function P(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=K(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},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,s=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){l=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(l)throw i}}}}function K(e,t){if(e){if("string"==typeof e)return T(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)?T(e,t):void 0}}function T(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function M(){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}}m(N,"defaultProps",{node:null,index:null,last:null,parent:null,path:null,disabled:!1,selectionMode:null,selectionKeys:null,contextMenuSelectionKey:null,metaKeySelection:!0,expandedKeys:null,propagateSelectionUp:!0,propagateSelectionDown:!0,dragdropScope:null,ariaLabel:null,ariaLabelledBy:null,nodeTemplate:null,togglerTemplate:null,isNodeLeaf:null,onSelect:null,onUnselect:null,onExpand:null,onCollapse:null,onToggle:null,onSelectionChange:null,onContextMenuSelectionChange:null,onPropagateUp:null,onDragStart:null,onDragEnd:null,onDrop:null,onDropPoint:null,onContextMenu:null,onNodeClick:null,onNodeDoubleClick:null});var j=function(n){g(f,e.Component);var o,i,c=(o=f,i=M(),function(){var e,t=b(o);if(i){var n=b(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return v(this,e)});function f(e){var t;return d(this,f),(t=c.call(this,e)).state={},t.props.onFilterValueChange||(t.state.filterValue=""),t.props.onToggle||(t.state.expandedKeys=t.props.expandedKeys),t.isNodeLeaf=t.isNodeLeaf.bind(u(t)),t.onToggle=t.onToggle.bind(u(t)),t.onDragStart=t.onDragStart.bind(u(t)),t.onDragEnd=t.onDragEnd.bind(u(t)),t.onDrop=t.onDrop.bind(u(t)),t.onDropPoint=t.onDropPoint.bind(u(t)),t.onFilterInputChange=t.onFilterInputChange.bind(u(t)),t.onFilterInputKeyDown=t.onFilterInputKeyDown.bind(u(t)),t}return h(f,[{key:"getFilterValue",value:function(){return this.props.onFilterValueChange?this.props.filterValue:this.state.filterValue}},{key:"getExpandedKeys",value:function(){return this.props.onToggle?this.props.expandedKeys:this.state.expandedKeys}},{key:"getRootNode",value:function(){return this.props.filter&&this.filteredNodes?this.filteredNodes:this.props.value}},{key:"onToggle",value:function(e){this.props.onToggle?this.props.onToggle(e):this.setState({expandedKeys:e.value})}},{key:"onDragStart",value:function(e){this.dragState={path:e.path,index:e.index}}},{key:"onDragEnd",value:function(){this.dragState=null}},{key:"onDrop",value:function(e){if(this.validateDropNode(this.dragState.path,e.path)){var t=JSON.parse(JSON.stringify(this.props.value)),n=this.dragState.path.split("-");n.pop();var o=this.findNode(t,n),r=o?o.children[this.dragState.index]:t[this.dragState.index],i=this.findNode(t,e.path.split("-"));i.children?i.children.push(r):i.children=[r],o?o.children.splice(this.dragState.index,1):t.splice(this.dragState.index,1),this.props.onDragDrop&&this.props.onDragDrop({originalEvent:e.originalEvent,value:t,dragNode:r,dropNode:i,dropIndex:e.index})}}},{key:"onDropPoint",value:function(e){if(this.validateDropPoint(e)){var t=JSON.parse(JSON.stringify(this.props.value)),n=this.dragState.path.split("-");n.pop();var o=e.path.split("-");o.pop();var r=this.findNode(t,n),i=this.findNode(t,o),s=r?r.children[this.dragState.index]:t[this.dragState.index],l=this.areSiblings(this.dragState.path,e.path);if(r?r.children.splice(this.dragState.index,1):t.splice(this.dragState.index,1),e.position<0){var a=l?this.dragState.index>e.index?e.index:e.index-1:e.index;i?i.children.splice(a,0,s):t.splice(a,0,s)}else i?i.children.push(s):t.push(s);this.props.onDragDrop&&this.props.onDragDrop({originalEvent:e.originalEvent,value:t,dragNode:s,dropNode:i,dropIndex:e.index})}}},{key:"validateDrop",value:function(e,t){return!!e&&(e!==t&&0!==t.indexOf(e))}},{key:"validateDropNode",value:function(e,t){return!!this.validateDrop(e,t)&&!(e.indexOf("-")>0&&e.substring(0,e.lastIndexOf("-"))===t)}},{key:"validateDropPoint",value:function(e){return!!this.validateDrop(this.dragState.path,e.path)&&(-1!==e.position||!this.areSiblings(this.dragState.path,e.path)||this.dragState.index+1!==e.index)}},{key:"areSiblings",value:function(e,t){return 1===e.length&&1===t.length||e.substring(0,e.lastIndexOf("-"))===t.substring(0,t.lastIndexOf("-"))}},{key:"findNode",value:function(e,t){if(0===t.length)return null;var n=parseInt(t[0],10),o=e.children?e.children[n]:e[n];return 1===t.length?o:(t.shift(),this.findNode(o,t))}},{key:"isNodeLeaf",value:function(e){return!1!==e.leaf&&!(e.children&&e.children.length)}},{key:"onFilterInputKeyDown",value:function(e){13===e.which&&e.preventDefault()}},{key:"onFilterInputChange",value:function(e){this.filterChanged=!0;var t=e.target.value;this.props.onFilterValueChange?this.props.onFilterValueChange({originalEvent:e,value:t}):this.setState({filterValue:t})}},{key:"filter",value:function(e){this.setState({filterValue:t.ObjectUtils.isNotEmpty(e)?e:""},this._filter)}},{key:"_filter",value:function(){if(this.filterChanged){var e=this.getFilterValue();if(t.ObjectUtils.isEmpty(e))this.filteredNodes=this.props.value;else{this.filteredNodes=[];var n,o=this.props.filterBy.split(","),r=e.toLocaleLowerCase(this.props.filterLocale),i="strict"===this.props.filterMode,s=P(this.props.value);try{for(s.s();!(n=s.n()).done;){var l=w({},n.value),a={searchFields:o,filterText:r,isStrictMode:i};(i&&(this.findFilteredNodes(l,a)||this.isFilterMatched(l,a))||!i&&(this.isFilterMatched(l,a)||this.findFilteredNodes(l,a)))&&this.filteredNodes.push(l)}}catch(e){s.e(e)}finally{s.f()}}this.filterChanged=!1}}},{key:"findFilteredNodes",value:function(e,t){if(e){var n=!1;if(e.children){var o=s(c=e.children)||l(c)||a(c)||p();e.children=[];var r,i=P(o);try{for(i.s();!(r=i.n()).done;){var d=w({},r.value);this.isFilterMatched(d,t)&&(n=!0,e.children.push(d))}}catch(e){i.e(e)}finally{i.f()}}if(n)return e.expanded=!0,!0}var c}},{key:"isFilterMatched",value:function(e,n){var o,r=n.searchFields,i=n.filterText,s=n.isStrictMode,l=!1,a=P(r);try{for(a.s();!(o=a.n()).done;){String(t.ObjectUtils.resolveFieldData(e,o.value)).toLocaleLowerCase(this.props.filterLocale).indexOf(i)>-1&&(l=!0)}}catch(e){a.e(e)}finally{a.f()}return(!l||s&&!this.isNodeLeaf(e))&&(l=this.findFilteredNodes(e,{searchFields:r,filterText:i,isStrictMode:s})||l),l}},{key:"renderRootChild",value:function(e,t,n){return r.default.createElement(N,{key:e.key||e.label,node:e,index:t,last:n,path:String(t),disabled:this.props.disabled,selectionMode:this.props.selectionMode,selectionKeys:this.props.selectionKeys,onSelectionChange:this.props.onSelectionChange,metaKeySelection:this.props.metaKeySelection,contextMenuSelectionKey:this.props.contextMenuSelectionKey,onContextMenuSelectionChange:this.props.onContextMenuSelectionChange,onContextMenu:this.props.onContextMenu,propagateSelectionDown:this.props.propagateSelectionDown,propagateSelectionUp:this.props.propagateSelectionUp,onExpand:this.props.onExpand,onCollapse:this.props.onCollapse,onSelect:this.props.onSelect,onUnselect:this.props.onUnselect,expandedKeys:this.getExpandedKeys(),onToggle:this.onToggle,nodeTemplate:this.props.nodeTemplate,togglerTemplate:this.props.togglerTemplate,isNodeLeaf:this.isNodeLeaf,dragdropScope:this.props.dragdropScope,onDragStart:this.onDragStart,onDragEnd:this.onDragEnd,onDrop:this.onDrop,onDropPoint:this.onDropPoint,onNodeClick:this.props.onNodeClick,onNodeDoubleClick:this.props.onNodeDoubleClick})}},{key:"renderRootChildren",value:function(){var e=this;this.props.filter&&(this.filterChanged=!0,this._filter());var t=this.getRootNode();return t.map((function(n,o){return e.renderRootChild(n,o,o===t.length-1)}))}},{key:"renderModel",value:function(){if(this.props.value){var e=this.renderRootChildren(),n=t.classNames("p-tree-container",this.props.contentClassName);return r.default.createElement("ul",{className:n,role:"tree","aria-label":this.props.ariaLabel,"aria-labelledby":this.props.ariaLabelledBy,style:this.props.contentStyle},e)}return null}},{key:"renderLoader",value:function(){if(this.props.loading){var e=t.classNames("p-tree-loading-icon pi-spin",this.props.loadingIcon);return r.default.createElement("div",{className:"p-tree-loading-overlay p-component-overlay"},r.default.createElement("i",{className:e}))}return null}},{key:"renderFilter",value:function(){if(this.props.filter){var e=this.getFilterValue();return e=t.ObjectUtils.isNotEmpty(e)?e:"",r.default.createElement("div",{className:"p-tree-filter-container"},r.default.createElement("input",{type:"text",value:e,autoComplete:"off",className:"p-tree-filter p-inputtext p-component",placeholder:this.props.filterPlaceholder,onKeyDown:this.onFilterInputKeyDown,onChange:this.onFilterInputChange,disabled:this.props.disabled}),r.default.createElement("span",{className:"p-tree-filter-icon pi pi-search"}))}return null}},{key:"renderHeader",value:function(){if(this.props.showHeader){var e=this.renderFilter(),n=e;if(this.props.header)n=t.ObjectUtils.getJSXElement(this.props.header,{filterContainerClassName:"p-tree-filter-container",filterIconClasssName:"p-tree-filter-icon pi pi-search",filterInput:{className:"p-tree-filter p-inputtext p-component",onKeyDown:this.onFilterInputKeyDown,onChange:this.onFilterInputChange},filterElement:e,element:n,props:this.props});return r.default.createElement("div",{className:"p-tree-header"},n)}return null}},{key:"renderFooter",value:function(){var e=t.ObjectUtils.getJSXElement(this.props.footer,this.props);return r.default.createElement("div",{className:"p-tree-footer"},e)}},{key:"render",value:function(){var e=t.classNames("p-tree p-component",this.props.className,{"p-tree-selectable":this.props.selectionMode,"p-tree-loading":this.props.loading,"p-disabled":this.props.disabled}),n=this.renderLoader(),o=this.renderModel(),i=this.renderHeader(),s=this.renderFooter();return r.default.createElement("div",{id:this.props.id,className:e,style:this.props.style},n,i,o,s)}}]),f}();m(j,"defaultProps",{id:null,value:null,disabled:!1,selectionMode:null,selectionKeys:null,onSelectionChange:null,contextMenuSelectionKey:null,onContextMenuSelectionChange:null,expandedKeys:null,style:null,className:null,contentStyle:null,contentClassName:null,metaKeySelection:!0,propagateSelectionUp:!0,propagateSelectionDown:!0,loading:!1,loadingIcon:"pi pi-spinner",dragdropScope:null,header:null,footer:null,showHeader:!0,filter:!1,filterValue:null,filterBy:"label",filterMode:"lenient",filterPlaceholder:null,filterLocale:void 0,nodeTemplate:null,togglerTemplate:null,onSelect:null,onUnselect:null,onExpand:null,onCollapse:null,onToggle:null,onDragDrop:null,onContextMenu:null,onFilterValueChange:null,onNodeClick:null,onNodeDoubleClick:null}),exports.Tree=j;
|