@rokku-x/react-hook-dialog 0.0.1 → 0.0.2
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 +0 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +70 -269
- package/package.json +27 -14
package/README.md
CHANGED
|
@@ -9,7 +9,6 @@ A powerful and flexible React dialog hook library for confirmation dialogs, aler
|
|
|
9
9
|
- 🧩 **Modular Components** - Composed from reusable Backdrop and DialogWindow components
|
|
10
10
|
- 📝 **Dialog Actions** - Flexible action button system with left/right positioning
|
|
11
11
|
- 💅 **Full Customization** - Injectable className and styles at every level
|
|
12
|
-
- 🧮 **Zustand State** - Centralized state management with Zustand
|
|
13
12
|
- ⌨️ **Rich Configuration** - Default configs with per-call overrides
|
|
14
13
|
- 🎁 **Zero Dependencies** - Only requires React, Zustand, and @rokku-x/react-hook-modal
|
|
15
14
|
- 📱 **TypeScript Support** - Full type safety out of the box
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@rokku-x/react-hook-modal"),k=require("react"),l=require("react/jsx-runtime"),$=require("zustand"),w={primary:{backgroundColor:"#2563eb",color:"#fff"},secondary:{backgroundColor:"#e5e7eb",color:"#111"},danger:{backgroundColor:"#dc2626",color:"#fff"},success:{backgroundColor:"#16a34a",color:"#fff"},warning:{backgroundColor:"#f59e0b",color:"#111"},info:{backgroundColor:"#0ea5e9",color:"#fff"},neutral:{backgroundColor:"#6b7280",color:"#fff"}};function R({modalWindowId:s,handleAction:y,handleClose:a,config:n}){const{actions:r=[],title:i,content:m,backdropCancel:h,showCloseButton:v,classNames:o={},styles:e={},variantStyles:c={}}=n,d=(r.length?r:[[{title:"OK",variant:"primary"}]]).filter(g=>g&&g.length),u={...w,...c},p=()=>{h===!0&&a(s)};return l.jsx(b.ModalBackdrop,{onClick:p,className:o.backdrop||"",style:e.backdrop,children:l.jsxs(b.ModalWindow,{className:o.dialog||"",style:e.dialog,children:[v&&l.jsx("button",{type:"button",className:`hook-dialog-close-button ${o.closeButton||""}`,"aria-label":"Close",onClick:()=>a(s),style:{position:"absolute",top:0,right:0,transform:"translate(75%, -75%)",width:32,height:32,background:"none",border:"none",fontSize:21,cursor:"pointer",lineHeight:1,color:"#555",...e.closeButton},children:"×"}),i&&l.jsx("h3",{className:`hook-dialog-title ${o.title||""}`,style:{margin:"0 0 15px",fontSize:20,...e.title},children:i}),m&&l.jsx("div",{className:`hook-dialog-content ${o.content||""}`,style:{marginBottom:15,color:"#555",...e.content},children:m}),l.jsx("div",{className:`hook-dialog-actions ${o.actions||""}`,style:{display:"flex",flexDirection:"column",gap:10,...e.actions},children:d.map((g,x)=>{const j=g.filter(t=>t.isOnLeft),N=g.filter(t=>!t.isOnLeft),C=(t,f)=>{const S=t.variant||"secondary",M=u[S]||u.secondary;return l.jsx("button",{type:"button",className:`hook-dialog-action-button hook-dialog-action-${t.variant||"secondary"} ${o.actionButton||""} ${t.className||""}`,onClick:B=>{t.onClick?.(B,t),y(s,t)},style:{border:"none",borderRadius:15,padding:"10px 18px",fontSize:14,fontWeight:800,cursor:"pointer",...M,...e.actionButton,...t.style||{}},children:t.title},`${t.title}-${f}`)};return l.jsxs("div",{className:`hook-dialog-actions-row ${o.actionsRow||""}`,style:{display:"flex",gap:8,justifyContent:"space-between",marginTop:10,...e.actionsRow},children:[l.jsx("div",{className:"hook-dialog-actions-left",style:{display:"flex",gap:8},children:j.map((t,f)=>C(t,f))}),l.jsx("div",{className:"hook-dialog-actions-right",style:{display:"flex",gap:8},children:N.map((t,f)=>C(t,f))})]},x)})})]})})}const I=$.create((s,y)=>({instances:[],addInstance:a=>s(n=>({instances:[...n.instances,a]})),removeInstance:a=>s(n=>({instances:n.instances.filter(r=>r.id!==a)})),getInstance:a=>y().instances.find(n=>n.id===a)}));function O(s){const{instances:y,addInstance:a,removeInstance:n,getInstance:r}=I(),i=b.useBaseModal(),m=k.useCallback(o=>{const e=r(o);e&&(i.popModal(o),e.config.rejectOnCancel!==!1?e.reject(e.config.defaultCancelValue):e.resolve(e.config.defaultCancelValue),n(o))},[r,n,i]),h=k.useCallback((o,e)=>{const c=r(o);c&&(i.popModal(o),e.isCancel&&c.config.rejectOnCancel!==!1?c.reject(e.value):c.resolve(e.value),n(o))},[r,n,i]);return[o=>new Promise((e,c)=>{const d=Math.random().toString(36).substring(2,6),u={...s,...o,classNames:{...s?.classNames,...o.classNames},styles:{...s?.styles,...o.styles},variantStyles:{...s?.variantStyles,...o.variantStyles}},p={id:d,config:u,resolve:e,reject:c};a(p),p.id=i.pushModal(d,k.createElement(R,{config:u,modalWindowId:d,handleClose:m,handleAction:h}))})]}Object.defineProperty(exports,"BaseModalRenderer",{enumerable:!0,get:()=>b.BaseModalRenderer});exports.useHookDialog=O;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,187 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const a = typeof c == "function" ? c(o) : c;
|
|
9
|
-
if (!Object.is(a, o)) {
|
|
10
|
-
const r = o;
|
|
11
|
-
o = y ?? (typeof a != "object" || a === null) ? a : Object.assign({}, o, a), e.forEach((u) => u(o, r));
|
|
12
|
-
}
|
|
13
|
-
}, l = () => o, s = { setState: n, getState: l, getInitialState: () => p, subscribe: (c) => (e.add(c), () => e.delete(c)) }, p = o = t(n, l, s);
|
|
14
|
-
return s;
|
|
15
|
-
}, z = ((t) => t ? j(t) : j), V = (t) => t;
|
|
16
|
-
function U(t, o = V) {
|
|
17
|
-
const e = k.useSyncExternalStore(
|
|
18
|
-
t.subscribe,
|
|
19
|
-
k.useCallback(() => o(t.getState()), [t, o]),
|
|
20
|
-
k.useCallback(() => o(t.getInitialState()), [t, o])
|
|
21
|
-
);
|
|
22
|
-
return k.useDebugValue(e), e;
|
|
23
|
-
}
|
|
24
|
-
const D = (t) => {
|
|
25
|
-
const o = z(t), e = (n) => U(o, n);
|
|
26
|
-
return Object.assign(e, o), e;
|
|
27
|
-
}, H = ((t) => t ? D(t) : D), C = {
|
|
28
|
-
STACKED: 0,
|
|
29
|
-
CURRENT_ONLY: 1,
|
|
30
|
-
CURRENT_HIDDEN_STACK: 2
|
|
31
|
-
}, x = H()((t, o) => ({
|
|
32
|
-
modalStackMap: /* @__PURE__ */ new Map(),
|
|
33
|
-
isMounted: !1,
|
|
34
|
-
renderMode: C.STACKED,
|
|
35
|
-
modalWindowRefs: void 0,
|
|
36
|
-
currentModalId: void 0,
|
|
37
|
-
internalActions: {
|
|
38
|
-
setModalWindowRefRef: (e) => t((n) => ({ modalWindowRefs: e })),
|
|
39
|
-
setIsMounted: (e) => t({ isMounted: e }),
|
|
40
|
-
setRenderMode: (e) => t({ renderMode: e })
|
|
41
|
-
},
|
|
42
|
-
actions: {
|
|
43
|
-
pushModal: (e, n, l = !1) => (e = e ?? K(), o().isMounted || console.error("BaseModalRenderer must be mounted before using."), o().modalStackMap.get(e) !== void 0 ? (o().actions.focusModal(e), e) : (t((s) => {
|
|
44
|
-
let p = [n, l];
|
|
45
|
-
const c = new Map(s.modalStackMap);
|
|
46
|
-
return c.set(e, p), { modalStackMap: c, currentModalId: e };
|
|
47
|
-
}), e)),
|
|
48
|
-
popModal: (e) => o().modalStackMap.get(e) ? (t((n) => {
|
|
49
|
-
const l = new Map(n.modalStackMap);
|
|
50
|
-
l.delete(e);
|
|
51
|
-
const s = Array.from(l.keys())[l.size - 1];
|
|
52
|
-
return { modalStackMap: l, currentModalId: s };
|
|
53
|
-
}), !0) : !1,
|
|
54
|
-
getModal: (e) => o().modalStackMap.get(e),
|
|
55
|
-
updateModal: (e, n, l) => {
|
|
56
|
-
const s = o().modalStackMap.get(e);
|
|
57
|
-
return s ? (t((p) => {
|
|
58
|
-
const c = new Map(p.modalStackMap);
|
|
59
|
-
return s[1] === !0 ? (console.warn(`Modal with id ${e} is dynamic. Cannot update content.`), { modalStackMap: p.modalStackMap }) : (s[0] = n, s[1] = l ?? s[1], c.set(e, s), { modalStackMap: c });
|
|
60
|
-
}), !0) : !1;
|
|
61
|
-
},
|
|
62
|
-
focusModal: (e) => {
|
|
63
|
-
const n = o().modalStackMap.get(e);
|
|
64
|
-
return n ? (t((l) => {
|
|
65
|
-
const s = new Map(l.modalStackMap);
|
|
66
|
-
return s.delete(e), s.set(e, n), { modalStackMap: s, currentModalId: e };
|
|
67
|
-
}), !0) : !1;
|
|
68
|
-
},
|
|
69
|
-
getModalOrderIndex: (e) => Array.from(o().modalStackMap.keys()).indexOf(e),
|
|
70
|
-
getModalWindowRef: (e) => o().modalWindowRefs?.get(e)
|
|
71
|
-
}
|
|
72
|
-
}));
|
|
73
|
-
function L() {
|
|
74
|
-
const { actions: t, currentModalId: o, renderMode: e } = x((n) => n);
|
|
75
|
-
return { ...t, currentModalId: o, renderMode: e };
|
|
76
|
-
}
|
|
77
|
-
function P() {
|
|
78
|
-
const { internalActions: t, isMounted: o, modalStackMap: e, modalWindowRefs: n, currentModalId: l, renderMode: s } = x((p) => p);
|
|
79
|
-
return { ...t, isMounted: o, modalStackMap: e, modalWindowRefs: n, currentModalId: l, renderMode: s, store: x };
|
|
80
|
-
}
|
|
81
|
-
function se({ renderMode: t = C.STACKED, id: o, style: e, className: n, windowClassName: l, windowStyle: s, disableBackgroundScroll: p = !0 }) {
|
|
82
|
-
const c = $(null), y = $(/* @__PURE__ */ new Map()), { setIsMounted: a, setModalWindowRefRef: r, modalStackMap: u, currentModalId: h, store: M } = P(), g = Array.from(u.values()), d = Array.from(u.keys()), S = o || "base-modal-wrapper";
|
|
83
|
-
A(() => {
|
|
84
|
-
if (M.getState().isMounted) throw new Error("Multiple BaseModalRenderer detected. Only one BaseModalRenderer is allowed at a time.");
|
|
85
|
-
return r(y.current), a(!0), () => {
|
|
86
|
-
a(!1), r(void 0);
|
|
87
|
-
};
|
|
88
|
-
}, []), A(() => {
|
|
89
|
-
const f = d[d.length - 1];
|
|
90
|
-
f !== void 0 ? (c.current?.showModal(), document.body.setAttribute("inert", "")) : f === void 0 && (c.current?.close(), document.body.removeAttribute("inert"));
|
|
91
|
-
}, [h]);
|
|
92
|
-
const w = I((f, i) => {
|
|
93
|
-
f ? y.current.set(i, f) : y.current.delete(i);
|
|
94
|
-
}, []), N = () => {
|
|
95
|
-
switch (t) {
|
|
96
|
-
case C.STACKED:
|
|
97
|
-
return g.map(([f, i], m) => /* @__PURE__ */ b(
|
|
98
|
-
"div",
|
|
99
|
-
{
|
|
100
|
-
ref: (v) => w(v, d[m]),
|
|
101
|
-
className: `modal-window ${l || ""}`,
|
|
102
|
-
id: d[m],
|
|
103
|
-
style: { ...s || {} },
|
|
104
|
-
...h !== d[m] ? { inert: "" } : {},
|
|
105
|
-
children: typeof f == "function" ? f() : f
|
|
106
|
-
},
|
|
107
|
-
d[m]
|
|
108
|
-
));
|
|
109
|
-
case C.CURRENT_ONLY:
|
|
110
|
-
return /* @__PURE__ */ b(
|
|
111
|
-
"div",
|
|
112
|
-
{
|
|
113
|
-
id: d[g.length - 1],
|
|
114
|
-
ref: (f) => w(f, d[g.length - 1]),
|
|
115
|
-
className: `modal-window ${l || ""}`,
|
|
116
|
-
style: { ...s || {} },
|
|
117
|
-
children: g[g.length - 1][1] ? null : typeof g[g.length - 1][0] == "function" ? g[g.length - 1][0]() : g[g.length - 1][0]
|
|
118
|
-
},
|
|
119
|
-
d[g.length - 1]
|
|
120
|
-
);
|
|
121
|
-
case C.CURRENT_HIDDEN_STACK:
|
|
122
|
-
return g.map(([f, i], m) => /* @__PURE__ */ b(
|
|
123
|
-
"div",
|
|
124
|
-
{
|
|
125
|
-
ref: (v) => w(v, d[m]),
|
|
126
|
-
id: d[m],
|
|
127
|
-
className: `modal-window ${l || ""}`,
|
|
128
|
-
style: {
|
|
129
|
-
...s || {},
|
|
130
|
-
visibility: h === d[m] ? "visible" : "hidden"
|
|
131
|
-
},
|
|
132
|
-
...h !== d[m] ? { inert: "" } : {},
|
|
133
|
-
children: i ? null : typeof f == "function" ? f() : f
|
|
134
|
-
},
|
|
135
|
-
d[m]
|
|
136
|
-
));
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
return d.length === 0 ? null : /* @__PURE__ */ R(_, { children: [
|
|
140
|
-
E(/* @__PURE__ */ b("style", { children: `${p ? `body:has(dialog#${S}[open]){overflow:hidden}body{scrollbar-gutter:stable}` : ""}dialog#${S}[open]{width:100vw;height:100vh;max-width:100%;max-height:100%}.modal-wrapper{border:none;padding:0;background:unset}.modal-window{display:block;position:absolute;width:100%;height:100%;backdrop-filter:blur(2px);background-color:rgba(0,0,0,.1)}` }), document.head),
|
|
141
|
-
E(/* @__PURE__ */ b("dialog", { ref: c, id: S, className: `modal-wrapper ${n || ""}`, style: e, children: N() }), document.body)
|
|
142
|
-
] });
|
|
143
|
-
}
|
|
144
|
-
function q({ onClick: t, className: o = "", style: e = {}, children: n }) {
|
|
145
|
-
return /* @__PURE__ */ b(
|
|
146
|
-
"div",
|
|
147
|
-
{
|
|
148
|
-
className: `hook-modal-backdrop ${o}`,
|
|
149
|
-
style: {
|
|
150
|
-
position: "fixed",
|
|
151
|
-
inset: 0,
|
|
152
|
-
display: "flex",
|
|
153
|
-
alignItems: "center",
|
|
154
|
-
justifyContent: "center",
|
|
155
|
-
zIndex: 1e3,
|
|
156
|
-
...e
|
|
157
|
-
},
|
|
158
|
-
onClick: t,
|
|
159
|
-
children: n
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
const F = (t) => t.stopPropagation();
|
|
164
|
-
function Y({ className: t = "", style: o = {}, children: e }) {
|
|
165
|
-
return /* @__PURE__ */ b(
|
|
166
|
-
"div",
|
|
167
|
-
{
|
|
168
|
-
className: `hook-modal-window ${t}`,
|
|
169
|
-
style: {
|
|
170
|
-
minWidth: 360,
|
|
171
|
-
maxWidth: "90vw",
|
|
172
|
-
backgroundColor: "#fff",
|
|
173
|
-
borderRadius: 30,
|
|
174
|
-
boxShadow: "0 10px 40px rgba(0,0,0,0.2)",
|
|
175
|
-
padding: 25,
|
|
176
|
-
position: "relative",
|
|
177
|
-
...o
|
|
178
|
-
},
|
|
179
|
-
onClick: F,
|
|
180
|
-
children: e
|
|
181
|
-
}
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
const G = {
|
|
2
|
+
import { ModalBackdrop as w, ModalWindow as j, useBaseModal as I } from "@rokku-x/react-hook-modal";
|
|
3
|
+
import { BaseModalRenderer as P } from "@rokku-x/react-hook-modal";
|
|
4
|
+
import R, { useCallback as v } from "react";
|
|
5
|
+
import { jsx as i, jsxs as C } from "react/jsx-runtime";
|
|
6
|
+
import { create as D } from "zustand";
|
|
7
|
+
const O = {
|
|
185
8
|
primary: { backgroundColor: "#2563eb", color: "#fff" },
|
|
186
9
|
secondary: { backgroundColor: "#e5e7eb", color: "#111" },
|
|
187
10
|
danger: { backgroundColor: "#dc2626", color: "#fff" },
|
|
@@ -190,29 +13,29 @@ const G = {
|
|
|
190
13
|
info: { backgroundColor: "#0ea5e9", color: "#fff" },
|
|
191
14
|
neutral: { backgroundColor: "#6b7280", color: "#fff" }
|
|
192
15
|
};
|
|
193
|
-
function
|
|
194
|
-
const { actions: l = [], title:
|
|
195
|
-
return /* @__PURE__ */
|
|
196
|
-
|
|
16
|
+
function V({ modalWindowId: a, handleAction: m, handleClose: s, config: n }) {
|
|
17
|
+
const { actions: l = [], title: c, content: p, backdropCancel: y, showCloseButton: b, classNames: o = {}, styles: e = {}, variantStyles: r = {} } = n, d = (l.length ? l : [[{ title: "OK", variant: "primary" }]]).filter((u) => u && u.length), f = { ...O, ...r };
|
|
18
|
+
return /* @__PURE__ */ i(
|
|
19
|
+
w,
|
|
197
20
|
{
|
|
198
21
|
onClick: () => {
|
|
199
|
-
|
|
22
|
+
y === !0 && s(a);
|
|
200
23
|
},
|
|
201
|
-
className:
|
|
202
|
-
style:
|
|
203
|
-
children: /* @__PURE__ */
|
|
204
|
-
|
|
24
|
+
className: o.backdrop || "",
|
|
25
|
+
style: e.backdrop,
|
|
26
|
+
children: /* @__PURE__ */ C(
|
|
27
|
+
j,
|
|
205
28
|
{
|
|
206
|
-
className:
|
|
207
|
-
style:
|
|
29
|
+
className: o.dialog || "",
|
|
30
|
+
style: e.dialog,
|
|
208
31
|
children: [
|
|
209
|
-
|
|
32
|
+
b && /* @__PURE__ */ i(
|
|
210
33
|
"button",
|
|
211
34
|
{
|
|
212
35
|
type: "button",
|
|
213
|
-
className: `hook-dialog-close-button ${
|
|
36
|
+
className: `hook-dialog-close-button ${o.closeButton || ""}`,
|
|
214
37
|
"aria-label": "Close",
|
|
215
|
-
onClick: () =>
|
|
38
|
+
onClick: () => s(a),
|
|
216
39
|
style: {
|
|
217
40
|
position: "absolute",
|
|
218
41
|
top: 0,
|
|
@@ -226,23 +49,23 @@ function J({ modalWindowId: t, handleAction: o, handleClose: e, config: n }) {
|
|
|
226
49
|
cursor: "pointer",
|
|
227
50
|
lineHeight: 1,
|
|
228
51
|
color: "#555",
|
|
229
|
-
...
|
|
52
|
+
...e.closeButton
|
|
230
53
|
},
|
|
231
54
|
children: "×"
|
|
232
55
|
}
|
|
233
56
|
),
|
|
234
|
-
|
|
235
|
-
p && /* @__PURE__ */
|
|
236
|
-
/* @__PURE__ */
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
return /* @__PURE__ */
|
|
57
|
+
c && /* @__PURE__ */ i("h3", { className: `hook-dialog-title ${o.title || ""}`, style: { margin: "0 0 15px", fontSize: 20, ...e.title }, children: c }),
|
|
58
|
+
p && /* @__PURE__ */ i("div", { className: `hook-dialog-content ${o.content || ""}`, style: { marginBottom: 15, color: "#555", ...e.content }, children: p }),
|
|
59
|
+
/* @__PURE__ */ i("div", { className: `hook-dialog-actions ${o.actions || ""}`, style: { display: "flex", flexDirection: "column", gap: 10, ...e.actions }, children: d.map((u, N) => {
|
|
60
|
+
const x = u.filter((t) => t.isOnLeft), B = u.filter((t) => !t.isOnLeft), k = (t, g) => {
|
|
61
|
+
const S = t.variant || "secondary", M = f[S] || f.secondary;
|
|
62
|
+
return /* @__PURE__ */ i(
|
|
240
63
|
"button",
|
|
241
64
|
{
|
|
242
65
|
type: "button",
|
|
243
|
-
className: `hook-dialog-action-button hook-dialog-action-${
|
|
244
|
-
onClick: (
|
|
245
|
-
|
|
66
|
+
className: `hook-dialog-action-button hook-dialog-action-${t.variant || "secondary"} ${o.actionButton || ""} ${t.className || ""}`,
|
|
67
|
+
onClick: ($) => {
|
|
68
|
+
t.onClick?.($, t), m(a, t);
|
|
246
69
|
},
|
|
247
70
|
style: {
|
|
248
71
|
border: "none",
|
|
@@ -251,19 +74,19 @@ function J({ modalWindowId: t, handleAction: o, handleClose: e, config: n }) {
|
|
|
251
74
|
fontSize: 14,
|
|
252
75
|
fontWeight: 800,
|
|
253
76
|
cursor: "pointer",
|
|
254
|
-
...
|
|
255
|
-
...
|
|
256
|
-
...
|
|
77
|
+
...M,
|
|
78
|
+
...e.actionButton,
|
|
79
|
+
...t.style || {}
|
|
257
80
|
},
|
|
258
|
-
children:
|
|
81
|
+
children: t.title
|
|
259
82
|
},
|
|
260
|
-
`${
|
|
83
|
+
`${t.title}-${g}`
|
|
261
84
|
);
|
|
262
85
|
};
|
|
263
|
-
return /* @__PURE__ */
|
|
264
|
-
/* @__PURE__ */
|
|
265
|
-
/* @__PURE__ */
|
|
266
|
-
] },
|
|
86
|
+
return /* @__PURE__ */ C("div", { className: `hook-dialog-actions-row ${o.actionsRow || ""}`, style: { display: "flex", gap: 8, justifyContent: "space-between", marginTop: 10, ...e.actionsRow }, children: [
|
|
87
|
+
/* @__PURE__ */ i("div", { className: "hook-dialog-actions-left", style: { display: "flex", gap: 8 }, children: x.map((t, g) => k(t, g)) }),
|
|
88
|
+
/* @__PURE__ */ i("div", { className: "hook-dialog-actions-right", style: { display: "flex", gap: 8 }, children: B.map((t, g) => k(t, g)) })
|
|
89
|
+
] }, N);
|
|
267
90
|
}) })
|
|
268
91
|
]
|
|
269
92
|
}
|
|
@@ -271,72 +94,50 @@ function J({ modalWindowId: t, handleAction: o, handleClose: e, config: n }) {
|
|
|
271
94
|
}
|
|
272
95
|
);
|
|
273
96
|
}
|
|
274
|
-
const
|
|
275
|
-
let o;
|
|
276
|
-
const e = /* @__PURE__ */ new Set(), n = (a, r) => {
|
|
277
|
-
const u = typeof a == "function" ? a(o) : a;
|
|
278
|
-
if (!Object.is(u, o)) {
|
|
279
|
-
const h = o;
|
|
280
|
-
o = r ?? (typeof u != "object" || u === null) ? u : Object.assign({}, o, u), e.forEach((M) => M(o, h));
|
|
281
|
-
}
|
|
282
|
-
}, l = () => o, c = { setState: n, getState: l, getInitialState: () => y, subscribe: (a) => (e.add(a), () => e.delete(a)) }, y = o = t(n, l, c);
|
|
283
|
-
return c;
|
|
284
|
-
}, Q = ((t) => t ? O(t) : O), X = (t) => t;
|
|
285
|
-
function Z(t, o = X) {
|
|
286
|
-
const e = k.useSyncExternalStore(
|
|
287
|
-
t.subscribe,
|
|
288
|
-
k.useCallback(() => o(t.getState()), [t, o]),
|
|
289
|
-
k.useCallback(() => o(t.getInitialState()), [t, o])
|
|
290
|
-
);
|
|
291
|
-
return k.useDebugValue(e), e;
|
|
292
|
-
}
|
|
293
|
-
const B = (t) => {
|
|
294
|
-
const o = Q(t), e = (n) => Z(o, n);
|
|
295
|
-
return Object.assign(e, o), e;
|
|
296
|
-
}, ee = ((t) => t ? B(t) : B), te = ee((t, o) => ({
|
|
97
|
+
const z = D((a, m) => ({
|
|
297
98
|
instances: [],
|
|
298
|
-
addInstance: (
|
|
299
|
-
instances: [...n.instances,
|
|
99
|
+
addInstance: (s) => a((n) => ({
|
|
100
|
+
instances: [...n.instances, s]
|
|
300
101
|
})),
|
|
301
|
-
removeInstance: (
|
|
302
|
-
instances: n.instances.filter((l) => l.id !==
|
|
102
|
+
removeInstance: (s) => a((n) => ({
|
|
103
|
+
instances: n.instances.filter((l) => l.id !== s)
|
|
303
104
|
})),
|
|
304
|
-
getInstance: (
|
|
105
|
+
getInstance: (s) => m().instances.find((n) => n.id === s)
|
|
305
106
|
}));
|
|
306
|
-
function
|
|
307
|
-
const { instances:
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
}, [l, n,
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
}, [l, n,
|
|
314
|
-
return [(
|
|
315
|
-
const
|
|
316
|
-
...t,
|
|
107
|
+
function K(a) {
|
|
108
|
+
const { instances: m, addInstance: s, removeInstance: n, getInstance: l } = z(), c = I(), p = v((o) => {
|
|
109
|
+
const e = l(o);
|
|
110
|
+
e && (c.popModal(o), e.config.rejectOnCancel !== !1 ? e.reject(e.config.defaultCancelValue) : e.resolve(e.config.defaultCancelValue), n(o));
|
|
111
|
+
}, [l, n, c]), y = v((o, e) => {
|
|
112
|
+
const r = l(o);
|
|
113
|
+
r && (c.popModal(o), e.isCancel && r.config.rejectOnCancel !== !1 ? r.reject(e.value) : r.resolve(e.value), n(o));
|
|
114
|
+
}, [l, n, c]);
|
|
115
|
+
return [(o) => new Promise((e, r) => {
|
|
116
|
+
const d = Math.random().toString(36).substring(2, 6), f = {
|
|
317
117
|
...a,
|
|
118
|
+
...o,
|
|
318
119
|
classNames: {
|
|
319
|
-
...
|
|
320
|
-
...
|
|
120
|
+
...a?.classNames,
|
|
121
|
+
...o.classNames
|
|
321
122
|
},
|
|
322
123
|
styles: {
|
|
323
|
-
...
|
|
324
|
-
...
|
|
124
|
+
...a?.styles,
|
|
125
|
+
...o.styles
|
|
325
126
|
},
|
|
326
127
|
variantStyles: {
|
|
327
|
-
...
|
|
328
|
-
...
|
|
128
|
+
...a?.variantStyles,
|
|
129
|
+
...o.variantStyles
|
|
329
130
|
}
|
|
330
|
-
},
|
|
331
|
-
id:
|
|
332
|
-
config:
|
|
333
|
-
resolve:
|
|
334
|
-
reject:
|
|
131
|
+
}, h = {
|
|
132
|
+
id: d,
|
|
133
|
+
config: f,
|
|
134
|
+
resolve: e,
|
|
135
|
+
reject: r
|
|
335
136
|
};
|
|
336
|
-
|
|
137
|
+
s(h), h.id = c.pushModal(d, R.createElement(V, { config: f, modalWindowId: d, handleClose: p, handleAction: y }));
|
|
337
138
|
})];
|
|
338
139
|
}
|
|
339
140
|
export {
|
|
340
|
-
|
|
341
|
-
|
|
141
|
+
P as BaseModalRenderer,
|
|
142
|
+
K as useHookDialog
|
|
342
143
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokku-x/react-hook-dialog",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"author": "rokku-x",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,23 +9,24 @@
|
|
|
9
9
|
"main": "dist/index.cjs.js",
|
|
10
10
|
"module": "dist/index.esm.js",
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@testing-library/jest-dom": "^6.
|
|
13
|
-
"@testing-library/react": "^14.
|
|
14
|
-
"@testing-library/user-event": "^14.
|
|
12
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
13
|
+
"@testing-library/react": "^14.3.1",
|
|
14
|
+
"@testing-library/user-event": "^14.6.1",
|
|
15
15
|
"@types/jest": "^30.0.0",
|
|
16
|
-
"@types/react": "^18.
|
|
17
|
-
"@types/react-dom": "^18.
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
16
|
+
"@types/react": "^18.3.27",
|
|
17
|
+
"@types/react-dom": "^18.3.7",
|
|
18
|
+
"jsdom": "^24.1.3",
|
|
19
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
20
|
+
"typescript": "^5.9.3",
|
|
21
|
+
"vite": "^7.3.1",
|
|
21
22
|
"vite-plugin-dts": "^4.5.4",
|
|
22
|
-
"vitest": "^1.
|
|
23
|
+
"vitest": "^1.6.1"
|
|
23
24
|
},
|
|
24
25
|
"peerDependencies": {
|
|
25
|
-
"@rokku-x/react-hook-modal": "^0.7.
|
|
26
|
+
"@rokku-x/react-hook-modal": "^0.7.8",
|
|
26
27
|
"react": "^18.0.0",
|
|
27
28
|
"react-dom": "^18.0.0",
|
|
28
|
-
"zustand": "^
|
|
29
|
+
"zustand": "^5.0.10"
|
|
29
30
|
},
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"bugs": {
|
|
39
40
|
"url": "https://github.com/rokku-x/react-hook-dialog/issues"
|
|
40
41
|
},
|
|
41
|
-
"description": "A React library",
|
|
42
|
+
"description": "A React dialog hook library for confirmation dialogs, alerts, and modals with rich variants and full customization",
|
|
42
43
|
"files": [
|
|
43
44
|
"dist",
|
|
44
45
|
"README.md"
|
|
@@ -46,9 +47,21 @@
|
|
|
46
47
|
"homepage": "https://github.com/rokku-x/react-hook-dialog#readme",
|
|
47
48
|
"keywords": [
|
|
48
49
|
"react",
|
|
50
|
+
"react-hooks",
|
|
51
|
+
"dialog",
|
|
52
|
+
"modal",
|
|
53
|
+
"confirmation",
|
|
54
|
+
"alert",
|
|
55
|
+
"prompt",
|
|
49
56
|
"hook",
|
|
57
|
+
"typescript",
|
|
58
|
+
"zustand",
|
|
59
|
+
"ui",
|
|
50
60
|
"component",
|
|
51
|
-
"
|
|
61
|
+
"dialog-box",
|
|
62
|
+
"confirmation-dialog",
|
|
63
|
+
"react-dialog",
|
|
64
|
+
"react-modal"
|
|
52
65
|
],
|
|
53
66
|
"license": "MIT",
|
|
54
67
|
"publishConfig": {
|