v-click-outside-x.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*!
  2. {
  3. "author": "Graham Fairweather",
  4. "copywrite": "Copyright (c) 2018-present",
  5. "date": "2021-04-25T10:03:52.017Z",
  6. "describe": "",
  7. "description": "Vue directive to react on clicks outside an element.",
  8. "file": "v-click-outside-x.js",
  9. "hash": "178d9f5de12efbbd3fe7",
  10. "license": "MIT",
  11. "version": "4.1.2"
  12. }
  13. */
  14. (function webpackUniversalModuleDefinition(root, factory) {
  15. if(typeof exports === 'object' && typeof module === 'object')
  16. module.exports = factory();
  17. else if(typeof define === 'function' && define.amd)
  18. define([], factory);
  19. else if(typeof exports === 'object')
  20. exports["vClickOutsideX"] = factory();
  21. else
  22. root["vClickOutsideX"] = factory();
  23. })((function() {
  24. 'use strict';
  25. var ObjectCtr = {}.constructor;
  26. var objectPrototype = ObjectCtr.prototype;
  27. var defineProperty = ObjectCtr.defineProperty;
  28. var $globalThis;
  29. var getGlobalFallback = function() {
  30. if (typeof self !== 'undefined') {
  31. return self;
  32. }
  33. if (typeof window !== 'undefined') {
  34. return window;
  35. }
  36. if (typeof global !== 'undefined') {
  37. return global;
  38. }
  39. return void 0;
  40. };
  41. var returnThis = function() {
  42. return this;
  43. };
  44. try {
  45. if (defineProperty) {
  46. defineProperty(objectPrototype, '$$globalThis$$', {
  47. get: returnThis,
  48. configurable: true
  49. });
  50. } else {
  51. objectPrototype.__defineGetter__('$$globalThis$$', returnThis);
  52. }
  53. $globalThis = typeof $$globalThis$$ === 'undefined' ? getGlobalFallback() : $$globalThis$$;
  54. delete objectPrototype.$$globalThis$$;
  55. return $globalThis;
  56. } catch (error) {
  57. return getGlobalFallback();
  58. }
  59. }()), function() {
  60. return /******/ (function(modules) { // webpackBootstrap
  61. /******/ // The module cache
  62. /******/ var installedModules = {};
  63. /******/
  64. /******/ // The require function
  65. /******/ function __webpack_require__(moduleId) {
  66. /******/
  67. /******/ // Check if module is in cache
  68. /******/ if(installedModules[moduleId]) {
  69. /******/ return installedModules[moduleId].exports;
  70. /******/ }
  71. /******/ // Create a new module (and put it into the cache)
  72. /******/ var module = installedModules[moduleId] = {
  73. /******/ i: moduleId,
  74. /******/ l: false,
  75. /******/ exports: {}
  76. /******/ };
  77. /******/
  78. /******/ // Execute the module function
  79. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  80. /******/
  81. /******/ // Flag the module as loaded
  82. /******/ module.l = true;
  83. /******/
  84. /******/ // Return the exports of the module
  85. /******/ return module.exports;
  86. /******/ }
  87. /******/
  88. /******/
  89. /******/ // expose the modules object (__webpack_modules__)
  90. /******/ __webpack_require__.m = modules;
  91. /******/
  92. /******/ // expose the module cache
  93. /******/ __webpack_require__.c = installedModules;
  94. /******/
  95. /******/ // define getter function for harmony exports
  96. /******/ __webpack_require__.d = function(exports, name, getter) {
  97. /******/ if(!__webpack_require__.o(exports, name)) {
  98. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  99. /******/ }
  100. /******/ };
  101. /******/
  102. /******/ // define __esModule on exports
  103. /******/ __webpack_require__.r = function(exports) {
  104. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  105. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  106. /******/ }
  107. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  108. /******/ };
  109. /******/
  110. /******/ // create a fake namespace object
  111. /******/ // mode & 1: value is a module id, require it
  112. /******/ // mode & 2: merge all properties of value into the ns
  113. /******/ // mode & 4: return value when already ns object
  114. /******/ // mode & 8|1: behave like require
  115. /******/ __webpack_require__.t = function(value, mode) {
  116. /******/ if(mode & 1) value = __webpack_require__(value);
  117. /******/ if(mode & 8) return value;
  118. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  119. /******/ var ns = Object.create(null);
  120. /******/ __webpack_require__.r(ns);
  121. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  122. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  123. /******/ return ns;
  124. /******/ };
  125. /******/
  126. /******/ // getDefaultExport function for compatibility with non-harmony modules
  127. /******/ __webpack_require__.n = function(module) {
  128. /******/ var getter = module && module.__esModule ?
  129. /******/ function getDefault() { return module['default']; } :
  130. /******/ function getModuleExports() { return module; };
  131. /******/ __webpack_require__.d(getter, 'a', getter);
  132. /******/ return getter;
  133. /******/ };
  134. /******/
  135. /******/ // Object.prototype.hasOwnProperty.call
  136. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  137. /******/
  138. /******/ // __webpack_public_path__
  139. /******/ __webpack_require__.p = "";
  140. /******/
  141. /******/
  142. /******/ // Load entry module and return exports
  143. /******/ return __webpack_require__(__webpack_require__.s = 1);
  144. /******/ })
  145. /************************************************************************/
  146. /******/ ([
  147. /* 0 */
  148. /***/ (function(module) {
  149. module.exports = JSON.parse("{\"name\":\"v-click-outside-x\",\"version\":\"4.1.2\",\"description\":\"Vue directive to react on clicks outside an element.\",\"homepage\":\"https://github.com/SergioCrisostomo/v-click-outside-x.git\",\"author\":{\"name\":\"Graham Fairweather\"},\"maintainers\":[{\"name\":\"Sérgio Crisóstomo\",\"email\":\"sergiosbox@gmail.com\"}],\"copyright\":\"Copyright (c) 2018-present\",\"keywords\":[\"vue\",\"click\",\"outside\",\"directive\"],\"files\":[\"dist\",\"src\"],\"module\":\"dist/v-click-outside-x.esm.js\",\"main\":\"dist/v-click-outside-x.js\",\"typings\":\"types/index.d.ts\",\"jsdelivr\":\"dist/v-click-outside-x.min.js\",\"scripts\":{\"build:esm\":\"mkdirp dist && babel -s true --env-name esm src/v-click-outside-x.js -o dist/v-click-outside-x.esm.js\",\"build:base\":\"webpack --bail --progress --profile --colors\",\"build\":\"npm run build:esm && cross-env NODE_ENV=production npm run build:base --\",\"build:dev\":\"npm run build:base --\",\"clean\":\"rimraf dist && npm run clean:coverage\",\"clean:coverage\":\"rimraf __tests__/coverage\",\"lint\":\"eslint -f 'node_modules/eslint-friendly-formatter' --ext .js,.json .\",\"lint-fix\":\"npm run lint -- --fix\",\"report\":\"npm run build -- --env.report\",\"report:dev\":\"npm run build:dev -- --env.report\",\"security\":\"npm audit\",\"security-fix\":\"npm run security -- fix\",\"start\":\"nodemon --exec \\\"npm run build\\\" --watch src\",\"test\":\"npm run clean:coverage && jest\",\"test:ci\":\"npm run test -- --ci --maxWorkers=2\",\"test:ci-coveralls\":\"npm run test:ci -- --coverage --coverageReporters=text-lcov | coveralls\",\"test:coverage\":\"npm run test -- --coverage\"},\"license\":\"MIT\",\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/Xotic750/v-click-outside-x.git\"},\"bugs\":{\"url\":\"https://github.com/Xotic750/v-click-outside-x/issues\"},\"dependencies\":{},\"devDependencies\":{\"@babel/cli\":\"^7.13.16\",\"@babel/core\":\"^7.13.16\",\"@babel/node\":\"^7.13.13\",\"@babel/plugin-transform-property-mutators\":\"^7.12.13\",\"@babel/plugin-transform-runtime\":\"^7.13.15\",\"@babel/preset-env\":\"^7.13.15\",\"@babel/runtime\":\"^7.13.17\",\"@types/jest\":\"^24.9.1\",\"@types/node\":\"^13.13.50\",\"@types/webpack\":\"^4.41.27\",\"@typescript-eslint/eslint-plugin\":\"^2.34.0\",\"@typescript-eslint/parser\":\"^2.34.0\",\"babel-core\":\"^7.0.0-0\",\"babel-eslint\":\"^10.1.0\",\"babel-loader\":\"^8.2.2\",\"babel-plugin-lodash\":\"^3.3.4\",\"caniuse-lite\":\"^1.0.30001214\",\"coveralls\":\"^3.1.0\",\"cross-env\":\"^6.0.3\",\"eslint\":\"^6.8.0\",\"eslint-friendly-formatter\":\"^4.0.1\",\"eslint-import-resolver-webpack\":\"^0.12.2\",\"eslint-loader\":\"^3.0.4\",\"eslint-plugin-babel\":\"^5.3.1\",\"eslint-plugin-compat\":\"^3.9.0\",\"eslint-plugin-css-modules\":\"^2.11.0\",\"eslint-plugin-eslint-comments\":\"^3.2.0\",\"eslint-plugin-html\":\"^6.1.2\",\"eslint-plugin-import\":\"^2.22.1\",\"eslint-plugin-jest\":\"^22.17.0\",\"eslint-plugin-jsdoc\":\"^20.4.0\",\"eslint-plugin-json\":\"^1.4.0\",\"eslint-plugin-lodash\":\"^6.0.0\",\"eslint-plugin-no-use-extend-native\":\"^0.4.1\",\"eslint-plugin-prefer-object-spread\":\"^1.2.1\",\"eslint-plugin-prettier\":\"^3.4.0\",\"eslint-plugin-promise\":\"^4.3.1\",\"eslint-plugin-sort-class-members\":\"^1.11.0\",\"eslint-plugin-switch-case\":\"^1.1.2\",\"jest\":\"^24.9.0\",\"jest-cli\":\"^24.9.0\",\"jest-file\":\"^1.0.0\",\"lodash\":\"^4.17.21\",\"lodash-webpack-plugin\":\"^0.11.6\",\"mkdirp\":\"^0.5.5\",\"nodemon\":\"^2.0.7\",\"prettier\":\"^1.19.1\",\"rimraf\":\"^3.0.2\",\"source-map-loader\":\"^0.2.4\",\"strip-ansi\":\"^6.0.0\",\"terser-webpack-plugin\":\"^2.3.8\",\"typescript\":\"^3.9.9\",\"webpack\":\"^4.46.0\",\"webpack-bundle-analyzer\":\"^3.9.0\",\"webpack-cli\":\"^3.3.12\",\"webpack-global-object-x\":\"^1.0.1\",\"webpack-merge\":\"^4.2.2\"},\"engines\":{\"node\":\">=8.11.4\",\"npm\":\">=6.10.1\"},\"browserslist\":[\"> 1%\",\"Explorer >= 9\"]}");
  150. /***/ }),
  151. /* 1 */
  152. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  153. "use strict";
  154. __webpack_require__.r(__webpack_exports__);
  155. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "directive", function() { return directive; });
  156. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "install", function() { return install; });
  157. /* harmony import */ var _package_json__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
  158. var _package_json__WEBPACK_IMPORTED_MODULE_0___namespace = /*#__PURE__*/__webpack_require__.t(0, 1);
  159. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  160. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  161. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  162. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  163. var version = _package_json__WEBPACK_IMPORTED_MODULE_0__.version;
  164. /**
  165. * @typedef {import("../types/index.d.ts")} VClickOutsidePlugin
  166. */
  167. var CLICK = 'click';
  168. var captureInstances = Object.create(null);
  169. var nonCaptureInstances = Object.create(null);
  170. var captureEventHandlers = Object.create(null);
  171. var nonCaptureEventHandlers = Object.create(null);
  172. var instancesList = [captureInstances, nonCaptureInstances];
  173. /**
  174. * The common event handler for bot capture and non-capture events.
  175. *
  176. * @param {!object} context - The event context.
  177. * @param {!object} instances - The capture or non-capture registered instances.
  178. * @param {Event} event - The event object.
  179. * @param {string} arg - The event type.
  180. * @returns {undefined} Default.
  181. */
  182. var commonHandler = function onCommonEvent(context, instances, event, arg) {
  183. var target = event.target;
  184. var itemIteratee = function itemIteratee(item) {
  185. var el = item.el;
  186. if (el !== target && !el.contains(target)) {
  187. var binding = item.binding;
  188. if (binding.modifiers.stop) {
  189. event.stopPropagation();
  190. }
  191. if (binding.modifiers.prevent) {
  192. event.preventDefault();
  193. }
  194. binding.value.call(context, event);
  195. }
  196. };
  197. instances[arg].forEach(itemIteratee);
  198. };
  199. /**
  200. * Get the correct event handler: Capture or non-capture.
  201. *
  202. * @param {boolean} useCapture - Indicate which handler to use; 'true' to use
  203. * capture handler or 'false' for non-capture.
  204. * @param {string} arg - The event type.
  205. * @returns {Function} - The event handler.
  206. */
  207. var getEventHandler = function getEventHandler(useCapture, arg) {
  208. if (useCapture) {
  209. if (captureEventHandlers[arg]) {
  210. return captureEventHandlers[arg];
  211. }
  212. /**
  213. * Event handler for capture events.
  214. *
  215. * @param {Event} event - The event object.
  216. */
  217. captureEventHandlers[arg] = function onCaptureEvent(event) {
  218. commonHandler(this, captureInstances, event, arg);
  219. };
  220. return captureEventHandlers[arg];
  221. }
  222. if (nonCaptureEventHandlers[arg]) {
  223. return nonCaptureEventHandlers[arg];
  224. }
  225. /**
  226. * Event handler for non-capture events.
  227. *
  228. * @param {Event} event - The event object.
  229. */
  230. nonCaptureEventHandlers[arg] = function onNonCaptureEvent(event) {
  231. commonHandler(this, nonCaptureInstances, event, arg);
  232. };
  233. return nonCaptureEventHandlers[arg];
  234. };
  235. /**
  236. * The directive definition.
  237. * {@link https://vuejs.org/v2/guide/custom-directive.html|Custom directive}.
  238. *
  239. * @type {VClickOutsidePlugin.directive}
  240. * @property {!object} $captureInstances - Registered capture instances.
  241. * @property {!object} $nonCaptureInstances - Registered non-capture instances.
  242. * @property {Function} $_onCaptureEvent - Event handler for capture events.
  243. * @property {Function} $_onNonCaptureEvent - Event handler for non-capture events.
  244. * @property {Function} bind - Called only once, when the directive is first
  245. * bound to the element.
  246. * @property {Function} unbind - Called only once, when the directive is unbound
  247. * from the element.
  248. * @property {string} version - The version number of this release.
  249. */
  250. var directive = Object.defineProperties({}, {
  251. $captureInstances: {
  252. value: captureInstances
  253. },
  254. $nonCaptureInstances: {
  255. value: nonCaptureInstances
  256. },
  257. $captureEventHandlers: {
  258. value: captureEventHandlers
  259. },
  260. $nonCaptureEventHandlers: {
  261. value: nonCaptureEventHandlers
  262. },
  263. bind: {
  264. value: function bind(el, binding) {
  265. if (typeof binding.value !== 'function') {
  266. throw new TypeError('Binding value must be a function.');
  267. }
  268. var arg = binding.arg || CLICK;
  269. var normalisedBinding = _objectSpread(_objectSpread({}, binding), {
  270. arg: arg,
  271. modifiers: _objectSpread(_objectSpread({}, {
  272. capture: false,
  273. prevent: false,
  274. stop: false
  275. }), binding.modifiers)
  276. });
  277. var useCapture = normalisedBinding.modifiers.capture;
  278. var instances = useCapture ? captureInstances : nonCaptureInstances;
  279. if (!Array.isArray(instances[arg])) {
  280. instances[arg] = [];
  281. }
  282. if (instances[arg].push({
  283. el: el,
  284. binding: normalisedBinding
  285. }) === 1) {
  286. /* istanbul ignore next */
  287. if ((typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object' && document) {
  288. document.addEventListener(arg, getEventHandler(useCapture, arg), useCapture);
  289. }
  290. }
  291. }
  292. },
  293. unbind: {
  294. value: function unbind(el) {
  295. var compareElements = function compareElements(item) {
  296. return item.el !== el;
  297. };
  298. var instancesIteratee = function instancesIteratee(instances) {
  299. var instanceKeys = Object.keys(instances);
  300. if (instanceKeys.length) {
  301. var useCapture = instances === captureInstances;
  302. var keysIteratee = function keysIteratee(eventName) {
  303. var newInstance = instances[eventName].filter(compareElements);
  304. if (newInstance.length) {
  305. instances[eventName] = newInstance;
  306. } else {
  307. /* istanbul ignore next */
  308. if ((typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object' && document) {
  309. document.removeEventListener(eventName, getEventHandler(useCapture, eventName), useCapture);
  310. }
  311. delete instances[eventName];
  312. }
  313. };
  314. instanceKeys.forEach(keysIteratee);
  315. }
  316. };
  317. instancesList.forEach(instancesIteratee);
  318. }
  319. },
  320. /* Note: This needs to be manually updated to match package.json. */
  321. version: {
  322. enumerable: true,
  323. value: version
  324. }
  325. });
  326. /**
  327. * A Vue.js plugin should expose an install method. The method will be called
  328. * with the Vue constructor as the first argument, along with possible options.
  329. * {@link https://vuejs.org/v2/guide/plugins.html#Writing-a-Plugin|Writing a plugin}.
  330. *
  331. * @type {VClickOutsidePlugin.install}
  332. * @param {import("vue")} Vue - The Vue constructor.
  333. */
  334. function install(Vue) {
  335. Vue.directive('click-outside', directive);
  336. }
  337. /***/ })
  338. /******/ ]);
  339. });
  340. //# sourceMappingURL=v-click-outside-x.js.map