primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 7.33 kB
JavaScript
this.primevue=this.primevue||{},this.primevue.organizationchart=function(e,n){"use strict";var t={name:"OrganizationChartNode",emits:["node-click","node-toggle"],props:{node:{type:null,default:null},templates:{type:null,default:null},collapsible:{type:Boolean,default:!1},collapsedKeys:{type:null,default:null},selectionKeys:{type:null,default:null},selectionMode:{type:String,default:null}},methods:{onNodeClick(n){e.DomHandler.hasClass(n.target,"p-node-toggler")||e.DomHandler.hasClass(n.target,"p-node-toggler-icon")||this.selectionMode&&this.$emit("node-click",this.node)},onChildNodeClick(e){this.$emit("node-click",e)},toggleNode(){this.$emit("node-toggle",this.node)},onChildNodeToggle(e){this.$emit("node-toggle",e)},onKeydown(e){"Enter"!==e.code&&"Space"!==e.code||(this.toggleNode(),e.preventDefault())}},computed:{nodeContentClass(){return["p-organizationchart-node-content",this.node.styleClass,{"p-organizationchart-selectable-node":this.selectable,"p-highlight":this.selected}]},leaf(){return!1!==this.node.leaf&&!(this.node.children&&this.node.children.length)},colspan(){return this.node.children&&this.node.children.length?2*this.node.children.length:null},childStyle(){return{visibility:!this.leaf&&this.expanded?"inherit":"hidden"}},expanded(){return void 0===this.collapsedKeys[this.node.key]},selectable(){return this.selectionMode&&!1!==this.node.selectable},selected(){return this.selectable&&this.selectionKeys&&!0===this.selectionKeys[this.node.key]},toggleable(){return this.collapsible&&!1!==this.node.collapsible&&!this.leaf}}};const o={class:"p-organizationchart-table"},l={key:0},i=["colspan"],a=["colspan"],s=[n.createElementVNode("div",{class:"p-organizationchart-line-down"},null,-1)],d=["colspan"],c=[n.createElementVNode("div",{class:"p-organizationchart-line-down"},null,-1)];t.render=function(e,t,r,p,h,g){const m=n.resolveComponent("OrganizationChartNode",!0);return n.openBlock(),n.createElementBlock("table",o,[n.createElementVNode("tbody",null,[r.node?(n.openBlock(),n.createElementBlock("tr",l,[n.createElementVNode("td",{colspan:g.colspan},[n.createElementVNode("div",{class:n.normalizeClass(g.nodeContentClass),onClick:t[2]||(t[2]=(...e)=>g.onNodeClick&&g.onNodeClick(...e))},[(n.openBlock(),n.createBlock(n.resolveDynamicComponent(r.templates[r.node.type]||r.templates.default),{node:r.node},null,8,["node"])),g.toggleable?(n.openBlock(),n.createElementBlock("a",{key:0,tabindex:"0",class:"p-node-toggler",onClick:t[0]||(t[0]=(...e)=>g.toggleNode&&g.toggleNode(...e)),onKeydown:t[1]||(t[1]=(...e)=>g.onKeydown&&g.onKeydown(...e))},[n.createElementVNode("i",{class:n.normalizeClass(["p-node-toggler-icon pi",{"pi-chevron-down":g.expanded,"pi-chevron-up":!g.expanded}])},null,2)],32)):n.createCommentVNode("",!0)],2)],8,i)])):n.createCommentVNode("",!0),n.createElementVNode("tr",{style:n.normalizeStyle(g.childStyle),class:"p-organizationchart-lines"},[n.createElementVNode("td",{colspan:g.colspan},s,8,a)],4),n.createElementVNode("tr",{style:n.normalizeStyle(g.childStyle),class:"p-organizationchart-lines"},[r.node.children&&1===r.node.children.length?(n.openBlock(),n.createElementBlock("td",{key:0,colspan:g.colspan},c,8,d)):n.createCommentVNode("",!0),r.node.children&&r.node.children.length>1?(n.openBlock(!0),n.createElementBlock(n.Fragment,{key:1},n.renderList(r.node.children,((e,t)=>(n.openBlock(),n.createElementBlock(n.Fragment,{key:e.key},[n.createElementVNode("td",{class:n.normalizeClass(["p-organizationchart-line-left",{"p-organizationchart-line-top":!(0===t)}])}," ",2),n.createElementVNode("td",{class:n.normalizeClass(["p-organizationchart-line-right",{"p-organizationchart-line-top":!(t===r.node.children.length-1)}])}," ",2)],64)))),128)):n.createCommentVNode("",!0)],4),n.createElementVNode("tr",{style:n.normalizeStyle(g.childStyle),class:"p-organizationchart-nodes"},[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(r.node.children,(e=>(n.openBlock(),n.createElementBlock("td",{key:e.key,colspan:"2"},[n.createVNode(m,{node:e,templates:r.templates,collapsedKeys:r.collapsedKeys,onNodeToggle:g.onChildNodeToggle,collapsible:r.collapsible,selectionMode:r.selectionMode,selectionKeys:r.selectionKeys,onNodeClick:g.onChildNodeClick},null,8,["node","templates","collapsedKeys","onNodeToggle","collapsible","selectionMode","selectionKeys","onNodeClick"])])))),128))],4)])])};var r={name:"OrganizationChart",emits:["node-unselect","node-select","update:selectionKeys","node-expand","node-collapse","update:collapsedKeys"],props:{value:{type:null,default:null},selectionKeys:{type:null,default:null},selectionMode:{type:String,default:null},collapsible:{type:Boolean,default:!1},collapsedKeys:{type:null,default:null}},data(){return{d_collapsedKeys:this.collapsedKeys||{}}},watch:{collapsedKeys(e){this.d_collapsedKeys=e}},methods:{onNodeClick(e){const n=e.key;if(this.selectionMode){let t=this.selectionKeys?{...this.selectionKeys}:{};t[n]?(delete t[n],this.$emit("node-unselect",e)):("single"===this.selectionMode&&(t={}),t[n]=!0,this.$emit("node-select",e)),this.$emit("update:selectionKeys",t)}},onNodeToggle(e){const n=e.key;this.d_collapsedKeys[n]?(delete this.d_collapsedKeys[n],this.$emit("node-expand",e)):(this.d_collapsedKeys[n]=!0,this.$emit("node-collapse",e)),this.d_collapsedKeys={...this.d_collapsedKeys},this.$emit("update:collapsedKeys",this.d_collapsedKeys)}},components:{OrganizationChartNode:t}};const p={class:"p-organizationchart p-component"};return function(e,n){void 0===n&&(n={});var t=n.insertAt;if(e&&"undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],l=document.createElement("style");l.type="text/css","top"===t&&o.firstChild?o.insertBefore(l,o.firstChild):o.appendChild(l),l.styleSheet?l.styleSheet.cssText=e:l.appendChild(document.createTextNode(e))}}("\n.p-organizationchart-table {\n border-spacing: 0;\n border-collapse: separate;\n margin: 0 auto;\n}\n.p-organizationchart-table > tbody > tr > td {\n text-align: center;\n vertical-align: top;\n padding: 0 0.75rem;\n}\n.p-organizationchart-node-content {\n display: inline-block;\n position: relative;\n}\n.p-organizationchart-node-content .p-node-toggler {\n position: absolute;\n bottom: -0.75rem;\n margin-left: -0.75rem;\n z-index: 2;\n left: 50%;\n user-select: none;\n cursor: pointer;\n width: 1.5rem;\n height: 1.5rem;\n text-decoration: none;\n}\n.p-organizationchart-node-content .p-node-toggler .p-node-toggler-icon {\n position: relative;\n top: 0.25rem;\n}\n.p-organizationchart-line-down {\n margin: 0 auto;\n height: 20px;\n width: 1px;\n}\n.p-organizationchart-line-right {\n border-radius: 0px;\n}\n.p-organizationchart-line-left {\n border-radius: 0;\n}\n.p-organizationchart-selectable-node {\n cursor: pointer;\n}\n"),r.render=function(e,t,o,l,i,a){const s=n.resolveComponent("OrganizationChartNode");return n.openBlock(),n.createElementBlock("div",p,[n.createVNode(s,{node:o.value,templates:e.$slots,onNodeToggle:a.onNodeToggle,collapsedKeys:i.d_collapsedKeys,collapsible:o.collapsible,onNodeClick:a.onNodeClick,selectionMode:o.selectionMode,selectionKeys:o.selectionKeys},null,8,["node","templates","onNodeToggle","collapsedKeys","collapsible","onNodeClick","selectionMode","selectionKeys"])])},r}(primevue.utils,Vue);