38247ada8d7371f4840aa4c8675fd8c3.json 24.4 KB
{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useRef, useEffect } from 'react';\nimport { STATUS_APPEAR, STATUS_NONE, STATUS_LEAVE, STATUS_ENTER, STEP_PREPARE, STEP_START, STEP_ACTIVE } from '../interface';\nimport useState from './useState';\nimport useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';\nimport useStepQueue, { DoStep, SkipStep, isActive } from './useStepQueue';\nimport useDomMotionEvents from './useDomMotionEvents';\nexport default function useStatus(supportMotion, visible, getElement, _ref) {\n  var _ref$motionEnter = _ref.motionEnter,\n      motionEnter = _ref$motionEnter === void 0 ? true : _ref$motionEnter,\n      _ref$motionAppear = _ref.motionAppear,\n      motionAppear = _ref$motionAppear === void 0 ? true : _ref$motionAppear,\n      _ref$motionLeave = _ref.motionLeave,\n      motionLeave = _ref$motionLeave === void 0 ? true : _ref$motionLeave,\n      motionDeadline = _ref.motionDeadline,\n      motionLeaveImmediately = _ref.motionLeaveImmediately,\n      onAppearPrepare = _ref.onAppearPrepare,\n      onEnterPrepare = _ref.onEnterPrepare,\n      onLeavePrepare = _ref.onLeavePrepare,\n      onAppearStart = _ref.onAppearStart,\n      onEnterStart = _ref.onEnterStart,\n      onLeaveStart = _ref.onLeaveStart,\n      onAppearActive = _ref.onAppearActive,\n      onEnterActive = _ref.onEnterActive,\n      onLeaveActive = _ref.onLeaveActive,\n      onAppearEnd = _ref.onAppearEnd,\n      onEnterEnd = _ref.onEnterEnd,\n      onLeaveEnd = _ref.onLeaveEnd,\n      onVisibleChanged = _ref.onVisibleChanged; // Used for outer render usage to avoid `visible: false & status: none` to render nothing\n\n  var _useState = useState(),\n      _useState2 = _slicedToArray(_useState, 2),\n      asyncVisible = _useState2[0],\n      setAsyncVisible = _useState2[1];\n\n  var _useState3 = useState(STATUS_NONE),\n      _useState4 = _slicedToArray(_useState3, 2),\n      status = _useState4[0],\n      setStatus = _useState4[1];\n\n  var _useState5 = useState(null),\n      _useState6 = _slicedToArray(_useState5, 2),\n      style = _useState6[0],\n      setStyle = _useState6[1];\n\n  var mountedRef = useRef(false);\n  var deadlineRef = useRef(null);\n  var destroyedRef = useRef(false); // =========================== Dom Node ===========================\n\n  var cacheElementRef = useRef(null);\n\n  function getDomElement() {\n    var element = getElement();\n    return element || cacheElementRef.current;\n  } // ========================== Motion End ==========================\n\n\n  var activeRef = useRef(false);\n\n  function onInternalMotionEnd(event) {\n    var element = getDomElement();\n\n    if (event && !event.deadline && event.target !== element) {\n      // event exists\n      // not initiated by deadline\n      // transitionEnd not fired by inner elements\n      return;\n    }\n\n    var canEnd;\n\n    if (status === STATUS_APPEAR && activeRef.current) {\n      canEnd = onAppearEnd === null || onAppearEnd === void 0 ? void 0 : onAppearEnd(element, event);\n    } else if (status === STATUS_ENTER && activeRef.current) {\n      canEnd = onEnterEnd === null || onEnterEnd === void 0 ? void 0 : onEnterEnd(element, event);\n    } else if (status === STATUS_LEAVE && activeRef.current) {\n      canEnd = onLeaveEnd === null || onLeaveEnd === void 0 ? void 0 : onLeaveEnd(element, event);\n    } // Only update status when `canEnd` and not destroyed\n\n\n    if (canEnd !== false && !destroyedRef.current) {\n      setStatus(STATUS_NONE);\n      setStyle(null);\n    }\n  }\n\n  var _useDomMotionEvents = useDomMotionEvents(onInternalMotionEnd),\n      _useDomMotionEvents2 = _slicedToArray(_useDomMotionEvents, 1),\n      patchMotionEvents = _useDomMotionEvents2[0]; // ============================= Step =============================\n\n\n  var eventHandlers = React.useMemo(function () {\n    var _ref2, _ref3, _ref4;\n\n    switch (status) {\n      case 'appear':\n        return _ref2 = {}, _defineProperty(_ref2, STEP_PREPARE, onAppearPrepare), _defineProperty(_ref2, STEP_START, onAppearStart), _defineProperty(_ref2, STEP_ACTIVE, onAppearActive), _ref2;\n\n      case 'enter':\n        return _ref3 = {}, _defineProperty(_ref3, STEP_PREPARE, onEnterPrepare), _defineProperty(_ref3, STEP_START, onEnterStart), _defineProperty(_ref3, STEP_ACTIVE, onEnterActive), _ref3;\n\n      case 'leave':\n        return _ref4 = {}, _defineProperty(_ref4, STEP_PREPARE, onLeavePrepare), _defineProperty(_ref4, STEP_START, onLeaveStart), _defineProperty(_ref4, STEP_ACTIVE, onLeaveActive), _ref4;\n\n      default:\n        return {};\n    }\n  }, [status]);\n\n  var _useStepQueue = useStepQueue(status, function (newStep) {\n    // Only prepare step can be skip\n    if (newStep === STEP_PREPARE) {\n      var onPrepare = eventHandlers[STEP_PREPARE];\n\n      if (!onPrepare) {\n        return SkipStep;\n      }\n\n      return onPrepare(getDomElement());\n    } // Rest step is sync update\n\n\n    if (step in eventHandlers) {\n      var _eventHandlers$step;\n\n      setStyle(((_eventHandlers$step = eventHandlers[step]) === null || _eventHandlers$step === void 0 ? void 0 : _eventHandlers$step.call(eventHandlers, getDomElement(), null)) || null);\n    }\n\n    if (step === STEP_ACTIVE) {\n      // Patch events when motion needed\n      patchMotionEvents(getDomElement());\n\n      if (motionDeadline > 0) {\n        clearTimeout(deadlineRef.current);\n        deadlineRef.current = setTimeout(function () {\n          onInternalMotionEnd({\n            deadline: true\n          });\n        }, motionDeadline);\n      }\n    }\n\n    return DoStep;\n  }),\n      _useStepQueue2 = _slicedToArray(_useStepQueue, 2),\n      startStep = _useStepQueue2[0],\n      step = _useStepQueue2[1];\n\n  var active = isActive(step);\n  activeRef.current = active; // ============================ Status ============================\n  // Update with new status\n\n  useIsomorphicLayoutEffect(function () {\n    setAsyncVisible(visible);\n\n    if (!supportMotion) {\n      return;\n    }\n\n    var isMounted = mountedRef.current;\n    mountedRef.current = true;\n    var nextStatus; // Appear\n\n    if (!isMounted && visible && motionAppear) {\n      nextStatus = STATUS_APPEAR;\n    } // Enter\n\n\n    if (isMounted && visible && motionEnter) {\n      nextStatus = STATUS_ENTER;\n    } // Leave\n\n\n    if (isMounted && !visible && motionLeave || !isMounted && motionLeaveImmediately && !visible && motionLeave) {\n      nextStatus = STATUS_LEAVE;\n    } // Update to next status\n\n\n    if (nextStatus) {\n      setStatus(nextStatus);\n      startStep();\n    }\n  }, [visible]); // ============================ Effect ============================\n  // Reset when motion changed\n\n  useEffect(function () {\n    if ( // Cancel appear\n    status === STATUS_APPEAR && !motionAppear || // Cancel enter\n    status === STATUS_ENTER && !motionEnter || // Cancel leave\n    status === STATUS_LEAVE && !motionLeave) {\n      setStatus(STATUS_NONE);\n    }\n  }, [motionAppear, motionEnter, motionLeave]);\n  useEffect(function () {\n    return function () {\n      clearTimeout(deadlineRef.current);\n      destroyedRef.current = true;\n    };\n  }, []); // Trigger `onVisibleChanged`\n\n  useEffect(function () {\n    if (asyncVisible !== undefined && status === STATUS_NONE) {\n      onVisibleChanged === null || onVisibleChanged === void 0 ? void 0 : onVisibleChanged(asyncVisible);\n    }\n  }, [asyncVisible, status]); // ============================ Styles ============================\n\n  var mergedStyle = style;\n\n  if (eventHandlers[STEP_PREPARE] && step === STEP_START) {\n    mergedStyle = _objectSpread({\n      transition: 'none'\n    }, mergedStyle);\n  }\n\n  return [status, step, mergedStyle, asyncVisible !== null && asyncVisible !== void 0 ? asyncVisible : visible];\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-motion/es/hooks/useStatus.js"],"names":["_objectSpread","_defineProperty","_slicedToArray","React","useRef","useEffect","STATUS_APPEAR","STATUS_NONE","STATUS_LEAVE","STATUS_ENTER","STEP_PREPARE","STEP_START","STEP_ACTIVE","useState","useIsomorphicLayoutEffect","useStepQueue","DoStep","SkipStep","isActive","useDomMotionEvents","useStatus","supportMotion","visible","getElement","_ref","_ref$motionEnter","motionEnter","_ref$motionAppear","motionAppear","_ref$motionLeave","motionLeave","motionDeadline","motionLeaveImmediately","onAppearPrepare","onEnterPrepare","onLeavePrepare","onAppearStart","onEnterStart","onLeaveStart","onAppearActive","onEnterActive","onLeaveActive","onAppearEnd","onEnterEnd","onLeaveEnd","onVisibleChanged","_useState","_useState2","asyncVisible","setAsyncVisible","_useState3","_useState4","status","setStatus","_useState5","_useState6","style","setStyle","mountedRef","deadlineRef","destroyedRef","cacheElementRef","getDomElement","element","current","activeRef","onInternalMotionEnd","event","deadline","target","canEnd","_useDomMotionEvents","_useDomMotionEvents2","patchMotionEvents","eventHandlers","useMemo","_ref2","_ref3","_ref4","_useStepQueue","newStep","onPrepare","step","_eventHandlers$step","call","clearTimeout","setTimeout","_useStepQueue2","startStep","active","isMounted","nextStatus","undefined","mergedStyle","transition"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,0CAA1B;AACA,OAAOC,eAAP,MAA4B,2CAA5B;AACA,OAAOC,cAAP,MAA2B,0CAA3B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,MAAT,EAAiBC,SAAjB,QAAkC,OAAlC;AACA,SAASC,aAAT,EAAwBC,WAAxB,EAAqCC,YAArC,EAAmDC,YAAnD,EAAiEC,YAAjE,EAA+EC,UAA/E,EAA2FC,WAA3F,QAA8G,cAA9G;AACA,OAAOC,QAAP,MAAqB,YAArB;AACA,OAAOC,yBAAP,MAAsC,6BAAtC;AACA,OAAOC,YAAP,IAAuBC,MAAvB,EAA+BC,QAA/B,EAAyCC,QAAzC,QAAyD,gBAAzD;AACA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,eAAe,SAASC,SAAT,CAAmBC,aAAnB,EAAkCC,OAAlC,EAA2CC,UAA3C,EAAuDC,IAAvD,EAA6D;AAC1E,MAAIC,gBAAgB,GAAGD,IAAI,CAACE,WAA5B;AAAA,MACIA,WAAW,GAAGD,gBAAgB,KAAK,KAAK,CAA1B,GAA8B,IAA9B,GAAqCA,gBADvD;AAAA,MAEIE,iBAAiB,GAAGH,IAAI,CAACI,YAF7B;AAAA,MAGIA,YAAY,GAAGD,iBAAiB,KAAK,KAAK,CAA3B,GAA+B,IAA/B,GA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M9C;;AAE5B,MAAIyC,WAAW,GAAGrC,KAAlB;;AAEA,MAAIkB,aAAa,CAAChE,YAAD,CAAb,IAA+BwE,IAAI,KAAKvE,UAA5C,EAAwD;AACtDkF,IAAAA,WAAW,GAAG7F,aAAa,CAAC;AAC1B8F,MAAAA,UAAU,EAAE;AADc,KAAD,EAExBD,WAFwB,CAA3B;AAGD;;AAED,SAAO,CAACzC,MAAD,EAAS8B,IAAT,EAAeW,WAAf,EAA4B7C,YAAY,KAAK,IAAjB,IAAyBA,YAAY,KAAK,KAAK,CAA/C,GAAmDA,YAAnD,GAAkE1B,OAA9F,CAAP;AACD","sourcesContent":["import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useRef, useEffect } from 'react';\nimport { STATUS_APPEAR, STATUS_NONE, STATUS_LEAVE, STATUS_ENTER, STEP_PREPARE, STEP_START, STEP_ACTIVE } from '../interface';\nimport useState from './useState';\nimport useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';\nimport useStepQueue, { DoStep, SkipStep, isActive } from './useStepQueue';\nimport useDomMotionEvents from './useDomMotionEvents';\nexport default function useStatus(supportMotion, visible, getElement, _ref) {\n  var _ref$motionEnter = _ref.motionEnter,\n      motionEnter = _ref$motionEnter === void 0 ? true : _ref$motionEnter,\n      _ref$motionAppear = _ref.motionAppear,\n      motionAppear = _ref$motionAppear === void 0 ? true : _ref$motionAppear,\n      _ref$motionLeave = _ref.motionLeave,\n      motionLeave = _ref$motionLeave === void 0 ? true : _ref$motionLeave,\n      motionDeadline = _ref.motionDeadline,\n      motionLeaveImmediately = _ref.motionLeaveImmediately,\n      onAppearPrepare = _ref.onAppearPrepare,\n      onEnterPrepare = _ref.onEnterPrepare,\n      onLeavePrepare = _ref.onLeavePrepare,\n      onAppearStart = _ref.onAppearStart,\n      onEnterStart = _ref.onEnterStart,\n      onLeaveStart = _ref.onLeaveStart,\n      onAppearActive = _ref.onAppearActive,\n      onEnterActive = _ref.onEnterActive,\n      onLeaveActive = _ref.onLeaveActive,\n      onAppearEnd = _ref.onAppearEnd,\n      onEnterEnd = _ref.onEnterEnd,\n      onLeaveEnd = _ref.onLeaveEnd,\n      onVisibleChanged = _ref.onVisibleChanged;\n\n  // Used for outer render usage to avoid `visible: false & status: none` to render nothing\n  var _useState = useState(),\n      _useState2 = _slicedToArray(_useState, 2),\n      asyncVisible = _useState2[0],\n      setAsyncVisible = _useState2[1];\n\n  var _useState3 = useState(STATUS_NONE),\n      _useState4 = _slicedToArray(_useState3, 2),\n      status = _useState4[0],\n      setStatus = _useState4[1];\n\n  var _useState5 = useState(null),\n      _useState6 = _slicedToArray(_useState5, 2),\n      style = _useState6[0],\n      setStyle = _useState6[1];\n\n  var mountedRef = useRef(false);\n  var deadlineRef = useRef(null);\n  var destroyedRef = useRef(false); // =========================== Dom Node ===========================\n\n  var cacheElementRef = useRef(null);\n\n  function getDomElement() {\n    var element = getElement();\n    return element || cacheElementRef.current;\n  } // ========================== Motion End ==========================\n\n\n  var activeRef = useRef(false);\n\n  function onInternalMotionEnd(event) {\n    var element = getDomElement();\n\n    if (event && !event.deadline && event.target !== element) {\n      // event exists\n      // not initiated by deadline\n      // transitionEnd not fired by inner elements\n      return;\n    }\n\n    var canEnd;\n\n    if (status === STATUS_APPEAR && activeRef.current) {\n      canEnd = onAppearEnd === null || onAppearEnd === void 0 ? void 0 : onAppearEnd(element, event);\n    } else if (status === STATUS_ENTER && activeRef.current) {\n      canEnd = onEnterEnd === null || onEnterEnd === void 0 ? void 0 : onEnterEnd(element, event);\n    } else if (status === STATUS_LEAVE && activeRef.current) {\n      canEnd = onLeaveEnd === null || onLeaveEnd === void 0 ? void 0 : onLeaveEnd(element, event);\n    } // Only update status when `canEnd` and not destroyed\n\n\n    if (canEnd !== false && !destroyedRef.current) {\n      setStatus(STATUS_NONE);\n      setStyle(null);\n    }\n  }\n\n  var _useDomMotionEvents = useDomMotionEvents(onInternalMotionEnd),\n      _useDomMotionEvents2 = _slicedToArray(_useDomMotionEvents, 1),\n      patchMotionEvents = _useDomMotionEvents2[0]; // ============================= Step =============================\n\n\n  var eventHandlers = React.useMemo(function () {\n    var _ref2, _ref3, _ref4;\n\n    switch (status) {\n      case 'appear':\n        return _ref2 = {}, _defineProperty(_ref2, STEP_PREPARE, onAppearPrepare), _defineProperty(_ref2, STEP_START, onAppearStart), _defineProperty(_ref2, STEP_ACTIVE, onAppearActive), _ref2;\n\n      case 'enter':\n        return _ref3 = {}, _defineProperty(_ref3, STEP_PREPARE, onEnterPrepare), _defineProperty(_ref3, STEP_START, onEnterStart), _defineProperty(_ref3, STEP_ACTIVE, onEnterActive), _ref3;\n\n      case 'leave':\n        return _ref4 = {}, _defineProperty(_ref4, STEP_PREPARE, onLeavePrepare), _defineProperty(_ref4, STEP_START, onLeaveStart), _defineProperty(_ref4, STEP_ACTIVE, onLeaveActive), _ref4;\n\n      default:\n        return {};\n    }\n  }, [status]);\n\n  var _useStepQueue = useStepQueue(status, function (newStep) {\n    // Only prepare step can be skip\n    if (newStep === STEP_PREPARE) {\n      var onPrepare = eventHandlers[STEP_PREPARE];\n\n      if (!onPrepare) {\n        return SkipStep;\n      }\n\n      return onPrepare(getDomElement());\n    } // Rest step is sync update\n\n\n    if (step in eventHandlers) {\n      var _eventHandlers$step;\n\n      setStyle(((_eventHandlers$step = eventHandlers[step]) === null || _eventHandlers$step === void 0 ? void 0 : _eventHandlers$step.call(eventHandlers, getDomElement(), null)) || null);\n    }\n\n    if (step === STEP_ACTIVE) {\n      // Patch events when motion needed\n      patchMotionEvents(getDomElement());\n\n      if (motionDeadline > 0) {\n        clearTimeout(deadlineRef.current);\n        deadlineRef.current = setTimeout(function () {\n          onInternalMotionEnd({\n            deadline: true\n          });\n        }, motionDeadline);\n      }\n    }\n\n    return DoStep;\n  }),\n      _useStepQueue2 = _slicedToArray(_useStepQueue, 2),\n      startStep = _useStepQueue2[0],\n      step = _useStepQueue2[1];\n\n  var active = isActive(step);\n  activeRef.current = active; // ============================ Status ============================\n  // Update with new status\n\n  useIsomorphicLayoutEffect(function () {\n    setAsyncVisible(visible);\n\n    if (!supportMotion) {\n      return;\n    }\n\n    var isMounted = mountedRef.current;\n    mountedRef.current = true;\n    var nextStatus; // Appear\n\n    if (!isMounted && visible && motionAppear) {\n      nextStatus = STATUS_APPEAR;\n    } // Enter\n\n\n    if (isMounted && visible && motionEnter) {\n      nextStatus = STATUS_ENTER;\n    } // Leave\n\n\n    if (isMounted && !visible && motionLeave || !isMounted && motionLeaveImmediately && !visible && motionLeave) {\n      nextStatus = STATUS_LEAVE;\n    } // Update to next status\n\n\n    if (nextStatus) {\n      setStatus(nextStatus);\n      startStep();\n    }\n  }, [visible]); // ============================ Effect ============================\n  // Reset when motion changed\n\n  useEffect(function () {\n    if ( // Cancel appear\n    status === STATUS_APPEAR && !motionAppear || // Cancel enter\n    status === STATUS_ENTER && !motionEnter || // Cancel leave\n    status === STATUS_LEAVE && !motionLeave) {\n      setStatus(STATUS_NONE);\n    }\n  }, [motionAppear, motionEnter, motionLeave]);\n  useEffect(function () {\n    return function () {\n      clearTimeout(deadlineRef.current);\n      destroyedRef.current = true;\n    };\n  }, []); // Trigger `onVisibleChanged`\n\n  useEffect(function () {\n    if (asyncVisible !== undefined && status === STATUS_NONE) {\n      onVisibleChanged === null || onVisibleChanged === void 0 ? void 0 : onVisibleChanged(asyncVisible);\n    }\n  }, [asyncVisible, status]); // ============================ Styles ============================\n\n  var mergedStyle = style;\n\n  if (eventHandlers[STEP_PREPARE] && step === STEP_START) {\n    mergedStyle = _objectSpread({\n      transition: 'none'\n    }, mergedStyle);\n  }\n\n  return [status, step, mergedStyle, asyncVisible !== null && asyncVisible !== void 0 ? asyncVisible : visible];\n}"]},"metadata":{},"sourceType":"module"}