@interop-ui/react-presence
Advanced tools
Comparing version 0.0.1-0 to 0.0.1-1
@@ -1,2 +0,2 @@ | ||
var n,e,t=require("@xstate/fsm"),r=t.createMachine,i=t.interpret,u=require("@interop-ui/react-utils").useComposedRefs,o=(n={},e=require("react"),Object.keys(e).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(n,t,{enumerable:!0,get:function(){return e[t]}})})),n);function a(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(n)))return;var t=[],r=!0,i=!1,u=void 0;try{for(var o,a=n[Symbol.iterator]();!(r=(o=a.next()).done)&&(t.push(o.value),!e||t.length!==e);r=!0);}catch(n){i=!0,u=n}finally{try{r||null==a.return||a.return()}finally{if(i)throw u}}return t}(n,e)||function(n,e){if(!n)return;if("string"==typeof n)return c(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);"Object"===t&&n.constructor&&(t=n.constructor.name);if("Map"===t||"Set"===t)return Array.from(n);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return c(n,e)}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function s(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(n)))return;var t=[],r=!0,i=!1,u=void 0;try{for(var o,a=n[Symbol.iterator]();!(r=(o=a.next()).done)&&(t.push(o.value),!e||t.length!==e);r=!0);}catch(n){i=!0,u=n}finally{try{r||null==a.return||a.return()}finally{if(i)throw u}}return t}(n,e)||function(n,e){if(!n)return;if("string"==typeof n)return f(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);"Object"===t&&n.constructor&&(t=n.constructor.name);if("Map"===t||"Set"===t)return Array.from(n);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return f(n,e)}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}var l=function(n){var e=n.present,t=n.children,c=function(n){var e=s(o.useState(),2),t=e[0],u=e[1],c=s(o.useState(),2),f=c[0],l=c[1],m=o.useRef(n),v=o.useRef(),y=function(n){var e=a(o.useState((function(){return i(r(n))})),1)[0],t=a(o.useState(n.initial),2),u=t[0],c=t[1],s=a(o.useState(n.context),2),f=s[0],l=s[1];return o.useEffect((function(){var n=e.subscribe((function(n){c(n.value),l(n.context)}));return e.start(),function(){n.unsubscribe(),e.stop()}}),[e]),o.useMemo((function(){return{state:u,context:f,send:e.send}}),[u,f,e])}({id:"presence",initial:n?"mounted":"unmounted",states:{mounted:{on:{UNMOUNT:"unmounted",ANIMATION_RUN:"unmountSuspended",TRANSITION_RUN:"unmountSuspended"}},unmountSuspended:{on:{ANIMATION_END:"unmounted",TRANSITION_END:"unmounted"}},unmounted:{on:{MOUNT:"mounted"}}}}),p=y.state,N=y.send;return o.useEffect((function(){if(t){var n=getComputedStyle(t);v.current=d(n),l(n)}}),[t]),o.useEffect((function(){return function(){var n,e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){},r=requestAnimationFrame((function(){n=requestAnimationFrame((function(){e=requestAnimationFrame(t)}))}));return function(){cancelAnimationFrame(r),cancelAnimationFrame(n),cancelAnimationFrame(e)}}((function(){var e=m.current,t=v.current,r=d(f),i=String(t)!==String(r);v.current=r,m.current=n,N(n?"MOUNT":e&&i?"none"===(null==f?void 0:f.display)?"UNMOUNT":"ANIMATION_RUN":"UNMOUNT")}))}),[n,f,N]),o.useEffect((function(){if(t){var n=function(){return N("ANIMATION_END")},e=function(){return N("TRANSITION_RUN")},r=function(){return N("TRANSITION_END")};return t.addEventListener("animationcancel",n),t.addEventListener("animationend",n),t.addEventListener("transitionrun",e),t.addEventListener("transitioncancel",r),t.addEventListener("transitionend",r),function(){t.removeEventListener("animationcancel",n),t.removeEventListener("animationend",n),t.removeEventListener("transitionrun",e),t.removeEventListener("transitioncancel",r),t.removeEventListener("transitionend",r)}}}),[t,n,N]),{ref:function(n){return u(n)},isPresent:["mounted","unmountSuspended"].includes(p)}}(e),f="function"==typeof t?t({present:c.isPresent}):o.Children.only(t),l=u(c.ref,f.ref);return"function"==typeof t||c.isPresent?o.cloneElement(f,{ref:l}):null};function d(n){return(null==n?void 0:n.animationName)||"none"}exports.Presence=l,l.displayName="Presence"; | ||
var n,e,t=require("@xstate/fsm"),r=t.createMachine,i=t.interpret,u=require("@interop-ui/react-utils").useComposedRefs,o=(n={},e=require("react"),Object.keys(e).forEach((function(t){"default"!==t&&"__esModule"!==t&&Object.defineProperty(n,t,{enumerable:!0,get:function(){return e[t]}})})),n);function a(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(n)))return;var t=[],r=!0,i=!1,u=void 0;try{for(var o,a=n[Symbol.iterator]();!(r=(o=a.next()).done)&&(t.push(o.value),!e||t.length!==e);r=!0);}catch(n){i=!0,u=n}finally{try{r||null==a.return||a.return()}finally{if(i)throw u}}return t}(n,e)||function(n,e){if(!n)return;if("string"==typeof n)return c(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);"Object"===t&&n.constructor&&(t=n.constructor.name);if("Map"===t||"Set"===t)return Array.from(n);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return c(n,e)}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function s(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(n)))return;var t=[],r=!0,i=!1,u=void 0;try{for(var o,a=n[Symbol.iterator]();!(r=(o=a.next()).done)&&(t.push(o.value),!e||t.length!==e);r=!0);}catch(n){i=!0,u=n}finally{try{r||null==a.return||a.return()}finally{if(i)throw u}}return t}(n,e)||function(n,e){if(!n)return;if("string"==typeof n)return f(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);"Object"===t&&n.constructor&&(t=n.constructor.name);if("Map"===t||"Set"===t)return Array.from(n);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return f(n,e)}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}var l=function(n){var e=n.present,t=n.children,c=function(n){var e=s(o.useState(),2),t=e[0],u=e[1],c=s(o.useState(),2),f=c[0],l=c[1],m=o.useRef(n),v=o.useRef(),y=function(n){var e=a(o.useState((function(){return i(r(n))})),1)[0],t=a(o.useState(n.initial),2),u=t[0],c=t[1],s=a(o.useState(n.context),2),f=s[0],l=s[1];return o.useEffect((function(){var n=e.subscribe((function(n){c(n.value),l(n.context)}));return e.start(),function(){n.unsubscribe(),e.stop()}}),[e]),o.useMemo((function(){return{state:u,context:f,send:e.send}}),[u,f,e])}({id:"presence",initial:n?"mounted":"unmounted",states:{mounted:{on:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended",TRANSITION_OUT:"unmountSuspended"}},unmountSuspended:{on:{ANIMATION_END:"unmounted",TRANSITION_END:"unmounted"}},unmounted:{on:{MOUNT:"mounted"}}}}),p=y.state,A=y.send;return o.useEffect((function(){if(t){var n=getComputedStyle(t);v.current=d(n),l(n)}}),[t]),o.useEffect((function(){return function(){var n,e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){},r=requestAnimationFrame((function(){n=requestAnimationFrame((function(){e=requestAnimationFrame(t)}))}));return function(){cancelAnimationFrame(r),cancelAnimationFrame(n),cancelAnimationFrame(e)}}((function(){var e=m.current,t=v.current,r=d(f),i=String(t)!==String(r);v.current=r,m.current=n,A(n?"MOUNT":e&&i?"none"===(null==f?void 0:f.display)?"UNMOUNT":"ANIMATION_OUT":"UNMOUNT")}))}),[n,f,A]),o.useEffect((function(){if(t){var e=function(e){var r=m.current,i=!n&&r;e.target===t&&i&&A("TRANSITION_OUT")},r=function(n){n.target===t&&A("TRANSITION_END")},i=function(n){n.target===t&&A("ANIMATION_END")};return t.addEventListener("animationcancel",i),t.addEventListener("animationend",i),t.addEventListener("transitionrun",e),t.addEventListener("transitioncancel",r),t.addEventListener("transitionend",r),function(){t.removeEventListener("animationcancel",i),t.removeEventListener("animationend",i),t.removeEventListener("transitionrun",e),t.removeEventListener("transitioncancel",r),t.removeEventListener("transitionend",r)}}}),[t,n,A]),{ref:function(n){return u(n)},isPresent:["mounted","unmountSuspended"].includes(p)}}(e),f="function"==typeof t?t({present:c.isPresent}):o.Children.only(t),l=u(c.ref,f.ref);return"function"==typeof t||c.isPresent?o.cloneElement(f,{ref:l}):null};function d(n){return(null==n?void 0:n.animationName)||"none"}exports.Presence=l,l.displayName="Presence"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import{createMachine as e,interpret as n}from"@xstate/fsm";import{useComposedRefs as t}from"@interop-ui/react-utils";import*as r from"react";export const Presence=s=>{const{present:o,children:u}=s,a=function(t){const[s,o]=r.useState(),[u,a]=r.useState(),c=r.useRef(t),m=r.useRef(),{state:d,send:N}=function(t){const[i]=r.useState((()=>n(e(t)))),[s,o]=r.useState(t.initial),[u,a]=r.useState(t.context);return r.useEffect((()=>{const e=i.subscribe((e=>{o(e.value),a(e.context)}));return i.start(),()=>{e.unsubscribe(),i.stop()}}),[i]),r.useMemo((()=>({state:s,context:u,send:i.send})),[s,u,i])}({id:"presence",initial:t?"mounted":"unmounted",states:{mounted:{on:{UNMOUNT:"unmounted",ANIMATION_RUN:"unmountSuspended",TRANSITION_RUN:"unmountSuspended"}},unmountSuspended:{on:{ANIMATION_END:"unmounted",TRANSITION_END:"unmounted"}},unmounted:{on:{MOUNT:"mounted"}}}});return r.useEffect((()=>{if(s){const e=getComputedStyle(s);m.current=i(e),a(e)}}),[s]),r.useEffect((()=>function(e=(()=>{})){let n,t;const r=requestAnimationFrame((()=>{n=requestAnimationFrame((()=>{t=requestAnimationFrame(e)}))}));return()=>{cancelAnimationFrame(r),cancelAnimationFrame(n),cancelAnimationFrame(t)}}((()=>{const e=c.current,n=m.current,r=i(u),s=String(n)!==String(r);m.current=r,c.current=t,N(t?"MOUNT":e&&s?"none"===(null==u?void 0:u.display)?"UNMOUNT":"ANIMATION_RUN":"UNMOUNT")}))),[t,u,N]),r.useEffect((()=>{if(s){const e=()=>N("ANIMATION_END"),n=()=>N("TRANSITION_RUN"),t=()=>N("TRANSITION_END");return s.addEventListener("animationcancel",e),s.addEventListener("animationend",e),s.addEventListener("transitionrun",n),s.addEventListener("transitioncancel",t),s.addEventListener("transitionend",t),()=>{s.removeEventListener("animationcancel",e),s.removeEventListener("animationend",e),s.removeEventListener("transitionrun",n),s.removeEventListener("transitioncancel",t),s.removeEventListener("transitionend",t)}}}),[s,t,N]),{ref:e=>o(e),isPresent:["mounted","unmountSuspended"].includes(d)}}(o),c="function"==typeof u?u({present:a.isPresent}):r.Children.only(u),m=t(a.ref,c.ref);return"function"==typeof u||a.isPresent?r.cloneElement(c,{ref:m}):null};function i(e){return(null==e?void 0:e.animationName)||"none"}Presence.displayName="Presence"; | ||
import{createMachine as e,interpret as n}from"@xstate/fsm";import{useComposedRefs as t}from"@interop-ui/react-utils";import*as r from"react";export const Presence=s=>{const{present:o,children:u}=s,a=function(t){const[s,o]=r.useState(),[u,a]=r.useState(),c=r.useRef(t),m=r.useRef(),{state:d,send:N}=function(t){const[i]=r.useState((()=>n(e(t)))),[s,o]=r.useState(t.initial),[u,a]=r.useState(t.context);return r.useEffect((()=>{const e=i.subscribe((e=>{o(e.value),a(e.context)}));return i.start(),()=>{e.unsubscribe(),i.stop()}}),[i]),r.useMemo((()=>({state:s,context:u,send:i.send})),[s,u,i])}({id:"presence",initial:t?"mounted":"unmounted",states:{mounted:{on:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended",TRANSITION_OUT:"unmountSuspended"}},unmountSuspended:{on:{ANIMATION_END:"unmounted",TRANSITION_END:"unmounted"}},unmounted:{on:{MOUNT:"mounted"}}}});return r.useEffect((()=>{if(s){const e=getComputedStyle(s);m.current=i(e),a(e)}}),[s]),r.useEffect((()=>function(e=(()=>{})){let n,t;const r=requestAnimationFrame((()=>{n=requestAnimationFrame((()=>{t=requestAnimationFrame(e)}))}));return()=>{cancelAnimationFrame(r),cancelAnimationFrame(n),cancelAnimationFrame(t)}}((()=>{const e=c.current,n=m.current,r=i(u),s=String(n)!==String(r);m.current=r,c.current=t,N(t?"MOUNT":e&&s?"none"===(null==u?void 0:u.display)?"UNMOUNT":"ANIMATION_OUT":"UNMOUNT")}))),[t,u,N]),r.useEffect((()=>{if(s){const e=e=>{const n=c.current,r=!t&&n;e.target===s&&r&&N("TRANSITION_OUT")},n=e=>{e.target===s&&N("TRANSITION_END")},r=e=>{e.target===s&&N("ANIMATION_END")};return s.addEventListener("animationcancel",r),s.addEventListener("animationend",r),s.addEventListener("transitionrun",e),s.addEventListener("transitioncancel",n),s.addEventListener("transitionend",n),()=>{s.removeEventListener("animationcancel",r),s.removeEventListener("animationend",r),s.removeEventListener("transitionrun",e),s.removeEventListener("transitioncancel",n),s.removeEventListener("transitionend",n)}}}),[s,t,N]),{ref:e=>o(e),isPresent:["mounted","unmountSuspended"].includes(d)}}(o),c="function"==typeof u?u({present:a.isPresent}):r.Children.only(u),m=t(a.ref,c.ref);return"function"==typeof u||a.isPresent?r.cloneElement(c,{ref:m}):null};function i(e){return(null==e?void 0:e.animationName)||"none"}Presence.displayName="Presence"; | ||
//# sourceMappingURL=index.module.js.map |
{ | ||
"name": "@interop-ui/react-presence", | ||
"version": "0.0.1-0", | ||
"version": "0.0.1-1", | ||
"license": "MIT", | ||
@@ -20,3 +20,3 @@ "source": "src/index.ts", | ||
"dependencies": { | ||
"@interop-ui/react-utils": "0.0.1-14", | ||
"@interop-ui/react-utils": "0.0.1-15", | ||
"@xstate/fsm": "^1.5.1" | ||
@@ -23,0 +23,0 @@ }, |
@@ -13,17 +13,2 @@ # `react-presence` | ||
Manages mounting/unmounting of its child component. It will suspend the unmount phase if the child component is animating or transitioning via CSS. | ||
```js | ||
import * as React from 'react'; | ||
import { Presence } from '@interop-ui/react-presence'; | ||
function MyComponent(props) { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
return ( | ||
<Presence present={isOpen}> | ||
<div {...props}>Content</div> | ||
</Presence> | ||
); | ||
} | ||
``` | ||
This is an internal utility, not intended for public usage. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32015
14
+ Added@interop-ui/react-polymorphic@0.0.1-2(transitive)
+ Added@interop-ui/react-utils@0.0.1-15(transitive)
+ Added@interop-ui/utils@0.0.1-7(transitive)
- Removed@interop-ui/react-utils@0.0.1-14(transitive)
- Removed@interop-ui/utils@0.0.1-6(transitive)