primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 10.2 kB
JavaScript
import e from"primevue/basecomponent";import{useStyle as n}from"primevue/usestyle";import t from"primevue/icons/chevrondown";import o from"primevue/icons/chevronup";import{DomHandler as l}from"primevue/utils";import{resolveComponent as i,openBlock as r,createElementBlock as s,mergeProps as a,createElementVNode as c,normalizeProps as d,guardReactiveProps as p,createBlock as u,resolveDynamicComponent as g,createCommentVNode as h,Fragment as y,renderList as f,createVNode as m}from"vue";var b;function v(e){return v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},v(e)}function x(e,n,t){return(n=K(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function K(e){var n=N(e,"string");return"symbol"===v(n)?n:String(n)}function N(e,n){if("object"!==v(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,n||"default");if("object"!==v(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}var O=(x(b={root:"p-organizationchart p-component",table:"p-organizationchart-table",node:function(e){var n=e.instance;return["p-organizationchart-node-content",{"p-organizationchart-selectable-node":n.selectable,"p-highlight":n.selected}]},nodeToggler:"p-node-toggler",nodeTogglerIcon:"p-node-toggler-icon",lines:"p-organizationchart-lines",lineDown:"p-organizationchart-line-down"},"lines","p-organizationchart-lines"),x(b,"lineLeft",(function(e){return["p-organizationchart-line-left",{"p-organizationchart-line-top":!(0===e.index)}]})),x(b,"lineRight",(function(e){return["p-organizationchart-line-right",{"p-organizationchart-line-top":!(e.index===e.props.node.children.length-1)}]})),x(b,"nodes","p-organizationchart-nodes"),b),k=n("\n.p-organizationchart-table {\n border-spacing: 0;\n border-collapse: separate;\n margin: 0 auto;\n}\n\n.p-organizationchart-table > tbody > tr > td {\n text-align: center;\n vertical-align: top;\n padding: 0 0.75rem;\n}\n\n.p-organizationchart-node-content {\n display: inline-block;\n position: relative;\n}\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\n.p-organizationchart-node-content .p-node-toggler .p-node-toggler-icon {\n position: relative;\n top: 0.25rem;\n}\n\n.p-organizationchart-line-down {\n margin: 0 auto;\n height: 20px;\n width: 1px;\n}\n\n.p-organizationchart-line-right {\n border-radius: 0px;\n}\n\n.p-organizationchart-line-left {\n border-radius: 0;\n}\n\n.p-organizationchart-selectable-node {\n cursor: pointer;\n}\n",{name:"organizationchart",manual:!0}),C={name:"BaseOrganizationChart",extends:e,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}},css:{classes:O,loadStyle:k.load},provide:function(){return{$parentInstance:this}}},w={name:"OrganizationChartNode",hostName:"OrganizationChart",extends:e,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:{getPTOptions:function(e){return this.ptm(e,{context:{expanded:this.expanded,selectable:this.selectable,selected:this.selected,toggleable:this.toggleable,active:this.selected}})},getNodeOptions:function(e,n){return this.ptm(n,{context:{lineTop:e}})},onNodeClick:function(e){l.getAttribute(e.target,"nodeToggler")||l.getAttribute(e.target,"nodeTogglerIcon")||this.selectionMode&&this.$emit("node-click",this.node)},onChildNodeClick:function(e){this.$emit("node-click",e)},toggleNode:function(){this.$emit("node-toggle",this.node)},onChildNodeToggle:function(e){this.$emit("node-toggle",e)},onKeydown:function(e){"Enter"!==e.code&&"Space"!==e.code||(this.toggleNode(),e.preventDefault())}},computed:{leaf:function(){return!1!==this.node.leaf&&!(this.node.children&&this.node.children.length)},colspan:function(){return this.node.children&&this.node.children.length?2*this.node.children.length:null},childStyle:function(){return{visibility:!this.leaf&&this.expanded?"inherit":"hidden"}},expanded:function(){return void 0===this.collapsedKeys[this.node.key]},selectable:function(){return this.selectionMode&&!1!==this.node.selectable},selected:function(){return this.selectable&&this.selectionKeys&&!0===this.selectionKeys[this.node.key]},toggleable:function(){return this.collapsible&&!1!==this.node.collapsible&&!this.leaf}},components:{ChevronDownIcon:t,ChevronUpIcon:o}},z=["colspan"],S=["colspan"],T=["colspan"];function P(e){return P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},P(e)}function j(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n&&(o=o.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,o)}return t}function D(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?j(Object(t),!0).forEach((function(n){M(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):j(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function M(e,n,t){return(n=$(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function $(e){var n=I(e,"string");return"symbol"===P(n)?n:String(n)}function I(e,n){if("object"!==P(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,n||"default");if("object"!==P(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}w.render=function(e,n,t,o,l,b){var v=i("OrganizationChartNode",!0);return r(),s("table",a({class:e.cx("table")},e.ptm("table")),[c("tbody",d(p(e.ptm("body"))),[t.node?(r(),s("tr",d(a({key:0},e.ptm("row"))),[c("td",a({colspan:b.colspan},e.ptm("cell")),[c("div",a({class:[e.cx("node"),t.node.styleClass],onClick:n[2]||(n[2]=function(){return b.onNodeClick&&b.onNodeClick.apply(b,arguments)})},b.getPTOptions("node")),[(r(),u(g(t.templates[t.node.type]||t.templates.default),{node:t.node},null,8,["node"])),b.toggleable?(r(),s("a",a({key:0,tabindex:"0",class:e.cx("nodeToggler"),onClick:n[0]||(n[0]=function(){return b.toggleNode&&b.toggleNode.apply(b,arguments)}),onKeydown:n[1]||(n[1]=function(){return b.onKeydown&&b.onKeydown.apply(b,arguments)})},b.getPTOptions("nodeToggler")),[t.templates.togglericon?(r(),u(g(t.templates.togglericon),{key:0,expanded:b.expanded,class:"p-node-toggler-icon"},null,8,["expanded"])):(r(),u(g(b.expanded?"ChevronDownIcon":"ChevronUpIcon"),a({key:1,class:e.cx("nodeTogglerIcon")},b.getPTOptions("nodeTogglerIcon")),null,16,["class"]))],16)):h("",!0)],16)],16,z)],16)):h("",!0),c("tr",a({style:b.childStyle,class:e.cx("lines")},e.ptm("lines")),[c("td",a({colspan:b.colspan},e.ptm("lineCell")),[c("div",a({class:e.cx("lineDown")},e.ptm("lineDown")),null,16)],16,S)],16),c("tr",a({style:b.childStyle,class:e.cx("lines")},e.ptm("lines")),[t.node.children&&1===t.node.children.length?(r(),s("td",a({key:0,colspan:b.colspan},e.ptm("lineCell")),[c("div",a({class:e.cx("lineDown")},e.ptm("lineDown")),null,16)],16,T)):h("",!0),t.node.children&&t.node.children.length>1?(r(!0),s(y,{key:1},f(t.node.children,(function(n,o){return r(),s(y,{key:n.key},[c("td",a({class:e.cx("lineLeft",{index:o})},b.getNodeOptions(!(0===o),"lineLeft"))," ",16),c("td",a({class:e.cx("lineRight",{index:o})},b.getNodeOptions(!(o===t.node.children.length-1),"lineRight"))," ",16)],64)})),128)):h("",!0)],16),c("tr",a({style:b.childStyle,class:e.cx("nodes")},e.ptm("nodes")),[(r(!0),s(y,null,f(t.node.children,(function(n){return r(),s("td",a({key:n.key,colspan:"2"},e.ptm("nodeCell")),[m(v,{node:n,templates:t.templates,collapsedKeys:t.collapsedKeys,onNodeToggle:b.onChildNodeToggle,collapsible:t.collapsible,selectionMode:t.selectionMode,selectionKeys:t.selectionKeys,onNodeClick:b.onChildNodeClick,pt:e.pt,unstyled:e.unstyled},null,8,["node","templates","collapsedKeys","onNodeToggle","collapsible","selectionMode","selectionKeys","onNodeClick","pt","unstyled"])],16)})),128))],16)],16)],16)};var _={name:"OrganizationChart",extends:C,emits:["node-unselect","node-select","update:selectionKeys","node-expand","node-collapse","update:collapsedKeys"],data:function(){return{d_collapsedKeys:this.collapsedKeys||{}}},watch:{collapsedKeys:function(e){this.d_collapsedKeys=e}},methods:{onNodeClick:function(e){var n=e.key;if(this.selectionMode){var t=this.selectionKeys?D({},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:function(e){var 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=D({},this.d_collapsedKeys),this.$emit("update:collapsedKeys",this.d_collapsedKeys)}},components:{OrganizationChartNode:w}};_.render=function(e,n,t,o,l,c){var d=i("OrganizationChartNode");return r(),s("div",a({class:e.cx("root")},e.ptm("root")),[m(d,{node:e.value,templates:e.$slots,onNodeToggle:c.onNodeToggle,collapsedKeys:l.d_collapsedKeys,collapsible:e.collapsible,onNodeClick:c.onNodeClick,selectionMode:e.selectionMode,selectionKeys:e.selectionKeys,pt:e.pt,unstyled:e.unstyled},null,8,["node","templates","onNodeToggle","collapsedKeys","collapsible","onNodeClick","selectionMode","selectionKeys","pt","unstyled"])],16)};export{_ as default};