UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 90+ 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) 6.25 kB
this.primereact=this.primereact||{},this.primereact.organizationchart=function(e,t,n){"use strict";function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var l=r(t);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o.apply(this,arguments)}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function i(e){if(Array.isArray(e))return a(e)}function c(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function s(e,t){if(e){if("string"==typeof e)return a(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)?a(e,t):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.")}var d={defaultProps:{__TYPE:"OrganizationChart",id:null,value:null,style:null,className:null,selectionMode:null,selection:null,nodeTemplate:null,onSelectionChange:null,onNodeSelect:null,onNodeUnselect:null,children:void 0},getProps:function(e){return n.ObjectUtils.getMergedProps(e,d.defaultProps)},getOtherProps:function(e){return n.ObjectUtils.getDiffProps(e,d.defaultProps)}};function f(e){if(Array.isArray(e))return e}function m(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,l,o,a,i=[],c=!0,s=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=o.call(n)).done)&&(i.push(r.value),i.length!==t);c=!0);}catch(e){s=!0,l=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw l}}return i}}function p(){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 h=l.memo((function(e){var t,r,o,a,i,c,u=e.node,d=l.useState(u.expanded),g=(r=2,f(t=d)||m(t,r)||s(t,r)||p()),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",O=function(t,n){e.onNodeClick(t,n)},z=function(){if(!b){var e=n.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 t=e,y((function(e){return!e})),void t.preventDefault();var t}},l.createElement("i",{className:e}))}return null},j=function(){var t=e.nodeTemplate&&n.ObjectUtils.getJSXElement(e.nodeTemplate,u)||u.label;return l.createElement("div",null,t)},C=(o=n.classNames("p-organizationchart-node-content",{"p-organizationchart-selectable-node":e.selectionMode&&!1!==u.selectable,"p-highlight":E},u.className),a=j(),i=z(),l.createElement("tr",null,l.createElement("td",{colSpan:N},l.createElement("div",{className:o,style:u.style,onClick:function(e){return O(e,u)}},a,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"}))),P=(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,t){var r=n.classNames("p-organizationchart-line-left",{"p-organizationchart-line-top":0!==t}),o=n.classNames("p-organizationchart-line-right",{"p-organizationchart-line-top":t!==c-1});return[l.createElement("td",{key:t+"_lineleft",className:r}," "),l.createElement("td",{key:t+"_lineright",className:o}," ")]})))),w=l.createElement("tr",{style:{visibility:S},className:"p-organizationchart-nodes"},u.children&&u.children.map((function(t,n){return l.createElement("td",{key:n,colSpan:"2"},l.createElement(h,{node:t,nodeTemplate:e.nodeTemplate,selectionMode:e.selectionMode,onNodeClick:e.onNodeClick,isSelected:e.isSelected}))})));return l.createElement("table",{className:"p-organizationchart-table"},l.createElement("tbody",null,C,M,P,w))}));h.displayName="OrganizationChartNode";var g=l.memo(l.forwardRef((function(e,t){var r=d.getProps(e),a=l.useRef(null),f=r.value&&r.value.length?r.value[0]:null,m=function(e){if(r.selectionMode&&r.selection){if("single"===r.selectionMode)return r.selection===e?0:-1;if("multiple"===r.selectionMode)return r.selection.findIndex((function(t){return t===e}))}return-1};l.useImperativeHandle(t,(function(){return{props:r,getElement:function(){return a.current}}}));var p=d.getOtherProps(r),g=n.classNames("p-organizationchart p-component",r.className);return l.createElement("div",o({id:r.id,ref:a,style:r.style,className:g},p),l.createElement(h,{node:f,nodeTemplate:r.nodeTemplate,selectionMode:r.selectionMode,onNodeClick:function(e,t){if(r.selectionMode){var l=e.target;if(!1===t.selectable||n.DomHandler.hasClass(l,"p-node-toggler")||n.DomHandler.hasClass(l,"p-node-toggler-icon"))return;var o,a=m(t),d=a>=0;"single"===r.selectionMode?d?(o=null,r.onNodeUnselect&&r.onNodeUnselect({originalEvent:e,node:t})):(o=t,r.onNodeSelect&&r.onNodeSelect({originalEvent:e,node:t})):"multiple"===r.selectionMode&&(d?(o=r.selection.filter((function(e,t){return t!==a})),r.onNodeUnselect&&r.onNodeUnselect({originalEvent:e,node:t})):(o=[].concat(i(f=r.selection||[])||c(f)||s(f)||u(),[t]),r.onNodeSelect&&r.onNodeSelect({originalEvent:e,node:t}))),r.onSelectionChange&&r.onSelectionChange({originalEvent:e,data:o})}var f},isSelected:function(e){return-1!==m(e)}}))})));return g.displayName="OrganizationChart",e.OrganizationChart=g,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils);