@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 +1 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -2
- package/package.json +1 -1
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"),
|
|
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