2 lines
31 KiB
JavaScript
2 lines
31 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.tree=function(e,t,n,o){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=r(t);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 l(e){if(Array.isArray(e))return s(e)}function a(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function p(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 D(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(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 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){D(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(e){y(l,e);var t,r,s=(t=l,r=N(),function(){var e,n=m(t);if(r){var o=m(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return b(this,e)});function l(e){var t;return c(this,l),(t=s.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(l,[{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.DomHandler.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.DomHandler.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.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=S(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,t){e.preventDefault(),!1!==this.props.node.droppable&&(n.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: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.DomHandler.addClass(e.target,"p-treenode-droppoint-active")}},{key:"onDropPointDragLeave",value:function(e){e.dataTransfer.types[1]===this.props.dragdropScope.toLocaleLowerCase()&&n.DomHandler.removeClass(e.target,"p-treenode-droppoint-active")}},{key:"onDrop",value:function(e){this.props.dragdropScope&&!1!==this.props.node.droppable&&(n.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&&n.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 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.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=i.default.createElement("span",{className:"p-treenode-label"},this.props.node.label);if(this.props.nodeTemplate){var t={onTogglerClick:this.onTogglerClick,className:"p-treenode-label",element:e,props:this.props,expanded:this.isExpanded()};e=n.ObjectUtils.getJSXElement(this.props.nodeTemplate,this.props.node,t)}return e}},{key:"renderCheckbox",value:function(){if(this.isCheckboxSelectionMode()&&!1!==this.props.node.selectable){var e=this.isChecked(),t=this.isPartialChecked(),o=n.classNames("p-checkbox-box",{"p-highlight":e,"p-indeterminate":t,"p-disabled":this.props.disabled}),r=n.classNames("p-checkbox-icon p-c",{"pi pi-check":e,"pi pi-minus":t});return i.default.createElement("div",{className:"p-checkbox p-component"},i.default.createElement("div",{className:o,role:"checkbox","aria-checked":e},i.default.createElement("span",{className:r})))}return null}},{key:"renderIcon",value:function(e){var t=this.props.node.icon||(e?this.props.node.expandedIcon:this.props.node.collapsedIcon);if(t){var o=n.classNames("p-treenode-icon",t);return i.default.createElement("span",{className:o})}return null}},{key:"renderToggler",value:function(e){var t=n.classNames("p-tree-toggler-icon pi pi-fw",{"pi-chevron-right":!e,"pi-chevron-down":e}),r=i.default.createElement("button",{type:"button",className:"p-tree-toggler p-link",tabIndex:-1,onClick:this.onTogglerClick},i.default.createElement("span",{className:t}),i.default.createElement(o.Ripple,null));this.props.togglerTemplate&&(r=n.ObjectUtils.getJSXElement(this.props.togglerTemplate,this.props.node,{onClick:this.onTogglerClick,containerClassName:"p-tree-toggler p-link",iconClassName:"p-tree-toggler-icon",element:r,props:this.props,expanded:e}));return r}},{key:"renderDropPoint",value:function(e){var t=this;return this.props.dragdropScope?i.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,t=this.isSelected(),o=this.isChecked(),r=n.classNames("p-treenode-content",this.props.node.className,{"p-treenode-selectable":this.props.selectionMode&&!1!==this.props.node.selectable,"p-highlight":this.isCheckboxSelectionMode()?o:t,"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 i.default.createElement("div",{ref:function(t){return e.contentElement=t},className:r,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||t},l,a,p,d)}},{key:"renderChildren",value:function(){var e=this;return this.props.node.children&&this.props.node.children.length&&this.isExpanded()?i.default.createElement("ul",{className:"p-treenode-children",role:"group"},this.props.node.children.map((function(t,n){return i.default.createElement(l,{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=n.classNames("p-treenode",{"p-treenode-leaf":this.isLeaf()},this.props.node.className),t=this.renderContent(),o=this.renderChildren();return i.default.createElement("li",{className:e,style:this.props.node.style},t,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 i.default.createElement(i.default.Fragment,null,t,e,n)}return e}}]),l}(t.Component);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){D(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,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 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 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}}D(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 L=function(e){y(s,e);var t,o,r=(t=s,o=j(),function(){var e,n=m(t);if(o){var r=m(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return b(this,e)});function s(e){var t;return c(this,s),(t=r.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(s,[{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:n.ObjectUtils.isNotEmpty(e)?e:""},this._filter)}},{key:"_filter",value:function(){if(this.filterChanged){var e=this.getFilterValue();if(n.ObjectUtils.isEmpty(e))this.filteredNodes=this.props.value;else{this.filteredNodes=[];var t,o=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 l=P({},t.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=l(c=e.children)||a(c)||p(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 o,r=t.searchFields,i=t.filterText,s=t.isStrictMode,l=!1,a=K(r);try{for(a.s();!(o=a.n()).done;){String(n.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 i.default.createElement(O,{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(),t=n.classNames("p-tree-container",this.props.contentClassName);return i.default.createElement("ul",{className:t,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=n.classNames("p-tree-loading-icon pi-spin",this.props.loadingIcon);return i.default.createElement("div",{className:"p-tree-loading-overlay p-component-overlay"},i.default.createElement("i",{className:e}))}return null}},{key:"renderFilter",value:function(){if(this.props.filter){var e=this.getFilterValue();return e=n.ObjectUtils.isNotEmpty(e)?e:"",i.default.createElement("div",{className:"p-tree-filter-container"},i.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}),i.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(),t=e;if(this.props.header)t=n.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:t,props:this.props});return i.default.createElement("div",{className:"p-tree-header"},t)}return null}},{key:"renderFooter",value:function(){var e=n.ObjectUtils.getJSXElement(this.props.footer,this.props);return i.default.createElement("div",{className:"p-tree-footer"},e)}},{key:"render",value:function(){var e=n.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}),t=this.renderLoader(),o=this.renderModel(),r=this.renderHeader(),s=this.renderFooter();return i.default.createElement("div",{id:this.props.id,className:e,style:this.props.style},t,r,o,s)}}]),s}(t.Component);return D(L,"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}),e.Tree=L,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.ripple);
|