primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 6.73 kB
JavaScript
import{DomHandler as e}from"primevue/utils";import{resolveComponent as n,openBlock as t,createElementBlock as o,createElementVNode as l,normalizeClass as i,createBlock as s,resolveDynamicComponent as d,withKeys as a,createCommentVNode as c,normalizeStyle as r,Fragment as p,renderList as h,createVNode as g}from"vue";var u={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.hasClass(n.target,"p-node-toggler")||e.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)}},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 y={class:"p-organizationchart-table"},m={key:0},K=["colspan"],b=["colspan"],f=[l("div",{class:"p-organizationchart-line-down"},null,-1)],C=["colspan"],k=[l("div",{class:"p-organizationchart-line-down"},null,-1)];u.render=function(e,u,N,z,v,x){const M=n("OrganizationChartNode",!0);return t(),o("table",y,[l("tbody",null,[N.node?(t(),o("tr",m,[l("td",{colspan:x.colspan},[l("div",{class:i(x.nodeContentClass),onClick:u[2]||(u[2]=(...e)=>x.onNodeClick&&x.onNodeClick(...e))},[(t(),s(d(N.templates[N.node.type]||N.templates.default),{node:N.node},null,8,["node"])),x.toggleable?(t(),o("a",{key:0,tabindex:"0",class:"p-node-toggler",onClick:u[0]||(u[0]=(...e)=>x.toggleNode&&x.toggleNode(...e)),onKeydown:u[1]||(u[1]=a(((...e)=>x.toggleNode&&x.toggleNode(...e)),["enter"]))},[l("i",{class:i(["p-node-toggler-icon pi",{"pi-chevron-down":x.expanded,"pi-chevron-up":!x.expanded}])},null,2)],32)):c("",!0)],2)],8,K)])):c("",!0),l("tr",{style:r(x.childStyle),class:"p-organizationchart-lines"},[l("td",{colspan:x.colspan},f,8,b)],4),l("tr",{style:r(x.childStyle),class:"p-organizationchart-lines"},[N.node.children&&1===N.node.children.length?(t(),o("td",{key:0,colspan:x.colspan},k,8,C)):c("",!0),N.node.children&&N.node.children.length>1?(t(!0),o(p,{key:1},h(N.node.children,((e,n)=>(t(),o(p,{key:e.key},[l("td",{class:i(["p-organizationchart-line-left",{"p-organizationchart-line-top":!(0===n)}])}," ",2),l("td",{class:i(["p-organizationchart-line-right",{"p-organizationchart-line-top":!(n===N.node.children.length-1)}])}," ",2)],64)))),128)):c("",!0)],4),l("tr",{style:r(x.childStyle),class:"p-organizationchart-nodes"},[(t(!0),o(p,null,h(N.node.children,(e=>(t(),o("td",{key:e.key,colspan:"2"},[g(M,{node:e,templates:N.templates,collapsedKeys:N.collapsedKeys,onNodeToggle:x.onChildNodeToggle,collapsible:N.collapsible,selectionMode:N.selectionMode,selectionKeys:N.selectionKeys,onNodeClick:x.onChildNodeClick},null,8,["node","templates","collapsedKeys","onNodeToggle","collapsible","selectionMode","selectionKeys","onNodeClick"])])))),128))],4)])])};var N={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:u}};const z={class:"p-organizationchart p-component"};!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 .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: -.75rem;\n margin-left: -.75rem;\n z-index: 2;\n left: 50%;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\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: .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"),N.render=function(e,l,i,s,d,a){const c=n("OrganizationChartNode");return t(),o("div",z,[g(c,{node:i.value,templates:e.$slots,onNodeToggle:a.onNodeToggle,collapsedKeys:d.d_collapsedKeys,collapsible:i.collapsible,onNodeClick:a.onNodeClick,selectionMode:i.selectionMode,selectionKeys:i.selectionKeys},null,8,["node","templates","onNodeToggle","collapsedKeys","collapsible","onNodeClick","selectionMode","selectionKeys"])])};export{N as default};