react-redactor 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -3
- package/package.json +4 -1
- package/src/main.js +35 -0
- package/src/Badge.js +0 -24
- package/src/Protect.js +0 -13
- package/src/useProtection.js +0 -22
package/index.js
CHANGED
package/package.json
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-redactor",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.7",
|
4
4
|
"description": "Redactor is a lightweight library for conditional rendering, context management, and navigation in React applications.",
|
5
5
|
"main": "index.jsx",
|
6
|
+
"type": "module",
|
6
7
|
"scripts": {
|
7
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
8
9
|
},
|
9
10
|
"keywords": [
|
10
11
|
"redactor",
|
12
|
+
"react-redactor",
|
11
13
|
"router",
|
12
14
|
"route-protector"
|
13
15
|
],
|
@@ -15,6 +17,7 @@
|
|
15
17
|
"license": "ISC",
|
16
18
|
"dependencies": {
|
17
19
|
"react": "^18.3.1",
|
20
|
+
"react-dom": "^18.3.1",
|
18
21
|
"react-router-dom": "^7.0.1"
|
19
22
|
}
|
20
23
|
}
|
package/src/main.js
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
import React, { createContext, useContext, useEffect } from "react";
|
2
|
+
import { useNavigate } from "react-router-dom";
|
3
|
+
|
4
|
+
const BadgeContext = createContext(null);
|
5
|
+
|
6
|
+
export function useBadge() {
|
7
|
+
return useContext(BadgeContext);
|
8
|
+
}
|
9
|
+
|
10
|
+
export function Provider({ children, validator }) {
|
11
|
+
const badgeValue = validator();
|
12
|
+
|
13
|
+
return (
|
14
|
+
<BadgeContext.Provider value={badgeValue}>
|
15
|
+
{children}
|
16
|
+
</BadgeContext.Provider>
|
17
|
+
);
|
18
|
+
}
|
19
|
+
|
20
|
+
export function Protect({ Proceed, Return, Badge }) {
|
21
|
+
return Badge ? <Proceed /> : <Return />;
|
22
|
+
}
|
23
|
+
|
24
|
+
export function useProtection(goto_url, returnto_url) {
|
25
|
+
const navigate = useNavigate();
|
26
|
+
const badge = useBadge();
|
27
|
+
|
28
|
+
useEffect(() => {
|
29
|
+
if (badge) {
|
30
|
+
navigate(goto_url);
|
31
|
+
} else {
|
32
|
+
navigate(returnto_url);
|
33
|
+
}
|
34
|
+
}, [badge, goto_url, returnto_url, navigate]);
|
35
|
+
}
|
package/src/Badge.js
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import React, { createContext, useContext } from "react";
|
2
|
-
|
3
|
-
// Badge Context
|
4
|
-
const BadgeContext = createContext(null);
|
5
|
-
|
6
|
-
/**
|
7
|
-
* `Badge` Hook
|
8
|
-
* Allows consumers to access the BadgeContext value.
|
9
|
-
* @returns {*} Context value
|
10
|
-
*/
|
11
|
-
export function useBadge() {
|
12
|
-
return useContext(BadgeContext);
|
13
|
-
}
|
14
|
-
|
15
|
-
/**
|
16
|
-
* `Provider` Component
|
17
|
-
* Wraps children with BadgeContext.Provider
|
18
|
-
* @param {Object} props
|
19
|
-
* @param {*} props.value - The value to pass to the context.
|
20
|
-
* @param {React.ReactNode} props.children - Components to render within the provider.
|
21
|
-
*/
|
22
|
-
export function BadgeProvider({ value, children }) {
|
23
|
-
return <BadgeContext.Provider value={value}>{children}</BadgeContext.Provider>;
|
24
|
-
}
|
package/src/Protect.js
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
import React from "react";
|
2
|
-
|
3
|
-
/**
|
4
|
-
* `Protect` Component
|
5
|
-
* Conditionally renders one of two components based on a badge value.
|
6
|
-
* @param {Object} props
|
7
|
-
* @param {React.ComponentType} props.Proceed - Component to render if badgeValue is true.
|
8
|
-
* @param {React.ComponentType} props.Return - Component to render if badgeValue is false.
|
9
|
-
* @param {boolean} props.badgeValue - Determines which component to render.
|
10
|
-
*/
|
11
|
-
export function Protect({ Proceed, Return, badgeValue }) {
|
12
|
-
return badgeValue ? <Proceed /> : <Return />;
|
13
|
-
}
|
package/src/useProtection.js
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
import { useEffect } from "react";
|
2
|
-
import { useNavigate } from "react-router-dom";
|
3
|
-
|
4
|
-
/**
|
5
|
-
* ;)
|
6
|
-
* `useProtection` Hook
|
7
|
-
* Redirects based on a validation function's result.
|
8
|
-
* @param {Function} validationFunc - A function that returns a boolean.
|
9
|
-
* @param {string} goto_url - URL to navigate to if the validation passes.
|
10
|
-
* @param {string} returnto_url - URL to navigate to if the validation fails.
|
11
|
-
*/
|
12
|
-
export function useProtection(validationFunc, goto_url, returnto_url) {
|
13
|
-
const navigate = useNavigate();
|
14
|
-
|
15
|
-
useEffect(() => {
|
16
|
-
if (validationFunc()) {
|
17
|
-
navigate(goto_url);
|
18
|
-
} else {
|
19
|
-
navigate(returnto_url);
|
20
|
-
}
|
21
|
-
}, [validationFunc, goto_url, returnto_url, navigate]);
|
22
|
-
}
|