react-transition-group.js 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) :
  4. (global = global || self, factory(global.ReactTransitionGroup = {}, global.React, global.ReactDOM));
  5. }(this, (function (exports, React, ReactDOM) { 'use strict';
  6. var React__default = 'default' in React ? React['default'] : React;
  7. ReactDOM = ReactDOM && Object.prototype.hasOwnProperty.call(ReactDOM, 'default') ? ReactDOM['default'] : ReactDOM;
  8. function _extends() {
  9. _extends = Object.assign || function (target) {
  10. for (var i = 1; i < arguments.length; i++) {
  11. var source = arguments[i];
  12. for (var key in source) {
  13. if (Object.prototype.hasOwnProperty.call(source, key)) {
  14. target[key] = source[key];
  15. }
  16. }
  17. }
  18. return target;
  19. };
  20. return _extends.apply(this, arguments);
  21. }
  22. function _objectWithoutPropertiesLoose(source, excluded) {
  23. if (source == null) return {};
  24. var target = {};
  25. var sourceKeys = Object.keys(source);
  26. var key, i;
  27. for (i = 0; i < sourceKeys.length; i++) {
  28. key = sourceKeys[i];
  29. if (excluded.indexOf(key) >= 0) continue;
  30. target[key] = source[key];
  31. }
  32. return target;
  33. }
  34. function _inheritsLoose(subClass, superClass) {
  35. subClass.prototype = Object.create(superClass.prototype);
  36. subClass.prototype.constructor = subClass;
  37. subClass.__proto__ = superClass;
  38. }
  39. function createCommonjsModule(fn, module) {
  40. return module = { exports: {} }, fn(module, module.exports), module.exports;
  41. }
  42. var reactIs_development = createCommonjsModule(function (module, exports) {
  43. {
  44. (function() {
  45. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  46. // nor polyfill, then a plain number is used for performance.
  47. var hasSymbol = typeof Symbol === 'function' && Symbol.for;
  48. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
  49. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
  50. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
  51. var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
  52. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
  53. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
  54. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  55. // (unstable) APIs that have been removed. Can we remove the symbols?
  56. var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
  57. var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
  58. var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
  59. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
  60. var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
  61. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
  62. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
  63. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
  64. var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
  65. var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
  66. var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
  67. function isValidElementType(type) {
  68. return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
  69. type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
  70. }
  71. function typeOf(object) {
  72. if (typeof object === 'object' && object !== null) {
  73. var $$typeof = object.$$typeof;
  74. switch ($$typeof) {
  75. case REACT_ELEMENT_TYPE:
  76. var type = object.type;
  77. switch (type) {
  78. case REACT_ASYNC_MODE_TYPE:
  79. case REACT_CONCURRENT_MODE_TYPE:
  80. case REACT_FRAGMENT_TYPE:
  81. case REACT_PROFILER_TYPE:
  82. case REACT_STRICT_MODE_TYPE:
  83. case REACT_SUSPENSE_TYPE:
  84. return type;
  85. default:
  86. var $$typeofType = type && type.$$typeof;
  87. switch ($$typeofType) {
  88. case REACT_CONTEXT_TYPE:
  89. case REACT_FORWARD_REF_TYPE:
  90. case REACT_LAZY_TYPE:
  91. case REACT_MEMO_TYPE:
  92. case REACT_PROVIDER_TYPE:
  93. return $$typeofType;
  94. default:
  95. return $$typeof;
  96. }
  97. }
  98. case REACT_PORTAL_TYPE:
  99. return $$typeof;
  100. }
  101. }
  102. return undefined;
  103. } // AsyncMode is deprecated along with isAsyncMode
  104. var AsyncMode = REACT_ASYNC_MODE_TYPE;
  105. var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
  106. var ContextConsumer = REACT_CONTEXT_TYPE;
  107. var ContextProvider = REACT_PROVIDER_TYPE;
  108. var Element = REACT_ELEMENT_TYPE;
  109. var ForwardRef = REACT_FORWARD_REF_TYPE;
  110. var Fragment = REACT_FRAGMENT_TYPE;
  111. var Lazy = REACT_LAZY_TYPE;
  112. var Memo = REACT_MEMO_TYPE;
  113. var Portal = REACT_PORTAL_TYPE;
  114. var Profiler = REACT_PROFILER_TYPE;
  115. var StrictMode = REACT_STRICT_MODE_TYPE;
  116. var Suspense = REACT_SUSPENSE_TYPE;
  117. var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
  118. function isAsyncMode(object) {
  119. {
  120. if (!hasWarnedAboutDeprecatedIsAsyncMode) {
  121. hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
  122. console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
  123. }
  124. }
  125. return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
  126. }
  127. function isConcurrentMode(object) {
  128. return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
  129. }
  130. function isContextConsumer(object) {
  131. return typeOf(object) === REACT_CONTEXT_TYPE;
  132. }
  133. function isContextProvider(object) {
  134. return typeOf(object) === REACT_PROVIDER_TYPE;
  135. }
  136. function isElement(object) {
  137. return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
  138. }
  139. function isForwardRef(object) {
  140. return typeOf(object) === REACT_FORWARD_REF_TYPE;
  141. }
  142. function isFragment(object) {
  143. return typeOf(object) === REACT_FRAGMENT_TYPE;
  144. }
  145. function isLazy(object) {
  146. return typeOf(object) === REACT_LAZY_TYPE;
  147. }
  148. function isMemo(object) {
  149. return typeOf(object) === REACT_MEMO_TYPE;
  150. }
  151. function isPortal(object) {
  152. return typeOf(object) === REACT_PORTAL_TYPE;
  153. }
  154. function isProfiler(object) {
  155. return typeOf(object) === REACT_PROFILER_TYPE;
  156. }
  157. function isStrictMode(object) {
  158. return typeOf(object) === REACT_STRICT_MODE_TYPE;
  159. }
  160. function isSuspense(object) {
  161. return typeOf(object) === REACT_SUSPENSE_TYPE;
  162. }
  163. exports.AsyncMode = AsyncMode;
  164. exports.ConcurrentMode = ConcurrentMode;
  165. exports.ContextConsumer = ContextConsumer;
  166. exports.ContextProvider = ContextProvider;
  167. exports.Element = Element;
  168. exports.ForwardRef = ForwardRef;
  169. exports.Fragment = Fragment;
  170. exports.Lazy = Lazy;
  171. exports.Memo = Memo;
  172. exports.Portal = Portal;
  173. exports.Profiler = Profiler;
  174. exports.StrictMode = StrictMode;
  175. exports.Suspense = Suspense;
  176. exports.isAsyncMode = isAsyncMode;
  177. exports.isConcurrentMode = isConcurrentMode;
  178. exports.isContextConsumer = isContextConsumer;
  179. exports.isContextProvider = isContextProvider;
  180. exports.isElement = isElement;
  181. exports.isForwardRef = isForwardRef;
  182. exports.isFragment = isFragment;
  183. exports.isLazy = isLazy;
  184. exports.isMemo = isMemo;
  185. exports.isPortal = isPortal;
  186. exports.isProfiler = isProfiler;
  187. exports.isStrictMode = isStrictMode;
  188. exports.isSuspense = isSuspense;
  189. exports.isValidElementType = isValidElementType;
  190. exports.typeOf = typeOf;
  191. })();
  192. }
  193. });
  194. var reactIs_development_1 = reactIs_development.AsyncMode;
  195. var reactIs_development_2 = reactIs_development.ConcurrentMode;
  196. var reactIs_development_3 = reactIs_development.ContextConsumer;
  197. var reactIs_development_4 = reactIs_development.ContextProvider;
  198. var reactIs_development_5 = reactIs_development.Element;
  199. var reactIs_development_6 = reactIs_development.ForwardRef;
  200. var reactIs_development_7 = reactIs_development.Fragment;
  201. var reactIs_development_8 = reactIs_development.Lazy;
  202. var reactIs_development_9 = reactIs_development.Memo;
  203. var reactIs_development_10 = reactIs_development.Portal;
  204. var reactIs_development_11 = reactIs_development.Profiler;
  205. var reactIs_development_12 = reactIs_development.StrictMode;
  206. var reactIs_development_13 = reactIs_development.Suspense;
  207. var reactIs_development_14 = reactIs_development.isAsyncMode;
  208. var reactIs_development_15 = reactIs_development.isConcurrentMode;
  209. var reactIs_development_16 = reactIs_development.isContextConsumer;
  210. var reactIs_development_17 = reactIs_development.isContextProvider;
  211. var reactIs_development_18 = reactIs_development.isElement;
  212. var reactIs_development_19 = reactIs_development.isForwardRef;
  213. var reactIs_development_20 = reactIs_development.isFragment;
  214. var reactIs_development_21 = reactIs_development.isLazy;
  215. var reactIs_development_22 = reactIs_development.isMemo;
  216. var reactIs_development_23 = reactIs_development.isPortal;
  217. var reactIs_development_24 = reactIs_development.isProfiler;
  218. var reactIs_development_25 = reactIs_development.isStrictMode;
  219. var reactIs_development_26 = reactIs_development.isSuspense;
  220. var reactIs_development_27 = reactIs_development.isValidElementType;
  221. var reactIs_development_28 = reactIs_development.typeOf;
  222. var reactIs = createCommonjsModule(function (module) {
  223. {
  224. module.exports = reactIs_development;
  225. }
  226. });
  227. /*
  228. object-assign
  229. (c) Sindre Sorhus
  230. @license MIT
  231. */
  232. /* eslint-disable no-unused-vars */
  233. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  234. var hasOwnProperty = Object.prototype.hasOwnProperty;
  235. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  236. function toObject(val) {
  237. if (val === null || val === undefined) {
  238. throw new TypeError('Object.assign cannot be called with null or undefined');
  239. }
  240. return Object(val);
  241. }
  242. function shouldUseNative() {
  243. try {
  244. if (!Object.assign) {
  245. return false;
  246. }
  247. // Detect buggy property enumeration order in older V8 versions.
  248. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  249. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  250. test1[5] = 'de';
  251. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  252. return false;
  253. }
  254. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  255. var test2 = {};
  256. for (var i = 0; i < 10; i++) {
  257. test2['_' + String.fromCharCode(i)] = i;
  258. }
  259. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  260. return test2[n];
  261. });
  262. if (order2.join('') !== '0123456789') {
  263. return false;
  264. }
  265. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  266. var test3 = {};
  267. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  268. test3[letter] = letter;
  269. });
  270. if (Object.keys(Object.assign({}, test3)).join('') !==
  271. 'abcdefghijklmnopqrst') {
  272. return false;
  273. }
  274. return true;
  275. } catch (err) {
  276. // We don't expect any of the above to throw, but better to be safe.
  277. return false;
  278. }
  279. }
  280. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  281. var from;
  282. var to = toObject(target);
  283. var symbols;
  284. for (var s = 1; s < arguments.length; s++) {
  285. from = Object(arguments[s]);
  286. for (var key in from) {
  287. if (hasOwnProperty.call(from, key)) {
  288. to[key] = from[key];
  289. }
  290. }
  291. if (getOwnPropertySymbols) {
  292. symbols = getOwnPropertySymbols(from);
  293. for (var i = 0; i < symbols.length; i++) {
  294. if (propIsEnumerable.call(from, symbols[i])) {
  295. to[symbols[i]] = from[symbols[i]];
  296. }
  297. }
  298. }
  299. }
  300. return to;
  301. };
  302. /**
  303. * Copyright (c) 2013-present, Facebook, Inc.
  304. *
  305. * This source code is licensed under the MIT license found in the
  306. * LICENSE file in the root directory of this source tree.
  307. */
  308. var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
  309. var ReactPropTypesSecret_1 = ReactPropTypesSecret;
  310. var printWarning = function() {};
  311. {
  312. var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
  313. var loggedTypeFailures = {};
  314. var has = Function.call.bind(Object.prototype.hasOwnProperty);
  315. printWarning = function(text) {
  316. var message = 'Warning: ' + text;
  317. if (typeof console !== 'undefined') {
  318. console.error(message);
  319. }
  320. try {
  321. // --- Welcome to debugging React ---
  322. // This error was thrown as a convenience so that you can use this stack
  323. // to find the callsite that caused this warning to fire.
  324. throw new Error(message);
  325. } catch (x) {}
  326. };
  327. }
  328. /**
  329. * Assert that the values match with the type specs.
  330. * Error messages are memorized and will only be shown once.
  331. *
  332. * @param {object} typeSpecs Map of name to a ReactPropType
  333. * @param {object} values Runtime values that need to be type-checked
  334. * @param {string} location e.g. "prop", "context", "child context"
  335. * @param {string} componentName Name of the component for error messages.
  336. * @param {?Function} getStack Returns the component stack.
  337. * @private
  338. */
  339. function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
  340. {
  341. for (var typeSpecName in typeSpecs) {
  342. if (has(typeSpecs, typeSpecName)) {
  343. var error;
  344. // Prop type validation may throw. In case they do, we don't want to
  345. // fail the render phase where it didn't fail before. So we log it.
  346. // After these have been cleaned up, we'll let them throw.
  347. try {
  348. // This is intentionally an invariant that gets caught. It's the same
  349. // behavior as without this statement except with a better message.
  350. if (typeof typeSpecs[typeSpecName] !== 'function') {
  351. var err = Error(
  352. (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
  353. 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
  354. );
  355. err.name = 'Invariant Violation';
  356. throw err;
  357. }
  358. error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
  359. } catch (ex) {
  360. error = ex;
  361. }
  362. if (error && !(error instanceof Error)) {
  363. printWarning(
  364. (componentName || 'React class') + ': type specification of ' +
  365. location + ' `' + typeSpecName + '` is invalid; the type checker ' +
  366. 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
  367. 'You may have forgotten to pass an argument to the type checker ' +
  368. 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
  369. 'shape all require an argument).'
  370. );
  371. }
  372. if (error instanceof Error && !(error.message in loggedTypeFailures)) {
  373. // Only monitor this failure once because there tends to be a lot of the
  374. // same error.
  375. loggedTypeFailures[error.message] = true;
  376. var stack = getStack ? getStack() : '';
  377. printWarning(
  378. 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
  379. );
  380. }
  381. }
  382. }
  383. }
  384. }
  385. /**
  386. * Resets warning cache when testing.
  387. *
  388. * @private
  389. */
  390. checkPropTypes.resetWarningCache = function() {
  391. {
  392. loggedTypeFailures = {};
  393. }
  394. };
  395. var checkPropTypes_1 = checkPropTypes;
  396. var has$1 = Function.call.bind(Object.prototype.hasOwnProperty);
  397. var printWarning$1 = function() {};
  398. {
  399. printWarning$1 = function(text) {
  400. var message = 'Warning: ' + text;
  401. if (typeof console !== 'undefined') {
  402. console.error(message);
  403. }
  404. try {
  405. // --- Welcome to debugging React ---
  406. // This error was thrown as a convenience so that you can use this stack
  407. // to find the callsite that caused this warning to fire.
  408. throw new Error(message);
  409. } catch (x) {}
  410. };
  411. }
  412. function emptyFunctionThatReturnsNull() {
  413. return null;
  414. }
  415. var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
  416. /* global Symbol */
  417. var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  418. var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
  419. /**
  420. * Returns the iterator method function contained on the iterable object.
  421. *
  422. * Be sure to invoke the function with the iterable as context:
  423. *
  424. * var iteratorFn = getIteratorFn(myIterable);
  425. * if (iteratorFn) {
  426. * var iterator = iteratorFn.call(myIterable);
  427. * ...
  428. * }
  429. *
  430. * @param {?object} maybeIterable
  431. * @return {?function}
  432. */
  433. function getIteratorFn(maybeIterable) {
  434. var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
  435. if (typeof iteratorFn === 'function') {
  436. return iteratorFn;
  437. }
  438. }
  439. /**
  440. * Collection of methods that allow declaration and validation of props that are
  441. * supplied to React components. Example usage:
  442. *
  443. * var Props = require('ReactPropTypes');
  444. * var MyArticle = React.createClass({
  445. * propTypes: {
  446. * // An optional string prop named "description".
  447. * description: Props.string,
  448. *
  449. * // A required enum prop named "category".
  450. * category: Props.oneOf(['News','Photos']).isRequired,
  451. *
  452. * // A prop named "dialog" that requires an instance of Dialog.
  453. * dialog: Props.instanceOf(Dialog).isRequired
  454. * },
  455. * render: function() { ... }
  456. * });
  457. *
  458. * A more formal specification of how these methods are used:
  459. *
  460. * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
  461. * decl := ReactPropTypes.{type}(.isRequired)?
  462. *
  463. * Each and every declaration produces a function with the same signature. This
  464. * allows the creation of custom validation functions. For example:
  465. *
  466. * var MyLink = React.createClass({
  467. * propTypes: {
  468. * // An optional string or URI prop named "href".
  469. * href: function(props, propName, componentName) {
  470. * var propValue = props[propName];
  471. * if (propValue != null && typeof propValue !== 'string' &&
  472. * !(propValue instanceof URI)) {
  473. * return new Error(
  474. * 'Expected a string or an URI for ' + propName + ' in ' +
  475. * componentName
  476. * );
  477. * }
  478. * }
  479. * },
  480. * render: function() {...}
  481. * });
  482. *
  483. * @internal
  484. */
  485. var ANONYMOUS = '<<anonymous>>';
  486. // Important!
  487. // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
  488. var ReactPropTypes = {
  489. array: createPrimitiveTypeChecker('array'),
  490. bool: createPrimitiveTypeChecker('boolean'),
  491. func: createPrimitiveTypeChecker('function'),
  492. number: createPrimitiveTypeChecker('number'),
  493. object: createPrimitiveTypeChecker('object'),
  494. string: createPrimitiveTypeChecker('string'),
  495. symbol: createPrimitiveTypeChecker('symbol'),
  496. any: createAnyTypeChecker(),
  497. arrayOf: createArrayOfTypeChecker,
  498. element: createElementTypeChecker(),
  499. elementType: createElementTypeTypeChecker(),
  500. instanceOf: createInstanceTypeChecker,
  501. node: createNodeChecker(),
  502. objectOf: createObjectOfTypeChecker,
  503. oneOf: createEnumTypeChecker,
  504. oneOfType: createUnionTypeChecker,
  505. shape: createShapeTypeChecker,
  506. exact: createStrictShapeTypeChecker,
  507. };
  508. /**
  509. * inlined Object.is polyfill to avoid requiring consumers ship their own
  510. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  511. */
  512. /*eslint-disable no-self-compare*/
  513. function is(x, y) {
  514. // SameValue algorithm
  515. if (x === y) {
  516. // Steps 1-5, 7-10
  517. // Steps 6.b-6.e: +0 != -0
  518. return x !== 0 || 1 / x === 1 / y;
  519. } else {
  520. // Step 6.a: NaN == NaN
  521. return x !== x && y !== y;
  522. }
  523. }
  524. /*eslint-enable no-self-compare*/
  525. /**
  526. * We use an Error-like object for backward compatibility as people may call
  527. * PropTypes directly and inspect their output. However, we don't use real
  528. * Errors anymore. We don't inspect their stack anyway, and creating them
  529. * is prohibitively expensive if they are created too often, such as what
  530. * happens in oneOfType() for any type before the one that matched.
  531. */
  532. function PropTypeError(message) {
  533. this.message = message;
  534. this.stack = '';
  535. }
  536. // Make `instanceof Error` still work for returned errors.
  537. PropTypeError.prototype = Error.prototype;
  538. function createChainableTypeChecker(validate) {
  539. {
  540. var manualPropTypeCallCache = {};
  541. var manualPropTypeWarningCount = 0;
  542. }
  543. function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
  544. componentName = componentName || ANONYMOUS;
  545. propFullName = propFullName || propName;
  546. if (secret !== ReactPropTypesSecret_1) {
  547. if (throwOnDirectAccess) {
  548. // New behavior only for users of `prop-types` package
  549. var err = new Error(
  550. 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
  551. 'Use `PropTypes.checkPropTypes()` to call them. ' +
  552. 'Read more at http://fb.me/use-check-prop-types'
  553. );
  554. err.name = 'Invariant Violation';
  555. throw err;
  556. } else if ( typeof console !== 'undefined') {
  557. // Old behavior for people using React.PropTypes
  558. var cacheKey = componentName + ':' + propName;
  559. if (
  560. !manualPropTypeCallCache[cacheKey] &&
  561. // Avoid spamming the console because they are often not actionable except for lib authors
  562. manualPropTypeWarningCount < 3
  563. ) {
  564. printWarning$1(
  565. 'You are manually calling a React.PropTypes validation ' +
  566. 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
  567. 'and will throw in the standalone `prop-types` package. ' +
  568. 'You may be seeing this warning due to a third-party PropTypes ' +
  569. 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
  570. );
  571. manualPropTypeCallCache[cacheKey] = true;
  572. manualPropTypeWarningCount++;
  573. }
  574. }
  575. }
  576. if (props[propName] == null) {
  577. if (isRequired) {
  578. if (props[propName] === null) {
  579. return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
  580. }
  581. return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
  582. }
  583. return null;
  584. } else {
  585. return validate(props, propName, componentName, location, propFullName);
  586. }
  587. }
  588. var chainedCheckType = checkType.bind(null, false);
  589. chainedCheckType.isRequired = checkType.bind(null, true);
  590. return chainedCheckType;
  591. }
  592. function createPrimitiveTypeChecker(expectedType) {
  593. function validate(props, propName, componentName, location, propFullName, secret) {
  594. var propValue = props[propName];
  595. var propType = getPropType(propValue);
  596. if (propType !== expectedType) {
  597. // `propValue` being instance of, say, date/regexp, pass the 'object'
  598. // check, but we can offer a more precise error message here rather than
  599. // 'of type `object`'.
  600. var preciseType = getPreciseType(propValue);
  601. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
  602. }
  603. return null;
  604. }
  605. return createChainableTypeChecker(validate);
  606. }
  607. function createAnyTypeChecker() {
  608. return createChainableTypeChecker(emptyFunctionThatReturnsNull);
  609. }
  610. function createArrayOfTypeChecker(typeChecker) {
  611. function validate(props, propName, componentName, location, propFullName) {
  612. if (typeof typeChecker !== 'function') {
  613. return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
  614. }
  615. var propValue = props[propName];
  616. if (!Array.isArray(propValue)) {
  617. var propType = getPropType(propValue);
  618. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
  619. }
  620. for (var i = 0; i < propValue.length; i++) {
  621. var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
  622. if (error instanceof Error) {
  623. return error;
  624. }
  625. }
  626. return null;
  627. }
  628. return createChainableTypeChecker(validate);
  629. }
  630. function createElementTypeChecker() {
  631. function validate(props, propName, componentName, location, propFullName) {
  632. var propValue = props[propName];
  633. if (!isValidElement(propValue)) {
  634. var propType = getPropType(propValue);
  635. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
  636. }
  637. return null;
  638. }
  639. return createChainableTypeChecker(validate);
  640. }
  641. function createElementTypeTypeChecker() {
  642. function validate(props, propName, componentName, location, propFullName) {
  643. var propValue = props[propName];
  644. if (!reactIs.isValidElementType(propValue)) {
  645. var propType = getPropType(propValue);
  646. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
  647. }
  648. return null;
  649. }
  650. return createChainableTypeChecker(validate);
  651. }
  652. function createInstanceTypeChecker(expectedClass) {
  653. function validate(props, propName, componentName, location, propFullName) {
  654. if (!(props[propName] instanceof expectedClass)) {
  655. var expectedClassName = expectedClass.name || ANONYMOUS;
  656. var actualClassName = getClassName(props[propName]);
  657. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
  658. }
  659. return null;
  660. }
  661. return createChainableTypeChecker(validate);
  662. }
  663. function createEnumTypeChecker(expectedValues) {
  664. if (!Array.isArray(expectedValues)) {
  665. {
  666. if (arguments.length > 1) {
  667. printWarning$1(
  668. 'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
  669. 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
  670. );
  671. } else {
  672. printWarning$1('Invalid argument supplied to oneOf, expected an array.');
  673. }
  674. }
  675. return emptyFunctionThatReturnsNull;
  676. }
  677. function validate(props, propName, componentName, location, propFullName) {
  678. var propValue = props[propName];
  679. for (var i = 0; i < expectedValues.length; i++) {
  680. if (is(propValue, expectedValues[i])) {
  681. return null;
  682. }
  683. }
  684. var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
  685. var type = getPreciseType(value);
  686. if (type === 'symbol') {
  687. return String(value);
  688. }
  689. return value;
  690. });
  691. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
  692. }
  693. return createChainableTypeChecker(validate);
  694. }
  695. function createObjectOfTypeChecker(typeChecker) {
  696. function validate(props, propName, componentName, location, propFullName) {
  697. if (typeof typeChecker !== 'function') {
  698. return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
  699. }
  700. var propValue = props[propName];
  701. var propType = getPropType(propValue);
  702. if (propType !== 'object') {
  703. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
  704. }
  705. for (var key in propValue) {
  706. if (has$1(propValue, key)) {
  707. var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  708. if (error instanceof Error) {
  709. return error;
  710. }
  711. }
  712. }
  713. return null;
  714. }
  715. return createChainableTypeChecker(validate);
  716. }
  717. function createUnionTypeChecker(arrayOfTypeCheckers) {
  718. if (!Array.isArray(arrayOfTypeCheckers)) {
  719. printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.') ;
  720. return emptyFunctionThatReturnsNull;
  721. }
  722. for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
  723. var checker = arrayOfTypeCheckers[i];
  724. if (typeof checker !== 'function') {
  725. printWarning$1(
  726. 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
  727. 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
  728. );
  729. return emptyFunctionThatReturnsNull;
  730. }
  731. }
  732. function validate(props, propName, componentName, location, propFullName) {
  733. for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
  734. var checker = arrayOfTypeCheckers[i];
  735. if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) {
  736. return null;
  737. }
  738. }
  739. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
  740. }
  741. return createChainableTypeChecker(validate);
  742. }
  743. function createNodeChecker() {
  744. function validate(props, propName, componentName, location, propFullName) {
  745. if (!isNode(props[propName])) {
  746. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
  747. }
  748. return null;
  749. }
  750. return createChainableTypeChecker(validate);
  751. }
  752. function createShapeTypeChecker(shapeTypes) {
  753. function validate(props, propName, componentName, location, propFullName) {
  754. var propValue = props[propName];
  755. var propType = getPropType(propValue);
  756. if (propType !== 'object') {
  757. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
  758. }
  759. for (var key in shapeTypes) {
  760. var checker = shapeTypes[key];
  761. if (!checker) {
  762. continue;
  763. }
  764. var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  765. if (error) {
  766. return error;
  767. }
  768. }
  769. return null;
  770. }
  771. return createChainableTypeChecker(validate);
  772. }
  773. function createStrictShapeTypeChecker(shapeTypes) {
  774. function validate(props, propName, componentName, location, propFullName) {
  775. var propValue = props[propName];
  776. var propType = getPropType(propValue);
  777. if (propType !== 'object') {
  778. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
  779. }
  780. // We need to check all keys in case some are required but missing from
  781. // props.
  782. var allKeys = objectAssign({}, props[propName], shapeTypes);
  783. for (var key in allKeys) {
  784. var checker = shapeTypes[key];
  785. if (!checker) {
  786. return new PropTypeError(
  787. 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
  788. '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
  789. '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
  790. );
  791. }
  792. var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  793. if (error) {
  794. return error;
  795. }
  796. }
  797. return null;
  798. }
  799. return createChainableTypeChecker(validate);
  800. }
  801. function isNode(propValue) {
  802. switch (typeof propValue) {
  803. case 'number':
  804. case 'string':
  805. case 'undefined':
  806. return true;
  807. case 'boolean':
  808. return !propValue;
  809. case 'object':
  810. if (Array.isArray(propValue)) {
  811. return propValue.every(isNode);
  812. }
  813. if (propValue === null || isValidElement(propValue)) {
  814. return true;
  815. }
  816. var iteratorFn = getIteratorFn(propValue);
  817. if (iteratorFn) {
  818. var iterator = iteratorFn.call(propValue);
  819. var step;
  820. if (iteratorFn !== propValue.entries) {
  821. while (!(step = iterator.next()).done) {
  822. if (!isNode(step.value)) {
  823. return false;
  824. }
  825. }
  826. } else {
  827. // Iterator will provide entry [k,v] tuples rather than values.
  828. while (!(step = iterator.next()).done) {
  829. var entry = step.value;
  830. if (entry) {
  831. if (!isNode(entry[1])) {
  832. return false;
  833. }
  834. }
  835. }
  836. }
  837. } else {
  838. return false;
  839. }
  840. return true;
  841. default:
  842. return false;
  843. }
  844. }
  845. function isSymbol(propType, propValue) {
  846. // Native Symbol.
  847. if (propType === 'symbol') {
  848. return true;
  849. }
  850. // falsy value can't be a Symbol
  851. if (!propValue) {
  852. return false;
  853. }
  854. // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
  855. if (propValue['@@toStringTag'] === 'Symbol') {
  856. return true;
  857. }
  858. // Fallback for non-spec compliant Symbols which are polyfilled.
  859. if (typeof Symbol === 'function' && propValue instanceof Symbol) {
  860. return true;
  861. }
  862. return false;
  863. }
  864. // Equivalent of `typeof` but with special handling for array and regexp.
  865. function getPropType(propValue) {
  866. var propType = typeof propValue;
  867. if (Array.isArray(propValue)) {
  868. return 'array';
  869. }
  870. if (propValue instanceof RegExp) {
  871. // Old webkits (at least until Android 4.0) return 'function' rather than
  872. // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
  873. // passes PropTypes.object.
  874. return 'object';
  875. }
  876. if (isSymbol(propType, propValue)) {
  877. return 'symbol';
  878. }
  879. return propType;
  880. }
  881. // This handles more types than `getPropType`. Only used for error messages.
  882. // See `createPrimitiveTypeChecker`.
  883. function getPreciseType(propValue) {
  884. if (typeof propValue === 'undefined' || propValue === null) {
  885. return '' + propValue;
  886. }
  887. var propType = getPropType(propValue);
  888. if (propType === 'object') {
  889. if (propValue instanceof Date) {
  890. return 'date';
  891. } else if (propValue instanceof RegExp) {
  892. return 'regexp';
  893. }
  894. }
  895. return propType;
  896. }
  897. // Returns a string that is postfixed to a warning about an invalid type.
  898. // For example, "undefined" or "of type array"
  899. function getPostfixForTypeWarning(value) {
  900. var type = getPreciseType(value);
  901. switch (type) {
  902. case 'array':
  903. case 'object':
  904. return 'an ' + type;
  905. case 'boolean':
  906. case 'date':
  907. case 'regexp':
  908. return 'a ' + type;
  909. default:
  910. return type;
  911. }
  912. }
  913. // Returns class name of the object, if any.
  914. function getClassName(propValue) {
  915. if (!propValue.constructor || !propValue.constructor.name) {
  916. return ANONYMOUS;
  917. }
  918. return propValue.constructor.name;
  919. }
  920. ReactPropTypes.checkPropTypes = checkPropTypes_1;
  921. ReactPropTypes.resetWarningCache = checkPropTypes_1.resetWarningCache;
  922. ReactPropTypes.PropTypes = ReactPropTypes;
  923. return ReactPropTypes;
  924. };
  925. var propTypes = createCommonjsModule(function (module) {
  926. /**
  927. * Copyright (c) 2013-present, Facebook, Inc.
  928. *
  929. * This source code is licensed under the MIT license found in the
  930. * LICENSE file in the root directory of this source tree.
  931. */
  932. {
  933. var ReactIs = reactIs;
  934. // By explicitly using `prop-types` you are opting into new development behavior.
  935. // http://fb.me/prop-types-in-prod
  936. var throwOnDirectAccess = true;
  937. module.exports = factoryWithTypeCheckers(ReactIs.isElement, throwOnDirectAccess);
  938. }
  939. });
  940. var propTypes_1 = propTypes.object;
  941. var propTypes_2 = propTypes.oneOfType;
  942. var propTypes_3 = propTypes.element;
  943. var propTypes_4 = propTypes.bool;
  944. var propTypes_5 = propTypes.func;
  945. function hasClass(element, className) {
  946. if (element.classList) return !!className && element.classList.contains(className);
  947. return (" " + (element.className.baseVal || element.className) + " ").indexOf(" " + className + " ") !== -1;
  948. }
  949. function addClass(element, className) {
  950. if (element.classList) element.classList.add(className);else if (!hasClass(element, className)) if (typeof element.className === 'string') element.className = element.className + " " + className;else element.setAttribute('class', (element.className && element.className.baseVal || '') + " " + className);
  951. }
  952. function replaceClassName(origClass, classToRemove) {
  953. return origClass.replace(new RegExp("(^|\\s)" + classToRemove + "(?:\\s|$)", 'g'), '$1').replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, '');
  954. }
  955. function removeClass(element, className) {
  956. if (element.classList) {
  957. element.classList.remove(className);
  958. } else if (typeof element.className === 'string') {
  959. element.className = replaceClassName(element.className, className);
  960. } else {
  961. element.setAttribute('class', replaceClassName(element.className && element.className.baseVal || '', className));
  962. }
  963. }
  964. var config = {
  965. disabled: false
  966. };
  967. var timeoutsShape = propTypes.oneOfType([propTypes.number, propTypes.shape({
  968. enter: propTypes.number,
  969. exit: propTypes.number,
  970. appear: propTypes.number
  971. }).isRequired]) ;
  972. var classNamesShape = propTypes.oneOfType([propTypes.string, propTypes.shape({
  973. enter: propTypes.string,
  974. exit: propTypes.string,
  975. active: propTypes.string
  976. }), propTypes.shape({
  977. enter: propTypes.string,
  978. enterDone: propTypes.string,
  979. enterActive: propTypes.string,
  980. exit: propTypes.string,
  981. exitDone: propTypes.string,
  982. exitActive: propTypes.string
  983. })]) ;
  984. var TransitionGroupContext = React__default.createContext(null);
  985. var forceReflow = function forceReflow(node) {
  986. return node.scrollTop;
  987. };
  988. var UNMOUNTED = 'unmounted';
  989. var EXITED = 'exited';
  990. var ENTERING = 'entering';
  991. var ENTERED = 'entered';
  992. var EXITING = 'exiting';
  993. /**
  994. * The Transition component lets you describe a transition from one component
  995. * state to another _over time_ with a simple declarative API. Most commonly
  996. * it's used to animate the mounting and unmounting of a component, but can also
  997. * be used to describe in-place transition states as well.
  998. *
  999. * ---
  1000. *
  1001. * **Note**: `Transition` is a platform-agnostic base component. If you're using
  1002. * transitions in CSS, you'll probably want to use
  1003. * [`CSSTransition`](https://reactcommunity.org/react-transition-group/css-transition)
  1004. * instead. It inherits all the features of `Transition`, but contains
  1005. * additional features necessary to play nice with CSS transitions (hence the
  1006. * name of the component).
  1007. *
  1008. * ---
  1009. *
  1010. * By default the `Transition` component does not alter the behavior of the
  1011. * component it renders, it only tracks "enter" and "exit" states for the
  1012. * components. It's up to you to give meaning and effect to those states. For
  1013. * example we can add styles to a component when it enters or exits:
  1014. *
  1015. * ```jsx
  1016. * import { Transition } from 'react-transition-group';
  1017. *
  1018. * const duration = 300;
  1019. *
  1020. * const defaultStyle = {
  1021. * transition: `opacity ${duration}ms ease-in-out`,
  1022. * opacity: 0,
  1023. * }
  1024. *
  1025. * const transitionStyles = {
  1026. * entering: { opacity: 1 },
  1027. * entered: { opacity: 1 },
  1028. * exiting: { opacity: 0 },
  1029. * exited: { opacity: 0 },
  1030. * };
  1031. *
  1032. * const Fade = ({ in: inProp }) => (
  1033. * <Transition in={inProp} timeout={duration}>
  1034. * {state => (
  1035. * <div style={{
  1036. * ...defaultStyle,
  1037. * ...transitionStyles[state]
  1038. * }}>
  1039. * I'm a fade Transition!
  1040. * </div>
  1041. * )}
  1042. * </Transition>
  1043. * );
  1044. * ```
  1045. *
  1046. * There are 4 main states a Transition can be in:
  1047. * - `'entering'`
  1048. * - `'entered'`
  1049. * - `'exiting'`
  1050. * - `'exited'`
  1051. *
  1052. * Transition state is toggled via the `in` prop. When `true` the component
  1053. * begins the "Enter" stage. During this stage, the component will shift from
  1054. * its current transition state, to `'entering'` for the duration of the
  1055. * transition and then to the `'entered'` stage once it's complete. Let's take
  1056. * the following example (we'll use the
  1057. * [useState](https://reactjs.org/docs/hooks-reference.html#usestate) hook):
  1058. *
  1059. * ```jsx
  1060. * function App() {
  1061. * const [inProp, setInProp] = useState(false);
  1062. * return (
  1063. * <div>
  1064. * <Transition in={inProp} timeout={500}>
  1065. * {state => (
  1066. * // ...
  1067. * )}
  1068. * </Transition>
  1069. * <button onClick={() => setInProp(true)}>
  1070. * Click to Enter
  1071. * </button>
  1072. * </div>
  1073. * );
  1074. * }
  1075. * ```
  1076. *
  1077. * When the button is clicked the component will shift to the `'entering'` state
  1078. * and stay there for 500ms (the value of `timeout`) before it finally switches
  1079. * to `'entered'`.
  1080. *
  1081. * When `in` is `false` the same thing happens except the state moves from
  1082. * `'exiting'` to `'exited'`.
  1083. */
  1084. var Transition = /*#__PURE__*/function (_React$Component) {
  1085. _inheritsLoose(Transition, _React$Component);
  1086. function Transition(props, context) {
  1087. var _this;
  1088. _this = _React$Component.call(this, props, context) || this;
  1089. var parentGroup = context; // In the context of a TransitionGroup all enters are really appears
  1090. var appear = parentGroup && !parentGroup.isMounting ? props.enter : props.appear;
  1091. var initialStatus;
  1092. _this.appearStatus = null;
  1093. if (props.in) {
  1094. if (appear) {
  1095. initialStatus = EXITED;
  1096. _this.appearStatus = ENTERING;
  1097. } else {
  1098. initialStatus = ENTERED;
  1099. }
  1100. } else {
  1101. if (props.unmountOnExit || props.mountOnEnter) {
  1102. initialStatus = UNMOUNTED;
  1103. } else {
  1104. initialStatus = EXITED;
  1105. }
  1106. }
  1107. _this.state = {
  1108. status: initialStatus
  1109. };
  1110. _this.nextCallback = null;
  1111. return _this;
  1112. }
  1113. Transition.getDerivedStateFromProps = function getDerivedStateFromProps(_ref, prevState) {
  1114. var nextIn = _ref.in;
  1115. if (nextIn && prevState.status === UNMOUNTED) {
  1116. return {
  1117. status: EXITED
  1118. };
  1119. }
  1120. return null;
  1121. } // getSnapshotBeforeUpdate(prevProps) {
  1122. // let nextStatus = null
  1123. // if (prevProps !== this.props) {
  1124. // const { status } = this.state
  1125. // if (this.props.in) {
  1126. // if (status !== ENTERING && status !== ENTERED) {
  1127. // nextStatus = ENTERING
  1128. // }
  1129. // } else {
  1130. // if (status === ENTERING || status === ENTERED) {
  1131. // nextStatus = EXITING
  1132. // }
  1133. // }
  1134. // }
  1135. // return { nextStatus }
  1136. // }
  1137. ;
  1138. var _proto = Transition.prototype;
  1139. _proto.componentDidMount = function componentDidMount() {
  1140. this.updateStatus(true, this.appearStatus);
  1141. };
  1142. _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
  1143. var nextStatus = null;
  1144. if (prevProps !== this.props) {
  1145. var status = this.state.status;
  1146. if (this.props.in) {
  1147. if (status !== ENTERING && status !== ENTERED) {
  1148. nextStatus = ENTERING;
  1149. }
  1150. } else {
  1151. if (status === ENTERING || status === ENTERED) {
  1152. nextStatus = EXITING;
  1153. }
  1154. }
  1155. }
  1156. this.updateStatus(false, nextStatus);
  1157. };
  1158. _proto.componentWillUnmount = function componentWillUnmount() {
  1159. this.cancelNextCallback();
  1160. };
  1161. _proto.getTimeouts = function getTimeouts() {
  1162. var timeout = this.props.timeout;
  1163. var exit, enter, appear;
  1164. exit = enter = appear = timeout;
  1165. if (timeout != null && typeof timeout !== 'number') {
  1166. exit = timeout.exit;
  1167. enter = timeout.enter; // TODO: remove fallback for next major
  1168. appear = timeout.appear !== undefined ? timeout.appear : enter;
  1169. }
  1170. return {
  1171. exit: exit,
  1172. enter: enter,
  1173. appear: appear
  1174. };
  1175. };
  1176. _proto.updateStatus = function updateStatus(mounting, nextStatus) {
  1177. if (mounting === void 0) {
  1178. mounting = false;
  1179. }
  1180. if (nextStatus !== null) {
  1181. // nextStatus will always be ENTERING or EXITING.
  1182. this.cancelNextCallback();
  1183. if (nextStatus === ENTERING) {
  1184. if (this.props.unmountOnExit || this.props.mountOnEnter) {
  1185. var node = this.props.nodeRef ? this.props.nodeRef.current : ReactDOM.findDOMNode(this); // https://github.com/reactjs/react-transition-group/pull/749
  1186. // With unmountOnExit or mountOnEnter, the enter animation should happen at the transition between `exited` and `entering`.
  1187. // To make the animation happen, we have to separate each rendering and avoid being processed as batched.
  1188. if (node) forceReflow(node);
  1189. }
  1190. this.performEnter(mounting);
  1191. } else {
  1192. this.performExit();
  1193. }
  1194. } else if (this.props.unmountOnExit && this.state.status === EXITED) {
  1195. this.setState({
  1196. status: UNMOUNTED
  1197. });
  1198. }
  1199. };
  1200. _proto.performEnter = function performEnter(mounting) {
  1201. var _this2 = this;
  1202. var enter = this.props.enter;
  1203. var appearing = this.context ? this.context.isMounting : mounting;
  1204. var _ref2 = this.props.nodeRef ? [appearing] : [ReactDOM.findDOMNode(this), appearing],
  1205. maybeNode = _ref2[0],
  1206. maybeAppearing = _ref2[1];
  1207. var timeouts = this.getTimeouts();
  1208. var enterTimeout = appearing ? timeouts.appear : timeouts.enter; // no enter animation skip right to ENTERED
  1209. // if we are mounting and running this it means appear _must_ be set
  1210. if (!mounting && !enter || config.disabled) {
  1211. this.safeSetState({
  1212. status: ENTERED
  1213. }, function () {
  1214. _this2.props.onEntered(maybeNode);
  1215. });
  1216. return;
  1217. }
  1218. this.props.onEnter(maybeNode, maybeAppearing);
  1219. this.safeSetState({
  1220. status: ENTERING
  1221. }, function () {
  1222. _this2.props.onEntering(maybeNode, maybeAppearing);
  1223. _this2.onTransitionEnd(enterTimeout, function () {
  1224. _this2.safeSetState({
  1225. status: ENTERED
  1226. }, function () {
  1227. _this2.props.onEntered(maybeNode, maybeAppearing);
  1228. });
  1229. });
  1230. });
  1231. };
  1232. _proto.performExit = function performExit() {
  1233. var _this3 = this;
  1234. var exit = this.props.exit;
  1235. var timeouts = this.getTimeouts();
  1236. var maybeNode = this.props.nodeRef ? undefined : ReactDOM.findDOMNode(this); // no exit animation skip right to EXITED
  1237. if (!exit || config.disabled) {
  1238. this.safeSetState({
  1239. status: EXITED
  1240. }, function () {
  1241. _this3.props.onExited(maybeNode);
  1242. });
  1243. return;
  1244. }
  1245. this.props.onExit(maybeNode);
  1246. this.safeSetState({
  1247. status: EXITING
  1248. }, function () {
  1249. _this3.props.onExiting(maybeNode);
  1250. _this3.onTransitionEnd(timeouts.exit, function () {
  1251. _this3.safeSetState({
  1252. status: EXITED
  1253. }, function () {
  1254. _this3.props.onExited(maybeNode);
  1255. });
  1256. });
  1257. });
  1258. };
  1259. _proto.cancelNextCallback = function cancelNextCallback() {
  1260. if (this.nextCallback !== null) {
  1261. this.nextCallback.cancel();
  1262. this.nextCallback = null;
  1263. }
  1264. };
  1265. _proto.safeSetState = function safeSetState(nextState, callback) {
  1266. // This shouldn't be necessary, but there are weird race conditions with
  1267. // setState callbacks and unmounting in testing, so always make sure that
  1268. // we can cancel any pending setState callbacks after we unmount.
  1269. callback = this.setNextCallback(callback);
  1270. this.setState(nextState, callback);
  1271. };
  1272. _proto.setNextCallback = function setNextCallback(callback) {
  1273. var _this4 = this;
  1274. var active = true;
  1275. this.nextCallback = function (event) {
  1276. if (active) {
  1277. active = false;
  1278. _this4.nextCallback = null;
  1279. callback(event);
  1280. }
  1281. };
  1282. this.nextCallback.cancel = function () {
  1283. active = false;
  1284. };
  1285. return this.nextCallback;
  1286. };
  1287. _proto.onTransitionEnd = function onTransitionEnd(timeout, handler) {
  1288. this.setNextCallback(handler);
  1289. var node = this.props.nodeRef ? this.props.nodeRef.current : ReactDOM.findDOMNode(this);
  1290. var doesNotHaveTimeoutOrListener = timeout == null && !this.props.addEndListener;
  1291. if (!node || doesNotHaveTimeoutOrListener) {
  1292. setTimeout(this.nextCallback, 0);
  1293. return;
  1294. }
  1295. if (this.props.addEndListener) {
  1296. var _ref3 = this.props.nodeRef ? [this.nextCallback] : [node, this.nextCallback],
  1297. maybeNode = _ref3[0],
  1298. maybeNextCallback = _ref3[1];
  1299. this.props.addEndListener(maybeNode, maybeNextCallback);
  1300. }
  1301. if (timeout != null) {
  1302. setTimeout(this.nextCallback, timeout);
  1303. }
  1304. };
  1305. _proto.render = function render() {
  1306. var status = this.state.status;
  1307. if (status === UNMOUNTED) {
  1308. return null;
  1309. }
  1310. var _this$props = this.props,
  1311. children = _this$props.children,
  1312. _in = _this$props.in,
  1313. _mountOnEnter = _this$props.mountOnEnter,
  1314. _unmountOnExit = _this$props.unmountOnExit,
  1315. _appear = _this$props.appear,
  1316. _enter = _this$props.enter,
  1317. _exit = _this$props.exit,
  1318. _timeout = _this$props.timeout,
  1319. _addEndListener = _this$props.addEndListener,
  1320. _onEnter = _this$props.onEnter,
  1321. _onEntering = _this$props.onEntering,
  1322. _onEntered = _this$props.onEntered,
  1323. _onExit = _this$props.onExit,
  1324. _onExiting = _this$props.onExiting,
  1325. _onExited = _this$props.onExited,
  1326. _nodeRef = _this$props.nodeRef,
  1327. childProps = _objectWithoutPropertiesLoose(_this$props, ["children", "in", "mountOnEnter", "unmountOnExit", "appear", "enter", "exit", "timeout", "addEndListener", "onEnter", "onEntering", "onEntered", "onExit", "onExiting", "onExited", "nodeRef"]);
  1328. return (
  1329. /*#__PURE__*/
  1330. // allows for nested Transitions
  1331. React__default.createElement(TransitionGroupContext.Provider, {
  1332. value: null
  1333. }, typeof children === 'function' ? children(status, childProps) : React__default.cloneElement(React__default.Children.only(children), childProps))
  1334. );
  1335. };
  1336. return Transition;
  1337. }(React__default.Component);
  1338. Transition.contextType = TransitionGroupContext;
  1339. Transition.propTypes = {
  1340. /**
  1341. * A React reference to DOM element that need to transition:
  1342. * https://stackoverflow.com/a/51127130/4671932
  1343. *
  1344. * - When `nodeRef` prop is used, `node` is not passed to callback functions
  1345. * (e.g. `onEnter`) because user already has direct access to the node.
  1346. * - When changing `key` prop of `Transition` in a `TransitionGroup` a new
  1347. * `nodeRef` need to be provided to `Transition` with changed `key` prop
  1348. * (see
  1349. * [test/CSSTransition-test.js](https://github.com/reactjs/react-transition-group/blob/13435f897b3ab71f6e19d724f145596f5910581c/test/CSSTransition-test.js#L362-L437)).
  1350. */
  1351. nodeRef: propTypes.shape({
  1352. current: typeof Element === 'undefined' ? propTypes.any : function (propValue, key, componentName, location, propFullName, secret) {
  1353. var value = propValue[key];
  1354. return propTypes.instanceOf(value && 'ownerDocument' in value ? value.ownerDocument.defaultView.Element : Element)(propValue, key, componentName, location, propFullName, secret);
  1355. }
  1356. }),
  1357. /**
  1358. * A `function` child can be used instead of a React element. This function is
  1359. * called with the current transition status (`'entering'`, `'entered'`,
  1360. * `'exiting'`, `'exited'`), which can be used to apply context
  1361. * specific props to a component.
  1362. *
  1363. * ```jsx
  1364. * <Transition in={this.state.in} timeout={150}>
  1365. * {state => (
  1366. * <MyComponent className={`fade fade-${state}`} />
  1367. * )}
  1368. * </Transition>
  1369. * ```
  1370. */
  1371. children: propTypes.oneOfType([propTypes.func.isRequired, propTypes.element.isRequired]).isRequired,
  1372. /**
  1373. * Show the component; triggers the enter or exit states
  1374. */
  1375. in: propTypes.bool,
  1376. /**
  1377. * By default the child component is mounted immediately along with
  1378. * the parent `Transition` component. If you want to "lazy mount" the component on the
  1379. * first `in={true}` you can set `mountOnEnter`. After the first enter transition the component will stay
  1380. * mounted, even on "exited", unless you also specify `unmountOnExit`.
  1381. */
  1382. mountOnEnter: propTypes.bool,
  1383. /**
  1384. * By default the child component stays mounted after it reaches the `'exited'` state.
  1385. * Set `unmountOnExit` if you'd prefer to unmount the component after it finishes exiting.
  1386. */
  1387. unmountOnExit: propTypes.bool,
  1388. /**
  1389. * By default the child component does not perform the enter transition when
  1390. * it first mounts, regardless of the value of `in`. If you want this
  1391. * behavior, set both `appear` and `in` to `true`.
  1392. *
  1393. * > **Note**: there are no special appear states like `appearing`/`appeared`, this prop
  1394. * > only adds an additional enter transition. However, in the
  1395. * > `<CSSTransition>` component that first enter transition does result in
  1396. * > additional `.appear-*` classes, that way you can choose to style it
  1397. * > differently.
  1398. */
  1399. appear: propTypes.bool,
  1400. /**
  1401. * Enable or disable enter transitions.
  1402. */
  1403. enter: propTypes.bool,
  1404. /**
  1405. * Enable or disable exit transitions.
  1406. */
  1407. exit: propTypes.bool,
  1408. /**
  1409. * The duration of the transition, in milliseconds.
  1410. * Required unless `addEndListener` is provided.
  1411. *
  1412. * You may specify a single timeout for all transitions:
  1413. *
  1414. * ```jsx
  1415. * timeout={500}
  1416. * ```
  1417. *
  1418. * or individually:
  1419. *
  1420. * ```jsx
  1421. * timeout={{
  1422. * appear: 500,
  1423. * enter: 300,
  1424. * exit: 500,
  1425. * }}
  1426. * ```
  1427. *
  1428. * - `appear` defaults to the value of `enter`
  1429. * - `enter` defaults to `0`
  1430. * - `exit` defaults to `0`
  1431. *
  1432. * @type {number | { enter?: number, exit?: number, appear?: number }}
  1433. */
  1434. timeout: function timeout(props) {
  1435. var pt = timeoutsShape;
  1436. if (!props.addEndListener) pt = pt.isRequired;
  1437. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1438. args[_key - 1] = arguments[_key];
  1439. }
  1440. return pt.apply(void 0, [props].concat(args));
  1441. },
  1442. /**
  1443. * Add a custom transition end trigger. Called with the transitioning
  1444. * DOM node and a `done` callback. Allows for more fine grained transition end
  1445. * logic. Timeouts are still used as a fallback if provided.
  1446. *
  1447. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1448. *
  1449. * ```jsx
  1450. * addEndListener={(node, done) => {
  1451. * // use the css transitionend event to mark the finish of a transition
  1452. * node.addEventListener('transitionend', done, false);
  1453. * }}
  1454. * ```
  1455. */
  1456. addEndListener: propTypes.func,
  1457. /**
  1458. * Callback fired before the "entering" status is applied. An extra parameter
  1459. * `isAppearing` is supplied to indicate if the enter stage is occurring on the initial mount
  1460. *
  1461. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1462. *
  1463. * @type Function(node: HtmlElement, isAppearing: bool) -> void
  1464. */
  1465. onEnter: propTypes.func,
  1466. /**
  1467. * Callback fired after the "entering" status is applied. An extra parameter
  1468. * `isAppearing` is supplied to indicate if the enter stage is occurring on the initial mount
  1469. *
  1470. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1471. *
  1472. * @type Function(node: HtmlElement, isAppearing: bool)
  1473. */
  1474. onEntering: propTypes.func,
  1475. /**
  1476. * Callback fired after the "entered" status is applied. An extra parameter
  1477. * `isAppearing` is supplied to indicate if the enter stage is occurring on the initial mount
  1478. *
  1479. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1480. *
  1481. * @type Function(node: HtmlElement, isAppearing: bool) -> void
  1482. */
  1483. onEntered: propTypes.func,
  1484. /**
  1485. * Callback fired before the "exiting" status is applied.
  1486. *
  1487. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1488. *
  1489. * @type Function(node: HtmlElement) -> void
  1490. */
  1491. onExit: propTypes.func,
  1492. /**
  1493. * Callback fired after the "exiting" status is applied.
  1494. *
  1495. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1496. *
  1497. * @type Function(node: HtmlElement) -> void
  1498. */
  1499. onExiting: propTypes.func,
  1500. /**
  1501. * Callback fired after the "exited" status is applied.
  1502. *
  1503. * **Note**: when `nodeRef` prop is passed, `node` is not passed
  1504. *
  1505. * @type Function(node: HtmlElement) -> void
  1506. */
  1507. onExited: propTypes.func
  1508. } ; // Name the function so it is clearer in the documentation
  1509. function noop() {}
  1510. Transition.defaultProps = {
  1511. in: false,
  1512. mountOnEnter: false,
  1513. unmountOnExit: false,
  1514. appear: false,
  1515. enter: true,
  1516. exit: true,
  1517. onEnter: noop,
  1518. onEntering: noop,
  1519. onEntered: noop,
  1520. onExit: noop,
  1521. onExiting: noop,
  1522. onExited: noop
  1523. };
  1524. Transition.UNMOUNTED = UNMOUNTED;
  1525. Transition.EXITED = EXITED;
  1526. Transition.ENTERING = ENTERING;
  1527. Transition.ENTERED = ENTERED;
  1528. Transition.EXITING = EXITING;
  1529. var _addClass = function addClass$1(node, classes) {
  1530. return node && classes && classes.split(' ').forEach(function (c) {
  1531. return addClass(node, c);
  1532. });
  1533. };
  1534. var removeClass$1 = function removeClass$1(node, classes) {
  1535. return node && classes && classes.split(' ').forEach(function (c) {
  1536. return removeClass(node, c);
  1537. });
  1538. };
  1539. /**
  1540. * A transition component inspired by the excellent
  1541. * [ng-animate](https://docs.angularjs.org/api/ngAnimate) library, you should
  1542. * use it if you're using CSS transitions or animations. It's built upon the
  1543. * [`Transition`](https://reactcommunity.org/react-transition-group/transition)
  1544. * component, so it inherits all of its props.
  1545. *
  1546. * `CSSTransition` applies a pair of class names during the `appear`, `enter`,
  1547. * and `exit` states of the transition. The first class is applied and then a
  1548. * second `*-active` class in order to activate the CSS transition. After the
  1549. * transition, matching `*-done` class names are applied to persist the
  1550. * transition state.
  1551. *
  1552. * ```jsx
  1553. * function App() {
  1554. * const [inProp, setInProp] = useState(false);
  1555. * return (
  1556. * <div>
  1557. * <CSSTransition in={inProp} timeout={200} classNames="my-node">
  1558. * <div>
  1559. * {"I'll receive my-node-* classes"}
  1560. * </div>
  1561. * </CSSTransition>
  1562. * <button type="button" onClick={() => setInProp(true)}>
  1563. * Click to Enter
  1564. * </button>
  1565. * </div>
  1566. * );
  1567. * }
  1568. * ```
  1569. *
  1570. * When the `in` prop is set to `true`, the child component will first receive
  1571. * the class `example-enter`, then the `example-enter-active` will be added in
  1572. * the next tick. `CSSTransition` [forces a
  1573. * reflow](https://github.com/reactjs/react-transition-group/blob/5007303e729a74be66a21c3e2205e4916821524b/src/CSSTransition.js#L208-L215)
  1574. * between before adding the `example-enter-active`. This is an important trick
  1575. * because it allows us to transition between `example-enter` and
  1576. * `example-enter-active` even though they were added immediately one after
  1577. * another. Most notably, this is what makes it possible for us to animate
  1578. * _appearance_.
  1579. *
  1580. * ```css
  1581. * .my-node-enter {
  1582. * opacity: 0;
  1583. * }
  1584. * .my-node-enter-active {
  1585. * opacity: 1;
  1586. * transition: opacity 200ms;
  1587. * }
  1588. * .my-node-exit {
  1589. * opacity: 1;
  1590. * }
  1591. * .my-node-exit-active {
  1592. * opacity: 0;
  1593. * transition: opacity 200ms;
  1594. * }
  1595. * ```
  1596. *
  1597. * `*-active` classes represent which styles you want to animate **to**, so it's
  1598. * important to add `transition` declaration only to them, otherwise transitions
  1599. * might not behave as intended! This might not be obvious when the transitions
  1600. * are symmetrical, i.e. when `*-enter-active` is the same as `*-exit`, like in
  1601. * the example above (minus `transition`), but it becomes apparent in more
  1602. * complex transitions.
  1603. *
  1604. * **Note**: If you're using the
  1605. * [`appear`](http://reactcommunity.org/react-transition-group/transition#Transition-prop-appear)
  1606. * prop, make sure to define styles for `.appear-*` classes as well.
  1607. */
  1608. var CSSTransition = /*#__PURE__*/function (_React$Component) {
  1609. _inheritsLoose(CSSTransition, _React$Component);
  1610. function CSSTransition() {
  1611. var _this;
  1612. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1613. args[_key] = arguments[_key];
  1614. }
  1615. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  1616. _this.appliedClasses = {
  1617. appear: {},
  1618. enter: {},
  1619. exit: {}
  1620. };
  1621. _this.onEnter = function (maybeNode, maybeAppearing) {
  1622. var _this$resolveArgument = _this.resolveArguments(maybeNode, maybeAppearing),
  1623. node = _this$resolveArgument[0],
  1624. appearing = _this$resolveArgument[1];
  1625. _this.removeClasses(node, 'exit');
  1626. _this.addClass(node, appearing ? 'appear' : 'enter', 'base');
  1627. if (_this.props.onEnter) {
  1628. _this.props.onEnter(maybeNode, maybeAppearing);
  1629. }
  1630. };
  1631. _this.onEntering = function (maybeNode, maybeAppearing) {
  1632. var _this$resolveArgument2 = _this.resolveArguments(maybeNode, maybeAppearing),
  1633. node = _this$resolveArgument2[0],
  1634. appearing = _this$resolveArgument2[1];
  1635. var type = appearing ? 'appear' : 'enter';
  1636. _this.addClass(node, type, 'active');
  1637. if (_this.props.onEntering) {
  1638. _this.props.onEntering(maybeNode, maybeAppearing);
  1639. }
  1640. };
  1641. _this.onEntered = function (maybeNode, maybeAppearing) {
  1642. var _this$resolveArgument3 = _this.resolveArguments(maybeNode, maybeAppearing),
  1643. node = _this$resolveArgument3[0],
  1644. appearing = _this$resolveArgument3[1];
  1645. var type = appearing ? 'appear' : 'enter';
  1646. _this.removeClasses(node, type);
  1647. _this.addClass(node, type, 'done');
  1648. if (_this.props.onEntered) {
  1649. _this.props.onEntered(maybeNode, maybeAppearing);
  1650. }
  1651. };
  1652. _this.onExit = function (maybeNode) {
  1653. var _this$resolveArgument4 = _this.resolveArguments(maybeNode),
  1654. node = _this$resolveArgument4[0];
  1655. _this.removeClasses(node, 'appear');
  1656. _this.removeClasses(node, 'enter');
  1657. _this.addClass(node, 'exit', 'base');
  1658. if (_this.props.onExit) {
  1659. _this.props.onExit(maybeNode);
  1660. }
  1661. };
  1662. _this.onExiting = function (maybeNode) {
  1663. var _this$resolveArgument5 = _this.resolveArguments(maybeNode),
  1664. node = _this$resolveArgument5[0];
  1665. _this.addClass(node, 'exit', 'active');
  1666. if (_this.props.onExiting) {
  1667. _this.props.onExiting(maybeNode);
  1668. }
  1669. };
  1670. _this.onExited = function (maybeNode) {
  1671. var _this$resolveArgument6 = _this.resolveArguments(maybeNode),
  1672. node = _this$resolveArgument6[0];
  1673. _this.removeClasses(node, 'exit');
  1674. _this.addClass(node, 'exit', 'done');
  1675. if (_this.props.onExited) {
  1676. _this.props.onExited(maybeNode);
  1677. }
  1678. };
  1679. _this.resolveArguments = function (maybeNode, maybeAppearing) {
  1680. return _this.props.nodeRef ? [_this.props.nodeRef.current, maybeNode] // here `maybeNode` is actually `appearing`
  1681. : [maybeNode, maybeAppearing];
  1682. };
  1683. _this.getClassNames = function (type) {
  1684. var classNames = _this.props.classNames;
  1685. var isStringClassNames = typeof classNames === 'string';
  1686. var prefix = isStringClassNames && classNames ? classNames + "-" : '';
  1687. var baseClassName = isStringClassNames ? "" + prefix + type : classNames[type];
  1688. var activeClassName = isStringClassNames ? baseClassName + "-active" : classNames[type + "Active"];
  1689. var doneClassName = isStringClassNames ? baseClassName + "-done" : classNames[type + "Done"];
  1690. return {
  1691. baseClassName: baseClassName,
  1692. activeClassName: activeClassName,
  1693. doneClassName: doneClassName
  1694. };
  1695. };
  1696. return _this;
  1697. }
  1698. var _proto = CSSTransition.prototype;
  1699. _proto.addClass = function addClass(node, type, phase) {
  1700. var className = this.getClassNames(type)[phase + "ClassName"];
  1701. var _this$getClassNames = this.getClassNames('enter'),
  1702. doneClassName = _this$getClassNames.doneClassName;
  1703. if (type === 'appear' && phase === 'done' && doneClassName) {
  1704. className += " " + doneClassName;
  1705. } // This is to force a repaint,
  1706. // which is necessary in order to transition styles when adding a class name.
  1707. if (phase === 'active') {
  1708. if (node) forceReflow(node);
  1709. }
  1710. if (className) {
  1711. this.appliedClasses[type][phase] = className;
  1712. _addClass(node, className);
  1713. }
  1714. };
  1715. _proto.removeClasses = function removeClasses(node, type) {
  1716. var _this$appliedClasses$ = this.appliedClasses[type],
  1717. baseClassName = _this$appliedClasses$.base,
  1718. activeClassName = _this$appliedClasses$.active,
  1719. doneClassName = _this$appliedClasses$.done;
  1720. this.appliedClasses[type] = {};
  1721. if (baseClassName) {
  1722. removeClass$1(node, baseClassName);
  1723. }
  1724. if (activeClassName) {
  1725. removeClass$1(node, activeClassName);
  1726. }
  1727. if (doneClassName) {
  1728. removeClass$1(node, doneClassName);
  1729. }
  1730. };
  1731. _proto.render = function render() {
  1732. var _this$props = this.props,
  1733. _ = _this$props.classNames,
  1734. props = _objectWithoutPropertiesLoose(_this$props, ["classNames"]);
  1735. return /*#__PURE__*/React__default.createElement(Transition, _extends({}, props, {
  1736. onEnter: this.onEnter,
  1737. onEntered: this.onEntered,
  1738. onEntering: this.onEntering,
  1739. onExit: this.onExit,
  1740. onExiting: this.onExiting,
  1741. onExited: this.onExited
  1742. }));
  1743. };
  1744. return CSSTransition;
  1745. }(React__default.Component);
  1746. CSSTransition.defaultProps = {
  1747. classNames: ''
  1748. };
  1749. CSSTransition.propTypes = _extends({}, Transition.propTypes, {
  1750. /**
  1751. * The animation classNames applied to the component as it appears, enters,
  1752. * exits or has finished the transition. A single name can be provided, which
  1753. * will be suffixed for each stage, e.g. `classNames="fade"` applies:
  1754. *
  1755. * - `fade-appear`, `fade-appear-active`, `fade-appear-done`
  1756. * - `fade-enter`, `fade-enter-active`, `fade-enter-done`
  1757. * - `fade-exit`, `fade-exit-active`, `fade-exit-done`
  1758. *
  1759. * A few details to note about how these classes are applied:
  1760. *
  1761. * 1. They are _joined_ with the ones that are already defined on the child
  1762. * component, so if you want to add some base styles, you can use
  1763. * `className` without worrying that it will be overridden.
  1764. *
  1765. * 2. If the transition component mounts with `in={false}`, no classes are
  1766. * applied yet. You might be expecting `*-exit-done`, but if you think
  1767. * about it, a component cannot finish exiting if it hasn't entered yet.
  1768. *
  1769. * 2. `fade-appear-done` and `fade-enter-done` will _both_ be applied. This
  1770. * allows you to define different behavior for when appearing is done and
  1771. * when regular entering is done, using selectors like
  1772. * `.fade-enter-done:not(.fade-appear-done)`. For example, you could apply
  1773. * an epic entrance animation when element first appears in the DOM using
  1774. * [Animate.css](https://daneden.github.io/animate.css/). Otherwise you can
  1775. * simply use `fade-enter-done` for defining both cases.
  1776. *
  1777. * Each individual classNames can also be specified independently like:
  1778. *
  1779. * ```js
  1780. * classNames={{
  1781. * appear: 'my-appear',
  1782. * appearActive: 'my-active-appear',
  1783. * appearDone: 'my-done-appear',
  1784. * enter: 'my-enter',
  1785. * enterActive: 'my-active-enter',
  1786. * enterDone: 'my-done-enter',
  1787. * exit: 'my-exit',
  1788. * exitActive: 'my-active-exit',
  1789. * exitDone: 'my-done-exit',
  1790. * }}
  1791. * ```
  1792. *
  1793. * If you want to set these classes using CSS Modules:
  1794. *
  1795. * ```js
  1796. * import styles from './styles.css';
  1797. * ```
  1798. *
  1799. * you might want to use camelCase in your CSS file, that way could simply
  1800. * spread them instead of listing them one by one:
  1801. *
  1802. * ```js
  1803. * classNames={{ ...styles }}
  1804. * ```
  1805. *
  1806. * @type {string | {
  1807. * appear?: string,
  1808. * appearActive?: string,
  1809. * appearDone?: string,
  1810. * enter?: string,
  1811. * enterActive?: string,
  1812. * enterDone?: string,
  1813. * exit?: string,
  1814. * exitActive?: string,
  1815. * exitDone?: string,
  1816. * }}
  1817. */
  1818. classNames: classNamesShape,
  1819. /**
  1820. * A `<Transition>` callback fired immediately after the 'enter' or 'appear' class is
  1821. * applied.
  1822. *
  1823. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1824. *
  1825. * @type Function(node: HtmlElement, isAppearing: bool)
  1826. */
  1827. onEnter: propTypes.func,
  1828. /**
  1829. * A `<Transition>` callback fired immediately after the 'enter-active' or
  1830. * 'appear-active' class is applied.
  1831. *
  1832. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1833. *
  1834. * @type Function(node: HtmlElement, isAppearing: bool)
  1835. */
  1836. onEntering: propTypes.func,
  1837. /**
  1838. * A `<Transition>` callback fired immediately after the 'enter' or
  1839. * 'appear' classes are **removed** and the `done` class is added to the DOM node.
  1840. *
  1841. * **Note**: when `nodeRef` prop is passed, `node` is not passed.
  1842. *
  1843. * @type Function(node: HtmlElement, isAppearing: bool)
  1844. */
  1845. onEntered: propTypes.func,
  1846. /**
  1847. * A `<Transition>` callback fired immediately after the 'exit' class is
  1848. * applied.
  1849. *
  1850. * **Note**: when `nodeRef` prop is passed, `node` is not passed
  1851. *
  1852. * @type Function(node: HtmlElement)
  1853. */
  1854. onExit: propTypes.func,
  1855. /**
  1856. * A `<Transition>` callback fired immediately after the 'exit-active' is applied.
  1857. *
  1858. * **Note**: when `nodeRef` prop is passed, `node` is not passed
  1859. *
  1860. * @type Function(node: HtmlElement)
  1861. */
  1862. onExiting: propTypes.func,
  1863. /**
  1864. * A `<Transition>` callback fired immediately after the 'exit' classes
  1865. * are **removed** and the `exit-done` class is added to the DOM node.
  1866. *
  1867. * **Note**: when `nodeRef` prop is passed, `node` is not passed
  1868. *
  1869. * @type Function(node: HtmlElement)
  1870. */
  1871. onExited: propTypes.func
  1872. }) ;
  1873. function _assertThisInitialized(self) {
  1874. if (self === void 0) {
  1875. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1876. }
  1877. return self;
  1878. }
  1879. /**
  1880. * Given `this.props.children`, return an object mapping key to child.
  1881. *
  1882. * @param {*} children `this.props.children`
  1883. * @return {object} Mapping of key to child
  1884. */
  1885. function getChildMapping(children, mapFn) {
  1886. var mapper = function mapper(child) {
  1887. return mapFn && React.isValidElement(child) ? mapFn(child) : child;
  1888. };
  1889. var result = Object.create(null);
  1890. if (children) React.Children.map(children, function (c) {
  1891. return c;
  1892. }).forEach(function (child) {
  1893. // run the map function here instead so that the key is the computed one
  1894. result[child.key] = mapper(child);
  1895. });
  1896. return result;
  1897. }
  1898. /**
  1899. * When you're adding or removing children some may be added or removed in the
  1900. * same render pass. We want to show *both* since we want to simultaneously
  1901. * animate elements in and out. This function takes a previous set of keys
  1902. * and a new set of keys and merges them with its best guess of the correct
  1903. * ordering. In the future we may expose some of the utilities in
  1904. * ReactMultiChild to make this easy, but for now React itself does not
  1905. * directly have this concept of the union of prevChildren and nextChildren
  1906. * so we implement it here.
  1907. *
  1908. * @param {object} prev prev children as returned from
  1909. * `ReactTransitionChildMapping.getChildMapping()`.
  1910. * @param {object} next next children as returned from
  1911. * `ReactTransitionChildMapping.getChildMapping()`.
  1912. * @return {object} a key set that contains all keys in `prev` and all keys
  1913. * in `next` in a reasonable order.
  1914. */
  1915. function mergeChildMappings(prev, next) {
  1916. prev = prev || {};
  1917. next = next || {};
  1918. function getValueForKey(key) {
  1919. return key in next ? next[key] : prev[key];
  1920. } // For each key of `next`, the list of keys to insert before that key in
  1921. // the combined list
  1922. var nextKeysPending = Object.create(null);
  1923. var pendingKeys = [];
  1924. for (var prevKey in prev) {
  1925. if (prevKey in next) {
  1926. if (pendingKeys.length) {
  1927. nextKeysPending[prevKey] = pendingKeys;
  1928. pendingKeys = [];
  1929. }
  1930. } else {
  1931. pendingKeys.push(prevKey);
  1932. }
  1933. }
  1934. var i;
  1935. var childMapping = {};
  1936. for (var nextKey in next) {
  1937. if (nextKeysPending[nextKey]) {
  1938. for (i = 0; i < nextKeysPending[nextKey].length; i++) {
  1939. var pendingNextKey = nextKeysPending[nextKey][i];
  1940. childMapping[nextKeysPending[nextKey][i]] = getValueForKey(pendingNextKey);
  1941. }
  1942. }
  1943. childMapping[nextKey] = getValueForKey(nextKey);
  1944. } // Finally, add the keys which didn't appear before any key in `next`
  1945. for (i = 0; i < pendingKeys.length; i++) {
  1946. childMapping[pendingKeys[i]] = getValueForKey(pendingKeys[i]);
  1947. }
  1948. return childMapping;
  1949. }
  1950. function getProp(child, prop, props) {
  1951. return props[prop] != null ? props[prop] : child.props[prop];
  1952. }
  1953. function getInitialChildMapping(props, onExited) {
  1954. return getChildMapping(props.children, function (child) {
  1955. return React.cloneElement(child, {
  1956. onExited: onExited.bind(null, child),
  1957. in: true,
  1958. appear: getProp(child, 'appear', props),
  1959. enter: getProp(child, 'enter', props),
  1960. exit: getProp(child, 'exit', props)
  1961. });
  1962. });
  1963. }
  1964. function getNextChildMapping(nextProps, prevChildMapping, onExited) {
  1965. var nextChildMapping = getChildMapping(nextProps.children);
  1966. var children = mergeChildMappings(prevChildMapping, nextChildMapping);
  1967. Object.keys(children).forEach(function (key) {
  1968. var child = children[key];
  1969. if (!React.isValidElement(child)) return;
  1970. var hasPrev = (key in prevChildMapping);
  1971. var hasNext = (key in nextChildMapping);
  1972. var prevChild = prevChildMapping[key];
  1973. var isLeaving = React.isValidElement(prevChild) && !prevChild.props.in; // item is new (entering)
  1974. if (hasNext && (!hasPrev || isLeaving)) {
  1975. // console.log('entering', key)
  1976. children[key] = React.cloneElement(child, {
  1977. onExited: onExited.bind(null, child),
  1978. in: true,
  1979. exit: getProp(child, 'exit', nextProps),
  1980. enter: getProp(child, 'enter', nextProps)
  1981. });
  1982. } else if (!hasNext && hasPrev && !isLeaving) {
  1983. // item is old (exiting)
  1984. // console.log('leaving', key)
  1985. children[key] = React.cloneElement(child, {
  1986. in: false
  1987. });
  1988. } else if (hasNext && hasPrev && React.isValidElement(prevChild)) {
  1989. // item hasn't changed transition states
  1990. // copy over the last transition props;
  1991. // console.log('unchanged', key)
  1992. children[key] = React.cloneElement(child, {
  1993. onExited: onExited.bind(null, child),
  1994. in: prevChild.props.in,
  1995. exit: getProp(child, 'exit', nextProps),
  1996. enter: getProp(child, 'enter', nextProps)
  1997. });
  1998. }
  1999. });
  2000. return children;
  2001. }
  2002. var values = Object.values || function (obj) {
  2003. return Object.keys(obj).map(function (k) {
  2004. return obj[k];
  2005. });
  2006. };
  2007. var defaultProps = {
  2008. component: 'div',
  2009. childFactory: function childFactory(child) {
  2010. return child;
  2011. }
  2012. };
  2013. /**
  2014. * The `<TransitionGroup>` component manages a set of transition components
  2015. * (`<Transition>` and `<CSSTransition>`) in a list. Like with the transition
  2016. * components, `<TransitionGroup>` is a state machine for managing the mounting
  2017. * and unmounting of components over time.
  2018. *
  2019. * Consider the example below. As items are removed or added to the TodoList the
  2020. * `in` prop is toggled automatically by the `<TransitionGroup>`.
  2021. *
  2022. * Note that `<TransitionGroup>` does not define any animation behavior!
  2023. * Exactly _how_ a list item animates is up to the individual transition
  2024. * component. This means you can mix and match animations across different list
  2025. * items.
  2026. */
  2027. var TransitionGroup = /*#__PURE__*/function (_React$Component) {
  2028. _inheritsLoose(TransitionGroup, _React$Component);
  2029. function TransitionGroup(props, context) {
  2030. var _this;
  2031. _this = _React$Component.call(this, props, context) || this;
  2032. var handleExited = _this.handleExited.bind(_assertThisInitialized(_this)); // Initial children should all be entering, dependent on appear
  2033. _this.state = {
  2034. contextValue: {
  2035. isMounting: true
  2036. },
  2037. handleExited: handleExited,
  2038. firstRender: true
  2039. };
  2040. return _this;
  2041. }
  2042. var _proto = TransitionGroup.prototype;
  2043. _proto.componentDidMount = function componentDidMount() {
  2044. this.mounted = true;
  2045. this.setState({
  2046. contextValue: {
  2047. isMounting: false
  2048. }
  2049. });
  2050. };
  2051. _proto.componentWillUnmount = function componentWillUnmount() {
  2052. this.mounted = false;
  2053. };
  2054. TransitionGroup.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, _ref) {
  2055. var prevChildMapping = _ref.children,
  2056. handleExited = _ref.handleExited,
  2057. firstRender = _ref.firstRender;
  2058. return {
  2059. children: firstRender ? getInitialChildMapping(nextProps, handleExited) : getNextChildMapping(nextProps, prevChildMapping, handleExited),
  2060. firstRender: false
  2061. };
  2062. } // node is `undefined` when user provided `nodeRef` prop
  2063. ;
  2064. _proto.handleExited = function handleExited(child, node) {
  2065. var currentChildMapping = getChildMapping(this.props.children);
  2066. if (child.key in currentChildMapping) return;
  2067. if (child.props.onExited) {
  2068. child.props.onExited(node);
  2069. }
  2070. if (this.mounted) {
  2071. this.setState(function (state) {
  2072. var children = _extends({}, state.children);
  2073. delete children[child.key];
  2074. return {
  2075. children: children
  2076. };
  2077. });
  2078. }
  2079. };
  2080. _proto.render = function render() {
  2081. var _this$props = this.props,
  2082. Component = _this$props.component,
  2083. childFactory = _this$props.childFactory,
  2084. props = _objectWithoutPropertiesLoose(_this$props, ["component", "childFactory"]);
  2085. var contextValue = this.state.contextValue;
  2086. var children = values(this.state.children).map(childFactory);
  2087. delete props.appear;
  2088. delete props.enter;
  2089. delete props.exit;
  2090. if (Component === null) {
  2091. return /*#__PURE__*/React__default.createElement(TransitionGroupContext.Provider, {
  2092. value: contextValue
  2093. }, children);
  2094. }
  2095. return /*#__PURE__*/React__default.createElement(TransitionGroupContext.Provider, {
  2096. value: contextValue
  2097. }, /*#__PURE__*/React__default.createElement(Component, props, children));
  2098. };
  2099. return TransitionGroup;
  2100. }(React__default.Component);
  2101. TransitionGroup.propTypes = {
  2102. /**
  2103. * `<TransitionGroup>` renders a `<div>` by default. You can change this
  2104. * behavior by providing a `component` prop.
  2105. * If you use React v16+ and would like to avoid a wrapping `<div>` element
  2106. * you can pass in `component={null}`. This is useful if the wrapping div
  2107. * borks your css styles.
  2108. */
  2109. component: propTypes.any,
  2110. /**
  2111. * A set of `<Transition>` components, that are toggled `in` and out as they
  2112. * leave. the `<TransitionGroup>` will inject specific transition props, so
  2113. * remember to spread them through if you are wrapping the `<Transition>` as
  2114. * with our `<Fade>` example.
  2115. *
  2116. * While this component is meant for multiple `Transition` or `CSSTransition`
  2117. * children, sometimes you may want to have a single transition child with
  2118. * content that you want to be transitioned out and in when you change it
  2119. * (e.g. routes, images etc.) In that case you can change the `key` prop of
  2120. * the transition child as you change its content, this will cause
  2121. * `TransitionGroup` to transition the child out and back in.
  2122. */
  2123. children: propTypes.node,
  2124. /**
  2125. * A convenience prop that enables or disables appear animations
  2126. * for all children. Note that specifying this will override any defaults set
  2127. * on individual children Transitions.
  2128. */
  2129. appear: propTypes.bool,
  2130. /**
  2131. * A convenience prop that enables or disables enter animations
  2132. * for all children. Note that specifying this will override any defaults set
  2133. * on individual children Transitions.
  2134. */
  2135. enter: propTypes.bool,
  2136. /**
  2137. * A convenience prop that enables or disables exit animations
  2138. * for all children. Note that specifying this will override any defaults set
  2139. * on individual children Transitions.
  2140. */
  2141. exit: propTypes.bool,
  2142. /**
  2143. * You may need to apply reactive updates to a child as it is exiting.
  2144. * This is generally done by using `cloneElement` however in the case of an exiting
  2145. * child the element has already been removed and not accessible to the consumer.
  2146. *
  2147. * If you do need to update a child as it leaves you can provide a `childFactory`
  2148. * to wrap every child, even the ones that are leaving.
  2149. *
  2150. * @type Function(child: ReactElement) -> ReactElement
  2151. */
  2152. childFactory: propTypes.func
  2153. } ;
  2154. TransitionGroup.defaultProps = defaultProps;
  2155. /**
  2156. * The `<ReplaceTransition>` component is a specialized `Transition` component
  2157. * that animates between two children.
  2158. *
  2159. * ```jsx
  2160. * <ReplaceTransition in>
  2161. * <Fade><div>I appear first</div></Fade>
  2162. * <Fade><div>I replace the above</div></Fade>
  2163. * </ReplaceTransition>
  2164. * ```
  2165. */
  2166. var ReplaceTransition = /*#__PURE__*/function (_React$Component) {
  2167. _inheritsLoose(ReplaceTransition, _React$Component);
  2168. function ReplaceTransition() {
  2169. var _this;
  2170. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  2171. _args[_key] = arguments[_key];
  2172. }
  2173. _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
  2174. _this.handleEnter = function () {
  2175. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  2176. args[_key2] = arguments[_key2];
  2177. }
  2178. return _this.handleLifecycle('onEnter', 0, args);
  2179. };
  2180. _this.handleEntering = function () {
  2181. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  2182. args[_key3] = arguments[_key3];
  2183. }
  2184. return _this.handleLifecycle('onEntering', 0, args);
  2185. };
  2186. _this.handleEntered = function () {
  2187. for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  2188. args[_key4] = arguments[_key4];
  2189. }
  2190. return _this.handleLifecycle('onEntered', 0, args);
  2191. };
  2192. _this.handleExit = function () {
  2193. for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  2194. args[_key5] = arguments[_key5];
  2195. }
  2196. return _this.handleLifecycle('onExit', 1, args);
  2197. };
  2198. _this.handleExiting = function () {
  2199. for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  2200. args[_key6] = arguments[_key6];
  2201. }
  2202. return _this.handleLifecycle('onExiting', 1, args);
  2203. };
  2204. _this.handleExited = function () {
  2205. for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
  2206. args[_key7] = arguments[_key7];
  2207. }
  2208. return _this.handleLifecycle('onExited', 1, args);
  2209. };
  2210. return _this;
  2211. }
  2212. var _proto = ReplaceTransition.prototype;
  2213. _proto.handleLifecycle = function handleLifecycle(handler, idx, originalArgs) {
  2214. var _child$props;
  2215. var children = this.props.children;
  2216. var child = React__default.Children.toArray(children)[idx];
  2217. if (child.props[handler]) (_child$props = child.props)[handler].apply(_child$props, originalArgs);
  2218. if (this.props[handler]) {
  2219. var maybeNode = child.props.nodeRef ? undefined : ReactDOM.findDOMNode(this);
  2220. this.props[handler](maybeNode);
  2221. }
  2222. };
  2223. _proto.render = function render() {
  2224. var _this$props = this.props,
  2225. children = _this$props.children,
  2226. inProp = _this$props.in,
  2227. props = _objectWithoutPropertiesLoose(_this$props, ["children", "in"]);
  2228. var _React$Children$toArr = React__default.Children.toArray(children),
  2229. first = _React$Children$toArr[0],
  2230. second = _React$Children$toArr[1];
  2231. delete props.onEnter;
  2232. delete props.onEntering;
  2233. delete props.onEntered;
  2234. delete props.onExit;
  2235. delete props.onExiting;
  2236. delete props.onExited;
  2237. return /*#__PURE__*/React__default.createElement(TransitionGroup, props, inProp ? React__default.cloneElement(first, {
  2238. key: 'first',
  2239. onEnter: this.handleEnter,
  2240. onEntering: this.handleEntering,
  2241. onEntered: this.handleEntered
  2242. }) : React__default.cloneElement(second, {
  2243. key: 'second',
  2244. onEnter: this.handleExit,
  2245. onEntering: this.handleExiting,
  2246. onEntered: this.handleExited
  2247. }));
  2248. };
  2249. return ReplaceTransition;
  2250. }(React__default.Component);
  2251. ReplaceTransition.propTypes = {
  2252. in: propTypes.bool.isRequired,
  2253. children: function children(props, propName) {
  2254. if (React__default.Children.count(props[propName]) !== 2) return new Error("\"" + propName + "\" must be exactly two transition components.");
  2255. return null;
  2256. }
  2257. } ;
  2258. var _leaveRenders, _enterRenders;
  2259. function areChildrenDifferent(oldChildren, newChildren) {
  2260. if (oldChildren === newChildren) return false;
  2261. if (React__default.isValidElement(oldChildren) && React__default.isValidElement(newChildren) && oldChildren.key != null && oldChildren.key === newChildren.key) {
  2262. return false;
  2263. }
  2264. return true;
  2265. }
  2266. /**
  2267. * Enum of modes for SwitchTransition component
  2268. * @enum { string }
  2269. */
  2270. var modes = {
  2271. out: 'out-in',
  2272. in: 'in-out'
  2273. };
  2274. var callHook = function callHook(element, name, cb) {
  2275. return function () {
  2276. var _element$props;
  2277. element.props[name] && (_element$props = element.props)[name].apply(_element$props, arguments);
  2278. cb();
  2279. };
  2280. };
  2281. var leaveRenders = (_leaveRenders = {}, _leaveRenders[modes.out] = function (_ref) {
  2282. var current = _ref.current,
  2283. changeState = _ref.changeState;
  2284. return React__default.cloneElement(current, {
  2285. in: false,
  2286. onExited: callHook(current, 'onExited', function () {
  2287. changeState(ENTERING, null);
  2288. })
  2289. });
  2290. }, _leaveRenders[modes.in] = function (_ref2) {
  2291. var current = _ref2.current,
  2292. changeState = _ref2.changeState,
  2293. children = _ref2.children;
  2294. return [current, React__default.cloneElement(children, {
  2295. in: true,
  2296. onEntered: callHook(children, 'onEntered', function () {
  2297. changeState(ENTERING);
  2298. })
  2299. })];
  2300. }, _leaveRenders);
  2301. var enterRenders = (_enterRenders = {}, _enterRenders[modes.out] = function (_ref3) {
  2302. var children = _ref3.children,
  2303. changeState = _ref3.changeState;
  2304. return React__default.cloneElement(children, {
  2305. in: true,
  2306. onEntered: callHook(children, 'onEntered', function () {
  2307. changeState(ENTERED, React__default.cloneElement(children, {
  2308. in: true
  2309. }));
  2310. })
  2311. });
  2312. }, _enterRenders[modes.in] = function (_ref4) {
  2313. var current = _ref4.current,
  2314. children = _ref4.children,
  2315. changeState = _ref4.changeState;
  2316. return [React__default.cloneElement(current, {
  2317. in: false,
  2318. onExited: callHook(current, 'onExited', function () {
  2319. changeState(ENTERED, React__default.cloneElement(children, {
  2320. in: true
  2321. }));
  2322. })
  2323. }), React__default.cloneElement(children, {
  2324. in: true
  2325. })];
  2326. }, _enterRenders);
  2327. /**
  2328. * A transition component inspired by the [vue transition modes](https://vuejs.org/v2/guide/transitions.html#Transition-Modes).
  2329. * You can use it when you want to control the render between state transitions.
  2330. * Based on the selected mode and the child's key which is the `Transition` or `CSSTransition` component, the `SwitchTransition` makes a consistent transition between them.
  2331. *
  2332. * If the `out-in` mode is selected, the `SwitchTransition` waits until the old child leaves and then inserts a new child.
  2333. * If the `in-out` mode is selected, the `SwitchTransition` inserts a new child first, waits for the new child to enter and then removes the old child.
  2334. *
  2335. * **Note**: If you want the animation to happen simultaneously
  2336. * (that is, to have the old child removed and a new child inserted **at the same time**),
  2337. * you should use
  2338. * [`TransitionGroup`](https://reactcommunity.org/react-transition-group/transition-group)
  2339. * instead.
  2340. *
  2341. * ```jsx
  2342. * function App() {
  2343. * const [state, setState] = useState(false);
  2344. * return (
  2345. * <SwitchTransition>
  2346. * <CSSTransition
  2347. * key={state ? "Goodbye, world!" : "Hello, world!"}
  2348. * addEndListener={(node, done) => node.addEventListener("transitionend", done, false)}
  2349. * classNames='fade'
  2350. * >
  2351. * <button onClick={() => setState(state => !state)}>
  2352. * {state ? "Goodbye, world!" : "Hello, world!"}
  2353. * </button>
  2354. * </CSSTransition>
  2355. * </SwitchTransition>
  2356. * );
  2357. * }
  2358. * ```
  2359. *
  2360. * ```css
  2361. * .fade-enter{
  2362. * opacity: 0;
  2363. * }
  2364. * .fade-exit{
  2365. * opacity: 1;
  2366. * }
  2367. * .fade-enter-active{
  2368. * opacity: 1;
  2369. * }
  2370. * .fade-exit-active{
  2371. * opacity: 0;
  2372. * }
  2373. * .fade-enter-active,
  2374. * .fade-exit-active{
  2375. * transition: opacity 500ms;
  2376. * }
  2377. * ```
  2378. */
  2379. var SwitchTransition = /*#__PURE__*/function (_React$Component) {
  2380. _inheritsLoose(SwitchTransition, _React$Component);
  2381. function SwitchTransition() {
  2382. var _this;
  2383. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2384. args[_key] = arguments[_key];
  2385. }
  2386. _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
  2387. _this.state = {
  2388. status: ENTERED,
  2389. current: null
  2390. };
  2391. _this.appeared = false;
  2392. _this.changeState = function (status, current) {
  2393. if (current === void 0) {
  2394. current = _this.state.current;
  2395. }
  2396. _this.setState({
  2397. status: status,
  2398. current: current
  2399. });
  2400. };
  2401. return _this;
  2402. }
  2403. var _proto = SwitchTransition.prototype;
  2404. _proto.componentDidMount = function componentDidMount() {
  2405. this.appeared = true;
  2406. };
  2407. SwitchTransition.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
  2408. if (props.children == null) {
  2409. return {
  2410. current: null
  2411. };
  2412. }
  2413. if (state.status === ENTERING && props.mode === modes.in) {
  2414. return {
  2415. status: ENTERING
  2416. };
  2417. }
  2418. if (state.current && areChildrenDifferent(state.current, props.children)) {
  2419. return {
  2420. status: EXITING
  2421. };
  2422. }
  2423. return {
  2424. current: React__default.cloneElement(props.children, {
  2425. in: true
  2426. })
  2427. };
  2428. };
  2429. _proto.render = function render() {
  2430. var _this$props = this.props,
  2431. children = _this$props.children,
  2432. mode = _this$props.mode,
  2433. _this$state = this.state,
  2434. status = _this$state.status,
  2435. current = _this$state.current;
  2436. var data = {
  2437. children: children,
  2438. current: current,
  2439. changeState: this.changeState,
  2440. status: status
  2441. };
  2442. var component;
  2443. switch (status) {
  2444. case ENTERING:
  2445. component = enterRenders[mode](data);
  2446. break;
  2447. case EXITING:
  2448. component = leaveRenders[mode](data);
  2449. break;
  2450. case ENTERED:
  2451. component = current;
  2452. }
  2453. return /*#__PURE__*/React__default.createElement(TransitionGroupContext.Provider, {
  2454. value: {
  2455. isMounting: !this.appeared
  2456. }
  2457. }, component);
  2458. };
  2459. return SwitchTransition;
  2460. }(React__default.Component);
  2461. SwitchTransition.propTypes = {
  2462. /**
  2463. * Transition modes.
  2464. * `out-in`: Current element transitions out first, then when complete, the new element transitions in.
  2465. * `in-out`: New element transitions in first, then when complete, the current element transitions out.
  2466. *
  2467. * @type {'out-in'|'in-out'}
  2468. */
  2469. mode: propTypes.oneOf([modes.in, modes.out]),
  2470. /**
  2471. * Any `Transition` or `CSSTransition` component.
  2472. */
  2473. children: propTypes.oneOfType([propTypes.element.isRequired])
  2474. } ;
  2475. SwitchTransition.defaultProps = {
  2476. mode: modes.out
  2477. };
  2478. exports.CSSTransition = CSSTransition;
  2479. exports.ReplaceTransition = ReplaceTransition;
  2480. exports.SwitchTransition = SwitchTransition;
  2481. exports.Transition = Transition;
  2482. exports.TransitionGroup = TransitionGroup;
  2483. exports.config = config;
  2484. Object.defineProperty(exports, '__esModule', { value: true });
  2485. })));