2 lines
7.8 KiB
JavaScript
2 lines
7.8 KiB
JavaScript
import e,{Component as t}from"react";import{classNames as n}from"primereact/utils";function o(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 r(e){if(Array.isArray(e))return o(e)}function i(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function l(e,t){if(e){if("string"==typeof e)return o(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)?o(e,t):void 0}}function s(){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 a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(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 d(e,t,n){return t&&p(e.prototype,t),n&&p(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function u(e,t){return u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},u(e,t)}function h(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&&u(e,t)}function f(e){return f="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},f(e)}function m(e,t){if(t&&("object"===f(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return a(e)}function y(e){return y=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},y(e)}function g(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function v(e){var t=b();return function(){var n,o=y(e);if(t){var r=y(this).constructor;n=Reflect.construct(o,arguments,r)}else n=o.apply(this,arguments);return m(this,n)}}function b(){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){h(i,t);var r=v(i);function i(e){var t;return c(this,i),(t=r.call(this,e)).node=t.props.node,t.state={expanded:t.node.expanded},t}return d(i,[{key:"getLeaf",value:function(){return!1!==this.node.leaf&&!(this.node.children&&this.node.children.length)}},{key:"getColspan",value:function(){return this.node.children&&this.node.children.length?2*this.node.children.length:null}},{key:"onNodeClick",value:function(e,t){this.props.onNodeClick(e,t)}},{key:"toggleNode",value:function(e,t){this.setState((function(e){return{expanded:!e.expanded}})),e.preventDefault()}},{key:"isSelected",value:function(){return this.props.isSelected(this.node)}},{key:"render",value:function(){var t=this;this.node=this.props.node;var o=this.getColspan(),r=n("p-organizationchart-node-content",this.node.className,{"p-organizationchart-selectable-node":this.props.selectionMode&&!1!==this.node.selectable,"p-highlight":this.isSelected()}),l=this.props.nodeTemplate&&this.props.nodeTemplate(this.node)?e.createElement("div",null,this.props.nodeTemplate(this.node)):e.createElement("div",null,this.node.label),s=n("p-node-toggler-icon",{"pi pi-chevron-down":this.state.expanded,"pi pi-chevron-up":!this.state.expanded}),a=e.createElement("tr",null,e.createElement("td",{colSpan:o},e.createElement("div",{className:r,onClick:function(e){return t.onNodeClick(e,t.node)}},l,!this.getLeaf()&&e.createElement("a",{href:"#",className:"p-node-toggler",onClick:function(e){return t.toggleNode(e,t.node)}},e.createElement("i",{className:s}))))),c=!this.getLeaf()&&this.state.expanded?"inherit":"hidden",p=e.createElement("tr",{style:{visibility:c},className:"p-organizationchart-lines"},e.createElement("td",{colSpan:o},e.createElement("div",{className:"p-organizationchart-line-down"}))),d=this.node.children&&this.node.children.length,u=e.createElement("tr",{style:{visibility:c},className:"p-organizationchart-lines"},this.node.children&&1===this.node.children.length&&e.createElement("td",{colSpan:this.getColspan()},e.createElement("div",{className:"p-organizationchart-line-down"})),this.node.children&&this.node.children.length>1&&this.node.children.map((function(t,o){var r=n("p-organizationchart-line-left",{"p-organizationchart-line-top":0!==o}),i=n("p-organizationchart-line-right",{"p-organizationchart-line-top":o!==d-1});return[e.createElement("td",{key:o+"_lineleft",className:r}," "),e.createElement("td",{key:o+"_lineright",className:i}," ")]}))),h=e.createElement("tr",{style:{visibility:c},className:"p-organizationchart-nodes"},this.node.children&&this.node.children.map((function(n,o){return e.createElement("td",{key:o,colSpan:"2"},e.createElement(i,{node:n,nodeTemplate:t.props.nodeTemplate,selectionMode:t.props.selectionMode,onNodeClick:t.props.onNodeClick,isSelected:t.props.isSelected}))})));return e.createElement("table",{className:"p-organizationchart-table"},e.createElement("tbody",null,a,p,u,h))}}]),i}();g(N,"defaultProps",{node:null,nodeTemplate:null,root:!1,first:!1,last:!1,selectionMode:null,onNodeClick:null,isSelected:null});var S=function(o){h(u,t);var p=v(u);function u(e){var t;return c(this,u),(t=p.call(this,e)).root=t.props.value&&t.props.value.length?t.props.value[0]:null,t.onNodeClick=t.onNodeClick.bind(a(t)),t.isSelected=t.isSelected.bind(a(t)),t}return d(u,[{key:"onNodeClick",value:function(e,t){if(this.props.selectionMode){var n=e.target;if(n.className&&(-1!==n.className.indexOf("p-node-toggler")||-1!==n.className.indexOf("p-node-toggler-icon")))return;if(!1===t.selectable)return;var o,a=this.findIndexInSelection(t),c=a>=0;"single"===this.props.selectionMode?c?(o=null,this.props.onNodeUnselect&&this.props.onNodeUnselect({originalEvent:e,node:t})):(o=t,this.props.onNodeSelect&&this.props.onNodeSelect({originalEvent:e,node:t})):"multiple"===this.props.selectionMode&&(c?(o=this.props.selection.filter((function(e,t){return t!==a})),this.props.onNodeUnselect&&this.props.onNodeUnselect({originalEvent:e,node:t})):(o=[].concat(r(p=this.props.selection||[])||i(p)||l(p)||s(),[t]),this.props.onNodeSelect&&this.props.onNodeSelect({originalEvent:e,node:t}))),this.props.onSelectionChange&&this.props.onSelectionChange({originalEvent:e,data:o})}var p}},{key:"findIndexInSelection",value:function(e){var t=-1;if(this.props.selectionMode&&this.props.selection)if("single"===this.props.selectionMode)t=this.props.selection===e?0:-1;else if("multiple"===this.props.selectionMode)for(var n=0;n<this.props.selection.length;n++)if(this.props.selection[n]===e){t=n;break}return t}},{key:"isSelected",value:function(e){return-1!==this.findIndexInSelection(e)}},{key:"render",value:function(){this.root=this.props.value&&this.props.value.length?this.props.value[0]:null;var t=n("p-organizationchart p-component",this.props.className);return e.createElement("div",{id:this.props.id,style:this.props.style,className:t},e.createElement(N,{node:this.root,nodeTemplate:this.props.nodeTemplate,selectionMode:this.props.selectionMode,onNodeClick:this.onNodeClick,isSelected:this.isSelected}))}}]),u}();g(S,"defaultProps",{id:null,value:null,style:null,className:null,selectionMode:null,selection:null,nodeTemplate:null,onSelectionChange:null,onNodeSelect:null,onNodeUnselect:null});export{S as OrganizationChart,N as OrganizationChartNode};
|