react-hook-popup
Advanced tools
Comparing version 0.0.5-alpha.1 to 0.0.5-alpha.2
@@ -1,7 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.usePopup = exports.PopupProvider = void 0; | ||
var PopupProvider_1 = require("./PopupProvider"); | ||
Object.defineProperty(exports, "PopupProvider", { enumerable: true, get: function () { return PopupProvider_1.PopupProvider; } }); | ||
var usePopup_1 = require("./usePopup"); | ||
Object.defineProperty(exports, "usePopup", { enumerable: true, get: function () { return usePopup_1.usePopup; } }); | ||
export {PopupProvider} from "./PopupProvider.js"; | ||
export {usePopup} from "./hooks/usePopup.js"; |
@@ -1,18 +0,16 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PopupContext = void 0; | ||
var react_1 = require("react"); | ||
exports.PopupContext = react_1.createContext({ | ||
registerPopup: function () { | ||
throw new Error('Something has gone wrong'); | ||
}, | ||
unRegisterPopup: function () { | ||
throw new Error('Something has gone wrong'); | ||
}, | ||
displayPopup: function () { | ||
throw new Error('Something has gone wrong'); | ||
}, | ||
closePopup: function () { | ||
throw new Error('Something has gone wrong'); | ||
}, | ||
import {createContext} from "./web_modules/react.js"; | ||
import {consts as consts2} from "./utils/consts.js"; | ||
export const PopupContext = createContext({ | ||
registerPopup: () => { | ||
throw new Error(consts2.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
unRegisterPopup: () => { | ||
throw new Error(consts2.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
displayPopup: () => { | ||
throw new Error(consts2.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
closePopup: () => { | ||
throw new Error(consts2.CONTEXT_ERROR_MESSAGE); | ||
} | ||
}); |
@@ -1,59 +0,38 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
import React, {useState} from "./web_modules/react.js"; | ||
import {PopupContext as PopupContext2} from "./PopupContext.js"; | ||
import { | ||
addPopup, | ||
removePopup, | ||
setPopupClosed, | ||
setPopupMessage, | ||
setPopupOpen | ||
} from "./utils/reducers.js"; | ||
export const PopupProvider = ({children}) => { | ||
const [popups, setPopups] = useState({}); | ||
const registerPopup = (key, popupRenderer) => { | ||
setPopups((previous) => addPopup(previous, key, popupRenderer)); | ||
}; | ||
const unRegisterPopup = (key) => { | ||
setPopups((previous) => removePopup(previous, key)); | ||
}; | ||
const displayPopup = (key, message) => { | ||
setPopups((previous) => setPopupOpen(previous, key)); | ||
setPopups((previous) => setPopupMessage(previous, key, message)); | ||
}; | ||
const closePopup = (key) => { | ||
setPopups((previous) => setPopupClosed(previous, key)); | ||
}; | ||
return /* @__PURE__ */ React.createElement(PopupContext2.Provider, { | ||
value: { | ||
registerPopup, | ||
unRegisterPopup, | ||
displayPopup, | ||
closePopup | ||
} | ||
}, children, Object.entries(popups).map(([key, popup]) => { | ||
return popup.open && React.cloneElement(popup.renderer?.({ | ||
message: popup.message, | ||
handleClose: () => closePopup(key) | ||
}), {key}); | ||
})); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PopupProvider = void 0; | ||
var react_1 = __importStar(require("react")); | ||
var PopupContext_1 = require("./PopupContext"); | ||
var reducers_1 = require("./utils/reducers"); | ||
var PopupProvider = function (_a) { | ||
var children = _a.children; | ||
var _b = react_1.useState({}), popups = _b[0], setPopups = _b[1]; | ||
var registerPopup = function (key, popupRenderer) { | ||
setPopups(function (previous) { return reducers_1.addPopup(previous, key, popupRenderer); }); | ||
}; | ||
var unRegisterPopup = function (key) { | ||
setPopups(function (previous) { return reducers_1.removePopup(previous, key); }); | ||
}; | ||
var displayPopup = function (key, message) { | ||
setPopups(function (previous) { return reducers_1.setPopupOpen(previous, key); }); | ||
setPopups(function (previous) { return reducers_1.setPopupMessage(previous, key, message); }); | ||
}; | ||
var closePopup = function (key) { | ||
setPopups(function (previous) { return reducers_1.setPopupClosed(previous, key); }); | ||
}; | ||
return (react_1.default.createElement(PopupContext_1.PopupContext.Provider, { value: { | ||
registerPopup: registerPopup, | ||
unRegisterPopup: unRegisterPopup, | ||
displayPopup: displayPopup, | ||
closePopup: closePopup, | ||
} }, | ||
children, | ||
Object.entries(popups).map(function (_a) { | ||
var _b; | ||
var key = _a[0], popup = _a[1]; | ||
return (popup.open && | ||
react_1.default.cloneElement((_b = popup.renderer) === null || _b === void 0 ? void 0 : _b.call(popup, { | ||
message: popup.message, | ||
handleClose: function () { return closePopup(key); }, | ||
}), { key: key })); | ||
}))); | ||
}; | ||
exports.PopupProvider = PopupProvider; |
@@ -1,67 +0,48 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setPopupMessage = exports.setPopupClosed = exports.setPopupOpen = exports.removePopup = exports.addPopup = void 0; | ||
var utils_1 = require("./utils"); | ||
function addPopup(popups, key, renderer) { | ||
var _a; | ||
if (popups[key]) { | ||
return popups; | ||
import {enforceExistingPopup} from "./utils.js"; | ||
export function addPopup(popups, key, renderer) { | ||
if (popups[key]) { | ||
return popups; | ||
} | ||
return { | ||
...popups, | ||
[key]: { | ||
renderer, | ||
open: false | ||
} | ||
return __assign(__assign({}, popups), (_a = {}, _a[key] = { | ||
renderer: renderer, | ||
open: false, | ||
}, _a)); | ||
}; | ||
} | ||
exports.addPopup = addPopup; | ||
function removePopup(popups, key) { | ||
if (!popups[key]) { | ||
return popups; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
var _a = popups, _b = key, _ = _a[_b], updatedPopups = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); | ||
return updatedPopups; | ||
export function removePopup(popups, key) { | ||
if (!popups[key]) { | ||
return popups; | ||
} | ||
const {[key]: _, ...updatedPopups} = popups; | ||
return updatedPopups; | ||
} | ||
exports.removePopup = removePopup; | ||
function togglePopupOpenState(popups, key, value) { | ||
var _a; | ||
utils_1.enforceExistingPopup(popups, key); | ||
return __assign(__assign({}, popups), (_a = {}, _a[key] = __assign(__assign({}, popups[key]), { open: value }), _a)); | ||
enforceExistingPopup(popups, key); | ||
return { | ||
...popups, | ||
[key]: { | ||
...popups[key], | ||
open: value | ||
} | ||
}; | ||
} | ||
function setPopupOpen(popups, key) { | ||
utils_1.enforceExistingPopup(popups, key); | ||
return togglePopupOpenState(popups, key, true); | ||
export function setPopupOpen(popups, key) { | ||
enforceExistingPopup(popups, key); | ||
return togglePopupOpenState(popups, key, true); | ||
} | ||
exports.setPopupOpen = setPopupOpen; | ||
function setPopupClosed(popups, key) { | ||
utils_1.enforceExistingPopup(popups, key); | ||
return togglePopupOpenState(popups, key, false); | ||
export function setPopupClosed(popups, key) { | ||
enforceExistingPopup(popups, key); | ||
return togglePopupOpenState(popups, key, false); | ||
} | ||
exports.setPopupClosed = setPopupClosed; | ||
function setPopupMessage(popups, key, message) { | ||
var _a; | ||
utils_1.enforceExistingPopup(popups, key); | ||
return __assign(__assign({}, popups), (_a = {}, _a[key] = __assign(__assign({}, popups[key]), { message: message }), _a)); | ||
export function setPopupMessage(popups, key, message) { | ||
enforceExistingPopup(popups, key); | ||
return { | ||
...popups, | ||
[key]: { | ||
...popups[key], | ||
message | ||
} | ||
}; | ||
} | ||
exports.setPopupMessage = setPopupMessage; |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.enforceExistingPopup = void 0; | ||
function enforceExistingPopup(popups, key) { | ||
if (!popups[key]) { | ||
throw new Error("Attempted to act on a non-existing popup with key: " + key); | ||
} | ||
import {consts as consts2} from "./consts.js"; | ||
export function enforceExistingPopup(popups, key) { | ||
if (!popups[key]) { | ||
throw new Error(consts2.UNFOUND_POPUP(key)); | ||
} | ||
} | ||
exports.enforceExistingPopup = enforceExistingPopup; |
{ | ||
"name": "react-hook-popup", | ||
"version": "0.0.5-alpha.1", | ||
"version": "0.0.5-alpha.2", | ||
"description": "Easily manage popups like alerts and modals in React with a single hook", | ||
@@ -9,7 +9,6 @@ "homepage": "https://github.com/aidanjw1/react-hook-popup#readme", | ||
"scripts": { | ||
"build": "tsc", | ||
"build:watch": "tsc --watch", | ||
"build:local-install": "npm run build && rm -r node_modules", | ||
"build:dry-run": "npm run build -- --noEmit", | ||
"test": "npm run build:dry-run && jest", | ||
"build": "snowpack build && npm run build-cleanup", | ||
"build-cleanup": "rm -r dist/web_modules && rm -r dist/sass && rm -r dist/__snowpack__", | ||
"typecheck": "tsc --noEmit", | ||
"test": "npm run typecheck && jest", | ||
"test:watch": "jest --watch" | ||
@@ -22,2 +21,3 @@ }, | ||
"devDependencies": { | ||
"@snowpack/plugin-sass": "^1.1.2", | ||
"@types/enzyme": "^3.10.8", | ||
@@ -37,2 +37,3 @@ "@types/enzyme-adapter-react-16": "^1.0.6", | ||
"react-dom": "^16.14.0", | ||
"snowpack": "^2.18.2", | ||
"ts-jest": "^26.4.4", | ||
@@ -39,0 +40,0 @@ "typescript": "^4.1.2" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9797
18
208
1