New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@atomico/hooks

Package Overview
Dependencies
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atomico/hooks - npm Package Compare versions

Comparing version 3.7.1 to 3.8.0

src/use-copy.js

4

package.json
{
"name": "@atomico/hooks",
"description": "Series of utilities in hooks format to extend the operation of Atomico",
"version": "3.7.1",
"version": "3.8.0",
"type": "module",

@@ -10,4 +10,6 @@ "exports": {

"./use-child-nodes": "./src/use-child-nodes.js",
"./use-copy": "./src/use-copy.js",
"./use-css-light-dom": "./src/use-css-light-dom.js",
"./use-debounce-state": "./src/use-debounce-state.js",
"./use-drag": "./src/use-drag.js",
"./use-force-render": "./src/use-force-render.js",

@@ -14,0 +16,0 @@ "./use-mutation-observer": "./src/use-mutation-observer.js",

@@ -10,3 +10,3 @@ import { useState, useEffect } from "atomico";

/**
*
* allows you to listen to only one route
* @param {import("./use-router/matches").Routes} routes

@@ -43,3 +43,3 @@ */

/**
*
* allows you to listen to only one route
* @param {string} path

@@ -74,2 +74,32 @@ * @param {import("./use-router/matches").RouterCallback} callback

/**
* Capture the click events of a reference to find
* if a node declares href to associate redirection
* @param {import("atomico").Ref<Element>} ref
* @param {(path:string)=>string} [proxy] allows to change the redirect url
*/
export function useRedirect(ref, proxy) {
useEffect(() => {
const { current } = ref;
const handler = (ev) => {
let { target } = ev;
do {
if (
target.hasAttribute &&
target.hasAttribute("href") &&
!target.hasAttribute("ignore")
) {
ev.preventDefault();
const href = target.getAttribute("href");
if (!/^(http(s){0,1}:){0,1}\/\//.test(href))
redirect(proxy ? proxy(href) : href);
break;
}
} while ((target = target.parentNode));
};
current.addEventListener("click", handler);
return () => current.removeEventListener("click", handler);
}, [ref]);
}
/**
* @typedef {Object} InternalState

@@ -76,0 +106,0 @@ * @property {string} [path]

/**
*
* allows you to listen to only one route
* @param {import("./use-router/matches").Routes} routes

@@ -7,3 +7,3 @@ */

/**
*
* allows you to listen to only one route
* @param {string} path

@@ -29,2 +29,9 @@ * @param {import("./use-router/matches").RouterCallback} callback

export function useRouteMatch(): (path: string) => import("@uppercod/exp-route").Match;
/**
* Capture the click events of a reference to find
* if a node declares href to associate redirection
* @param {import("atomico").Ref<Element>} ref
* @param {(path:string)=>string} [proxy] allows to change the redirect url
*/
export function useRedirect(ref: import("atomico").Ref<Element>, proxy?: (path: string) => string): void;
export type InternalState = {

@@ -31,0 +38,0 @@ path?: string;

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