UNPKG

tdesign-mobile-vue

Version:
81 lines (73 loc) 3.18 kB
/** * tdesign v1.7.0 * (c) 2024 TDesign Group * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray'); var core = require('@vueuse/core'); var isArray = require('lodash/isArray'); var shared_util = require('../util.js'); require('@babel/runtime/helpers/slicedToArray'); require('lodash/isNumber'); require('../../config.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray); var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray); function useClickAway(target, fn) { var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!shared_util.isBrowser) return; var _options$eventName = options.eventName, eventName = _options$eventName === void 0 ? "touchstart" : _options$eventName, _options$capture = options.capture, capture = _options$capture === void 0 ? true : _options$capture, _options$ignore = options.ignore, ignore = _options$ignore === void 0 ? [] : _options$ignore, _options$detectIframe = options.detectIframe, detectIframe = _options$detectIframe === void 0 ? false : _options$detectIframe; var listenerOptions = { passive: true, capture: capture }; var checkElInEvtTarget = function checkElInEvtTarget(el, event) { return el && (event.target === el || event.composedPath().includes(el)); }; var shouldIgnore = function shouldIgnore(event) { return ignore.some(function (ignoreTarget) { return checkElInEvtTarget(core.unrefElement(ignoreTarget), event); }); }; var eventHandler = function eventHandler(event) { var targets = isArray__default["default"](target) ? _toConsumableArray__default["default"](target) : [target]; var shouldTrigger = targets.every(function (targetItem) { return !checkElInEvtTarget(core.unrefElement(targetItem), event); }); if (!shouldTrigger) return; shouldTrigger = !shouldIgnore(event); if (!shouldTrigger) return; fn(event); }; var cleanup = [core.useEventListener(window, eventName, eventHandler, listenerOptions)]; if (detectIframe) { cleanup.push(core.useEventListener(window, "blur", function (event) { setTimeout(function () { var targets = isArray__default["default"](target) ? _toConsumableArray__default["default"](target) : [target]; if (targets.every(function (targetItem) { var _window$document$acti; var el = core.unrefElement(targetItem); return ((_window$document$acti = window.document.activeElement) === null || _window$document$acti === void 0 ? void 0 : _window$document$acti.tagName) === "IFRAME" && !(el !== null && el !== void 0 && el.contains(window.document.activeElement)); })) { fn(event); } }, 0); })); } return function () { return cleanup.forEach(function (clean) { return clean(); }); }; } exports.useClickAway = useClickAway; //# sourceMappingURL=index.js.map