Socket
Socket
Sign inDemoInstall

event-from

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.6.0 to 0.6.1

24

dist/event-from.cjs.development.js

@@ -6,4 +6,5 @@ 'use strict';

let recentEventFrom = 'key';
let recentFocusFrom = recentEventFrom;
let recentTouch = false;
let recentFocusFrom = recentEventFrom;
let recentMouse = false;
let recentWindowFocus = false;

@@ -35,2 +36,11 @@ // To determine if there was a recentTouch event

};
let recentMouseTimeoutId;
const setRecentEventFromMouse = () => {
recentMouse = true;
recentEventFrom = 'mouse';
window.clearTimeout(recentMouseTimeoutId);
recentMouseTimeoutId = window.setTimeout(() => {
recentMouse = false;
}, 200);
};
const handleTouchEvent = (touchDelay) => () => setRecentEventFromTouch(touchDelay);

@@ -40,3 +50,3 @@ const handlePointerEvent = (touchDelay) => (e) => {

case 'mouse':
recentEventFrom = 'mouse';
setRecentEventFromMouse();
break;

@@ -51,3 +61,3 @@ case 'pen':

if (!recentTouch) {
recentEventFrom = 'mouse';
setRecentEventFromMouse();
}

@@ -60,3 +70,3 @@ };

// set document focus event capture listener which sets recentFocusFrom equal to recentEventFrom
// except if there is a recent window focus event where the window is the target,
// except if there is a recent window focus event where the window is the target (unless there is also a recent mouse or touch event),
// in which case leave recentFocusFrom unchanged to maintain correct recentFocusFrom after switching apps/windows/tabs/etc,

@@ -77,3 +87,3 @@ // if/when the focus event is passed into eventFrom later in the cycle, just return recentFocusFrom.

const handleDocumentFocusEvent = () => {
if (!recentWindowFocus) {
if (!recentWindowFocus || recentMouse || recentTouch) {
recentFocusFrom = recentEventFrom;

@@ -134,3 +144,3 @@ }

case 'mouse':
recentEventFrom = 'mouse';
setRecentEventFromMouse();
break;

@@ -148,3 +158,3 @@ case 'pen':

if (/mouse/.test(event.type) && !recentTouch) {
recentEventFrom = 'mouse';
setRecentEventFromMouse();
}

@@ -151,0 +161,0 @@ if (/touch/.test(event.type)) {

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});let e,t="key",o=!1,u=t,s=!1;const n=u=>{o=!0,t="touch",window.clearTimeout(e),e=window.setTimeout((()=>{o=!1}),u)},c=e=>()=>n(e),r=e=>o=>{switch(o.pointerType){case"mouse":t="mouse";break;case"pen":case"touch":n(e)}},i=()=>{o||(t="mouse")},p=()=>{t="key"};let d;const a=e=>{e.target!==window&&e.target!==document||(s=!0,window.clearTimeout(d),d=window.setTimeout((()=>{s=!1}),300))},m={capture:!0,passive:!0},w=[["touchstart",c(750)],["touchend",c(300)],["touchcancel",c(300)],["pointerenter",r(300)],["pointerover",r(300)],["pointerout",r(300)],["pointerleave",r(300)],["pointerdown",r(750)],["pointerup",r(300)],["pointercancel",r(300)],["mouseenter",i],["mouseover",i],["mouseout",i],["mouseleave",i],["mousedown",i],["mouseup",i],["keydown",p],["keyup",p],["focus",()=>{s||(u=t)}]];"undefined"!=typeof window&&"undefined"!=typeof document&&(w.forEach((([e,t])=>{document.addEventListener(e,t,m)})),window.addEventListener("focus",a,m));exports.eventFrom=e=>{switch(e.pointerType){case"mouse":t="mouse";break;case"pen":case"touch":o?t="touch":n(300)}return/mouse/.test(e.type)&&!o&&(t="mouse"),/touch/.test(e.type)&&(o?t="touch":n(300)),/focus/.test(e.type)?u:t},exports.setEventFrom=e=>{"mouse"!==e&&"touch"!==e&&"key"!==e||(t=e,u=e)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});let e,t="key",o=t,n=!1,u=!1,s=!1;const c=o=>{n=!0,t="touch",window.clearTimeout(e),e=window.setTimeout((()=>{n=!1}),o)};let r;const i=()=>{u=!0,t="mouse",window.clearTimeout(r),r=window.setTimeout((()=>{u=!1}),200)},p=e=>()=>c(e),d=e=>t=>{switch(t.pointerType){case"mouse":i();break;case"pen":case"touch":c(e)}},a=()=>{n||i()},w=()=>{t="key"};let m;const h=e=>{e.target!==window&&e.target!==document||(s=!0,window.clearTimeout(m),m=window.setTimeout((()=>{s=!1}),300))},y={capture:!0,passive:!0},l=[["touchstart",p(750)],["touchend",p(300)],["touchcancel",p(300)],["pointerenter",d(300)],["pointerover",d(300)],["pointerout",d(300)],["pointerleave",d(300)],["pointerdown",d(750)],["pointerup",d(300)],["pointercancel",d(300)],["mouseenter",a],["mouseover",a],["mouseout",a],["mouseleave",a],["mousedown",a],["mouseup",a],["keydown",w],["keyup",w],["focus",()=>{(!s||u||n)&&(o=t)}]];"undefined"!=typeof window&&"undefined"!=typeof document&&(l.forEach((([e,t])=>{document.addEventListener(e,t,y)})),window.addEventListener("focus",h,y));exports.eventFrom=e=>{switch(e.pointerType){case"mouse":i();break;case"pen":case"touch":n?t="touch":c(300)}return/mouse/.test(e.type)&&!n&&i(),/touch/.test(e.type)&&(n?t="touch":c(300)),/focus/.test(e.type)?o:t},exports.setEventFrom=e=>{"mouse"!==e&&"touch"!==e&&"key"!==e||(t=e,o=e)};
//# sourceMappingURL=event-from.cjs.production.js.map
let recentEventFrom = 'key';
let recentFocusFrom = recentEventFrom;
let recentTouch = false;
let recentFocusFrom = recentEventFrom;
let recentMouse = false;
let recentWindowFocus = false;

@@ -30,2 +31,11 @@ // To determine if there was a recentTouch event

};
let recentMouseTimeoutId;
const setRecentEventFromMouse = () => {
recentMouse = true;
recentEventFrom = 'mouse';
window.clearTimeout(recentMouseTimeoutId);
recentMouseTimeoutId = window.setTimeout(() => {
recentMouse = false;
}, 200);
};
const handleTouchEvent = (touchDelay) => () => setRecentEventFromTouch(touchDelay);

@@ -35,3 +45,3 @@ const handlePointerEvent = (touchDelay) => (e) => {

case 'mouse':
recentEventFrom = 'mouse';
setRecentEventFromMouse();
break;

@@ -46,3 +56,3 @@ case 'pen':

if (!recentTouch) {
recentEventFrom = 'mouse';
setRecentEventFromMouse();
}

@@ -55,3 +65,3 @@ };

// set document focus event capture listener which sets recentFocusFrom equal to recentEventFrom
// except if there is a recent window focus event where the window is the target,
// except if there is a recent window focus event where the window is the target (unless there is also a recent mouse or touch event),
// in which case leave recentFocusFrom unchanged to maintain correct recentFocusFrom after switching apps/windows/tabs/etc,

@@ -72,3 +82,3 @@ // if/when the focus event is passed into eventFrom later in the cycle, just return recentFocusFrom.

const handleDocumentFocusEvent = () => {
if (!recentWindowFocus) {
if (!recentWindowFocus || recentMouse || recentTouch) {
recentFocusFrom = recentEventFrom;

@@ -129,3 +139,3 @@ }

case 'mouse':
recentEventFrom = 'mouse';
setRecentEventFromMouse();
break;

@@ -143,3 +153,3 @@ case 'pen':

if (/mouse/.test(event.type) && !recentTouch) {
recentEventFrom = 'mouse';
setRecentEventFromMouse();
}

@@ -146,0 +156,0 @@ if (/touch/.test(event.type)) {

{
"name": "event-from",
"version": "0.6.0",
"version": "0.6.1",
"description": "Determine if an event was caused by mouse, touch or key input.",

@@ -5,0 +5,0 @@ "main": "dist/event-from.cjs.js",

@@ -112,6 +112,6 @@ # Event From

// some where in your code where you want to call focus on the element
// somewhere in your code where you want to call focus on the element
// and have it be treated as an event from 'key' input
// now the call to eventFrom(e) in handleFocusEvent will return 'key'
setEventFrom('key');
// now the call to eventFrom(e) in handleFocusEvent will return 'key'
element.focus();

@@ -118,0 +118,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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc