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

@thanhnn/react-chrome-extension-helper

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thanhnn/react-chrome-extension-helper - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

25

dist/react-chrome-extension-helper.cjs.development.js

@@ -6,3 +6,3 @@ 'use strict';

var client = require('react-dom/client');
require('react');
var react = require('react');

@@ -157,2 +157,24 @@ function _extends() {

var useRemoveReact = function useRemoveReact(id, options) {
var _ref = options || {},
_ref$keyCode = _ref.keyCode,
keyCode = _ref$keyCode === void 0 ? 'Escape' : _ref$keyCode;
var handleKeyDown = react.useCallback(function (event) {
if (event.key === keyCode) {
removeReact(id);
}
}, [id, keyCode]);
react.useEffect(function () {
window.addEventListener('keydown', handleKeyDown);
return function () {
window.removeEventListener('keydown', handleKeyDown);
};
}, [handleKeyDown]);
return {
onClose: function onClose() {
return removeReact(id);
}
};
};
exports.addContextMenu = addContextMenu;

@@ -167,2 +189,3 @@ exports.getId = getId;

exports.setupContextMenuListener = setupContextMenuListener;
exports.useRemoveReact = useRemoveReact;
//# sourceMappingURL=react-chrome-extension-helper.cjs.development.js.map

2

dist/react-chrome-extension-helper.cjs.production.min.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react-dom/client");function t(){return(t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(null,arguments)}require("react");var n=function(e,n,r){chrome.contextMenus.create(t({id:e,title:n},r))},r=function(e){return"chrome-extension-app__"+e},o=function(e){var n=e.reduce((function(e,n){var r;return t({},e,((r={})[n.action]=n.callback,r))}),{});chrome.runtime.onMessage.addListener((function(e,t,r){var o=n[e.type];o&&o({data:e.data,sendResponse:r})}))},a=function(){chrome.contextMenus.onClicked.addListener((function(e,t){var n=null==t?void 0:t.id;n&&chrome.tabs.sendMessage(n,{type:e.menuItemId,data:e})}))};exports.addContextMenu=n,exports.getId=r,exports.injectReact=function(t){var n=t.id,o=t.component,a=t.css,c=t.cssString,s=t.fontUrl,i=r(n),d=document.getElementById(i)||document.createElement("div");d.id=i,document.documentElement.appendChild(d);var u=d.attachShadow({mode:"open"}),l=document.createElement("html");if(a){var m=r(n+"-css");if(document.getElementById(m))return;var p=document.createElement("link");p.id=m,p.rel="stylesheet",p.type="text/css",p.href=chrome.runtime.getURL("css/main.css"),p.media="all";var h=document.createElement("head");h.appendChild(p),l.appendChild(h)}var f=document.createElement("body");if(l.appendChild(f),c){var v=document.createElement("style");v.textContent=c,u.appendChild(v)}if(s){var g=document.createElement("link");g.rel="preconnect",g.href="https://fonts.googleapis.com",u.appendChild(g);var x=document.createElement("link");x.rel="preconnect",x.href="https://fonts.gstatic.com",x.crossOrigin="anonymous",u.appendChild(x);var y=document.createElement("link");y.rel="stylesheet",y.href=s,u.appendChild(y)}u.appendChild(l),e.createRoot(f).render(o)},exports.removeReact=function(e){var t=r(e),n=document.getElementById(t);n&&n.remove()},exports.sendChromeMessage=function(e){var n=e.type,r=e.data,o=e.callback;chrome.tabs&&chrome.tabs.query(t({active:!0,currentWindow:!0},e.query),(function(e){var t;chrome.tabs.sendMessage(null!=(t=e[0].id)?t:0,{type:n,data:r},(function(t){return null==o?void 0:o(e,t)}))}))},exports.setUpContentExtension=function(e){o(e)},exports.setupBackgroundExtension=function(e){null==e||e.forEach((function(e){n(e.id,e.title,e.options)})),a()},exports.setupChromeMessageListener=o,exports.setupContextMenuListener=a;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react-dom/client"),t=require("react");function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(null,arguments)}var r=function(e,t,r){chrome.contextMenus.create(n({id:e,title:t},r))},o=function(e){return"chrome-extension-app__"+e},c=function(e){var t=o(e),n=document.getElementById(t);n&&n.remove()},a=function(e){var t=e.reduce((function(e,t){var r;return n({},e,((r={})[t.action]=t.callback,r))}),{});chrome.runtime.onMessage.addListener((function(e,n,r){var o=t[e.type];o&&o({data:e.data,sendResponse:r})}))},i=function(){chrome.contextMenus.onClicked.addListener((function(e,t){var n=null==t?void 0:t.id;n&&chrome.tabs.sendMessage(n,{type:e.menuItemId,data:e})}))};exports.addContextMenu=r,exports.getId=o,exports.injectReact=function(t){var n=t.id,r=t.component,c=t.css,a=t.cssString,i=t.fontUrl,s=o(n),d=document.getElementById(s)||document.createElement("div");d.id=s,document.documentElement.appendChild(d);var u=d.attachShadow({mode:"open"}),l=document.createElement("html");if(c){var m=o(n+"-css");if(document.getElementById(m))return;var p=document.createElement("link");p.id=m,p.rel="stylesheet",p.type="text/css",p.href=chrome.runtime.getURL("css/main.css"),p.media="all";var f=document.createElement("head");f.appendChild(p),l.appendChild(f)}var h=document.createElement("body");if(l.appendChild(h),a){var v=document.createElement("style");v.textContent=a,u.appendChild(v)}if(i){var y=document.createElement("link");y.rel="preconnect",y.href="https://fonts.googleapis.com",u.appendChild(y);var x=document.createElement("link");x.rel="preconnect",x.href="https://fonts.gstatic.com",x.crossOrigin="anonymous",u.appendChild(x);var E=document.createElement("link");E.rel="stylesheet",E.href=i,u.appendChild(E)}u.appendChild(l),e.createRoot(h).render(r)},exports.removeReact=c,exports.sendChromeMessage=function(e){var t=e.type,r=e.data,o=e.callback;chrome.tabs&&chrome.tabs.query(n({active:!0,currentWindow:!0},e.query),(function(e){var n;chrome.tabs.sendMessage(null!=(n=e[0].id)?n:0,{type:t,data:r},(function(t){return null==o?void 0:o(e,t)}))}))},exports.setUpContentExtension=function(e){a(e)},exports.setupBackgroundExtension=function(e){null==e||e.forEach((function(e){r(e.id,e.title,e.options)})),i()},exports.setupChromeMessageListener=a,exports.setupContextMenuListener=i,exports.useRemoveReact=function(e,n){var r=(n||{}).keyCode,o=void 0===r?"Escape":r,a=t.useCallback((function(t){t.key===o&&c(e)}),[e,o]);return t.useEffect((function(){return window.addEventListener("keydown",a),function(){window.removeEventListener("keydown",a)}}),[a]),{onClose:function(){return c(e)}}};
//# sourceMappingURL=react-chrome-extension-helper.cjs.production.min.js.map
import { createRoot } from 'react-dom/client';
import 'react';
import { useCallback, useEffect } from 'react';

@@ -152,3 +152,25 @@ function _extends() {

export { addContextMenu, getId, injectReact, removeReact, sendChromeMessage, setUpContentExtension, setupBackgroundExtension, setupChromeMessageListener, setupContextMenuListener };
var useRemoveReact = function useRemoveReact(id, options) {
var _ref = options || {},
_ref$keyCode = _ref.keyCode,
keyCode = _ref$keyCode === void 0 ? 'Escape' : _ref$keyCode;
var handleKeyDown = useCallback(function (event) {
if (event.key === keyCode) {
removeReact(id);
}
}, [id, keyCode]);
useEffect(function () {
window.addEventListener('keydown', handleKeyDown);
return function () {
window.removeEventListener('keydown', handleKeyDown);
};
}, [handleKeyDown]);
return {
onClose: function onClose() {
return removeReact(id);
}
};
};
export { addContextMenu, getId, injectReact, removeReact, sendChromeMessage, setUpContentExtension, setupBackgroundExtension, setupChromeMessageListener, setupContextMenuListener, useRemoveReact };
//# sourceMappingURL=react-chrome-extension-helper.esm.js.map
import { ChromeActionConfig, ChromeContextMenuConfig } from './type';
export declare const setupBackgroundExtension: (contextMenus: ChromeContextMenuConfig[]) => void;
export declare const setUpContentExtension: (actions: ChromeActionConfig[]) => void;
export declare const setupBackgroundExtension: (contextMenus: ChromeContextMenuConfig) => void;
export declare const setUpContentExtension: (actions: ChromeActionConfig) => void;
import { ChromeActionConfig } from './type';
export declare const setupChromeMessageListener: (actions: ChromeActionConfig[]) => void;
export declare const setupChromeMessageListener: (actions: ChromeActionConfig) => void;
export declare const setupContextMenuListener: () => void;

@@ -6,10 +6,10 @@ /// <reference types="chrome" />

};
export interface ChromeActionConfig {
export declare type ChromeActionConfig = {
action: string;
callback: (data: unknown, sendResponse: (response: unknown) => void) => void;
}
export interface ChromeContextMenuConfig {
callback: <D, R>(data: D, sendResponse: (response: R) => void) => void;
}[];
export declare type ChromeContextMenuConfig = {
id: string;
title: string;
options?: chrome.contextMenus.CreateProperties;
}
}[];

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

declare const useRemoveReact: (id: string, options?: {
export declare const useRemoveReact: (id: string, options?: {
keyCode?: string | undefined;

@@ -6,2 +6,1 @@ } | undefined) => {

};
export default useRemoveReact;
{
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -9,3 +9,3 @@ import { ChromeActionConfig, ChromeContextMenuConfig } from './type';

export const setupBackgroundExtension = (
contextMenus: ChromeContextMenuConfig[]
contextMenus: ChromeContextMenuConfig
) => {

@@ -19,4 +19,4 @@ // Register context menus

export const setUpContentExtension = (actions: ChromeActionConfig[]) => {
export const setUpContentExtension = (actions: ChromeActionConfig) => {
setupChromeMessageListener(actions);
};
import { ChromeActionConfig, ChromeMessage } from './type';
export const setupChromeMessageListener = (actions: ChromeActionConfig[]) => {
export const setupChromeMessageListener = (actions: ChromeActionConfig) => {
const configObj = actions.reduce(

@@ -5,0 +5,0 @@ (prev, cur) => ({ ...prev, [cur.action]: cur.callback }),

@@ -6,11 +6,11 @@ export type ChromeMessage<T> = {

export interface ChromeActionConfig {
export type ChromeActionConfig = {
action: string;
callback: (data: unknown, sendResponse: (response: unknown) => void) => void;
}
callback: <D, R>(data: D, sendResponse: (response: R) => void) => void;
}[];
export interface ChromeContextMenuConfig {
export type ChromeContextMenuConfig = {
id: string;
title: string;
options?: chrome.contextMenus.CreateProperties;
}
}[];
import { useCallback, useEffect } from 'react';
import { removeReact } from './remove-react';
const useRemoveReact = (id: string, options?: { keyCode?: string }) => {
export const useRemoveReact = (id: string, options?: { keyCode?: string }) => {
const { keyCode = 'Escape' } = options || {};

@@ -25,3 +25,1 @@

};
export default useRemoveReact;

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