tooltip.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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 = 136);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 136:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. __webpack_require__.r(__webpack_exports__);
  93. // EXTERNAL MODULE: external "element-ui/lib/utils/vue-popper"
  94. var vue_popper_ = __webpack_require__(5);
  95. var vue_popper_default = /*#__PURE__*/__webpack_require__.n(vue_popper_);
  96. // EXTERNAL MODULE: external "throttle-debounce/debounce"
  97. var debounce_ = __webpack_require__(18);
  98. var debounce_default = /*#__PURE__*/__webpack_require__.n(debounce_);
  99. // EXTERNAL MODULE: external "element-ui/lib/utils/dom"
  100. var dom_ = __webpack_require__(2);
  101. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  102. var util_ = __webpack_require__(3);
  103. // EXTERNAL MODULE: external "vue"
  104. var external_vue_ = __webpack_require__(7);
  105. var external_vue_default = /*#__PURE__*/__webpack_require__.n(external_vue_);
  106. // CONCATENATED MODULE: ./packages/tooltip/src/main.js
  107. /* harmony default export */ var main = ({
  108. name: 'ElTooltip',
  109. mixins: [vue_popper_default.a],
  110. props: {
  111. openDelay: {
  112. type: Number,
  113. default: 0
  114. },
  115. disabled: Boolean,
  116. manual: Boolean,
  117. effect: {
  118. type: String,
  119. default: 'dark'
  120. },
  121. arrowOffset: {
  122. type: Number,
  123. default: 0
  124. },
  125. popperClass: String,
  126. content: String,
  127. visibleArrow: {
  128. default: true
  129. },
  130. transition: {
  131. type: String,
  132. default: 'el-fade-in-linear'
  133. },
  134. popperOptions: {
  135. default: function _default() {
  136. return {
  137. boundariesPadding: 10,
  138. gpuAcceleration: false
  139. };
  140. }
  141. },
  142. enterable: {
  143. type: Boolean,
  144. default: true
  145. },
  146. hideAfter: {
  147. type: Number,
  148. default: 0
  149. },
  150. tabindex: {
  151. type: Number,
  152. default: 0
  153. }
  154. },
  155. data: function data() {
  156. return {
  157. tooltipId: 'el-tooltip-' + Object(util_["generateId"])(),
  158. timeoutPending: null,
  159. focusing: false
  160. };
  161. },
  162. beforeCreate: function beforeCreate() {
  163. var _this = this;
  164. if (this.$isServer) return;
  165. this.popperVM = new external_vue_default.a({
  166. data: { node: '' },
  167. render: function render(h) {
  168. return this.node;
  169. }
  170. }).$mount();
  171. this.debounceClose = debounce_default()(200, function () {
  172. return _this.handleClosePopper();
  173. });
  174. },
  175. render: function render(h) {
  176. var _this2 = this;
  177. if (this.popperVM) {
  178. this.popperVM.node = h(
  179. 'transition',
  180. {
  181. attrs: {
  182. name: this.transition
  183. },
  184. on: {
  185. 'afterLeave': this.doDestroy
  186. }
  187. },
  188. [h(
  189. 'div',
  190. {
  191. on: {
  192. 'mouseleave': function mouseleave() {
  193. _this2.setExpectedState(false);_this2.debounceClose();
  194. },
  195. 'mouseenter': function mouseenter() {
  196. _this2.setExpectedState(true);
  197. }
  198. },
  199. ref: 'popper',
  200. attrs: { role: 'tooltip',
  201. id: this.tooltipId,
  202. 'aria-hidden': this.disabled || !this.showPopper ? 'true' : 'false'
  203. },
  204. directives: [{
  205. name: 'show',
  206. value: !this.disabled && this.showPopper
  207. }],
  208. 'class': ['el-tooltip__popper', 'is-' + this.effect, this.popperClass] },
  209. [this.$slots.content || this.content]
  210. )]
  211. );
  212. }
  213. var firstElement = this.getFirstElement();
  214. if (!firstElement) return null;
  215. var data = firstElement.data = firstElement.data || {};
  216. data.staticClass = this.addTooltipClass(data.staticClass);
  217. return firstElement;
  218. },
  219. mounted: function mounted() {
  220. var _this3 = this;
  221. this.referenceElm = this.$el;
  222. if (this.$el.nodeType === 1) {
  223. this.$el.setAttribute('aria-describedby', this.tooltipId);
  224. this.$el.setAttribute('tabindex', this.tabindex);
  225. Object(dom_["on"])(this.referenceElm, 'mouseenter', this.show);
  226. Object(dom_["on"])(this.referenceElm, 'mouseleave', this.hide);
  227. Object(dom_["on"])(this.referenceElm, 'focus', function () {
  228. if (!_this3.$slots.default || !_this3.$slots.default.length) {
  229. _this3.handleFocus();
  230. return;
  231. }
  232. var instance = _this3.$slots.default[0].componentInstance;
  233. if (instance && instance.focus) {
  234. instance.focus();
  235. } else {
  236. _this3.handleFocus();
  237. }
  238. });
  239. Object(dom_["on"])(this.referenceElm, 'blur', this.handleBlur);
  240. Object(dom_["on"])(this.referenceElm, 'click', this.removeFocusing);
  241. }
  242. // fix issue https://github.com/ElemeFE/element/issues/14424
  243. if (this.value && this.popperVM) {
  244. this.popperVM.$nextTick(function () {
  245. if (_this3.value) {
  246. _this3.updatePopper();
  247. }
  248. });
  249. }
  250. },
  251. watch: {
  252. focusing: function focusing(val) {
  253. if (val) {
  254. Object(dom_["addClass"])(this.referenceElm, 'focusing');
  255. } else {
  256. Object(dom_["removeClass"])(this.referenceElm, 'focusing');
  257. }
  258. }
  259. },
  260. methods: {
  261. show: function show() {
  262. this.setExpectedState(true);
  263. this.handleShowPopper();
  264. },
  265. hide: function hide() {
  266. this.setExpectedState(false);
  267. this.debounceClose();
  268. },
  269. handleFocus: function handleFocus() {
  270. this.focusing = true;
  271. this.show();
  272. },
  273. handleBlur: function handleBlur() {
  274. this.focusing = false;
  275. this.hide();
  276. },
  277. removeFocusing: function removeFocusing() {
  278. this.focusing = false;
  279. },
  280. addTooltipClass: function addTooltipClass(prev) {
  281. if (!prev) {
  282. return 'el-tooltip';
  283. } else {
  284. return 'el-tooltip ' + prev.replace('el-tooltip', '');
  285. }
  286. },
  287. handleShowPopper: function handleShowPopper() {
  288. var _this4 = this;
  289. if (!this.expectedState || this.manual) return;
  290. clearTimeout(this.timeout);
  291. this.timeout = setTimeout(function () {
  292. _this4.showPopper = true;
  293. }, this.openDelay);
  294. if (this.hideAfter > 0) {
  295. this.timeoutPending = setTimeout(function () {
  296. _this4.showPopper = false;
  297. }, this.hideAfter);
  298. }
  299. },
  300. handleClosePopper: function handleClosePopper() {
  301. if (this.enterable && this.expectedState || this.manual) return;
  302. clearTimeout(this.timeout);
  303. if (this.timeoutPending) {
  304. clearTimeout(this.timeoutPending);
  305. }
  306. this.showPopper = false;
  307. if (this.disabled) {
  308. this.doDestroy();
  309. }
  310. },
  311. setExpectedState: function setExpectedState(expectedState) {
  312. if (expectedState === false) {
  313. clearTimeout(this.timeoutPending);
  314. }
  315. this.expectedState = expectedState;
  316. },
  317. getFirstElement: function getFirstElement() {
  318. var slots = this.$slots.default;
  319. if (!Array.isArray(slots)) return null;
  320. var element = null;
  321. for (var index = 0; index < slots.length; index++) {
  322. if (slots[index] && slots[index].tag) {
  323. element = slots[index];
  324. };
  325. }
  326. return element;
  327. }
  328. },
  329. beforeDestroy: function beforeDestroy() {
  330. this.popperVM && this.popperVM.$destroy();
  331. },
  332. destroyed: function destroyed() {
  333. var reference = this.referenceElm;
  334. if (reference.nodeType === 1) {
  335. Object(dom_["off"])(reference, 'mouseenter', this.show);
  336. Object(dom_["off"])(reference, 'mouseleave', this.hide);
  337. Object(dom_["off"])(reference, 'focus', this.handleFocus);
  338. Object(dom_["off"])(reference, 'blur', this.handleBlur);
  339. Object(dom_["off"])(reference, 'click', this.removeFocusing);
  340. }
  341. }
  342. });
  343. // CONCATENATED MODULE: ./packages/tooltip/index.js
  344. /* istanbul ignore next */
  345. main.install = function (Vue) {
  346. Vue.component(main.name, main);
  347. };
  348. /* harmony default export */ var tooltip = __webpack_exports__["default"] = (main);
  349. /***/ }),
  350. /***/ 18:
  351. /***/ (function(module, exports) {
  352. module.exports = require("throttle-debounce/debounce");
  353. /***/ }),
  354. /***/ 2:
  355. /***/ (function(module, exports) {
  356. module.exports = require("element-ui/lib/utils/dom");
  357. /***/ }),
  358. /***/ 3:
  359. /***/ (function(module, exports) {
  360. module.exports = require("element-ui/lib/utils/util");
  361. /***/ }),
  362. /***/ 5:
  363. /***/ (function(module, exports) {
  364. module.exports = require("element-ui/lib/utils/vue-popper");
  365. /***/ }),
  366. /***/ 7:
  367. /***/ (function(module, exports) {
  368. module.exports = require("vue");
  369. /***/ })
  370. /******/ });