@mateosuarezdev/react-ui 1.0.0 → 1.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/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),o=require("react"),h=require("react-dom"),a=o.createContext(null),P=({children:e,value:r})=>f.jsx(a.Provider,{value:r,children:e}),K=()=>{const e=o.useContext(a);if(!e)throw new Error("useAliveScope must be wrapped within AliveScopeProvider");return e},S=({children:e})=>{const[r,l]=o.useState({}),n=o.useRef({}),c=o.useRef({}),p=(t,u,s)=>{if(!r[t]){const i=document.createElement("div");return t&&(i.id=t),s&&(i.className=s),l(v=>({...v,[t]:{children:u,element:i}})),n.current[t]=[],c.current[t]=[],n.current&&n.current[t]&&n.current[t].forEach(v=>v(t)),i}return n.current&&n.current[t]&&n.current[t].forEach(i=>i(t)),r[t].element},m=t=>{l(u=>{const s={...u};return delete s[t],s}),c.current&&c.current[t]&&c.current[t].forEach(u=>u(t))};return f.jsxs(P,{value:{getPortalElement:p,dropPortalElement:m},children:[e,Object.entries(r).map(([t,{children:u,element:s}])=>f.jsx(j,{id:t,onMountCallbacks:n,onDropCallbacks:c,children:u,element:s},t))]})},A=o.createContext(null),x=({children:e,value:r})=>f.jsx(A.Provider,{value:r,children:e}),j=o.memo(({id:e,onMountCallbacks:r,onDropCallbacks:l,children:n,element:c})=>{const p=(t,u={runOnFirstMount:!1})=>{o.useEffect(()=>{const s=()=>{if(document.getElementById(e))t(e);else{const v=new MutationObserver((b,E)=>{document.getElementById(e)&&(t(e),E.disconnect())});return v.observe(document.body,{childList:!0,subtree:!0}),()=>v.disconnect()}};return u?.runOnFirstMount&&s(),r.current[e].push(s),()=>{r.current[e]=r.current[e].filter(i=>i!==s)}},[])},m=t=>{o.useEffect(()=>(l.current[e].push(t),()=>{l.current[e]=l.current[e].filter(u=>u!==t)}),[])};return f.jsx(x,{value:{keepAliveId:e,onKeepAliveMount:p,onKeepAliveDrop:m},children:h.createPortal(n,c,e)})}),w=()=>{const e=o.useContext(A);if(!e)throw new Error("useKeepAlive must be used within KeepAliveProvider");return e},C=({aliveKey:e,children:r,enabled:l=!0,...n})=>{const c=o.useRef(null),{getPortalElement:p}=K();return o.useEffect(()=>{const m=p(e,r,n.className);return l&&c.current&&c.current.replaceWith(m),()=>{}},[e,r,l,n]),f.jsx("div",{...n,ref:c})};exports.AliveScope=S;exports.KeepAlive=C;exports.KeepAliveContext=A;exports.KeepAliveProvider=x;exports.useKeepAlive=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),o=require("react"),E=require("react-dom"),A=o.createContext(null),h=({children:e,value:r})=>f.jsx(A.Provider,{value:r,children:e}),P=()=>{const e=o.useContext(A);if(!e)throw new Error("useAliveScope must be wrapped within AliveScopeProvider");return e},S=({children:e})=>{const[r,l]=o.useState({}),n=o.useRef({}),c=o.useRef({}),p=(t,u,s)=>{if(!r[t]){const i=document.createElement("div");return t&&(i.id=t),s&&(i.className=s),l(v=>({...v,[t]:{children:u,element:i}})),n.current[t]=[],c.current[t]=[],n.current&&n.current[t]&&n.current[t].forEach(v=>v(t)),i}return n.current&&n.current[t]&&n.current[t].forEach(i=>i(t)),r[t].element},m=t=>{l(u=>{const s={...u};return delete s[t],s}),c.current&&c.current[t]&&c.current[t].forEach(u=>u(t))};return f.jsxs(h,{value:{getPortalElement:p,dropPortalElement:m},children:[e,Object.entries(r).map(([t,{children:u,element:s}])=>f.jsx(K,{id:t,onMountCallbacks:n,onDropCallbacks:c,children:u,element:s},t))]})},a=o.createContext(null),j=({children:e,value:r})=>f.jsx(a.Provider,{value:r,children:e}),K=o.memo(({id:e,onMountCallbacks:r,onDropCallbacks:l,children:n,element:c})=>{const p=(t,u={runOnFirstMount:!1})=>{o.useEffect(()=>{const s=()=>{if(document.getElementById(e))t(e);else{const v=new MutationObserver((g,x)=>{document.getElementById(e)&&(t(e),x.disconnect())});return v.observe(document.body,{childList:!0,subtree:!0}),()=>v.disconnect()}};return u?.runOnFirstMount&&s(),r.current[e].push(s),()=>{r.current[e]=r.current[e].filter(i=>i!==s)}},[])},m=t=>{o.useEffect(()=>(l.current[e].push(t),()=>{l.current[e]=l.current[e].filter(u=>u!==t)}),[])};return f.jsx(j,{value:{keepAliveId:e,onKeepAliveMount:p,onKeepAliveDrop:m},children:E.createPortal(n,c,e)})}),w=()=>{const e=o.useContext(a);if(!e)throw new Error("useKeepAlive must be used within KeepAliveProvider");return e},b=({aliveKey:e,children:r,enabled:l=!0,...n})=>{const c=o.useRef(null),{getPortalElement:p}=P();return o.useEffect(()=>{const m=p(e,r,n.className);return l&&c.current&&c.current.replaceWith(m),()=>{}},[e,r,l,n]),f.jsx("div",{...n,ref:c})};exports.AliveScope=S;exports.KeepAlive=b;exports.useKeepAlive=w;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- import { Context } from 'react';
2
- import { JSX } from 'react/jsx-runtime';
3
-
4
1
  export declare const AliveScope: React.FC<AliveScopeProps>;
5
2
 
6
3
  declare type AliveScopeProps = {
@@ -9,8 +6,6 @@ declare type AliveScopeProps = {
9
6
 
10
7
  export declare const KeepAlive: React.FC<KeepAliveProps>;
11
8
 
12
- export declare const KeepAliveContext: Context<KeepAliveContextType | null>;
13
-
14
9
  declare type KeepAliveContextType = {
15
10
  keepAliveId: string;
16
11
  onKeepAliveMount: (callback: (id: string) => void, options?: {
@@ -25,11 +20,6 @@ declare type KeepAliveProps = React.HTMLAttributes<HTMLDivElement> & {
25
20
  enabled?: boolean;
26
21
  };
27
22
 
28
- export declare const KeepAliveProvider: ({ children, value, }: {
29
- children: React.ReactNode;
30
- value: KeepAliveContextType;
31
- }) => JSX.Element;
32
-
33
23
  export declare const useKeepAlive: () => KeepAliveContextType;
34
24
 
35
25
  export { }
package/dist/index.js CHANGED
@@ -111,8 +111,6 @@ const h = a(null), b = ({
111
111
  export {
112
112
  F as AliveScope,
113
113
  R as KeepAlive,
114
- P as KeepAliveContext,
115
- M as KeepAliveProvider,
116
114
  N as useKeepAlive
117
115
  };
118
116
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mateosuarezdev/react-ui",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Dynamic React UI library designed to work alongside @mateosuarezdev/react-router",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",