Socket
Socket
Sign inDemoInstall

react-useportal

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-useportal - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

35

dist/usePortal.js

@@ -57,3 +57,3 @@ "use strict";

}, [isServer, bindTo]);
var useCustomEventCallback = function (cb, deps) { return react_1.useCallback(function (e) {
var customEvent = react_1.useCallback(function (e) {
var event = e || {};

@@ -65,12 +65,5 @@ if (event.persist)

event.event = e;
cb(event);
}, deps); };
var handleEvent = react_1.useCallback(function (func, event) {
if (!func || isServer)
return;
if (event && event.currentTarget && event.currentTarget !== document)
targetEl.current = event.currentTarget;
// i.e. onClick, etc. inside usePortal({ onClick({ portal, targetEl }) {} })
func(event);
}, [portal, targetEl]);
return event;
}, []);
var useCustomEventCallback = function (cb, deps) { return react_1.useCallback(function (e) { return cb(customEvent(event)); }, deps); };
// this should handle all eventHandlers like onClick, onMouseOver, etc. passed into the config

@@ -81,3 +74,7 @@ var customEventHandlers = Object

var handlerName = _a[0], eventHandler = _a[1];
acc[handlerName] = function (event) { return handleEvent(eventHandler, event); };
acc[handlerName] = function (event) {
if (isServer)
return;
eventHandler(customEvent(event));
};
return acc;

@@ -100,5 +97,5 @@ }, {});

if (onOpen)
handleEvent(onOpen, event);
onOpen(event);
setOpen(true);
}, [isServer, portal, setOpen, handleEvent, targetEl, onOpen]);
}, [isServer, portal, setOpen, targetEl, onOpen]);
var closePortal = useCustomEventCallback(function (event) {

@@ -108,6 +105,6 @@ if (isServer)

if (onClose && open.current)
handleEvent(onClose, event);
onClose(event);
if (open.current)
setOpen(false);
}, [isServer, handleEvent, onClose, setOpen]);
}, [isServer, onClose, setOpen]);
var togglePortal = react_1.useCallback(function (e) {

@@ -126,7 +123,7 @@ return open.current ? closePortal(e) : openPortal(e);

}, [isServer, closePortal, closeOnOutsideClick, portal]);
var handleMouseDown = react_1.useCallback(function (e) {
var handleMouseDown = useCustomEventCallback(function (e) {
if (isServer || !(portal.current instanceof HTMLElement))
return;
if (portal.current.contains(e.target) && onPortalClick)
handleEvent(onPortalClick, e);
onPortalClick(e);
handleOutsideMouseClick(e);

@@ -155,3 +152,3 @@ }, [handleOutsideMouseClick]);

return;
eventListeners.current[handlerName] = function (e) { return handleEvent(eventHandlers[handlerName], e); };
eventListeners.current[handlerName] = function (e) { return eventHandlers[handlerName](e); };
document.addEventListener(eventListenerName, eventListeners.current[handlerName]);

@@ -158,0 +155,0 @@ });

{
"name": "react-useportal",
"version": "1.0.8",
"version": "1.0.9",
"homepage": "https://codesandbox.io/s/w6jp7z4pkk",

@@ -5,0 +5,0 @@ "main": "dist/usePortal.js",

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