t.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
  6. var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
  7. var _extends2 = require('babel-runtime/helpers/extends');
  8. var _extends3 = _interopRequireDefault(_extends2);
  9. var _vue = require('vue');
  10. var _vue2 = _interopRequireDefault(_vue);
  11. var _vueRef = require('vue-ref');
  12. var _vueRef2 = _interopRequireDefault(_vueRef);
  13. var _vueTypes = require('../_util/vue-types');
  14. var _vueTypes2 = _interopRequireDefault(_vueTypes);
  15. var _contains = require('../vc-util/Dom/contains');
  16. var _contains2 = _interopRequireDefault(_contains);
  17. var _propsUtil = require('../_util/props-util');
  18. var _requestAnimationTimeout = require('../_util/requestAnimationTimeout');
  19. var _addEventListener = require('../vc-util/Dom/addEventListener');
  20. var _addEventListener2 = _interopRequireDefault(_addEventListener);
  21. var _warning = require('../_util/warning');
  22. var _warning2 = _interopRequireDefault(_warning);
  23. var _Popup = require('./Popup');
  24. var _Popup2 = _interopRequireDefault(_Popup);
  25. var _utils = require('./utils');
  26. var _BaseMixin = require('../_util/BaseMixin');
  27. var _BaseMixin2 = _interopRequireDefault(_BaseMixin);
  28. var _vnode = require('../_util/vnode');
  29. var _Portal = require('../_util/Portal');
  30. var _Portal2 = _interopRequireDefault(_Portal);
  31. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  32. _vue2['default'].use(_vueRef2['default'], { name: 'ant-ref' });
  33. function returnEmptyString() {
  34. return '';
  35. }
  36. function returnDocument() {
  37. return window.document;
  38. }
  39. var ALL_HANDLERS = ['click', 'mousedown', 'touchstart', 'mouseenter', 'mouseleave', 'focus', 'blur', 'contextmenu'];
  40. exports['default'] = {
  41. name: 'Trigger',
  42. mixins: [_BaseMixin2['default']],
  43. props: {
  44. action: _vueTypes2['default'].oneOfType([_vueTypes2['default'].string, _vueTypes2['default'].arrayOf(_vueTypes2['default'].string)]).def([]),
  45. showAction: _vueTypes2['default'].any.def([]),
  46. hideAction: _vueTypes2['default'].any.def([]),
  47. getPopupClassNameFromAlign: _vueTypes2['default'].any.def(returnEmptyString),
  48. // onPopupVisibleChange: PropTypes.func.def(noop),
  49. afterPopupVisibleChange: _vueTypes2['default'].func.def(_utils.noop),
  50. popup: _vueTypes2['default'].any,
  51. popupStyle: _vueTypes2['default'].object.def(function () {
  52. return {};
  53. }),
  54. prefixCls: _vueTypes2['default'].string.def('rc-trigger-popup'),
  55. popupClassName: _vueTypes2['default'].string.def(''),
  56. popupPlacement: _vueTypes2['default'].string,
  57. builtinPlacements: _vueTypes2['default'].object,
  58. popupTransitionName: _vueTypes2['default'].oneOfType([_vueTypes2['default'].string, _vueTypes2['default'].object]),
  59. popupAnimation: _vueTypes2['default'].any,
  60. mouseEnterDelay: _vueTypes2['default'].number.def(0),
  61. mouseLeaveDelay: _vueTypes2['default'].number.def(0.1),
  62. zIndex: _vueTypes2['default'].number,
  63. focusDelay: _vueTypes2['default'].number.def(0),
  64. blurDelay: _vueTypes2['default'].number.def(0.15),
  65. getPopupContainer: _vueTypes2['default'].func,
  66. getDocument: _vueTypes2['default'].func.def(returnDocument),
  67. forceRender: _vueTypes2['default'].bool,
  68. destroyPopupOnHide: _vueTypes2['default'].bool.def(false),
  69. mask: _vueTypes2['default'].bool.def(false),
  70. maskClosable: _vueTypes2['default'].bool.def(true),
  71. // onPopupAlign: PropTypes.func.def(noop),
  72. popupAlign: _vueTypes2['default'].object.def(function () {
  73. return {};
  74. }),
  75. popupVisible: _vueTypes2['default'].bool,
  76. defaultPopupVisible: _vueTypes2['default'].bool.def(false),
  77. maskTransitionName: _vueTypes2['default'].oneOfType([_vueTypes2['default'].string, _vueTypes2['default'].object]),
  78. maskAnimation: _vueTypes2['default'].string,
  79. stretch: _vueTypes2['default'].string,
  80. alignPoint: _vueTypes2['default'].bool // Maybe we can support user pass position in the future
  81. },
  82. provide: function provide() {
  83. return {
  84. vcTriggerContext: this
  85. };
  86. },
  87. inject: {
  88. vcTriggerContext: { 'default': function _default() {
  89. return {};
  90. } },
  91. savePopupRef: { 'default': function _default() {
  92. return _utils.noop;
  93. } },
  94. dialogContext: { 'default': function _default() {
  95. return null;
  96. } }
  97. },
  98. data: function data() {
  99. var _this = this;
  100. var props = this.$props;
  101. var popupVisible = void 0;
  102. if ((0, _propsUtil.hasProp)(this, 'popupVisible')) {
  103. popupVisible = !!props.popupVisible;
  104. } else {
  105. popupVisible = !!props.defaultPopupVisible;
  106. }
  107. ALL_HANDLERS.forEach(function (h) {
  108. _this['fire' + h] = function (e) {
  109. _this.fireEvents(h, e);
  110. };
  111. });
  112. return {
  113. prevPopupVisible: popupVisible,
  114. sPopupVisible: popupVisible,
  115. point: null
  116. };
  117. },
  118. watch: {
  119. popupVisible: function popupVisible(val) {
  120. if (val !== undefined) {
  121. this.prevPopupVisible = this.sPopupVisible;
  122. this.sPopupVisible = val;
  123. }
  124. }
  125. },
  126. deactivated: function deactivated() {
  127. this.setPopupVisible(false);
  128. },
  129. mounted: function mounted() {
  130. var _this2 = this;
  131. this.$nextTick(function () {
  132. _this2.updatedCal();
  133. });
  134. },
  135. updated: function updated() {
  136. var _this3 = this;
  137. this.$nextTick(function () {
  138. _this3.updatedCal();
  139. });
  140. },
  141. beforeDestroy: function beforeDestroy() {
  142. this.clearDelayTimer();
  143. this.clearOutsideHandler();
  144. clearTimeout(this.mouseDownTimeout);
  145. },
  146. methods: {
  147. updatedCal: function updatedCal() {
  148. var props = this.$props;
  149. var state = this.$data;
  150. // We must listen to `mousedown` or `touchstart`, edge case:
  151. // https://github.com/ant-design/ant-design/issues/5804
  152. // https://github.com/react-component/calendar/issues/250
  153. // https://github.com/react-component/trigger/issues/50
  154. if (state.sPopupVisible) {
  155. var currentDocument = void 0;
  156. if (!this.clickOutsideHandler && (this.isClickToHide() || this.isContextmenuToShow())) {
  157. currentDocument = props.getDocument();
  158. this.clickOutsideHandler = (0, _addEventListener2['default'])(currentDocument, 'mousedown', this.onDocumentClick);
  159. }
  160. // always hide on mobile
  161. if (!this.touchOutsideHandler) {
  162. currentDocument = currentDocument || props.getDocument();
  163. this.touchOutsideHandler = (0, _addEventListener2['default'])(currentDocument, 'touchstart', this.onDocumentClick);
  164. }
  165. // close popup when trigger type contains 'onContextmenu' and document is scrolling.
  166. if (!this.contextmenuOutsideHandler1 && this.isContextmenuToShow()) {
  167. currentDocument = currentDocument || props.getDocument();
  168. this.contextmenuOutsideHandler1 = (0, _addEventListener2['default'])(currentDocument, 'scroll', this.onContextmenuClose);
  169. }
  170. // close popup when trigger type contains 'onContextmenu' and window is blur.
  171. if (!this.contextmenuOutsideHandler2 && this.isContextmenuToShow()) {
  172. this.contextmenuOutsideHandler2 = (0, _addEventListener2['default'])(window, 'blur', this.onContextmenuClose);
  173. }
  174. } else {
  175. this.clearOutsideHandler();
  176. }
  177. },
  178. onMouseenter: function onMouseenter(e) {
  179. var mouseEnterDelay = this.$props.mouseEnterDelay;
  180. this.fireEvents('mouseenter', e);
  181. this.delaySetPopupVisible(true, mouseEnterDelay, mouseEnterDelay ? null : e);
  182. },
  183. onMouseMove: function onMouseMove(e) {
  184. this.fireEvents('mousemove', e);
  185. this.setPoint(e);
  186. },
  187. onMouseleave: function onMouseleave(e) {
  188. this.fireEvents('mouseleave', e);
  189. this.delaySetPopupVisible(false, this.$props.mouseLeaveDelay);
  190. },
  191. onPopupMouseenter: function onPopupMouseenter() {
  192. this.clearDelayTimer();
  193. },
  194. onPopupMouseleave: function onPopupMouseleave(e) {
  195. if (e && e.relatedTarget && !e.relatedTarget.setTimeout && this._component && this._component.getPopupDomNode && (0, _contains2['default'])(this._component.getPopupDomNode(), e.relatedTarget)) {
  196. return;
  197. }
  198. this.delaySetPopupVisible(false, this.$props.mouseLeaveDelay);
  199. },
  200. onFocus: function onFocus(e) {
  201. this.fireEvents('focus', e);
  202. // incase focusin and focusout
  203. this.clearDelayTimer();
  204. if (this.isFocusToShow()) {
  205. this.focusTime = Date.now();
  206. this.delaySetPopupVisible(true, this.$props.focusDelay);
  207. }
  208. },
  209. onMousedown: function onMousedown(e) {
  210. this.fireEvents('mousedown', e);
  211. this.preClickTime = Date.now();
  212. },
  213. onTouchstart: function onTouchstart(e) {
  214. this.fireEvents('touchstart', e);
  215. this.preTouchTime = Date.now();
  216. },
  217. onBlur: function onBlur(e) {
  218. if (!(0, _contains2['default'])(e.target, e.relatedTarget || document.activeElement)) {
  219. this.fireEvents('blur', e);
  220. this.clearDelayTimer();
  221. if (this.isBlurToHide()) {
  222. this.delaySetPopupVisible(false, this.$props.blurDelay);
  223. }
  224. }
  225. },
  226. onContextmenu: function onContextmenu(e) {
  227. e.preventDefault();
  228. this.fireEvents('contextmenu', e);
  229. this.setPopupVisible(true, e);
  230. },
  231. onContextmenuClose: function onContextmenuClose() {
  232. if (this.isContextmenuToShow()) {
  233. this.close();
  234. }
  235. },
  236. onClick: function onClick(event) {
  237. this.fireEvents('click', event);
  238. // focus will trigger click
  239. if (this.focusTime) {
  240. var preTime = void 0;
  241. if (this.preClickTime && this.preTouchTime) {
  242. preTime = Math.min(this.preClickTime, this.preTouchTime);
  243. } else if (this.preClickTime) {
  244. preTime = this.preClickTime;
  245. } else if (this.preTouchTime) {
  246. preTime = this.preTouchTime;
  247. }
  248. if (Math.abs(preTime - this.focusTime) < 20) {
  249. return;
  250. }
  251. this.focusTime = 0;
  252. }
  253. this.preClickTime = 0;
  254. this.preTouchTime = 0;
  255. // Only prevent default when all the action is click.
  256. // https://github.com/ant-design/ant-design/issues/17043
  257. // https://github.com/ant-design/ant-design/issues/17291
  258. if (this.isClickToShow() && (this.isClickToHide() || this.isBlurToHide()) && event && event.preventDefault) {
  259. event.preventDefault();
  260. }
  261. if (event && event.domEvent) {
  262. event.domEvent.preventDefault();
  263. }
  264. var nextVisible = !this.$data.sPopupVisible;
  265. if (this.isClickToHide() && !nextVisible || nextVisible && this.isClickToShow()) {
  266. this.setPopupVisible(!this.$data.sPopupVisible, event);
  267. }
  268. },
  269. onPopupMouseDown: function onPopupMouseDown() {
  270. var _this4 = this;
  271. var _vcTriggerContext = this.vcTriggerContext,
  272. vcTriggerContext = _vcTriggerContext === undefined ? {} : _vcTriggerContext;
  273. this.hasPopupMouseDown = true;
  274. clearTimeout(this.mouseDownTimeout);
  275. this.mouseDownTimeout = setTimeout(function () {
  276. _this4.hasPopupMouseDown = false;
  277. }, 0);
  278. if (vcTriggerContext.onPopupMouseDown) {
  279. vcTriggerContext.onPopupMouseDown.apply(vcTriggerContext, arguments);
  280. }
  281. },
  282. onDocumentClick: function onDocumentClick(event) {
  283. if (this.$props.mask && !this.$props.maskClosable) {
  284. return;
  285. }
  286. var target = event.target;
  287. var root = this.$el;
  288. if (!(0, _contains2['default'])(root, target) && !this.hasPopupMouseDown) {
  289. this.close();
  290. }
  291. },
  292. getPopupDomNode: function getPopupDomNode() {
  293. if (this._component && this._component.getPopupDomNode) {
  294. return this._component.getPopupDomNode();
  295. }
  296. return null;
  297. },
  298. getRootDomNode: function getRootDomNode() {
  299. return this.$el;
  300. // return this.$el.children[0] || this.$el
  301. },
  302. handleGetPopupClassFromAlign: function handleGetPopupClassFromAlign(align) {
  303. var className = [];
  304. var props = this.$props;
  305. var popupPlacement = props.popupPlacement,
  306. builtinPlacements = props.builtinPlacements,
  307. prefixCls = props.prefixCls,
  308. alignPoint = props.alignPoint,
  309. getPopupClassNameFromAlign = props.getPopupClassNameFromAlign;
  310. if (popupPlacement && builtinPlacements) {
  311. className.push((0, _utils.getAlignPopupClassName)(builtinPlacements, prefixCls, align, alignPoint));
  312. }
  313. if (getPopupClassNameFromAlign) {
  314. className.push(getPopupClassNameFromAlign(align));
  315. }
  316. return className.join(' ');
  317. },
  318. getPopupAlign: function getPopupAlign() {
  319. var props = this.$props;
  320. var popupPlacement = props.popupPlacement,
  321. popupAlign = props.popupAlign,
  322. builtinPlacements = props.builtinPlacements;
  323. if (popupPlacement && builtinPlacements) {
  324. return (0, _utils.getAlignFromPlacement)(builtinPlacements, popupPlacement, popupAlign);
  325. }
  326. return popupAlign;
  327. },
  328. savePopup: function savePopup(node) {
  329. this._component = node;
  330. this.savePopupRef(node);
  331. },
  332. getComponent: function getComponent() {
  333. var h = this.$createElement;
  334. var self = this;
  335. var mouseProps = {};
  336. if (this.isMouseEnterToShow()) {
  337. mouseProps.mouseenter = self.onPopupMouseenter;
  338. }
  339. if (this.isMouseLeaveToHide()) {
  340. mouseProps.mouseleave = self.onPopupMouseleave;
  341. }
  342. mouseProps.mousedown = this.onPopupMouseDown;
  343. mouseProps.touchstart = this.onPopupMouseDown;
  344. var handleGetPopupClassFromAlign = self.handleGetPopupClassFromAlign,
  345. getRootDomNode = self.getRootDomNode,
  346. getContainer = self.getContainer;
  347. var _self$$props = self.$props,
  348. prefixCls = _self$$props.prefixCls,
  349. destroyPopupOnHide = _self$$props.destroyPopupOnHide,
  350. popupClassName = _self$$props.popupClassName,
  351. action = _self$$props.action,
  352. popupAnimation = _self$$props.popupAnimation,
  353. popupTransitionName = _self$$props.popupTransitionName,
  354. popupStyle = _self$$props.popupStyle,
  355. mask = _self$$props.mask,
  356. maskAnimation = _self$$props.maskAnimation,
  357. maskTransitionName = _self$$props.maskTransitionName,
  358. zIndex = _self$$props.zIndex,
  359. stretch = _self$$props.stretch,
  360. alignPoint = _self$$props.alignPoint;
  361. var _$data = this.$data,
  362. sPopupVisible = _$data.sPopupVisible,
  363. point = _$data.point;
  364. var align = this.getPopupAlign();
  365. var popupProps = {
  366. props: {
  367. prefixCls: prefixCls,
  368. destroyPopupOnHide: destroyPopupOnHide,
  369. visible: sPopupVisible,
  370. point: alignPoint && point,
  371. action: action,
  372. align: align,
  373. animation: popupAnimation,
  374. getClassNameFromAlign: handleGetPopupClassFromAlign,
  375. stretch: stretch,
  376. getRootDomNode: getRootDomNode,
  377. mask: mask,
  378. zIndex: zIndex,
  379. transitionName: popupTransitionName,
  380. maskAnimation: maskAnimation,
  381. maskTransitionName: maskTransitionName,
  382. getContainer: getContainer,
  383. popupClassName: popupClassName,
  384. popupStyle: popupStyle
  385. },
  386. on: (0, _extends3['default'])({
  387. align: (0, _propsUtil.getListeners)(this).popupAlign || _utils.noop
  388. }, mouseProps),
  389. directives: [{
  390. name: 'ant-ref',
  391. value: this.savePopup
  392. }]
  393. };
  394. return h(
  395. _Popup2['default'],
  396. popupProps,
  397. [(0, _propsUtil.getComponentFromProp)(self, 'popup')]
  398. );
  399. },
  400. getContainer: function getContainer() {
  401. var props = this.$props,
  402. dialogContext = this.dialogContext;
  403. var popupContainer = document.createElement('div');
  404. // Make sure default popup container will never cause scrollbar appearing
  405. // https://github.com/react-component/trigger/issues/41
  406. popupContainer.style.position = 'absolute';
  407. popupContainer.style.top = '0';
  408. popupContainer.style.left = '0';
  409. popupContainer.style.width = '100%';
  410. var mountNode = props.getPopupContainer ? props.getPopupContainer(this.$el, dialogContext) : props.getDocument().body;
  411. mountNode.appendChild(popupContainer);
  412. this.popupContainer = popupContainer;
  413. return popupContainer;
  414. },
  415. setPopupVisible: function setPopupVisible(sPopupVisible, event) {
  416. var alignPoint = this.alignPoint,
  417. prevPopupVisible = this.sPopupVisible;
  418. this.clearDelayTimer();
  419. if (prevPopupVisible !== sPopupVisible) {
  420. if (!(0, _propsUtil.hasProp)(this, 'popupVisible')) {
  421. this.setState({
  422. sPopupVisible: sPopupVisible,
  423. prevPopupVisible: prevPopupVisible
  424. });
  425. }
  426. var listeners = (0, _propsUtil.getListeners)(this);
  427. listeners.popupVisibleChange && listeners.popupVisibleChange(sPopupVisible);
  428. }
  429. // Always record the point position since mouseEnterDelay will delay the show
  430. if (alignPoint && event) {
  431. this.setPoint(event);
  432. }
  433. },
  434. setPoint: function setPoint(point) {
  435. var alignPoint = this.$props.alignPoint;
  436. if (!alignPoint || !point) return;
  437. this.setState({
  438. point: {
  439. pageX: point.pageX,
  440. pageY: point.pageY
  441. }
  442. });
  443. },
  444. handlePortalUpdate: function handlePortalUpdate() {
  445. if (this.prevPopupVisible !== this.sPopupVisible) {
  446. this.afterPopupVisibleChange(this.sPopupVisible);
  447. }
  448. },
  449. delaySetPopupVisible: function delaySetPopupVisible(visible, delayS, event) {
  450. var _this5 = this;
  451. var delay = delayS * 1000;
  452. this.clearDelayTimer();
  453. if (delay) {
  454. var point = event ? { pageX: event.pageX, pageY: event.pageY } : null;
  455. this.delayTimer = (0, _requestAnimationTimeout.requestAnimationTimeout)(function () {
  456. _this5.setPopupVisible(visible, point);
  457. _this5.clearDelayTimer();
  458. }, delay);
  459. } else {
  460. this.setPopupVisible(visible, event);
  461. }
  462. },
  463. clearDelayTimer: function clearDelayTimer() {
  464. if (this.delayTimer) {
  465. (0, _requestAnimationTimeout.cancelAnimationTimeout)(this.delayTimer);
  466. this.delayTimer = null;
  467. }
  468. },
  469. clearOutsideHandler: function clearOutsideHandler() {
  470. if (this.clickOutsideHandler) {
  471. this.clickOutsideHandler.remove();
  472. this.clickOutsideHandler = null;
  473. }
  474. if (this.contextmenuOutsideHandler1) {
  475. this.contextmenuOutsideHandler1.remove();
  476. this.contextmenuOutsideHandler1 = null;
  477. }
  478. if (this.contextmenuOutsideHandler2) {
  479. this.contextmenuOutsideHandler2.remove();
  480. this.contextmenuOutsideHandler2 = null;
  481. }
  482. if (this.touchOutsideHandler) {
  483. this.touchOutsideHandler.remove();
  484. this.touchOutsideHandler = null;
  485. }
  486. },
  487. createTwoChains: function createTwoChains(event) {
  488. var fn = function fn() {};
  489. var events = (0, _propsUtil.getListeners)(this);
  490. if (this.childOriginEvents[event] && events[event]) {
  491. return this['fire' + event];
  492. }
  493. fn = this.childOriginEvents[event] || events[event] || fn;
  494. return fn;
  495. },
  496. isClickToShow: function isClickToShow() {
  497. var _$props = this.$props,
  498. action = _$props.action,
  499. showAction = _$props.showAction;
  500. return action.indexOf('click') !== -1 || showAction.indexOf('click') !== -1;
  501. },
  502. isContextmenuToShow: function isContextmenuToShow() {
  503. var _$props2 = this.$props,
  504. action = _$props2.action,
  505. showAction = _$props2.showAction;
  506. return action.indexOf('contextmenu') !== -1 || showAction.indexOf('contextmenu') !== -1;
  507. },
  508. isClickToHide: function isClickToHide() {
  509. var _$props3 = this.$props,
  510. action = _$props3.action,
  511. hideAction = _$props3.hideAction;
  512. return action.indexOf('click') !== -1 || hideAction.indexOf('click') !== -1;
  513. },
  514. isMouseEnterToShow: function isMouseEnterToShow() {
  515. var _$props4 = this.$props,
  516. action = _$props4.action,
  517. showAction = _$props4.showAction;
  518. return action.indexOf('hover') !== -1 || showAction.indexOf('mouseenter') !== -1;
  519. },
  520. isMouseLeaveToHide: function isMouseLeaveToHide() {
  521. var _$props5 = this.$props,
  522. action = _$props5.action,
  523. hideAction = _$props5.hideAction;
  524. return action.indexOf('hover') !== -1 || hideAction.indexOf('mouseleave') !== -1;
  525. },
  526. isFocusToShow: function isFocusToShow() {
  527. var _$props6 = this.$props,
  528. action = _$props6.action,
  529. showAction = _$props6.showAction;
  530. return action.indexOf('focus') !== -1 || showAction.indexOf('focus') !== -1;
  531. },
  532. isBlurToHide: function isBlurToHide() {
  533. var _$props7 = this.$props,
  534. action = _$props7.action,
  535. hideAction = _$props7.hideAction;
  536. return action.indexOf('focus') !== -1 || hideAction.indexOf('blur') !== -1;
  537. },
  538. forcePopupAlign: function forcePopupAlign() {
  539. if (this.$data.sPopupVisible && this._component && this._component.$refs.alignInstance) {
  540. this._component.$refs.alignInstance.forceAlign();
  541. }
  542. },
  543. fireEvents: function fireEvents(type, e) {
  544. if (this.childOriginEvents[type]) {
  545. this.childOriginEvents[type](e);
  546. }
  547. this.__emit(type, e);
  548. },
  549. close: function close() {
  550. this.setPopupVisible(false);
  551. }
  552. },
  553. render: function render() {
  554. var _this6 = this;
  555. var h = arguments[0];
  556. var sPopupVisible = this.sPopupVisible;
  557. var children = (0, _propsUtil.filterEmpty)(this.$slots['default']);
  558. var _$props8 = this.$props,
  559. forceRender = _$props8.forceRender,
  560. alignPoint = _$props8.alignPoint;
  561. if (children.length > 1) {
  562. (0, _warning2['default'])(false, 'Trigger $slots.default.length > 1, just support only one default', true);
  563. }
  564. var child = children[0];
  565. this.childOriginEvents = (0, _propsUtil.getEvents)(child);
  566. var newChildProps = {
  567. props: {},
  568. on: {},
  569. key: 'trigger'
  570. };
  571. if (this.isContextmenuToShow()) {
  572. newChildProps.on.contextmenu = this.onContextmenu;
  573. } else {
  574. newChildProps.on.contextmenu = this.createTwoChains('contextmenu');
  575. }
  576. if (this.isClickToHide() || this.isClickToShow()) {
  577. newChildProps.on.click = this.onClick;
  578. newChildProps.on.mousedown = this.onMousedown;
  579. newChildProps.on.touchstart = this.onTouchstart;
  580. } else {
  581. newChildProps.on.click = this.createTwoChains('click');
  582. newChildProps.on.mousedown = this.createTwoChains('mousedown');
  583. newChildProps.on.touchstart = this.createTwoChains('onTouchstart');
  584. }
  585. if (this.isMouseEnterToShow()) {
  586. newChildProps.on.mouseenter = this.onMouseenter;
  587. if (alignPoint) {
  588. newChildProps.on.mousemove = this.onMouseMove;
  589. }
  590. } else {
  591. newChildProps.on.mouseenter = this.createTwoChains('mouseenter');
  592. }
  593. if (this.isMouseLeaveToHide()) {
  594. newChildProps.on.mouseleave = this.onMouseleave;
  595. } else {
  596. newChildProps.on.mouseleave = this.createTwoChains('mouseleave');
  597. }
  598. if (this.isFocusToShow() || this.isBlurToHide()) {
  599. newChildProps.on.focus = this.onFocus;
  600. newChildProps.on.blur = this.onBlur;
  601. } else {
  602. newChildProps.on.focus = this.createTwoChains('focus');
  603. newChildProps.on.blur = function (e) {
  604. if (e && (!e.relatedTarget || !(0, _contains2['default'])(e.target, e.relatedTarget))) {
  605. _this6.createTwoChains('blur')(e);
  606. }
  607. };
  608. }
  609. var trigger = (0, _vnode.cloneElement)(child, newChildProps);
  610. var portal = void 0;
  611. // prevent unmounting after it's rendered
  612. if (sPopupVisible || this._component || forceRender) {
  613. portal = h(_Portal2['default'], {
  614. key: 'portal',
  615. attrs: { children: this.getComponent(),
  616. getContainer: this.getContainer,
  617. didUpdate: this.handlePortalUpdate
  618. }
  619. });
  620. }
  621. return portal ? (0, _vnode.cloneElement)(trigger, {
  622. children: [].concat((0, _toConsumableArray3['default'])((trigger.componentOptions ? trigger.componentOptions.children : trigger.children) || []), [portal])
  623. }) : trigger;
  624. }
  625. };