@thomasjahoda-forks/radix-ui-react-presence 1.1.4-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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 WorkOS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `react-presence`
2
+
3
+ This is an internal utility, not intended for public usage.
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+
3
+ interface PresenceProps {
4
+ children: React.ReactElement | ((props: {
5
+ present: boolean;
6
+ }) => React.ReactElement);
7
+ present: boolean;
8
+ }
9
+ declare const Presence: React.FC<PresenceProps>;
10
+ declare const Root: React.FC<PresenceProps>;
11
+
12
+ export { Presence, type PresenceProps, Root };
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+
3
+ interface PresenceProps {
4
+ children: React.ReactElement | ((props: {
5
+ present: boolean;
6
+ }) => React.ReactElement);
7
+ present: boolean;
8
+ }
9
+ declare const Presence: React.FC<PresenceProps>;
10
+ declare const Root: React.FC<PresenceProps>;
11
+
12
+ export { Presence, type PresenceProps, Root };
package/dist/index.js ADDED
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ Presence: () => Presence,
35
+ Root: () => Root
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/presence.tsx
40
+ var React2 = __toESM(require("react"));
41
+ var import_react_compose_refs = require("@radix-ui/react-compose-refs");
42
+ var import_react_use_layout_effect = require("@radix-ui/react-use-layout-effect");
43
+
44
+ // src/use-state-machine.tsx
45
+ var React = __toESM(require("react"));
46
+ function useStateMachine(initialState, machine) {
47
+ return React.useReducer((state, event) => {
48
+ const nextState = machine[state][event];
49
+ return nextState ?? state;
50
+ }, initialState);
51
+ }
52
+
53
+ // src/presence.tsx
54
+ var Presence = (props) => {
55
+ const { present, children } = props;
56
+ const presence = usePresence(present);
57
+ const child = typeof children === "function" ? children({ present: presence.isPresent }) : React2.Children.only(children);
58
+ const ref = (0, import_react_compose_refs.useComposedRefs)(presence.ref, getElementRef(child));
59
+ const forceMount = typeof children === "function";
60
+ return forceMount || presence.isPresent ? React2.cloneElement(child, { ref }) : null;
61
+ };
62
+ Presence.displayName = "Presence";
63
+ function usePresence(present) {
64
+ const [node, setNode] = React2.useState();
65
+ const stylesRef = React2.useRef(null);
66
+ const prevPresentRef = React2.useRef(present);
67
+ const prevAnimationNameRef = React2.useRef("none");
68
+ const initialState = present ? "mounted" : "unmounted";
69
+ const [state, send] = useStateMachine(initialState, {
70
+ mounted: {
71
+ UNMOUNT: "unmounted",
72
+ ANIMATION_OUT: "unmountSuspended"
73
+ },
74
+ unmountSuspended: {
75
+ MOUNT: "mounted",
76
+ ANIMATION_END: "unmounted"
77
+ },
78
+ unmounted: {
79
+ MOUNT: "mounted"
80
+ }
81
+ });
82
+ React2.useEffect(() => {
83
+ const timeout = setTimeout(() => {
84
+ prevAnimationNameRef.current = state === "mounted" ? getAnimationName(stylesRef.current) : "none";
85
+ }, 0);
86
+ return () => clearTimeout(timeout);
87
+ }, [state]);
88
+ (0, import_react_use_layout_effect.useLayoutEffect)(() => {
89
+ const styles = stylesRef.current;
90
+ const wasPresent = prevPresentRef.current;
91
+ const hasPresentChanged = wasPresent !== present;
92
+ if (hasPresentChanged) {
93
+ const prevAnimationName = prevAnimationNameRef.current;
94
+ const currentAnimationName = getAnimationName(styles);
95
+ if (present) {
96
+ send("MOUNT");
97
+ } else if (currentAnimationName === "none" || styles?.display === "none") {
98
+ send("UNMOUNT");
99
+ } else {
100
+ const isAnimating = prevAnimationName !== currentAnimationName;
101
+ if (wasPresent && isAnimating) {
102
+ send("ANIMATION_OUT");
103
+ } else {
104
+ send("UNMOUNT");
105
+ }
106
+ }
107
+ prevPresentRef.current = present;
108
+ }
109
+ }, [present, send]);
110
+ (0, import_react_use_layout_effect.useLayoutEffect)(() => {
111
+ if (node) {
112
+ let timeoutId;
113
+ const ownerWindow = node.ownerDocument.defaultView ?? window;
114
+ const handleAnimationEnd = (event) => {
115
+ const currentAnimationName = getAnimationName(stylesRef.current);
116
+ const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
117
+ if (event.target === node && isCurrentAnimation) {
118
+ send("ANIMATION_END");
119
+ if (!prevPresentRef.current) {
120
+ const currentFillMode = node.style.animationFillMode;
121
+ node.style.animationFillMode = "forwards";
122
+ timeoutId = ownerWindow.setTimeout(() => {
123
+ if (node.style.animationFillMode === "forwards") {
124
+ node.style.animationFillMode = currentFillMode;
125
+ }
126
+ });
127
+ }
128
+ }
129
+ };
130
+ const handleAnimationStart = (event) => {
131
+ if (event.target === node) {
132
+ prevAnimationNameRef.current = getAnimationName(stylesRef.current);
133
+ }
134
+ };
135
+ node.addEventListener("animationstart", handleAnimationStart);
136
+ node.addEventListener("animationcancel", handleAnimationEnd);
137
+ node.addEventListener("animationend", handleAnimationEnd);
138
+ return () => {
139
+ ownerWindow.clearTimeout(timeoutId);
140
+ node.removeEventListener("animationstart", handleAnimationStart);
141
+ node.removeEventListener("animationcancel", handleAnimationEnd);
142
+ node.removeEventListener("animationend", handleAnimationEnd);
143
+ };
144
+ } else {
145
+ send("ANIMATION_END");
146
+ }
147
+ }, [node, send]);
148
+ return {
149
+ isPresent: ["mounted", "unmountSuspended"].includes(state),
150
+ ref: React2.useCallback((node2) => {
151
+ stylesRef.current = node2 ? getComputedStyle(node2) : null;
152
+ setNode(node2);
153
+ }, [])
154
+ };
155
+ }
156
+ function getAnimationName(styles) {
157
+ return styles?.animationName || "none";
158
+ }
159
+ function getElementRef(element) {
160
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
161
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
162
+ if (mayWarn) {
163
+ return element.ref;
164
+ }
165
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
166
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
167
+ if (mayWarn) {
168
+ return element.props.ref;
169
+ }
170
+ return element.props.ref || element.ref;
171
+ }
172
+ var Root = Presence;
173
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/presence.tsx", "../src/use-state-machine.tsx"],
4
+ "sourcesContent": ["'use client';\nexport { Presence, Root } from './presence';\nexport type { PresenceProps } from './presence';\n", "import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { useStateMachine } from './use-state-machine';\n\ninterface PresenceProps {\n children: React.ReactElement | ((props: { present: boolean }) => React.ReactElement);\n present: boolean;\n}\n\nconst Presence: React.FC<PresenceProps> = (props) => {\n const { present, children } = props;\n const presence = usePresence(present);\n\n const child = (\n typeof children === 'function'\n ? children({ present: presence.isPresent })\n : React.Children.only(children)\n ) as React.ReactElement<{ ref?: React.Ref<HTMLElement> }>;\n\n const ref = useComposedRefs(presence.ref, getElementRef(child));\n const forceMount = typeof children === 'function';\n return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;\n};\n\nPresence.displayName = 'Presence';\n\n/* -------------------------------------------------------------------------------------------------\n * usePresence\n * -----------------------------------------------------------------------------------------------*/\n\nfunction usePresence(present: boolean) {\n const [node, setNode] = React.useState<HTMLElement>();\n const stylesRef = React.useRef<CSSStyleDeclaration | null>(null);\n const prevPresentRef = React.useRef(present);\n const prevAnimationNameRef = React.useRef<string>('none');\n const initialState = present ? 'mounted' : 'unmounted';\n const [state, send] = useStateMachine(initialState, {\n mounted: {\n UNMOUNT: 'unmounted',\n ANIMATION_OUT: 'unmountSuspended',\n },\n unmountSuspended: {\n MOUNT: 'mounted',\n ANIMATION_END: 'unmounted',\n },\n unmounted: {\n MOUNT: 'mounted',\n },\n });\n\n React.useEffect(() => {\n // only read animationName after the full task has run, so we don't cause forced reflow due to accessing the styles\n const timeout = setTimeout(() => {\n prevAnimationNameRef.current =\n state === 'mounted' ? getAnimationName(stylesRef.current) : 'none';\n }, 0);\n return () => clearTimeout(timeout);\n }, [state]);\n\n useLayoutEffect(() => {\n const styles = stylesRef.current;\n const wasPresent = prevPresentRef.current;\n const hasPresentChanged = wasPresent !== present;\n\n if (hasPresentChanged) {\n const prevAnimationName = prevAnimationNameRef.current;\n const currentAnimationName = getAnimationName(styles);\n\n if (present) {\n send('MOUNT');\n } else if (currentAnimationName === 'none' || styles?.display === 'none') {\n // If there is no exit animation or the element is hidden, animations won't run\n // so we unmount instantly\n send('UNMOUNT');\n } else {\n /**\n * When `present` changes to `false`, we check changes to animation-name to\n * determine whether an animation has started. We chose this approach (reading\n * computed styles) because there is no `animationrun` event and `animationstart`\n * fires after `animation-delay` has expired which would be too late.\n */\n const isAnimating = prevAnimationName !== currentAnimationName;\n\n if (wasPresent && isAnimating) {\n send('ANIMATION_OUT');\n } else {\n send('UNMOUNT');\n }\n }\n\n prevPresentRef.current = present;\n }\n }, [present, send]);\n\n useLayoutEffect(() => {\n if (node) {\n let timeoutId: number;\n const ownerWindow = node.ownerDocument.defaultView ?? window;\n /**\n * Triggering an ANIMATION_OUT during an ANIMATION_IN will fire an `animationcancel`\n * event for ANIMATION_IN after we have entered `unmountSuspended` state. So, we\n * make sure we only trigger ANIMATION_END for the currently active animation.\n */\n const handleAnimationEnd = (event: AnimationEvent) => {\n const currentAnimationName = getAnimationName(stylesRef.current);\n // The event.animationName is unescaped for CSS syntax,\n // so we need to escape it to compare with the animationName computed from the style.\n const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));\n if (event.target === node && isCurrentAnimation) {\n // With React 18 concurrency this update is applied a frame after the\n // animation ends, creating a flash of visible content. By setting the\n // animation fill mode to \"forwards\", we force the node to keep the\n // styles of the last keyframe, removing the flash.\n //\n // Previously we flushed the update via ReactDom.flushSync, but with\n // exit animations this resulted in the node being removed from the\n // DOM before the synthetic animationEnd event was dispatched, meaning\n // user-provided event handlers would not be called.\n // https://github.com/radix-ui/primitives/pull/1849\n send('ANIMATION_END');\n if (!prevPresentRef.current) {\n const currentFillMode = node.style.animationFillMode;\n node.style.animationFillMode = 'forwards';\n // Reset the style after the node had time to unmount (for cases\n // where the component chooses not to unmount). Doing this any\n // sooner than `setTimeout` (e.g. with `requestAnimationFrame`)\n // still causes a flash.\n timeoutId = ownerWindow.setTimeout(() => {\n if (node.style.animationFillMode === 'forwards') {\n node.style.animationFillMode = currentFillMode;\n }\n });\n }\n }\n };\n const handleAnimationStart = (event: AnimationEvent) => {\n if (event.target === node) {\n // if animation occurred, store its name as the previous animation.\n prevAnimationNameRef.current = getAnimationName(stylesRef.current);\n }\n };\n node.addEventListener('animationstart', handleAnimationStart);\n node.addEventListener('animationcancel', handleAnimationEnd);\n node.addEventListener('animationend', handleAnimationEnd);\n return () => {\n ownerWindow.clearTimeout(timeoutId);\n node.removeEventListener('animationstart', handleAnimationStart);\n node.removeEventListener('animationcancel', handleAnimationEnd);\n node.removeEventListener('animationend', handleAnimationEnd);\n };\n } else {\n // Transition to the unmounted state if the node is removed prematurely.\n // We avoid doing so during cleanup as the node may change but still exist.\n send('ANIMATION_END');\n }\n }, [node, send]);\n\n return {\n isPresent: ['mounted', 'unmountSuspended'].includes(state),\n ref: React.useCallback((node: HTMLElement) => {\n stylesRef.current = node ? getComputedStyle(node) : null;\n setNode(node);\n }, []),\n };\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction getAnimationName(styles: CSSStyleDeclaration | null) {\n return styles?.animationName || 'none';\n}\n\n// Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`\n// After React 19 accessing `element.ref` does the opposite.\n// https://github.com/facebook/react/pull/28348\n//\n// Access the ref using the method that doesn't yield a warning.\nfunction getElementRef(element: React.ReactElement<{ ref?: React.Ref<unknown> }>) {\n // React <=18 in DEV\n let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get;\n let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element as any).ref;\n }\n\n // React 19 in DEV\n getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get;\n mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return element.props.ref;\n }\n\n // Not DEV\n return element.props.ref || (element as any).ref;\n}\n\nconst Root = Presence;\n\nexport {\n Presence,\n //\n Root,\n};\nexport type { PresenceProps };\n", "import * as React from 'react';\n\ntype Machine<S> = { [k: string]: { [k: string]: S } };\ntype MachineState<T> = keyof T;\ntype MachineEvent<T> = keyof UnionToIntersection<T[keyof T]>;\n\n// \uD83E\uDD2F https://fettblog.eu/typescript-union-to-intersection/\ntype UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any\n ? R\n : never;\n\nexport function useStateMachine<M>(\n initialState: MachineState<M>,\n machine: M & Machine<MachineState<M>>\n) {\n return React.useReducer((state: MachineState<M>, event: MachineEvent<M>): MachineState<M> => {\n const nextState = (machine[state] as any)[event];\n return nextState ?? state;\n }, initialState);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,SAAuB;AACvB,gCAAgC;AAChC,qCAAgC;;;ACFhC,YAAuB;AAWhB,SAAS,gBACd,cACA,SACA;AACA,SAAa,iBAAW,CAAC,OAAwB,UAA4C;AAC3F,UAAM,YAAa,QAAQ,KAAK,EAAU,KAAK;AAC/C,WAAO,aAAa;AAAA,EACtB,GAAG,YAA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BAAoB,gBAAgB,kBAAkB;AAAA,MAC7D;AAAA,IACF,OAAO;AAGL,WAAK,eAAe;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,MAAM,IAAI,CAAC;AAEf,SAAO;AAAA,IACL,WAAW,CAAC,WAAW,kBAAkB,EAAE,SAAS,KAAK;AAAA,IACzD,KAAW,mBAAY,CAACC,UAAsB;AAC5C,gBAAU,UAAUA,QAAO,iBAAiBA,KAAI,IAAI;AACpD,cAAQA,KAAI;AAAA,IACd,GAAG,CAAC,CAAC;AAAA,EACP;AACF;AAIA,SAAS,iBAAiB,QAAoC;AAC5D,SAAO,QAAQ,iBAAiB;AAClC;AAOA,SAAS,cAAc,SAA2D;AAEhF,MAAI,SAAS,OAAO,yBAAyB,QAAQ,OAAO,KAAK,GAAG;AACpE,MAAI,UAAU,UAAU,oBAAoB,UAAU,OAAO;AAC7D,MAAI,SAAS;AACX,WAAQ,QAAgB;AAAA,EAC1B;AAGA,WAAS,OAAO,yBAAyB,SAAS,KAAK,GAAG;AAC1D,YAAU,UAAU,oBAAoB,UAAU,OAAO;AACzD,MAAI,SAAS;AACX,WAAO,QAAQ,MAAM;AAAA,EACvB;AAGA,SAAO,QAAQ,MAAM,OAAQ,QAAgB;AAC/C;AAEA,IAAM,OAAO;",
6
+ "names": ["React", "node"]
7
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,141 @@
1
+ "use client";
2
+
3
+ // src/presence.tsx
4
+ import * as React2 from "react";
5
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
6
+ import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
7
+
8
+ // src/use-state-machine.tsx
9
+ import * as React from "react";
10
+ function useStateMachine(initialState, machine) {
11
+ return React.useReducer((state, event) => {
12
+ const nextState = machine[state][event];
13
+ return nextState ?? state;
14
+ }, initialState);
15
+ }
16
+
17
+ // src/presence.tsx
18
+ var Presence = (props) => {
19
+ const { present, children } = props;
20
+ const presence = usePresence(present);
21
+ const child = typeof children === "function" ? children({ present: presence.isPresent }) : React2.Children.only(children);
22
+ const ref = useComposedRefs(presence.ref, getElementRef(child));
23
+ const forceMount = typeof children === "function";
24
+ return forceMount || presence.isPresent ? React2.cloneElement(child, { ref }) : null;
25
+ };
26
+ Presence.displayName = "Presence";
27
+ function usePresence(present) {
28
+ const [node, setNode] = React2.useState();
29
+ const stylesRef = React2.useRef(null);
30
+ const prevPresentRef = React2.useRef(present);
31
+ const prevAnimationNameRef = React2.useRef("none");
32
+ const initialState = present ? "mounted" : "unmounted";
33
+ const [state, send] = useStateMachine(initialState, {
34
+ mounted: {
35
+ UNMOUNT: "unmounted",
36
+ ANIMATION_OUT: "unmountSuspended"
37
+ },
38
+ unmountSuspended: {
39
+ MOUNT: "mounted",
40
+ ANIMATION_END: "unmounted"
41
+ },
42
+ unmounted: {
43
+ MOUNT: "mounted"
44
+ }
45
+ });
46
+ React2.useEffect(() => {
47
+ const timeout = setTimeout(() => {
48
+ prevAnimationNameRef.current = state === "mounted" ? getAnimationName(stylesRef.current) : "none";
49
+ }, 0);
50
+ return () => clearTimeout(timeout);
51
+ }, [state]);
52
+ useLayoutEffect(() => {
53
+ const styles = stylesRef.current;
54
+ const wasPresent = prevPresentRef.current;
55
+ const hasPresentChanged = wasPresent !== present;
56
+ if (hasPresentChanged) {
57
+ const prevAnimationName = prevAnimationNameRef.current;
58
+ const currentAnimationName = getAnimationName(styles);
59
+ if (present) {
60
+ send("MOUNT");
61
+ } else if (currentAnimationName === "none" || styles?.display === "none") {
62
+ send("UNMOUNT");
63
+ } else {
64
+ const isAnimating = prevAnimationName !== currentAnimationName;
65
+ if (wasPresent && isAnimating) {
66
+ send("ANIMATION_OUT");
67
+ } else {
68
+ send("UNMOUNT");
69
+ }
70
+ }
71
+ prevPresentRef.current = present;
72
+ }
73
+ }, [present, send]);
74
+ useLayoutEffect(() => {
75
+ if (node) {
76
+ let timeoutId;
77
+ const ownerWindow = node.ownerDocument.defaultView ?? window;
78
+ const handleAnimationEnd = (event) => {
79
+ const currentAnimationName = getAnimationName(stylesRef.current);
80
+ const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
81
+ if (event.target === node && isCurrentAnimation) {
82
+ send("ANIMATION_END");
83
+ if (!prevPresentRef.current) {
84
+ const currentFillMode = node.style.animationFillMode;
85
+ node.style.animationFillMode = "forwards";
86
+ timeoutId = ownerWindow.setTimeout(() => {
87
+ if (node.style.animationFillMode === "forwards") {
88
+ node.style.animationFillMode = currentFillMode;
89
+ }
90
+ });
91
+ }
92
+ }
93
+ };
94
+ const handleAnimationStart = (event) => {
95
+ if (event.target === node) {
96
+ prevAnimationNameRef.current = getAnimationName(stylesRef.current);
97
+ }
98
+ };
99
+ node.addEventListener("animationstart", handleAnimationStart);
100
+ node.addEventListener("animationcancel", handleAnimationEnd);
101
+ node.addEventListener("animationend", handleAnimationEnd);
102
+ return () => {
103
+ ownerWindow.clearTimeout(timeoutId);
104
+ node.removeEventListener("animationstart", handleAnimationStart);
105
+ node.removeEventListener("animationcancel", handleAnimationEnd);
106
+ node.removeEventListener("animationend", handleAnimationEnd);
107
+ };
108
+ } else {
109
+ send("ANIMATION_END");
110
+ }
111
+ }, [node, send]);
112
+ return {
113
+ isPresent: ["mounted", "unmountSuspended"].includes(state),
114
+ ref: React2.useCallback((node2) => {
115
+ stylesRef.current = node2 ? getComputedStyle(node2) : null;
116
+ setNode(node2);
117
+ }, [])
118
+ };
119
+ }
120
+ function getAnimationName(styles) {
121
+ return styles?.animationName || "none";
122
+ }
123
+ function getElementRef(element) {
124
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
125
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
126
+ if (mayWarn) {
127
+ return element.ref;
128
+ }
129
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
130
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
131
+ if (mayWarn) {
132
+ return element.props.ref;
133
+ }
134
+ return element.props.ref || element.ref;
135
+ }
136
+ var Root = Presence;
137
+ export {
138
+ Presence,
139
+ Root
140
+ };
141
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/presence.tsx", "../src/use-state-machine.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { useStateMachine } from './use-state-machine';\n\ninterface PresenceProps {\n children: React.ReactElement | ((props: { present: boolean }) => React.ReactElement);\n present: boolean;\n}\n\nconst Presence: React.FC<PresenceProps> = (props) => {\n const { present, children } = props;\n const presence = usePresence(present);\n\n const child = (\n typeof children === 'function'\n ? children({ present: presence.isPresent })\n : React.Children.only(children)\n ) as React.ReactElement<{ ref?: React.Ref<HTMLElement> }>;\n\n const ref = useComposedRefs(presence.ref, getElementRef(child));\n const forceMount = typeof children === 'function';\n return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;\n};\n\nPresence.displayName = 'Presence';\n\n/* -------------------------------------------------------------------------------------------------\n * usePresence\n * -----------------------------------------------------------------------------------------------*/\n\nfunction usePresence(present: boolean) {\n const [node, setNode] = React.useState<HTMLElement>();\n const stylesRef = React.useRef<CSSStyleDeclaration | null>(null);\n const prevPresentRef = React.useRef(present);\n const prevAnimationNameRef = React.useRef<string>('none');\n const initialState = present ? 'mounted' : 'unmounted';\n const [state, send] = useStateMachine(initialState, {\n mounted: {\n UNMOUNT: 'unmounted',\n ANIMATION_OUT: 'unmountSuspended',\n },\n unmountSuspended: {\n MOUNT: 'mounted',\n ANIMATION_END: 'unmounted',\n },\n unmounted: {\n MOUNT: 'mounted',\n },\n });\n\n React.useEffect(() => {\n // only read animationName after the full task has run, so we don't cause forced reflow due to accessing the styles\n const timeout = setTimeout(() => {\n prevAnimationNameRef.current =\n state === 'mounted' ? getAnimationName(stylesRef.current) : 'none';\n }, 0);\n return () => clearTimeout(timeout);\n }, [state]);\n\n useLayoutEffect(() => {\n const styles = stylesRef.current;\n const wasPresent = prevPresentRef.current;\n const hasPresentChanged = wasPresent !== present;\n\n if (hasPresentChanged) {\n const prevAnimationName = prevAnimationNameRef.current;\n const currentAnimationName = getAnimationName(styles);\n\n if (present) {\n send('MOUNT');\n } else if (currentAnimationName === 'none' || styles?.display === 'none') {\n // If there is no exit animation or the element is hidden, animations won't run\n // so we unmount instantly\n send('UNMOUNT');\n } else {\n /**\n * When `present` changes to `false`, we check changes to animation-name to\n * determine whether an animation has started. We chose this approach (reading\n * computed styles) because there is no `animationrun` event and `animationstart`\n * fires after `animation-delay` has expired which would be too late.\n */\n const isAnimating = prevAnimationName !== currentAnimationName;\n\n if (wasPresent && isAnimating) {\n send('ANIMATION_OUT');\n } else {\n send('UNMOUNT');\n }\n }\n\n prevPresentRef.current = present;\n }\n }, [present, send]);\n\n useLayoutEffect(() => {\n if (node) {\n let timeoutId: number;\n const ownerWindow = node.ownerDocument.defaultView ?? window;\n /**\n * Triggering an ANIMATION_OUT during an ANIMATION_IN will fire an `animationcancel`\n * event for ANIMATION_IN after we have entered `unmountSuspended` state. So, we\n * make sure we only trigger ANIMATION_END for the currently active animation.\n */\n const handleAnimationEnd = (event: AnimationEvent) => {\n const currentAnimationName = getAnimationName(stylesRef.current);\n // The event.animationName is unescaped for CSS syntax,\n // so we need to escape it to compare with the animationName computed from the style.\n const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));\n if (event.target === node && isCurrentAnimation) {\n // With React 18 concurrency this update is applied a frame after the\n // animation ends, creating a flash of visible content. By setting the\n // animation fill mode to \"forwards\", we force the node to keep the\n // styles of the last keyframe, removing the flash.\n //\n // Previously we flushed the update via ReactDom.flushSync, but with\n // exit animations this resulted in the node being removed from the\n // DOM before the synthetic animationEnd event was dispatched, meaning\n // user-provided event handlers would not be called.\n // https://github.com/radix-ui/primitives/pull/1849\n send('ANIMATION_END');\n if (!prevPresentRef.current) {\n const currentFillMode = node.style.animationFillMode;\n node.style.animationFillMode = 'forwards';\n // Reset the style after the node had time to unmount (for cases\n // where the component chooses not to unmount). Doing this any\n // sooner than `setTimeout` (e.g. with `requestAnimationFrame`)\n // still causes a flash.\n timeoutId = ownerWindow.setTimeout(() => {\n if (node.style.animationFillMode === 'forwards') {\n node.style.animationFillMode = currentFillMode;\n }\n });\n }\n }\n };\n const handleAnimationStart = (event: AnimationEvent) => {\n if (event.target === node) {\n // if animation occurred, store its name as the previous animation.\n prevAnimationNameRef.current = getAnimationName(stylesRef.current);\n }\n };\n node.addEventListener('animationstart', handleAnimationStart);\n node.addEventListener('animationcancel', handleAnimationEnd);\n node.addEventListener('animationend', handleAnimationEnd);\n return () => {\n ownerWindow.clearTimeout(timeoutId);\n node.removeEventListener('animationstart', handleAnimationStart);\n node.removeEventListener('animationcancel', handleAnimationEnd);\n node.removeEventListener('animationend', handleAnimationEnd);\n };\n } else {\n // Transition to the unmounted state if the node is removed prematurely.\n // We avoid doing so during cleanup as the node may change but still exist.\n send('ANIMATION_END');\n }\n }, [node, send]);\n\n return {\n isPresent: ['mounted', 'unmountSuspended'].includes(state),\n ref: React.useCallback((node: HTMLElement) => {\n stylesRef.current = node ? getComputedStyle(node) : null;\n setNode(node);\n }, []),\n };\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction getAnimationName(styles: CSSStyleDeclaration | null) {\n return styles?.animationName || 'none';\n}\n\n// Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`\n// After React 19 accessing `element.ref` does the opposite.\n// https://github.com/facebook/react/pull/28348\n//\n// Access the ref using the method that doesn't yield a warning.\nfunction getElementRef(element: React.ReactElement<{ ref?: React.Ref<unknown> }>) {\n // React <=18 in DEV\n let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get;\n let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return (element as any).ref;\n }\n\n // React 19 in DEV\n getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get;\n mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning;\n if (mayWarn) {\n return element.props.ref;\n }\n\n // Not DEV\n return element.props.ref || (element as any).ref;\n}\n\nconst Root = Presence;\n\nexport {\n Presence,\n //\n Root,\n};\nexport type { PresenceProps };\n", "import * as React from 'react';\n\ntype Machine<S> = { [k: string]: { [k: string]: S } };\ntype MachineState<T> = keyof T;\ntype MachineEvent<T> = keyof UnionToIntersection<T[keyof T]>;\n\n// \uD83E\uDD2F https://fettblog.eu/typescript-union-to-intersection/\ntype UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any\n ? R\n : never;\n\nexport function useStateMachine<M>(\n initialState: MachineState<M>,\n machine: M & Machine<MachineState<M>>\n) {\n return React.useReducer((state: MachineState<M>, event: MachineEvent<M>): MachineState<M> => {\n const nextState = (machine[state] as any)[event];\n return nextState ?? state;\n }, initialState);\n}\n"],
5
+ "mappings": ";;;AAAA,YAAYA,YAAW;AACvB,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;;;ACFhC,YAAY,WAAW;AAWhB,SAAS,gBACd,cACA,SACA;AACA,SAAa,iBAAW,CAAC,OAAwB,UAA4C;AAC3F,UAAM,YAAa,QAAQ,KAAK,EAAU,KAAK;AAC/C,WAAO,aAAa;AAAA,EACtB,GAAG,YAAY;AACjB;;;ADTA,IAAM,WAAoC,CAAC,UAAU;AACnD,QAAM,EAAE,SAAS,SAAS,IAAI;AAC9B,QAAM,WAAW,YAAY,OAAO;AAEpC,QAAM,QACJ,OAAO,aAAa,aAChB,SAAS,EAAE,SAAS,SAAS,UAAU,CAAC,IAClC,gBAAS,KAAK,QAAQ;AAGlC,QAAM,MAAM,gBAAgB,SAAS,KAAK,cAAc,KAAK,CAAC;AAC9D,QAAM,aAAa,OAAO,aAAa;AACvC,SAAO,cAAc,SAAS,YAAkB,oBAAa,OAAO,EAAE,IAAI,CAAC,IAAI;AACjF;AAEA,SAAS,cAAc;AAMvB,SAAS,YAAY,SAAkB;AACrC,QAAM,CAAC,MAA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MAAI,SAAS,OAAO,yBAAyB,QAAQ,OAAO,KAAK,GAAG;AACpE,MAAI,UAAU,UAAU,oBAAoB,UAAU,OAAO;AAC7D,MAAI,SAAS;AACX,WAAQ,QAAgB;AAAA,EAC1B;AAGA,WAAS,OAAO,yBAAyB,SAAS,KAAK,GAAG;AAC1D,YAAU,UAAU,oBAAoB,UAAU,OAAO;AACzD,MAAI,SAAS;AACX,WAAO,QAAQ,MAAM;AAAA,EACvB;AAGA,SAAO,QAAQ,MAAM,OAAQ,QAAgB;AAC/C;AAEA,IAAM,OAAO;",
6
+ "names": ["React", "node"]
7
+ }
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@thomasjahoda-forks/radix-ui-react-presence",
3
+ "version": "1.1.4-1",
4
+ "license": "MIT",
5
+ "source": "./src/index.ts",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "sideEffects": false,
13
+ "dependencies": {
14
+ "@radix-ui/react-compose-refs": "1.1.2",
15
+ "@radix-ui/react-use-layout-effect": "1.1.1"
16
+ },
17
+ "devDependencies": {
18
+ "@types/react": "^19.0.7",
19
+ "@types/react-dom": "^19.0.3",
20
+ "eslint": "^9.18.0",
21
+ "react": "^19.1.0",
22
+ "react-dom": "^19.1.0",
23
+ "typescript": "^5.7.3",
24
+ "@repo/typescript-config": "0.0.0",
25
+ "@repo/eslint-config": "0.0.0",
26
+ "@repo/builder": "0.0.0"
27
+ },
28
+ "peerDependencies": {
29
+ "@types/react": "*",
30
+ "@types/react-dom": "*",
31
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
32
+ "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@types/react": {
36
+ "optional": true
37
+ },
38
+ "@types/react-dom": {
39
+ "optional": true
40
+ }
41
+ },
42
+ "homepage": "https://radix-ui.com/primitives",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/radix-ui/primitives.git"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/radix-ui/primitives/issues"
49
+ },
50
+ "scripts": {
51
+ "lint": "eslint --max-warnings 0 src",
52
+ "clean": "rm -rf dist",
53
+ "typecheck": "tsc --noEmit",
54
+ "build": "radix-build"
55
+ },
56
+ "types": "./dist/index.d.ts",
57
+ "exports": {
58
+ ".": {
59
+ "import": {
60
+ "types": "./dist/index.d.mts",
61
+ "default": "./dist/index.mjs"
62
+ },
63
+ "require": {
64
+ "types": "./dist/index.d.ts",
65
+ "default": "./dist/index.js"
66
+ }
67
+ }
68
+ }
69
+ }