tree.js 62 KB

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