UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime

2 lines (1 loc) 5.51 kB
import*as e from"react";import{classNames as n,ObjectUtils as t,DomHandler as r}from"primereact/utils";function l(){return l=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},l.apply(this,arguments)}function o(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function a(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 c(e,n){if(e){if("string"==typeof e)return o(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,n):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 s(e){if(Array.isArray(e))return e}function u(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,l,o=[],a=!0,i=!1;try{for(t=t.call(e);!(a=(r=t.next()).done)&&(o.push(r.value),!n||o.length!==n);a=!0);}catch(e){i=!0,l=e}finally{try{a||null==t.return||t.return()}finally{if(i)throw l}}return o}}function m(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var p=e.memo((function(r){var l,o,a,i,d,f,h=r.node,g=e.useState(h.expanded),v=(o=2,s(l=g)||u(l,o)||c(l,o)||m()),y=v[0],N=v[1],E=!1!==h.leaf&&!(h.children&&h.children.length),b=h.children&&h.children.length?2*h.children.length:null,S=r.isSelected(h),z=!E&&y?"inherit":"hidden",C=function(e,n){r.onNodeClick(e,n)},M=function(){if(!E){var t=n("p-node-toggler-icon",{"pi pi-chevron-down":y,"pi pi-chevron-up":!y});return e.createElement("a",{href:"#",className:"p-node-toggler",onClick:function(e){return n=e,N((function(e){return!e})),void n.preventDefault();var n}},e.createElement("i",{className:t}))}return null},w=function(){var n=r.nodeTemplate&&t.getJSXElement(r.nodeTemplate,h)||h.label;return e.createElement("div",null,n)},T=(a=n("p-organizationchart-node-content",{"p-organizationchart-selectable-node":r.selectionMode&&!1!==h.selectable,"p-highlight":S},h.className),i=w(),d=M(),e.createElement("tr",null,e.createElement("td",{colSpan:b},e.createElement("div",{className:a,onClick:function(e){return C(e,h)}},i,d)))),k=e.createElement("tr",{style:{visibility:z},className:"p-organizationchart-lines"},e.createElement("td",{colSpan:b},e.createElement("div",{className:"p-organizationchart-line-down"}))),A=(f=h.children&&h.children.length,e.createElement("tr",{style:{visibility:z},className:"p-organizationchart-lines"},h.children&&1===h.children.length&&e.createElement("td",{colSpan:b},e.createElement("div",{className:"p-organizationchart-line-down"})),h.children&&h.children.length>1&&h.children.map((function(t,r){var l=n("p-organizationchart-line-left",{"p-organizationchart-line-top":0!==r}),o=n("p-organizationchart-line-right",{"p-organizationchart-line-top":r!==f-1});return[e.createElement("td",{key:r+"_lineleft",className:l}," "),e.createElement("td",{key:r+"_lineright",className:o}," ")]})))),O=e.createElement("tr",{style:{visibility:z},className:"p-organizationchart-nodes"},h.children&&h.children.map((function(n,t){return e.createElement("td",{key:t,colSpan:"2"},e.createElement(p,{node:n,nodeTemplate:r.nodeTemplate,selectionMode:r.selectionMode,onNodeClick:r.onNodeClick,isSelected:r.isSelected}))})));return e.createElement("table",{className:"p-organizationchart-table"},e.createElement("tbody",null,T,k,A,O))}));p.displayName="OrganizationChartNode";var f=e.memo(e.forwardRef((function(o,s){var u=e.useRef(null),m=o.value&&o.value.length?o.value[0]:null,h=function(e){if(o.selectionMode&&o.selection){if("single"===o.selectionMode)return o.selection===e?0:-1;if("multiple"===o.selectionMode)return o.selection.findIndex((function(n){return n===e}))}return-1};e.useImperativeHandle(s,(function(){return{props:o,getElement:function(){return u.current}}}));var g=t.findDiffKeys(o,f.defaultProps),v=n("p-organizationchart p-component",o.className);return e.createElement("div",l({id:o.id,ref:u,style:o.style,className:v},g),e.createElement(p,{node:m,nodeTemplate:o.nodeTemplate,selectionMode:o.selectionMode,onNodeClick:function(e,n){if(o.selectionMode){var t=e.target;if(!1===n.selectable||!r.hasClass(t,"p-node-toggler")||!r.hasClass(t,"p-node-toggler-icon"))return;var l,s=h(n),u=s>=0;"single"===o.selectionMode?u?(l=null,o.onNodeUnselect&&o.onNodeUnselect({originalEvent:e,node:n})):(l=n,o.onNodeSelect&&o.onNodeSelect({originalEvent:e,node:n})):"multiple"===o.selectionMode&&(u?(l=o.selection.filter((function(e,n){return n!==s})),o.onNodeUnselect&&o.onNodeUnselect({originalEvent:e,node:n})):(l=[].concat(a(m=o.selection||[])||i(m)||c(m)||d(),[n]),o.onNodeSelect&&o.onNodeSelect({originalEvent:e,node:n}))),o.onSelectionChange&&o.onSelectionChange({originalEvent:e,data:l})}var m},isSelected:function(e){return-1!==h(e)}}))})));f.displayName="OrganizationChart",f.defaultProps={__TYPE:"OrganizationChart",id:null,value:null,style:null,className:null,selectionMode:null,selection:null,nodeTemplate:null,onSelectionChange:null,onNodeSelect:null,onNodeUnselect:null};export{f as OrganizationChart};