Trigger.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _vue = require("vue");
  8. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  9. var _interface = require("./interface");
  10. var _contains = _interopRequireDefault(require("../vc-util/Dom/contains"));
  11. var _raf = _interopRequireDefault(require("../_util/raf"));
  12. var _propsUtil = require("../_util/props-util");
  13. var _addEventListener = _interopRequireDefault(require("../vc-util/Dom/addEventListener"));
  14. var _Popup = _interopRequireDefault(require("./Popup"));
  15. var _alignUtil = require("./utils/alignUtil");
  16. var _BaseMixin = _interopRequireDefault(require("../_util/BaseMixin"));
  17. var _PortalWrapper = _interopRequireDefault(require("../_util/PortalWrapper"));
  18. var _classNames = _interopRequireDefault(require("../_util/classNames"));
  19. var _vnode = require("../_util/vnode");
  20. var _supportsPassive = _interopRequireDefault(require("../_util/supportsPassive"));
  21. var _context = require("./context");
  22. const ALL_HANDLERS = ['onClick', 'onMousedown', 'onTouchstart', 'onMouseenter', 'onMouseleave', 'onFocus', 'onBlur', 'onContextmenu'];
  23. var _default = exports.default = (0, _vue.defineComponent)({
  24. compatConfig: {
  25. MODE: 3
  26. },
  27. name: 'Trigger',
  28. mixins: [_BaseMixin.default],
  29. inheritAttrs: false,
  30. props: (0, _interface.triggerProps)(),
  31. setup(props) {
  32. const align = (0, _vue.computed)(() => {
  33. const {
  34. popupPlacement,
  35. popupAlign,
  36. builtinPlacements
  37. } = props;
  38. if (popupPlacement && builtinPlacements) {
  39. return (0, _alignUtil.getAlignFromPlacement)(builtinPlacements, popupPlacement, popupAlign);
  40. }
  41. return popupAlign;
  42. });
  43. const popupRef = (0, _vue.shallowRef)(null);
  44. const setPopupRef = val => {
  45. popupRef.value = val;
  46. };
  47. return {
  48. vcTriggerContext: (0, _vue.inject)('vcTriggerContext', {}),
  49. popupRef,
  50. setPopupRef,
  51. triggerRef: (0, _vue.shallowRef)(null),
  52. align,
  53. focusTime: null,
  54. clickOutsideHandler: null,
  55. contextmenuOutsideHandler1: null,
  56. contextmenuOutsideHandler2: null,
  57. touchOutsideHandler: null,
  58. attachId: null,
  59. delayTimer: null,
  60. hasPopupMouseDown: false,
  61. preClickTime: null,
  62. preTouchTime: null,
  63. mouseDownTimeout: null,
  64. childOriginEvents: {}
  65. };
  66. },
  67. data() {
  68. const props = this.$props;
  69. let popupVisible;
  70. if (this.popupVisible !== undefined) {
  71. popupVisible = !!props.popupVisible;
  72. } else {
  73. popupVisible = !!props.defaultPopupVisible;
  74. }
  75. ALL_HANDLERS.forEach(h => {
  76. this[`fire${h}`] = e => {
  77. this.fireEvents(h, e);
  78. };
  79. });
  80. return {
  81. prevPopupVisible: popupVisible,
  82. sPopupVisible: popupVisible,
  83. point: null
  84. };
  85. },
  86. watch: {
  87. popupVisible(val) {
  88. if (val !== undefined) {
  89. this.prevPopupVisible = this.sPopupVisible;
  90. this.sPopupVisible = val;
  91. }
  92. }
  93. },
  94. created() {
  95. (0, _vue.provide)('vcTriggerContext', {
  96. onPopupMouseDown: this.onPopupMouseDown,
  97. onPopupMouseenter: this.onPopupMouseenter,
  98. onPopupMouseleave: this.onPopupMouseleave
  99. });
  100. (0, _context.useProvidePortal)(this);
  101. },
  102. deactivated() {
  103. this.setPopupVisible(false);
  104. },
  105. mounted() {
  106. this.$nextTick(() => {
  107. this.updatedCal();
  108. });
  109. },
  110. updated() {
  111. this.$nextTick(() => {
  112. this.updatedCal();
  113. });
  114. },
  115. beforeUnmount() {
  116. this.clearDelayTimer();
  117. this.clearOutsideHandler();
  118. clearTimeout(this.mouseDownTimeout);
  119. _raf.default.cancel(this.attachId);
  120. },
  121. methods: {
  122. updatedCal() {
  123. const props = this.$props;
  124. const state = this.$data;
  125. // We must listen to `mousedown` or `touchstart`, edge case:
  126. // https://github.com/ant-design/ant-design/issues/5804
  127. // https://github.com/react-component/calendar/issues/250
  128. // https://github.com/react-component/trigger/issues/50
  129. if (state.sPopupVisible) {
  130. let currentDocument;
  131. if (!this.clickOutsideHandler && (this.isClickToHide() || this.isContextmenuToShow())) {
  132. currentDocument = props.getDocument(this.getRootDomNode());
  133. this.clickOutsideHandler = (0, _addEventListener.default)(currentDocument, 'mousedown', this.onDocumentClick);
  134. }
  135. // always hide on mobile
  136. if (!this.touchOutsideHandler) {
  137. currentDocument = currentDocument || props.getDocument(this.getRootDomNode());
  138. this.touchOutsideHandler = (0, _addEventListener.default)(currentDocument, 'touchstart', this.onDocumentClick, _supportsPassive.default ? {
  139. passive: false
  140. } : false);
  141. }
  142. // close popup when trigger type contains 'onContextmenu' and document is scrolling.
  143. if (!this.contextmenuOutsideHandler1 && this.isContextmenuToShow()) {
  144. currentDocument = currentDocument || props.getDocument(this.getRootDomNode());
  145. this.contextmenuOutsideHandler1 = (0, _addEventListener.default)(currentDocument, 'scroll', this.onContextmenuClose);
  146. }
  147. // close popup when trigger type contains 'onContextmenu' and window is blur.
  148. if (!this.contextmenuOutsideHandler2 && this.isContextmenuToShow()) {
  149. this.contextmenuOutsideHandler2 = (0, _addEventListener.default)(window, 'blur', this.onContextmenuClose);
  150. }
  151. } else {
  152. this.clearOutsideHandler();
  153. }
  154. },
  155. onMouseenter(e) {
  156. const {
  157. mouseEnterDelay
  158. } = this.$props;
  159. this.fireEvents('onMouseenter', e);
  160. this.delaySetPopupVisible(true, mouseEnterDelay, mouseEnterDelay ? null : e);
  161. },
  162. onMouseMove(e) {
  163. this.fireEvents('onMousemove', e);
  164. this.setPoint(e);
  165. },
  166. onMouseleave(e) {
  167. this.fireEvents('onMouseleave', e);
  168. this.delaySetPopupVisible(false, this.$props.mouseLeaveDelay);
  169. },
  170. onPopupMouseenter() {
  171. const {
  172. vcTriggerContext = {}
  173. } = this;
  174. if (vcTriggerContext.onPopupMouseenter) {
  175. vcTriggerContext.onPopupMouseenter();
  176. }
  177. this.clearDelayTimer();
  178. },
  179. onPopupMouseleave(e) {
  180. var _a;
  181. if (e && e.relatedTarget && !e.relatedTarget.setTimeout && (0, _contains.default)((_a = this.popupRef) === null || _a === void 0 ? void 0 : _a.getElement(), e.relatedTarget)) {
  182. return;
  183. }
  184. if (this.isMouseLeaveToHide()) {
  185. this.delaySetPopupVisible(false, this.$props.mouseLeaveDelay);
  186. }
  187. const {
  188. vcTriggerContext = {}
  189. } = this;
  190. if (vcTriggerContext.onPopupMouseleave) {
  191. vcTriggerContext.onPopupMouseleave(e);
  192. }
  193. },
  194. onFocus(e) {
  195. this.fireEvents('onFocus', e);
  196. // incase focusin and focusout
  197. this.clearDelayTimer();
  198. if (this.isFocusToShow()) {
  199. this.focusTime = Date.now();
  200. this.delaySetPopupVisible(true, this.$props.focusDelay);
  201. }
  202. },
  203. onMousedown(e) {
  204. this.fireEvents('onMousedown', e);
  205. this.preClickTime = Date.now();
  206. },
  207. onTouchstart(e) {
  208. this.fireEvents('onTouchstart', e);
  209. this.preTouchTime = Date.now();
  210. },
  211. onBlur(e) {
  212. if (!(0, _contains.default)(e.target, e.relatedTarget || document.activeElement)) {
  213. this.fireEvents('onBlur', e);
  214. this.clearDelayTimer();
  215. if (this.isBlurToHide()) {
  216. this.delaySetPopupVisible(false, this.$props.blurDelay);
  217. }
  218. }
  219. },
  220. onContextmenu(e) {
  221. e.preventDefault();
  222. this.fireEvents('onContextmenu', e);
  223. this.setPopupVisible(true, e);
  224. },
  225. onContextmenuClose() {
  226. if (this.isContextmenuToShow()) {
  227. this.close();
  228. }
  229. },
  230. onClick(event) {
  231. this.fireEvents('onClick', event);
  232. // focus will trigger click
  233. if (this.focusTime) {
  234. let preTime;
  235. if (this.preClickTime && this.preTouchTime) {
  236. preTime = Math.min(this.preClickTime, this.preTouchTime);
  237. } else if (this.preClickTime) {
  238. preTime = this.preClickTime;
  239. } else if (this.preTouchTime) {
  240. preTime = this.preTouchTime;
  241. }
  242. if (Math.abs(preTime - this.focusTime) < 20) {
  243. return;
  244. }
  245. this.focusTime = 0;
  246. }
  247. this.preClickTime = 0;
  248. this.preTouchTime = 0;
  249. // Only prevent default when all the action is click.
  250. // https://github.com/ant-design/ant-design/issues/17043
  251. // https://github.com/ant-design/ant-design/issues/17291
  252. if (this.isClickToShow() && (this.isClickToHide() || this.isBlurToHide()) && event && event.preventDefault) {
  253. event.preventDefault();
  254. }
  255. if (event && event.domEvent) {
  256. event.domEvent.preventDefault();
  257. }
  258. const nextVisible = !this.$data.sPopupVisible;
  259. if (this.isClickToHide() && !nextVisible || nextVisible && this.isClickToShow()) {
  260. this.setPopupVisible(!this.$data.sPopupVisible, event);
  261. }
  262. },
  263. onPopupMouseDown() {
  264. const {
  265. vcTriggerContext = {}
  266. } = this;
  267. this.hasPopupMouseDown = true;
  268. clearTimeout(this.mouseDownTimeout);
  269. this.mouseDownTimeout = setTimeout(() => {
  270. this.hasPopupMouseDown = false;
  271. }, 0);
  272. if (vcTriggerContext.onPopupMouseDown) {
  273. vcTriggerContext.onPopupMouseDown(...arguments);
  274. }
  275. },
  276. onDocumentClick(event) {
  277. if (this.$props.mask && !this.$props.maskClosable) {
  278. return;
  279. }
  280. const target = event.target;
  281. const root = this.getRootDomNode();
  282. const popupNode = this.getPopupDomNode();
  283. if (
  284. // mousedown on the target should also close popup when action is contextMenu.
  285. // https://github.com/ant-design/ant-design/issues/29853
  286. (!(0, _contains.default)(root, target) || this.isContextMenuOnly()) && !(0, _contains.default)(popupNode, target) && !this.hasPopupMouseDown) {
  287. // https://github.com/vuejs/core/issues/4462
  288. // vue 动画bug导致 https://github.com/vueComponent/ant-design-vue/issues/5259,
  289. // 改成延时解决
  290. this.delaySetPopupVisible(false, 0.1);
  291. }
  292. },
  293. getPopupDomNode() {
  294. var _a;
  295. // for test
  296. return ((_a = this.popupRef) === null || _a === void 0 ? void 0 : _a.getElement()) || null;
  297. },
  298. getRootDomNode() {
  299. var _a, _b, _c, _d;
  300. const {
  301. getTriggerDOMNode
  302. } = this.$props;
  303. if (getTriggerDOMNode) {
  304. const domNode = ((_b = (_a = this.triggerRef) === null || _a === void 0 ? void 0 : _a.$el) === null || _b === void 0 ? void 0 : _b.nodeName) === '#comment' ? null : (0, _propsUtil.findDOMNode)(this.triggerRef);
  305. return (0, _propsUtil.findDOMNode)(getTriggerDOMNode(domNode));
  306. }
  307. try {
  308. const domNode = ((_d = (_c = this.triggerRef) === null || _c === void 0 ? void 0 : _c.$el) === null || _d === void 0 ? void 0 : _d.nodeName) === '#comment' ? null : (0, _propsUtil.findDOMNode)(this.triggerRef);
  309. if (domNode) {
  310. return domNode;
  311. }
  312. } catch (err) {
  313. // Do nothing
  314. }
  315. return (0, _propsUtil.findDOMNode)(this);
  316. },
  317. handleGetPopupClassFromAlign(align) {
  318. const className = [];
  319. const props = this.$props;
  320. const {
  321. popupPlacement,
  322. builtinPlacements,
  323. prefixCls,
  324. alignPoint,
  325. getPopupClassNameFromAlign
  326. } = props;
  327. if (popupPlacement && builtinPlacements) {
  328. className.push((0, _alignUtil.getAlignPopupClassName)(builtinPlacements, prefixCls, align, alignPoint));
  329. }
  330. if (getPopupClassNameFromAlign) {
  331. className.push(getPopupClassNameFromAlign(align));
  332. }
  333. return className.join(' ');
  334. },
  335. getPopupAlign() {
  336. const props = this.$props;
  337. const {
  338. popupPlacement,
  339. popupAlign,
  340. builtinPlacements
  341. } = props;
  342. if (popupPlacement && builtinPlacements) {
  343. return (0, _alignUtil.getAlignFromPlacement)(builtinPlacements, popupPlacement, popupAlign);
  344. }
  345. return popupAlign;
  346. },
  347. getComponent() {
  348. const mouseProps = {};
  349. if (this.isMouseEnterToShow()) {
  350. mouseProps.onMouseenter = this.onPopupMouseenter;
  351. }
  352. if (this.isMouseLeaveToHide()) {
  353. mouseProps.onMouseleave = this.onPopupMouseleave;
  354. }
  355. mouseProps.onMousedown = this.onPopupMouseDown;
  356. mouseProps[_supportsPassive.default ? 'onTouchstartPassive' : 'onTouchstart'] = this.onPopupMouseDown;
  357. const {
  358. handleGetPopupClassFromAlign,
  359. getRootDomNode,
  360. $attrs
  361. } = this;
  362. const {
  363. prefixCls,
  364. destroyPopupOnHide,
  365. popupClassName,
  366. popupAnimation,
  367. popupTransitionName,
  368. popupStyle,
  369. mask,
  370. maskAnimation,
  371. maskTransitionName,
  372. zIndex,
  373. stretch,
  374. alignPoint,
  375. mobile,
  376. arrow,
  377. forceRender
  378. } = this.$props;
  379. const {
  380. sPopupVisible,
  381. point
  382. } = this.$data;
  383. const popupProps = (0, _extends2.default)((0, _extends2.default)({
  384. prefixCls,
  385. arrow,
  386. destroyPopupOnHide,
  387. visible: sPopupVisible,
  388. point: alignPoint ? point : null,
  389. align: this.align,
  390. animation: popupAnimation,
  391. getClassNameFromAlign: handleGetPopupClassFromAlign,
  392. stretch,
  393. getRootDomNode,
  394. mask,
  395. zIndex,
  396. transitionName: popupTransitionName,
  397. maskAnimation,
  398. maskTransitionName,
  399. class: popupClassName,
  400. style: popupStyle,
  401. onAlign: $attrs.onPopupAlign || _interface.noop
  402. }, mouseProps), {
  403. ref: this.setPopupRef,
  404. mobile,
  405. forceRender
  406. });
  407. return (0, _vue.createVNode)(_Popup.default, popupProps, {
  408. default: this.$slots.popup || (() => (0, _propsUtil.getComponent)(this, 'popup'))
  409. });
  410. },
  411. attachParent(popupContainer) {
  412. _raf.default.cancel(this.attachId);
  413. const {
  414. getPopupContainer,
  415. getDocument
  416. } = this.$props;
  417. const domNode = this.getRootDomNode();
  418. let mountNode;
  419. if (!getPopupContainer) {
  420. mountNode = getDocument(this.getRootDomNode()).body;
  421. } else if (domNode || getPopupContainer.length === 0) {
  422. // Compatible for legacy getPopupContainer with domNode argument.
  423. // If no need `domNode` argument, will call directly.
  424. // https://codesandbox.io/s/eloquent-mclean-ss93m?file=/src/App.js
  425. mountNode = getPopupContainer(domNode);
  426. }
  427. if (mountNode) {
  428. mountNode.appendChild(popupContainer);
  429. } else {
  430. // Retry after frame render in case parent not ready
  431. this.attachId = (0, _raf.default)(() => {
  432. this.attachParent(popupContainer);
  433. });
  434. }
  435. },
  436. getContainer() {
  437. const {
  438. $props: props
  439. } = this;
  440. const {
  441. getDocument
  442. } = props;
  443. const popupContainer = getDocument(this.getRootDomNode()).createElement('div');
  444. // Make sure default popup container will never cause scrollbar appearing
  445. // https://github.com/react-component/trigger/issues/41
  446. popupContainer.style.position = 'absolute';
  447. popupContainer.style.top = '0';
  448. popupContainer.style.left = '0';
  449. popupContainer.style.width = '100%';
  450. this.attachParent(popupContainer);
  451. return popupContainer;
  452. },
  453. setPopupVisible(sPopupVisible, event) {
  454. const {
  455. alignPoint,
  456. sPopupVisible: prevPopupVisible,
  457. onPopupVisibleChange
  458. } = this;
  459. this.clearDelayTimer();
  460. if (prevPopupVisible !== sPopupVisible) {
  461. if (!(0, _propsUtil.hasProp)(this, 'popupVisible')) {
  462. this.setState({
  463. sPopupVisible,
  464. prevPopupVisible
  465. });
  466. }
  467. onPopupVisibleChange && onPopupVisibleChange(sPopupVisible);
  468. }
  469. // Always record the point position since mouseEnterDelay will delay the show
  470. if (alignPoint && event && sPopupVisible) {
  471. this.setPoint(event);
  472. }
  473. },
  474. setPoint(point) {
  475. const {
  476. alignPoint
  477. } = this.$props;
  478. if (!alignPoint || !point) return;
  479. this.setState({
  480. point: {
  481. pageX: point.pageX,
  482. pageY: point.pageY
  483. }
  484. });
  485. },
  486. handlePortalUpdate() {
  487. if (this.prevPopupVisible !== this.sPopupVisible) {
  488. this.afterPopupVisibleChange(this.sPopupVisible);
  489. }
  490. },
  491. delaySetPopupVisible(visible, delayS, event) {
  492. const delay = delayS * 1000;
  493. this.clearDelayTimer();
  494. if (delay) {
  495. const point = event ? {
  496. pageX: event.pageX,
  497. pageY: event.pageY
  498. } : null;
  499. this.delayTimer = setTimeout(() => {
  500. this.setPopupVisible(visible, point);
  501. this.clearDelayTimer();
  502. }, delay);
  503. } else {
  504. this.setPopupVisible(visible, event);
  505. }
  506. },
  507. clearDelayTimer() {
  508. if (this.delayTimer) {
  509. clearTimeout(this.delayTimer);
  510. this.delayTimer = null;
  511. }
  512. },
  513. clearOutsideHandler() {
  514. if (this.clickOutsideHandler) {
  515. this.clickOutsideHandler.remove();
  516. this.clickOutsideHandler = null;
  517. }
  518. if (this.contextmenuOutsideHandler1) {
  519. this.contextmenuOutsideHandler1.remove();
  520. this.contextmenuOutsideHandler1 = null;
  521. }
  522. if (this.contextmenuOutsideHandler2) {
  523. this.contextmenuOutsideHandler2.remove();
  524. this.contextmenuOutsideHandler2 = null;
  525. }
  526. if (this.touchOutsideHandler) {
  527. this.touchOutsideHandler.remove();
  528. this.touchOutsideHandler = null;
  529. }
  530. },
  531. createTwoChains(event) {
  532. let fn = () => {};
  533. const events = (0, _propsUtil.getEvents)(this);
  534. if (this.childOriginEvents[event] && events[event]) {
  535. return this[`fire${event}`];
  536. }
  537. fn = this.childOriginEvents[event] || events[event] || fn;
  538. return fn;
  539. },
  540. isClickToShow() {
  541. const {
  542. action,
  543. showAction
  544. } = this.$props;
  545. return action.indexOf('click') !== -1 || showAction.indexOf('click') !== -1;
  546. },
  547. isContextMenuOnly() {
  548. const {
  549. action
  550. } = this.$props;
  551. return action === 'contextmenu' || action.length === 1 && action[0] === 'contextmenu';
  552. },
  553. isContextmenuToShow() {
  554. const {
  555. action,
  556. showAction
  557. } = this.$props;
  558. return action.indexOf('contextmenu') !== -1 || showAction.indexOf('contextmenu') !== -1;
  559. },
  560. isClickToHide() {
  561. const {
  562. action,
  563. hideAction
  564. } = this.$props;
  565. return action.indexOf('click') !== -1 || hideAction.indexOf('click') !== -1;
  566. },
  567. isMouseEnterToShow() {
  568. const {
  569. action,
  570. showAction
  571. } = this.$props;
  572. return action.indexOf('hover') !== -1 || showAction.indexOf('mouseenter') !== -1;
  573. },
  574. isMouseLeaveToHide() {
  575. const {
  576. action,
  577. hideAction
  578. } = this.$props;
  579. return action.indexOf('hover') !== -1 || hideAction.indexOf('mouseleave') !== -1;
  580. },
  581. isFocusToShow() {
  582. const {
  583. action,
  584. showAction
  585. } = this.$props;
  586. return action.indexOf('focus') !== -1 || showAction.indexOf('focus') !== -1;
  587. },
  588. isBlurToHide() {
  589. const {
  590. action,
  591. hideAction
  592. } = this.$props;
  593. return action.indexOf('focus') !== -1 || hideAction.indexOf('blur') !== -1;
  594. },
  595. forcePopupAlign() {
  596. var _a;
  597. if (this.$data.sPopupVisible) {
  598. (_a = this.popupRef) === null || _a === void 0 ? void 0 : _a.forceAlign();
  599. }
  600. },
  601. fireEvents(type, e) {
  602. if (this.childOriginEvents[type]) {
  603. this.childOriginEvents[type](e);
  604. }
  605. const event = this.$props[type] || this.$attrs[type];
  606. if (event) {
  607. event(e);
  608. }
  609. },
  610. close() {
  611. this.setPopupVisible(false);
  612. }
  613. },
  614. render() {
  615. const {
  616. $attrs
  617. } = this;
  618. const children = (0, _propsUtil.filterEmpty)((0, _propsUtil.getSlot)(this));
  619. const {
  620. alignPoint,
  621. getPopupContainer
  622. } = this.$props;
  623. const child = children[0];
  624. this.childOriginEvents = (0, _propsUtil.getEvents)(child);
  625. const newChildProps = {
  626. key: 'trigger'
  627. };
  628. if (this.isContextmenuToShow()) {
  629. newChildProps.onContextmenu = this.onContextmenu;
  630. } else {
  631. newChildProps.onContextmenu = this.createTwoChains('onContextmenu');
  632. }
  633. if (this.isClickToHide() || this.isClickToShow()) {
  634. newChildProps.onClick = this.onClick;
  635. newChildProps.onMousedown = this.onMousedown;
  636. newChildProps[_supportsPassive.default ? 'onTouchstartPassive' : 'onTouchstart'] = this.onTouchstart;
  637. } else {
  638. newChildProps.onClick = this.createTwoChains('onClick');
  639. newChildProps.onMousedown = this.createTwoChains('onMousedown');
  640. newChildProps[_supportsPassive.default ? 'onTouchstartPassive' : 'onTouchstart'] = this.createTwoChains('onTouchstart');
  641. }
  642. if (this.isMouseEnterToShow()) {
  643. newChildProps.onMouseenter = this.onMouseenter;
  644. if (alignPoint) {
  645. newChildProps.onMousemove = this.onMouseMove;
  646. }
  647. } else {
  648. newChildProps.onMouseenter = this.createTwoChains('onMouseenter');
  649. }
  650. if (this.isMouseLeaveToHide()) {
  651. newChildProps.onMouseleave = this.onMouseleave;
  652. } else {
  653. newChildProps.onMouseleave = this.createTwoChains('onMouseleave');
  654. }
  655. if (this.isFocusToShow() || this.isBlurToHide()) {
  656. newChildProps.onFocus = this.onFocus;
  657. newChildProps.onBlur = this.onBlur;
  658. } else {
  659. newChildProps.onFocus = this.createTwoChains('onFocus');
  660. newChildProps.onBlur = e => {
  661. if (e && (!e.relatedTarget || !(0, _contains.default)(e.target, e.relatedTarget))) {
  662. this.createTwoChains('onBlur')(e);
  663. }
  664. };
  665. }
  666. const childrenClassName = (0, _classNames.default)(child && child.props && child.props.class, $attrs.class);
  667. if (childrenClassName) {
  668. newChildProps.class = childrenClassName;
  669. }
  670. const trigger = (0, _vnode.cloneElement)(child, (0, _extends2.default)((0, _extends2.default)({}, newChildProps), {
  671. ref: 'triggerRef'
  672. }), true, true);
  673. const portal = (0, _vue.createVNode)(_PortalWrapper.default, {
  674. "key": "portal",
  675. "getContainer": getPopupContainer && (() => getPopupContainer(this.getRootDomNode())),
  676. "didUpdate": this.handlePortalUpdate,
  677. "visible": this.$data.sPopupVisible
  678. }, {
  679. default: this.getComponent
  680. });
  681. return (0, _vue.createVNode)(_vue.Fragment, null, [trigger, portal]);
  682. }
  683. });