UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 7.71 kB
this.primevue=this.primevue||{},this.primevue.organizationchart=function(e,n,o,t){"use strict";function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=l(e),a=l(n),s={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(e){o.DomHandler.hasClass(e.target,"p-node-toggler")||o.DomHandler.hasClass(e.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}},components:{ChevronDownIcon:i.default,ChevronUpIcon:a.default}};const d={class:"p-organizationchart-table"},c={key:0},r=["colspan"],p=["colspan"],h=[t.createElementVNode("div",{class:"p-organizationchart-line-down"},null,-1)],g=["colspan"],m=[t.createElementVNode("div",{class:"p-organizationchart-line-down"},null,-1)];s.render=function(e,n,o,l,i,a){const s=t.resolveComponent("OrganizationChartNode",!0);return t.openBlock(),t.createElementBlock("table",d,[t.createElementVNode("tbody",null,[o.node?(t.openBlock(),t.createElementBlock("tr",c,[t.createElementVNode("td",{colspan:a.colspan},[t.createElementVNode("div",{class:t.normalizeClass(a.nodeContentClass),onClick:n[2]||(n[2]=(...e)=>a.onNodeClick&&a.onNodeClick(...e))},[(t.openBlock(),t.createBlock(t.resolveDynamicComponent(o.templates[o.node.type]||o.templates.default),{node:o.node},null,8,["node"])),a.toggleable?(t.openBlock(),t.createElementBlock("a",{key:0,tabindex:"0",class:"p-node-toggler",onClick:n[0]||(n[0]=(...e)=>a.toggleNode&&a.toggleNode(...e)),onKeydown:n[1]||(n[1]=(...e)=>a.onKeydown&&a.onKeydown(...e))},[o.templates.togglericon?(t.openBlock(),t.createBlock(t.resolveDynamicComponent(o.templates.togglericon),{key:0,expanded:a.expanded,class:"p-node-toggler-icon"},null,8,["expanded"])):(t.openBlock(),t.createBlock(t.resolveDynamicComponent(a.expanded?"ChevronDownIcon":"ChevronUpIcon"),{key:1,class:"p-node-toggler-icon"}))],32)):t.createCommentVNode("",!0)],2)],8,r)])):t.createCommentVNode("",!0),t.createElementVNode("tr",{style:t.normalizeStyle(a.childStyle),class:"p-organizationchart-lines"},[t.createElementVNode("td",{colspan:a.colspan},h,8,p)],4),t.createElementVNode("tr",{style:t.normalizeStyle(a.childStyle),class:"p-organizationchart-lines"},[o.node.children&&1===o.node.children.length?(t.openBlock(),t.createElementBlock("td",{key:0,colspan:a.colspan},m,8,g)):t.createCommentVNode("",!0),o.node.children&&o.node.children.length>1?(t.openBlock(!0),t.createElementBlock(t.Fragment,{key:1},t.renderList(o.node.children,((e,n)=>(t.openBlock(),t.createElementBlock(t.Fragment,{key:e.key},[t.createElementVNode("td",{class:t.normalizeClass(["p-organizationchart-line-left",{"p-organizationchart-line-top":!(0===n)}])}," ",2),t.createElementVNode("td",{class:t.normalizeClass(["p-organizationchart-line-right",{"p-organizationchart-line-top":!(n===o.node.children.length-1)}])}," ",2)],64)))),128)):t.createCommentVNode("",!0)],4),t.createElementVNode("tr",{style:t.normalizeStyle(a.childStyle),class:"p-organizationchart-nodes"},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.node.children,(e=>(t.openBlock(),t.createElementBlock("td",{key:e.key,colspan:"2"},[t.createVNode(s,{node:e,templates:o.templates,collapsedKeys:o.collapsedKeys,onNodeToggle:a.onChildNodeToggle,collapsible:o.collapsible,selectionMode:o.selectionMode,selectionKeys:o.selectionKeys,onNodeClick:a.onChildNodeClick},null,8,["node","templates","collapsedKeys","onNodeToggle","collapsible","selectionMode","selectionKeys","onNodeClick"])])))),128))],4)])])};var u={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 o=this.selectionKeys?{...this.selectionKeys}:{};o[n]?(delete o[n],this.$emit("node-unselect",e)):("single"===this.selectionMode&&(o={}),o[n]=!0,this.$emit("node-select",e)),this.$emit("update:selectionKeys",o)}},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:s}};const y={class:"p-organizationchart p-component"};return function(e,n){void 0===n&&(n={});var o=n.insertAt;if(e&&"undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],l=document.createElement("style");l.type="text/css","top"===o&&t.firstChild?t.insertBefore(l,t.firstChild):t.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"),u.render=function(e,n,o,l,i,a){const s=t.resolveComponent("OrganizationChartNode");return t.openBlock(),t.createElementBlock("div",y,[t.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"])])},u}(primevue.icons.chevrondown,primevue.icons.chevronup,primevue.utils,Vue);