roks-rjsc 0.1.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 CHANGED
@@ -20,16 +20,16 @@
20
20
 
21
21
  Import named exports from the package root. Examples below assume React 18.
22
22
 
23
- Basic component:
23
+ Core components:
24
24
 
25
- ```tsx
26
- import React from 'react';
27
- import { Button } from 'roks-rjsc';
25
+ ```tsx
26
+ import React from 'react';
27
+ import { /* core exports */ } from 'roks-rjsc';
28
28
 
29
- export default function App() {
30
- return <Button onClick={() => alert('clicked')}>Click me</Button>;
31
- }
32
- ```
29
+ export default function App() {
30
+ return <div>Your app root</div>;
31
+ }
32
+ ```
33
33
 
34
34
  Loading provider and hook:
35
35
 
@@ -87,18 +87,21 @@
87
87
 
88
88
  export default function App() {
89
89
  return (
90
- <BaseModalProvider>
91
- <StaticExample />
92
- <DynamicExample />
93
- </BaseModalProvider>
90
+ <BaseModalProvider>
91
+ <StaticExample />
92
+ <DynamicExample />
93
+ </BaseModalProvider>
94
94
  )
95
95
  }
96
96
  ```
97
97
 
98
- API (top-level exports)
99
- - `Button` - basic button component
100
- - `LoadingProvider`, `useLoading`, `Loading`, `AnimationType` - loading utilities
101
- - `BaseModalProvider`, `useBaseModal`, `useStaticModal`, `useDynamicModal`, `RenderMode` - modal system
98
+ API (top-level exports)
99
+ - `LoadingProvider`, `useLoading`, `Loading`, `AnimationType` - loading utilities (available via `roks-rjsc/loading`)
100
+ - `BaseModalProvider`, `useBaseModal`, `useStaticModal`, `useDynamicModal`, `RenderMode` - modal system (available via `roks-rjsc/modal`)
101
+
102
+ Subpath imports
103
+ - `roks-rjsc/modal`: exports `BaseModalProvider`, `useBaseModal`, `useStaticModal`, `useDynamicModal`, `RenderMode`
104
+ - `roks-rjsc/loading`: exports `LoadingProvider`, `useLoading`, `Loading`, `AnimationType`
102
105
 
103
106
  ## License
104
107
 
@@ -0,0 +1,3 @@
1
+ export default function Loading({ isLoading }: {
2
+ isLoading: boolean;
3
+ }): null;
@@ -0,0 +1,38 @@
1
+ import { default as React, ReactNode } from 'react';
2
+ import { default as EventEmitter } from '../utils/EventEmitter';
3
+ type LoadingEvents = {
4
+ change: {
5
+ isLoading: boolean;
6
+ } | null;
7
+ start: null;
8
+ stop: null;
9
+ };
10
+ export declare const loadingEventTarget: EventEmitter<LoadingEvents>;
11
+ export declare const AnimationType: {
12
+ readonly Spin: "spin";
13
+ readonly FadeInOut: "fadeInOut";
14
+ readonly None: "none";
15
+ };
16
+ export type AnimationType = (typeof AnimationType)[keyof typeof AnimationType];
17
+ interface LoadingContextType {
18
+ isLoading: boolean;
19
+ startLoading: () => void;
20
+ stopLoading: () => void;
21
+ loadingEventTarget: EventEmitter<LoadingEvents>;
22
+ overrideLoading: (state: boolean | null) => void;
23
+ }
24
+ export declare const LoadingContext: React.Context<LoadingContextType | undefined>;
25
+ export declare const LoadingProvider: React.FC<{
26
+ id?: string;
27
+ children: ReactNode | null;
28
+ loadingComponent?: React.ComponentType | React.ReactElement;
29
+ animationType?: AnimationType;
30
+ animationDuration?: number;
31
+ wrapperStyle?: React.CSSProperties;
32
+ wrapperClassName?: string;
33
+ wrapperId?: string;
34
+ animationWrapperStyle?: React.CSSProperties;
35
+ animationWrapperClassName?: string;
36
+ animationWrapperId?: string;
37
+ }>;
38
+ export {};
@@ -0,0 +1,25 @@
1
+ import { default as React } from 'react';
2
+ export declare const BaseModalContext: React.Context<BaseModalContextType | undefined>;
3
+ export declare const RenderMode: {
4
+ STACKED: number;
5
+ CURRENT_ONLY: number;
6
+ CURRENT_HIDDEN_STACK: number;
7
+ };
8
+ export type RenderMode = (typeof RenderMode)[keyof typeof RenderMode];
9
+ export interface BaseModalContextType {
10
+ modalCount: number;
11
+ renderMode?: RenderMode;
12
+ currentModalId?: string;
13
+ pushModal: (el: React.ReactNode, modalId?: string, isDynamic?: boolean) => string;
14
+ popModal: (idEl: string | React.ReactNode) => boolean;
15
+ updateModalContent: (modalId: string, newContent: React.ReactNode) => void;
16
+ getModalWindowRef: (modalId: string) => HTMLDivElement | undefined;
17
+ focusModal: (modalId: string) => boolean;
18
+ getModalOrderIndex: (modalId: string) => number;
19
+ }
20
+ export default function BaseModalProvider({ children, wrapperId, renderMode, wrapperStyle }: {
21
+ children: React.ReactNode;
22
+ wrapperId?: string;
23
+ renderMode?: RenderMode;
24
+ wrapperStyle?: React.CSSProperties;
25
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ export type useAsyncLocalStorageStateOptions<T> = {
2
+ defaultValue?: T | (() => T | Promise<T>);
3
+ storageSync?: boolean;
4
+ resetStorage?: boolean;
5
+ resetIfError?: boolean;
6
+ serializer?: {
7
+ stringify: (value: unknown) => Promise<string>;
8
+ parse: (value: string) => Promise<unknown>;
9
+ };
10
+ };
11
+ export type useAsyncLocalStorageStateReturnType<T> = [
12
+ T,
13
+ (value: T | ((prevState: T) => T)) => Promise<void>,
14
+ () => void
15
+ ];
16
+ export declare function useAsyncLocalStorageState<T>(key: string, options?: useAsyncLocalStorageStateOptions<T>): useAsyncLocalStorageStateReturnType<T>;
17
+ export default useAsyncLocalStorageState;
@@ -0,0 +1,3 @@
1
+ import { BaseModalContextType, RenderMode } from '../contexts/ModalContext';
2
+ export default function useBaseModal(): BaseModalContextType;
3
+ export { RenderMode };
@@ -0,0 +1,4 @@
1
+ import { ReactNode } from 'react';
2
+ import { RenderMode } from '../contexts/ModalContext';
3
+ export default function useDynamicModal(id?: string): [(el: JSX.Element) => ReactNode, () => void, () => void, () => void, string, boolean];
4
+ export { RenderMode };
@@ -0,0 +1,16 @@
1
+ declare const useLoading: () => {
2
+ asyncUseLoading: <R, _ extends any[]>(asyncFunction: Promise<R>) => Promise<R>;
3
+ isLoading: boolean;
4
+ loadingEventTarget: import('../utils/EventEmitter').default<{
5
+ change: {
6
+ isLoading: boolean;
7
+ } | null;
8
+ start: null;
9
+ stop: null;
10
+ }>;
11
+ overrideLoading: (state: boolean | null) => void;
12
+ startLoading: () => void;
13
+ stopLoading: () => void;
14
+ isLocalLoading: boolean;
15
+ };
16
+ export default useLoading;
@@ -0,0 +1,3 @@
1
+ import { RenderMode } from '../contexts/ModalContext';
2
+ export { RenderMode };
3
+ export default function useStaticModal(id?: string): [(el: React.ReactNode) => () => boolean, () => boolean, string, boolean, (newContent: React.ReactNode) => void];
package/dist/index.cjs.js CHANGED
@@ -1,54 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),a=require("react"),N=require("react-dom"),F=({children:o,onClick:e})=>c.jsx("button",{onClick:e,children:o});class T extends EventTarget{constructor(){super(...arguments),this.controller=new AbortController}on(e,n){return this.addEventListener(e,f=>n(f.detail),{signal:this.controller.signal}),this}once(e,n){return this.addEventListener(e,f=>n(f.detail),{signal:this.controller.signal,once:!0}),this}emit(e,n){return this.dispatchEvent(new CustomEvent(e,{detail:n}))}removeAllListeners(){this.controller.abort(),this.controller=new AbortController}}const C=new T,w={Spin:"spin",FadeInOut:"fadeInOut",None:"none"},I=({animationType:o=w.Spin,animationDuration:e,children:n,style:f,className:g,id:r})=>{const u=o,h=o===w.Spin?1:o===w.FadeInOut?2:0,d=e||h,s=o===w.Spin?"linear":o===w.FadeInOut?"ease-in-out":"linear",m=o===w.None?"none":`${u} ${d}s ${s} infinite`;return c.jsx("div",{style:{animation:m,...f},className:g,id:r,children:n})},$=()=>c.jsx("div",{id:"loading-circle",style:{width:"60px",height:"60px",border:"10px solid #f3f3f3",borderTop:"10px solid #009b4bff",borderRadius:"50%"}}),U=()=>c.jsx("div",{style:{padding:"20px",fontSize:"25px",color:"#333",fontFamily:"system-ui, sans-serif"},children:"Please wait..."}),P=a.createContext(void 0),W=({children:o,loadingComponent:e,animationType:n=w.FadeInOut,animationDuration:f,wrapperStyle:g,wrapperClassName:r,wrapperId:u,animationWrapperStyle:h,animationWrapperClassName:d,animationWrapperId:s})=>{e=e||(n===w.Spin?$:U);const[m,p]=a.useState(0),[R,E]=a.useState(null),b=R??m>0,j=M=>E(M),k=()=>p(M=>M+1),A=()=>p(M=>Math.max(0,M-1)),L=a.useRef(null);a.useEffect(()=>{C.emit("change",{isLoading:b}),C.emit(b?"start":"stop",null),b?(L.current?.showModal(),document.body.setAttribute("inert","")):b||document.body.removeAttribute("inert")},[m]),a.useEffect(()=>()=>{p(0),C.removeAllListeners()},[]);const y=u||"loading-dialog";return c.jsxs(P.Provider,{value:{get isLoading(){return b},startLoading:k,stopLoading:A,loadingEventTarget:C,overrideLoading:j},children:[o,b&&N.createPortal(c.jsxs(c.Fragment,{children:[c.jsx("style",{children:`
2
- dialog#${y}[open] {
3
- display: flex !important;
4
- justify-content: center;
5
- align-items: center;
6
- width: 100vw;
7
- height: 100vh;
8
- max-width: 100%;
9
- max-height: 100%;
10
- }
11
- @keyframes spin {
12
- 0% { transform: rotate(0deg); }
13
- 100% { transform: rotate(360deg); }
14
- }
15
- @keyframes fadeInOut {
16
- 0%, 100% { opacity: 0.2; }
17
- 50% { opacity: 1; }
18
- }
19
- body:has(dialog#${y}[open]) {
20
- overflow: hidden;
21
- }
22
- body {
23
- scrollbar-gutter: stable;
24
- }
25
- `}),c.jsx("dialog",{ref:L,style:{border:"none",padding:0,backgroundColor:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)",...g},className:r,id:y,children:c.jsx(I,{animationType:n,animationDuration:f,style:h,className:d,id:s,children:a.isValidElement(e)?e:a.createElement(e)})})]}),document.body)]})},B=()=>{const o=a.useContext(P);if(!o)throw new Error("useLoading must be used within a LoadingProvider");const e=a.useRef(0),{startLoading:n,stopLoading:f,isLoading:g,...r}=o,u=()=>{n(),e.current+=1},h=()=>{e.current>0&&(f(),e.current-=1)};return{startLoading:u,stopLoading:h,get isLocalLoading(){return e.current>0},...r,asyncUseLoading:async s=>{u();try{return await s}finally{h()}},isLoading:g}};function _({isLoading:o=!1}){const e=B();return a.useEffect(()=>(o?e.startLoading():e.stopLoading(),()=>{o&&e.stopLoading()}),[o]),null}const S=a.createContext(void 0),x={STACKED:0,CURRENT_ONLY:1,CURRENT_HIDDEN_STACK:2};function K({children:o,wrapperId:e,renderMode:n=x.STACKED,wrapperStyle:f}){const g=a.useRef(null),r=a.useRef(new Map),[u,h]=a.useState(r.current),d=Array.from(u.values()),s=Array.from(u.keys()),m=a.useRef(new Map),[p,R]=a.useState(void 0),E=(t,i=Math.random().toString(36).substring(2,6),l=!1)=>{if(s.indexOf(i)!==-1)return console.warn(`Modal with id ${i} already exists. Choose a different id.`),i;let D=[t,l];return r.current=new Map(r.current),r.current.set(i,D),h(new Map(r.current)),i},b=t=>{let i="";if(typeof t!="string"){for(let[l,v]of r.current.entries())if(v[0]===t){i=l;break}}else typeof t=="string"&&(i=t);return r.current.has(i)?(r.current=new Map(r.current),r.current.delete(i),h(new Map(r.current)),!0):!1},j=(t,i)=>{if(r.current.has(t)){let l=r.current.get(t);if(l[1]===!1){console.warn(`Modal with id ${t} is dynamic. Cannot update content.`);return}l[0]=i,r.current.set(t,l),h(new Map(r.current))}},k=t=>{if(!u.has(t))return!1;let i=r.current.get(t);return r.current.delete(t),r.current.set(t,i),h(new Map(r.current)),!0},A=t=>s.indexOf(t),L=t=>m.current.get(t);a.useEffect(()=>{const t=s[s.length-1];t!==void 0?(g.current?.showModal(),document.body.setAttribute("inert","")):t===void 0&&(g.current?.close(),document.body.removeAttribute("inert")),R(t)},[u]);const y=e||"base-modal-wrapper",M=a.useCallback((t,i)=>{t?m.current.set(i,t):m.current.delete(i)},[]),O=()=>{switch(n){case x.STACKED:return d.map(([t,i],l)=>c.jsx("div",{ref:v=>M(v,s[l]),className:"modal-window",id:s[l],style:{display:"block",zIndex:s[l]===p?1e3:100},...p!==s[l]?{inert:""}:{},children:i?null:t},s[l]));case x.CURRENT_ONLY:return d.length>0?c.jsx("div",{id:s[d.length-1],ref:t=>M(t,s[d.length-1]),className:"modal-window",style:{display:"block"},children:d[d.length-1][1]?null:d[d.length-1][0]},s[d.length-1]):null;case x.CURRENT_HIDDEN_STACK:return d.length>0?d.map(([t,i],l)=>c.jsx("div",{ref:v=>M(v,s[l]),id:s[l],className:"modal-window",style:{display:p===s[l]?"block":"none"},...p!==s[l]?{inert:""}:{},children:i?null:t},s[l])):null}};return c.jsxs(S.Provider,{value:{modalCount:0,get renderMode(){return n},pushModal:E,popModal:b,currentModalId:p,updateModalContent:j,getModalWindowRef:L,focusModal:k,getModalOrderIndex:A},children:[o,s.length===0?null:N.createPortal(c.jsxs(c.Fragment,{children:[c.jsx("style",{children:`
26
- dialog#${y}[open] {
27
- display: flex !important;
28
- justify-content: center;
29
- align-items: center;
30
- width: 100vw;
31
- height: 100vh;
32
- max-width: 100%;
33
- max-height: 100%;
34
- }
35
- body:has(dialog#${y}[open]) {
36
- overflow: hidden;
37
- }
38
- body {
39
- scrollbar-gutter: stable;
40
- }
41
- .modal-wrapper{
42
- border: none;
43
- padding: 0;
44
- background: unset;
45
- }
46
- .modal-window {
47
- position: absolute;
48
- width: 100%;
49
- height: 100%;
50
- display: none;
51
- background-color: rgba(0, 0, 0, 0.1);
52
- backdrop-filter: blur(2px);
53
- }
54
- `}),c.jsx("dialog",{className:"modal-wrapper",ref:g,id:y,style:f,children:O()})]}),document.body)]})}function q(){const o=a.useContext(S);if(!o)throw new Error("useBaseModal must be used within a BaseModalProvider");return o}function z(o=Math.random().toString(36).substring(2,6)){const e=a.useContext(S);if(!e)throw new Error("useBaseModal must be used within a BaseModalProvider");let n=a.useRef(o);const f=u=>(e.pushModal(u,n.current),g),g=()=>e.popModal(n.current),r=u=>{e.updateModalContent(n.current,u)};return[f,g,n.current,e.currentModalId===n.current,r]}function H(o=Math.random().toString(36).substring(2,6)){const e=a.useContext(S);if(!e)throw new Error("useBaseModal must be used within a BaseModalProvider");let n=a.useRef(o);const f=e.currentModalId===n.current;return[d=>e.getModalWindowRef(n.current)?N.createPortal(d,e.getModalWindowRef(n.current)):null,()=>{e.pushModal(null,n.current,!0)[1]},()=>{e.popModal(n.current)},()=>{e.focusModal(n.current)},n.current,f]}exports.AnimationType=w;exports.BaseModalProvider=K;exports.Button=F;exports.Loading=_;exports.LoadingProvider=W;exports.RenderMode=x;exports.useBaseModal=q;exports.useDynamicModal=H;exports.useLoading=B;exports.useStaticModal=z;
1
+ "use strict";
package/dist/index.d.ts CHANGED
@@ -1,96 +1 @@
1
- import { default as default_2 } from 'react';
2
- import { JSX as JSX_2 } from 'react/jsx-runtime';
3
- import { ReactNode } from 'react';
4
-
5
- export declare const AnimationType: {
6
- readonly Spin: "spin";
7
- readonly FadeInOut: "fadeInOut";
8
- readonly None: "none";
9
- };
10
-
11
- export declare type AnimationType = (typeof AnimationType)[keyof typeof AnimationType];
12
-
13
- declare interface BaseModalContextType {
14
- modalCount: number;
15
- renderMode?: RenderMode;
16
- currentModalId?: string;
17
- pushModal: (el: default_2.ReactNode, modalId?: string, isDynamic?: boolean) => string;
18
- popModal: (idEl: string | default_2.ReactNode) => boolean;
19
- updateModalContent: (modalId: string, newContent: default_2.ReactNode) => void;
20
- getModalWindowRef: (modalId: string) => HTMLDivElement | undefined;
21
- focusModal: (modalId: string) => boolean;
22
- getModalOrderIndex: (modalId: string) => number;
23
- }
24
-
25
- export declare function BaseModalProvider({ children, wrapperId, renderMode, wrapperStyle }: {
26
- children: default_2.ReactNode;
27
- wrapperId?: string;
28
- renderMode?: RenderMode;
29
- wrapperStyle?: default_2.CSSProperties;
30
- }): JSX_2.Element;
31
-
32
- export declare const Button: ({ children, onClick }: ButtonProps) => JSX_2.Element;
33
-
34
- declare interface ButtonProps {
35
- children: default_2.ReactNode;
36
- onClick?: () => void;
37
- }
38
-
39
- declare class EventEmitter<T extends EventMap> extends EventTarget {
40
- private controller;
41
- on<K extends keyof T>(type: K, callback: (detail: T[K]) => void): this;
42
- once<K extends keyof T>(type: K, callback: (detail: T[K]) => void): this;
43
- emit<K extends keyof T>(type: K, detail: T[K]): boolean;
44
- removeAllListeners(): void;
45
- }
46
-
47
- declare type EventMap = Record<string, any>;
48
-
49
- export declare function Loading({ isLoading }: {
50
- isLoading: boolean;
51
- }): null;
52
-
53
- export declare const LoadingProvider: default_2.FC<{
54
- children: ReactNode;
55
- loadingComponent?: default_2.ComponentType | default_2.ReactElement;
56
- animationType?: AnimationType;
57
- animationDuration?: number;
58
- wrapperStyle?: default_2.CSSProperties;
59
- wrapperClassName?: string;
60
- wrapperId?: string;
61
- animationWrapperStyle?: default_2.CSSProperties;
62
- animationWrapperClassName?: string;
63
- animationWrapperId?: string;
64
- }>;
65
-
66
- export declare const RenderMode: {
67
- STACKED: number;
68
- CURRENT_ONLY: number;
69
- CURRENT_HIDDEN_STACK: number;
70
- };
71
-
72
- export declare type RenderMode = (typeof RenderMode)[keyof typeof RenderMode];
73
-
74
- export declare function useBaseModal(): BaseModalContextType;
75
-
76
- export declare function useDynamicModal(id?: string): [(el: JSX.Element) => ReactNode, () => void, () => void, () => void, string, boolean];
77
-
78
- export declare const useLoading: () => {
79
- asyncUseLoading: <R, _ extends any[]>(asyncFunction: Promise<R>) => Promise<R>;
80
- isLoading: boolean;
81
- loadingEventTarget: EventEmitter< {
82
- change: {
83
- isLoading: boolean;
84
- } | null;
85
- start: null;
86
- stop: null;
87
- }>;
88
- overrideLoading: (state: boolean) => void;
89
- startLoading: () => void;
90
- stopLoading: () => void;
91
- isLocalLoading: boolean;
92
- };
93
-
94
- export declare function useStaticModal(id?: string): [(el: React.ReactNode) => () => boolean, () => boolean, string, boolean, (newContent: React.ReactNode) => void];
95
-
96
- export { }
1
+ export {};
package/dist/index.esm.js CHANGED
@@ -1,309 +1 @@
1
- import { jsx as f, jsxs as S, Fragment as $ } from "react/jsx-runtime";
2
- import I, { useState as E, useRef as y, useEffect as R, createContext as T, useContext as k, useCallback as K } from "react";
3
- import { createPortal as D } from "react-dom";
4
- const Q = ({ children: o, onClick: e }) => /* @__PURE__ */ f("button", { onClick: e, children: o });
5
- class j extends EventTarget {
6
- constructor() {
7
- super(...arguments), this.controller = new AbortController();
8
- }
9
- on(e, n) {
10
- return this.addEventListener(
11
- e,
12
- (c) => n(c.detail),
13
- { signal: this.controller.signal }
14
- ), this;
15
- }
16
- once(e, n) {
17
- return this.addEventListener(
18
- e,
19
- (c) => n(c.detail),
20
- {
21
- signal: this.controller.signal,
22
- once: !0
23
- }
24
- ), this;
25
- }
26
- emit(e, n) {
27
- return this.dispatchEvent(new CustomEvent(e, { detail: n }));
28
- }
29
- removeAllListeners() {
30
- this.controller.abort(), this.controller = new AbortController();
31
- }
32
- }
33
- const C = new j(), M = {
34
- Spin: "spin",
35
- FadeInOut: "fadeInOut",
36
- None: "none"
37
- }, z = ({ animationType: o = M.Spin, animationDuration: e, children: n, style: c, className: u, id: r }) => {
38
- const d = o, g = o === M.Spin ? 1 : o === M.FadeInOut ? 2 : 0, l = e || g, a = o === M.Spin ? "linear" : o === M.FadeInOut ? "ease-in-out" : "linear", w = o === M.None ? "none" : `${d} ${l}s ${a} infinite`;
39
- return /* @__PURE__ */ f("div", { style: { animation: w, ...c }, className: u, id: r, children: n });
40
- }, H = () => /* @__PURE__ */ f("div", { id: "loading-circle", style: { width: "60px", height: "60px", border: "10px solid #f3f3f3", borderTop: "10px solid #009b4bff", borderRadius: "50%" } }), Y = () => /* @__PURE__ */ f("div", { style: { padding: "20px", fontSize: "25px", color: "#333", fontFamily: "system-ui, sans-serif" }, children: "Please wait..." }), U = T(void 0), X = ({ children: o, loadingComponent: e, animationType: n = M.FadeInOut, animationDuration: c, wrapperStyle: u, wrapperClassName: r, wrapperId: d, animationWrapperStyle: g, animationWrapperClassName: l, animationWrapperId: a }) => {
41
- e = e || (n === M.Spin ? H : Y);
42
- const [w, h] = E(0), [N, O] = E(null), m = N ?? w > 0, P = (p) => O(p), B = () => h((p) => p + 1), F = () => h((p) => Math.max(0, p - 1)), L = y(null);
43
- R(() => {
44
- C.emit("change", { isLoading: m }), C.emit(m ? "start" : "stop", null), m ? (L.current?.showModal(), document.body.setAttribute("inert", "")) : m || document.body.removeAttribute("inert");
45
- }, [w]), R(() => () => {
46
- h(0), C.removeAllListeners();
47
- }, []);
48
- const b = d || "loading-dialog";
49
- return /* @__PURE__ */ S(U.Provider, { value: { get isLoading() {
50
- return m;
51
- }, startLoading: B, stopLoading: F, loadingEventTarget: C, overrideLoading: P }, children: [
52
- o,
53
- m && D(
54
- /* @__PURE__ */ S($, { children: [
55
- /* @__PURE__ */ f("style", { children: `
56
- dialog#${b}[open] {
57
- display: flex !important;
58
- justify-content: center;
59
- align-items: center;
60
- width: 100vw;
61
- height: 100vh;
62
- max-width: 100%;
63
- max-height: 100%;
64
- }
65
- @keyframes spin {
66
- 0% { transform: rotate(0deg); }
67
- 100% { transform: rotate(360deg); }
68
- }
69
- @keyframes fadeInOut {
70
- 0%, 100% { opacity: 0.2; }
71
- 50% { opacity: 1; }
72
- }
73
- body:has(dialog#${b}[open]) {
74
- overflow: hidden;
75
- }
76
- body {
77
- scrollbar-gutter: stable;
78
- }
79
- ` }),
80
- /* @__PURE__ */ f(
81
- "dialog",
82
- {
83
- ref: L,
84
- style: {
85
- border: "none",
86
- padding: 0,
87
- backgroundColor: "rgba(0, 0, 0, 0.5)",
88
- backdropFilter: "blur(2px)",
89
- ...u
90
- },
91
- className: r,
92
- id: b,
93
- children: /* @__PURE__ */ f(z, { animationType: n, animationDuration: c, style: g, className: l, id: a, children: I.isValidElement(e) ? e : I.createElement(e) })
94
- }
95
- )
96
- ] }),
97
- document.body
98
- )
99
- ] });
100
- }, V = () => {
101
- const o = k(U);
102
- if (!o) throw new Error("useLoading must be used within a LoadingProvider");
103
- const e = y(0), { startLoading: n, stopLoading: c, isLoading: u, ...r } = o, d = () => {
104
- n(), e.current += 1;
105
- }, g = () => {
106
- e.current > 0 && (c(), e.current -= 1);
107
- };
108
- return {
109
- startLoading: d,
110
- stopLoading: g,
111
- get isLocalLoading() {
112
- return e.current > 0;
113
- },
114
- ...r,
115
- asyncUseLoading: async (a) => {
116
- d();
117
- try {
118
- return await a;
119
- } finally {
120
- g();
121
- }
122
- },
123
- isLoading: u
124
- };
125
- };
126
- function Z({ isLoading: o = !1 }) {
127
- const e = V();
128
- return R(() => (o ? e.startLoading() : e.stopLoading(), () => {
129
- o && e.stopLoading();
130
- }), [o]), null;
131
- }
132
- const A = T(void 0), x = {
133
- STACKED: 0,
134
- CURRENT_ONLY: 1,
135
- CURRENT_HIDDEN_STACK: 2
136
- };
137
- function ee({ children: o, wrapperId: e, renderMode: n = x.STACKED, wrapperStyle: c }) {
138
- const u = y(null), r = y(/* @__PURE__ */ new Map()), [d, g] = E(r.current), l = Array.from(d.values()), a = Array.from(d.keys()), w = y(/* @__PURE__ */ new Map()), [h, N] = E(void 0), O = (t, s = Math.random().toString(36).substring(2, 6), i = !1) => {
139
- if (a.indexOf(s) !== -1)
140
- return console.warn(`Modal with id ${s} already exists. Choose a different id.`), s;
141
- let _ = [t, i];
142
- return r.current = new Map(r.current), r.current.set(s, _), g(new Map(r.current)), s;
143
- }, m = (t) => {
144
- let s = "";
145
- if (typeof t != "string") {
146
- for (let [i, v] of r.current.entries())
147
- if (v[0] === t) {
148
- s = i;
149
- break;
150
- }
151
- } else typeof t == "string" && (s = t);
152
- return r.current.has(s) ? (r.current = new Map(r.current), r.current.delete(s), g(new Map(r.current)), !0) : !1;
153
- }, P = (t, s) => {
154
- if (r.current.has(t)) {
155
- let i = r.current.get(t);
156
- if (i[1] === !1) {
157
- console.warn(`Modal with id ${t} is dynamic. Cannot update content.`);
158
- return;
159
- }
160
- i[0] = s, r.current.set(t, i), g(new Map(r.current));
161
- }
162
- }, B = (t) => {
163
- if (!d.has(t)) return !1;
164
- let s = r.current.get(t);
165
- return r.current.delete(t), r.current.set(t, s), g(new Map(r.current)), !0;
166
- }, F = (t) => a.indexOf(t), L = (t) => w.current.get(t);
167
- R(() => {
168
- const t = a[a.length - 1];
169
- t !== void 0 ? (u.current?.showModal(), document.body.setAttribute("inert", "")) : t === void 0 && (u.current?.close(), document.body.removeAttribute("inert")), N(t);
170
- }, [d]);
171
- const b = e || "base-modal-wrapper", p = K((t, s) => {
172
- t ? w.current.set(s, t) : w.current.delete(s);
173
- }, []), W = () => {
174
- switch (n) {
175
- case x.STACKED:
176
- return l.map(([t, s], i) => /* @__PURE__ */ f(
177
- "div",
178
- {
179
- ref: (v) => p(v, a[i]),
180
- className: "modal-window",
181
- id: a[i],
182
- style: { display: "block", zIndex: a[i] === h ? 1e3 : 100 },
183
- ...h !== a[i] ? { inert: "" } : {},
184
- children: s ? null : t
185
- },
186
- a[i]
187
- ));
188
- case x.CURRENT_ONLY:
189
- return l.length > 0 ? /* @__PURE__ */ f(
190
- "div",
191
- {
192
- id: a[l.length - 1],
193
- ref: (t) => p(t, a[l.length - 1]),
194
- className: "modal-window",
195
- style: { display: "block" },
196
- children: l[l.length - 1][1] ? null : l[l.length - 1][0]
197
- },
198
- a[l.length - 1]
199
- ) : null;
200
- case x.CURRENT_HIDDEN_STACK:
201
- return l.length > 0 ? l.map(([t, s], i) => /* @__PURE__ */ f(
202
- "div",
203
- {
204
- ref: (v) => p(v, a[i]),
205
- id: a[i],
206
- className: "modal-window",
207
- style: {
208
- display: h === a[i] ? "block" : "none"
209
- },
210
- ...h !== a[i] ? { inert: "" } : {},
211
- children: s ? null : t
212
- },
213
- a[i]
214
- )) : null;
215
- }
216
- };
217
- return /* @__PURE__ */ S(A.Provider, { value: { modalCount: 0, get renderMode() {
218
- return n;
219
- }, pushModal: O, popModal: m, currentModalId: h, updateModalContent: P, getModalWindowRef: L, focusModal: B, getModalOrderIndex: F }, children: [
220
- o,
221
- a.length === 0 ? null : D(
222
- /* @__PURE__ */ S($, { children: [
223
- /* @__PURE__ */ f("style", { children: `
224
- dialog#${b}[open] {
225
- display: flex !important;
226
- justify-content: center;
227
- align-items: center;
228
- width: 100vw;
229
- height: 100vh;
230
- max-width: 100%;
231
- max-height: 100%;
232
- }
233
- body:has(dialog#${b}[open]) {
234
- overflow: hidden;
235
- }
236
- body {
237
- scrollbar-gutter: stable;
238
- }
239
- .modal-wrapper{
240
- border: none;
241
- padding: 0;
242
- background: unset;
243
- }
244
- .modal-window {
245
- position: absolute;
246
- width: 100%;
247
- height: 100%;
248
- display: none;
249
- background-color: rgba(0, 0, 0, 0.1);
250
- backdrop-filter: blur(2px);
251
- }
252
- ` }),
253
- /* @__PURE__ */ f(
254
- "dialog",
255
- {
256
- className: "modal-wrapper",
257
- ref: u,
258
- id: b,
259
- style: c,
260
- children: W()
261
- }
262
- )
263
- ] }),
264
- document.body
265
- )
266
- ] });
267
- }
268
- function te() {
269
- const o = k(A);
270
- if (!o) throw new Error("useBaseModal must be used within a BaseModalProvider");
271
- return o;
272
- }
273
- function ne(o = Math.random().toString(36).substring(2, 6)) {
274
- const e = k(A);
275
- if (!e) throw new Error("useBaseModal must be used within a BaseModalProvider");
276
- let n = y(o);
277
- const c = (d) => (e.pushModal(d, n.current), u), u = () => e.popModal(n.current), r = (d) => {
278
- e.updateModalContent(n.current, d);
279
- };
280
- return [c, u, n.current, e.currentModalId === n.current, r];
281
- }
282
- function re(o = Math.random().toString(36).substring(2, 6)) {
283
- const e = k(A);
284
- if (!e) throw new Error("useBaseModal must be used within a BaseModalProvider");
285
- let n = y(o);
286
- const c = e.currentModalId === n.current;
287
- return [(l) => e.getModalWindowRef(n.current) ? D(
288
- l,
289
- e.getModalWindowRef(n.current)
290
- ) : null, () => {
291
- e.pushModal(null, n.current, !0)[1];
292
- }, () => {
293
- e.popModal(n.current);
294
- }, () => {
295
- e.focusModal(n.current);
296
- }, n.current, c];
297
- }
298
- export {
299
- M as AnimationType,
300
- ee as BaseModalProvider,
301
- Q as Button,
302
- Z as Loading,
303
- X as LoadingProvider,
304
- x as RenderMode,
305
- te as useBaseModal,
306
- re as useDynamicModal,
307
- V as useLoading,
308
- ne as useStaticModal
309
- };
1
+
@@ -0,0 +1,25 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),r=require("react"),$=require("react-dom");class C extends EventTarget{constructor(){super(...arguments),this.controller=new AbortController}on(t,n){return this.addEventListener(t,o=>n(o.detail),{signal:this.controller.signal}),this}once(t,n){return this.addEventListener(t,o=>n(o.detail),{signal:this.controller.signal,once:!0}),this}emit(t,n){return this.dispatchEvent(new CustomEvent(t,{detail:n}))}removeAllListeners(){this.controller.abort(),this.controller=new AbortController}}const m=new C,s={Spin:"spin",FadeInOut:"fadeInOut",None:"none"},F=({animationType:e=s.Spin,animationDuration:t,children:n,style:o,className:u,id:g,prefix:d})=>{const l=e,p=e===s.Spin?1:e===s.FadeInOut?2:0,f=t||p,c=e===s.Spin?"linear":e===s.FadeInOut?"ease-in-out":"linear",L=e===s.None?"none":`${d}-${l} ${f}s ${c} infinite`;return i.jsx("div",{style:{animation:L,...o},className:u,id:g,children:n})},I=()=>i.jsx("div",{id:"loading-circle",style:{width:"60px",height:"60px",border:"10px solid #f3f3f3",borderTop:"10px solid #009b4bff",borderRadius:"50%"}}),O=()=>i.jsx("div",{style:{padding:"20px",fontSize:"25px",color:"#333",fontFamily:"system-ui, sans-serif"},children:"Please wait..."}),y=r.createContext(void 0),R=({children:e=null,loadingComponent:t,animationType:n=s.Spin,animationDuration:o,wrapperStyle:u,wrapperClassName:g,wrapperId:d,animationWrapperStyle:l,animationWrapperClassName:p,animationWrapperId:f})=>{t=t||(n===s.Spin?I:O);const c=r.useRef(Math.random().toString(36).substring(2,6).replace(/[0-9]/g,"")),[L,x]=r.useState(0),[S,E]=r.useState(null),a=S??L>0,j=h=>E(h),A=()=>x(h=>h+1),P=()=>x(h=>Math.max(0,h-1)),v=r.useRef(null);r.useEffect(()=>{m.emit("change",{isLoading:a}),m.emit(a?"start":"stop",null),a?(v.current?.showModal(),document.body.setAttribute("inert","")):a||document.body.removeAttribute("inert")},[L,a]),r.useEffect(()=>()=>{x(0),m.removeAllListeners()},[]);const b=d||"loading-wrapper-"+c.current;return i.jsxs(y.Provider,{value:{get isLoading(){return a},startLoading:A,stopLoading:P,loadingEventTarget:m,overrideLoading:j},children:[e,a&&$.createPortal(i.jsxs(i.Fragment,{children:[i.jsx("style",{children:`
2
+ dialog#${b}[open] {
3
+ display: flex !important;
4
+ justify-content: center;
5
+ align-items: center;
6
+ width: 100vw;
7
+ height: 100vh;
8
+ max-width: 100%;
9
+ max-height: 100%;
10
+ }
11
+ @keyframes ${c.current}-spin {
12
+ 0% { transform: rotate(0deg); }
13
+ 100% { transform: rotate(360deg); }
14
+ }
15
+ @keyframes ${c.current}-fadeInOut {
16
+ 0%, 100% { opacity: 0.2; }
17
+ 50% { opacity: 1; }
18
+ }
19
+ body:has(dialog#${b}[open]) {
20
+ overflow: hidden;
21
+ }
22
+ body {
23
+ scrollbar-gutter: stable;
24
+ }
25
+ `}),i.jsx("dialog",{ref:v,style:{border:"none",padding:0,backgroundColor:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)",...u},className:g,id:b,children:i.jsx(F,{animationType:n,animationDuration:o,style:l,className:p,id:f,prefix:c.current,children:r.isValidElement(t)?t:r.createElement(t)})})]}),document.body)]})},w=()=>{const e=r.useContext(y);if(!e)throw new Error("useLoading must be used within a LoadingProvider");const t=r.useRef(0),{startLoading:n,stopLoading:o,isLoading:u,...g}=e,d=()=>{n(),t.current+=1},l=()=>{t.current>0&&(o(),t.current-=1)};return{startLoading:d,stopLoading:l,get isLocalLoading(){return t.current>0},...g,asyncUseLoading:async f=>{d();try{return await f}finally{l()}},isLoading:u}};function N({isLoading:e=!1}){const t=w();return r.useEffect(()=>(e?t.startLoading():t.stopLoading(),()=>{e&&t.stopLoading()}),[e]),null}exports.AnimationType=s;exports.Loading=N;exports.LoadingProvider=R;exports.useLoading=w;
@@ -0,0 +1,3 @@
1
+ export { LoadingProvider, AnimationType } from './contexts/LoadingContext';
2
+ export { default as Loading } from './components/Loading';
3
+ export { default as useLoading } from './hooks/useLoading';
@@ -0,0 +1,147 @@
1
+ import { jsx as l, jsxs as w, Fragment as P } from "react/jsx-runtime";
2
+ import S, { useRef as v, useState as E, useEffect as x, createContext as N, useContext as k } from "react";
3
+ import { createPortal as R } from "react-dom";
4
+ class j extends EventTarget {
5
+ constructor() {
6
+ super(...arguments), this.controller = new AbortController();
7
+ }
8
+ on(t, n) {
9
+ return this.addEventListener(
10
+ t,
11
+ (r) => n(r.detail),
12
+ { signal: this.controller.signal }
13
+ ), this;
14
+ }
15
+ once(t, n) {
16
+ return this.addEventListener(
17
+ t,
18
+ (r) => n(r.detail),
19
+ {
20
+ signal: this.controller.signal,
21
+ once: !0
22
+ }
23
+ ), this;
24
+ }
25
+ emit(t, n) {
26
+ return this.dispatchEvent(new CustomEvent(t, { detail: n }));
27
+ }
28
+ removeAllListeners() {
29
+ this.controller.abort(), this.controller = new AbortController();
30
+ }
31
+ }
32
+ const m = new j(), o = {
33
+ Spin: "spin",
34
+ FadeInOut: "fadeInOut",
35
+ None: "none"
36
+ }, M = ({ animationType: e = o.Spin, animationDuration: t, children: n, style: r, className: c, id: u, prefix: s }) => {
37
+ const a = e, p = e === o.Spin ? 1 : e === o.FadeInOut ? 2 : 0, g = t || p, d = e === o.Spin ? "linear" : e === o.FadeInOut ? "ease-in-out" : "linear", h = e === o.None ? "none" : `${s}-${a} ${g}s ${d} infinite`;
38
+ return /* @__PURE__ */ l("div", { style: { animation: h, ...r }, className: c, id: u, children: n });
39
+ }, U = () => /* @__PURE__ */ l("div", { id: "loading-circle", style: { width: "60px", height: "60px", border: "10px solid #f3f3f3", borderTop: "10px solid #009b4bff", borderRadius: "50%" } }), W = () => /* @__PURE__ */ l("div", { style: { padding: "20px", fontSize: "25px", color: "#333", fontFamily: "system-ui, sans-serif" }, children: "Please wait..." }), A = N(void 0), B = ({
40
+ children: e = null,
41
+ loadingComponent: t,
42
+ animationType: n = o.Spin,
43
+ animationDuration: r,
44
+ wrapperStyle: c,
45
+ wrapperClassName: u,
46
+ wrapperId: s,
47
+ animationWrapperStyle: a,
48
+ animationWrapperClassName: p,
49
+ animationWrapperId: g
50
+ }) => {
51
+ t = t || (n === o.Spin ? U : W);
52
+ const d = v(Math.random().toString(36).substring(2, 6).replace(/[0-9]/g, "")), [h, L] = E(0), [$, C] = E(null), i = $ ?? h > 0, F = (f) => C(f), I = () => L((f) => f + 1), O = () => L((f) => Math.max(0, f - 1)), y = v(null);
53
+ x(() => {
54
+ m.emit("change", { isLoading: i }), m.emit(i ? "start" : "stop", null), i ? (y.current?.showModal(), document.body.setAttribute("inert", "")) : i || document.body.removeAttribute("inert");
55
+ }, [h, i]), x(() => () => {
56
+ L(0), m.removeAllListeners();
57
+ }, []);
58
+ const b = s || "loading-wrapper-" + d.current;
59
+ return /* @__PURE__ */ w(A.Provider, { value: { get isLoading() {
60
+ return i;
61
+ }, startLoading: I, stopLoading: O, loadingEventTarget: m, overrideLoading: F }, children: [
62
+ e,
63
+ i && R(
64
+ /* @__PURE__ */ w(P, { children: [
65
+ /* @__PURE__ */ l("style", { children: `
66
+ dialog#${b}[open] {
67
+ display: flex !important;
68
+ justify-content: center;
69
+ align-items: center;
70
+ width: 100vw;
71
+ height: 100vh;
72
+ max-width: 100%;
73
+ max-height: 100%;
74
+ }
75
+ @keyframes ${d.current}-spin {
76
+ 0% { transform: rotate(0deg); }
77
+ 100% { transform: rotate(360deg); }
78
+ }
79
+ @keyframes ${d.current}-fadeInOut {
80
+ 0%, 100% { opacity: 0.2; }
81
+ 50% { opacity: 1; }
82
+ }
83
+ body:has(dialog#${b}[open]) {
84
+ overflow: hidden;
85
+ }
86
+ body {
87
+ scrollbar-gutter: stable;
88
+ }
89
+ ` }),
90
+ /* @__PURE__ */ l(
91
+ "dialog",
92
+ {
93
+ ref: y,
94
+ style: {
95
+ border: "none",
96
+ padding: 0,
97
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
98
+ backdropFilter: "blur(2px)",
99
+ ...c
100
+ },
101
+ className: u,
102
+ id: b,
103
+ children: /* @__PURE__ */ l(M, { animationType: n, animationDuration: r, style: a, className: p, id: g, prefix: d.current, children: S.isValidElement(t) ? t : S.createElement(t) })
104
+ }
105
+ )
106
+ ] }),
107
+ document.body
108
+ )
109
+ ] });
110
+ }, z = () => {
111
+ const e = k(A);
112
+ if (!e) throw new Error("useLoading must be used within a LoadingProvider");
113
+ const t = v(0), { startLoading: n, stopLoading: r, isLoading: c, ...u } = e, s = () => {
114
+ n(), t.current += 1;
115
+ }, a = () => {
116
+ t.current > 0 && (r(), t.current -= 1);
117
+ };
118
+ return {
119
+ startLoading: s,
120
+ stopLoading: a,
121
+ get isLocalLoading() {
122
+ return t.current > 0;
123
+ },
124
+ ...u,
125
+ asyncUseLoading: async (g) => {
126
+ s();
127
+ try {
128
+ return await g;
129
+ } finally {
130
+ a();
131
+ }
132
+ },
133
+ isLoading: c
134
+ };
135
+ };
136
+ function G({ isLoading: e = !1 }) {
137
+ const t = z();
138
+ return x(() => (e ? t.startLoading() : t.stopLoading(), () => {
139
+ e && t.stopLoading();
140
+ }), [e]), null;
141
+ }
142
+ export {
143
+ o as AnimationType,
144
+ G as Loading,
145
+ B as LoadingProvider,
146
+ z as useLoading
147
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),u=require("react"),R=require("react-dom"),m=u.createContext(void 0),g={STACKED:0,CURRENT_ONLY:1,CURRENT_HIDDEN_STACK:2};function T({children:d,wrapperId:s,renderMode:a=g.STACKED,wrapperStyle:h}){const M=u.useRef(null),t=u.useRef(new Map),[c,p]=u.useState(t.current),l=Array.from(c.values()),o=Array.from(c.keys()),b=u.useRef(new Map),[w,v]=u.useState(void 0),x=(e,r=Math.random().toString(36).substring(2,6),n=!1)=>{if(o.indexOf(r)!==-1)return console.warn(`Modal with id ${r} already exists. Choose a different id.`),r;let D=[e,n];return t.current=new Map(t.current),t.current.set(r,D),p(new Map(t.current)),r},S=e=>{let r="";if(typeof e!="string"){for(let[n,f]of t.current.entries())if(f[0]===e){r=n;break}}else typeof e=="string"&&(r=e);return t.current.has(r)?(t.current=new Map(t.current),t.current.delete(r),p(new Map(t.current)),!0):!1},k=(e,r)=>{if(t.current.has(e)){let n=t.current.get(e);if(n[1]===!1){console.warn(`Modal with id ${e} is dynamic. Cannot update content.`);return}n[0]=r,t.current.set(e,n),p(new Map(t.current))}},E=e=>{if(!c.has(e))return!1;let r=t.current.get(e);return t.current.delete(e),t.current.set(e,r),p(new Map(t.current)),!0},N=e=>o.indexOf(e),B=e=>b.current.get(e);u.useEffect(()=>{const e=o[o.length-1];e!==void 0?(M.current?.showModal(),document.body.setAttribute("inert","")):e===void 0&&(M.current?.close(),document.body.removeAttribute("inert")),v(e)},[c]);const y=s||"base-modal-wrapper",C=u.useCallback((e,r)=>{e?b.current.set(r,e):b.current.delete(r)},[]),j=()=>{switch(a){case g.STACKED:return l.map(([e,r],n)=>i.jsx("div",{ref:f=>C(f,o[n]),className:"modal-window",id:o[n],style:{display:"block",zIndex:o[n]===w?1e3:100},...w!==o[n]?{inert:""}:{},children:r?null:e},o[n]));case g.CURRENT_ONLY:return l.length>0?i.jsx("div",{id:o[l.length-1],ref:e=>C(e,o[l.length-1]),className:"modal-window",style:{display:"block"},children:l[l.length-1][1]?null:l[l.length-1][0]},o[l.length-1]):null;case g.CURRENT_HIDDEN_STACK:return l.length>0?l.map(([e,r],n)=>i.jsx("div",{ref:f=>C(f,o[n]),id:o[n],className:"modal-window",style:{display:w===o[n]?"block":"none"},...w!==o[n]?{inert:""}:{},children:r?null:e},o[n])):null}};return i.jsxs(m.Provider,{value:{modalCount:0,get renderMode(){return a},pushModal:x,popModal:S,currentModalId:w,updateModalContent:k,getModalWindowRef:B,focusModal:E,getModalOrderIndex:N},children:[d,o.length===0?null:R.createPortal(i.jsxs(i.Fragment,{children:[i.jsx("style",{children:`
2
+ dialog#${y}[open] {
3
+ display: flex !important;
4
+ justify-content: center;
5
+ align-items: center;
6
+ width: 100vw;
7
+ height: 100vh;
8
+ max-width: 100%;
9
+ max-height: 100%;
10
+ }
11
+ body:has(dialog#${y}[open]) {
12
+ overflow: hidden;
13
+ }
14
+ body {
15
+ scrollbar-gutter: stable;
16
+ }
17
+ .modal-wrapper{
18
+ border: none;
19
+ padding: 0;
20
+ background: unset;
21
+ }
22
+ .modal-window {
23
+ position: absolute;
24
+ width: 100%;
25
+ height: 100%;
26
+ display: none;
27
+ background-color: rgba(0, 0, 0, 0.1);
28
+ backdrop-filter: blur(2px);
29
+ }
30
+ `}),i.jsx("dialog",{className:"modal-wrapper",ref:M,id:y,style:h,children:j()})]}),document.body)]})}function A(){const d=u.useContext(m);if(!d)throw new Error("useBaseModal must be used within a BaseModalProvider");return d}function P(d=Math.random().toString(36).substring(2,6)){const s=u.useContext(m);if(!s)throw new Error("useBaseModal must be used within a BaseModalProvider");let a=u.useRef(d);const h=c=>(s.pushModal(c,a.current),M),M=()=>s.popModal(a.current),t=c=>{s.updateModalContent(a.current,c)};return[h,M,a.current,s.currentModalId===a.current,t]}function O(d=Math.random().toString(36).substring(2,6)){const s=u.useContext(m);if(!s)throw new Error("useBaseModal must be used within a BaseModalProvider");let a=u.useRef(d);const h=s.currentModalId===a.current;return[l=>s.getModalWindowRef(a.current)?R.createPortal(l,s.getModalWindowRef(a.current)):null,()=>{s.pushModal(null,a.current,!0)[1]},()=>{s.popModal(a.current)},()=>{s.focusModal(a.current)},a.current,h]}exports.BaseModalProvider=T;exports.RenderMode=g;exports.useBaseModal=A;exports.useDynamicModal=O;exports.useStaticModal=P;
@@ -0,0 +1,4 @@
1
+ export { default as BaseModalProvider } from './contexts/ModalContext';
2
+ export { default as useBaseModal, RenderMode } from './hooks/useBaseModal';
3
+ export { default as useStaticModal } from './hooks/useStaticModal';
4
+ export { default as useDynamicModal } from './hooks/useDynamicModal';
@@ -0,0 +1,176 @@
1
+ import { jsxs as R, Fragment as K, jsx as h } from "react/jsx-runtime";
2
+ import { useRef as w, useState as k, useEffect as O, useCallback as U, createContext as W, useContext as v } from "react";
3
+ import { createPortal as S } from "react-dom";
4
+ const m = W(void 0), g = {
5
+ STACKED: 0,
6
+ CURRENT_ONLY: 1,
7
+ CURRENT_HIDDEN_STACK: 2
8
+ };
9
+ function H({ children: d, wrapperId: l, renderMode: a = g.STACKED, wrapperStyle: f }) {
10
+ const u = w(null), t = w(/* @__PURE__ */ new Map()), [c, M] = k(t.current), s = Array.from(c.values()), o = Array.from(c.keys()), b = w(/* @__PURE__ */ new Map()), [p, x] = k(void 0), E = (e, r = Math.random().toString(36).substring(2, 6), n = !1) => {
11
+ if (o.indexOf(r) !== -1)
12
+ return console.warn(`Modal with id ${r} already exists. Choose a different id.`), r;
13
+ let _ = [e, n];
14
+ return t.current = new Map(t.current), t.current.set(r, _), M(new Map(t.current)), r;
15
+ }, N = (e) => {
16
+ let r = "";
17
+ if (typeof e != "string") {
18
+ for (let [n, i] of t.current.entries())
19
+ if (i[0] === e) {
20
+ r = n;
21
+ break;
22
+ }
23
+ } else typeof e == "string" && (r = e);
24
+ return t.current.has(r) ? (t.current = new Map(t.current), t.current.delete(r), M(new Map(t.current)), !0) : !1;
25
+ }, A = (e, r) => {
26
+ if (t.current.has(e)) {
27
+ let n = t.current.get(e);
28
+ if (n[1] === !1) {
29
+ console.warn(`Modal with id ${e} is dynamic. Cannot update content.`);
30
+ return;
31
+ }
32
+ n[0] = r, t.current.set(e, n), M(new Map(t.current));
33
+ }
34
+ }, B = (e) => {
35
+ if (!c.has(e)) return !1;
36
+ let r = t.current.get(e);
37
+ return t.current.delete(e), t.current.set(e, r), M(new Map(t.current)), !0;
38
+ }, T = (e) => o.indexOf(e), D = (e) => b.current.get(e);
39
+ O(() => {
40
+ const e = o[o.length - 1];
41
+ e !== void 0 ? (u.current?.showModal(), document.body.setAttribute("inert", "")) : e === void 0 && (u.current?.close(), document.body.removeAttribute("inert")), x(e);
42
+ }, [c]);
43
+ const y = l || "base-modal-wrapper", C = U((e, r) => {
44
+ e ? b.current.set(r, e) : b.current.delete(r);
45
+ }, []), P = () => {
46
+ switch (a) {
47
+ case g.STACKED:
48
+ return s.map(([e, r], n) => /* @__PURE__ */ h(
49
+ "div",
50
+ {
51
+ ref: (i) => C(i, o[n]),
52
+ className: "modal-window",
53
+ id: o[n],
54
+ style: { display: "block", zIndex: o[n] === p ? 1e3 : 100 },
55
+ ...p !== o[n] ? { inert: "" } : {},
56
+ children: r ? null : e
57
+ },
58
+ o[n]
59
+ ));
60
+ case g.CURRENT_ONLY:
61
+ return s.length > 0 ? /* @__PURE__ */ h(
62
+ "div",
63
+ {
64
+ id: o[s.length - 1],
65
+ ref: (e) => C(e, o[s.length - 1]),
66
+ className: "modal-window",
67
+ style: { display: "block" },
68
+ children: s[s.length - 1][1] ? null : s[s.length - 1][0]
69
+ },
70
+ o[s.length - 1]
71
+ ) : null;
72
+ case g.CURRENT_HIDDEN_STACK:
73
+ return s.length > 0 ? s.map(([e, r], n) => /* @__PURE__ */ h(
74
+ "div",
75
+ {
76
+ ref: (i) => C(i, o[n]),
77
+ id: o[n],
78
+ className: "modal-window",
79
+ style: {
80
+ display: p === o[n] ? "block" : "none"
81
+ },
82
+ ...p !== o[n] ? { inert: "" } : {},
83
+ children: r ? null : e
84
+ },
85
+ o[n]
86
+ )) : null;
87
+ }
88
+ };
89
+ return /* @__PURE__ */ R(m.Provider, { value: { modalCount: 0, get renderMode() {
90
+ return a;
91
+ }, pushModal: E, popModal: N, currentModalId: p, updateModalContent: A, getModalWindowRef: D, focusModal: B, getModalOrderIndex: T }, children: [
92
+ d,
93
+ o.length === 0 ? null : S(
94
+ /* @__PURE__ */ R(K, { children: [
95
+ /* @__PURE__ */ h("style", { children: `
96
+ dialog#${y}[open] {
97
+ display: flex !important;
98
+ justify-content: center;
99
+ align-items: center;
100
+ width: 100vw;
101
+ height: 100vh;
102
+ max-width: 100%;
103
+ max-height: 100%;
104
+ }
105
+ body:has(dialog#${y}[open]) {
106
+ overflow: hidden;
107
+ }
108
+ body {
109
+ scrollbar-gutter: stable;
110
+ }
111
+ .modal-wrapper{
112
+ border: none;
113
+ padding: 0;
114
+ background: unset;
115
+ }
116
+ .modal-window {
117
+ position: absolute;
118
+ width: 100%;
119
+ height: 100%;
120
+ display: none;
121
+ background-color: rgba(0, 0, 0, 0.1);
122
+ backdrop-filter: blur(2px);
123
+ }
124
+ ` }),
125
+ /* @__PURE__ */ h(
126
+ "dialog",
127
+ {
128
+ className: "modal-wrapper",
129
+ ref: u,
130
+ id: y,
131
+ style: f,
132
+ children: P()
133
+ }
134
+ )
135
+ ] }),
136
+ document.body
137
+ )
138
+ ] });
139
+ }
140
+ function I() {
141
+ const d = v(m);
142
+ if (!d) throw new Error("useBaseModal must be used within a BaseModalProvider");
143
+ return d;
144
+ }
145
+ function L(d = Math.random().toString(36).substring(2, 6)) {
146
+ const l = v(m);
147
+ if (!l) throw new Error("useBaseModal must be used within a BaseModalProvider");
148
+ let a = w(d);
149
+ const f = (c) => (l.pushModal(c, a.current), u), u = () => l.popModal(a.current), t = (c) => {
150
+ l.updateModalContent(a.current, c);
151
+ };
152
+ return [f, u, a.current, l.currentModalId === a.current, t];
153
+ }
154
+ function Y(d = Math.random().toString(36).substring(2, 6)) {
155
+ const l = v(m);
156
+ if (!l) throw new Error("useBaseModal must be used within a BaseModalProvider");
157
+ let a = w(d);
158
+ const f = l.currentModalId === a.current;
159
+ return [(s) => l.getModalWindowRef(a.current) ? S(
160
+ s,
161
+ l.getModalWindowRef(a.current)
162
+ ) : null, () => {
163
+ l.pushModal(null, a.current, !0)[1];
164
+ }, () => {
165
+ l.popModal(a.current);
166
+ }, () => {
167
+ l.focusModal(a.current);
168
+ }, a.current, f];
169
+ }
170
+ export {
171
+ H as BaseModalProvider,
172
+ g as RenderMode,
173
+ I as useBaseModal,
174
+ Y as useDynamicModal,
175
+ L as useStaticModal
176
+ };
@@ -0,0 +1,9 @@
1
+ type EventMap = Record<string, any>;
2
+ export default class EventEmitter<T extends EventMap> extends EventTarget {
3
+ private controller;
4
+ on<K extends keyof T>(type: K, callback: (detail: T[K]) => void): this;
5
+ once<K extends keyof T>(type: K, callback: (detail: T[K]) => void): this;
6
+ emit<K extends keyof T>(type: K, detail: T[K]): boolean;
7
+ removeAllListeners(): void;
8
+ }
9
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roks-rjsc",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "A React component library",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -35,7 +35,8 @@
35
35
  },
36
36
  "sideEffects": false,
37
37
  "publishConfig": {
38
- "access": "public"
38
+ "access": "public",
39
+ "provenance": true
39
40
  },
40
41
  "repository": {
41
42
  "type": "git",
@@ -51,8 +52,25 @@
51
52
  "import": "./dist/index.esm.js",
52
53
  "require": "./dist/index.cjs.js"
53
54
  },
55
+ "./modal": {
56
+ "types": "./dist/modal.d.ts",
57
+ "import": "./dist/modal.esm.js",
58
+ "require": "./dist/modal.cjs.js"
59
+ },
60
+ "./loading": {
61
+ "types": "./dist/loading.d.ts",
62
+ "import": "./dist/loading.esm.js",
63
+ "require": "./dist/loading.cjs.js"
64
+ },
54
65
  "./package.json": "./package.json"
55
66
  },
67
+ "typesVersions": {
68
+ "*": {
69
+ "*": [
70
+ "dist/*"
71
+ ]
72
+ }
73
+ },
56
74
  "keywords": [
57
75
  "react",
58
76
  "component",
@@ -60,4 +78,4 @@
60
78
  ],
61
79
  "author": "rokku",
62
80
  "license": "MIT"
63
- }
81
+ }