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.19 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils");function n(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 r=n(e);function l(){return l=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},l.apply(this,arguments)}function o(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 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,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.")}var u={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 t.ObjectUtils.getMergedProps(e,u.defaultProps)},getOtherProps:function(e){return t.ObjectUtils.getDiffProps(e,u.defaultProps)}};function d(e){if(Array.isArray(e))return e}function f(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 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=r.memo((function(e){var n,l,o,a,i,s,u=e.node,h=r.useState(u.expanded),g=(l=2,d(n=h)||f(n,l)||c(n,l)||m()),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)},j=function(){if(!b){var e=t.classNames("p-node-toggler-icon",{"pi pi-chevron-down":v,"pi pi-chevron-up":!v});return r.createElement("a",{href:"#",className:"p-node-toggler",onClick:function(e){return t=e,y((function(e){return!e})),void t.preventDefault();var t}},r.createElement("i",{className:e}))}return null},z=function(){var n=e.nodeTemplate&&t.ObjectUtils.getJSXElement(e.nodeTemplate,u)||u.label;return r.createElement("div",null,n)},C=(o=t.classNames("p-organizationchart-node-content",{"p-organizationchart-selectable-node":e.selectionMode&&!1!==u.selectable,"p-highlight":E},u.className),a=z(),i=j(),r.createElement("tr",null,r.createElement("td",{colSpan:N},r.createElement("div",{className:o,style:u.style,onClick:function(e){return O(e,u)}},a,i)))),M=r.createElement("tr",{style:{visibility:S},className:"p-organizationchart-lines"},r.createElement("td",{colSpan:N},r.createElement("div",{className:"p-organizationchart-line-down"}))),P=(s=u.children&&u.children.length,r.createElement("tr",{style:{visibility:S},className:"p-organizationchart-lines"},u.children&&1===u.children.length&&r.createElement("td",{colSpan:N},r.createElement("div",{className:"p-organizationchart-line-down"})),u.children&&u.children.length>1&&u.children.map((function(e,n){var l=t.classNames("p-organizationchart-line-left",{"p-organizationchart-line-top":0!==n}),o=t.classNames("p-organizationchart-line-right",{"p-organizationchart-line-top":n!==s-1});return[r.createElement("td",{key:n+"_lineleft",className:l}," "),r.createElement("td",{key:n+"_lineright",className:o}," ")]})))),w=r.createElement("tr",{style:{visibility:S},className:"p-organizationchart-nodes"},u.children&&u.children.map((function(t,n){return r.createElement("td",{key:n,colSpan:"2"},r.createElement(p,{node:t,nodeTemplate:e.nodeTemplate,selectionMode:e.selectionMode,onNodeClick:e.onNodeClick,isSelected:e.isSelected}))})));return r.createElement("table",{className:"p-organizationchart-table"},r.createElement("tbody",null,C,M,P,w))}));p.displayName="OrganizationChartNode";var h=r.memo(r.forwardRef((function(e,n){var o=u.getProps(e),d=r.useRef(null),f=o.value&&o.value.length?o.value[0]:null,m=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(t){return t===e}))}return-1};r.useImperativeHandle(n,(function(){return{props:o,getElement:function(){return d.current}}}));var h=u.getOtherProps(o),g=t.classNames("p-organizationchart p-component",o.className);return r.createElement("div",l({id:o.id,ref:d,style:o.style,className:g},h),r.createElement(p,{node:f,nodeTemplate:o.nodeTemplate,selectionMode:o.selectionMode,onNodeClick:function(e,n){if(o.selectionMode){var r=e.target;if(!1===n.selectable||t.DomHandler.hasClass(r,"p-node-toggler")||t.DomHandler.hasClass(r,"p-node-toggler-icon"))return;var l,u=m(n),d=u>=0;"single"===o.selectionMode?d?(l=null,o.onNodeUnselect&&o.onNodeUnselect({originalEvent:e,node:n})):(l=n,o.onNodeSelect&&o.onNodeSelect({originalEvent:e,node:n})):"multiple"===o.selectionMode&&(d?(l=o.selection.filter((function(e,t){return t!==u})),o.onNodeUnselect&&o.onNodeUnselect({originalEvent:e,node:n})):(l=[].concat(a(f=o.selection||[])||i(f)||c(f)||s(),[n]),o.onNodeSelect&&o.onNodeSelect({originalEvent:e,node:n}))),o.onSelectionChange&&o.onSelectionChange({originalEvent:e,data:l})}var f},isSelected:function(e){return-1!==m(e)}}))})));h.displayName="OrganizationChart",exports.OrganizationChart=h;