Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

v-click-outside-x

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

v-click-outside-x - npm Package Compare versions

Comparing version 3.7.1 to 4.0.0

562

__tests__/v-click-outside-x.test.js
import PACKAGE_JSON from 'RootDir/package';
import * as ESM from 'src/index';
import * as WEB from 'dist/v-click-outside-x';
import * as MIN from 'dist/v-click-outside-x.min';
import {directive, install} from 'src/index';
const ESMREQ = require('src/index');
const WEBREQ = require('dist/v-click-outside-x');
const MINREQ = require('dist/v-click-outside-x.min');
const namePrefix = 'vClickOutside';
const methods = [
{method: ESM, name: `${namePrefix} ESM`},
{method: WEB, name: `${namePrefix} WEB`},
{method: MIN, name: `${namePrefix} MIN`},
{method: ESMREQ, name: `${namePrefix} ESMREQ`},
{method: WEBREQ, name: `${namePrefix} WEBREQ`},
{method: MINREQ, name: `${namePrefix} MINREQ`},
{method: ESM, name: `${namePrefix} ESM no document`, noDoc: true},
];
const doc = window.document;
methods.forEach(({method, name, noDoc}) => {
const {directive, install} = method;
let calls = 1;
describe('vClickOutside', () => {
beforeEach(() => {
doc.addEventListener = jest.fn();
doc.removeEventListener = jest.fn();
});
describe(`${name}`, () => {
beforeAll(() => {
if (noDoc) {
calls = 0;
delete window.document;
}
});
afterEach(() => {
doc.addEventListener = undefined;
doc.removeEventListener = undefined;
});
beforeEach(() => {
doc.addEventListener = jest.fn();
doc.removeEventListener = jest.fn();
});
describe('plugin', () => {
it('the directive is an object', () => {
expect.assertions(1);
afterEach(() => {
doc.addEventListener = undefined;
doc.removeEventListener = undefined;
expect(directive).toBeInstanceOf(Object);
});
describe('plugin', () => {
it('the directive is an object', () => {
expect.assertions(1);
it('it has all hook functions available', () => {
expect.assertions(2);
expect(directive).toBeInstanceOf(Object);
['bind', 'unbind'].forEach(functionName => {
expect(directive[functionName]).toBeInstanceOf(Function);
});
});
it('it has all hook functions available', () => {
expect.assertions(2);
it('$_captureInstances is an empty Object', () => {
expect.assertions(1);
['bind', 'unbind'].forEach(functionName => {
expect(directive[functionName]).toBeInstanceOf(Function);
});
});
expect(Object.keys(directive.$_captureInstances)).toHaveLength(0);
});
it('$_captureInstances is an empty Map', () => {
expect.assertions(1);
it('$_nonCaptureInstances is an empty Object', () => {
expect.assertions(1);
expect(Object.keys(directive.$_captureInstances)).toHaveLength(0);
});
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
});
it('$_nonCaptureInstances is an empty Map', () => {
expect.assertions(1);
it('$_captureEventHandlers an empty Object', () => {
expect.assertions(1);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
});
expect(Object.keys(directive.$_captureEventHandlers)).toHaveLength(0);
});
it('$_onCaptureEvent to be a function', () => {
expect.assertions(1);
it('$_nonCaptureEventHandlers an empty Object', () => {
expect.assertions(1);
expect(directive.$_onCaptureEvent).toBeInstanceOf(Function);
});
expect(Object.keys(directive.$_nonCaptureEventHandlers)).toHaveLength(0);
});
it('$_onNonCaptureEvent to be a function', () => {
expect.assertions(1);
it('version to be a string', () => {
expect.assertions(1);
expect(directive.$_onNonCaptureEvent).toBeInstanceOf(Function);
});
expect(typeof directive.version).toStrictEqual('string');
});
it('version to be a string', () => {
expect.assertions(1);
it('version to be as per package.json', () => {
expect.assertions(1);
expect(typeof directive.version).toStrictEqual('string');
});
expect(directive.version).toStrictEqual(PACKAGE_JSON.version);
});
it('version to be as per package.json', () => {
expect.assertions(1);
it('version to be enumerable', () => {
expect.assertions(1);
expect(directive.version).toStrictEqual(PACKAGE_JSON.version);
});
expect(
Object.prototype.propertyIsEnumerable.call(directive, 'version'),
).toBe(true);
});
it('version to be enumerable', () => {
expect.assertions(1);
it('install the directive into the vue instance', () => {
expect.assertions(2);
expect(
Object.prototype.propertyIsEnumerable.call(directive, 'version'),
).toBe(true);
});
const vue = {
directive: jest.fn(),
};
it('install the directive into the vue instance', () => {
expect.assertions(2);
install(vue);
const vue = {
directive: jest.fn(),
};
install(vue);
expect(vue.directive).toHaveBeenCalledWith('click-outside', directive);
expect(vue.directive).toHaveBeenCalledTimes(1);
});
expect(vue.directive).toHaveBeenCalledWith('click-outside', directive);
expect(vue.directive).toHaveBeenCalledTimes(1);
});
});
describe('directive', () => {
describe('bind/unbind', () => {
describe('bind exceptions', () => {
it('throws an error if value is not a function', () => {
expect.assertions(1);
describe('directive', () => {
describe('bind/unbind', () => {
describe('bind exceptions', () => {
it('throws an error if value is not a function', () => {
expect.assertions(1);
const div1 = doc.createElement('div');
const div1 = doc.createElement('div');
const bindWithNoFunction = () => directive.bind(div1, {});
const bindWithNoFunction = () => directive.bind(div1, {});
expect(bindWithNoFunction).toThrowErrorMatchingSnapshot();
});
expect(bindWithNoFunction).toThrowErrorMatchingSnapshot();
});
});
describe('single', () => {
const div1 = doc.createElement('div');
describe('single', () => {
const div1 = doc.createElement('div');
it('adds to the list and event listener', () => {
expect.assertions(6);
it('adds to the list and event listener', () => {
expect.assertions(6);
const eventHandler = jest.fn();
const eventHandler = jest.fn();
directive.bind(div1, {value: eventHandler});
directive.bind(div1, {value: eventHandler});
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(
1,
);
expect(directive.$_nonCaptureInstances).toHaveProperty('click');
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(1);
expect(directive.$_nonCaptureInstances).toHaveProperty('click');
const clickInstances = directive.$_nonCaptureInstances.click;
const clickInstances = directive.$_nonCaptureInstances.click;
expect(clickInstances).toBeInstanceOf(Array);
expect(clickInstances).toHaveLength(1);
expect(clickInstances.find(item => item.el === div1)).toBeDefined();
expect(doc.addEventListener.mock.calls).toHaveLength(calls);
});
expect(clickInstances).toBeInstanceOf(Array);
expect(clickInstances).toHaveLength(1);
expect(clickInstances.find(item => item.el === div1)).toBeDefined();
expect(doc.addEventListener.mock.calls).toHaveLength(1);
});
it('removes from the list and event listener', () => {
expect.assertions(2);
it('removes from the list and event listener', () => {
expect.assertions(2);
directive.unbind(div1);
directive.unbind(div1);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(
0,
);
expect(doc.removeEventListener.mock.calls).toHaveLength(calls);
});
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
expect(doc.removeEventListener.mock.calls).toHaveLength(1);
});
});
describe('multiple', () => {
const div1 = doc.createElement('div');
const div2 = doc.createElement('div');
describe('multiple', () => {
const div1 = doc.createElement('div');
const div2 = doc.createElement('div');
it('adds to the list and event listener', () => {
expect.assertions(7);
it('adds to the list and event listener', () => {
expect.assertions(7);
const eventHandler1 = jest.fn();
const eventHandler2 = jest.fn();
const eventHandler1 = jest.fn();
const eventHandler2 = jest.fn();
directive.bind(div1, {value: eventHandler1});
directive.bind(div2, {arg: 'click', value: eventHandler2});
directive.bind(div1, {value: eventHandler1});
directive.bind(div2, {arg: 'click', value: eventHandler2});
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(
1,
);
expect(directive.$_nonCaptureInstances).toHaveProperty('click');
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(1);
expect(directive.$_nonCaptureInstances).toHaveProperty('click');
const clickInstances = directive.$_nonCaptureInstances.click;
const clickInstances = directive.$_nonCaptureInstances.click;
expect(clickInstances).toBeInstanceOf(Array);
expect(clickInstances).toHaveLength(2);
expect(clickInstances).toBeInstanceOf(Array);
expect(clickInstances).toHaveLength(2);
expect(clickInstances.find(item => item.el === div1)).toBeDefined();
expect(clickInstances.find(item => item.el === div2)).toBeDefined();
expect(doc.addEventListener.mock.calls).toHaveLength(calls);
});
expect(clickInstances.find(item => item.el === div1)).toBeDefined();
expect(clickInstances.find(item => item.el === div2)).toBeDefined();
expect(doc.addEventListener.mock.calls).toHaveLength(1);
});
it('removes from the list and the event listener', () => {
expect.assertions(7);
it('removes from the list and the event listener', () => {
expect.assertions(7);
directive.unbind(div1);
directive.unbind(div1);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(
1,
);
expect(directive.$_nonCaptureInstances).toHaveProperty('click');
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(1);
expect(directive.$_nonCaptureInstances).toHaveProperty('click');
const clickInstances = directive.$_nonCaptureInstances.click;
const clickInstances = directive.$_nonCaptureInstances.click;
expect(clickInstances).toBeInstanceOf(Array);
expect(clickInstances).toHaveLength(1);
expect(clickInstances.find(item => item.el === div2)).toBeDefined();
expect(clickInstances).toBeInstanceOf(Array);
expect(clickInstances).toHaveLength(1);
expect(clickInstances.find(item => item.el === div2)).toBeDefined();
directive.unbind(div2);
directive.unbind(div2);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(
0,
);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
expect(doc.removeEventListener.mock.calls).toHaveLength(calls);
});
expect(doc.removeEventListener.mock.calls).toHaveLength(1);
});
});
describe('bind', () => {
it('saves the instance binding and element', () => {
expect.assertions(11);
describe('bind', () => {
it('saves the instance binding and element', () => {
expect.assertions(13);
const div1 = doc.createElement('div');
const div2 = doc.createElement('div');
const div3 = doc.createElement('div');
const eventHandler1 = jest.fn();
const eventHandler2 = jest.fn();
const div1 = doc.createElement('div');
const div2 = doc.createElement('div');
const div3 = doc.createElement('div');
const eventHandler1 = jest.fn();
const eventHandler2 = jest.fn();
directive.bind(div1, {
arg: 'pointerdown',
modifiers: {capture: true},
value: eventHandler1,
});
directive.bind(div2, {
arg: 'pointerdown',
modifiers: {stop: true},
value: eventHandler2,
});
directive.bind(div3, {
arg: 'pointerdown',
modifiers: {prevent: true},
value: eventHandler2,
});
directive.bind(div1, {
arg: 'pointerdown',
modifiers: {capture: true},
value: eventHandler1,
});
directive.bind(div2, {
arg: 'pointerdown',
modifiers: {stop: true},
value: eventHandler2,
});
directive.bind(div3, {
arg: 'pointerdown',
modifiers: {prevent: true},
value: eventHandler2,
});
expect(Object.keys(directive.$_captureInstances)).toHaveLength(1);
expect(directive.$_captureInstances).toHaveProperty('pointerdown');
expect(Object.keys(directive.$_captureInstances)).toHaveLength(1);
expect(directive.$_captureInstances).toHaveProperty('pointerdown');
const clickCaptureInstances =
directive.$_captureInstances.pointerdown;
const clickCaptureInstances =
directive.$_captureInstances.pointerdown;
expect(clickCaptureInstances).toBeInstanceOf(Array);
expect(clickCaptureInstances).toHaveLength(1);
expect(clickCaptureInstances).toBeInstanceOf(Array);
expect(clickCaptureInstances).toHaveLength(1);
expect(
clickCaptureInstances.find(item => item.el === div1),
).toStrictEqual({
binding: {
arg: 'pointerdown',
modifiers: {
capture: true,
prevent: false,
stop: false,
},
value: eventHandler1,
expect(
clickCaptureInstances.find(item => item.el === div1),
).toStrictEqual({
binding: {
arg: 'pointerdown',
modifiers: {
capture: true,
prevent: false,
stop: false,
},
el: div1,
});
value: eventHandler1,
},
el: div1,
});
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(
1,
);
expect(directive.$_nonCaptureInstances).toHaveProperty(
'pointerdown',
);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(1);
expect(directive.$_nonCaptureInstances).toHaveProperty('pointerdown');
const clickNonCaptureInstances =
directive.$_nonCaptureInstances.pointerdown;
const clickNonCaptureInstances =
directive.$_nonCaptureInstances.pointerdown;
expect(clickNonCaptureInstances).toBeInstanceOf(Array);
expect(clickNonCaptureInstances).toHaveLength(2);
expect(clickNonCaptureInstances).toBeInstanceOf(Array);
expect(clickNonCaptureInstances).toHaveLength(2);
expect(
clickNonCaptureInstances.find(item => item.el === div2),
).toStrictEqual({
binding: {
arg: 'pointerdown',
modifiers: {
capture: false,
prevent: false,
stop: true,
},
value: eventHandler2,
expect(
clickNonCaptureInstances.find(item => item.el === div2),
).toStrictEqual({
binding: {
arg: 'pointerdown',
modifiers: {
capture: false,
prevent: false,
stop: true,
},
el: div1,
});
value: eventHandler2,
},
el: div1,
});
expect(
clickNonCaptureInstances.find(item => item.el === div3),
).toStrictEqual({
binding: {
arg: 'pointerdown',
modifiers: {
capture: false,
prevent: true,
stop: false,
},
value: eventHandler2,
expect(
clickNonCaptureInstances.find(item => item.el === div3),
).toStrictEqual({
binding: {
arg: 'pointerdown',
modifiers: {
capture: false,
prevent: true,
stop: false,
},
el: div1,
});
value: eventHandler2,
},
el: div1,
});
directive.unbind(div1);
directive.unbind(div2);
directive.unbind(div3);
});
directive.unbind(div1);
directive.unbind(div2);
directive.unbind(div3);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
expect(Object.keys(directive.$_captureInstances)).toHaveLength(0);
});
});
});
describe('$_onCaptureEvent', () => {
const div1 = doc.createElement('div');
const span = doc.createElement('span');
div1.appendChild(span);
describe('eventHandlers', () => {
const div1 = doc.createElement('div');
const span = doc.createElement('span');
div1.appendChild(span);
it('calls the callback if the element is not the same and does not contain the event target', () => {
expect.assertions(10);
it('calls the callback if the element is not the same and does not contain the event target', () => {
expect.assertions(12);
const a = doc.createElement('a');
const event = {
preventDefault: jest.fn(),
stopPropagation: jest.fn(),
target: a,
};
const a = doc.createElement('a');
const event = {
preventDefault: jest.fn(),
stopPropagation: jest.fn(),
target: a,
};
const eventHandler1 = jest.fn();
const eventHandler1 = jest.fn();
directive.bind(div1, {value: eventHandler1});
directive.$_onNonCaptureEvent(event);
directive.bind(div1, {value: eventHandler1});
directive.$_nonCaptureEventHandlers.click(event);
expect(eventHandler1).toHaveBeenCalledWith(event);
expect(eventHandler1.mock.instances).toHaveLength(1);
expect(eventHandler1.mock.instances[0]).toBe(directive);
expect(eventHandler1).toHaveBeenCalledWith(event);
expect(eventHandler1.mock.instances).toHaveLength(1);
// expect(eventHandler1.mock.instances[0]).toBe(directive);
expect(event.preventDefault).not.toHaveBeenCalled();
expect(event.stopPropagation).not.toHaveBeenCalled();
expect(event.preventDefault).not.toHaveBeenCalled();
expect(event.stopPropagation).not.toHaveBeenCalled();
directive.unbind(div1);
directive.unbind(div1);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
expect(Object.keys(directive.$_captureInstances)).toHaveLength(0);
const eventHandler2 = jest.fn();
const eventHandler2 = jest.fn();
directive.bind(div1, {
arg: 'touchdown',
modifiers: {capture: true, prevent: true, stop: true},
value: eventHandler2,
});
directive.$_onCaptureEvent(event);
directive.bind(div1, {
arg: 'touchdown',
modifiers: {capture: true, prevent: true, stop: true},
value: eventHandler2,
});
directive.$_captureEventHandlers.touchdown(event);
expect(eventHandler2).toHaveBeenCalledWith(event);
expect(eventHandler2.mock.instances).toHaveLength(1);
expect(eventHandler2.mock.instances[0]).toBe(directive);
expect(eventHandler2).toHaveBeenCalledWith(event);
expect(eventHandler2.mock.instances).toHaveLength(1);
// expect(eventHandler2.mock.instances[0]).toBe(directive);
expect(event.preventDefault).toHaveBeenCalled();
expect(event.stopPropagation).toHaveBeenCalled();
expect(event.preventDefault).toHaveBeenCalled();
expect(event.stopPropagation).toHaveBeenCalled();
directive.unbind(div1);
});
directive.unbind(div1);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
expect(Object.keys(directive.$_captureInstances)).toHaveLength(0);
});
it('does not execute the callback if the event target its the element from the instance', () => {
expect.assertions(2);
it('does not execute the callback if the event target its the element from the instance', () => {
expect.assertions(4);
const event = {
target: div1,
};
const event = {
target: div1,
};
const eventHandler = jest.fn();
const eventHandler = jest.fn();
directive.bind(div1, {value: eventHandler});
directive.$_onNonCaptureEvent(event);
directive.bind(div1, {value: eventHandler});
directive.$_nonCaptureEventHandlers.click(event);
expect(eventHandler).not.toHaveBeenCalled();
expect(eventHandler.mock.instances).toHaveLength(0);
expect(eventHandler).not.toHaveBeenCalled();
expect(eventHandler.mock.instances).toHaveLength(0);
directive.unbind(div1);
});
directive.unbind(div1);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
expect(Object.keys(directive.$_captureInstances)).toHaveLength(0);
});
it('does not execute the callback if the event target is contained in the element from the instance', () => {
expect.assertions(2);
it('does not execute the callback if the event target is contained in the element from the instance', () => {
expect.assertions(4);
const event = {
target: span,
};
const event = {
target: span,
};
const eventHandler = jest.fn();
const eventHandler = jest.fn();
directive.bind(div1, {value: eventHandler});
directive.$_onNonCaptureEvent(event);
directive.bind(div1, {value: eventHandler});
directive.$_nonCaptureEventHandlers.click(event);
expect(eventHandler).not.toHaveBeenCalled();
expect(eventHandler.mock.instances).toHaveLength(0);
expect(eventHandler).not.toHaveBeenCalled();
expect(eventHandler.mock.instances).toHaveLength(0);
directive.unbind(div1);
});
directive.unbind(div1);
expect(Object.keys(directive.$_nonCaptureInstances)).toHaveLength(0);
expect(Object.keys(directive.$_captureInstances)).toHaveLength(0);
});

@@ -405,0 +373,0 @@ });

/*!
{
"copywrite": "Copyright (c) 2018-present",
"date": "2019-01-21T12:39:36.944Z",
"date": "2019-03-02T15:01:20.705Z",
"describe": "",
"description": "Vue directive to react on clicks outside an element.",
"file": "v-click-outside-x.js",
"hash": "092bce160dbfe488bc08",
"hash": "21b0aa42ea4496984219",
"license": "MIT",
"version": "3.7.1"
"version": "4.0.0"
}

@@ -147,2 +147,4 @@ */

var nonCaptureInstances = Object.create(null);
var captureEventHandlers = Object.create(null);
var nonCaptureEventHandlers = Object.create(null);
var instancesList = [captureInstances, nonCaptureInstances];

@@ -155,6 +157,7 @@ /**

* @param {Event} event - The event object.
* @param {string} arg - The event type.
* @returns {undefined} Default.
*/
var commonHandler = function _onCommonEvent(context, instances, event) {
var commonHandler = function _onCommonEvent(context, instances, event, arg) {
var target = event.target;

@@ -180,31 +183,5 @@

var keysIteratee = function _keysIteratee(eventName) {
return instances[eventName].forEach(itemIteratee);
};
Object.keys(instances).forEach(keysIteratee);
instances[arg].forEach(itemIteratee);
};
/**
* Event handler for capture events.
*
* @param {Event} event - The event object.
*/
var captureEventHandler = function onCaptureEvent(event) {
/* eslint-disable-next-line babel/no-invalid-this */
commonHandler(this, captureInstances, event);
};
/**
* Event handler for non-capture events.
*
* @param {Event} event - The event object.
*/
var nonCaptureEventHandler = function onNonCaptureEvent(event) {
/* eslint-disable-next-line babel/no-invalid-this */
commonHandler(this, nonCaptureInstances, event);
};
/**
* Get the correct event handler: Capture or non-capture.

@@ -214,2 +191,3 @@ *

* capture handler or 'false' for non-capture.
* @param {string} arg - The event type.
* @returns {Function} - The event handler.

@@ -219,4 +197,36 @@ */

var getEventHandler = function _getEventHandler(useCapture) {
return useCapture ? captureEventHandler : nonCaptureEventHandler;
var getEventHandler = function _getEventHandler(useCapture, arg) {
if (useCapture) {
if (captureEventHandlers[arg]) {
return captureEventHandlers[arg];
}
/**
* Event handler for capture events.
*
* @param {Event} event - The event object.
*/
captureEventHandlers[arg] = function onCaptureEvent(event) {
commonHandler(this, captureInstances, event, arg);
};
return captureEventHandlers[arg];
}
if (nonCaptureEventHandlers[arg]) {
return nonCaptureEventHandlers[arg];
}
/**
* Event handler for non-capture events.
*
* @param {Event} event - The event object.
*/
nonCaptureEventHandlers[arg] = function onNonCaptureEvent(event) {
commonHandler(this, nonCaptureInstances, event, arg);
};
return nonCaptureEventHandlers[arg];
};

@@ -247,7 +257,7 @@ /**

},
$_onCaptureEvent: {
value: captureEventHandler
$_captureEventHandlers: {
value: captureEventHandlers
},
$_onNonCaptureEvent: {
value: nonCaptureEventHandler
$_nonCaptureEventHandlers: {
value: nonCaptureEventHandlers
},

@@ -283,3 +293,3 @@ bind: {

if ((typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object' && document) {
document.addEventListener(arg, getEventHandler(useCapture), useCapture);
document.addEventListener(arg, getEventHandler(useCapture, arg), useCapture);
}

@@ -308,3 +318,3 @@ }

if ((typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object' && document) {
document.removeEventListener(eventName, getEventHandler(useCapture), useCapture);
document.removeEventListener(eventName, getEventHandler(useCapture, eventName), useCapture);
}

@@ -327,3 +337,3 @@

enumerable: true,
value: '3.7.1'
value: '4.0.0'
}

@@ -330,0 +340,0 @@ });

/*!
{
"copywrite": "Copyright (c) 2018-present",
"date": "2019-01-21T12:39:36.944Z",
"date": "2019-03-02T15:01:20.705Z",
"describe": "",
"description": "Vue directive to react on clicks outside an element.",
"file": "v-click-outside-x.min.js",
"hash": "ef8b7b3c24168423686e",
"hash": "91eca26e4e7f69762b75",
"license": "MIT",
"version": "3.7.1"
"version": "4.0.0"
}
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.vClickOutside=t():e.vClickOutside=t()}(function(){"use strict";return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:Function("return this")()}(),function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){u(e,t,n[t])})}return e}function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}Object.defineProperty(t,"__esModule",{value:!0}),t.install=function(e){e.directive("click-outside",s)},t.directive=void 0;var i=Object.create(null),c=Object.create(null),f=[i,c],l=function(e,t,n){var r=n.target,o=function(t){var o=t.el;if(o!==r&&!o.contains(r)){var u=t.binding;u.modifiers.stop&&n.stopPropagation(),u.modifiers.prevent&&n.preventDefault(),u.value.call(e,n)}};Object.keys(t).forEach(function(e){return t[e].forEach(o)})},a=function(e){l(this,i,e)},d=function(e){l(this,c,e)},p=function(e){return e?a:d},s=Object.defineProperties({},{$_captureInstances:{value:i},$_nonCaptureInstances:{value:c},$_onCaptureEvent:{value:a},$_onNonCaptureEvent:{value:d},bind:{value:function(e,t){if("function"!=typeof t.value)throw new TypeError("Binding value must be a function.");var n=t.arg||"click",u=o({},t,{arg:n,modifiers:o({},{capture:!1,prevent:!1,stop:!1},t.modifiers)}),f=u.modifiers.capture,l=f?i:c;Array.isArray(l[n])||(l[n]=[]),1===l[n].push({el:e,binding:u})&&"object"===("undefined"==typeof document?"undefined":r(document))&&document&&document.addEventListener(n,p(f),f)}},unbind:{value:function(e){var t=function(t){return t.el!==e};f.forEach(function(e){var n=Object.keys(e);if(n.length){var o=e===i;n.forEach(function(n){var u=e[n].filter(t);u.length?e[n]=u:("object"===("undefined"==typeof document?"undefined":r(document))&&document&&document.removeEventListener(n,p(o),o),delete e[n])})}})}},version:{enumerable:!0,value:"3.7.1"}});t.directive=s}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.vClickOutside=t():e.vClickOutside=t()}(function(){"use strict";return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:Function("return this")()}(),function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){u(e,t,n[t])})}return e}function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}Object.defineProperty(t,"__esModule",{value:!0}),t.install=function(e){e.directive("click-outside",s)},t.directive=void 0;var i=Object.create(null),c=Object.create(null),f=Object.create(null),l=Object.create(null),a=[i,c],d=function(e,t,n,r){var o=n.target;t[r].forEach(function(t){var r=t.el;if(r!==o&&!r.contains(o)){var u=t.binding;u.modifiers.stop&&n.stopPropagation(),u.modifiers.prevent&&n.preventDefault(),u.value.call(e,n)}})},p=function(e,t){return e?f[t]?f[t]:(f[t]=function(e){d(this,i,e,t)},f[t]):l[t]?l[t]:(l[t]=function(e){d(this,c,e,t)},l[t])},s=Object.defineProperties({},{$_captureInstances:{value:i},$_nonCaptureInstances:{value:c},$_captureEventHandlers:{value:f},$_nonCaptureEventHandlers:{value:l},bind:{value:function(e,t){if("function"!=typeof t.value)throw new TypeError("Binding value must be a function.");var n=t.arg||"click",u=o({},t,{arg:n,modifiers:o({},{capture:!1,prevent:!1,stop:!1},t.modifiers)}),f=u.modifiers.capture,l=f?i:c;Array.isArray(l[n])||(l[n]=[]),1===l[n].push({el:e,binding:u})&&"object"===("undefined"==typeof document?"undefined":r(document))&&document&&document.addEventListener(n,p(f,n),f)}},unbind:{value:function(e){var t=function(t){return t.el!==e};a.forEach(function(e){var n=Object.keys(e);if(n.length){var o=e===i;n.forEach(function(n){var u=e[n].filter(t);u.length?e[n]=u:("object"===("undefined"==typeof document?"undefined":r(document))&&document&&document.removeEventListener(n,p(o,n),o),delete e[n])})}})}},version:{enumerable:!0,value:"4.0.0"}});t.directive=s}])});
//# sourceMappingURL=v-click-outside-x.min.js.map
{
"name": "v-click-outside-x",
"version": "3.7.1",
"version": "4.0.0",
"description": "Vue directive to react on clicks outside an element.",

@@ -50,8 +50,8 @@ "homepage": "https://github.com/Xotic750/v-click-outside-x.git",

"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/core": "^7.3.4",
"@babel/plugin-transform-property-mutators": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.2.3",
"@babel/runtime": "^7.2.0",
"@prorenata/eslint-config-vue": "^1.11.0",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/runtime": "^7.3.4",
"@prorenata/eslint-config-vue": "^1.12.0",
"babel-core": "^7.0.0-0",

@@ -61,17 +61,17 @@ "babel-eslint": "^10.0.1",

"cross-env": "^5.2.0",
"eslint": "^5.12.1",
"eslint": "^5.15.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.6.0",
"eslint-config-prettier": "^4.1.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-import-resolver-webpack": "^0.10.1",
"eslint-loader": "^2.1.1",
"eslint-import-resolver-webpack": "^0.11.0",
"eslint-loader": "^2.1.2",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-compat": "^2.6.3",
"eslint-plugin-compat": "^2.7.0",
"eslint-plugin-css-modules": "^2.11.0",
"eslint-plugin-eslint-comments": "^3.0.1",
"eslint-plugin-html": "^5.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^22.1.3",
"eslint-plugin-jsdoc": "^4.0.0",
"eslint-plugin-json": "^1.3.2",
"eslint-plugin-eslint-comments": "^3.1.1",
"eslint-plugin-html": "^5.0.3",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.3.0",
"eslint-plugin-jsdoc": "^4.1.1",
"eslint-plugin-json": "^1.4.0",
"eslint-plugin-lodash": "^5.1.0",

@@ -84,7 +84,7 @@ "eslint-plugin-no-use-extend-native": "^0.4.0",

"eslint-plugin-switch-case": "^1.1.2",
"eslint-plugin-vue": "^5.1.0",
"eslint-plugin-vue": "^5.2.2",
"friendly-errors-webpack-plugin": "^1.7.0",
"husky": "^1.3.1",
"jest": "^23.6.0",
"jest-cli": "^23.6.0",
"jest": "^24.1.0",
"jest-cli": "^24.1.0",
"jest-file": "^1.0.0",

@@ -94,6 +94,6 @@ "prettier": "^1.14.3",

"semver": "^5.6.0",
"terser-webpack-plugin": "^1.2.1",
"webpack": "^4.29.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^3.2.1",
"terser-webpack-plugin": "^1.2.3",
"webpack": "^4.29.6",
"webpack-bundle-analyzer": "^3.1.0",
"webpack-cli": "^3.2.3",
"webpack-merge": "^4.2.1"

@@ -100,0 +100,0 @@ },

const CLICK = 'click';
const captureInstances = Object.create(null);
const nonCaptureInstances = Object.create(null);
const captureEventHandlers = Object.create(null);
const nonCaptureEventHandlers = Object.create(null);
const instancesList = [captureInstances, nonCaptureInstances];

@@ -12,5 +14,6 @@

* @param {Event} event - The event object.
* @param {string} arg - The event type.
* @returns {undefined} Default.
*/
const commonHandler = function _onCommonEvent(context, instances, event) {
const commonHandler = function _onCommonEvent(context, instances, event, arg) {
const {target} = event;

@@ -36,30 +39,6 @@

const keysIteratee = function _keysIteratee(eventName) {
return instances[eventName].forEach(itemIteratee);
};
Object.keys(instances).forEach(keysIteratee);
instances[arg].forEach(itemIteratee);
};
/**
* Event handler for capture events.
*
* @param {Event} event - The event object.
*/
const captureEventHandler = function onCaptureEvent(event) {
/* eslint-disable-next-line babel/no-invalid-this */
commonHandler(this, captureInstances, event);
};
/**
* Event handler for non-capture events.
*
* @param {Event} event - The event object.
*/
const nonCaptureEventHandler = function onNonCaptureEvent(event) {
/* eslint-disable-next-line babel/no-invalid-this */
commonHandler(this, nonCaptureInstances, event);
};
/**
* Get the correct event handler: Capture or non-capture.

@@ -69,6 +48,37 @@ *

* capture handler or 'false' for non-capture.
* @param {string} arg - The event type.
* @returns {Function} - The event handler.
*/
const getEventHandler = function _getEventHandler(useCapture) {
return useCapture ? captureEventHandler : nonCaptureEventHandler;
const getEventHandler = function _getEventHandler(useCapture, arg) {
if (useCapture) {
if (captureEventHandlers[arg]) {
return captureEventHandlers[arg];
}
/**
* Event handler for capture events.
*
* @param {Event} event - The event object.
*/
captureEventHandlers[arg] = function onCaptureEvent(event) {
commonHandler(this, captureInstances, event, arg);
};
return captureEventHandlers[arg];
}
if (nonCaptureEventHandlers[arg]) {
return nonCaptureEventHandlers[arg];
}
/**
* Event handler for non-capture events.
*
* @param {Event} event - The event object.
*/
nonCaptureEventHandlers[arg] = function onNonCaptureEvent(event) {
commonHandler(this, nonCaptureInstances, event, arg);
};
return nonCaptureEventHandlers[arg];
};

@@ -102,8 +112,8 @@

$_onCaptureEvent: {
value: captureEventHandler,
$_captureEventHandlers: {
value: captureEventHandlers,
},
$_onNonCaptureEvent: {
value: nonCaptureEventHandler,
$_nonCaptureEventHandlers: {
value: nonCaptureEventHandlers,
},

@@ -144,3 +154,3 @@

arg,
getEventHandler(useCapture),
getEventHandler(useCapture, arg),
useCapture,

@@ -174,3 +184,3 @@ );

eventName,
getEventHandler(useCapture),
getEventHandler(useCapture, eventName),
useCapture,

@@ -195,3 +205,3 @@ );

enumerable: true,
value: '3.7.1',
value: '4.0.0',
},

@@ -198,0 +208,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc