@fluentui/react-motion 9.16.0 → 9.16.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/CHANGELOG.md +23 -2
- package/dist/index.d.cts +368 -0
- package/lib/components/MotionRefForwarder.js +1 -1
- package/lib/components/PresenceGroup.js +4 -4
- package/lib/components/PresenceGroup.js.map +1 -1
- package/lib/components/PresenceGroupItemProvider.js +2 -2
- package/lib/components/PresenceGroupItemProvider.js.map +1 -1
- package/lib/contexts/MotionBehaviourContext.js +1 -1
- package/lib/contexts/PresenceGroupChildContext.js +1 -1
- package/lib/factories/createMotionComponent.js +7 -8
- package/lib/factories/createMotionComponent.js.map +1 -1
- package/lib/factories/createMotionComponentVariant.js +1 -1
- package/lib/factories/createMotionComponentVariant.js.map +1 -1
- package/lib/factories/createPresenceComponent.js +10 -11
- package/lib/factories/createPresenceComponent.js.map +1 -1
- package/lib/factories/createPresenceComponentVariant.js +1 -1
- package/lib/factories/createPresenceComponentVariant.js.map +1 -1
- package/lib/hooks/useAnimateAtoms.js +2 -3
- package/lib/hooks/useAnimateAtoms.js.map +1 -1
- package/lib/hooks/useIsReducedMotion.js +3 -3
- package/lib/hooks/useMotionImperativeRef.js +1 -1
- package/lib/hooks/useMountedState.js +2 -2
- package/lib/index.js +11 -11
- package/lib/index.js.map +1 -1
- package/lib/slots/motionSlot.js +2 -2
- package/lib/slots/presenceMotionSlot.js +2 -2
- package/lib/utils/groups/getChildMapping.js +1 -1
- package/lib/utils/groups/getNextChildMapping.js +1 -1
- package/lib/utils/groups/getNextChildMapping.js.map +1 -1
- package/lib/utils/useChildElement.js +2 -2
- package/lib-commonjs/components/{PresenceGroup.js → PresenceGroup.cjs} +3 -3
- package/lib-commonjs/components/{PresenceGroupItemProvider.js → PresenceGroupItemProvider.cjs} +1 -1
- package/lib-commonjs/factories/{createMotionComponent.js → createMotionComponent.cjs} +5 -6
- package/lib-commonjs/factories/createMotionComponent.cjs.map +1 -0
- package/lib-commonjs/factories/{createMotionComponentVariant.js → createMotionComponentVariant.cjs} +1 -1
- package/lib-commonjs/factories/{createPresenceComponent.js → createPresenceComponent.cjs} +8 -9
- package/lib-commonjs/factories/createPresenceComponent.cjs.map +1 -0
- package/lib-commonjs/factories/{createPresenceComponentVariant.js → createPresenceComponentVariant.cjs} +1 -1
- package/lib-commonjs/hooks/{useAnimateAtoms.js → useAnimateAtoms.cjs} +1 -2
- package/lib-commonjs/hooks/{useAnimateAtoms.js.map → useAnimateAtoms.cjs.map} +1 -1
- package/lib-commonjs/{index.js → index.cjs} +11 -11
- package/lib-commonjs/utils/groups/{getNextChildMapping.js → getNextChildMapping.cjs} +1 -1
- package/package.json +15 -9
- package/lib-commonjs/factories/createMotionComponent.js.map +0 -1
- package/lib-commonjs/factories/createPresenceComponent.js.map +0 -1
- /package/lib-commonjs/components/{MotionRefForwarder.js → MotionRefForwarder.cjs} +0 -0
- /package/lib-commonjs/components/{MotionRefForwarder.js.map → MotionRefForwarder.cjs.map} +0 -0
- /package/lib-commonjs/components/{PresenceGroup.js.map → PresenceGroup.cjs.map} +0 -0
- /package/lib-commonjs/components/{PresenceGroupItemProvider.js.map → PresenceGroupItemProvider.cjs.map} +0 -0
- /package/lib-commonjs/contexts/{MotionBehaviourContext.js → MotionBehaviourContext.cjs} +0 -0
- /package/lib-commonjs/contexts/{MotionBehaviourContext.js.map → MotionBehaviourContext.cjs.map} +0 -0
- /package/lib-commonjs/contexts/{PresenceGroupChildContext.js → PresenceGroupChildContext.cjs} +0 -0
- /package/lib-commonjs/contexts/{PresenceGroupChildContext.js.map → PresenceGroupChildContext.cjs.map} +0 -0
- /package/lib-commonjs/factories/{createMotionComponentVariant.js.map → createMotionComponentVariant.cjs.map} +0 -0
- /package/lib-commonjs/factories/{createPresenceComponentVariant.js.map → createPresenceComponentVariant.cjs.map} +0 -0
- /package/lib-commonjs/hooks/{useIsReducedMotion.js → useIsReducedMotion.cjs} +0 -0
- /package/lib-commonjs/hooks/{useIsReducedMotion.js.map → useIsReducedMotion.cjs.map} +0 -0
- /package/lib-commonjs/hooks/{useMotionImperativeRef.js → useMotionImperativeRef.cjs} +0 -0
- /package/lib-commonjs/hooks/{useMotionImperativeRef.js.map → useMotionImperativeRef.cjs.map} +0 -0
- /package/lib-commonjs/hooks/{useMountedState.js → useMountedState.cjs} +0 -0
- /package/lib-commonjs/hooks/{useMountedState.js.map → useMountedState.cjs.map} +0 -0
- /package/lib-commonjs/{index.js.map → index.cjs.map} +0 -0
- /package/lib-commonjs/motions/{motionTokens.js → motionTokens.cjs} +0 -0
- /package/lib-commonjs/motions/{motionTokens.js.map → motionTokens.cjs.map} +0 -0
- /package/lib-commonjs/slots/{motionSlot.js → motionSlot.cjs} +0 -0
- /package/lib-commonjs/slots/{motionSlot.js.map → motionSlot.cjs.map} +0 -0
- /package/lib-commonjs/slots/{presenceMotionSlot.js → presenceMotionSlot.cjs} +0 -0
- /package/lib-commonjs/slots/{presenceMotionSlot.js.map → presenceMotionSlot.cjs.map} +0 -0
- /package/lib-commonjs/{types.js → types.cjs} +0 -0
- /package/lib-commonjs/{types.js.map → types.cjs.map} +0 -0
- /package/lib-commonjs/utils/groups/{getChildMapping.js → getChildMapping.cjs} +0 -0
- /package/lib-commonjs/utils/groups/{getChildMapping.js.map → getChildMapping.cjs.map} +0 -0
- /package/lib-commonjs/utils/groups/{getNextChildMapping.js.map → getNextChildMapping.cjs.map} +0 -0
- /package/lib-commonjs/utils/groups/{mergeChildMappings.js → mergeChildMappings.cjs} +0 -0
- /package/lib-commonjs/utils/groups/{mergeChildMappings.js.map → mergeChildMappings.cjs.map} +0 -0
- /package/lib-commonjs/utils/groups/{types.js → types.cjs} +0 -0
- /package/lib-commonjs/utils/groups/{types.js.map → types.cjs.map} +0 -0
- /package/lib-commonjs/utils/{isAnimationRunning.js → isAnimationRunning.cjs} +0 -0
- /package/lib-commonjs/utils/{isAnimationRunning.js.map → isAnimationRunning.cjs.map} +0 -0
- /package/lib-commonjs/utils/{useChildElement.js → useChildElement.cjs} +0 -0
- /package/lib-commonjs/utils/{useChildElement.js.map → useChildElement.cjs.map} +0 -0
|
@@ -58,14 +58,14 @@ _export(exports, {
|
|
|
58
58
|
return _PresenceGroupChildContext.usePresenceGroupChildContext;
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
const _motionTokens = require("./motions/motionTokens");
|
|
62
|
-
const _createMotionComponent = require("./factories/createMotionComponent");
|
|
63
|
-
const _createMotionComponentVariant = require("./factories/createMotionComponentVariant");
|
|
64
|
-
const _createPresenceComponent = require("./factories/createPresenceComponent");
|
|
65
|
-
const _createPresenceComponentVariant = require("./factories/createPresenceComponentVariant");
|
|
66
|
-
const _PresenceGroup = require("./components/PresenceGroup");
|
|
67
|
-
const _MotionRefForwarder = require("./components/MotionRefForwarder");
|
|
68
|
-
const _motionSlot = require("./slots/motionSlot");
|
|
69
|
-
const _presenceMotionSlot = require("./slots/presenceMotionSlot");
|
|
70
|
-
const _PresenceGroupChildContext = require("./contexts/PresenceGroupChildContext");
|
|
71
|
-
const _MotionBehaviourContext = require("./contexts/MotionBehaviourContext");
|
|
61
|
+
const _motionTokens = require("./motions/motionTokens.cjs");
|
|
62
|
+
const _createMotionComponent = require("./factories/createMotionComponent.cjs");
|
|
63
|
+
const _createMotionComponentVariant = require("./factories/createMotionComponentVariant.cjs");
|
|
64
|
+
const _createPresenceComponent = require("./factories/createPresenceComponent.cjs");
|
|
65
|
+
const _createPresenceComponentVariant = require("./factories/createPresenceComponentVariant.cjs");
|
|
66
|
+
const _PresenceGroup = require("./components/PresenceGroup.cjs");
|
|
67
|
+
const _MotionRefForwarder = require("./components/MotionRefForwarder.cjs");
|
|
68
|
+
const _motionSlot = require("./slots/motionSlot.cjs");
|
|
69
|
+
const _presenceMotionSlot = require("./slots/presenceMotionSlot.cjs");
|
|
70
|
+
const _PresenceGroupChildContext = require("./contexts/PresenceGroupChildContext.cjs");
|
|
71
|
+
const _MotionBehaviourContext = require("./contexts/MotionBehaviourContext.cjs");
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "getNextChildMapping", {
|
|
|
8
8
|
return getNextChildMapping;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _mergeChildMappings = require("./mergeChildMappings");
|
|
11
|
+
const _mergeChildMappings = require("./mergeChildMappings.cjs");
|
|
12
12
|
function getNextChildMapping(prevChildMapping, nextChildMapping) {
|
|
13
13
|
const childrenMapping = (0, _mergeChildMappings.mergeChildMappings)(prevChildMapping, nextChildMapping);
|
|
14
14
|
Object.entries(childrenMapping).forEach(([key, childDefinition])=>{
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-motion",
|
|
3
|
-
"version": "9.16.
|
|
3
|
+
"version": "9.16.2",
|
|
4
4
|
"description": "A package with utilities & motion definitions using Web Animations API",
|
|
5
|
-
"main": "lib-commonjs/index.
|
|
5
|
+
"main": "lib-commonjs/index.cjs",
|
|
6
6
|
"module": "lib/index.js",
|
|
7
7
|
"typings": "./dist/index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
10
10
|
"*.md",
|
|
11
11
|
"dist/*.d.ts",
|
|
12
|
+
"dist/*.d.cts",
|
|
12
13
|
"lib",
|
|
13
14
|
"lib-commonjs"
|
|
14
15
|
],
|
|
@@ -18,8 +19,8 @@
|
|
|
18
19
|
},
|
|
19
20
|
"license": "MIT",
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@fluentui/react-shared-contexts": "^9.26.
|
|
22
|
-
"@fluentui/react-utilities": "^9.26.
|
|
22
|
+
"@fluentui/react-shared-contexts": "^9.26.3",
|
|
23
|
+
"@fluentui/react-utilities": "^9.26.6",
|
|
23
24
|
"@swc/helpers": "^0.5.1"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
@@ -30,10 +31,14 @@
|
|
|
30
31
|
},
|
|
31
32
|
"exports": {
|
|
32
33
|
".": {
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./lib/index.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/index.d.cts",
|
|
40
|
+
"default": "./lib-commonjs/index.cjs"
|
|
41
|
+
}
|
|
37
42
|
},
|
|
38
43
|
"./package.json": "./package.json"
|
|
39
44
|
},
|
|
@@ -42,5 +47,6 @@
|
|
|
42
47
|
"major",
|
|
43
48
|
"prerelease"
|
|
44
49
|
]
|
|
45
|
-
}
|
|
50
|
+
},
|
|
51
|
+
"type": "module"
|
|
46
52
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/factories/createMotionComponent.ts"],"sourcesContent":["'use client';\n\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport { useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { useAnimateAtoms } from '../hooks/useAnimateAtoms';\nimport { useMotionImperativeRef } from '../hooks/useMotionImperativeRef';\nimport { useIsReducedMotion } from '../hooks/useIsReducedMotion';\nimport { useChildElement } from '../utils/useChildElement';\nimport type { AtomMotion, AtomMotionFn, MotionParam, MotionImperativeRef, AnimationHandle } from '../types';\nimport { useMotionBehaviourContext } from '../contexts/MotionBehaviourContext';\n\n/**\n * A private symbol to store the motion definition on the component for variants.\n *\n * @internal\n */\nexport const MOTION_DEFINITION = Symbol('MOTION_DEFINITION');\n\nexport type MotionComponentProps = {\n children: JSXElement;\n\n /** Provides imperative controls for the animation. */\n imperativeRef?: React.Ref<MotionImperativeRef | undefined>;\n\n /**\n * Callback that is called when the whole motion finishes.\n *\n * A motion definition can contain multiple animations and therefore multiple \"finish\" events. The callback is\n * triggered once all animations have finished with \"null\" instead of an event object to avoid ambiguity.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- EventHandler<T> does not support \"null\"\n onMotionFinish?: (ev: null) => void;\n\n /**\n * Callback that is called when the whole motion is cancelled.\n *\n * A motion definition can contain multiple animations and therefore multiple \"cancel\" events. The callback is\n * triggered once all animations have been cancelled with \"null\" instead of an event object to avoid ambiguity.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- EventHandler<T> does not support \"null\"\n onMotionCancel?: (ev: null) => void;\n\n /**\n * Callback that is called when the whole motion starts.\n *\n * A motion definition can contain multiple animations and therefore multiple \"start\" events. The callback is\n * triggered when the first animation is started. There is no official \"start\" event with the Web Animations API.\n * so the callback is triggered with \"null\".\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- EventHandler<T> does not support \"null\"\n onMotionStart?: (ev: null) => void;\n\n /**\n * When this value changes, the animation replays from the start on the same DOM element,\n * cancelling any in-progress animation, without remounting the component or its children.\n *\n * **Why not just use a React `key`?** Changing a React `key` forces a full unmount and\n * remount of the subtree: DOM nodes are destroyed and recreated, focus is lost, and any\n * child state is reset. `replayKey` avoids all of that — only the animation effect reruns\n * while the DOM and component state remain intact.\n *\n * Use this when you want to retrigger a motion in response to a state change (e.g. a user\n * action or a data update) while preserving DOM continuity. It is the declarative equivalent\n * of calling `imperativeRef.current.play()` but driven by a prop rather than a ref call.\n *\n * @example\n * ```tsx\n * // Replay a Fade.In each time the user clicks \"Refresh\"\n * const [replayKey, setReplayKey] = React.useState(0);\n * <Fade.In replayKey={replayKey}>\n * <div>Content</div>\n * </Fade.In>\n * <button onClick={() => setReplayKey(k => k + 1)}>Refresh</button>\n * ```\n */\n replayKey?: string | number;\n};\n\nexport type MotionComponent<MotionParams extends Record<string, MotionParam> = {}> = React.FC<\n MotionComponentProps & MotionParams\n> & {\n [MOTION_DEFINITION]: AtomMotionFn<MotionParams>;\n};\n\n/**\n * Creates a component that will animate the children using the provided motion.\n *\n * @param value - A motion definition.\n */\nexport function createMotionComponent<MotionParams extends Record<string, MotionParam> = {}>(\n value: AtomMotion | AtomMotion[] | AtomMotionFn<MotionParams>,\n): MotionComponent<MotionParams> {\n const Atom: React.FC<MotionComponentProps & MotionParams> = props => {\n 'use no memo';\n\n const {\n children,\n imperativeRef,\n onMotionFinish: onMotionFinishProp,\n onMotionStart: onMotionStartProp,\n onMotionCancel: onMotionCancelProp,\n replayKey,\n ..._rest\n } = props;\n const params = _rest as Exclude<typeof props, MotionComponentProps>;\n const [child, childRef] = useChildElement(children);\n\n const handleRef = useMotionImperativeRef(imperativeRef);\n const isInitialRender = React.useRef(true);\n const skipMotions = useMotionBehaviourContext() === 'skip';\n const optionsRef = React.useRef<{ skipMotions: boolean; params: MotionParams }>({\n skipMotions,\n params,\n });\n\n const animateAtoms = useAnimateAtoms();\n const isReducedMotion = useIsReducedMotion();\n\n const onMotionStart = useEventCallback(() => {\n onMotionStartProp?.(null);\n });\n\n const onMotionFinish = useEventCallback(() => {\n onMotionFinishProp?.(null);\n });\n\n const onMotionCancel = useEventCallback(() => {\n onMotionCancelProp?.(null);\n });\n\n // Stable callback (all deps are refs or useEventCallback) that activates a handle for a new playback cycle.\n //\n // TODO: consider moving the cancel+play+rewire sequence into a handle.replay() method on AnimationHandle,\n // keeping pure animation sequencing on the handle and React callbacks here in the component.\n const activateAnimationHandle = React.useCallback(\n (handle: AnimationHandle) => {\n onMotionStart();\n handle.setMotionEndCallbacks(onMotionFinish, onMotionCancel);\n if (optionsRef.current.skipMotions) {\n handle.finish();\n }\n },\n [onMotionStart, onMotionFinish, onMotionCancel],\n );\n\n useIsomorphicLayoutEffect(() => {\n // Heads up!\n // We store the params in a ref to avoid re-rendering the component when the params change.\n optionsRef.current = { skipMotions, params };\n });\n\n useIsomorphicLayoutEffect(() => {\n const element = childRef.current;\n\n if (element) {\n const atoms = typeof value === 'function' ? value({ element, ...optionsRef.current.params }) : value;\n\n const handle = animateAtoms(element, atoms, { isReducedMotion: isReducedMotion() });\n handleRef.current = handle;\n activateAnimationHandle(handle);\n\n return () => {\n handle.cancel();\n };\n }\n }, [animateAtoms, childRef, handleRef, isReducedMotion, activateAnimationHandle]);\n\n // Skips initial mount; on replayKey changes, reuses existing Animation objects via cancel+play\n // rather than recreating them, preserving DOM continuity.\n useIsomorphicLayoutEffect(() => {\n if (isInitialRender.current) {\n return;\n }\n\n const handle = handleRef.current;\n if (handle) {\n handle.cancel();\n handle.play();\n activateAnimationHandle(handle);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- replayKey is intentionally the only trigger; other deps are stable refs/callbacks\n }, [replayKey]);\n\n useIsomorphicLayoutEffect(() => {\n isInitialRender.current = false;\n\n return () => {\n isInitialRender.current = true;\n };\n }, []);\n\n return child;\n };\n\n return Object.assign(Atom, {\n // Heads up!\n // Always normalize it to a function to simplify types\n [MOTION_DEFINITION]: typeof value === 'function' ? value : () => value,\n });\n}\n"],"names":["MOTION_DEFINITION","createMotionComponent","Symbol","value","Atom","props","children","imperativeRef","onMotionFinish","onMotionFinishProp","onMotionStart","onMotionStartProp","onMotionCancel","onMotionCancelProp","replayKey","_rest","params","child","childRef","useChildElement","handleRef","useMotionImperativeRef","isInitialRender","React","useRef","skipMotions","useMotionBehaviourContext","optionsRef","animateAtoms","useAnimateAtoms","isReducedMotion","useIsReducedMotion","useEventCallback","activateAnimationHandle","useCallback","handle","setMotionEndCallbacks","current","finish","useIsomorphicLayoutEffect","element","atoms","cancel","play","Object","assign"],"mappings":"AAAA;;;;;;;;;;;;IAkBaA,iBAAiB;eAAjBA;;IAyEGC,qBAAqB;eAArBA;;;;gCAxF4C;iEACrC;iCAES;wCACO;oCACJ;iCACH;wCAEU;AAOnC,MAAMD,oBAAoBE,OAAO;AAyEjC,SAASD,sBACdE,KAA6D;IAE7D,MAAMC,OAAsDC,CAAAA;QAC1D;QAEA,MAAM,EACJC,QAAQ,EACRC,aAAa,EACbC,gBAAgBC,kBAAkB,EAClCC,eAAeC,iBAAiB,EAChCC,gBAAgBC,kBAAkB,EAClCC,SAAS,EACT,GAAGC,OACJ,GAAGV;QACJ,MAAMW,SAASD;QACf,MAA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,UAAUiB,OAAO,GAAGF;gBACpBF,wBAAwBE;gBAExB,OAAO;oBACLA,OAAOO,MAAM;gBACf;YACF;QACF,GAAG;YAACd;YAAcV;YAAUE;YAAWU;YAAiBG;SAAwB;QAEhF,+FAA+F;QAC/F,0DAA0D;QAC1DM,IAAAA,yCAAyB,EAAC;YACxB,IAAIjB,gBAAgBe,OAAO,EAAE;gBAC3B;YACF;YAEA,MAAMF,SAASf,UAAUiB,OAAO;YAChC,IAAIF,QAAQ;gBACVA,OAAOO,MAAM;gBACbP,OAAOQ,IAAI;gBACXV,wBAAwBE;YAC1B;QACA,4IAA4I;QAC9I,GAAG;YAACrB;SAAU;QAEdyB,IAAAA,yCAAyB,EAAC;YACxBjB,gBAAgBe,OAAO,GAAG;YAE1B,OAAO;gBACLf,gBAAgBe,OAAO,GAAG;YAC5B;QACF,GAAG,EAAE;QAEL,OAAOpB;IACT;IAEA,OAAO2B,OAAOC,MAAM,CAACzC,MAAM;QACzB,YAAY;QACZ,sDAAsD;QACtD,CAACJ,kBAAkB,EAAE,OAAOG,UAAU,aAAaA,QAAQ,IAAMA;IACnE;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/factories/createPresenceComponent.ts"],"sourcesContent":["'use client';\n\nimport { useEventCallback, useFirstMount, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { PresenceGroupChildContext } from '../contexts/PresenceGroupChildContext';\nimport { useAnimateAtoms } from '../hooks/useAnimateAtoms';\nimport { useMotionImperativeRef } from '../hooks/useMotionImperativeRef';\nimport { useMountedState } from '../hooks/useMountedState';\nimport { useIsReducedMotion } from '../hooks/useIsReducedMotion';\nimport { useChildElement } from '../utils/useChildElement';\nimport type {\n MotionParam,\n PresenceMotion,\n MotionImperativeRef,\n PresenceMotionFn,\n PresenceDirection,\n AnimationHandle,\n} from '../types';\nimport { useMotionBehaviourContext } from '../contexts/MotionBehaviourContext';\nimport type { MotionComponent } from './createMotionComponent';\nimport { createMotionComponent } from './createMotionComponent';\n\n/**\n * A private symbol to store the motion definition on the component for variants.\n *\n * @internal\n */\nexport const PRESENCE_MOTION_DEFINITION = Symbol('PRESENCE_MOTION_DEFINITION');\n\nexport type PresenceComponentProps = {\n /**\n * By default, the child component won't execute the \"enter\" motion when it initially mounts, regardless of the value\n * of \"visible\". If you desire this behavior, ensure both \"appear\" and \"visible\" are set to \"true\".\n */\n appear?: boolean;\n\n /** A React element that will be cloned and will have motion effects applied to it. */\n children: JSXElement;\n\n /** Provides imperative controls for the animation. */\n imperativeRef?: React.Ref<MotionImperativeRef | undefined>;\n\n /**\n * Callback that is called when the whole motion finishes.\n *\n * A motion definition can contain multiple animations and therefore multiple \"finish\" events. The callback is\n * triggered once all animations have finished with \"null\" instead of an event object to avoid ambiguity.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- EventHandler<T> does not support \"null\"\n onMotionFinish?: (ev: null, data: { direction: PresenceDirection }) => void;\n\n /**\n * Callback that is called when the whole motion is cancelled. When a motion is cancelled it does not\n * emit a finish event but a specific cancel event\n *\n * A motion definition can contain multiple animations and therefore multiple \"finish\" events. The callback is\n * triggered once all animations have finished with \"null\" instead of an event object to avoid ambiguity.\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- EventHandler<T> does not support \"null\"\n onMotionCancel?: (ev: null, data: { direction: PresenceDirection }) => void;\n\n /**\n * Callback that is called when the whole motion starts.\n *\n * A motion definition can contain multiple animations and therefore multiple \"start\" events. The callback is\n * triggered when the first animation is started. There is no official \"start\" event with the Web Animations API.\n * so the callback is triggered with \"null\".\n */\n // eslint-disable-next-line @nx/workspace-consistent-callback-type -- EventHandler<T> does not support \"null\"\n onMotionStart?: (ev: null, data: { direction: PresenceDirection }) => void;\n\n /** Defines whether a component is visible; triggers the \"enter\" or \"exit\" motions. */\n visible?: boolean;\n\n /**\n * By default, the child component remains mounted after it reaches the \"finished\" state. Set \"unmountOnExit\" if\n * you prefer to unmount the component after it finishes exiting.\n */\n unmountOnExit?: boolean;\n};\n\nexport type PresenceComponent<MotionParams extends Record<string, MotionParam> = {}> = React.FC<\n PresenceComponentProps & MotionParams\n> & {\n (props: PresenceComponentProps & MotionParams): JSXElement | null;\n [PRESENCE_MOTION_DEFINITION]: PresenceMotionFn<MotionParams>;\n In: MotionComponent<MotionParams>;\n Out: MotionComponent<MotionParams>;\n};\n\nconst INTERRUPTABLE_MOTION_SYMBOL = Symbol.for('interruptablePresence');\n\nexport function createPresenceComponent<MotionParams extends Record<string, MotionParam> = {}>(\n value: PresenceMotion | PresenceMotionFn<MotionParams>,\n): PresenceComponent<MotionParams> {\n return Object.assign(\n (props: PresenceComponentProps & MotionParams) => {\n 'use no memo';\n\n const itemContext = React.useContext(PresenceGroupChildContext);\n const merged = { ...itemContext, ...props };\n const skipMotions = useMotionBehaviourContext() === 'skip';\n\n const {\n appear,\n children,\n imperativeRef,\n onExit,\n onMotionFinish,\n onMotionStart,\n onMotionCancel,\n visible,\n unmountOnExit,\n ..._rest\n } = merged;\n const params = _rest as Exclude<typeof merged, PresenceComponentProps | typeof itemContext>;\n\n const [mounted, setMounted] = useMountedState(visible, unmountOnExit);\n const [child, childRef] = useChildElement(children, mounted);\n\n const handleRef = useMotionImperativeRef(imperativeRef);\n const optionsRef = React.useRef<{ appear?: boolean; params: MotionParams; skipMotions: boolean }>({\n appear,\n params,\n skipMotions,\n });\n\n const animateAtoms = useAnimateAtoms();\n const isFirstMount = useFirstMount();\n const isReducedMotion = useIsReducedMotion();\n\n const handleMotionStart = useEventCallback((direction: PresenceDirection) => {\n onMotionStart?.(null, { direction });\n });\n const handleMotionFinish = useEventCallback((direction: PresenceDirection) => {\n onMotionFinish?.(null, { direction });\n\n if (direction === 'exit' && unmountOnExit) {\n setMounted(false);\n onExit?.();\n }\n });\n\n const handleMotionCancel = useEventCallback((direction: PresenceDirection) => {\n onMotionCancel?.(null, { direction });\n });\n\n useIsomorphicLayoutEffect(() => {\n // Heads up!\n // We store the params in a ref to avoid re-rendering the component when the params change.\n optionsRef.current = { appear, params, skipMotions };\n });\n\n useIsomorphicLayoutEffect(\n () => {\n const element = childRef.current;\n\n if (!element) {\n return;\n }\n\n let handle: AnimationHandle | undefined;\n\n function cleanup() {\n if (!handle) {\n return;\n }\n\n // Heads up!\n //\n // If the animation is interruptible & is running, we don't want to cancel it as it will be reversed in\n // the next effect.\n if (IS_EXPERIMENTAL_INTERRUPTIBLE_MOTION && handle.isRunning()) {\n return;\n }\n\n handle.cancel();\n handleRef.current = undefined;\n }\n\n const presenceMotion =\n typeof value === 'function' ? value({ element, ...optionsRef.current.params }) : (value as PresenceMotion);\n const IS_EXPERIMENTAL_INTERRUPTIBLE_MOTION = (\n presenceMotion as PresenceMotion & { [INTERRUPTABLE_MOTION_SYMBOL]?: boolean }\n )[INTERRUPTABLE_MOTION_SYMBOL];\n\n if (IS_EXPERIMENTAL_INTERRUPTIBLE_MOTION) {\n handle = handleRef.current;\n\n if (handle && handle.isRunning()) {\n handle.reverse();\n\n return cleanup;\n }\n }\n\n const atoms = visible ? presenceMotion.enter : presenceMotion.exit;\n const direction: PresenceDirection = visible ? 'enter' : 'exit';\n\n // Heads up!\n // Initial styles are applied when the component is mounted for the first time and \"appear\" is set to \"false\" (otherwise animations are triggered)\n const applyInitialStyles = !optionsRef.current.appear && isFirstMount;\n const skipAnimationByConfig = optionsRef.current.skipMotions;\n\n if (!applyInitialStyles) {\n handleMotionStart(direction);\n }\n\n handle = animateAtoms(element, atoms, { isReducedMotion: isReducedMotion() });\n\n if (applyInitialStyles) {\n // Heads up!\n // .finish() is used in this case to skip animation and apply animation styles immediately\n handle.finish();\n\n return cleanup;\n }\n\n handleRef.current = handle;\n handle.setMotionEndCallbacks(\n () => handleMotionFinish(direction),\n () => handleMotionCancel(direction),\n );\n\n if (skipAnimationByConfig) {\n handle.finish();\n }\n\n return cleanup;\n },\n // Excluding `isFirstMount` from deps to prevent re-triggering the animation on subsequent renders\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n animateAtoms,\n childRef,\n handleRef,\n isReducedMotion,\n handleMotionFinish,\n handleMotionStart,\n handleMotionCancel,\n visible,\n ],\n );\n\n React.useEffect(() => {\n // Heads up!\n //\n // Dispose the handle when unmounting the component to clean up retained references. Doing it in a separate\n // effect to ensure that the component is unmounted.\n\n if (unmountOnExit && !mounted) {\n handleRef.current?.dispose();\n }\n }, [handleRef, unmountOnExit, mounted]);\n\n if (mounted) {\n return child;\n }\n\n return null;\n },\n {\n // Heads up!\n // Always normalize it to a function to simplify types\n [PRESENCE_MOTION_DEFINITION]: typeof value === 'function' ? value : () => value,\n },\n {\n // Wrap `enter` in its own motion component as a static method, e.g. <Fade.In>\n In: createMotionComponent(\n // If we have a motion function, wrap it to forward the runtime params and pick `enter`.\n // Otherwise, pass the `enter` motion object directly.\n typeof value === 'function' ? (...args: Parameters<typeof value>) => value(...args).enter : value.enter,\n ),\n\n // Wrap `exit` in its own motion component as a static method, e.g. <Fade.Out>\n Out: createMotionComponent(\n // If we have a motion function, wrap it to forward the runtime params and pick `exit`.\n // Otherwise, pass the `exit` motion object directly.\n typeof value === 'function' ? (...args: Parameters<typeof value>) => value(...args).exit : value.exit,\n ),\n },\n );\n}\n"],"names":["PRESENCE_MOTION_DEFINITION","createPresenceComponent","Symbol","INTERRUPTABLE_MOTION_SYMBOL","for","value","Object","assign","props","itemContext","React","useContext","PresenceGroupChildContext","merged","skipMotions","useMotionBehaviourContext","appear","children","imperativeRef","onExit","onMotionFinish","onMotionStart","onMotionCancel","visible","unmountOnExit","_rest","params","mounted","setMounted","useMountedState","child","childRef","useChildElement","handleRef","useMotionImperativeRef","optionsRef","useRef","animateAtoms","useAnimateAtoms","isFirstMount","useFirstMount","isReducedMotion","useIsReducedMotion","handleMotionStart","useEventCallback","direction","handleMotionFinish","handleMotionCancel","useIsomorphicLayoutEffect","current","element","handle","cleanup","IS_EXPERIMENTAL_INTERRUPTIBLE_MOTION","isRunning","cancel","undefined","presenceMotion","reverse","atoms","enter","exit","applyInitialStyles","skipAnimationByConfig","finish","setMotionEndCallbacks","useEffect","dispose","In","createMotionComponent","args","Out"],"mappings":"AAAA;;;;;;;;;;;;IA6BaA,0BAA0B;eAA1BA;;IAiEGC,uBAAuB;eAAvBA;;;;gCA5F2D;iEAEpD;2CAEmB;iCACV;wCACO;iCACP;oCACG;iCACH;wCASU;uCAEJ;AAO/B,MAAMD,6BAA6BE,OAAO;AA+DjD,MAAMC,8BAA8BD,OAAOE,GAAG,CAAC;AAExC,SAASH,wBACdI,KAAsD;IAEtD,OAAOC,OAAOC,MAAM,CAClB,CAACC;QACC;QAEA,MAAMC,cAAcC,OAAMC,UAAU,CAACC,oDAAyB;QAC9D,MAAMC,SAAS;YAAE,GAAGJ,WAAW;YAAE,GAAGD,KAAK;QAAC;QAC1C,MAAMM,cAAcC,IAAAA,iDAAyB,QAAO;QAEpD,MAAM,EACJC,MAAM,EACNC,QAAQ,EACRC,aAAa,EACbC,MAAM,EACNC,cAAc,EACdC,aAAa,EACbC,cAAc,EACdC,OAAO,EACPC,aAAa,EACb,GAAGC,OACJ,GAAGZ;QACJ,MAAMa,SAASD;QAEf,MAAM,CAACE,SAASC,WAAW,GAAGC,IAAAA,gCAAe,EAACN,SAASC;QACvD,MAAM,CAACM,OAAOC,SAAS,GAAGC,IAAAA,gCAAe,EAACf,UAAUU;QAEpD,MAAMM,YAAYC,IAAAA,8CAAsB,EAAChB;QACzC,MAAMiB,aAAazB,OAAM0B,MAAM,CAAmE;YAChGpB;YACAU;YACAZ;QACF;QAEA,MAAMuB,eAAeC,IAAAA,gCAAe;QACpC,MAAMC,eAAeC,IAAAA,6BAAa;QAClC,MAAMC,kBAAkBC,IAAAA,sCAAkB;QAE1C,MAAMC,oBAAoBC,IAAAA,gCAAgB,EAAC,CAACC;YAC1CxB,0BAAAA,oCAAAA,cAAgB,MAAM;gBAAEwB;YAAU;QACpC;QACA,MAAMC,qBAAqBF,IA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T,IAAI,GAAGxD,MAAMwD,IAAI;IAEzG;AAEJ"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib-commonjs/contexts/{MotionBehaviourContext.js.map → MotionBehaviourContext.cjs.map}
RENAMED
|
File without changes
|
/package/lib-commonjs/contexts/{PresenceGroupChildContext.js → PresenceGroupChildContext.cjs}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib-commonjs/hooks/{useMotionImperativeRef.js.map → useMotionImperativeRef.cjs.map}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib-commonjs/utils/groups/{getNextChildMapping.js.map → getNextChildMapping.cjs.map}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|