tree.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 58);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 18:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/checkbox");
  182. /***/ }),
  183. /***/ 19:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/locale");
  186. /***/ }),
  187. /***/ 2:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/utils/dom");
  190. /***/ }),
  191. /***/ 28:
  192. /***/ (function(module, exports) {
  193. module.exports = require("element-ui/lib/transitions/collapse-transition");
  194. /***/ }),
  195. /***/ 3:
  196. /***/ (function(module, exports) {
  197. module.exports = require("element-ui/lib/utils/util");
  198. /***/ }),
  199. /***/ 4:
  200. /***/ (function(module, exports) {
  201. module.exports = require("element-ui/lib/mixins/emitter");
  202. /***/ }),
  203. /***/ 58:
  204. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  205. "use strict";
  206. __webpack_require__.r(__webpack_exports__);
  207. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/tree/src/tree.vue?vue&type=template&id=547575a6&
  208. var render = function() {
  209. var _vm = this
  210. var _h = _vm.$createElement
  211. var _c = _vm._self._c || _h
  212. return _c(
  213. "div",
  214. {
  215. staticClass: "el-tree",
  216. class: {
  217. "el-tree--highlight-current": _vm.highlightCurrent,
  218. "is-dragging": !!_vm.dragState.draggingNode,
  219. "is-drop-not-allow": !_vm.dragState.allowDrop,
  220. "is-drop-inner": _vm.dragState.dropType === "inner"
  221. },
  222. attrs: { role: "tree" }
  223. },
  224. [
  225. _vm._l(_vm.root.childNodes, function(child) {
  226. return _c("el-tree-node", {
  227. key: _vm.getNodeKey(child),
  228. attrs: {
  229. node: child,
  230. props: _vm.props,
  231. "render-after-expand": _vm.renderAfterExpand,
  232. "show-checkbox": _vm.showCheckbox,
  233. "render-content": _vm.renderContent
  234. },
  235. on: { "node-expand": _vm.handleNodeExpand }
  236. })
  237. }),
  238. _vm.isEmpty
  239. ? _c("div", { staticClass: "el-tree__empty-block" }, [
  240. _c("span", { staticClass: "el-tree__empty-text" }, [
  241. _vm._v(_vm._s(_vm.emptyText))
  242. ])
  243. ])
  244. : _vm._e(),
  245. _c("div", {
  246. directives: [
  247. {
  248. name: "show",
  249. rawName: "v-show",
  250. value: _vm.dragState.showDropIndicator,
  251. expression: "dragState.showDropIndicator"
  252. }
  253. ],
  254. ref: "dropIndicator",
  255. staticClass: "el-tree__drop-indicator"
  256. })
  257. ],
  258. 2
  259. )
  260. }
  261. var staticRenderFns = []
  262. render._withStripped = true
  263. // CONCATENATED MODULE: ./packages/tree/src/tree.vue?vue&type=template&id=547575a6&
  264. // EXTERNAL MODULE: external "element-ui/lib/utils/merge"
  265. var merge_ = __webpack_require__(9);
  266. var merge_default = /*#__PURE__*/__webpack_require__.n(merge_);
  267. // CONCATENATED MODULE: ./packages/tree/src/model/util.js
  268. var NODE_KEY = '$treeNodeId';
  269. var markNodeData = function markNodeData(node, data) {
  270. if (!data || data[NODE_KEY]) return;
  271. Object.defineProperty(data, NODE_KEY, {
  272. value: node.id,
  273. enumerable: false,
  274. configurable: false,
  275. writable: false
  276. });
  277. };
  278. var util_getNodeKey = function getNodeKey(key, data) {
  279. if (!key) return data[NODE_KEY];
  280. return data[key];
  281. };
  282. var findNearestComponent = function findNearestComponent(element, componentName) {
  283. var target = element;
  284. while (target && target.tagName !== 'BODY') {
  285. if (target.__vue__ && target.__vue__.$options.name === componentName) {
  286. return target.__vue__;
  287. }
  288. target = target.parentNode;
  289. }
  290. return null;
  291. };
  292. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  293. var util_ = __webpack_require__(3);
  294. // CONCATENATED MODULE: ./packages/tree/src/model/node.js
  295. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  296. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  297. var getChildState = function getChildState(node) {
  298. var all = true;
  299. var none = true;
  300. var allWithoutDisable = true;
  301. for (var i = 0, j = node.length; i < j; i++) {
  302. var n = node[i];
  303. if (n.checked !== true || n.indeterminate) {
  304. all = false;
  305. if (!n.disabled) {
  306. allWithoutDisable = false;
  307. }
  308. }
  309. if (n.checked !== false || n.indeterminate) {
  310. none = false;
  311. }
  312. }
  313. return { all: all, none: none, allWithoutDisable: allWithoutDisable, half: !all && !none };
  314. };
  315. var reInitChecked = function reInitChecked(node) {
  316. if (node.childNodes.length === 0) return;
  317. var _getChildState = getChildState(node.childNodes),
  318. all = _getChildState.all,
  319. none = _getChildState.none,
  320. half = _getChildState.half;
  321. if (all) {
  322. node.checked = true;
  323. node.indeterminate = false;
  324. } else if (half) {
  325. node.checked = false;
  326. node.indeterminate = true;
  327. } else if (none) {
  328. node.checked = false;
  329. node.indeterminate = false;
  330. }
  331. var parent = node.parent;
  332. if (!parent || parent.level === 0) return;
  333. if (!node.store.checkStrictly) {
  334. reInitChecked(parent);
  335. }
  336. };
  337. var getPropertyFromData = function getPropertyFromData(node, prop) {
  338. var props = node.store.props;
  339. var data = node.data || {};
  340. var config = props[prop];
  341. if (typeof config === 'function') {
  342. return config(data, node);
  343. } else if (typeof config === 'string') {
  344. return data[config];
  345. } else if (typeof config === 'undefined') {
  346. var dataProp = data[prop];
  347. return dataProp === undefined ? '' : dataProp;
  348. }
  349. };
  350. var nodeIdSeed = 0;
  351. var node_Node = function () {
  352. function Node(options) {
  353. _classCallCheck(this, Node);
  354. this.id = nodeIdSeed++;
  355. this.text = null;
  356. this.checked = false;
  357. this.indeterminate = false;
  358. this.data = null;
  359. this.expanded = false;
  360. this.parent = null;
  361. this.visible = true;
  362. this.isCurrent = false;
  363. for (var name in options) {
  364. if (options.hasOwnProperty(name)) {
  365. this[name] = options[name];
  366. }
  367. }
  368. // internal
  369. this.level = 0;
  370. this.loaded = false;
  371. this.childNodes = [];
  372. this.loading = false;
  373. if (this.parent) {
  374. this.level = this.parent.level + 1;
  375. }
  376. var store = this.store;
  377. if (!store) {
  378. throw new Error('[Node]store is required!');
  379. }
  380. store.registerNode(this);
  381. var props = store.props;
  382. if (props && typeof props.isLeaf !== 'undefined') {
  383. var isLeaf = getPropertyFromData(this, 'isLeaf');
  384. if (typeof isLeaf === 'boolean') {
  385. this.isLeafByUser = isLeaf;
  386. }
  387. }
  388. if (store.lazy !== true && this.data) {
  389. this.setData(this.data);
  390. if (store.defaultExpandAll) {
  391. this.expanded = true;
  392. }
  393. } else if (this.level > 0 && store.lazy && store.defaultExpandAll) {
  394. this.expand();
  395. }
  396. if (!Array.isArray(this.data)) {
  397. markNodeData(this, this.data);
  398. }
  399. if (!this.data) return;
  400. var defaultExpandedKeys = store.defaultExpandedKeys;
  401. var key = store.key;
  402. if (key && defaultExpandedKeys && defaultExpandedKeys.indexOf(this.key) !== -1) {
  403. this.expand(null, store.autoExpandParent);
  404. }
  405. if (key && store.currentNodeKey !== undefined && this.key === store.currentNodeKey) {
  406. store.currentNode = this;
  407. store.currentNode.isCurrent = true;
  408. }
  409. if (store.lazy) {
  410. store._initDefaultCheckedNode(this);
  411. }
  412. this.updateLeafState();
  413. }
  414. Node.prototype.setData = function setData(data) {
  415. if (!Array.isArray(data)) {
  416. markNodeData(this, data);
  417. }
  418. this.data = data;
  419. this.childNodes = [];
  420. var children = void 0;
  421. if (this.level === 0 && this.data instanceof Array) {
  422. children = this.data;
  423. } else {
  424. children = getPropertyFromData(this, 'children') || [];
  425. }
  426. for (var i = 0, j = children.length; i < j; i++) {
  427. this.insertChild({ data: children[i] });
  428. }
  429. };
  430. Node.prototype.contains = function contains(target) {
  431. var deep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  432. var walk = function walk(parent) {
  433. var children = parent.childNodes || [];
  434. var result = false;
  435. for (var i = 0, j = children.length; i < j; i++) {
  436. var child = children[i];
  437. if (child === target || deep && walk(child)) {
  438. result = true;
  439. break;
  440. }
  441. }
  442. return result;
  443. };
  444. return walk(this);
  445. };
  446. Node.prototype.remove = function remove() {
  447. var parent = this.parent;
  448. if (parent) {
  449. parent.removeChild(this);
  450. }
  451. };
  452. Node.prototype.insertChild = function insertChild(child, index, batch) {
  453. if (!child) throw new Error('insertChild error: child is required.');
  454. if (!(child instanceof Node)) {
  455. if (!batch) {
  456. var children = this.getChildren(true);
  457. if (children.indexOf(child.data) === -1) {
  458. if (typeof index === 'undefined' || index < 0) {
  459. children.push(child.data);
  460. } else {
  461. children.splice(index, 0, child.data);
  462. }
  463. }
  464. }
  465. merge_default()(child, {
  466. parent: this,
  467. store: this.store
  468. });
  469. child = new Node(child);
  470. }
  471. child.level = this.level + 1;
  472. if (typeof index === 'undefined' || index < 0) {
  473. this.childNodes.push(child);
  474. } else {
  475. this.childNodes.splice(index, 0, child);
  476. }
  477. this.updateLeafState();
  478. };
  479. Node.prototype.insertBefore = function insertBefore(child, ref) {
  480. var index = void 0;
  481. if (ref) {
  482. index = this.childNodes.indexOf(ref);
  483. }
  484. this.insertChild(child, index);
  485. };
  486. Node.prototype.insertAfter = function insertAfter(child, ref) {
  487. var index = void 0;
  488. if (ref) {
  489. index = this.childNodes.indexOf(ref);
  490. if (index !== -1) index += 1;
  491. }
  492. this.insertChild(child, index);
  493. };
  494. Node.prototype.removeChild = function removeChild(child) {
  495. var children = this.getChildren() || [];
  496. var dataIndex = children.indexOf(child.data);
  497. if (dataIndex > -1) {
  498. children.splice(dataIndex, 1);
  499. }
  500. var index = this.childNodes.indexOf(child);
  501. if (index > -1) {
  502. this.store && this.store.deregisterNode(child);
  503. child.parent = null;
  504. this.childNodes.splice(index, 1);
  505. }
  506. this.updateLeafState();
  507. };
  508. Node.prototype.removeChildByData = function removeChildByData(data) {
  509. var targetNode = null;
  510. for (var i = 0; i < this.childNodes.length; i++) {
  511. if (this.childNodes[i].data === data) {
  512. targetNode = this.childNodes[i];
  513. break;
  514. }
  515. }
  516. if (targetNode) {
  517. this.removeChild(targetNode);
  518. }
  519. };
  520. Node.prototype.expand = function expand(callback, expandParent) {
  521. var _this = this;
  522. var done = function done() {
  523. if (expandParent) {
  524. var parent = _this.parent;
  525. while (parent.level > 0) {
  526. parent.expanded = true;
  527. parent = parent.parent;
  528. }
  529. }
  530. _this.expanded = true;
  531. if (callback) callback();
  532. };
  533. if (this.shouldLoadData()) {
  534. this.loadData(function (data) {
  535. if (data instanceof Array) {
  536. if (_this.checked) {
  537. _this.setChecked(true, true);
  538. } else if (!_this.store.checkStrictly) {
  539. reInitChecked(_this);
  540. }
  541. done();
  542. }
  543. });
  544. } else {
  545. done();
  546. }
  547. };
  548. Node.prototype.doCreateChildren = function doCreateChildren(array) {
  549. var _this2 = this;
  550. var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  551. array.forEach(function (item) {
  552. _this2.insertChild(merge_default()({ data: item }, defaultProps), undefined, true);
  553. });
  554. };
  555. Node.prototype.collapse = function collapse() {
  556. this.expanded = false;
  557. };
  558. Node.prototype.shouldLoadData = function shouldLoadData() {
  559. return this.store.lazy === true && this.store.load && !this.loaded;
  560. };
  561. Node.prototype.updateLeafState = function updateLeafState() {
  562. if (this.store.lazy === true && this.loaded !== true && typeof this.isLeafByUser !== 'undefined') {
  563. this.isLeaf = this.isLeafByUser;
  564. return;
  565. }
  566. var childNodes = this.childNodes;
  567. if (!this.store.lazy || this.store.lazy === true && this.loaded === true) {
  568. this.isLeaf = !childNodes || childNodes.length === 0;
  569. return;
  570. }
  571. this.isLeaf = false;
  572. };
  573. Node.prototype.setChecked = function setChecked(value, deep, recursion, passValue) {
  574. var _this3 = this;
  575. this.indeterminate = value === 'half';
  576. this.checked = value === true;
  577. if (this.store.checkStrictly) return;
  578. if (!(this.shouldLoadData() && !this.store.checkDescendants)) {
  579. var _getChildState2 = getChildState(this.childNodes),
  580. all = _getChildState2.all,
  581. allWithoutDisable = _getChildState2.allWithoutDisable;
  582. if (!this.isLeaf && !all && allWithoutDisable) {
  583. this.checked = false;
  584. value = false;
  585. }
  586. var handleDescendants = function handleDescendants() {
  587. if (deep) {
  588. var childNodes = _this3.childNodes;
  589. for (var i = 0, j = childNodes.length; i < j; i++) {
  590. var child = childNodes[i];
  591. passValue = passValue || value !== false;
  592. var isCheck = child.disabled ? child.checked : passValue;
  593. child.setChecked(isCheck, deep, true, passValue);
  594. }
  595. var _getChildState3 = getChildState(childNodes),
  596. half = _getChildState3.half,
  597. _all = _getChildState3.all;
  598. if (!_all) {
  599. _this3.checked = _all;
  600. _this3.indeterminate = half;
  601. }
  602. }
  603. };
  604. if (this.shouldLoadData()) {
  605. // Only work on lazy load data.
  606. this.loadData(function () {
  607. handleDescendants();
  608. reInitChecked(_this3);
  609. }, {
  610. checked: value !== false
  611. });
  612. return;
  613. } else {
  614. handleDescendants();
  615. }
  616. }
  617. var parent = this.parent;
  618. if (!parent || parent.level === 0) return;
  619. if (!recursion) {
  620. reInitChecked(parent);
  621. }
  622. };
  623. Node.prototype.getChildren = function getChildren() {
  624. var forceInit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  625. // this is data
  626. if (this.level === 0) return this.data;
  627. var data = this.data;
  628. if (!data) return null;
  629. var props = this.store.props;
  630. var children = 'children';
  631. if (props) {
  632. children = props.children || 'children';
  633. }
  634. if (data[children] === undefined) {
  635. data[children] = null;
  636. }
  637. if (forceInit && !data[children]) {
  638. data[children] = [];
  639. }
  640. return data[children];
  641. };
  642. Node.prototype.updateChildren = function updateChildren() {
  643. var _this4 = this;
  644. var newData = this.getChildren() || [];
  645. var oldData = this.childNodes.map(function (node) {
  646. return node.data;
  647. });
  648. var newDataMap = {};
  649. var newNodes = [];
  650. newData.forEach(function (item, index) {
  651. var key = item[NODE_KEY];
  652. var isNodeExists = !!key && Object(util_["arrayFindIndex"])(oldData, function (data) {
  653. return data[NODE_KEY] === key;
  654. }) >= 0;
  655. if (isNodeExists) {
  656. newDataMap[key] = { index: index, data: item };
  657. } else {
  658. newNodes.push({ index: index, data: item });
  659. }
  660. });
  661. if (!this.store.lazy) {
  662. oldData.forEach(function (item) {
  663. if (!newDataMap[item[NODE_KEY]]) _this4.removeChildByData(item);
  664. });
  665. }
  666. newNodes.forEach(function (_ref) {
  667. var index = _ref.index,
  668. data = _ref.data;
  669. _this4.insertChild({ data: data }, index);
  670. });
  671. this.updateLeafState();
  672. };
  673. Node.prototype.loadData = function loadData(callback) {
  674. var _this5 = this;
  675. var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  676. if (this.store.lazy === true && this.store.load && !this.loaded && (!this.loading || Object.keys(defaultProps).length)) {
  677. this.loading = true;
  678. var resolve = function resolve(children) {
  679. _this5.loaded = true;
  680. _this5.loading = false;
  681. _this5.childNodes = [];
  682. _this5.doCreateChildren(children, defaultProps);
  683. _this5.updateLeafState();
  684. if (callback) {
  685. callback.call(_this5, children);
  686. }
  687. };
  688. this.store.load(this, resolve);
  689. } else {
  690. if (callback) {
  691. callback.call(this);
  692. }
  693. }
  694. };
  695. _createClass(Node, [{
  696. key: 'label',
  697. get: function get() {
  698. return getPropertyFromData(this, 'label');
  699. }
  700. }, {
  701. key: 'key',
  702. get: function get() {
  703. var nodeKey = this.store.key;
  704. if (this.data) return this.data[nodeKey];
  705. return null;
  706. }
  707. }, {
  708. key: 'disabled',
  709. get: function get() {
  710. return getPropertyFromData(this, 'disabled');
  711. }
  712. }, {
  713. key: 'nextSibling',
  714. get: function get() {
  715. var parent = this.parent;
  716. if (parent) {
  717. var index = parent.childNodes.indexOf(this);
  718. if (index > -1) {
  719. return parent.childNodes[index + 1];
  720. }
  721. }
  722. return null;
  723. }
  724. }, {
  725. key: 'previousSibling',
  726. get: function get() {
  727. var parent = this.parent;
  728. if (parent) {
  729. var index = parent.childNodes.indexOf(this);
  730. if (index > -1) {
  731. return index > 0 ? parent.childNodes[index - 1] : null;
  732. }
  733. }
  734. return null;
  735. }
  736. }]);
  737. return Node;
  738. }();
  739. /* harmony default export */ var model_node = (node_Node);
  740. // CONCATENATED MODULE: ./packages/tree/src/model/tree-store.js
  741. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  742. function tree_store_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  743. var tree_store_TreeStore = function () {
  744. function TreeStore(options) {
  745. var _this = this;
  746. tree_store_classCallCheck(this, TreeStore);
  747. this.currentNode = null;
  748. this.currentNodeKey = null;
  749. for (var option in options) {
  750. if (options.hasOwnProperty(option)) {
  751. this[option] = options[option];
  752. }
  753. }
  754. this.nodesMap = {};
  755. this.root = new model_node({
  756. data: this.data,
  757. store: this
  758. });
  759. if (this.lazy && this.load) {
  760. var loadFn = this.load;
  761. loadFn(this.root, function (data) {
  762. _this.root.doCreateChildren(data);
  763. _this._initDefaultCheckedNodes();
  764. });
  765. } else {
  766. this._initDefaultCheckedNodes();
  767. }
  768. }
  769. TreeStore.prototype.filter = function filter(value) {
  770. var filterNodeMethod = this.filterNodeMethod;
  771. var lazy = this.lazy;
  772. var traverse = function traverse(node) {
  773. var childNodes = node.root ? node.root.childNodes : node.childNodes;
  774. childNodes.forEach(function (child) {
  775. child.visible = filterNodeMethod.call(child, value, child.data, child);
  776. traverse(child);
  777. });
  778. if (!node.visible && childNodes.length) {
  779. var allHidden = true;
  780. allHidden = !childNodes.some(function (child) {
  781. return child.visible;
  782. });
  783. if (node.root) {
  784. node.root.visible = allHidden === false;
  785. } else {
  786. node.visible = allHidden === false;
  787. }
  788. }
  789. if (!value) return;
  790. if (node.visible && !node.isLeaf && !lazy) node.expand();
  791. };
  792. traverse(this);
  793. };
  794. TreeStore.prototype.setData = function setData(newVal) {
  795. var instanceChanged = newVal !== this.root.data;
  796. if (instanceChanged) {
  797. this.root.setData(newVal);
  798. this._initDefaultCheckedNodes();
  799. } else {
  800. this.root.updateChildren();
  801. }
  802. };
  803. TreeStore.prototype.getNode = function getNode(data) {
  804. if (data instanceof model_node) return data;
  805. var key = (typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object' ? data : util_getNodeKey(this.key, data);
  806. return this.nodesMap[key] || null;
  807. };
  808. TreeStore.prototype.insertBefore = function insertBefore(data, refData) {
  809. var refNode = this.getNode(refData);
  810. refNode.parent.insertBefore({ data: data }, refNode);
  811. };
  812. TreeStore.prototype.insertAfter = function insertAfter(data, refData) {
  813. var refNode = this.getNode(refData);
  814. refNode.parent.insertAfter({ data: data }, refNode);
  815. };
  816. TreeStore.prototype.remove = function remove(data) {
  817. var node = this.getNode(data);
  818. if (node && node.parent) {
  819. if (node === this.currentNode) {
  820. this.currentNode = null;
  821. }
  822. node.parent.removeChild(node);
  823. }
  824. };
  825. TreeStore.prototype.append = function append(data, parentData) {
  826. var parentNode = parentData ? this.getNode(parentData) : this.root;
  827. if (parentNode) {
  828. parentNode.insertChild({ data: data });
  829. }
  830. };
  831. TreeStore.prototype._initDefaultCheckedNodes = function _initDefaultCheckedNodes() {
  832. var _this2 = this;
  833. var defaultCheckedKeys = this.defaultCheckedKeys || [];
  834. var nodesMap = this.nodesMap;
  835. defaultCheckedKeys.forEach(function (checkedKey) {
  836. var node = nodesMap[checkedKey];
  837. if (node) {
  838. node.setChecked(true, !_this2.checkStrictly);
  839. }
  840. });
  841. };
  842. TreeStore.prototype._initDefaultCheckedNode = function _initDefaultCheckedNode(node) {
  843. var defaultCheckedKeys = this.defaultCheckedKeys || [];
  844. if (defaultCheckedKeys.indexOf(node.key) !== -1) {
  845. node.setChecked(true, !this.checkStrictly);
  846. }
  847. };
  848. TreeStore.prototype.setDefaultCheckedKey = function setDefaultCheckedKey(newVal) {
  849. if (newVal !== this.defaultCheckedKeys) {
  850. this.defaultCheckedKeys = newVal;
  851. this._initDefaultCheckedNodes();
  852. }
  853. };
  854. TreeStore.prototype.registerNode = function registerNode(node) {
  855. var key = this.key;
  856. if (!key || !node || !node.data) return;
  857. var nodeKey = node.key;
  858. if (nodeKey !== undefined) this.nodesMap[node.key] = node;
  859. };
  860. TreeStore.prototype.deregisterNode = function deregisterNode(node) {
  861. var _this3 = this;
  862. var key = this.key;
  863. if (!key || !node || !node.data) return;
  864. node.childNodes.forEach(function (child) {
  865. _this3.deregisterNode(child);
  866. });
  867. delete this.nodesMap[node.key];
  868. };
  869. TreeStore.prototype.getCheckedNodes = function getCheckedNodes() {
  870. var leafOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  871. var includeHalfChecked = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  872. var checkedNodes = [];
  873. var traverse = function traverse(node) {
  874. var childNodes = node.root ? node.root.childNodes : node.childNodes;
  875. childNodes.forEach(function (child) {
  876. if ((child.checked || includeHalfChecked && child.indeterminate) && (!leafOnly || leafOnly && child.isLeaf)) {
  877. checkedNodes.push(child.data);
  878. }
  879. traverse(child);
  880. });
  881. };
  882. traverse(this);
  883. return checkedNodes;
  884. };
  885. TreeStore.prototype.getCheckedKeys = function getCheckedKeys() {
  886. var _this4 = this;
  887. var leafOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  888. return this.getCheckedNodes(leafOnly).map(function (data) {
  889. return (data || {})[_this4.key];
  890. });
  891. };
  892. TreeStore.prototype.getHalfCheckedNodes = function getHalfCheckedNodes() {
  893. var nodes = [];
  894. var traverse = function traverse(node) {
  895. var childNodes = node.root ? node.root.childNodes : node.childNodes;
  896. childNodes.forEach(function (child) {
  897. if (child.indeterminate) {
  898. nodes.push(child.data);
  899. }
  900. traverse(child);
  901. });
  902. };
  903. traverse(this);
  904. return nodes;
  905. };
  906. TreeStore.prototype.getHalfCheckedKeys = function getHalfCheckedKeys() {
  907. var _this5 = this;
  908. return this.getHalfCheckedNodes().map(function (data) {
  909. return (data || {})[_this5.key];
  910. });
  911. };
  912. TreeStore.prototype._getAllNodes = function _getAllNodes() {
  913. var allNodes = [];
  914. var nodesMap = this.nodesMap;
  915. for (var nodeKey in nodesMap) {
  916. if (nodesMap.hasOwnProperty(nodeKey)) {
  917. allNodes.push(nodesMap[nodeKey]);
  918. }
  919. }
  920. return allNodes;
  921. };
  922. TreeStore.prototype.updateChildren = function updateChildren(key, data) {
  923. var node = this.nodesMap[key];
  924. if (!node) return;
  925. var childNodes = node.childNodes;
  926. for (var i = childNodes.length - 1; i >= 0; i--) {
  927. var child = childNodes[i];
  928. this.remove(child.data);
  929. }
  930. for (var _i = 0, j = data.length; _i < j; _i++) {
  931. var _child = data[_i];
  932. this.append(_child, node.data);
  933. }
  934. };
  935. TreeStore.prototype._setCheckedKeys = function _setCheckedKeys(key) {
  936. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  937. var checkedKeys = arguments[2];
  938. var allNodes = this._getAllNodes().sort(function (a, b) {
  939. return b.level - a.level;
  940. });
  941. var cache = Object.create(null);
  942. var keys = Object.keys(checkedKeys);
  943. allNodes.forEach(function (node) {
  944. return node.setChecked(false, false);
  945. });
  946. for (var i = 0, j = allNodes.length; i < j; i++) {
  947. var node = allNodes[i];
  948. var nodeKey = node.data[key].toString();
  949. var checked = keys.indexOf(nodeKey) > -1;
  950. if (!checked) {
  951. if (node.checked && !cache[nodeKey]) {
  952. node.setChecked(false, false);
  953. }
  954. continue;
  955. }
  956. var parent = node.parent;
  957. while (parent && parent.level > 0) {
  958. cache[parent.data[key]] = true;
  959. parent = parent.parent;
  960. }
  961. if (node.isLeaf || this.checkStrictly) {
  962. node.setChecked(true, false);
  963. continue;
  964. }
  965. node.setChecked(true, true);
  966. if (leafOnly) {
  967. (function () {
  968. node.setChecked(false, false);
  969. var traverse = function traverse(node) {
  970. var childNodes = node.childNodes;
  971. childNodes.forEach(function (child) {
  972. if (!child.isLeaf) {
  973. child.setChecked(false, false);
  974. }
  975. traverse(child);
  976. });
  977. };
  978. traverse(node);
  979. })();
  980. }
  981. }
  982. };
  983. TreeStore.prototype.setCheckedNodes = function setCheckedNodes(array) {
  984. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  985. var key = this.key;
  986. var checkedKeys = {};
  987. array.forEach(function (item) {
  988. checkedKeys[(item || {})[key]] = true;
  989. });
  990. this._setCheckedKeys(key, leafOnly, checkedKeys);
  991. };
  992. TreeStore.prototype.setCheckedKeys = function setCheckedKeys(keys) {
  993. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  994. this.defaultCheckedKeys = keys;
  995. var key = this.key;
  996. var checkedKeys = {};
  997. keys.forEach(function (key) {
  998. checkedKeys[key] = true;
  999. });
  1000. this._setCheckedKeys(key, leafOnly, checkedKeys);
  1001. };
  1002. TreeStore.prototype.setDefaultExpandedKeys = function setDefaultExpandedKeys(keys) {
  1003. var _this6 = this;
  1004. keys = keys || [];
  1005. this.defaultExpandedKeys = keys;
  1006. keys.forEach(function (key) {
  1007. var node = _this6.getNode(key);
  1008. if (node) node.expand(null, _this6.autoExpandParent);
  1009. });
  1010. };
  1011. TreeStore.prototype.setChecked = function setChecked(data, checked, deep) {
  1012. var node = this.getNode(data);
  1013. if (node) {
  1014. node.setChecked(!!checked, deep);
  1015. }
  1016. };
  1017. TreeStore.prototype.getCurrentNode = function getCurrentNode() {
  1018. return this.currentNode;
  1019. };
  1020. TreeStore.prototype.setCurrentNode = function setCurrentNode(currentNode) {
  1021. var prevCurrentNode = this.currentNode;
  1022. if (prevCurrentNode) {
  1023. prevCurrentNode.isCurrent = false;
  1024. }
  1025. this.currentNode = currentNode;
  1026. this.currentNode.isCurrent = true;
  1027. };
  1028. TreeStore.prototype.setUserCurrentNode = function setUserCurrentNode(node) {
  1029. var key = node[this.key];
  1030. var currNode = this.nodesMap[key];
  1031. this.setCurrentNode(currNode);
  1032. };
  1033. TreeStore.prototype.setCurrentNodeKey = function setCurrentNodeKey(key) {
  1034. if (key === null || key === undefined) {
  1035. this.currentNode && (this.currentNode.isCurrent = false);
  1036. this.currentNode = null;
  1037. return;
  1038. }
  1039. var node = this.getNode(key);
  1040. if (node) {
  1041. this.setCurrentNode(node);
  1042. }
  1043. };
  1044. return TreeStore;
  1045. }();
  1046. /* harmony default export */ var tree_store = (tree_store_TreeStore);
  1047. ;
  1048. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/tree/src/tree-node.vue?vue&type=template&id=3ba3ef0e&
  1049. var tree_nodevue_type_template_id_3ba3ef0e_render = function() {
  1050. var this$1 = this
  1051. var _vm = this
  1052. var _h = _vm.$createElement
  1053. var _c = _vm._self._c || _h
  1054. return _c(
  1055. "div",
  1056. {
  1057. directives: [
  1058. {
  1059. name: "show",
  1060. rawName: "v-show",
  1061. value: _vm.node.visible,
  1062. expression: "node.visible"
  1063. }
  1064. ],
  1065. ref: "node",
  1066. staticClass: "el-tree-node",
  1067. class: {
  1068. "is-expanded": _vm.expanded,
  1069. "is-current": _vm.node.isCurrent,
  1070. "is-hidden": !_vm.node.visible,
  1071. "is-focusable": !_vm.node.disabled,
  1072. "is-checked": !_vm.node.disabled && _vm.node.checked
  1073. },
  1074. attrs: {
  1075. role: "treeitem",
  1076. tabindex: "-1",
  1077. "aria-expanded": _vm.expanded,
  1078. "aria-disabled": _vm.node.disabled,
  1079. "aria-checked": _vm.node.checked,
  1080. draggable: _vm.tree.draggable
  1081. },
  1082. on: {
  1083. click: function($event) {
  1084. $event.stopPropagation()
  1085. return _vm.handleClick($event)
  1086. },
  1087. contextmenu: function($event) {
  1088. return this$1.handleContextMenu($event)
  1089. },
  1090. dragstart: function($event) {
  1091. $event.stopPropagation()
  1092. return _vm.handleDragStart($event)
  1093. },
  1094. dragover: function($event) {
  1095. $event.stopPropagation()
  1096. return _vm.handleDragOver($event)
  1097. },
  1098. dragend: function($event) {
  1099. $event.stopPropagation()
  1100. return _vm.handleDragEnd($event)
  1101. },
  1102. drop: function($event) {
  1103. $event.stopPropagation()
  1104. return _vm.handleDrop($event)
  1105. }
  1106. }
  1107. },
  1108. [
  1109. _c(
  1110. "div",
  1111. {
  1112. staticClass: "el-tree-node__content",
  1113. style: {
  1114. "padding-left": (_vm.node.level - 1) * _vm.tree.indent + "px"
  1115. }
  1116. },
  1117. [
  1118. _c("span", {
  1119. class: [
  1120. {
  1121. "is-leaf": _vm.node.isLeaf,
  1122. expanded: !_vm.node.isLeaf && _vm.expanded
  1123. },
  1124. "el-tree-node__expand-icon",
  1125. _vm.tree.iconClass ? _vm.tree.iconClass : "el-icon-caret-right"
  1126. ],
  1127. on: {
  1128. click: function($event) {
  1129. $event.stopPropagation()
  1130. return _vm.handleExpandIconClick($event)
  1131. }
  1132. }
  1133. }),
  1134. _vm.showCheckbox
  1135. ? _c("el-checkbox", {
  1136. attrs: {
  1137. indeterminate: _vm.node.indeterminate,
  1138. disabled: !!_vm.node.disabled
  1139. },
  1140. on: { change: _vm.handleCheckChange },
  1141. nativeOn: {
  1142. click: function($event) {
  1143. $event.stopPropagation()
  1144. }
  1145. },
  1146. model: {
  1147. value: _vm.node.checked,
  1148. callback: function($$v) {
  1149. _vm.$set(_vm.node, "checked", $$v)
  1150. },
  1151. expression: "node.checked"
  1152. }
  1153. })
  1154. : _vm._e(),
  1155. _vm.node.loading
  1156. ? _c("span", {
  1157. staticClass: "el-tree-node__loading-icon el-icon-loading"
  1158. })
  1159. : _vm._e(),
  1160. _c("node-content", { attrs: { node: _vm.node } })
  1161. ],
  1162. 1
  1163. ),
  1164. _c("el-collapse-transition", [
  1165. !_vm.renderAfterExpand || _vm.childNodeRendered
  1166. ? _c(
  1167. "div",
  1168. {
  1169. directives: [
  1170. {
  1171. name: "show",
  1172. rawName: "v-show",
  1173. value: _vm.expanded,
  1174. expression: "expanded"
  1175. }
  1176. ],
  1177. staticClass: "el-tree-node__children",
  1178. attrs: { role: "group", "aria-expanded": _vm.expanded }
  1179. },
  1180. _vm._l(_vm.node.childNodes, function(child) {
  1181. return _c("el-tree-node", {
  1182. key: _vm.getNodeKey(child),
  1183. attrs: {
  1184. "render-content": _vm.renderContent,
  1185. "render-after-expand": _vm.renderAfterExpand,
  1186. "show-checkbox": _vm.showCheckbox,
  1187. node: child
  1188. },
  1189. on: { "node-expand": _vm.handleChildNodeExpand }
  1190. })
  1191. }),
  1192. 1
  1193. )
  1194. : _vm._e()
  1195. ])
  1196. ],
  1197. 1
  1198. )
  1199. }
  1200. var tree_nodevue_type_template_id_3ba3ef0e_staticRenderFns = []
  1201. tree_nodevue_type_template_id_3ba3ef0e_render._withStripped = true
  1202. // CONCATENATED MODULE: ./packages/tree/src/tree-node.vue?vue&type=template&id=3ba3ef0e&
  1203. // EXTERNAL MODULE: external "element-ui/lib/transitions/collapse-transition"
  1204. var collapse_transition_ = __webpack_require__(28);
  1205. var collapse_transition_default = /*#__PURE__*/__webpack_require__.n(collapse_transition_);
  1206. // EXTERNAL MODULE: external "element-ui/lib/checkbox"
  1207. var checkbox_ = __webpack_require__(18);
  1208. var checkbox_default = /*#__PURE__*/__webpack_require__.n(checkbox_);
  1209. // EXTERNAL MODULE: external "element-ui/lib/mixins/emitter"
  1210. var emitter_ = __webpack_require__(4);
  1211. var emitter_default = /*#__PURE__*/__webpack_require__.n(emitter_);
  1212. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/tree/src/tree-node.vue?vue&type=script&lang=js&
  1213. //
  1214. //
  1215. //
  1216. //
  1217. //
  1218. //
  1219. //
  1220. //
  1221. //
  1222. //
  1223. //
  1224. //
  1225. //
  1226. //
  1227. //
  1228. //
  1229. //
  1230. //
  1231. //
  1232. //
  1233. //
  1234. //
  1235. //
  1236. //
  1237. //
  1238. //
  1239. //
  1240. //
  1241. //
  1242. //
  1243. //
  1244. //
  1245. //
  1246. //
  1247. //
  1248. //
  1249. //
  1250. //
  1251. //
  1252. //
  1253. //
  1254. //
  1255. //
  1256. //
  1257. //
  1258. //
  1259. //
  1260. //
  1261. //
  1262. //
  1263. //
  1264. //
  1265. //
  1266. //
  1267. //
  1268. //
  1269. //
  1270. //
  1271. //
  1272. //
  1273. //
  1274. //
  1275. //
  1276. //
  1277. //
  1278. //
  1279. //
  1280. //
  1281. //
  1282. //
  1283. //
  1284. //
  1285. //
  1286. /* harmony default export */ var tree_nodevue_type_script_lang_js_ = ({
  1287. name: 'ElTreeNode',
  1288. componentName: 'ElTreeNode',
  1289. mixins: [emitter_default.a],
  1290. props: {
  1291. node: {
  1292. default: function _default() {
  1293. return {};
  1294. }
  1295. },
  1296. props: {},
  1297. renderContent: Function,
  1298. renderAfterExpand: {
  1299. type: Boolean,
  1300. default: true
  1301. },
  1302. showCheckbox: {
  1303. type: Boolean,
  1304. default: false
  1305. }
  1306. },
  1307. components: {
  1308. ElCollapseTransition: collapse_transition_default.a,
  1309. ElCheckbox: checkbox_default.a,
  1310. NodeContent: {
  1311. props: {
  1312. node: {
  1313. required: true
  1314. }
  1315. },
  1316. render: function render(h) {
  1317. var parent = this.$parent;
  1318. var tree = parent.tree;
  1319. var node = this.node;
  1320. var data = node.data,
  1321. store = node.store;
  1322. return parent.renderContent ? parent.renderContent.call(parent._renderProxy, h, { _self: tree.$vnode.context, node: node, data: data, store: store }) : tree.$scopedSlots.default ? tree.$scopedSlots.default({ node: node, data: data }) : h(
  1323. 'span',
  1324. { 'class': 'el-tree-node__label' },
  1325. [node.label]
  1326. );
  1327. }
  1328. }
  1329. },
  1330. data: function data() {
  1331. return {
  1332. tree: null,
  1333. expanded: false,
  1334. childNodeRendered: false,
  1335. oldChecked: null,
  1336. oldIndeterminate: null
  1337. };
  1338. },
  1339. watch: {
  1340. 'node.indeterminate': function nodeIndeterminate(val) {
  1341. this.handleSelectChange(this.node.checked, val);
  1342. },
  1343. 'node.checked': function nodeChecked(val) {
  1344. this.handleSelectChange(val, this.node.indeterminate);
  1345. },
  1346. 'node.expanded': function nodeExpanded(val) {
  1347. var _this = this;
  1348. this.$nextTick(function () {
  1349. return _this.expanded = val;
  1350. });
  1351. if (val) {
  1352. this.childNodeRendered = true;
  1353. }
  1354. }
  1355. },
  1356. methods: {
  1357. getNodeKey: function getNodeKey(node) {
  1358. return util_getNodeKey(this.tree.nodeKey, node.data);
  1359. },
  1360. handleSelectChange: function handleSelectChange(checked, indeterminate) {
  1361. if (this.oldChecked !== checked && this.oldIndeterminate !== indeterminate) {
  1362. this.tree.$emit('check-change', this.node.data, checked, indeterminate);
  1363. }
  1364. this.oldChecked = checked;
  1365. this.indeterminate = indeterminate;
  1366. },
  1367. handleClick: function handleClick() {
  1368. var store = this.tree.store;
  1369. store.setCurrentNode(this.node);
  1370. this.tree.$emit('current-change', store.currentNode ? store.currentNode.data : null, store.currentNode);
  1371. this.tree.currentNode = this;
  1372. if (this.tree.expandOnClickNode) {
  1373. this.handleExpandIconClick();
  1374. }
  1375. if (this.tree.checkOnClickNode && !this.node.disabled) {
  1376. this.handleCheckChange(null, {
  1377. target: { checked: !this.node.checked }
  1378. });
  1379. }
  1380. this.tree.$emit('node-click', this.node.data, this.node, this);
  1381. },
  1382. handleContextMenu: function handleContextMenu(event) {
  1383. if (this.tree._events['node-contextmenu'] && this.tree._events['node-contextmenu'].length > 0) {
  1384. event.stopPropagation();
  1385. event.preventDefault();
  1386. }
  1387. this.tree.$emit('node-contextmenu', event, this.node.data, this.node, this);
  1388. },
  1389. handleExpandIconClick: function handleExpandIconClick() {
  1390. if (this.node.isLeaf) return;
  1391. if (this.expanded) {
  1392. this.tree.$emit('node-collapse', this.node.data, this.node, this);
  1393. this.node.collapse();
  1394. } else {
  1395. this.node.expand();
  1396. this.$emit('node-expand', this.node.data, this.node, this);
  1397. }
  1398. },
  1399. handleCheckChange: function handleCheckChange(value, ev) {
  1400. var _this2 = this;
  1401. this.node.setChecked(ev.target.checked, !this.tree.checkStrictly);
  1402. this.$nextTick(function () {
  1403. var store = _this2.tree.store;
  1404. _this2.tree.$emit('check', _this2.node.data, {
  1405. checkedNodes: store.getCheckedNodes(),
  1406. checkedKeys: store.getCheckedKeys(),
  1407. halfCheckedNodes: store.getHalfCheckedNodes(),
  1408. halfCheckedKeys: store.getHalfCheckedKeys()
  1409. });
  1410. });
  1411. },
  1412. handleChildNodeExpand: function handleChildNodeExpand(nodeData, node, instance) {
  1413. this.broadcast('ElTreeNode', 'tree-node-expand', node);
  1414. this.tree.$emit('node-expand', nodeData, node, instance);
  1415. },
  1416. handleDragStart: function handleDragStart(event) {
  1417. if (!this.tree.draggable) return;
  1418. this.tree.$emit('tree-node-drag-start', event, this);
  1419. },
  1420. handleDragOver: function handleDragOver(event) {
  1421. if (!this.tree.draggable) return;
  1422. this.tree.$emit('tree-node-drag-over', event, this);
  1423. event.preventDefault();
  1424. },
  1425. handleDrop: function handleDrop(event) {
  1426. event.preventDefault();
  1427. },
  1428. handleDragEnd: function handleDragEnd(event) {
  1429. if (!this.tree.draggable) return;
  1430. this.tree.$emit('tree-node-drag-end', event, this);
  1431. }
  1432. },
  1433. created: function created() {
  1434. var _this3 = this;
  1435. var parent = this.$parent;
  1436. if (parent.isTree) {
  1437. this.tree = parent;
  1438. } else {
  1439. this.tree = parent.tree;
  1440. }
  1441. var tree = this.tree;
  1442. if (!tree) {
  1443. console.warn('Can not find node\'s tree.');
  1444. }
  1445. var props = tree.props || {};
  1446. var childrenKey = props['children'] || 'children';
  1447. this.$watch('node.data.' + childrenKey, function () {
  1448. _this3.node.updateChildren();
  1449. });
  1450. if (this.node.expanded) {
  1451. this.expanded = true;
  1452. this.childNodeRendered = true;
  1453. }
  1454. if (this.tree.accordion) {
  1455. this.$on('tree-node-expand', function (node) {
  1456. if (_this3.node !== node) {
  1457. _this3.node.collapse();
  1458. }
  1459. });
  1460. }
  1461. }
  1462. });
  1463. // CONCATENATED MODULE: ./packages/tree/src/tree-node.vue?vue&type=script&lang=js&
  1464. /* harmony default export */ var src_tree_nodevue_type_script_lang_js_ = (tree_nodevue_type_script_lang_js_);
  1465. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  1466. var componentNormalizer = __webpack_require__(0);
  1467. // CONCATENATED MODULE: ./packages/tree/src/tree-node.vue
  1468. /* normalize component */
  1469. var component = Object(componentNormalizer["a" /* default */])(
  1470. src_tree_nodevue_type_script_lang_js_,
  1471. tree_nodevue_type_template_id_3ba3ef0e_render,
  1472. tree_nodevue_type_template_id_3ba3ef0e_staticRenderFns,
  1473. false,
  1474. null,
  1475. null,
  1476. null
  1477. )
  1478. /* hot reload */
  1479. if (false) { var api; }
  1480. component.options.__file = "packages/tree/src/tree-node.vue"
  1481. /* harmony default export */ var tree_node = (component.exports);
  1482. // EXTERNAL MODULE: external "element-ui/lib/locale"
  1483. var locale_ = __webpack_require__(19);
  1484. // EXTERNAL MODULE: external "element-ui/lib/utils/dom"
  1485. var dom_ = __webpack_require__(2);
  1486. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/tree/src/tree.vue?vue&type=script&lang=js&
  1487. //
  1488. //
  1489. //
  1490. //
  1491. //
  1492. //
  1493. //
  1494. //
  1495. //
  1496. //
  1497. //
  1498. //
  1499. //
  1500. //
  1501. //
  1502. //
  1503. //
  1504. //
  1505. //
  1506. //
  1507. //
  1508. //
  1509. //
  1510. //
  1511. //
  1512. //
  1513. //
  1514. //
  1515. //
  1516. //
  1517. //
  1518. //
  1519. /* harmony default export */ var treevue_type_script_lang_js_ = ({
  1520. name: 'ElTree',
  1521. mixins: [emitter_default.a],
  1522. components: {
  1523. ElTreeNode: tree_node
  1524. },
  1525. data: function data() {
  1526. return {
  1527. store: null,
  1528. root: null,
  1529. currentNode: null,
  1530. treeItems: null,
  1531. checkboxItems: [],
  1532. dragState: {
  1533. showDropIndicator: false,
  1534. draggingNode: null,
  1535. dropNode: null,
  1536. allowDrop: true
  1537. }
  1538. };
  1539. },
  1540. props: {
  1541. data: {
  1542. type: Array
  1543. },
  1544. emptyText: {
  1545. type: String,
  1546. default: function _default() {
  1547. return Object(locale_["t"])('el.tree.emptyText');
  1548. }
  1549. },
  1550. renderAfterExpand: {
  1551. type: Boolean,
  1552. default: true
  1553. },
  1554. nodeKey: String,
  1555. checkStrictly: Boolean,
  1556. defaultExpandAll: Boolean,
  1557. expandOnClickNode: {
  1558. type: Boolean,
  1559. default: true
  1560. },
  1561. checkOnClickNode: Boolean,
  1562. checkDescendants: {
  1563. type: Boolean,
  1564. default: false
  1565. },
  1566. autoExpandParent: {
  1567. type: Boolean,
  1568. default: true
  1569. },
  1570. defaultCheckedKeys: Array,
  1571. defaultExpandedKeys: Array,
  1572. currentNodeKey: [String, Number],
  1573. renderContent: Function,
  1574. showCheckbox: {
  1575. type: Boolean,
  1576. default: false
  1577. },
  1578. draggable: {
  1579. type: Boolean,
  1580. default: false
  1581. },
  1582. allowDrag: Function,
  1583. allowDrop: Function,
  1584. props: {
  1585. default: function _default() {
  1586. return {
  1587. children: 'children',
  1588. label: 'label',
  1589. disabled: 'disabled'
  1590. };
  1591. }
  1592. },
  1593. lazy: {
  1594. type: Boolean,
  1595. default: false
  1596. },
  1597. highlightCurrent: Boolean,
  1598. load: Function,
  1599. filterNodeMethod: Function,
  1600. accordion: Boolean,
  1601. indent: {
  1602. type: Number,
  1603. default: 18
  1604. },
  1605. iconClass: String
  1606. },
  1607. computed: {
  1608. children: {
  1609. set: function set(value) {
  1610. this.data = value;
  1611. },
  1612. get: function get() {
  1613. return this.data;
  1614. }
  1615. },
  1616. treeItemArray: function treeItemArray() {
  1617. return Array.prototype.slice.call(this.treeItems);
  1618. },
  1619. isEmpty: function isEmpty() {
  1620. var childNodes = this.root.childNodes;
  1621. return !childNodes || childNodes.length === 0 || childNodes.every(function (_ref) {
  1622. var visible = _ref.visible;
  1623. return !visible;
  1624. });
  1625. }
  1626. },
  1627. watch: {
  1628. defaultCheckedKeys: function defaultCheckedKeys(newVal) {
  1629. this.store.setDefaultCheckedKey(newVal);
  1630. },
  1631. defaultExpandedKeys: function defaultExpandedKeys(newVal) {
  1632. this.store.defaultExpandedKeys = newVal;
  1633. this.store.setDefaultExpandedKeys(newVal);
  1634. },
  1635. data: function data(newVal) {
  1636. this.store.setData(newVal);
  1637. },
  1638. checkboxItems: function checkboxItems(val) {
  1639. Array.prototype.forEach.call(val, function (checkbox) {
  1640. checkbox.setAttribute('tabindex', -1);
  1641. });
  1642. },
  1643. checkStrictly: function checkStrictly(newVal) {
  1644. this.store.checkStrictly = newVal;
  1645. }
  1646. },
  1647. methods: {
  1648. filter: function filter(value) {
  1649. if (!this.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter');
  1650. this.store.filter(value);
  1651. },
  1652. getNodeKey: function getNodeKey(node) {
  1653. return util_getNodeKey(this.nodeKey, node.data);
  1654. },
  1655. getNodePath: function getNodePath(data) {
  1656. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in getNodePath');
  1657. var node = this.store.getNode(data);
  1658. if (!node) return [];
  1659. var path = [node.data];
  1660. var parent = node.parent;
  1661. while (parent && parent !== this.root) {
  1662. path.push(parent.data);
  1663. parent = parent.parent;
  1664. }
  1665. return path.reverse();
  1666. },
  1667. getCheckedNodes: function getCheckedNodes(leafOnly, includeHalfChecked) {
  1668. return this.store.getCheckedNodes(leafOnly, includeHalfChecked);
  1669. },
  1670. getCheckedKeys: function getCheckedKeys(leafOnly) {
  1671. return this.store.getCheckedKeys(leafOnly);
  1672. },
  1673. getCurrentNode: function getCurrentNode() {
  1674. var currentNode = this.store.getCurrentNode();
  1675. return currentNode ? currentNode.data : null;
  1676. },
  1677. getCurrentKey: function getCurrentKey() {
  1678. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in getCurrentKey');
  1679. var currentNode = this.getCurrentNode();
  1680. return currentNode ? currentNode[this.nodeKey] : null;
  1681. },
  1682. setCheckedNodes: function setCheckedNodes(nodes, leafOnly) {
  1683. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
  1684. this.store.setCheckedNodes(nodes, leafOnly);
  1685. },
  1686. setCheckedKeys: function setCheckedKeys(keys, leafOnly) {
  1687. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedKeys');
  1688. this.store.setCheckedKeys(keys, leafOnly);
  1689. },
  1690. setChecked: function setChecked(data, checked, deep) {
  1691. this.store.setChecked(data, checked, deep);
  1692. },
  1693. getHalfCheckedNodes: function getHalfCheckedNodes() {
  1694. return this.store.getHalfCheckedNodes();
  1695. },
  1696. getHalfCheckedKeys: function getHalfCheckedKeys() {
  1697. return this.store.getHalfCheckedKeys();
  1698. },
  1699. setCurrentNode: function setCurrentNode(node) {
  1700. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentNode');
  1701. this.store.setUserCurrentNode(node);
  1702. },
  1703. setCurrentKey: function setCurrentKey(key) {
  1704. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentKey');
  1705. this.store.setCurrentNodeKey(key);
  1706. },
  1707. getNode: function getNode(data) {
  1708. return this.store.getNode(data);
  1709. },
  1710. remove: function remove(data) {
  1711. this.store.remove(data);
  1712. },
  1713. append: function append(data, parentNode) {
  1714. this.store.append(data, parentNode);
  1715. },
  1716. insertBefore: function insertBefore(data, refNode) {
  1717. this.store.insertBefore(data, refNode);
  1718. },
  1719. insertAfter: function insertAfter(data, refNode) {
  1720. this.store.insertAfter(data, refNode);
  1721. },
  1722. handleNodeExpand: function handleNodeExpand(nodeData, node, instance) {
  1723. this.broadcast('ElTreeNode', 'tree-node-expand', node);
  1724. this.$emit('node-expand', nodeData, node, instance);
  1725. },
  1726. updateKeyChildren: function updateKeyChildren(key, data) {
  1727. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in updateKeyChild');
  1728. this.store.updateChildren(key, data);
  1729. },
  1730. initTabIndex: function initTabIndex() {
  1731. this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
  1732. this.checkboxItems = this.$el.querySelectorAll('input[type=checkbox]');
  1733. var checkedItem = this.$el.querySelectorAll('.is-checked[role=treeitem]');
  1734. if (checkedItem.length) {
  1735. checkedItem[0].setAttribute('tabindex', 0);
  1736. return;
  1737. }
  1738. this.treeItems[0] && this.treeItems[0].setAttribute('tabindex', 0);
  1739. },
  1740. handleKeydown: function handleKeydown(ev) {
  1741. var currentItem = ev.target;
  1742. if (currentItem.className.indexOf('el-tree-node') === -1) return;
  1743. var keyCode = ev.keyCode;
  1744. this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
  1745. var currentIndex = this.treeItemArray.indexOf(currentItem);
  1746. var nextIndex = void 0;
  1747. if ([38, 40].indexOf(keyCode) > -1) {
  1748. // up、down
  1749. ev.preventDefault();
  1750. if (keyCode === 38) {
  1751. // up
  1752. nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0;
  1753. } else {
  1754. nextIndex = currentIndex < this.treeItemArray.length - 1 ? currentIndex + 1 : 0;
  1755. }
  1756. this.treeItemArray[nextIndex].focus(); // 选中
  1757. }
  1758. if ([37, 39].indexOf(keyCode) > -1) {
  1759. // left、right 展开
  1760. ev.preventDefault();
  1761. currentItem.click(); // 选中
  1762. }
  1763. var hasInput = currentItem.querySelector('[type="checkbox"]');
  1764. if ([13, 32].indexOf(keyCode) > -1 && hasInput) {
  1765. // space enter选中checkbox
  1766. ev.preventDefault();
  1767. hasInput.click();
  1768. }
  1769. }
  1770. },
  1771. created: function created() {
  1772. var _this = this;
  1773. this.isTree = true;
  1774. this.store = new tree_store({
  1775. key: this.nodeKey,
  1776. data: this.data,
  1777. lazy: this.lazy,
  1778. props: this.props,
  1779. load: this.load,
  1780. currentNodeKey: this.currentNodeKey,
  1781. checkStrictly: this.checkStrictly,
  1782. checkDescendants: this.checkDescendants,
  1783. defaultCheckedKeys: this.defaultCheckedKeys,
  1784. defaultExpandedKeys: this.defaultExpandedKeys,
  1785. autoExpandParent: this.autoExpandParent,
  1786. defaultExpandAll: this.defaultExpandAll,
  1787. filterNodeMethod: this.filterNodeMethod
  1788. });
  1789. this.root = this.store.root;
  1790. var dragState = this.dragState;
  1791. this.$on('tree-node-drag-start', function (event, treeNode) {
  1792. if (typeof _this.allowDrag === 'function' && !_this.allowDrag(treeNode.node)) {
  1793. event.preventDefault();
  1794. return false;
  1795. }
  1796. event.dataTransfer.effectAllowed = 'move';
  1797. // wrap in try catch to address IE's error when first param is 'text/plain'
  1798. try {
  1799. // setData is required for draggable to work in FireFox
  1800. // the content has to be '' so dragging a node out of the tree won't open a new tab in FireFox
  1801. event.dataTransfer.setData('text/plain', '');
  1802. } catch (e) {}
  1803. dragState.draggingNode = treeNode;
  1804. _this.$emit('node-drag-start', treeNode.node, event);
  1805. });
  1806. this.$on('tree-node-drag-over', function (event, treeNode) {
  1807. var dropNode = findNearestComponent(event.target, 'ElTreeNode');
  1808. var oldDropNode = dragState.dropNode;
  1809. if (oldDropNode && oldDropNode !== dropNode) {
  1810. Object(dom_["removeClass"])(oldDropNode.$el, 'is-drop-inner');
  1811. }
  1812. var draggingNode = dragState.draggingNode;
  1813. if (!draggingNode || !dropNode) return;
  1814. var dropPrev = true;
  1815. var dropInner = true;
  1816. var dropNext = true;
  1817. var userAllowDropInner = true;
  1818. if (typeof _this.allowDrop === 'function') {
  1819. dropPrev = _this.allowDrop(draggingNode.node, dropNode.node, 'prev');
  1820. userAllowDropInner = dropInner = _this.allowDrop(draggingNode.node, dropNode.node, 'inner');
  1821. dropNext = _this.allowDrop(draggingNode.node, dropNode.node, 'next');
  1822. }
  1823. event.dataTransfer.dropEffect = dropInner ? 'move' : 'none';
  1824. if ((dropPrev || dropInner || dropNext) && oldDropNode !== dropNode) {
  1825. if (oldDropNode) {
  1826. _this.$emit('node-drag-leave', draggingNode.node, oldDropNode.node, event);
  1827. }
  1828. _this.$emit('node-drag-enter', draggingNode.node, dropNode.node, event);
  1829. }
  1830. if (dropPrev || dropInner || dropNext) {
  1831. dragState.dropNode = dropNode;
  1832. }
  1833. if (dropNode.node.nextSibling === draggingNode.node) {
  1834. dropNext = false;
  1835. }
  1836. if (dropNode.node.previousSibling === draggingNode.node) {
  1837. dropPrev = false;
  1838. }
  1839. if (dropNode.node.contains(draggingNode.node, false)) {
  1840. dropInner = false;
  1841. }
  1842. if (draggingNode.node === dropNode.node || draggingNode.node.contains(dropNode.node)) {
  1843. dropPrev = false;
  1844. dropInner = false;
  1845. dropNext = false;
  1846. }
  1847. var targetPosition = dropNode.$el.getBoundingClientRect();
  1848. var treePosition = _this.$el.getBoundingClientRect();
  1849. var dropType = void 0;
  1850. var prevPercent = dropPrev ? dropInner ? 0.25 : dropNext ? 0.45 : 1 : -1;
  1851. var nextPercent = dropNext ? dropInner ? 0.75 : dropPrev ? 0.55 : 0 : 1;
  1852. var indicatorTop = -9999;
  1853. var distance = event.clientY - targetPosition.top;
  1854. if (distance < targetPosition.height * prevPercent) {
  1855. dropType = 'before';
  1856. } else if (distance > targetPosition.height * nextPercent) {
  1857. dropType = 'after';
  1858. } else if (dropInner) {
  1859. dropType = 'inner';
  1860. } else {
  1861. dropType = 'none';
  1862. }
  1863. var iconPosition = dropNode.$el.querySelector('.el-tree-node__expand-icon').getBoundingClientRect();
  1864. var dropIndicator = _this.$refs.dropIndicator;
  1865. if (dropType === 'before') {
  1866. indicatorTop = iconPosition.top - treePosition.top;
  1867. } else if (dropType === 'after') {
  1868. indicatorTop = iconPosition.bottom - treePosition.top;
  1869. }
  1870. dropIndicator.style.top = indicatorTop + 'px';
  1871. dropIndicator.style.left = iconPosition.right - treePosition.left + 'px';
  1872. if (dropType === 'inner') {
  1873. Object(dom_["addClass"])(dropNode.$el, 'is-drop-inner');
  1874. } else {
  1875. Object(dom_["removeClass"])(dropNode.$el, 'is-drop-inner');
  1876. }
  1877. dragState.showDropIndicator = dropType === 'before' || dropType === 'after';
  1878. dragState.allowDrop = dragState.showDropIndicator || userAllowDropInner;
  1879. dragState.dropType = dropType;
  1880. _this.$emit('node-drag-over', draggingNode.node, dropNode.node, event);
  1881. });
  1882. this.$on('tree-node-drag-end', function (event) {
  1883. var draggingNode = dragState.draggingNode,
  1884. dropType = dragState.dropType,
  1885. dropNode = dragState.dropNode;
  1886. event.preventDefault();
  1887. event.dataTransfer.dropEffect = 'move';
  1888. if (draggingNode && dropNode) {
  1889. var draggingNodeCopy = { data: draggingNode.node.data };
  1890. if (dropType !== 'none') {
  1891. draggingNode.node.remove();
  1892. }
  1893. if (dropType === 'before') {
  1894. dropNode.node.parent.insertBefore(draggingNodeCopy, dropNode.node);
  1895. } else if (dropType === 'after') {
  1896. dropNode.node.parent.insertAfter(draggingNodeCopy, dropNode.node);
  1897. } else if (dropType === 'inner') {
  1898. dropNode.node.insertChild(draggingNodeCopy);
  1899. }
  1900. if (dropType !== 'none') {
  1901. _this.store.registerNode(draggingNodeCopy);
  1902. }
  1903. Object(dom_["removeClass"])(dropNode.$el, 'is-drop-inner');
  1904. _this.$emit('node-drag-end', draggingNode.node, dropNode.node, dropType, event);
  1905. if (dropType !== 'none') {
  1906. _this.$emit('node-drop', draggingNode.node, dropNode.node, dropType, event);
  1907. }
  1908. }
  1909. if (draggingNode && !dropNode) {
  1910. _this.$emit('node-drag-end', draggingNode.node, null, dropType, event);
  1911. }
  1912. dragState.showDropIndicator = false;
  1913. dragState.draggingNode = null;
  1914. dragState.dropNode = null;
  1915. dragState.allowDrop = true;
  1916. });
  1917. },
  1918. mounted: function mounted() {
  1919. this.initTabIndex();
  1920. this.$el.addEventListener('keydown', this.handleKeydown);
  1921. },
  1922. updated: function updated() {
  1923. this.treeItems = this.$el.querySelectorAll('[role=treeitem]');
  1924. this.checkboxItems = this.$el.querySelectorAll('input[type=checkbox]');
  1925. }
  1926. });
  1927. // CONCATENATED MODULE: ./packages/tree/src/tree.vue?vue&type=script&lang=js&
  1928. /* harmony default export */ var src_treevue_type_script_lang_js_ = (treevue_type_script_lang_js_);
  1929. // CONCATENATED MODULE: ./packages/tree/src/tree.vue
  1930. /* normalize component */
  1931. var tree_component = Object(componentNormalizer["a" /* default */])(
  1932. src_treevue_type_script_lang_js_,
  1933. render,
  1934. staticRenderFns,
  1935. false,
  1936. null,
  1937. null,
  1938. null
  1939. )
  1940. /* hot reload */
  1941. if (false) { var tree_api; }
  1942. tree_component.options.__file = "packages/tree/src/tree.vue"
  1943. /* harmony default export */ var tree = (tree_component.exports);
  1944. // CONCATENATED MODULE: ./packages/tree/index.js
  1945. /* istanbul ignore next */
  1946. tree.install = function (Vue) {
  1947. Vue.component(tree.name, tree);
  1948. };
  1949. /* harmony default export */ var packages_tree = __webpack_exports__["default"] = (tree);
  1950. /***/ }),
  1951. /***/ 9:
  1952. /***/ (function(module, exports) {
  1953. module.exports = require("element-ui/lib/utils/merge");
  1954. /***/ })
  1955. /******/ });