tabs.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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 = 60);
  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/utils/resize-event");
  182. /***/ }),
  183. /***/ 3:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/utils/util");
  186. /***/ }),
  187. /***/ 60:
  188. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  189. "use strict";
  190. __webpack_require__.r(__webpack_exports__);
  191. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/tabs/src/tab-bar.vue?vue&type=template&id=2031f33a&
  192. var render = function() {
  193. var _vm = this
  194. var _h = _vm.$createElement
  195. var _c = _vm._self._c || _h
  196. return _c("div", {
  197. staticClass: "el-tabs__active-bar",
  198. class: "is-" + _vm.rootTabs.tabPosition,
  199. style: _vm.barStyle
  200. })
  201. }
  202. var staticRenderFns = []
  203. render._withStripped = true
  204. // CONCATENATED MODULE: ./packages/tabs/src/tab-bar.vue?vue&type=template&id=2031f33a&
  205. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  206. var util_ = __webpack_require__(3);
  207. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/tabs/src/tab-bar.vue?vue&type=script&lang=js&
  208. //
  209. //
  210. //
  211. /* harmony default export */ var tab_barvue_type_script_lang_js_ = ({
  212. name: 'TabBar',
  213. props: {
  214. tabs: Array
  215. },
  216. inject: ['rootTabs'],
  217. computed: {
  218. barStyle: {
  219. get: function get() {
  220. var _this = this;
  221. var style = {};
  222. var offset = 0;
  223. var tabSize = 0;
  224. var sizeName = ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1 ? 'width' : 'height';
  225. var sizeDir = sizeName === 'width' ? 'x' : 'y';
  226. var firstUpperCase = function firstUpperCase(str) {
  227. return str.toLowerCase().replace(/( |^)[a-z]/g, function (L) {
  228. return L.toUpperCase();
  229. });
  230. };
  231. this.tabs.every(function (tab, index) {
  232. var $el = Object(util_["arrayFind"])(_this.$parent.$refs.tabs || [], function (t) {
  233. return t.id.replace('tab-', '') === tab.paneName;
  234. });
  235. if (!$el) {
  236. return false;
  237. }
  238. if (!tab.active) {
  239. offset += $el['client' + firstUpperCase(sizeName)];
  240. return true;
  241. } else {
  242. tabSize = $el['client' + firstUpperCase(sizeName)];
  243. var tabStyles = window.getComputedStyle($el);
  244. if (sizeName === 'width' && _this.tabs.length > 1) {
  245. tabSize -= parseFloat(tabStyles.paddingLeft) + parseFloat(tabStyles.paddingRight);
  246. }
  247. if (sizeName === 'width') {
  248. offset += parseFloat(tabStyles.paddingLeft);
  249. }
  250. return false;
  251. }
  252. });
  253. var transform = 'translate' + firstUpperCase(sizeDir) + '(' + offset + 'px)';
  254. style[sizeName] = tabSize + 'px';
  255. style.transform = transform;
  256. style.msTransform = transform;
  257. style.webkitTransform = transform;
  258. return style;
  259. }
  260. }
  261. }
  262. });
  263. // CONCATENATED MODULE: ./packages/tabs/src/tab-bar.vue?vue&type=script&lang=js&
  264. /* harmony default export */ var src_tab_barvue_type_script_lang_js_ = (tab_barvue_type_script_lang_js_);
  265. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  266. var componentNormalizer = __webpack_require__(0);
  267. // CONCATENATED MODULE: ./packages/tabs/src/tab-bar.vue
  268. /* normalize component */
  269. var component = Object(componentNormalizer["a" /* default */])(
  270. src_tab_barvue_type_script_lang_js_,
  271. render,
  272. staticRenderFns,
  273. false,
  274. null,
  275. null,
  276. null
  277. )
  278. /* hot reload */
  279. if (false) { var api; }
  280. component.options.__file = "packages/tabs/src/tab-bar.vue"
  281. /* harmony default export */ var tab_bar = (component.exports);
  282. // EXTERNAL MODULE: external "element-ui/lib/utils/resize-event"
  283. var resize_event_ = __webpack_require__(16);
  284. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/tabs/src/tab-nav.vue?vue&type=script&lang=js&
  285. function noop() {}
  286. var tab_navvue_type_script_lang_js_firstUpperCase = function firstUpperCase(str) {
  287. return str.toLowerCase().replace(/( |^)[a-z]/g, function (L) {
  288. return L.toUpperCase();
  289. });
  290. };
  291. /* harmony default export */ var tab_navvue_type_script_lang_js_ = ({
  292. name: 'TabNav',
  293. components: {
  294. TabBar: tab_bar
  295. },
  296. inject: ['rootTabs'],
  297. props: {
  298. panes: Array,
  299. currentName: String,
  300. editable: Boolean,
  301. onTabClick: {
  302. type: Function,
  303. default: noop
  304. },
  305. onTabRemove: {
  306. type: Function,
  307. default: noop
  308. },
  309. type: String,
  310. stretch: Boolean
  311. },
  312. data: function data() {
  313. return {
  314. scrollable: false,
  315. navOffset: 0,
  316. isFocus: false,
  317. focusable: true
  318. };
  319. },
  320. computed: {
  321. navStyle: function navStyle() {
  322. var dir = ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1 ? 'X' : 'Y';
  323. return {
  324. transform: 'translate' + dir + '(-' + this.navOffset + 'px)'
  325. };
  326. },
  327. sizeName: function sizeName() {
  328. return ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1 ? 'width' : 'height';
  329. }
  330. },
  331. methods: {
  332. scrollPrev: function scrollPrev() {
  333. var containerSize = this.$refs.navScroll['offset' + tab_navvue_type_script_lang_js_firstUpperCase(this.sizeName)];
  334. var currentOffset = this.navOffset;
  335. if (!currentOffset) return;
  336. var newOffset = currentOffset > containerSize ? currentOffset - containerSize : 0;
  337. this.navOffset = newOffset;
  338. },
  339. scrollNext: function scrollNext() {
  340. var navSize = this.$refs.nav['offset' + tab_navvue_type_script_lang_js_firstUpperCase(this.sizeName)];
  341. var containerSize = this.$refs.navScroll['offset' + tab_navvue_type_script_lang_js_firstUpperCase(this.sizeName)];
  342. var currentOffset = this.navOffset;
  343. if (navSize - currentOffset <= containerSize) return;
  344. var newOffset = navSize - currentOffset > containerSize * 2 ? currentOffset + containerSize : navSize - containerSize;
  345. this.navOffset = newOffset;
  346. },
  347. scrollToActiveTab: function scrollToActiveTab() {
  348. if (!this.scrollable) return;
  349. var nav = this.$refs.nav;
  350. var activeTab = this.$el.querySelector('.is-active');
  351. if (!activeTab) return;
  352. var navScroll = this.$refs.navScroll;
  353. var isHorizontal = ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1;
  354. var activeTabBounding = activeTab.getBoundingClientRect();
  355. var navScrollBounding = navScroll.getBoundingClientRect();
  356. var maxOffset = isHorizontal ? nav.offsetWidth - navScrollBounding.width : nav.offsetHeight - navScrollBounding.height;
  357. var currentOffset = this.navOffset;
  358. var newOffset = currentOffset;
  359. if (isHorizontal) {
  360. if (activeTabBounding.left < navScrollBounding.left) {
  361. newOffset = currentOffset - (navScrollBounding.left - activeTabBounding.left);
  362. }
  363. if (activeTabBounding.right > navScrollBounding.right) {
  364. newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
  365. }
  366. } else {
  367. if (activeTabBounding.top < navScrollBounding.top) {
  368. newOffset = currentOffset - (navScrollBounding.top - activeTabBounding.top);
  369. }
  370. if (activeTabBounding.bottom > navScrollBounding.bottom) {
  371. newOffset = currentOffset + (activeTabBounding.bottom - navScrollBounding.bottom);
  372. }
  373. }
  374. newOffset = Math.max(newOffset, 0);
  375. this.navOffset = Math.min(newOffset, maxOffset);
  376. },
  377. update: function update() {
  378. if (!this.$refs.nav) return;
  379. var sizeName = this.sizeName;
  380. var navSize = this.$refs.nav['offset' + tab_navvue_type_script_lang_js_firstUpperCase(sizeName)];
  381. var containerSize = this.$refs.navScroll['offset' + tab_navvue_type_script_lang_js_firstUpperCase(sizeName)];
  382. var currentOffset = this.navOffset;
  383. if (containerSize < navSize) {
  384. var _currentOffset = this.navOffset;
  385. this.scrollable = this.scrollable || {};
  386. this.scrollable.prev = _currentOffset;
  387. this.scrollable.next = _currentOffset + containerSize < navSize;
  388. if (navSize - _currentOffset < containerSize) {
  389. this.navOffset = navSize - containerSize;
  390. }
  391. } else {
  392. this.scrollable = false;
  393. if (currentOffset > 0) {
  394. this.navOffset = 0;
  395. }
  396. }
  397. },
  398. changeTab: function changeTab(e) {
  399. var keyCode = e.keyCode;
  400. var nextIndex = void 0;
  401. var currentIndex = void 0,
  402. tabList = void 0;
  403. if ([37, 38, 39, 40].indexOf(keyCode) !== -1) {
  404. // 左右上下键更换tab
  405. tabList = e.currentTarget.querySelectorAll('[role=tab]');
  406. currentIndex = Array.prototype.indexOf.call(tabList, e.target);
  407. } else {
  408. return;
  409. }
  410. if (keyCode === 37 || keyCode === 38) {
  411. // left
  412. if (currentIndex === 0) {
  413. // first
  414. nextIndex = tabList.length - 1;
  415. } else {
  416. nextIndex = currentIndex - 1;
  417. }
  418. } else {
  419. // right
  420. if (currentIndex < tabList.length - 1) {
  421. // not last
  422. nextIndex = currentIndex + 1;
  423. } else {
  424. nextIndex = 0;
  425. }
  426. }
  427. tabList[nextIndex].focus(); // 改变焦点元素
  428. tabList[nextIndex].click(); // 选中下一个tab
  429. this.setFocus();
  430. },
  431. setFocus: function setFocus() {
  432. if (this.focusable) {
  433. this.isFocus = true;
  434. }
  435. },
  436. removeFocus: function removeFocus() {
  437. this.isFocus = false;
  438. },
  439. visibilityChangeHandler: function visibilityChangeHandler() {
  440. var _this = this;
  441. var visibility = document.visibilityState;
  442. if (visibility === 'hidden') {
  443. this.focusable = false;
  444. } else if (visibility === 'visible') {
  445. setTimeout(function () {
  446. _this.focusable = true;
  447. }, 50);
  448. }
  449. },
  450. windowBlurHandler: function windowBlurHandler() {
  451. this.focusable = false;
  452. },
  453. windowFocusHandler: function windowFocusHandler() {
  454. var _this2 = this;
  455. setTimeout(function () {
  456. _this2.focusable = true;
  457. }, 50);
  458. }
  459. },
  460. updated: function updated() {
  461. this.update();
  462. },
  463. render: function render(h) {
  464. var _this3 = this;
  465. var type = this.type,
  466. panes = this.panes,
  467. editable = this.editable,
  468. stretch = this.stretch,
  469. onTabClick = this.onTabClick,
  470. onTabRemove = this.onTabRemove,
  471. navStyle = this.navStyle,
  472. scrollable = this.scrollable,
  473. scrollNext = this.scrollNext,
  474. scrollPrev = this.scrollPrev,
  475. changeTab = this.changeTab,
  476. setFocus = this.setFocus,
  477. removeFocus = this.removeFocus;
  478. var scrollBtn = scrollable ? [h(
  479. 'span',
  480. { 'class': ['el-tabs__nav-prev', scrollable.prev ? '' : 'is-disabled'], on: {
  481. 'click': scrollPrev
  482. }
  483. },
  484. [h('i', { 'class': 'el-icon-arrow-left' })]
  485. ), h(
  486. 'span',
  487. { 'class': ['el-tabs__nav-next', scrollable.next ? '' : 'is-disabled'], on: {
  488. 'click': scrollNext
  489. }
  490. },
  491. [h('i', { 'class': 'el-icon-arrow-right' })]
  492. )] : null;
  493. var tabs = this._l(panes, function (pane, index) {
  494. var _ref;
  495. var tabName = pane.name || pane.index || index;
  496. var closable = pane.isClosable || editable;
  497. pane.index = '' + index;
  498. var btnClose = closable ? h('span', { 'class': 'el-icon-close', on: {
  499. 'click': function click(ev) {
  500. onTabRemove(pane, ev);
  501. }
  502. }
  503. }) : null;
  504. var tabLabelContent = pane.$slots.label || pane.label;
  505. var tabindex = pane.active ? 0 : -1;
  506. return h(
  507. 'div',
  508. {
  509. 'class': (_ref = {
  510. 'el-tabs__item': true
  511. }, _ref['is-' + _this3.rootTabs.tabPosition] = true, _ref['is-active'] = pane.active, _ref['is-disabled'] = pane.disabled, _ref['is-closable'] = closable, _ref['is-focus'] = _this3.isFocus, _ref),
  512. attrs: { id: 'tab-' + tabName,
  513. 'aria-controls': 'pane-' + tabName,
  514. role: 'tab',
  515. 'aria-selected': pane.active,
  516. tabindex: tabindex
  517. },
  518. key: 'tab-' + tabName, ref: 'tabs', refInFor: true,
  519. on: {
  520. 'focus': function focus() {
  521. setFocus();
  522. },
  523. 'blur': function blur() {
  524. removeFocus();
  525. },
  526. 'click': function click(ev) {
  527. removeFocus();onTabClick(pane, tabName, ev);
  528. },
  529. 'keydown': function keydown(ev) {
  530. if (closable && (ev.keyCode === 46 || ev.keyCode === 8)) {
  531. onTabRemove(pane, ev);
  532. }
  533. }
  534. }
  535. },
  536. [tabLabelContent, btnClose]
  537. );
  538. });
  539. return h(
  540. 'div',
  541. { 'class': ['el-tabs__nav-wrap', scrollable ? 'is-scrollable' : '', 'is-' + this.rootTabs.tabPosition] },
  542. [scrollBtn, h(
  543. 'div',
  544. { 'class': ['el-tabs__nav-scroll'], ref: 'navScroll' },
  545. [h(
  546. 'div',
  547. {
  548. 'class': ['el-tabs__nav', 'is-' + this.rootTabs.tabPosition, stretch && ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1 ? 'is-stretch' : ''],
  549. ref: 'nav',
  550. style: navStyle,
  551. attrs: { role: 'tablist'
  552. },
  553. on: {
  554. 'keydown': changeTab
  555. }
  556. },
  557. [!type ? h('tab-bar', {
  558. attrs: { tabs: panes }
  559. }) : null, tabs]
  560. )]
  561. )]
  562. );
  563. },
  564. mounted: function mounted() {
  565. var _this4 = this;
  566. Object(resize_event_["addResizeListener"])(this.$el, this.update);
  567. document.addEventListener('visibilitychange', this.visibilityChangeHandler);
  568. window.addEventListener('blur', this.windowBlurHandler);
  569. window.addEventListener('focus', this.windowFocusHandler);
  570. setTimeout(function () {
  571. _this4.scrollToActiveTab();
  572. }, 0);
  573. },
  574. beforeDestroy: function beforeDestroy() {
  575. if (this.$el && this.update) Object(resize_event_["removeResizeListener"])(this.$el, this.update);
  576. document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
  577. window.removeEventListener('blur', this.windowBlurHandler);
  578. window.removeEventListener('focus', this.windowFocusHandler);
  579. }
  580. });
  581. // CONCATENATED MODULE: ./packages/tabs/src/tab-nav.vue?vue&type=script&lang=js&
  582. /* harmony default export */ var src_tab_navvue_type_script_lang_js_ = (tab_navvue_type_script_lang_js_);
  583. // CONCATENATED MODULE: ./packages/tabs/src/tab-nav.vue
  584. var tab_nav_render, tab_nav_staticRenderFns
  585. /* normalize component */
  586. var tab_nav_component = Object(componentNormalizer["a" /* default */])(
  587. src_tab_navvue_type_script_lang_js_,
  588. tab_nav_render,
  589. tab_nav_staticRenderFns,
  590. false,
  591. null,
  592. null,
  593. null
  594. )
  595. /* hot reload */
  596. if (false) { var tab_nav_api; }
  597. tab_nav_component.options.__file = "packages/tabs/src/tab-nav.vue"
  598. /* harmony default export */ var tab_nav = (tab_nav_component.exports);
  599. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/tabs/src/tabs.vue?vue&type=script&lang=js&
  600. /* harmony default export */ var tabsvue_type_script_lang_js_ = ({
  601. name: 'ElTabs',
  602. components: {
  603. TabNav: tab_nav
  604. },
  605. props: {
  606. type: String,
  607. activeName: String,
  608. closable: Boolean,
  609. addable: Boolean,
  610. value: {},
  611. editable: Boolean,
  612. tabPosition: {
  613. type: String,
  614. default: 'top'
  615. },
  616. beforeLeave: Function,
  617. stretch: Boolean
  618. },
  619. provide: function provide() {
  620. return {
  621. rootTabs: this
  622. };
  623. },
  624. data: function data() {
  625. return {
  626. currentName: this.value || this.activeName,
  627. panes: []
  628. };
  629. },
  630. watch: {
  631. activeName: function activeName(value) {
  632. this.setCurrentName(value);
  633. },
  634. value: function value(_value) {
  635. this.setCurrentName(_value);
  636. },
  637. currentName: function currentName(value) {
  638. var _this = this;
  639. if (this.$refs.nav) {
  640. this.$nextTick(function () {
  641. _this.$refs.nav.$nextTick(function (_) {
  642. _this.$refs.nav.scrollToActiveTab();
  643. });
  644. });
  645. }
  646. }
  647. },
  648. methods: {
  649. calcPaneInstances: function calcPaneInstances() {
  650. var _this2 = this;
  651. var isForceUpdate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  652. if (this.$slots.default) {
  653. var paneSlots = this.$slots.default.filter(function (vnode) {
  654. return vnode.tag && vnode.componentOptions && vnode.componentOptions.Ctor.options.name === 'ElTabPane';
  655. });
  656. // update indeed
  657. var panes = paneSlots.map(function (_ref) {
  658. var componentInstance = _ref.componentInstance;
  659. return componentInstance;
  660. });
  661. var panesChanged = !(panes.length === this.panes.length && panes.every(function (pane, index) {
  662. return pane === _this2.panes[index];
  663. }));
  664. if (isForceUpdate || panesChanged) {
  665. this.panes = panes;
  666. }
  667. } else if (this.panes.length !== 0) {
  668. this.panes = [];
  669. }
  670. },
  671. handleTabClick: function handleTabClick(tab, tabName, event) {
  672. if (tab.disabled) return;
  673. this.setCurrentName(tabName);
  674. this.$emit('tab-click', tab, event);
  675. },
  676. handleTabRemove: function handleTabRemove(pane, ev) {
  677. if (pane.disabled) return;
  678. ev.stopPropagation();
  679. this.$emit('edit', pane.name, 'remove');
  680. this.$emit('tab-remove', pane.name);
  681. },
  682. handleTabAdd: function handleTabAdd() {
  683. this.$emit('edit', null, 'add');
  684. this.$emit('tab-add');
  685. },
  686. setCurrentName: function setCurrentName(value) {
  687. var _this3 = this;
  688. var changeCurrentName = function changeCurrentName() {
  689. _this3.currentName = value;
  690. _this3.$emit('input', value);
  691. };
  692. if (this.currentName !== value && this.beforeLeave) {
  693. var before = this.beforeLeave(value, this.currentName);
  694. if (before && before.then) {
  695. before.then(function () {
  696. changeCurrentName();
  697. _this3.$refs.nav && _this3.$refs.nav.removeFocus();
  698. }, function () {
  699. // https://github.com/ElemeFE/element/pull/14816
  700. // ignore promise rejection in `before-leave` hook
  701. });
  702. } else if (before !== false) {
  703. changeCurrentName();
  704. }
  705. } else {
  706. changeCurrentName();
  707. }
  708. }
  709. },
  710. render: function render(h) {
  711. var _ref2;
  712. var type = this.type,
  713. handleTabClick = this.handleTabClick,
  714. handleTabRemove = this.handleTabRemove,
  715. handleTabAdd = this.handleTabAdd,
  716. currentName = this.currentName,
  717. panes = this.panes,
  718. editable = this.editable,
  719. addable = this.addable,
  720. tabPosition = this.tabPosition,
  721. stretch = this.stretch;
  722. var newButton = editable || addable ? h(
  723. 'span',
  724. {
  725. 'class': 'el-tabs__new-tab',
  726. on: {
  727. 'click': handleTabAdd,
  728. 'keydown': function keydown(ev) {
  729. if (ev.keyCode === 13) {
  730. handleTabAdd();
  731. }
  732. }
  733. },
  734. attrs: {
  735. tabindex: '0'
  736. }
  737. },
  738. [h('i', { 'class': 'el-icon-plus' })]
  739. ) : null;
  740. var navData = {
  741. props: {
  742. currentName: currentName,
  743. onTabClick: handleTabClick,
  744. onTabRemove: handleTabRemove,
  745. editable: editable,
  746. type: type,
  747. panes: panes,
  748. stretch: stretch
  749. },
  750. ref: 'nav'
  751. };
  752. var header = h(
  753. 'div',
  754. { 'class': ['el-tabs__header', 'is-' + tabPosition] },
  755. [newButton, h('tab-nav', navData)]
  756. );
  757. var panels = h(
  758. 'div',
  759. { 'class': 'el-tabs__content' },
  760. [this.$slots.default]
  761. );
  762. return h(
  763. 'div',
  764. { 'class': (_ref2 = {
  765. 'el-tabs': true,
  766. 'el-tabs--card': type === 'card'
  767. }, _ref2['el-tabs--' + tabPosition] = true, _ref2['el-tabs--border-card'] = type === 'border-card', _ref2) },
  768. [tabPosition !== 'bottom' ? [header, panels] : [panels, header]]
  769. );
  770. },
  771. created: function created() {
  772. if (!this.currentName) {
  773. this.setCurrentName('0');
  774. }
  775. this.$on('tab-nav-update', this.calcPaneInstances.bind(null, true));
  776. },
  777. mounted: function mounted() {
  778. this.calcPaneInstances();
  779. },
  780. updated: function updated() {
  781. this.calcPaneInstances();
  782. }
  783. });
  784. // CONCATENATED MODULE: ./packages/tabs/src/tabs.vue?vue&type=script&lang=js&
  785. /* harmony default export */ var src_tabsvue_type_script_lang_js_ = (tabsvue_type_script_lang_js_);
  786. // CONCATENATED MODULE: ./packages/tabs/src/tabs.vue
  787. var tabs_render, tabs_staticRenderFns
  788. /* normalize component */
  789. var tabs_component = Object(componentNormalizer["a" /* default */])(
  790. src_tabsvue_type_script_lang_js_,
  791. tabs_render,
  792. tabs_staticRenderFns,
  793. false,
  794. null,
  795. null,
  796. null
  797. )
  798. /* hot reload */
  799. if (false) { var tabs_api; }
  800. tabs_component.options.__file = "packages/tabs/src/tabs.vue"
  801. /* harmony default export */ var tabs = (tabs_component.exports);
  802. // CONCATENATED MODULE: ./packages/tabs/index.js
  803. /* istanbul ignore next */
  804. tabs.install = function (Vue) {
  805. Vue.component(tabs.name, tabs);
  806. };
  807. /* harmony default export */ var packages_tabs = __webpack_exports__["default"] = (tabs);
  808. /***/ })
  809. /******/ });