@okyrychenko-dev/react-action-guard 0.2.0 → 0.2.1
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/README.md +33 -37
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,16 +20,12 @@ npm install @okyrychenko-dev/react-action-guard zustand
|
|
|
20
20
|
## Quick Start
|
|
21
21
|
|
|
22
22
|
```jsx
|
|
23
|
-
import { useBlocker, useIsBlocked } from
|
|
23
|
+
import { useBlocker, useIsBlocked } from "@okyrychenko-dev/react-action-guard";
|
|
24
24
|
|
|
25
25
|
function MyComponent() {
|
|
26
|
-
const isBlocked = useIsBlocked(
|
|
26
|
+
const isBlocked = useIsBlocked("my-scope");
|
|
27
27
|
|
|
28
|
-
return
|
|
29
|
-
<button disabled={isBlocked}>
|
|
30
|
-
Click me
|
|
31
|
-
</button>
|
|
32
|
-
);
|
|
28
|
+
return <button disabled={isBlocked}>Click me</button>;
|
|
33
29
|
}
|
|
34
30
|
```
|
|
35
31
|
|
|
@@ -42,6 +38,7 @@ function MyComponent() {
|
|
|
42
38
|
Automatically adds a blocker when the component mounts and removes it on unmount.
|
|
43
39
|
|
|
44
40
|
**Parameters:**
|
|
41
|
+
|
|
45
42
|
- `blockerId: string` - Unique identifier for the blocker
|
|
46
43
|
- `config: BlockerConfig` - Configuration object
|
|
47
44
|
- `scope?: string | string[]` - Scope(s) to block (default: "global")
|
|
@@ -53,10 +50,10 @@ Automatically adds a blocker when the component mounts and removes it on unmount
|
|
|
53
50
|
|
|
54
51
|
```jsx
|
|
55
52
|
function MyComponent() {
|
|
56
|
-
useBlocker(
|
|
57
|
-
scope:
|
|
58
|
-
reason:
|
|
59
|
-
priority: 10
|
|
53
|
+
useBlocker("my-blocker", {
|
|
54
|
+
scope: "form",
|
|
55
|
+
reason: "Form is saving",
|
|
56
|
+
priority: 10,
|
|
60
57
|
});
|
|
61
58
|
|
|
62
59
|
return <div>Content</div>;
|
|
@@ -68,6 +65,7 @@ function MyComponent() {
|
|
|
68
65
|
Checks if a specific scope (or scopes) is currently blocked.
|
|
69
66
|
|
|
70
67
|
**Parameters:**
|
|
68
|
+
|
|
71
69
|
- `scope?: string | string[]` - Scope(s) to check (default: "global")
|
|
72
70
|
|
|
73
71
|
**Returns:** `boolean` - Whether the scope is blocked
|
|
@@ -76,13 +74,9 @@ Checks if a specific scope (or scopes) is currently blocked.
|
|
|
76
74
|
|
|
77
75
|
```jsx
|
|
78
76
|
function SubmitButton() {
|
|
79
|
-
const isFormBlocked = useIsBlocked(
|
|
77
|
+
const isFormBlocked = useIsBlocked("form");
|
|
80
78
|
|
|
81
|
-
return
|
|
82
|
-
<button disabled={isFormBlocked}>
|
|
83
|
-
Submit
|
|
84
|
-
</button>
|
|
85
|
-
);
|
|
79
|
+
return <button disabled={isFormBlocked}>Submit</button>;
|
|
86
80
|
}
|
|
87
81
|
```
|
|
88
82
|
|
|
@@ -91,6 +85,7 @@ function SubmitButton() {
|
|
|
91
85
|
Wraps an async function with automatic blocking/unblocking.
|
|
92
86
|
|
|
93
87
|
**Parameters:**
|
|
88
|
+
|
|
94
89
|
- `actionId: string` - Identifier for the action
|
|
95
90
|
- `scope?: string | string[]` - Scope(s) to block during execution
|
|
96
91
|
|
|
@@ -100,7 +95,7 @@ Wraps an async function with automatic blocking/unblocking.
|
|
|
100
95
|
|
|
101
96
|
```jsx
|
|
102
97
|
function MyComponent() {
|
|
103
|
-
const executeWithBlocking = useAsyncAction(
|
|
98
|
+
const executeWithBlocking = useAsyncAction("save-data", "form");
|
|
104
99
|
|
|
105
100
|
const handleSave = async () => {
|
|
106
101
|
await executeWithBlocking(async () => {
|
|
@@ -119,6 +114,7 @@ function MyComponent() {
|
|
|
119
114
|
Direct access to the Zustand store for advanced use cases.
|
|
120
115
|
|
|
121
116
|
**Methods:**
|
|
117
|
+
|
|
122
118
|
- `addBlocker(id, config)` - Manually add a blocker
|
|
123
119
|
- `removeBlocker(id)` - Manually remove a blocker
|
|
124
120
|
- `isBlocked(scope)` - Check if scope is blocked
|
|
@@ -129,21 +125,21 @@ Direct access to the Zustand store for advanced use cases.
|
|
|
129
125
|
**Example:**
|
|
130
126
|
|
|
131
127
|
```jsx
|
|
132
|
-
import { useUIBlockingStore } from
|
|
128
|
+
import { useUIBlockingStore } from "@okyrychenko-dev/react-action-guard";
|
|
133
129
|
|
|
134
130
|
function AdvancedComponent() {
|
|
135
131
|
const { addBlocker, removeBlocker } = useUIBlockingStore();
|
|
136
132
|
|
|
137
133
|
const startBlocking = () => {
|
|
138
|
-
addBlocker(
|
|
139
|
-
scope: [
|
|
140
|
-
reason:
|
|
141
|
-
priority: 100
|
|
134
|
+
addBlocker("custom-blocker", {
|
|
135
|
+
scope: ["form", "navigation"],
|
|
136
|
+
reason: "Critical operation in progress",
|
|
137
|
+
priority: 100,
|
|
142
138
|
});
|
|
143
139
|
};
|
|
144
140
|
|
|
145
141
|
const stopBlocking = () => {
|
|
146
|
-
removeBlocker(
|
|
142
|
+
removeBlocker("custom-blocker");
|
|
147
143
|
};
|
|
148
144
|
|
|
149
145
|
return (
|
|
@@ -160,11 +156,7 @@ function AdvancedComponent() {
|
|
|
160
156
|
The package is written in TypeScript and includes full type definitions.
|
|
161
157
|
|
|
162
158
|
```typescript
|
|
163
|
-
import type {
|
|
164
|
-
BlockerConfig,
|
|
165
|
-
BlockerInfo,
|
|
166
|
-
UIBlockingState
|
|
167
|
-
} from '@okyrychenko-dev/react-action-guard';
|
|
159
|
+
import type { BlockerConfig, BlockerInfo, UIBlockingState } from "@okyrychenko-dev/react-action-guard";
|
|
168
160
|
```
|
|
169
161
|
|
|
170
162
|
## Use Cases
|
|
@@ -175,10 +167,14 @@ import type {
|
|
|
175
167
|
function DataLoader() {
|
|
176
168
|
const [isLoading, setIsLoading] = useState(false);
|
|
177
169
|
|
|
178
|
-
useBlocker(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
170
|
+
useBlocker(
|
|
171
|
+
"data-loader",
|
|
172
|
+
{
|
|
173
|
+
scope: "content",
|
|
174
|
+
reason: "Loading data",
|
|
175
|
+
},
|
|
176
|
+
isLoading
|
|
177
|
+
);
|
|
182
178
|
|
|
183
179
|
// ... rest of component
|
|
184
180
|
}
|
|
@@ -188,8 +184,8 @@ function DataLoader() {
|
|
|
188
184
|
|
|
189
185
|
```jsx
|
|
190
186
|
function UserForm() {
|
|
191
|
-
const executeWithBlocking = useAsyncAction(
|
|
192
|
-
const isBlocked = useIsBlocked(
|
|
187
|
+
const executeWithBlocking = useAsyncAction("submit-form", "form");
|
|
188
|
+
const isBlocked = useIsBlocked("form");
|
|
193
189
|
|
|
194
190
|
const handleSubmit = async (data) => {
|
|
195
191
|
await executeWithBlocking(async () => {
|
|
@@ -210,7 +206,7 @@ function UserForm() {
|
|
|
210
206
|
|
|
211
207
|
```jsx
|
|
212
208
|
function App() {
|
|
213
|
-
const isGloballyBlocked = useIsBlocked(
|
|
209
|
+
const isGloballyBlocked = useIsBlocked("global");
|
|
214
210
|
|
|
215
211
|
return (
|
|
216
212
|
<div>
|
|
@@ -239,4 +235,4 @@ npm run dev
|
|
|
239
235
|
|
|
240
236
|
## License
|
|
241
237
|
|
|
242
|
-
MIT ©
|
|
238
|
+
MIT © Olexii Kyrychenko
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okyrychenko-dev/react-action-guard",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Elegant UI blocking management for React applications with priorities, scopes, and automatic cleanup",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"loading",
|
|
45
45
|
"async-operations"
|
|
46
46
|
],
|
|
47
|
-
"author": "
|
|
47
|
+
"author": "Olexii Kyrychenko alexey.kirichenko@gmail.com",
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"repository": {
|
|
50
50
|
"type": "git",
|