tree.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736
  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, {
  41. /******/ configurable: false,
  42. /******/ enumerable: true,
  43. /******/ get: getter
  44. /******/ });
  45. /******/ }
  46. /******/ };
  47. /******/
  48. /******/ // getDefaultExport function for compatibility with non-harmony modules
  49. /******/ __webpack_require__.n = function(module) {
  50. /******/ var getter = module && module.__esModule ?
  51. /******/ function getDefault() { return module['default']; } :
  52. /******/ function getModuleExports() { return module; };
  53. /******/ __webpack_require__.d(getter, 'a', getter);
  54. /******/ return getter;
  55. /******/ };
  56. /******/
  57. /******/ // Object.prototype.hasOwnProperty.call
  58. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  59. /******/
  60. /******/ // __webpack_public_path__
  61. /******/ __webpack_require__.p = "/dist/";
  62. /******/
  63. /******/ // Load entry module and return exports
  64. /******/ return __webpack_require__(__webpack_require__.s = 285);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 0:
  69. /***/ (function(module, exports) {
  70. /* globals __VUE_SSR_CONTEXT__ */
  71. // IMPORTANT: Do NOT use ES2015 features in this file.
  72. // This module is a runtime utility for cleaner component module output and will
  73. // be included in the final webpack user bundle.
  74. module.exports = function normalizeComponent (
  75. rawScriptExports,
  76. compiledTemplate,
  77. functionalTemplate,
  78. injectStyles,
  79. scopeId,
  80. moduleIdentifier /* server only */
  81. ) {
  82. var esModule
  83. var scriptExports = rawScriptExports = rawScriptExports || {}
  84. // ES6 modules interop
  85. var type = typeof rawScriptExports.default
  86. if (type === 'object' || type === 'function') {
  87. esModule = rawScriptExports
  88. scriptExports = rawScriptExports.default
  89. }
  90. // Vue.extend constructor export interop
  91. var options = typeof scriptExports === 'function'
  92. ? scriptExports.options
  93. : scriptExports
  94. // render functions
  95. if (compiledTemplate) {
  96. options.render = compiledTemplate.render
  97. options.staticRenderFns = compiledTemplate.staticRenderFns
  98. options._compiled = true
  99. }
  100. // functional template
  101. if (functionalTemplate) {
  102. options.functional = true
  103. }
  104. // scopedId
  105. if (scopeId) {
  106. options._scopeId = scopeId
  107. }
  108. var hook
  109. if (moduleIdentifier) { // server build
  110. hook = function (context) {
  111. // 2.3 injection
  112. context =
  113. context || // cached call
  114. (this.$vnode && this.$vnode.ssrContext) || // stateful
  115. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  116. // 2.2 with runInNewContext: true
  117. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  118. context = __VUE_SSR_CONTEXT__
  119. }
  120. // inject component styles
  121. if (injectStyles) {
  122. injectStyles.call(this, context)
  123. }
  124. // register component module identifier for async chunk inferrence
  125. if (context && context._registeredComponents) {
  126. context._registeredComponents.add(moduleIdentifier)
  127. }
  128. }
  129. // used by ssr in case component is cached and beforeCreate
  130. // never gets called
  131. options._ssrRegister = hook
  132. } else if (injectStyles) {
  133. hook = injectStyles
  134. }
  135. if (hook) {
  136. var functional = options.functional
  137. var existing = functional
  138. ? options.render
  139. : options.beforeCreate
  140. if (!functional) {
  141. // inject component registration as beforeCreate hook
  142. options.beforeCreate = existing
  143. ? [].concat(existing, hook)
  144. : [hook]
  145. } else {
  146. // for template-only hot-reload because in that case the render fn doesn't
  147. // go through the normalizer
  148. options._injectStyles = hook
  149. // register for functioal component in vue file
  150. options.render = function renderWithStyleInjection (h, context) {
  151. hook.call(context)
  152. return existing(h, context)
  153. }
  154. }
  155. }
  156. return {
  157. esModule: esModule,
  158. exports: scriptExports,
  159. options: options
  160. }
  161. }
  162. /***/ }),
  163. /***/ 1:
  164. /***/ (function(module, exports) {
  165. module.exports = require("element-ui/lib/mixins/emitter");
  166. /***/ }),
  167. /***/ 14:
  168. /***/ (function(module, exports) {
  169. module.exports = require("element-ui/lib/locale");
  170. /***/ }),
  171. /***/ 16:
  172. /***/ (function(module, exports) {
  173. module.exports = require("element-ui/lib/checkbox");
  174. /***/ }),
  175. /***/ 21:
  176. /***/ (function(module, exports) {
  177. module.exports = require("element-ui/lib/transitions/collapse-transition");
  178. /***/ }),
  179. /***/ 285:
  180. /***/ (function(module, exports, __webpack_require__) {
  181. module.exports = __webpack_require__(286);
  182. /***/ }),
  183. /***/ 286:
  184. /***/ (function(module, exports, __webpack_require__) {
  185. "use strict";
  186. exports.__esModule = true;
  187. var _tree = __webpack_require__(287);
  188. var _tree2 = _interopRequireDefault(_tree);
  189. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  190. /* istanbul ignore next */
  191. _tree2.default.install = function (Vue) {
  192. Vue.component(_tree2.default.name, _tree2.default);
  193. };
  194. exports.default = _tree2.default;
  195. /***/ }),
  196. /***/ 287:
  197. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  198. "use strict";
  199. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  200. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tree_vue__ = __webpack_require__(288);
  201. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tree_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tree_vue__);
  202. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_bdd5d816_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_tree_vue__ = __webpack_require__(294);
  203. var normalizeComponent = __webpack_require__(0)
  204. /* script */
  205. /* template */
  206. /* template functional */
  207. var __vue_template_functional__ = false
  208. /* styles */
  209. var __vue_styles__ = null
  210. /* scopeId */
  211. var __vue_scopeId__ = null
  212. /* moduleIdentifier (server only) */
  213. var __vue_module_identifier__ = null
  214. var Component = normalizeComponent(
  215. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tree_vue___default.a,
  216. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_bdd5d816_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_tree_vue__["a" /* default */],
  217. __vue_template_functional__,
  218. __vue_styles__,
  219. __vue_scopeId__,
  220. __vue_module_identifier__
  221. )
  222. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  223. /***/ }),
  224. /***/ 288:
  225. /***/ (function(module, exports, __webpack_require__) {
  226. "use strict";
  227. exports.__esModule = true;
  228. var _treeStore = __webpack_require__(289);
  229. var _treeStore2 = _interopRequireDefault(_treeStore);
  230. var _treeNode = __webpack_require__(291);
  231. var _treeNode2 = _interopRequireDefault(_treeNode);
  232. var _locale = __webpack_require__(14);
  233. var _emitter = __webpack_require__(1);
  234. var _emitter2 = _interopRequireDefault(_emitter);
  235. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  236. //
  237. //
  238. //
  239. //
  240. //
  241. //
  242. //
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. //
  250. //
  251. //
  252. //
  253. //
  254. //
  255. //
  256. exports.default = {
  257. name: 'ElTree',
  258. mixins: [_emitter2.default],
  259. components: {
  260. ElTreeNode: _treeNode2.default
  261. },
  262. data: function data() {
  263. return {
  264. store: null,
  265. root: null,
  266. currentNode: null,
  267. treeItems: null,
  268. checkboxItems: []
  269. };
  270. },
  271. props: {
  272. data: {
  273. type: Array
  274. },
  275. emptyText: {
  276. type: String,
  277. default: function _default() {
  278. return (0, _locale.t)('el.tree.emptyText');
  279. }
  280. },
  281. nodeKey: String,
  282. checkStrictly: Boolean,
  283. defaultExpandAll: Boolean,
  284. expandOnClickNode: {
  285. type: Boolean,
  286. default: true
  287. },
  288. checkDescendants: {
  289. type: Boolean,
  290. default: false
  291. },
  292. autoExpandParent: {
  293. type: Boolean,
  294. default: true
  295. },
  296. defaultCheckedKeys: Array,
  297. defaultExpandedKeys: Array,
  298. renderContent: Function,
  299. showCheckbox: {
  300. type: Boolean,
  301. default: false
  302. },
  303. props: {
  304. default: function _default() {
  305. return {
  306. children: 'children',
  307. label: 'label',
  308. icon: 'icon',
  309. disabled: 'disabled'
  310. };
  311. }
  312. },
  313. lazy: {
  314. type: Boolean,
  315. default: false
  316. },
  317. highlightCurrent: Boolean,
  318. load: Function,
  319. filterNodeMethod: Function,
  320. accordion: Boolean,
  321. indent: {
  322. type: Number,
  323. default: 18
  324. }
  325. },
  326. computed: {
  327. children: {
  328. set: function set(value) {
  329. this.data = value;
  330. },
  331. get: function get() {
  332. return this.data;
  333. }
  334. },
  335. treeItemArray: function treeItemArray() {
  336. return Array.prototype.slice.call(this.treeItems);
  337. }
  338. },
  339. watch: {
  340. defaultCheckedKeys: function defaultCheckedKeys(newVal) {
  341. this.store.defaultCheckedKeys = newVal;
  342. this.store.setDefaultCheckedKey(newVal);
  343. },
  344. defaultExpandedKeys: function defaultExpandedKeys(newVal) {
  345. this.store.defaultExpandedKeys = newVal;
  346. this.store.setDefaultExpandedKeys(newVal);
  347. },
  348. data: function data(newVal) {
  349. this.store.setData(newVal);
  350. },
  351. checkboxItems: function checkboxItems(val) {
  352. Array.prototype.forEach.call(val, function (checkbox) {
  353. checkbox.setAttribute('tabindex', -1);
  354. });
  355. }
  356. },
  357. methods: {
  358. filter: function filter(value) {
  359. if (!this.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter');
  360. this.store.filter(value);
  361. },
  362. getNodeKey: function getNodeKey(node, index) {
  363. var nodeKey = this.nodeKey;
  364. if (nodeKey && node) {
  365. return node.data[nodeKey];
  366. }
  367. return index;
  368. },
  369. getCheckedNodes: function getCheckedNodes(leafOnly) {
  370. return this.store.getCheckedNodes(leafOnly);
  371. },
  372. getCheckedKeys: function getCheckedKeys(leafOnly) {
  373. return this.store.getCheckedKeys(leafOnly);
  374. },
  375. getCurrentNode: function getCurrentNode() {
  376. var currentNode = this.store.getCurrentNode();
  377. return currentNode ? currentNode.data : null;
  378. },
  379. getCurrentKey: function getCurrentKey() {
  380. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in getCurrentKey');
  381. var currentNode = this.getCurrentNode();
  382. return currentNode ? currentNode[this.nodeKey] : null;
  383. },
  384. setCheckedNodes: function setCheckedNodes(nodes, leafOnly) {
  385. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
  386. this.store.setCheckedNodes(nodes, leafOnly);
  387. },
  388. setCheckedKeys: function setCheckedKeys(keys, leafOnly) {
  389. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedKeys');
  390. this.store.setCheckedKeys(keys, leafOnly);
  391. },
  392. setChecked: function setChecked(data, checked, deep) {
  393. this.store.setChecked(data, checked, deep);
  394. },
  395. setCurrentNode: function setCurrentNode(node) {
  396. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentNode');
  397. this.store.setUserCurrentNode(node);
  398. },
  399. setCurrentKey: function setCurrentKey(key) {
  400. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentKey');
  401. this.store.setCurrentNodeKey(key);
  402. },
  403. handleNodeExpand: function handleNodeExpand(nodeData, node, instance) {
  404. this.broadcast('ElTreeNode', 'tree-node-expand', node);
  405. this.$emit('node-expand', nodeData, node, instance);
  406. },
  407. updateKeyChildren: function updateKeyChildren(key, data) {
  408. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in updateKeyChild');
  409. this.store.updateChildren(key, data);
  410. },
  411. initTabindex: function initTabindex() {
  412. this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
  413. this.checkboxItems = this.$el.querySelectorAll('input[type=checkbox]');
  414. var checkedItem = this.$el.querySelectorAll('.is-checked[role=treeitem]');
  415. if (checkedItem.length) {
  416. checkedItem[0].setAttribute('tabindex', 0);
  417. return;
  418. }
  419. this.treeItems[0] && this.treeItems[0].setAttribute('tabindex', 0);
  420. },
  421. handelKeydown: function handelKeydown(ev) {
  422. var currentItem = ev.target;
  423. if (currentItem.className.indexOf('el-tree-node') === -1) return;
  424. ev.preventDefault();
  425. var keyCode = ev.keyCode;
  426. this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
  427. var currentIndex = this.treeItemArray.indexOf(currentItem);
  428. var nextIndex = void 0;
  429. if ([38, 40].indexOf(keyCode) > -1) {
  430. // up、down
  431. if (keyCode === 38) {
  432. // up
  433. nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0;
  434. } else {
  435. nextIndex = currentIndex < this.treeItemArray.length - 1 ? currentIndex + 1 : 0;
  436. }
  437. this.treeItemArray[nextIndex].focus(); // 选中
  438. }
  439. var hasInput = currentItem.querySelector('[type="checkbox"]');
  440. if ([37, 39].indexOf(keyCode) > -1) {
  441. // left、right 展开
  442. currentItem.click(); // 选中
  443. }
  444. if ([13, 32].indexOf(keyCode) > -1) {
  445. // space enter选中checkbox
  446. if (hasInput) {
  447. hasInput.click();
  448. }
  449. }
  450. }
  451. },
  452. created: function created() {
  453. this.isTree = true;
  454. this.store = new _treeStore2.default({
  455. key: this.nodeKey,
  456. data: this.data,
  457. lazy: this.lazy,
  458. props: this.props,
  459. load: this.load,
  460. currentNodeKey: this.currentNodeKey,
  461. checkStrictly: this.checkStrictly,
  462. checkDescendants: this.checkDescendants,
  463. defaultCheckedKeys: this.defaultCheckedKeys,
  464. defaultExpandedKeys: this.defaultExpandedKeys,
  465. autoExpandParent: this.autoExpandParent,
  466. defaultExpandAll: this.defaultExpandAll,
  467. filterNodeMethod: this.filterNodeMethod
  468. });
  469. this.root = this.store.root;
  470. },
  471. mounted: function mounted() {
  472. this.initTabindex();
  473. this.$el.addEventListener('keydown', this.handelKeydown);
  474. },
  475. updated: function updated() {
  476. this.treeItems = this.$el.querySelectorAll('[role=treeitem]');
  477. this.checkboxItems = this.$el.querySelectorAll('input[type=checkbox]');
  478. }
  479. };
  480. /***/ }),
  481. /***/ 289:
  482. /***/ (function(module, exports, __webpack_require__) {
  483. "use strict";
  484. exports.__esModule = true;
  485. 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; };
  486. var _node = __webpack_require__(290);
  487. var _node2 = _interopRequireDefault(_node);
  488. var _util = __webpack_require__(48);
  489. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  490. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  491. var TreeStore = function () {
  492. function TreeStore(options) {
  493. var _this = this;
  494. _classCallCheck(this, TreeStore);
  495. this.currentNode = null;
  496. this.currentNodeKey = null;
  497. for (var option in options) {
  498. if (options.hasOwnProperty(option)) {
  499. this[option] = options[option];
  500. }
  501. }
  502. this.nodesMap = {};
  503. this.root = new _node2.default({
  504. data: this.data,
  505. store: this
  506. });
  507. if (this.lazy && this.load) {
  508. var loadFn = this.load;
  509. loadFn(this.root, function (data) {
  510. _this.root.doCreateChildren(data);
  511. _this._initDefaultCheckedNodes();
  512. });
  513. } else {
  514. this._initDefaultCheckedNodes();
  515. }
  516. }
  517. TreeStore.prototype.filter = function filter(value) {
  518. var filterNodeMethod = this.filterNodeMethod;
  519. var traverse = function traverse(node) {
  520. var childNodes = node.root ? node.root.childNodes : node.childNodes;
  521. childNodes.forEach(function (child) {
  522. child.visible = filterNodeMethod.call(child, value, child.data, child);
  523. traverse(child);
  524. });
  525. if (!node.visible && childNodes.length) {
  526. var allHidden = true;
  527. childNodes.forEach(function (child) {
  528. if (child.visible) allHidden = false;
  529. });
  530. if (node.root) {
  531. node.root.visible = allHidden === false;
  532. } else {
  533. node.visible = allHidden === false;
  534. }
  535. }
  536. if (!value) return;
  537. if (node.visible && !node.isLeaf) node.expand();
  538. };
  539. traverse(this);
  540. };
  541. TreeStore.prototype.setData = function setData(newVal) {
  542. var instanceChanged = newVal !== this.root.data;
  543. this.root.setData(newVal);
  544. if (instanceChanged) {
  545. this._initDefaultCheckedNodes();
  546. }
  547. };
  548. TreeStore.prototype.getNode = function getNode(data) {
  549. var key = (typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object' ? data : (0, _util.getNodeKey)(this.key, data);
  550. return this.nodesMap[key];
  551. };
  552. TreeStore.prototype.insertBefore = function insertBefore(data, refData) {
  553. var refNode = this.getNode(refData);
  554. refNode.parent.insertBefore({ data: data }, refNode);
  555. };
  556. TreeStore.prototype.insertAfter = function insertAfter(data, refData) {
  557. var refNode = this.getNode(refData);
  558. refNode.parent.insertAfter({ data: data }, refNode);
  559. };
  560. TreeStore.prototype.remove = function remove(data) {
  561. var node = this.getNode(data);
  562. if (node) {
  563. node.parent.removeChild(node);
  564. }
  565. };
  566. TreeStore.prototype.append = function append(data, parentData) {
  567. var parentNode = parentData ? this.getNode(parentData) : this.root;
  568. if (parentNode) {
  569. parentNode.insertChild({ data: data });
  570. }
  571. };
  572. TreeStore.prototype._initDefaultCheckedNodes = function _initDefaultCheckedNodes() {
  573. var _this2 = this;
  574. var defaultCheckedKeys = this.defaultCheckedKeys || [];
  575. var nodesMap = this.nodesMap;
  576. defaultCheckedKeys.forEach(function (checkedKey) {
  577. var node = nodesMap[checkedKey];
  578. if (node) {
  579. node.setChecked(true, !_this2.checkStrictly);
  580. }
  581. });
  582. };
  583. TreeStore.prototype._initDefaultCheckedNode = function _initDefaultCheckedNode(node) {
  584. var defaultCheckedKeys = this.defaultCheckedKeys || [];
  585. if (defaultCheckedKeys.indexOf(node.key) !== -1) {
  586. node.setChecked(true, !this.checkStrictly);
  587. }
  588. };
  589. TreeStore.prototype.setDefaultCheckedKey = function setDefaultCheckedKey(newVal) {
  590. if (newVal !== this.defaultCheckedKeys) {
  591. this.defaultCheckedKeys = newVal;
  592. this._initDefaultCheckedNodes();
  593. }
  594. };
  595. TreeStore.prototype.registerNode = function registerNode(node) {
  596. var key = this.key;
  597. if (!key || !node || !node.data) return;
  598. var nodeKey = node.key;
  599. if (nodeKey !== undefined) this.nodesMap[node.key] = node;
  600. };
  601. TreeStore.prototype.deregisterNode = function deregisterNode(node) {
  602. var key = this.key;
  603. if (!key || !node || !node.data) return;
  604. var childNodes = node.childNodes;
  605. for (var i = 0, j = childNodes.length; i < j; i++) {
  606. var child = childNodes[i];
  607. this.deregisterNode(child);
  608. }
  609. delete this.nodesMap[node.key];
  610. };
  611. TreeStore.prototype.getCheckedNodes = function getCheckedNodes() {
  612. var leafOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  613. var checkedNodes = [];
  614. var traverse = function traverse(node) {
  615. var childNodes = node.root ? node.root.childNodes : node.childNodes;
  616. childNodes.forEach(function (child) {
  617. if (!leafOnly && child.checked || leafOnly && child.isLeaf && child.checked) {
  618. checkedNodes.push(child.data);
  619. }
  620. traverse(child);
  621. });
  622. };
  623. traverse(this);
  624. return checkedNodes;
  625. };
  626. TreeStore.prototype.getCheckedKeys = function getCheckedKeys() {
  627. var leafOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  628. var key = this.key;
  629. var allNodes = this._getAllNodes();
  630. var keys = [];
  631. allNodes.forEach(function (node) {
  632. if (!leafOnly || leafOnly && node.isLeaf) {
  633. if (node.checked) {
  634. keys.push((node.data || {})[key]);
  635. }
  636. }
  637. });
  638. return keys;
  639. };
  640. TreeStore.prototype._getAllNodes = function _getAllNodes() {
  641. var allNodes = [];
  642. var nodesMap = this.nodesMap;
  643. for (var nodeKey in nodesMap) {
  644. if (nodesMap.hasOwnProperty(nodeKey)) {
  645. allNodes.push(nodesMap[nodeKey]);
  646. }
  647. }
  648. return allNodes;
  649. };
  650. TreeStore.prototype.updateChildren = function updateChildren(key, data) {
  651. var node = this.nodesMap[key];
  652. if (!node) return;
  653. var childNodes = node.childNodes;
  654. for (var i = childNodes.length - 1; i >= 0; i--) {
  655. var child = childNodes[i];
  656. this.remove(child.data);
  657. }
  658. for (var _i = 0, j = data.length; _i < j; _i++) {
  659. var _child = data[_i];
  660. this.append(_child, node.data);
  661. }
  662. };
  663. TreeStore.prototype._setCheckedKeys = function _setCheckedKeys(key) {
  664. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  665. var checkedKeys = arguments[2];
  666. var allNodes = this._getAllNodes().sort(function (a, b) {
  667. return b.level - a.level;
  668. });
  669. var cache = Object.create(null);
  670. var keys = Object.keys(checkedKeys);
  671. allNodes.forEach(function (node) {
  672. return node.setChecked(false, false);
  673. });
  674. for (var i = 0, j = allNodes.length; i < j; i++) {
  675. var node = allNodes[i];
  676. var nodeKey = node.data[key].toString();
  677. var checked = keys.indexOf(nodeKey) > -1;
  678. if (!checked) {
  679. if (node.checked && !cache[nodeKey]) {
  680. node.setChecked(false, false);
  681. }
  682. continue;
  683. }
  684. var parent = node.parent;
  685. while (parent && parent.level > 0) {
  686. cache[parent.data[key]] = true;
  687. parent = parent.parent;
  688. }
  689. if (node.isLeaf || this.checkStrictly) {
  690. node.setChecked(true, false);
  691. continue;
  692. }
  693. node.setChecked(true, true);
  694. if (leafOnly) {
  695. (function () {
  696. node.setChecked(false, false);
  697. var traverse = function traverse(node) {
  698. var childNodes = node.childNodes;
  699. childNodes.forEach(function (child) {
  700. if (!child.isLeaf) {
  701. child.setChecked(false, false);
  702. }
  703. traverse(child);
  704. });
  705. };
  706. traverse(node);
  707. })();
  708. }
  709. }
  710. };
  711. TreeStore.prototype.setCheckedNodes = function setCheckedNodes(array) {
  712. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  713. var key = this.key;
  714. var checkedKeys = {};
  715. array.forEach(function (item) {
  716. checkedKeys[(item || {})[key]] = true;
  717. });
  718. this._setCheckedKeys(key, leafOnly, checkedKeys);
  719. };
  720. TreeStore.prototype.setCheckedKeys = function setCheckedKeys(keys) {
  721. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  722. this.defaultCheckedKeys = keys;
  723. var key = this.key;
  724. var checkedKeys = {};
  725. keys.forEach(function (key) {
  726. checkedKeys[key] = true;
  727. });
  728. this._setCheckedKeys(key, leafOnly, checkedKeys);
  729. };
  730. TreeStore.prototype.setDefaultExpandedKeys = function setDefaultExpandedKeys(keys) {
  731. var _this3 = this;
  732. keys = keys || [];
  733. this.defaultExpandedKeys = keys;
  734. keys.forEach(function (key) {
  735. var node = _this3.getNode(key);
  736. if (node) node.expand(null, _this3.autoExpandParent);
  737. });
  738. };
  739. TreeStore.prototype.setChecked = function setChecked(data, checked, deep) {
  740. var node = this.getNode(data);
  741. if (node) {
  742. node.setChecked(!!checked, deep);
  743. }
  744. };
  745. TreeStore.prototype.getCurrentNode = function getCurrentNode() {
  746. return this.currentNode;
  747. };
  748. TreeStore.prototype.setCurrentNode = function setCurrentNode(node) {
  749. this.currentNode = node;
  750. };
  751. TreeStore.prototype.setUserCurrentNode = function setUserCurrentNode(node) {
  752. var key = node[this.key];
  753. var currNode = this.nodesMap[key];
  754. this.setCurrentNode(currNode);
  755. };
  756. TreeStore.prototype.setCurrentNodeKey = function setCurrentNodeKey(key) {
  757. var node = this.getNode(key);
  758. if (node) {
  759. this.currentNode = node;
  760. }
  761. };
  762. return TreeStore;
  763. }();
  764. exports.default = TreeStore;
  765. ;
  766. /***/ }),
  767. /***/ 290:
  768. /***/ (function(module, exports, __webpack_require__) {
  769. "use strict";
  770. exports.__esModule = true;
  771. exports.getChildState = undefined;
  772. 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; };
  773. 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; }; }();
  774. var _merge = __webpack_require__(9);
  775. var _merge2 = _interopRequireDefault(_merge);
  776. var _util = __webpack_require__(48);
  777. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  778. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  779. var getChildState = exports.getChildState = function getChildState(node) {
  780. var all = true;
  781. var none = true;
  782. var allWithoutDisable = true;
  783. for (var i = 0, j = node.length; i < j; i++) {
  784. var n = node[i];
  785. if (n.checked !== true || n.indeterminate) {
  786. all = false;
  787. if (!n.disabled) {
  788. allWithoutDisable = false;
  789. }
  790. }
  791. if (n.checked !== false || n.indeterminate) {
  792. none = false;
  793. }
  794. }
  795. return { all: all, none: none, allWithoutDisable: allWithoutDisable, half: !all && !none };
  796. };
  797. var reInitChecked = function reInitChecked(node) {
  798. if (node.childNodes.length === 0) return;
  799. var _getChildState = getChildState(node.childNodes),
  800. all = _getChildState.all,
  801. none = _getChildState.none,
  802. half = _getChildState.half;
  803. if (all) {
  804. node.checked = true;
  805. node.indeterminate = false;
  806. } else if (half) {
  807. node.checked = false;
  808. node.indeterminate = true;
  809. } else if (none) {
  810. node.checked = false;
  811. node.indeterminate = false;
  812. }
  813. var parent = node.parent;
  814. if (!parent || parent.level === 0) return;
  815. if (!node.store.checkStrictly) {
  816. reInitChecked(parent);
  817. }
  818. };
  819. var getPropertyFromData = function getPropertyFromData(node, prop) {
  820. var props = node.store.props;
  821. var data = node.data || {};
  822. var config = props[prop];
  823. if (typeof config === 'function') {
  824. return config(data, node);
  825. } else if (typeof config === 'string') {
  826. return data[config];
  827. } else if (typeof config === 'undefined') {
  828. var dataProp = data[prop];
  829. return dataProp === undefined ? '' : dataProp;
  830. }
  831. };
  832. var nodeIdSeed = 0;
  833. var Node = function () {
  834. function Node(options) {
  835. _classCallCheck(this, Node);
  836. this.id = nodeIdSeed++;
  837. this.text = null;
  838. this.checked = false;
  839. this.indeterminate = false;
  840. this.data = null;
  841. this.expanded = false;
  842. this.parent = null;
  843. this.visible = true;
  844. for (var name in options) {
  845. if (options.hasOwnProperty(name)) {
  846. this[name] = options[name];
  847. }
  848. }
  849. // internal
  850. this.level = 0;
  851. this.loaded = false;
  852. this.childNodes = [];
  853. this.loading = false;
  854. if (this.parent) {
  855. this.level = this.parent.level + 1;
  856. }
  857. var store = this.store;
  858. if (!store) {
  859. throw new Error('[Node]store is required!');
  860. }
  861. store.registerNode(this);
  862. var props = store.props;
  863. if (props && typeof props.isLeaf !== 'undefined') {
  864. var isLeaf = getPropertyFromData(this, 'isLeaf');
  865. if (typeof isLeaf === 'boolean') {
  866. this.isLeafByUser = isLeaf;
  867. }
  868. }
  869. if (store.lazy !== true && this.data) {
  870. this.setData(this.data);
  871. if (store.defaultExpandAll) {
  872. this.expanded = true;
  873. }
  874. } else if (this.level > 0 && store.lazy && store.defaultExpandAll) {
  875. this.expand();
  876. }
  877. if (!this.data) return;
  878. var defaultExpandedKeys = store.defaultExpandedKeys;
  879. var key = store.key;
  880. if (key && defaultExpandedKeys && defaultExpandedKeys.indexOf(this.key) !== -1) {
  881. this.expand(null, store.autoExpandParent);
  882. }
  883. if (key && store.currentNodeKey !== undefined && this.key === store.currentNodeKey) {
  884. store.currentNode = this;
  885. }
  886. if (store.lazy) {
  887. store._initDefaultCheckedNode(this);
  888. }
  889. this.updateLeafState();
  890. }
  891. Node.prototype.setData = function setData(data) {
  892. if (!Array.isArray(data)) {
  893. (0, _util.markNodeData)(this, data);
  894. }
  895. this.data = data;
  896. this.childNodes = [];
  897. var children = void 0;
  898. if (this.level === 0 && this.data instanceof Array) {
  899. children = this.data;
  900. } else {
  901. children = getPropertyFromData(this, 'children') || [];
  902. }
  903. for (var i = 0, j = children.length; i < j; i++) {
  904. this.insertChild({ data: children[i] });
  905. }
  906. };
  907. Node.prototype.insertChild = function insertChild(child, index) {
  908. if (!child) throw new Error('insertChild error: child is required.');
  909. if (!(child instanceof Node)) {
  910. (0, _merge2.default)(child, {
  911. parent: this,
  912. store: this.store
  913. });
  914. child = new Node(child);
  915. }
  916. child.level = this.level + 1;
  917. if (typeof index === 'undefined' || index < 0) {
  918. this.childNodes.push(child);
  919. } else {
  920. this.childNodes.splice(index, 0, child);
  921. }
  922. this.updateLeafState();
  923. };
  924. Node.prototype.insertBefore = function insertBefore(child, ref) {
  925. var index = void 0;
  926. if (ref) {
  927. index = this.childNodes.indexOf(ref);
  928. }
  929. this.insertChild(child, index);
  930. };
  931. Node.prototype.insertAfter = function insertAfter(child, ref) {
  932. var index = void 0;
  933. if (ref) {
  934. index = this.childNodes.indexOf(ref);
  935. if (index !== -1) index += 1;
  936. }
  937. this.insertChild(child, index);
  938. };
  939. Node.prototype.removeChild = function removeChild(child) {
  940. var index = this.childNodes.indexOf(child);
  941. if (index > -1) {
  942. this.store && this.store.deregisterNode(child);
  943. child.parent = null;
  944. this.childNodes.splice(index, 1);
  945. }
  946. this.updateLeafState();
  947. };
  948. Node.prototype.removeChildByData = function removeChildByData(data) {
  949. var targetNode = null;
  950. this.childNodes.forEach(function (node) {
  951. if (node.data === data) {
  952. targetNode = node;
  953. }
  954. });
  955. if (targetNode) {
  956. this.removeChild(targetNode);
  957. }
  958. };
  959. Node.prototype.expand = function expand(callback, expandParent) {
  960. var _this = this;
  961. var done = function done() {
  962. if (expandParent) {
  963. var parent = _this.parent;
  964. while (parent.level > 0) {
  965. parent.expanded = true;
  966. parent = parent.parent;
  967. }
  968. }
  969. _this.expanded = true;
  970. if (callback) callback();
  971. };
  972. if (this.shouldLoadData()) {
  973. this.loadData(function (data) {
  974. if (data instanceof Array) {
  975. if (_this.checked) {
  976. _this.setChecked(true, true);
  977. } else {
  978. reInitChecked(_this);
  979. }
  980. done();
  981. }
  982. });
  983. } else {
  984. done();
  985. }
  986. };
  987. Node.prototype.doCreateChildren = function doCreateChildren(array) {
  988. var _this2 = this;
  989. var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  990. array.forEach(function (item) {
  991. _this2.insertChild((0, _merge2.default)({ data: item }, defaultProps));
  992. });
  993. };
  994. Node.prototype.collapse = function collapse() {
  995. this.expanded = false;
  996. };
  997. Node.prototype.shouldLoadData = function shouldLoadData() {
  998. return this.store.lazy === true && this.store.load && !this.loaded;
  999. };
  1000. Node.prototype.updateLeafState = function updateLeafState() {
  1001. if (this.store.lazy === true && this.loaded !== true && typeof this.isLeafByUser !== 'undefined') {
  1002. this.isLeaf = this.isLeafByUser;
  1003. return;
  1004. }
  1005. var childNodes = this.childNodes;
  1006. if (!this.store.lazy || this.store.lazy === true && this.loaded === true) {
  1007. this.isLeaf = !childNodes || childNodes.length === 0;
  1008. return;
  1009. }
  1010. this.isLeaf = false;
  1011. };
  1012. Node.prototype.setChecked = function setChecked(value, deep, recursion, passValue) {
  1013. var _this3 = this;
  1014. this.indeterminate = value === 'half';
  1015. this.checked = value === true;
  1016. if (this.store.checkStrictly) return;
  1017. if (!(this.shouldLoadData() && !this.store.checkDescendants)) {
  1018. var _ret = function () {
  1019. var _getChildState2 = getChildState(_this3.childNodes),
  1020. all = _getChildState2.all,
  1021. allWithoutDisable = _getChildState2.allWithoutDisable;
  1022. if (!_this3.isLeaf && !all && allWithoutDisable) {
  1023. _this3.checked = false;
  1024. value = false;
  1025. }
  1026. var handleDescendants = function handleDescendants() {
  1027. if (deep) {
  1028. var childNodes = _this3.childNodes;
  1029. for (var i = 0, j = childNodes.length; i < j; i++) {
  1030. var child = childNodes[i];
  1031. passValue = passValue || value !== false;
  1032. var isCheck = child.disabled ? child.checked : passValue;
  1033. child.setChecked(isCheck, deep, true, passValue);
  1034. }
  1035. var _getChildState3 = getChildState(childNodes),
  1036. half = _getChildState3.half,
  1037. _all = _getChildState3.all;
  1038. if (!_all) {
  1039. _this3.checked = _all;
  1040. _this3.indeterminate = half;
  1041. }
  1042. }
  1043. };
  1044. if (_this3.shouldLoadData()) {
  1045. // Only work on lazy load data.
  1046. _this3.loadData(function () {
  1047. handleDescendants();
  1048. reInitChecked(_this3);
  1049. }, {
  1050. checked: value !== false
  1051. });
  1052. return {
  1053. v: void 0
  1054. };
  1055. } else {
  1056. handleDescendants();
  1057. }
  1058. }();
  1059. if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
  1060. }
  1061. var parent = this.parent;
  1062. if (!parent || parent.level === 0) return;
  1063. if (!recursion) {
  1064. reInitChecked(parent);
  1065. }
  1066. };
  1067. Node.prototype.getChildren = function getChildren() {
  1068. // this is data
  1069. var data = this.data;
  1070. if (!data) return null;
  1071. var props = this.store.props;
  1072. var children = 'children';
  1073. if (props) {
  1074. children = props.children || 'children';
  1075. }
  1076. if (data[children] === undefined) {
  1077. data[children] = null;
  1078. }
  1079. return data[children];
  1080. };
  1081. Node.prototype.updateChildren = function updateChildren() {
  1082. var _this4 = this;
  1083. var newData = this.getChildren() || [];
  1084. var oldData = this.childNodes.map(function (node) {
  1085. return node.data;
  1086. });
  1087. var newDataMap = {};
  1088. var newNodes = [];
  1089. newData.forEach(function (item, index) {
  1090. if (item[_util.NODE_KEY]) {
  1091. newDataMap[item[_util.NODE_KEY]] = { index: index, data: item };
  1092. } else {
  1093. newNodes.push({ index: index, data: item });
  1094. }
  1095. });
  1096. oldData.forEach(function (item) {
  1097. if (!newDataMap[item[_util.NODE_KEY]]) _this4.removeChildByData(item);
  1098. });
  1099. newNodes.forEach(function (_ref) {
  1100. var index = _ref.index,
  1101. data = _ref.data;
  1102. _this4.insertChild({ data: data }, index);
  1103. });
  1104. this.updateLeafState();
  1105. };
  1106. Node.prototype.loadData = function loadData(callback) {
  1107. var _this5 = this;
  1108. var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1109. if (this.store.lazy === true && this.store.load && !this.loaded && (!this.loading || Object.keys(defaultProps).length)) {
  1110. this.loading = true;
  1111. var resolve = function resolve(children) {
  1112. _this5.loaded = true;
  1113. _this5.loading = false;
  1114. _this5.childNodes = [];
  1115. _this5.doCreateChildren(children, defaultProps);
  1116. _this5.updateLeafState();
  1117. if (callback) {
  1118. callback.call(_this5, children);
  1119. }
  1120. };
  1121. this.store.load(this, resolve);
  1122. } else {
  1123. if (callback) {
  1124. callback.call(this);
  1125. }
  1126. }
  1127. };
  1128. _createClass(Node, [{
  1129. key: 'label',
  1130. get: function get() {
  1131. return getPropertyFromData(this, 'label');
  1132. }
  1133. }, {
  1134. key: 'icon',
  1135. get: function get() {
  1136. return getPropertyFromData(this, 'icon');
  1137. }
  1138. }, {
  1139. key: 'key',
  1140. get: function get() {
  1141. var nodeKey = this.store.key;
  1142. if (this.data) return this.data[nodeKey];
  1143. return null;
  1144. }
  1145. }, {
  1146. key: 'disabled',
  1147. get: function get() {
  1148. return getPropertyFromData(this, 'disabled');
  1149. }
  1150. }]);
  1151. return Node;
  1152. }();
  1153. exports.default = Node;
  1154. /***/ }),
  1155. /***/ 291:
  1156. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1157. "use strict";
  1158. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  1159. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tree_node_vue__ = __webpack_require__(292);
  1160. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tree_node_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tree_node_vue__);
  1161. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_751ff8ec_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_tree_node_vue__ = __webpack_require__(293);
  1162. var normalizeComponent = __webpack_require__(0)
  1163. /* script */
  1164. /* template */
  1165. /* template functional */
  1166. var __vue_template_functional__ = false
  1167. /* styles */
  1168. var __vue_styles__ = null
  1169. /* scopeId */
  1170. var __vue_scopeId__ = null
  1171. /* moduleIdentifier (server only) */
  1172. var __vue_module_identifier__ = null
  1173. var Component = normalizeComponent(
  1174. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tree_node_vue___default.a,
  1175. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_751ff8ec_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_tree_node_vue__["a" /* default */],
  1176. __vue_template_functional__,
  1177. __vue_styles__,
  1178. __vue_scopeId__,
  1179. __vue_module_identifier__
  1180. )
  1181. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  1182. /***/ }),
  1183. /***/ 292:
  1184. /***/ (function(module, exports, __webpack_require__) {
  1185. "use strict";
  1186. exports.__esModule = true;
  1187. var _collapseTransition = __webpack_require__(21);
  1188. var _collapseTransition2 = _interopRequireDefault(_collapseTransition);
  1189. var _checkbox = __webpack_require__(16);
  1190. var _checkbox2 = _interopRequireDefault(_checkbox);
  1191. var _emitter = __webpack_require__(1);
  1192. var _emitter2 = _interopRequireDefault(_emitter);
  1193. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1194. exports.default = {
  1195. name: 'ElTreeNode',
  1196. componentName: 'ElTreeNode',
  1197. mixins: [_emitter2.default],
  1198. props: {
  1199. node: {
  1200. default: function _default() {
  1201. return {};
  1202. }
  1203. },
  1204. props: {},
  1205. renderContent: Function
  1206. },
  1207. components: {
  1208. ElCollapseTransition: _collapseTransition2.default,
  1209. ElCheckbox: _checkbox2.default,
  1210. NodeContent: {
  1211. props: {
  1212. node: {
  1213. required: true
  1214. }
  1215. },
  1216. render: function render(h) {
  1217. var parent = this.$parent;
  1218. var node = this.node;
  1219. var data = node.data;
  1220. var store = node.store;
  1221. return parent.renderContent ? parent.renderContent.call(parent._renderProxy, h, { _self: parent.tree.$vnode.context, node: node, data: data, store: store }) : h(
  1222. 'span',
  1223. { 'class': 'el-tree-node__label' },
  1224. [this.node.label]
  1225. );
  1226. }
  1227. }
  1228. },
  1229. data: function data() {
  1230. return {
  1231. tree: null,
  1232. expanded: false,
  1233. childNodeRendered: false,
  1234. showCheckbox: false,
  1235. oldChecked: null,
  1236. oldIndeterminate: null
  1237. };
  1238. },
  1239. watch: {
  1240. 'node.indeterminate': function nodeIndeterminate(val) {
  1241. this.handleSelectChange(this.node.checked, val);
  1242. },
  1243. 'node.checked': function nodeChecked(val) {
  1244. this.handleSelectChange(val, this.node.indeterminate);
  1245. },
  1246. 'node.expanded': function nodeExpanded(val) {
  1247. var _this = this;
  1248. this.$nextTick(function () {
  1249. return _this.expanded = val;
  1250. });
  1251. if (val) {
  1252. this.childNodeRendered = true;
  1253. }
  1254. }
  1255. },
  1256. methods: {
  1257. getNodeKey: function getNodeKey(node, index) {
  1258. var nodeKey = this.tree.nodeKey;
  1259. if (nodeKey && node) {
  1260. return node.data[nodeKey];
  1261. }
  1262. return index;
  1263. },
  1264. handleSelectChange: function handleSelectChange(checked, indeterminate) {
  1265. if (this.oldChecked !== checked && this.oldIndeterminate !== indeterminate) {
  1266. this.tree.$emit('check-change', this.node.data, checked, indeterminate);
  1267. }
  1268. this.oldChecked = checked;
  1269. this.indeterminate = indeterminate;
  1270. },
  1271. handleClick: function handleClick() {
  1272. var store = this.tree.store;
  1273. store.setCurrentNode(this.node);
  1274. this.tree.$emit('current-change', store.currentNode ? store.currentNode.data : null, store.currentNode);
  1275. this.tree.currentNode = this;
  1276. if (this.tree.expandOnClickNode) {
  1277. this.handleExpandIconClick();
  1278. }
  1279. this.tree.$emit('node-click', this.node.data, this.node, this);
  1280. },
  1281. handleExpandIconClick: function handleExpandIconClick() {
  1282. if (this.node.isLeaf) return;
  1283. if (this.expanded) {
  1284. this.tree.$emit('node-collapse', this.node.data, this.node, this);
  1285. this.node.collapse();
  1286. } else {
  1287. this.node.expand();
  1288. this.$emit('node-expand', this.node.data, this.node, this);
  1289. }
  1290. },
  1291. handleCheckChange: function handleCheckChange(value, ev) {
  1292. this.node.setChecked(ev.target.checked, !this.tree.checkStrictly);
  1293. },
  1294. handleChildNodeExpand: function handleChildNodeExpand(nodeData, node, instance) {
  1295. this.broadcast('ElTreeNode', 'tree-node-expand', node);
  1296. this.tree.$emit('node-expand', nodeData, node, instance);
  1297. }
  1298. },
  1299. created: function created() {
  1300. var _this2 = this;
  1301. var parent = this.$parent;
  1302. if (parent.isTree) {
  1303. this.tree = parent;
  1304. } else {
  1305. this.tree = parent.tree;
  1306. }
  1307. var tree = this.tree;
  1308. if (!tree) {
  1309. console.warn('Can not find node\'s tree.');
  1310. }
  1311. var props = tree.props || {};
  1312. var childrenKey = props['children'] || 'children';
  1313. this.$watch('node.data.' + childrenKey, function () {
  1314. _this2.node.updateChildren();
  1315. });
  1316. this.showCheckbox = tree.showCheckbox;
  1317. if (this.node.expanded) {
  1318. this.expanded = true;
  1319. this.childNodeRendered = true;
  1320. }
  1321. if (this.tree.accordion) {
  1322. this.$on('tree-node-expand', function (node) {
  1323. if (_this2.node !== node) {
  1324. _this2.node.collapse();
  1325. }
  1326. });
  1327. }
  1328. }
  1329. }; //
  1330. //
  1331. //
  1332. //
  1333. //
  1334. //
  1335. //
  1336. //
  1337. //
  1338. //
  1339. //
  1340. //
  1341. //
  1342. //
  1343. //
  1344. //
  1345. //
  1346. //
  1347. //
  1348. //
  1349. //
  1350. //
  1351. //
  1352. //
  1353. //
  1354. //
  1355. //
  1356. //
  1357. //
  1358. //
  1359. //
  1360. //
  1361. //
  1362. //
  1363. //
  1364. //
  1365. //
  1366. //
  1367. //
  1368. //
  1369. //
  1370. //
  1371. //
  1372. //
  1373. //
  1374. //
  1375. //
  1376. //
  1377. //
  1378. //
  1379. //
  1380. //
  1381. //
  1382. //
  1383. //
  1384. //
  1385. //
  1386. //
  1387. //
  1388. //
  1389. /***/ }),
  1390. /***/ 293:
  1391. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1392. "use strict";
  1393. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{directives:[{name:"show",rawName:"v-show",value:(_vm.node.visible),expression:"node.visible"}],staticClass:"el-tree-node",class:{
  1394. 'is-expanded': _vm.expanded,
  1395. 'is-current': _vm.tree.store.currentNode === _vm.node,
  1396. 'is-hidden': !_vm.node.visible,
  1397. 'is-focusable': !_vm.node.disabled,
  1398. 'is-checked': !_vm.node.disabled && _vm.node.checked
  1399. },attrs:{"role":"treeitem","tabindex":"-1","aria-expanded":_vm.expanded,"aria-disabled":_vm.node.disabled,"aria-checked":_vm.node.checked},on:{"click":function($event){$event.stopPropagation();_vm.handleClick($event)}}},[_c('div',{staticClass:"el-tree-node__content",style:({ 'padding-left': (_vm.node.level - 1) * _vm.tree.indent + 'px' })},[_c('span',{staticClass:"el-tree-node__expand-icon el-icon-caret-right",class:{ 'is-leaf': _vm.node.isLeaf, expanded: !_vm.node.isLeaf && _vm.expanded },on:{"click":function($event){$event.stopPropagation();_vm.handleExpandIconClick($event)}}}),(_vm.showCheckbox)?_c('el-checkbox',{attrs:{"indeterminate":_vm.node.indeterminate,"disabled":!!_vm.node.disabled},on:{"change":_vm.handleCheckChange},nativeOn:{"click":function($event){$event.stopPropagation();}},model:{value:(_vm.node.checked),callback:function ($$v) {_vm.$set(_vm.node, "checked", $$v)},expression:"node.checked"}}):_vm._e(),(_vm.node.loading)?_c('span',{staticClass:"el-tree-node__loading-icon el-icon-loading"}):_vm._e(),_c('node-content',{attrs:{"node":_vm.node}})],1),_c('el-collapse-transition',[(_vm.childNodeRendered)?_c('div',{directives:[{name:"show",rawName:"v-show",value:(_vm.expanded),expression:"expanded"}],staticClass:"el-tree-node__children",attrs:{"role":"group","aria-expanded":_vm.expanded}},_vm._l((_vm.node.childNodes),function(child){return _c('el-tree-node',{key:_vm.getNodeKey(child),attrs:{"render-content":_vm.renderContent,"node":child},on:{"node-expand":_vm.handleChildNodeExpand}})})):_vm._e()])],1)}
  1400. var staticRenderFns = []
  1401. var esExports = { render: render, staticRenderFns: staticRenderFns }
  1402. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  1403. /***/ }),
  1404. /***/ 294:
  1405. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1406. "use strict";
  1407. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"el-tree",class:{ 'el-tree--highlight-current': _vm.highlightCurrent },attrs:{"role":"tree"}},[_vm._l((_vm.root.childNodes),function(child){return _c('el-tree-node',{key:_vm.getNodeKey(child),attrs:{"node":child,"props":_vm.props,"render-content":_vm.renderContent},on:{"node-expand":_vm.handleNodeExpand}})}),(!_vm.root.childNodes || _vm.root.childNodes.length === 0)?_c('div',{staticClass:"el-tree__empty-block"},[_c('span',{staticClass:"el-tree__empty-text"},[_vm._v(_vm._s(_vm.emptyText))])]):_vm._e()],2)}
  1408. var staticRenderFns = []
  1409. var esExports = { render: render, staticRenderFns: staticRenderFns }
  1410. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  1411. /***/ }),
  1412. /***/ 48:
  1413. /***/ (function(module, exports, __webpack_require__) {
  1414. "use strict";
  1415. exports.__esModule = true;
  1416. var NODE_KEY = exports.NODE_KEY = '$treeNodeId';
  1417. var markNodeData = exports.markNodeData = function markNodeData(node, data) {
  1418. if (data[NODE_KEY]) return;
  1419. Object.defineProperty(data, NODE_KEY, {
  1420. value: node.id,
  1421. enumerable: false,
  1422. configurable: false,
  1423. writable: false
  1424. });
  1425. };
  1426. var getNodeKey = exports.getNodeKey = function getNodeKey(key, data) {
  1427. if (!key) return data[NODE_KEY];
  1428. return data[key];
  1429. };
  1430. /***/ }),
  1431. /***/ 9:
  1432. /***/ (function(module, exports) {
  1433. module.exports = require("element-ui/lib/utils/merge");
  1434. /***/ })
  1435. /******/ });