@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 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 m=require("react"),N=require("react-dom"),f=require("react/jsx-runtime"),R=t=>{let o;const e=new Set,n=(c,M)=>{const a=typeof c=="function"?c(o):c;if(!Object.is(a,o)){const r=o;o=M??(typeof a!="object"||a===null)?a:Object.assign({},o,a),e.forEach(u=>u(o,r))}},l=()=>o,s={setState:n,getState:l,getInitialState:()=>b,subscribe:c=>(e.add(c),()=>e.delete(c))},b=o=t(n,l,s);return s},O=(t=>t?R(t):R),B=t=>t;function T(t,o=B){const e=m.useSyncExternalStore(t.subscribe,m.useCallback(()=>o(t.getState()),[t,o]),m.useCallback(()=>o(t.getInitialState()),[t,o]));return m.useDebugValue(e),e}const I=t=>{const o=O(t),e=n=>T(o,n);return Object.assign(e,o),e},W=(t=>t?I(t):I),x={STACKED:0,CURRENT_ONLY:1,CURRENT_HIDDEN_STACK:2},j=W()((t,o)=>({modalStackMap:new Map,isMounted:!1,renderMode:x.STACKED,modalWindowRefs:void 0,currentModalId:void 0,internalActions:{setModalWindowRefRef:e=>t(n=>({modalWindowRefs:e})),setIsMounted:e=>t({isMounted:e}),setRenderMode:e=>t({renderMode:e})},actions:{pushModal:(e,n,l=!1)=>(e=e??m.useId(),o().isMounted||console.error("BaseModalRenderer must be mounted before using."),o().modalStackMap.get(e)!==void 0?(o().actions.focusModal(e),e):(t(s=>{let b=[n,l];const c=new Map(s.modalStackMap);return c.set(e,b),{modalStackMap:c,currentModalId:e}}),e)),popModal:e=>o().modalStackMap.get(e)?(t(n=>{const l=new Map(n.modalStackMap);l.delete(e);const s=Array.from(l.keys())[l.size-1];return{modalStackMap:l,currentModalId:s}}),!0):!1,getModal:e=>o().modalStackMap.get(e),updateModal:(e,n,l)=>{const s=o().modalStackMap.get(e);return s?(t(b=>{const c=new Map(b.modalStackMap);return s[1]===!0?(console.warn(`Modal with id ${e} is dynamic. Cannot update content.`),{modalStackMap:b.modalStackMap}):(s[0]=n,s[1]=l??s[1],c.set(e,s),{modalStackMap:c})}),!0):!1},focusModal:e=>{const n=o().modalStackMap.get(e);return n?(t(l=>{const s=new Map(l.modalStackMap);return s.delete(e),s.set(e,n),{modalStackMap:s,currentModalId:e}}),!0):!1},getModalOrderIndex:e=>Array.from(o().modalStackMap.keys()).indexOf(e),getModalWindowRef:e=>o().modalWindowRefs?.get(e)}}));function K(){const{actions:t,currentModalId:o,renderMode:e}=j(n=>n);return{...t,currentModalId:o,renderMode:e}}function _(){const{internalActions:t,isMounted:o,modalStackMap:e,modalWindowRefs:n,currentModalId:l,renderMode:s}=j(b=>b);return{...t,isMounted:o,modalStackMap:e,modalWindowRefs:n,currentModalId:l,renderMode:s,store:j}}function z({renderMode:t=x.STACKED,id:o,style:e,className:n,windowClassName:l,windowStyle:s,disableBackgroundScroll:b=!0}){const c=m.useRef(null),M=m.useRef(new Map),{setIsMounted:a,setModalWindowRefRef:r,modalStackMap:u,currentModalId:y,store:k}=_(),g=Array.from(u.values()),d=Array.from(u.keys()),S=o||"base-modal-wrapper";m.useEffect(()=>{if(k.getState().isMounted)throw new Error("Multiple BaseModalRenderer detected. Only one BaseModalRenderer is allowed at a time.");return r(M.current),a(!0),()=>{a(!1),r(void 0)}},[]),m.useEffect(()=>{const p=d[d.length-1];p!==void 0?(c.current?.showModal(),document.body.setAttribute("inert","")):p===void 0&&(c.current?.close(),document.body.removeAttribute("inert"))},[y]);const w=m.useCallback((p,i)=>{p?M.current.set(i,p):M.current.delete(i)},[]),C=()=>{switch(t){case x.STACKED:return g.map(([p,i],h)=>f.jsx("div",{ref:v=>w(v,d[h]),className:`modal-window ${l||""}`,id:d[h],style:{...s||{}},...y!==d[h]?{inert:""}:{},children:typeof p=="function"?p():p},d[h]));case x.CURRENT_ONLY:return f.jsx("div",{id:d[g.length-1],ref:p=>w(p,d[g.length-1]),className:`modal-window ${l||""}`,style:{...s||{}},children:g[g.length-1][1]?null:typeof g[g.length-1][0]=="function"?g[g.length-1][0]():g[g.length-1][0]},d[g.length-1]);case x.CURRENT_HIDDEN_STACK:return g.map(([p,i],h)=>f.jsx("div",{ref:v=>w(v,d[h]),id:d[h],className:`modal-window ${l||""}`,style:{...s||{},visibility:y===d[h]?"visible":"hidden"},...y!==d[h]?{inert:""}:{},children:i?null:typeof p=="function"?p():p},d[h]))}};return d.length===0?null:f.jsxs(f.Fragment,{children:[N.createPortal(f.jsx("style",{children:`${b?`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),N.createPortal(f.jsx("dialog",{ref:c,id:S,className:`modal-wrapper ${n||""}`,style:e,children:C()}),document.body)]})}function P({onClick:t,className:o="",style:e={},children:n}){return f.jsx("div",{className:`hook-modal-backdrop ${o}`,style:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,...e},onClick:t,children:n})}const V=t=>t.stopPropagation();function q({className:t="",style:o={},children:e}){return f.jsx("div",{className:`hook-modal-window ${t}`,style:{minWidth:360,maxWidth:"90vw",backgroundColor:"#fff",borderRadius:30,boxShadow:"0 10px 40px rgba(0,0,0,0.2)",padding:25,position:"relative",...o},onClick:V,children:e})}const H={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 U({modalWindowId:t,handleAction:o,handleClose:e,config:n}){const{actions:l=[],title:s,content:b,backdropCancel:c,showCloseButton:M,classNames:a={},styles:r={},variantStyles:u={}}=n,y=(l.length?l:[[{title:"OK",variant:"primary"}]]).filter(d=>d&&d.length),k={...H,...u},g=()=>{c===!0&&e(t)};return f.jsx(P,{onClick:g,className:a.backdrop||"",style:r.backdrop,children:f.jsxs(q,{className:a.dialog||"",style:r.dialog,children:[M&&f.jsx("button",{type:"button",className:`hook-dialog-close-button ${a.closeButton||""}`,"aria-label":"Close",onClick:()=>e(t),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",...r.closeButton},children:"×"}),s&&f.jsx("h3",{className:`hook-dialog-title ${a.title||""}`,style:{margin:"0 0 15px",fontSize:20,...r.title},children:s}),b&&f.jsx("div",{className:`hook-dialog-content ${a.content||""}`,style:{marginBottom:15,color:"#555",...r.content},children:b}),f.jsx("div",{className:`hook-dialog-actions ${a.actions||""}`,style:{display:"flex",flexDirection:"column",gap:10,...r.actions},children:y.map((d,S)=>{const w=d.filter(i=>i.isOnLeft),C=d.filter(i=>!i.isOnLeft),p=(i,h)=>{const v=i.variant||"secondary",D=k[v]||k.secondary;return f.jsx("button",{type:"button",className:`hook-dialog-action-button hook-dialog-action-${i.variant||"secondary"} ${a.actionButton||""} ${i.className||""}`,onClick:E=>{i.onClick?.(E,i),o(t,i)},style:{border:"none",borderRadius:15,padding:"10px 18px",fontSize:14,fontWeight:800,cursor:"pointer",...D,...r.actionButton,...i.style||{}},children:i.title},`${i.title}-${h}`)};return f.jsxs("div",{className:`hook-dialog-actions-row ${a.actionsRow||""}`,style:{display:"flex",gap:8,justifyContent:"space-between",marginTop:10,...r.actionsRow},children:[f.jsx("div",{className:"hook-dialog-actions-left",style:{display:"flex",gap:8},children:w.map((i,h)=>p(i,h))}),f.jsx("div",{className:"hook-dialog-actions-right",style:{display:"flex",gap:8},children:C.map((i,h)=>p(i,h))})]},S)})})]})})}const $=t=>{let o;const e=new Set,n=(a,r)=>{const u=typeof a=="function"?a(o):a;if(!Object.is(u,o)){const y=o;o=r??(typeof u!="object"||u===null)?u:Object.assign({},o,u),e.forEach(k=>k(o,y))}},l=()=>o,c={setState:n,getState:l,getInitialState:()=>M,subscribe:a=>(e.add(a),()=>e.delete(a))},M=o=t(n,l,c);return c},L=(t=>t?$(t):$),F=t=>t;function Y(t,o=F){const e=m.useSyncExternalStore(t.subscribe,m.useCallback(()=>o(t.getState()),[t,o]),m.useCallback(()=>o(t.getInitialState()),[t,o]));return m.useDebugValue(e),e}const A=t=>{const o=L(t),e=n=>Y(o,n);return Object.assign(e,o),e},G=(t=>t?A(t):A),J=G((t,o)=>({instances:[],addInstance:e=>t(n=>({instances:[...n.instances,e]})),removeInstance:e=>t(n=>({instances:n.instances.filter(l=>l.id!==e)})),getInstance:e=>o().instances.find(n=>n.id===e)}));function Q(t){const{instances:o,addInstance:e,removeInstance:n,getInstance:l}=J(),s=K(),b=m.useCallback(a=>{const r=l(a);r&&(s.popModal(a),r.config.rejectOnCancel!==!1?r.reject(r.config.defaultCancelValue):r.resolve(r.config.defaultCancelValue),n(a))},[l,n,s]),c=m.useCallback((a,r)=>{const u=l(a);u&&(s.popModal(a),r.isCancel&&u.config.rejectOnCancel!==!1?u.reject(r.value):u.resolve(r.value),n(a))},[l,n,s]);return[a=>new Promise((r,u)=>{const y=Math.random().toString(36).substring(2,6),k={...t,...a,classNames:{...t?.classNames,...a.classNames},styles:{...t?.styles,...a.styles},variantStyles:{...t?.variantStyles,...a.variantStyles}},g={id:y,config:k,resolve:r,reject:u};e(g),g.id=s.pushModal(y,m.createElement(U,{config:k,modalWindowId:y,handleClose:b,handleAction:c}))})]}exports.BaseModalRenderer=z;exports.useHookDialog=Q;
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 k, { useId as K, useRef as $, useEffect as A, useCallback as I } from "react";
3
- import { createPortal as E } from "react-dom";
4
- import { jsxs as R, Fragment as _, jsx as b } from "react/jsx-runtime";
5
- const j = (t) => {
6
- let o;
7
- const e = /* @__PURE__ */ new Set(), n = (c, y) => {
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 J({ modalWindowId: t, handleAction: o, handleClose: e, config: n }) {
194
- const { actions: l = [], title: s, content: p, backdropCancel: c, showCloseButton: y, classNames: a = {}, styles: r = {}, variantStyles: u = {} } = n, h = (l.length ? l : [[{ title: "OK", variant: "primary" }]]).filter((d) => d && d.length), M = { ...G, ...u };
195
- return /* @__PURE__ */ b(
196
- q,
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
- c === !0 && e(t);
22
+ y === !0 && s(a);
200
23
  },
201
- className: a.backdrop || "",
202
- style: r.backdrop,
203
- children: /* @__PURE__ */ R(
204
- Y,
24
+ className: o.backdrop || "",
25
+ style: e.backdrop,
26
+ children: /* @__PURE__ */ C(
27
+ j,
205
28
  {
206
- className: a.dialog || "",
207
- style: r.dialog,
29
+ className: o.dialog || "",
30
+ style: e.dialog,
208
31
  children: [
209
- y && /* @__PURE__ */ b(
32
+ b && /* @__PURE__ */ i(
210
33
  "button",
211
34
  {
212
35
  type: "button",
213
- className: `hook-dialog-close-button ${a.closeButton || ""}`,
36
+ className: `hook-dialog-close-button ${o.closeButton || ""}`,
214
37
  "aria-label": "Close",
215
- onClick: () => e(t),
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
- ...r.closeButton
52
+ ...e.closeButton
230
53
  },
231
54
  children: "×"
232
55
  }
233
56
  ),
234
- s && /* @__PURE__ */ b("h3", { className: `hook-dialog-title ${a.title || ""}`, style: { margin: "0 0 15px", fontSize: 20, ...r.title }, children: s }),
235
- p && /* @__PURE__ */ b("div", { className: `hook-dialog-content ${a.content || ""}`, style: { marginBottom: 15, color: "#555", ...r.content }, children: p }),
236
- /* @__PURE__ */ b("div", { className: `hook-dialog-actions ${a.actions || ""}`, style: { display: "flex", flexDirection: "column", gap: 10, ...r.actions }, children: h.map((d, S) => {
237
- const w = d.filter((i) => i.isOnLeft), N = d.filter((i) => !i.isOnLeft), f = (i, m) => {
238
- const v = i.variant || "secondary", T = M[v] || M.secondary;
239
- return /* @__PURE__ */ b(
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-${i.variant || "secondary"} ${a.actionButton || ""} ${i.className || ""}`,
244
- onClick: (W) => {
245
- i.onClick?.(W, i), o(t, i);
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
- ...T,
255
- ...r.actionButton,
256
- ...i.style || {}
77
+ ...M,
78
+ ...e.actionButton,
79
+ ...t.style || {}
257
80
  },
258
- children: i.title
81
+ children: t.title
259
82
  },
260
- `${i.title}-${m}`
83
+ `${t.title}-${g}`
261
84
  );
262
85
  };
263
- return /* @__PURE__ */ R("div", { className: `hook-dialog-actions-row ${a.actionsRow || ""}`, style: { display: "flex", gap: 8, justifyContent: "space-between", marginTop: 10, ...r.actionsRow }, children: [
264
- /* @__PURE__ */ b("div", { className: "hook-dialog-actions-left", style: { display: "flex", gap: 8 }, children: w.map((i, m) => f(i, m)) }),
265
- /* @__PURE__ */ b("div", { className: "hook-dialog-actions-right", style: { display: "flex", gap: 8 }, children: N.map((i, m) => f(i, m)) })
266
- ] }, S);
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 O = (t) => {
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: (e) => t((n) => ({
299
- instances: [...n.instances, e]
99
+ addInstance: (s) => a((n) => ({
100
+ instances: [...n.instances, s]
300
101
  })),
301
- removeInstance: (e) => t((n) => ({
302
- instances: n.instances.filter((l) => l.id !== e)
102
+ removeInstance: (s) => a((n) => ({
103
+ instances: n.instances.filter((l) => l.id !== s)
303
104
  })),
304
- getInstance: (e) => o().instances.find((n) => n.id === e)
105
+ getInstance: (s) => m().instances.find((n) => n.id === s)
305
106
  }));
306
- function le(t) {
307
- const { instances: o, addInstance: e, removeInstance: n, getInstance: l } = te(), s = L(), p = I((a) => {
308
- const r = l(a);
309
- r && (s.popModal(a), r.config.rejectOnCancel !== !1 ? r.reject(r.config.defaultCancelValue) : r.resolve(r.config.defaultCancelValue), n(a));
310
- }, [l, n, s]), c = I((a, r) => {
311
- const u = l(a);
312
- u && (s.popModal(a), r.isCancel && u.config.rejectOnCancel !== !1 ? u.reject(r.value) : u.resolve(r.value), n(a));
313
- }, [l, n, s]);
314
- return [(a) => new Promise((r, u) => {
315
- const h = Math.random().toString(36).substring(2, 6), M = {
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
- ...t?.classNames,
320
- ...a.classNames
120
+ ...a?.classNames,
121
+ ...o.classNames
321
122
  },
322
123
  styles: {
323
- ...t?.styles,
324
- ...a.styles
124
+ ...a?.styles,
125
+ ...o.styles
325
126
  },
326
127
  variantStyles: {
327
- ...t?.variantStyles,
328
- ...a.variantStyles
128
+ ...a?.variantStyles,
129
+ ...o.variantStyles
329
130
  }
330
- }, g = {
331
- id: h,
332
- config: M,
333
- resolve: r,
334
- reject: u
131
+ }, h = {
132
+ id: d,
133
+ config: f,
134
+ resolve: e,
135
+ reject: r
335
136
  };
336
- e(g), g.id = s.pushModal(h, k.createElement(J, { config: M, modalWindowId: h, handleClose: p, handleAction: c }));
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
- se as BaseModalRenderer,
341
- le as useHookDialog
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.1",
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.0.0",
13
- "@testing-library/react": "^14.0.0",
14
- "@testing-library/user-event": "^14.5.2",
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.0.0",
17
- "@types/react-dom": "^18.0.0",
18
- "@vitejs/plugin-react": "^5.0.4",
19
- "typescript": "^5.0.0",
20
- "vite": "^7.1.9",
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.0.0"
23
+ "vitest": "^1.6.1"
23
24
  },
24
25
  "peerDependencies": {
25
- "@rokku-x/react-hook-modal": "^0.7.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": "^4.0.0"
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
- "library"
61
+ "dialog-box",
62
+ "confirmation-dialog",
63
+ "react-dialog",
64
+ "react-modal"
52
65
  ],
53
66
  "license": "MIT",
54
67
  "publishConfig": {