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.99 kB
this.primereact=this.primereact||{},this.primereact.organizationchart=function(e,n,t){"use strict";function r(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})}})),n.default=e,Object.freeze(n)}var l=r(n);function a(){return a=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},a.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 i(e){if(Array.isArray(e))return o(e)}function c(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function s(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 u(){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){if(Array.isArray(e))return e}function m(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,l,a=[],o=!0,i=!1;try{for(t=t.call(e);!(o=(r=t.next()).done)&&(a.push(r.value),!n||a.length!==n);o=!0);}catch(e){i=!0,l=e}finally{try{o||null==t.return||t.return()}finally{if(i)throw l}}return a}}function f(){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=l.memo((function(e){var n,r,a,o,i,c,u=e.node,h=l.useState(u.expanded),g=(r=2,d(n=h)||m(n,r)||s(n,r)||f()),v=g[0],y=g[1],b=!1!==u.leaf&&!(u.children&&u.children.length),N=u.children&&u.children.length?2*u.children.length:null,E=e.isSelected(u),S=!b&&v?"inherit":"hidden",z=function(n,t){e.onNodeClick(n,t)},O=function(){if(!b){var e=t.classNames("p-node-toggler-icon",{"pi pi-chevron-down":v,"pi pi-chevron-up":!v});return l.createElement("a",{href:"#",className:"p-node-toggler",onClick:function(e){return n=e,y((function(e){return!e})),void n.preventDefault();var n}},l.createElement("i",{className:e}))}return null},C=function(){var n=e.nodeTemplate&&t.ObjectUtils.getJSXElement(e.nodeTemplate,u)||u.label;return l.createElement("div",null,n)},j=(a=t.classNames("p-organizationchart-node-content",{"p-organizationchart-selectable-node":e.selectionMode&&!1!==u.selectable,"p-highlight":E},u.className),o=C(),i=O(),l.createElement("tr",null,l.createElement("td",{colSpan:N},l.createElement("div",{className:a,onClick:function(e){return z(e,u)}},o,i)))),M=l.createElement("tr",{style:{visibility:S},className:"p-organizationchart-lines"},l.createElement("td",{colSpan:N},l.createElement("div",{className:"p-organizationchart-line-down"}))),w=(c=u.children&&u.children.length,l.createElement("tr",{style:{visibility:S},className:"p-organizationchart-lines"},u.children&&1===u.children.length&&l.createElement("td",{colSpan:N},l.createElement("div",{className:"p-organizationchart-line-down"})),u.children&&u.children.length>1&&u.children.map((function(e,n){var r=t.classNames("p-organizationchart-line-left",{"p-organizationchart-line-top":0!==n}),a=t.classNames("p-organizationchart-line-right",{"p-organizationchart-line-top":n!==c-1});return[l.createElement("td",{key:n+"_lineleft",className:r}," "),l.createElement("td",{key:n+"_lineright",className:a}," ")]})))),k=l.createElement("tr",{style:{visibility:S},className:"p-organizationchart-nodes"},u.children&&u.children.map((function(n,t){return l.createElement("td",{key:t,colSpan:"2"},l.createElement(p,{node:n,nodeTemplate:e.nodeTemplate,selectionMode:e.selectionMode,onNodeClick:e.onNodeClick,isSelected:e.isSelected}))})));return l.createElement("table",{className:"p-organizationchart-table"},l.createElement("tbody",null,j,M,w,k))}));p.displayName="OrganizationChartNode";var h=l.memo(l.forwardRef((function(e,n){var r=l.useRef(null),o=e.value&&e.value.length?e.value[0]:null,d=function(n){if(e.selectionMode&&e.selection){if("single"===e.selectionMode)return e.selection===n?0:-1;if("multiple"===e.selectionMode)return e.selection.findIndex((function(e){return e===n}))}return-1};l.useImperativeHandle(n,(function(){return{props:e,getElement:function(){return r.current}}}));var m=t.ObjectUtils.findDiffKeys(e,h.defaultProps),f=t.classNames("p-organizationchart p-component",e.className);return l.createElement("div",a({id:e.id,ref:r,style:e.style,className:f},m),l.createElement(p,{node:o,nodeTemplate:e.nodeTemplate,selectionMode:e.selectionMode,onNodeClick:function(n,r){if(e.selectionMode){var l=n.target;if(!1===r.selectable||!t.DomHandler.hasClass(l,"p-node-toggler")||!t.DomHandler.hasClass(l,"p-node-toggler-icon"))return;var a,o=d(r),m=o>=0;"single"===e.selectionMode?m?(a=null,e.onNodeUnselect&&e.onNodeUnselect({originalEvent:n,node:r})):(a=r,e.onNodeSelect&&e.onNodeSelect({originalEvent:n,node:r})):"multiple"===e.selectionMode&&(m?(a=e.selection.filter((function(e,n){return n!==o})),e.onNodeUnselect&&e.onNodeUnselect({originalEvent:n,node:r})):(a=[].concat(i(f=e.selection||[])||c(f)||s(f)||u(),[r]),e.onNodeSelect&&e.onNodeSelect({originalEvent:n,node:r}))),e.onSelectionChange&&e.onSelectionChange({originalEvent:n,data:a})}var f},isSelected:function(e){return-1!==d(e)}}))})));return h.displayName="OrganizationChart",h.defaultProps={__TYPE:"OrganizationChart",id:null,value:null,style:null,className:null,selectionMode:null,selection:null,nodeTemplate:null,onSelectionChange:null,onNodeSelect:null,onNodeUnselect:null},e.OrganizationChart=h,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils);