katoikia-app/web-ui/web-react/node_modules/primereact/tree/tree.esm.min.js

2 lines
30 KiB
JavaScript

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