UNPKG

jiku-ui

Version:

A Component Library for Vue.js.

2 lines (1 loc) 16.7 kB
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=73)}({0:function(e,t,n){"use strict";function r(e,t,n,r,i,o,a,s){var d,l="function"==typeof e?e.options:e;if(t&&(l.render=t,l.staticRenderFns=n,l._compiled=!0),r&&(l.functional=!0),o&&(l._scopeId="data-v-"+o),a?(d=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),i&&i.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(a)},l._ssrRegister=d):i&&(d=s?function(){i.call(this,(l.functional?this.parent:this).$root.$options.shadowRoot)}:i),d)if(l.functional){l._injectStyles=d;var h=l.render;l.render=function(e,t){return d.call(t),h(e,t)}}else{var u=l.beforeCreate;l.beforeCreate=u?[].concat(u,d):[d]}return{exports:e,options:l}}n.d(t,"a",(function(){return r}))},20:function(e,t){e.exports=require("jiku-ui/lib/locale")},21:function(e,t){e.exports=require("jiku-ui/lib/transitions/collapse-transition")},3:function(e,t){e.exports=require("jiku-ui/lib/utils/util")},4:function(e,t){e.exports=require("jiku-ui/lib/mixins/emitter")},73:function(e,t,n){"use strict";n.r(t);var r=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"hn-easy-tree",class:{"hn-easy-tree--highlight-current":e.highlightCurrent},attrs:{role:"tree"}},[e._l(e.root.childNodes,(function(t){return n("hn-tree-node",{key:e.getNodeKey(t),attrs:{node:t,props:e.props,"render-after-expand":e.renderAfterExpand,"render-content":e.renderContent,"show-branch":e.showBranch},on:{"node-expand":e.handleNodeExpand}})})),e.isEmpty?n("div",{staticClass:"hn-easy-tree__empty-block"},[n("span",{staticClass:"hn-easy-tree__empty-text"},[e._v(e._s(e.emptyText))])]):e._e()],2)};r._withStripped=!0;var i=n(4),o=n.n(i),a=n(20),s=function(){var e=this,t=this,n=t.$createElement,r=t._self._c||n;return r("div",{ref:"node",staticClass:"hn-easy-tree-node",class:{"is-expanded":t.expanded,"is-current":t.node.isCurrent,"is-last-child":t.node.isLastChild,"is-leaf":t.node.isLeaf},attrs:{role:"treeitem",tabindex:"-1","aria-expanded":t.expanded},on:{click:function(e){return e.stopPropagation(),t.handleClick(e)},contextmenu:function(t){return e.handleContextMenu(t)}}},[r("div",{staticClass:"hn-easy-tree-node__content",style:{"padding-left":(t.node.level-1)*t.tree.indent+"px"}},[t.showBranch&&1!==t.node.level?r("tree-branch",{attrs:{indent:t.tree.indent,"hide-bottom":t.node.parent.isLastChild&&t.node.isLastChild,"hide-vertical-positions":t.collectHideVertical(),node:t.node}}):t._e(),t.node.isLeaf?t._e():r("span",{class:["hn-easy-tree-node__expand-icon",t.tree.iconClass?t.tree.iconClass:"hn-iconfont-user"],on:{click:function(e){return e.stopPropagation(),t.handleExpandIconClick(e)}}}),r("node-content",{attrs:{node:t.node}})],1),r("hn-collapse-transition",[!t.renderAfterExpand||t.childNodeRendered?r("div",{directives:[{name:"show",rawName:"v-show",value:t.expanded,expression:"expanded"}],staticClass:"hn-easy-tree-node__children",attrs:{role:"group","aria-expanded":t.expanded}},t._l(t.node.childNodes,(function(e){return r("hn-tree-node",{key:t.getNodeKey(e),attrs:{"render-content":t.renderContent,"render-after-expand":t.renderAfterExpand,node:e,"show-branch":t.showBranch},on:{"node-expand":t.handleChildNodeExpand}})})),1):t._e()])],1)};s._withStripped=!0;var d=n(21),l=n.n(d),h=function(e,t){var n=t._c;return n("div",{staticClass:"hn-easy-tree-branch",style:{marginLeft:-t.props.indent/2+"px"}},[n("div",{staticClass:"hn-easy-tree-branch__top"}),n("div",{staticClass:"hn-easy-tree-branch__right"}),t.props.hideBottom?t._e():n("div",{staticClass:"hn-easy-tree-branch__bottom"}),t.props.node.level>2?t._l(Array(t.props.node.level-2).fill().map((function(e,t){return t})).filter((function(e){return!t.props.hideVerticalPositions.includes(e)})),(function(e){return n("span",{key:"tree-branch"+e,staticClass:"hn-easy-tree-branch__vertical",style:{left:-t.props.indent*(t.props.node.level-2-e)+"px"}})})):t._e()],2)};h._withStripped=!0;var u={name:"HnTreeBranch",props:{node:{type:Object,required:!0},indent:{type:Number,required:!0},hideBottom:{type:Boolean,default:!1},hideVerticalPositions:{type:Array,default:[]}}},c=n(0),p=Object(c.a)(u,h,[],!0,null,null,null);p.options.__file="packages/easy-tree/src/tree-branch.vue";var f=p.exports,y="$treeNodeId",v=function(e,t){t&&!t[y]&&Object.defineProperty(t,y,{value:e.id,enumerable:!1,configurable:!1,writable:!1})},C=function(e,t){return e?t[e]:t[y]},x={name:"HnTreeNode",componentName:"HnTreeNode",mixins:[o.a],props:{node:{default:function(){return{}}},renderContent:Function,renderAfterExpand:{type:Boolean,default:!0},showBranch:{type:Boolean,default:!0}},components:{HNCollapseTransition:l.a,TreeBranch:f,NodeContent:{props:{node:{required:!0}},render:function(e){var t=this.$parent,n=t.tree,r=this.node,i=r.data,o=r.store;return t.renderContent?t.renderContent.call(t._renderProxy,e,{_self:n.$vnode.context,node:r,data:i,store:o}):n.$scopedSlots.default?n.$scopedSlots.default({node:r,data:i}):e("span",{class:"hn-easy-tree-node__label"},[r.label])}}},data:function(){return{tree:null,expanded:!1,childNodeRendered:!1}},watch:{"node.expanded":function(e){var t=this;this.$nextTick((function(){return t.expanded=e})),e&&(this.childNodeRendered=!0)}},methods:{collectHideVertical:function(){for(var e=[],t=this.node.parent;t;)t.isLastChild&&t.parent&&t.parent.isLastChild&&e.push(t.level-2),t=t.parent;return e},getNodeKey:function(e){return C(this.tree.nodeKey,e.data)},handleClick:function(){var e=this.tree.store;e.setCurrentNode(this.node),this.tree.$emit("current-change",e.currentNode?e.currentNode.data:null,e.currentNode),this.tree.currentNode=this,this.tree.expandOnClickNode&&this.handleExpandIconClick(),this.tree.$emit("node-click",this.node.data,this.node,this)},handleContextMenu:function(e){this.tree._events["node-contextmenu"]&&this.tree._events["node-contextmenu"].length>0&&(e.stopPropagation(),e.preventDefault()),this.tree.$emit("node-contextmenu",e,this.node.data,this.node,this)},handleExpandIconClick:function(){this.node.isLeaf||(this.expanded?(this.tree.$emit("node-collapse",this.node.data,this.node,this),this.node.collapse()):(this.node.expand(),this.$emit("node-expand",this.node.data,this.node,this)))},handleChildNodeExpand:function(e,t,n){this.broadcast("HnTreeNode","tree-node-expand",t),this.tree.$emit("node-expand",e,t,n)}},created:function(){var e=this,t=this.$parent;t.isTree?this.tree=t:this.tree=t.tree;var n=this.tree;n||console.warn("Can not find node's tree.");var r=(n.props||{}).children||"children";this.$watch("node.data."+r,(function(){e.node.updateChildren()})),this.node.expanded&&(this.expanded=!0,this.childNodeRendered=!0),this.tree.accordion&&this.$on("tree-node-expand",(function(t){e.node!==t&&e.node.collapse()}))}},N=Object(c.a)(x,s,[],!1,null,null,null);N.options.__file="packages/easy-tree/src/tree-node.vue";var m=N.exports,g=n(9),b=n.n(g),_=n(3),w=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var E=function(e,t){var n=e.store.props,r=e.data||{},i=n[t];if("function"==typeof i)return i(r,e);if("string"==typeof i)return r[i];if(void 0===i){var o=r[t];return void 0===o?"":o}},k=0,S=function(){function e(t){for(var n in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.id=k++,this.text=null,this.data=null,this.expanded=!1,this.parent=null,this.isCurrent=!1,this.isLastChild=!1,t)t.hasOwnProperty(n)&&(this[n]=t[n]);this.level=0,this.childNodes=[],this.parent&&(this.level=this.parent.level+1);var r=this.store;if(!r)throw new Error("[Node]store is required!");(r.registerNode(this),this.data&&(this.setData(this.data),r.defaultExpandAll&&(this.expanded=!0)),Array.isArray(this.data)||v(this,this.data),this.data)&&(r.key&&void 0!==r.currentNodeKey&&this.key===r.currentNodeKey&&(r.currentNode=this,r.currentNode.isCurrent=!0),this.updateLeafState(),this.updateLastChildState())}return e.prototype.setData=function(e){Array.isArray(e)||v(this,e),this.data=e,this.childNodes=[];for(var t=void 0,n=0,r=(t=0===this.level&&this.data instanceof Array?this.data:E(this,"children")||[]).length;n<r;n++)this.insertChild({data:t[n]})},e.prototype.remove=function(){var e=this.parent;e&&e.removeChild(this)},e.prototype.insertChild=function(t,n,r){if(!t)throw new Error("insertChild error: child is required.");if(!(t instanceof e)){if(!r){var i=this.getChildren(!0);-1===i.indexOf(t.data)&&(void 0===n||n<0?i.push(t.data):i.splice(n,0,t.data))}b()(t,{parent:this,store:this.store}),t=new e(t)}t.level=this.level+1,void 0===n||n<0?this.childNodes.push(t):this.childNodes.splice(n,0,t),this.updateLeafState(),this.updateLastChildState()},e.prototype.removeChild=function(e){var t=this.getChildren()||[],n=t.indexOf(e.data);n>-1&&t.splice(n,1);var r=this.childNodes.indexOf(e);r>-1&&(this.store&&this.store.deregisterNode(e),e.parent=null,this.childNodes.splice(r,1)),this.updateLeafState(),this.updateLastChildState()},e.prototype.removeChildByData=function(e){for(var t=null,n=0;n<this.childNodes.length;n++)if(this.childNodes[n].data===e){t=this.childNodes[n];break}t&&this.removeChild(t)},e.prototype.expand=function(e){var t=this;!function(){for(var n=t.parent;n.level>0;)n.expanded=!0,n=n.parent;t.expanded=!0,e&&e()}()},e.prototype.doCreateChildren=function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e.forEach((function(e){t.insertChild(b()({data:e},n),void 0,!0)}))},e.prototype.collapse=function(){this.expanded=!1},e.prototype.updateLeafState=function(){var e=this.childNodes;this.isLeaf=!e||0===e.length},e.prototype.updateLastChildState=function(){if(this.store.showBranch){var e=this.getParentChildren(),t=e[e.length-1]===this.data;this.isLastChild=t}},e.prototype.getChildren=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(0===this.level)return this.data;var t=this.data;if(!t)return null;var n=this.store.props,r="children";return n&&(r=n.children||"children"),void 0===t[r]&&(t[r]=null),e&&!t[r]&&(t[r]=[]),t[r]},e.prototype.getParentChildren=function(){var e=this.parent;if(!e)return[];if(1===this.level)return e.data;var t=this.store.props,n="children";return t&&(n=t.children||"children"),e.data[n]||[]},e.prototype.updateChildren=function(){var e=this,t=this.getChildren()||[],n=this.childNodes.map((function(e){return e.data})),r={},i=[];t.forEach((function(e,t){var o=e[y];!!o&&Object(_.arrayFindIndex)(n,(function(e){return e[y]===o}))>=0?r[o]={index:t,data:e}:i.push({index:t,data:e})})),n.forEach((function(t){r[t[y]]||e.removeChildByData(t)})),i.forEach((function(t){var n=t.index,r=t.data;e.insertChild({data:r},n)})),this.updateLeafState(),this.updateLastChildState()},w(e,[{key:"label",get:function(){return E(this,"label")}},{key:"key",get:function(){var e=this.store.key;return this.data?this.data[e]:null}}]),e}(),K="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};var O=function(){function e(t){for(var n in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.currentNode=null,this.currentNodeKey=null,t)t.hasOwnProperty(n)&&(this[n]=t[n]);this.nodesMap={},this.root=new S({data:this.data,store:this})}return e.prototype.setData=function(e){e!==this.root.data?this.root.setData(e):this.root.updateChildren()},e.prototype.getNode=function(e){if(e instanceof S)return e;var t="object"!==(void 0===e?"undefined":K(e))?e:C(this.key,e);return this.nodesMap[t]||null},e.prototype.remove=function(e){var t=this.getNode(e);t&&t.parent&&(t===this.currentNode&&(this.currentNode=null),t.parent.removeChild(t))},e.prototype.append=function(e,t){var n=t?this.getNode(t):this.root;n&&n.insertChild({data:e})},e.prototype.registerNode=function(e){this.key&&e&&e.data&&(void 0!==e.key&&(this.nodesMap[e.key]=e))},e.prototype.deregisterNode=function(e){var t=this;this.key&&e&&e.data&&(e.childNodes.forEach((function(e){t.deregisterNode(e)})),delete this.nodesMap[e.key])},e.prototype.updateChildren=function(e,t){var n=this.nodesMap[e];if(n){for(var r=n.childNodes,i=r.length-1;i>=0;i--){var o=r[i];this.remove(o.data)}for(var a=0,s=t.length;a<s;a++){var d=t[a];this.append(d,n.data)}}},e.prototype.getCurrentNode=function(){return this.currentNode},e.prototype.setCurrentNode=function(e){var t=this.currentNode;t&&(t.isCurrent=!1),this.currentNode=e,this.currentNode.isCurrent=!0},e.prototype.setUserCurrentNode=function(e){var t=e[this.key],n=this.nodesMap[t];this.setCurrentNode(n)},e.prototype.setCurrentNodeKey=function(e){if(null===e)return this.currentNode.isCurrent=!1,void(this.currentNode=null);var t=this.getNode(e);t&&this.setCurrentNode(t)},e}(),T={name:"HnEasyTree",mixins:[o.a],components:{HnTreeNode:m},data:function(){return{store:null,root:null,currentNode:null,treeItems:null}},props:{data:{type:Array},emptyText:{type:String,default:function(){return Object(a.t)("hn.easyTree.emptyText")}},renderAfterExpand:{type:Boolean,default:!0},nodeKey:String,defaultExpandAll:Boolean,expandOnClickNode:{type:Boolean,default:!0},currentNodeKey:[String,Number],renderContent:Function,props:{default:function(){return{children:"children",label:"label",disabled:"disabled"}}},highlightCurrent:{type:Boolean,default:!0},accordion:Boolean,indent:{type:Number,default:26},iconClass:String,showBranch:{type:Boolean,default:!0}},computed:{children:{set:function(e){this.data=e},get:function(){return this.data}},treeItemArray:function(){return Array.prototype.slice.call(this.treeItems)},isEmpty:function(){var e=this.root.childNodes;return!e||0===e.length}},watch:{data:function(e){this.store.setData(e)}},methods:{getNodeKey:function(e){return C(this.nodeKey,e.data)},getCurrentNode:function(){var e=this.store.getCurrentNode();return e?e.data:null},getCurrentKey:function(){if(!this.nodeKey)throw new Error("[Tree] nodeKey is required in getCurrentKey");var e=this.getCurrentNode();return e?e[this.nodeKey]:null},setCurrentNode:function(e){if(!this.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentNode");this.store.setUserCurrentNode(e)},setCurrentKey:function(e){if(!this.nodeKey)throw new Error("[Tree] nodeKey is required in setCurrentKey");this.store.setCurrentNodeKey(e)},getNode:function(e){return this.store.getNode(e)},remove:function(e){this.store.remove(e)},append:function(e,t){this.store.append(e,t)},handleNodeExpand:function(e,t,n){this.broadcast("HnTreeNode","tree-node-expand",t),this.$emit("node-expand",e,t,n)},handleKeydown:function(e){var t=e.target;if(-1!==t.className.indexOf("hn-easy-tree-node")){var n=e.keyCode;this.treeItems=this.$el.querySelectorAll(".hn-easy-tree-node[role=treeitem]");var r=this.treeItemArray.indexOf(t),i=void 0;[38,40].indexOf(n)>-1&&(e.preventDefault(),i=38===n?0!==r?r-1:0:r<this.treeItemArray.length-1?r+1:0,this.treeItemArray[i].focus()),[37,39].indexOf(n)>-1&&(e.preventDefault(),t.click())}}},created:function(){this.isTree=!0,this.store=new O({key:this.nodeKey,data:this.data,props:this.props,currentNodeKey:this.currentNodeKey,defaultExpandAll:this.defaultExpandAll,showBranch:this.showBranch}),this.root=this.store.root},mounted:function(){this.$el.addEventListener("keydown",this.handleKeydown)},updated:function(){this.treeItems=this.$el.querySelectorAll("[role=treeitem]")}},$=Object(c.a)(T,r,[],!1,null,null,null);$.options.__file="packages/easy-tree/src/tree.vue";var A=$.exports;A.install=function(e){e.component(A.name,A)};t.default=A},9:function(e,t){e.exports=require("jiku-ui/lib/utils/merge")}}).default;