react.js 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714
  1. /** @license React v16.9.0
  2. * react.development.js
  3. *
  4. * Copyright (c) Facebook, Inc. and its affiliates.
  5. *
  6. * This source code is licensed under the MIT license found in the
  7. * LICENSE file in the root directory of this source tree.
  8. */
  9. 'use strict';
  10. (function (global, factory) {
  11. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  12. typeof define === 'function' && define.amd ? define(factory) :
  13. (global.React = factory());
  14. }(this, (function () { 'use strict';
  15. // TODO: this is special because it gets imported during build.
  16. var ReactVersion = '16.9.0';
  17. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  18. // nor polyfill, then a plain number is used for performance.
  19. var hasSymbol = typeof Symbol === 'function' && Symbol.for;
  20. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
  21. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
  22. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
  23. var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
  24. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
  25. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
  26. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
  27. // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  28. // (unstable) APIs that have been removed. Can we remove the symbols?
  29. var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
  30. var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
  31. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
  32. var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
  33. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
  34. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
  35. var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
  36. var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
  37. var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  38. var FAUX_ITERATOR_SYMBOL = '@@iterator';
  39. function getIteratorFn(maybeIterable) {
  40. if (maybeIterable === null || typeof maybeIterable !== 'object') {
  41. return null;
  42. }
  43. var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
  44. if (typeof maybeIterator === 'function') {
  45. return maybeIterator;
  46. }
  47. return null;
  48. }
  49. /*
  50. object-assign
  51. (c) Sindre Sorhus
  52. @license MIT
  53. */
  54. /* eslint-disable no-unused-vars */
  55. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  56. var hasOwnProperty = Object.prototype.hasOwnProperty;
  57. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  58. function toObject(val) {
  59. if (val === null || val === undefined) {
  60. throw new TypeError('Object.assign cannot be called with null or undefined');
  61. }
  62. return Object(val);
  63. }
  64. function shouldUseNative() {
  65. try {
  66. if (!Object.assign) {
  67. return false;
  68. }
  69. // Detect buggy property enumeration order in older V8 versions.
  70. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  71. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  72. test1[5] = 'de';
  73. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  74. return false;
  75. }
  76. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  77. var test2 = {};
  78. for (var i = 0; i < 10; i++) {
  79. test2['_' + String.fromCharCode(i)] = i;
  80. }
  81. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  82. return test2[n];
  83. });
  84. if (order2.join('') !== '0123456789') {
  85. return false;
  86. }
  87. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  88. var test3 = {};
  89. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  90. test3[letter] = letter;
  91. });
  92. if (Object.keys(Object.assign({}, test3)).join('') !==
  93. 'abcdefghijklmnopqrst') {
  94. return false;
  95. }
  96. return true;
  97. } catch (err) {
  98. // We don't expect any of the above to throw, but better to be safe.
  99. return false;
  100. }
  101. }
  102. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  103. var from;
  104. var to = toObject(target);
  105. var symbols;
  106. for (var s = 1; s < arguments.length; s++) {
  107. from = Object(arguments[s]);
  108. for (var key in from) {
  109. if (hasOwnProperty.call(from, key)) {
  110. to[key] = from[key];
  111. }
  112. }
  113. if (getOwnPropertySymbols) {
  114. symbols = getOwnPropertySymbols(from);
  115. for (var i = 0; i < symbols.length; i++) {
  116. if (propIsEnumerable.call(from, symbols[i])) {
  117. to[symbols[i]] = from[symbols[i]];
  118. }
  119. }
  120. }
  121. }
  122. return to;
  123. };
  124. // Do not require this module directly! Use normal `invariant` calls with
  125. // template literal strings. The messages will be converted to ReactError during
  126. // build, and in production they will be minified.
  127. // Do not require this module directly! Use normal `invariant` calls with
  128. // template literal strings. The messages will be converted to ReactError during
  129. // build, and in production they will be minified.
  130. function ReactError(error) {
  131. error.name = 'Invariant Violation';
  132. return error;
  133. }
  134. /**
  135. * Use invariant() to assert state which your program assumes to be true.
  136. *
  137. * Provide sprintf-style format (only %s is supported) and arguments
  138. * to provide information about what broke and what you were
  139. * expecting.
  140. *
  141. * The invariant message will be stripped in production, but the invariant
  142. * will remain to ensure logic does not differ in production.
  143. */
  144. /**
  145. * Forked from fbjs/warning:
  146. * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
  147. *
  148. * Only change is we use console.warn instead of console.error,
  149. * and do nothing when 'console' is not supported.
  150. * This really simplifies the code.
  151. * ---
  152. * Similar to invariant but only logs a warning if the condition is not met.
  153. * This can be used to log issues in development environments in critical
  154. * paths. Removing the logging code for production environments will keep the
  155. * same logic and follow the same code paths.
  156. */
  157. var lowPriorityWarning = function () {};
  158. {
  159. var printWarning = function (format) {
  160. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  161. args[_key - 1] = arguments[_key];
  162. }
  163. var argIndex = 0;
  164. var message = 'Warning: ' + format.replace(/%s/g, function () {
  165. return args[argIndex++];
  166. });
  167. if (typeof console !== 'undefined') {
  168. console.warn(message);
  169. }
  170. try {
  171. // --- Welcome to debugging React ---
  172. // This error was thrown as a convenience so that you can use this stack
  173. // to find the callsite that caused this warning to fire.
  174. throw new Error(message);
  175. } catch (x) {}
  176. };
  177. lowPriorityWarning = function (condition, format) {
  178. if (format === undefined) {
  179. throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
  180. }
  181. if (!condition) {
  182. for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  183. args[_key2 - 2] = arguments[_key2];
  184. }
  185. printWarning.apply(undefined, [format].concat(args));
  186. }
  187. };
  188. }
  189. var lowPriorityWarning$1 = lowPriorityWarning;
  190. /**
  191. * Similar to invariant but only logs a warning if the condition is not met.
  192. * This can be used to log issues in development environments in critical
  193. * paths. Removing the logging code for production environments will keep the
  194. * same logic and follow the same code paths.
  195. */
  196. var warningWithoutStack = function () {};
  197. {
  198. warningWithoutStack = function (condition, format) {
  199. for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  200. args[_key - 2] = arguments[_key];
  201. }
  202. if (format === undefined) {
  203. throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
  204. }
  205. if (args.length > 8) {
  206. // Check before the condition to catch violations early.
  207. throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
  208. }
  209. if (condition) {
  210. return;
  211. }
  212. if (typeof console !== 'undefined') {
  213. var argsWithFormat = args.map(function (item) {
  214. return '' + item;
  215. });
  216. argsWithFormat.unshift('Warning: ' + format);
  217. // We intentionally don't use spread (or .apply) directly because it
  218. // breaks IE9: https://github.com/facebook/react/issues/13610
  219. Function.prototype.apply.call(console.error, console, argsWithFormat);
  220. }
  221. try {
  222. // --- Welcome to debugging React ---
  223. // This error was thrown as a convenience so that you can use this stack
  224. // to find the callsite that caused this warning to fire.
  225. var argIndex = 0;
  226. var message = 'Warning: ' + format.replace(/%s/g, function () {
  227. return args[argIndex++];
  228. });
  229. throw new Error(message);
  230. } catch (x) {}
  231. };
  232. }
  233. var warningWithoutStack$1 = warningWithoutStack;
  234. var didWarnStateUpdateForUnmountedComponent = {};
  235. function warnNoop(publicInstance, callerName) {
  236. {
  237. var _constructor = publicInstance.constructor;
  238. var componentName = _constructor && (_constructor.displayName || _constructor.name) || 'ReactClass';
  239. var warningKey = componentName + '.' + callerName;
  240. if (didWarnStateUpdateForUnmountedComponent[warningKey]) {
  241. return;
  242. }
  243. warningWithoutStack$1(false, "Can't call %s on a component that is not yet mounted. " + 'This is a no-op, but it might indicate a bug in your application. ' + 'Instead, assign to `this.state` directly or define a `state = {};` ' + 'class property with the desired state in the %s component.', callerName, componentName);
  244. didWarnStateUpdateForUnmountedComponent[warningKey] = true;
  245. }
  246. }
  247. /**
  248. * This is the abstract API for an update queue.
  249. */
  250. var ReactNoopUpdateQueue = {
  251. /**
  252. * Checks whether or not this composite component is mounted.
  253. * @param {ReactClass} publicInstance The instance we want to test.
  254. * @return {boolean} True if mounted, false otherwise.
  255. * @protected
  256. * @final
  257. */
  258. isMounted: function (publicInstance) {
  259. return false;
  260. },
  261. /**
  262. * Forces an update. This should only be invoked when it is known with
  263. * certainty that we are **not** in a DOM transaction.
  264. *
  265. * You may want to call this when you know that some deeper aspect of the
  266. * component's state has changed but `setState` was not called.
  267. *
  268. * This will not invoke `shouldComponentUpdate`, but it will invoke
  269. * `componentWillUpdate` and `componentDidUpdate`.
  270. *
  271. * @param {ReactClass} publicInstance The instance that should rerender.
  272. * @param {?function} callback Called after component is updated.
  273. * @param {?string} callerName name of the calling function in the public API.
  274. * @internal
  275. */
  276. enqueueForceUpdate: function (publicInstance, callback, callerName) {
  277. warnNoop(publicInstance, 'forceUpdate');
  278. },
  279. /**
  280. * Replaces all of the state. Always use this or `setState` to mutate state.
  281. * You should treat `this.state` as immutable.
  282. *
  283. * There is no guarantee that `this.state` will be immediately updated, so
  284. * accessing `this.state` after calling this method may return the old value.
  285. *
  286. * @param {ReactClass} publicInstance The instance that should rerender.
  287. * @param {object} completeState Next state.
  288. * @param {?function} callback Called after component is updated.
  289. * @param {?string} callerName name of the calling function in the public API.
  290. * @internal
  291. */
  292. enqueueReplaceState: function (publicInstance, completeState, callback, callerName) {
  293. warnNoop(publicInstance, 'replaceState');
  294. },
  295. /**
  296. * Sets a subset of the state. This only exists because _pendingState is
  297. * internal. This provides a merging strategy that is not available to deep
  298. * properties which is confusing. TODO: Expose pendingState or don't use it
  299. * during the merge.
  300. *
  301. * @param {ReactClass} publicInstance The instance that should rerender.
  302. * @param {object} partialState Next partial state to be merged with state.
  303. * @param {?function} callback Called after component is updated.
  304. * @param {?string} Name of the calling function in the public API.
  305. * @internal
  306. */
  307. enqueueSetState: function (publicInstance, partialState, callback, callerName) {
  308. warnNoop(publicInstance, 'setState');
  309. }
  310. };
  311. var emptyObject = {};
  312. {
  313. Object.freeze(emptyObject);
  314. }
  315. /**
  316. * Base class helpers for the updating state of a component.
  317. */
  318. function Component(props, context, updater) {
  319. this.props = props;
  320. this.context = context;
  321. // If a component has string refs, we will assign a different object later.
  322. this.refs = emptyObject;
  323. // We initialize the default updater but the real one gets injected by the
  324. // renderer.
  325. this.updater = updater || ReactNoopUpdateQueue;
  326. }
  327. Component.prototype.isReactComponent = {};
  328. /**
  329. * Sets a subset of the state. Always use this to mutate
  330. * state. You should treat `this.state` as immutable.
  331. *
  332. * There is no guarantee that `this.state` will be immediately updated, so
  333. * accessing `this.state` after calling this method may return the old value.
  334. *
  335. * There is no guarantee that calls to `setState` will run synchronously,
  336. * as they may eventually be batched together. You can provide an optional
  337. * callback that will be executed when the call to setState is actually
  338. * completed.
  339. *
  340. * When a function is provided to setState, it will be called at some point in
  341. * the future (not synchronously). It will be called with the up to date
  342. * component arguments (state, props, context). These values can be different
  343. * from this.* because your function may be called after receiveProps but before
  344. * shouldComponentUpdate, and this new state, props, and context will not yet be
  345. * assigned to this.
  346. *
  347. * @param {object|function} partialState Next partial state or function to
  348. * produce next partial state to be merged with current state.
  349. * @param {?function} callback Called after state is updated.
  350. * @final
  351. * @protected
  352. */
  353. Component.prototype.setState = function (partialState, callback) {
  354. (function () {
  355. if (!(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null)) {
  356. {
  357. throw ReactError(Error('setState(...): takes an object of state variables to update or a function which returns an object of state variables.'));
  358. }
  359. }
  360. })();
  361. this.updater.enqueueSetState(this, partialState, callback, 'setState');
  362. };
  363. /**
  364. * Forces an update. This should only be invoked when it is known with
  365. * certainty that we are **not** in a DOM transaction.
  366. *
  367. * You may want to call this when you know that some deeper aspect of the
  368. * component's state has changed but `setState` was not called.
  369. *
  370. * This will not invoke `shouldComponentUpdate`, but it will invoke
  371. * `componentWillUpdate` and `componentDidUpdate`.
  372. *
  373. * @param {?function} callback Called after update is complete.
  374. * @final
  375. * @protected
  376. */
  377. Component.prototype.forceUpdate = function (callback) {
  378. this.updater.enqueueForceUpdate(this, callback, 'forceUpdate');
  379. };
  380. /**
  381. * Deprecated APIs. These APIs used to exist on classic React classes but since
  382. * we would like to deprecate them, we're not going to move them over to this
  383. * modern base class. Instead, we define a getter that warns if it's accessed.
  384. */
  385. {
  386. var deprecatedAPIs = {
  387. isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
  388. replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).']
  389. };
  390. var defineDeprecationWarning = function (methodName, info) {
  391. Object.defineProperty(Component.prototype, methodName, {
  392. get: function () {
  393. lowPriorityWarning$1(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]);
  394. return undefined;
  395. }
  396. });
  397. };
  398. for (var fnName in deprecatedAPIs) {
  399. if (deprecatedAPIs.hasOwnProperty(fnName)) {
  400. defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
  401. }
  402. }
  403. }
  404. function ComponentDummy() {}
  405. ComponentDummy.prototype = Component.prototype;
  406. /**
  407. * Convenience component with default shallow equality check for sCU.
  408. */
  409. function PureComponent(props, context, updater) {
  410. this.props = props;
  411. this.context = context;
  412. // If a component has string refs, we will assign a different object later.
  413. this.refs = emptyObject;
  414. this.updater = updater || ReactNoopUpdateQueue;
  415. }
  416. var pureComponentPrototype = PureComponent.prototype = new ComponentDummy();
  417. pureComponentPrototype.constructor = PureComponent;
  418. // Avoid an extra prototype jump for these methods.
  419. objectAssign(pureComponentPrototype, Component.prototype);
  420. pureComponentPrototype.isPureReactComponent = true;
  421. // an immutable object with a single mutable value
  422. function createRef() {
  423. var refObject = {
  424. current: null
  425. };
  426. {
  427. Object.seal(refObject);
  428. }
  429. return refObject;
  430. }
  431. /**
  432. * Keeps track of the current dispatcher.
  433. */
  434. var ReactCurrentDispatcher = {
  435. /**
  436. * @internal
  437. * @type {ReactComponent}
  438. */
  439. current: null
  440. };
  441. /**
  442. * Keeps track of the current batch's configuration such as how long an update
  443. * should suspend for if it needs to.
  444. */
  445. var ReactCurrentBatchConfig = {
  446. suspense: null
  447. };
  448. /**
  449. * Keeps track of the current owner.
  450. *
  451. * The current owner is the component who should own any components that are
  452. * currently being constructed.
  453. */
  454. var ReactCurrentOwner = {
  455. /**
  456. * @internal
  457. * @type {ReactComponent}
  458. */
  459. current: null
  460. };
  461. var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
  462. var describeComponentFrame = function (name, source, ownerName) {
  463. var sourceInfo = '';
  464. if (source) {
  465. var path = source.fileName;
  466. var fileName = path.replace(BEFORE_SLASH_RE, '');
  467. {
  468. // In DEV, include code for a common special case:
  469. // prefer "folder/index.js" instead of just "index.js".
  470. if (/^index\./.test(fileName)) {
  471. var match = path.match(BEFORE_SLASH_RE);
  472. if (match) {
  473. var pathBeforeSlash = match[1];
  474. if (pathBeforeSlash) {
  475. var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
  476. fileName = folderName + '/' + fileName;
  477. }
  478. }
  479. }
  480. }
  481. sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
  482. } else if (ownerName) {
  483. sourceInfo = ' (created by ' + ownerName + ')';
  484. }
  485. return '\n in ' + (name || 'Unknown') + sourceInfo;
  486. };
  487. var Resolved = 1;
  488. function refineResolvedLazyComponent(lazyComponent) {
  489. return lazyComponent._status === Resolved ? lazyComponent._result : null;
  490. }
  491. function getWrappedName(outerType, innerType, wrapperName) {
  492. var functionName = innerType.displayName || innerType.name || '';
  493. return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
  494. }
  495. function getComponentName(type) {
  496. if (type == null) {
  497. // Host root, text node or just invalid type.
  498. return null;
  499. }
  500. {
  501. if (typeof type.tag === 'number') {
  502. warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
  503. }
  504. }
  505. if (typeof type === 'function') {
  506. return type.displayName || type.name || null;
  507. }
  508. if (typeof type === 'string') {
  509. return type;
  510. }
  511. switch (type) {
  512. case REACT_FRAGMENT_TYPE:
  513. return 'Fragment';
  514. case REACT_PORTAL_TYPE:
  515. return 'Portal';
  516. case REACT_PROFILER_TYPE:
  517. return 'Profiler';
  518. case REACT_STRICT_MODE_TYPE:
  519. return 'StrictMode';
  520. case REACT_SUSPENSE_TYPE:
  521. return 'Suspense';
  522. case REACT_SUSPENSE_LIST_TYPE:
  523. return 'SuspenseList';
  524. }
  525. if (typeof type === 'object') {
  526. switch (type.$$typeof) {
  527. case REACT_CONTEXT_TYPE:
  528. return 'Context.Consumer';
  529. case REACT_PROVIDER_TYPE:
  530. return 'Context.Provider';
  531. case REACT_FORWARD_REF_TYPE:
  532. return getWrappedName(type, type.render, 'ForwardRef');
  533. case REACT_MEMO_TYPE:
  534. return getComponentName(type.type);
  535. case REACT_LAZY_TYPE:
  536. {
  537. var thenable = type;
  538. var resolvedThenable = refineResolvedLazyComponent(thenable);
  539. if (resolvedThenable) {
  540. return getComponentName(resolvedThenable);
  541. }
  542. break;
  543. }
  544. }
  545. }
  546. return null;
  547. }
  548. var ReactDebugCurrentFrame = {};
  549. var currentlyValidatingElement = null;
  550. function setCurrentlyValidatingElement(element) {
  551. {
  552. currentlyValidatingElement = element;
  553. }
  554. }
  555. {
  556. // Stack implementation injected by the current renderer.
  557. ReactDebugCurrentFrame.getCurrentStack = null;
  558. ReactDebugCurrentFrame.getStackAddendum = function () {
  559. var stack = '';
  560. // Add an extra top frame while an element is being validated
  561. if (currentlyValidatingElement) {
  562. var name = getComponentName(currentlyValidatingElement.type);
  563. var owner = currentlyValidatingElement._owner;
  564. stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner.type));
  565. }
  566. // Delegate to the injected renderer-specific implementation
  567. var impl = ReactDebugCurrentFrame.getCurrentStack;
  568. if (impl) {
  569. stack += impl() || '';
  570. }
  571. return stack;
  572. };
  573. }
  574. /**
  575. * Used by act() to track whether you're inside an act() scope.
  576. */
  577. var IsSomeRendererActing = {
  578. current: false
  579. };
  580. var ReactSharedInternals = {
  581. ReactCurrentDispatcher: ReactCurrentDispatcher,
  582. ReactCurrentBatchConfig: ReactCurrentBatchConfig,
  583. ReactCurrentOwner: ReactCurrentOwner,
  584. IsSomeRendererActing: IsSomeRendererActing,
  585. // Used by renderers to avoid bundling object-assign twice in UMD bundles:
  586. assign: objectAssign
  587. };
  588. {
  589. objectAssign(ReactSharedInternals, {
  590. // These should not be included in production.
  591. ReactDebugCurrentFrame: ReactDebugCurrentFrame,
  592. // Shim for React DOM 16.0.0 which still destructured (but not used) this.
  593. // TODO: remove in React 17.0.
  594. ReactComponentTreeHook: {}
  595. });
  596. }
  597. /**
  598. * Similar to invariant but only logs a warning if the condition is not met.
  599. * This can be used to log issues in development environments in critical
  600. * paths. Removing the logging code for production environments will keep the
  601. * same logic and follow the same code paths.
  602. */
  603. var warning = warningWithoutStack$1;
  604. {
  605. warning = function (condition, format) {
  606. if (condition) {
  607. return;
  608. }
  609. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  610. var stack = ReactDebugCurrentFrame.getStackAddendum();
  611. // eslint-disable-next-line react-internal/warning-and-invariant-args
  612. for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  613. args[_key - 2] = arguments[_key];
  614. }
  615. warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
  616. };
  617. }
  618. var warning$1 = warning;
  619. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  620. var RESERVED_PROPS = {
  621. key: true,
  622. ref: true,
  623. __self: true,
  624. __source: true
  625. };
  626. var specialPropKeyWarningShown = void 0;
  627. var specialPropRefWarningShown = void 0;
  628. function hasValidRef(config) {
  629. {
  630. if (hasOwnProperty$1.call(config, 'ref')) {
  631. var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
  632. if (getter && getter.isReactWarning) {
  633. return false;
  634. }
  635. }
  636. }
  637. return config.ref !== undefined;
  638. }
  639. function hasValidKey(config) {
  640. {
  641. if (hasOwnProperty$1.call(config, 'key')) {
  642. var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
  643. if (getter && getter.isReactWarning) {
  644. return false;
  645. }
  646. }
  647. }
  648. return config.key !== undefined;
  649. }
  650. function defineKeyPropWarningGetter(props, displayName) {
  651. var warnAboutAccessingKey = function () {
  652. if (!specialPropKeyWarningShown) {
  653. specialPropKeyWarningShown = true;
  654. warningWithoutStack$1(false, '%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName);
  655. }
  656. };
  657. warnAboutAccessingKey.isReactWarning = true;
  658. Object.defineProperty(props, 'key', {
  659. get: warnAboutAccessingKey,
  660. configurable: true
  661. });
  662. }
  663. function defineRefPropWarningGetter(props, displayName) {
  664. var warnAboutAccessingRef = function () {
  665. if (!specialPropRefWarningShown) {
  666. specialPropRefWarningShown = true;
  667. warningWithoutStack$1(false, '%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName);
  668. }
  669. };
  670. warnAboutAccessingRef.isReactWarning = true;
  671. Object.defineProperty(props, 'ref', {
  672. get: warnAboutAccessingRef,
  673. configurable: true
  674. });
  675. }
  676. /**
  677. * Factory method to create a new React element. This no longer adheres to
  678. * the class pattern, so do not use new to call it. Also, no instanceof check
  679. * will work. Instead test $$typeof field against Symbol.for('react.element') to check
  680. * if something is a React Element.
  681. *
  682. * @param {*} type
  683. * @param {*} props
  684. * @param {*} key
  685. * @param {string|object} ref
  686. * @param {*} owner
  687. * @param {*} self A *temporary* helper to detect places where `this` is
  688. * different from the `owner` when React.createElement is called, so that we
  689. * can warn. We want to get rid of owner and replace string `ref`s with arrow
  690. * functions, and as long as `this` and owner are the same, there will be no
  691. * change in behavior.
  692. * @param {*} source An annotation object (added by a transpiler or otherwise)
  693. * indicating filename, line number, and/or other information.
  694. * @internal
  695. */
  696. var ReactElement = function (type, key, ref, self, source, owner, props) {
  697. var element = {
  698. // This tag allows us to uniquely identify this as a React Element
  699. $$typeof: REACT_ELEMENT_TYPE,
  700. // Built-in properties that belong on the element
  701. type: type,
  702. key: key,
  703. ref: ref,
  704. props: props,
  705. // Record the component responsible for creating this element.
  706. _owner: owner
  707. };
  708. {
  709. // The validation flag is currently mutative. We put it on
  710. // an external backing store so that we can freeze the whole object.
  711. // This can be replaced with a WeakMap once they are implemented in
  712. // commonly used development environments.
  713. element._store = {};
  714. // To make comparing ReactElements easier for testing purposes, we make
  715. // the validation flag non-enumerable (where possible, which should
  716. // include every environment we run tests in), so the test framework
  717. // ignores it.
  718. Object.defineProperty(element._store, 'validated', {
  719. configurable: false,
  720. enumerable: false,
  721. writable: true,
  722. value: false
  723. });
  724. // self and source are DEV only properties.
  725. Object.defineProperty(element, '_self', {
  726. configurable: false,
  727. enumerable: false,
  728. writable: false,
  729. value: self
  730. });
  731. // Two elements created in two different places should be considered
  732. // equal for testing purposes and therefore we hide it from enumeration.
  733. Object.defineProperty(element, '_source', {
  734. configurable: false,
  735. enumerable: false,
  736. writable: false,
  737. value: source
  738. });
  739. if (Object.freeze) {
  740. Object.freeze(element.props);
  741. Object.freeze(element);
  742. }
  743. }
  744. return element;
  745. };
  746. /**
  747. * https://github.com/reactjs/rfcs/pull/107
  748. * @param {*} type
  749. * @param {object} props
  750. * @param {string} key
  751. */
  752. /**
  753. * https://github.com/reactjs/rfcs/pull/107
  754. * @param {*} type
  755. * @param {object} props
  756. * @param {string} key
  757. */
  758. function jsxDEV(type, config, maybeKey, source, self) {
  759. var propName = void 0;
  760. // Reserved names are extracted
  761. var props = {};
  762. var key = null;
  763. var ref = null;
  764. if (hasValidRef(config)) {
  765. ref = config.ref;
  766. }
  767. if (hasValidKey(config)) {
  768. key = '' + config.key;
  769. }
  770. // Remaining properties are added to a new props object
  771. for (propName in config) {
  772. if (hasOwnProperty$1.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
  773. props[propName] = config[propName];
  774. }
  775. }
  776. // intentionally not checking if key was set above
  777. // this key is higher priority as it's static
  778. if (maybeKey !== undefined) {
  779. key = '' + maybeKey;
  780. }
  781. // Resolve default props
  782. if (type && type.defaultProps) {
  783. var defaultProps = type.defaultProps;
  784. for (propName in defaultProps) {
  785. if (props[propName] === undefined) {
  786. props[propName] = defaultProps[propName];
  787. }
  788. }
  789. }
  790. if (key || ref) {
  791. var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
  792. if (key) {
  793. defineKeyPropWarningGetter(props, displayName);
  794. }
  795. if (ref) {
  796. defineRefPropWarningGetter(props, displayName);
  797. }
  798. }
  799. return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
  800. }
  801. /**
  802. * Create and return a new ReactElement of the given type.
  803. * See https://reactjs.org/docs/react-api.html#createelement
  804. */
  805. function createElement(type, config, children) {
  806. var propName = void 0;
  807. // Reserved names are extracted
  808. var props = {};
  809. var key = null;
  810. var ref = null;
  811. var self = null;
  812. var source = null;
  813. if (config != null) {
  814. if (hasValidRef(config)) {
  815. ref = config.ref;
  816. }
  817. if (hasValidKey(config)) {
  818. key = '' + config.key;
  819. }
  820. self = config.__self === undefined ? null : config.__self;
  821. source = config.__source === undefined ? null : config.__source;
  822. // Remaining properties are added to a new props object
  823. for (propName in config) {
  824. if (hasOwnProperty$1.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
  825. props[propName] = config[propName];
  826. }
  827. }
  828. }
  829. // Children can be more than one argument, and those are transferred onto
  830. // the newly allocated props object.
  831. var childrenLength = arguments.length - 2;
  832. if (childrenLength === 1) {
  833. props.children = children;
  834. } else if (childrenLength > 1) {
  835. var childArray = Array(childrenLength);
  836. for (var i = 0; i < childrenLength; i++) {
  837. childArray[i] = arguments[i + 2];
  838. }
  839. {
  840. if (Object.freeze) {
  841. Object.freeze(childArray);
  842. }
  843. }
  844. props.children = childArray;
  845. }
  846. // Resolve default props
  847. if (type && type.defaultProps) {
  848. var defaultProps = type.defaultProps;
  849. for (propName in defaultProps) {
  850. if (props[propName] === undefined) {
  851. props[propName] = defaultProps[propName];
  852. }
  853. }
  854. }
  855. {
  856. if (key || ref) {
  857. var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
  858. if (key) {
  859. defineKeyPropWarningGetter(props, displayName);
  860. }
  861. if (ref) {
  862. defineRefPropWarningGetter(props, displayName);
  863. }
  864. }
  865. }
  866. return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
  867. }
  868. /**
  869. * Return a function that produces ReactElements of a given type.
  870. * See https://reactjs.org/docs/react-api.html#createfactory
  871. */
  872. function cloneAndReplaceKey(oldElement, newKey) {
  873. var newElement = ReactElement(oldElement.type, newKey, oldElement.ref, oldElement._self, oldElement._source, oldElement._owner, oldElement.props);
  874. return newElement;
  875. }
  876. /**
  877. * Clone and return a new ReactElement using element as the starting point.
  878. * See https://reactjs.org/docs/react-api.html#cloneelement
  879. */
  880. function cloneElement(element, config, children) {
  881. (function () {
  882. if (!!(element === null || element === undefined)) {
  883. {
  884. throw ReactError(Error('React.cloneElement(...): The argument must be a React element, but you passed ' + element + '.'));
  885. }
  886. }
  887. })();
  888. var propName = void 0;
  889. // Original props are copied
  890. var props = objectAssign({}, element.props);
  891. // Reserved names are extracted
  892. var key = element.key;
  893. var ref = element.ref;
  894. // Self is preserved since the owner is preserved.
  895. var self = element._self;
  896. // Source is preserved since cloneElement is unlikely to be targeted by a
  897. // transpiler, and the original source is probably a better indicator of the
  898. // true owner.
  899. var source = element._source;
  900. // Owner will be preserved, unless ref is overridden
  901. var owner = element._owner;
  902. if (config != null) {
  903. if (hasValidRef(config)) {
  904. // Silently steal the ref from the parent.
  905. ref = config.ref;
  906. owner = ReactCurrentOwner.current;
  907. }
  908. if (hasValidKey(config)) {
  909. key = '' + config.key;
  910. }
  911. // Remaining properties override existing props
  912. var defaultProps = void 0;
  913. if (element.type && element.type.defaultProps) {
  914. defaultProps = element.type.defaultProps;
  915. }
  916. for (propName in config) {
  917. if (hasOwnProperty$1.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
  918. if (config[propName] === undefined && defaultProps !== undefined) {
  919. // Resolve default props
  920. props[propName] = defaultProps[propName];
  921. } else {
  922. props[propName] = config[propName];
  923. }
  924. }
  925. }
  926. }
  927. // Children can be more than one argument, and those are transferred onto
  928. // the newly allocated props object.
  929. var childrenLength = arguments.length - 2;
  930. if (childrenLength === 1) {
  931. props.children = children;
  932. } else if (childrenLength > 1) {
  933. var childArray = Array(childrenLength);
  934. for (var i = 0; i < childrenLength; i++) {
  935. childArray[i] = arguments[i + 2];
  936. }
  937. props.children = childArray;
  938. }
  939. return ReactElement(element.type, key, ref, self, source, owner, props);
  940. }
  941. /**
  942. * Verifies the object is a ReactElement.
  943. * See https://reactjs.org/docs/react-api.html#isvalidelement
  944. * @param {?object} object
  945. * @return {boolean} True if `object` is a ReactElement.
  946. * @final
  947. */
  948. function isValidElement(object) {
  949. return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
  950. }
  951. var SEPARATOR = '.';
  952. var SUBSEPARATOR = ':';
  953. /**
  954. * Escape and wrap key so it is safe to use as a reactid
  955. *
  956. * @param {string} key to be escaped.
  957. * @return {string} the escaped key.
  958. */
  959. function escape(key) {
  960. var escapeRegex = /[=:]/g;
  961. var escaperLookup = {
  962. '=': '=0',
  963. ':': '=2'
  964. };
  965. var escapedString = ('' + key).replace(escapeRegex, function (match) {
  966. return escaperLookup[match];
  967. });
  968. return '$' + escapedString;
  969. }
  970. /**
  971. * TODO: Test that a single child and an array with one item have the same key
  972. * pattern.
  973. */
  974. var didWarnAboutMaps = false;
  975. var userProvidedKeyEscapeRegex = /\/+/g;
  976. function escapeUserProvidedKey(text) {
  977. return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/');
  978. }
  979. var POOL_SIZE = 10;
  980. var traverseContextPool = [];
  981. function getPooledTraverseContext(mapResult, keyPrefix, mapFunction, mapContext) {
  982. if (traverseContextPool.length) {
  983. var traverseContext = traverseContextPool.pop();
  984. traverseContext.result = mapResult;
  985. traverseContext.keyPrefix = keyPrefix;
  986. traverseContext.func = mapFunction;
  987. traverseContext.context = mapContext;
  988. traverseContext.count = 0;
  989. return traverseContext;
  990. } else {
  991. return {
  992. result: mapResult,
  993. keyPrefix: keyPrefix,
  994. func: mapFunction,
  995. context: mapContext,
  996. count: 0
  997. };
  998. }
  999. }
  1000. function releaseTraverseContext(traverseContext) {
  1001. traverseContext.result = null;
  1002. traverseContext.keyPrefix = null;
  1003. traverseContext.func = null;
  1004. traverseContext.context = null;
  1005. traverseContext.count = 0;
  1006. if (traverseContextPool.length < POOL_SIZE) {
  1007. traverseContextPool.push(traverseContext);
  1008. }
  1009. }
  1010. /**
  1011. * @param {?*} children Children tree container.
  1012. * @param {!string} nameSoFar Name of the key path so far.
  1013. * @param {!function} callback Callback to invoke with each child found.
  1014. * @param {?*} traverseContext Used to pass information throughout the traversal
  1015. * process.
  1016. * @return {!number} The number of children in this subtree.
  1017. */
  1018. function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
  1019. var type = typeof children;
  1020. if (type === 'undefined' || type === 'boolean') {
  1021. // All of the above are perceived as null.
  1022. children = null;
  1023. }
  1024. var invokeCallback = false;
  1025. if (children === null) {
  1026. invokeCallback = true;
  1027. } else {
  1028. switch (type) {
  1029. case 'string':
  1030. case 'number':
  1031. invokeCallback = true;
  1032. break;
  1033. case 'object':
  1034. switch (children.$$typeof) {
  1035. case REACT_ELEMENT_TYPE:
  1036. case REACT_PORTAL_TYPE:
  1037. invokeCallback = true;
  1038. }
  1039. }
  1040. }
  1041. if (invokeCallback) {
  1042. callback(traverseContext, children,
  1043. // If it's the only child, treat the name as if it was wrapped in an array
  1044. // so that it's consistent if the number of children grows.
  1045. nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
  1046. return 1;
  1047. }
  1048. var child = void 0;
  1049. var nextName = void 0;
  1050. var subtreeCount = 0; // Count of children found in the current subtree.
  1051. var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
  1052. if (Array.isArray(children)) {
  1053. for (var i = 0; i < children.length; i++) {
  1054. child = children[i];
  1055. nextName = nextNamePrefix + getComponentKey(child, i);
  1056. subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
  1057. }
  1058. } else {
  1059. var iteratorFn = getIteratorFn(children);
  1060. if (typeof iteratorFn === 'function') {
  1061. {
  1062. // Warn about using Maps as children
  1063. if (iteratorFn === children.entries) {
  1064. !didWarnAboutMaps ? warning$1(false, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.') : void 0;
  1065. didWarnAboutMaps = true;
  1066. }
  1067. }
  1068. var iterator = iteratorFn.call(children);
  1069. var step = void 0;
  1070. var ii = 0;
  1071. while (!(step = iterator.next()).done) {
  1072. child = step.value;
  1073. nextName = nextNamePrefix + getComponentKey(child, ii++);
  1074. subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
  1075. }
  1076. } else if (type === 'object') {
  1077. var addendum = '';
  1078. {
  1079. addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + ReactDebugCurrentFrame.getStackAddendum();
  1080. }
  1081. var childrenString = '' + children;
  1082. (function () {
  1083. {
  1084. {
  1085. throw ReactError(Error('Objects are not valid as a React child (found: ' + (childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString) + ').' + addendum));
  1086. }
  1087. }
  1088. })();
  1089. }
  1090. }
  1091. return subtreeCount;
  1092. }
  1093. /**
  1094. * Traverses children that are typically specified as `props.children`, but
  1095. * might also be specified through attributes:
  1096. *
  1097. * - `traverseAllChildren(this.props.children, ...)`
  1098. * - `traverseAllChildren(this.props.leftPanelChildren, ...)`
  1099. *
  1100. * The `traverseContext` is an optional argument that is passed through the
  1101. * entire traversal. It can be used to store accumulations or anything else that
  1102. * the callback might find relevant.
  1103. *
  1104. * @param {?*} children Children tree object.
  1105. * @param {!function} callback To invoke upon traversing each child.
  1106. * @param {?*} traverseContext Context for traversal.
  1107. * @return {!number} The number of children in this subtree.
  1108. */
  1109. function traverseAllChildren(children, callback, traverseContext) {
  1110. if (children == null) {
  1111. return 0;
  1112. }
  1113. return traverseAllChildrenImpl(children, '', callback, traverseContext);
  1114. }
  1115. /**
  1116. * Generate a key string that identifies a component within a set.
  1117. *
  1118. * @param {*} component A component that could contain a manual key.
  1119. * @param {number} index Index that is used if a manual key is not provided.
  1120. * @return {string}
  1121. */
  1122. function getComponentKey(component, index) {
  1123. // Do some typechecking here since we call this blindly. We want to ensure
  1124. // that we don't block potential future ES APIs.
  1125. if (typeof component === 'object' && component !== null && component.key != null) {
  1126. // Explicit key
  1127. return escape(component.key);
  1128. }
  1129. // Implicit key determined by the index in the set
  1130. return index.toString(36);
  1131. }
  1132. function forEachSingleChild(bookKeeping, child, name) {
  1133. var func = bookKeeping.func,
  1134. context = bookKeeping.context;
  1135. func.call(context, child, bookKeeping.count++);
  1136. }
  1137. /**
  1138. * Iterates through children that are typically specified as `props.children`.
  1139. *
  1140. * See https://reactjs.org/docs/react-api.html#reactchildrenforeach
  1141. *
  1142. * The provided forEachFunc(child, index) will be called for each
  1143. * leaf child.
  1144. *
  1145. * @param {?*} children Children tree container.
  1146. * @param {function(*, int)} forEachFunc
  1147. * @param {*} forEachContext Context for forEachContext.
  1148. */
  1149. function forEachChildren(children, forEachFunc, forEachContext) {
  1150. if (children == null) {
  1151. return children;
  1152. }
  1153. var traverseContext = getPooledTraverseContext(null, null, forEachFunc, forEachContext);
  1154. traverseAllChildren(children, forEachSingleChild, traverseContext);
  1155. releaseTraverseContext(traverseContext);
  1156. }
  1157. function mapSingleChildIntoContext(bookKeeping, child, childKey) {
  1158. var result = bookKeeping.result,
  1159. keyPrefix = bookKeeping.keyPrefix,
  1160. func = bookKeeping.func,
  1161. context = bookKeeping.context;
  1162. var mappedChild = func.call(context, child, bookKeeping.count++);
  1163. if (Array.isArray(mappedChild)) {
  1164. mapIntoWithKeyPrefixInternal(mappedChild, result, childKey, function (c) {
  1165. return c;
  1166. });
  1167. } else if (mappedChild != null) {
  1168. if (isValidElement(mappedChild)) {
  1169. mappedChild = cloneAndReplaceKey(mappedChild,
  1170. // Keep both the (mapped) and old keys if they differ, just as
  1171. // traverseAllChildren used to do for objects as children
  1172. keyPrefix + (mappedChild.key && (!child || child.key !== mappedChild.key) ? escapeUserProvidedKey(mappedChild.key) + '/' : '') + childKey);
  1173. }
  1174. result.push(mappedChild);
  1175. }
  1176. }
  1177. function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context) {
  1178. var escapedPrefix = '';
  1179. if (prefix != null) {
  1180. escapedPrefix = escapeUserProvidedKey(prefix) + '/';
  1181. }
  1182. var traverseContext = getPooledTraverseContext(array, escapedPrefix, func, context);
  1183. traverseAllChildren(children, mapSingleChildIntoContext, traverseContext);
  1184. releaseTraverseContext(traverseContext);
  1185. }
  1186. /**
  1187. * Maps children that are typically specified as `props.children`.
  1188. *
  1189. * See https://reactjs.org/docs/react-api.html#reactchildrenmap
  1190. *
  1191. * The provided mapFunction(child, key, index) will be called for each
  1192. * leaf child.
  1193. *
  1194. * @param {?*} children Children tree container.
  1195. * @param {function(*, int)} func The map function.
  1196. * @param {*} context Context for mapFunction.
  1197. * @return {object} Object containing the ordered map of results.
  1198. */
  1199. function mapChildren(children, func, context) {
  1200. if (children == null) {
  1201. return children;
  1202. }
  1203. var result = [];
  1204. mapIntoWithKeyPrefixInternal(children, result, null, func, context);
  1205. return result;
  1206. }
  1207. /**
  1208. * Count the number of children that are typically specified as
  1209. * `props.children`.
  1210. *
  1211. * See https://reactjs.org/docs/react-api.html#reactchildrencount
  1212. *
  1213. * @param {?*} children Children tree container.
  1214. * @return {number} The number of children.
  1215. */
  1216. function countChildren(children) {
  1217. return traverseAllChildren(children, function () {
  1218. return null;
  1219. }, null);
  1220. }
  1221. /**
  1222. * Flatten a children object (typically specified as `props.children`) and
  1223. * return an array with appropriately re-keyed children.
  1224. *
  1225. * See https://reactjs.org/docs/react-api.html#reactchildrentoarray
  1226. */
  1227. function toArray(children) {
  1228. var result = [];
  1229. mapIntoWithKeyPrefixInternal(children, result, null, function (child) {
  1230. return child;
  1231. });
  1232. return result;
  1233. }
  1234. /**
  1235. * Returns the first child in a collection of children and verifies that there
  1236. * is only one child in the collection.
  1237. *
  1238. * See https://reactjs.org/docs/react-api.html#reactchildrenonly
  1239. *
  1240. * The current implementation of this function assumes that a single child gets
  1241. * passed without a wrapper, but the purpose of this helper function is to
  1242. * abstract away the particular structure of children.
  1243. *
  1244. * @param {?object} children Child collection structure.
  1245. * @return {ReactElement} The first and only `ReactElement` contained in the
  1246. * structure.
  1247. */
  1248. function onlyChild(children) {
  1249. (function () {
  1250. if (!isValidElement(children)) {
  1251. {
  1252. throw ReactError(Error('React.Children.only expected to receive a single React element child.'));
  1253. }
  1254. }
  1255. })();
  1256. return children;
  1257. }
  1258. function createContext(defaultValue, calculateChangedBits) {
  1259. if (calculateChangedBits === undefined) {
  1260. calculateChangedBits = null;
  1261. } else {
  1262. {
  1263. !(calculateChangedBits === null || typeof calculateChangedBits === 'function') ? warningWithoutStack$1(false, 'createContext: Expected the optional second argument to be a ' + 'function. Instead received: %s', calculateChangedBits) : void 0;
  1264. }
  1265. }
  1266. var context = {
  1267. $$typeof: REACT_CONTEXT_TYPE,
  1268. _calculateChangedBits: calculateChangedBits,
  1269. // As a workaround to support multiple concurrent renderers, we categorize
  1270. // some renderers as primary and others as secondary. We only expect
  1271. // there to be two concurrent renderers at most: React Native (primary) and
  1272. // Fabric (secondary); React DOM (primary) and React ART (secondary).
  1273. // Secondary renderers store their context values on separate fields.
  1274. _currentValue: defaultValue,
  1275. _currentValue2: defaultValue,
  1276. // Used to track how many concurrent renderers this context currently
  1277. // supports within in a single renderer. Such as parallel server rendering.
  1278. _threadCount: 0,
  1279. // These are circular
  1280. Provider: null,
  1281. Consumer: null
  1282. };
  1283. context.Provider = {
  1284. $$typeof: REACT_PROVIDER_TYPE,
  1285. _context: context
  1286. };
  1287. var hasWarnedAboutUsingNestedContextConsumers = false;
  1288. var hasWarnedAboutUsingConsumerProvider = false;
  1289. {
  1290. // A separate object, but proxies back to the original context object for
  1291. // backwards compatibility. It has a different $$typeof, so we can properly
  1292. // warn for the incorrect usage of Context as a Consumer.
  1293. var Consumer = {
  1294. $$typeof: REACT_CONTEXT_TYPE,
  1295. _context: context,
  1296. _calculateChangedBits: context._calculateChangedBits
  1297. };
  1298. // $FlowFixMe: Flow complains about not setting a value, which is intentional here
  1299. Object.defineProperties(Consumer, {
  1300. Provider: {
  1301. get: function () {
  1302. if (!hasWarnedAboutUsingConsumerProvider) {
  1303. hasWarnedAboutUsingConsumerProvider = true;
  1304. warning$1(false, 'Rendering <Context.Consumer.Provider> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Provider> instead?');
  1305. }
  1306. return context.Provider;
  1307. },
  1308. set: function (_Provider) {
  1309. context.Provider = _Provider;
  1310. }
  1311. },
  1312. _currentValue: {
  1313. get: function () {
  1314. return context._currentValue;
  1315. },
  1316. set: function (_currentValue) {
  1317. context._currentValue = _currentValue;
  1318. }
  1319. },
  1320. _currentValue2: {
  1321. get: function () {
  1322. return context._currentValue2;
  1323. },
  1324. set: function (_currentValue2) {
  1325. context._currentValue2 = _currentValue2;
  1326. }
  1327. },
  1328. _threadCount: {
  1329. get: function () {
  1330. return context._threadCount;
  1331. },
  1332. set: function (_threadCount) {
  1333. context._threadCount = _threadCount;
  1334. }
  1335. },
  1336. Consumer: {
  1337. get: function () {
  1338. if (!hasWarnedAboutUsingNestedContextConsumers) {
  1339. hasWarnedAboutUsingNestedContextConsumers = true;
  1340. warning$1(false, 'Rendering <Context.Consumer.Consumer> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
  1341. }
  1342. return context.Consumer;
  1343. }
  1344. }
  1345. });
  1346. // $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty
  1347. context.Consumer = Consumer;
  1348. }
  1349. {
  1350. context._currentRenderer = null;
  1351. context._currentRenderer2 = null;
  1352. }
  1353. return context;
  1354. }
  1355. function lazy(ctor) {
  1356. var lazyType = {
  1357. $$typeof: REACT_LAZY_TYPE,
  1358. _ctor: ctor,
  1359. // React uses these fields to store the result.
  1360. _status: -1,
  1361. _result: null
  1362. };
  1363. {
  1364. // In production, this would just set it on the object.
  1365. var defaultProps = void 0;
  1366. var propTypes = void 0;
  1367. Object.defineProperties(lazyType, {
  1368. defaultProps: {
  1369. configurable: true,
  1370. get: function () {
  1371. return defaultProps;
  1372. },
  1373. set: function (newDefaultProps) {
  1374. warning$1(false, 'React.lazy(...): It is not supported to assign `defaultProps` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
  1375. defaultProps = newDefaultProps;
  1376. // Match production behavior more closely:
  1377. Object.defineProperty(lazyType, 'defaultProps', {
  1378. enumerable: true
  1379. });
  1380. }
  1381. },
  1382. propTypes: {
  1383. configurable: true,
  1384. get: function () {
  1385. return propTypes;
  1386. },
  1387. set: function (newPropTypes) {
  1388. warning$1(false, 'React.lazy(...): It is not supported to assign `propTypes` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
  1389. propTypes = newPropTypes;
  1390. // Match production behavior more closely:
  1391. Object.defineProperty(lazyType, 'propTypes', {
  1392. enumerable: true
  1393. });
  1394. }
  1395. }
  1396. });
  1397. }
  1398. return lazyType;
  1399. }
  1400. function forwardRef(render) {
  1401. {
  1402. if (render != null && render.$$typeof === REACT_MEMO_TYPE) {
  1403. warningWithoutStack$1(false, 'forwardRef requires a render function but received a `memo` ' + 'component. Instead of forwardRef(memo(...)), use ' + 'memo(forwardRef(...)).');
  1404. } else if (typeof render !== 'function') {
  1405. warningWithoutStack$1(false, 'forwardRef requires a render function but was given %s.', render === null ? 'null' : typeof render);
  1406. } else {
  1407. !(
  1408. // Do not warn for 0 arguments because it could be due to usage of the 'arguments' object
  1409. render.length === 0 || render.length === 2) ? warningWithoutStack$1(false, 'forwardRef render functions accept exactly two parameters: props and ref. %s', render.length === 1 ? 'Did you forget to use the ref parameter?' : 'Any additional parameter will be undefined.') : void 0;
  1410. }
  1411. if (render != null) {
  1412. !(render.defaultProps == null && render.propTypes == null) ? warningWithoutStack$1(false, 'forwardRef render functions do not support propTypes or defaultProps. ' + 'Did you accidentally pass a React component?') : void 0;
  1413. }
  1414. }
  1415. return {
  1416. $$typeof: REACT_FORWARD_REF_TYPE,
  1417. render: render
  1418. };
  1419. }
  1420. function isValidElementType(type) {
  1421. return typeof type === 'string' || typeof type === 'function' ||
  1422. // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
  1423. 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);
  1424. }
  1425. function memo(type, compare) {
  1426. {
  1427. if (!isValidElementType(type)) {
  1428. warningWithoutStack$1(false, 'memo: The first argument must be a component. Instead ' + 'received: %s', type === null ? 'null' : typeof type);
  1429. }
  1430. }
  1431. return {
  1432. $$typeof: REACT_MEMO_TYPE,
  1433. type: type,
  1434. compare: compare === undefined ? null : compare
  1435. };
  1436. }
  1437. function resolveDispatcher() {
  1438. var dispatcher = ReactCurrentDispatcher.current;
  1439. (function () {
  1440. if (!(dispatcher !== null)) {
  1441. {
  1442. throw ReactError(Error('Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.'));
  1443. }
  1444. }
  1445. })();
  1446. return dispatcher;
  1447. }
  1448. function useContext(Context, unstable_observedBits) {
  1449. var dispatcher = resolveDispatcher();
  1450. {
  1451. !(unstable_observedBits === undefined) ? warning$1(false, 'useContext() second argument is reserved for future ' + 'use in React. Passing it is not supported. ' + 'You passed: %s.%s', unstable_observedBits, typeof unstable_observedBits === 'number' && Array.isArray(arguments[2]) ? '\n\nDid you call array.map(useContext)? ' + 'Calling Hooks inside a loop is not supported. ' + 'Learn more at https://fb.me/rules-of-hooks' : '') : void 0;
  1452. // TODO: add a more generic warning for invalid values.
  1453. if (Context._context !== undefined) {
  1454. var realContext = Context._context;
  1455. // Don't deduplicate because this legitimately causes bugs
  1456. // and nobody should be using this in existing code.
  1457. if (realContext.Consumer === Context) {
  1458. warning$1(false, 'Calling useContext(Context.Consumer) is not supported, may cause bugs, and will be ' + 'removed in a future major release. Did you mean to call useContext(Context) instead?');
  1459. } else if (realContext.Provider === Context) {
  1460. warning$1(false, 'Calling useContext(Context.Provider) is not supported. ' + 'Did you mean to call useContext(Context) instead?');
  1461. }
  1462. }
  1463. }
  1464. return dispatcher.useContext(Context, unstable_observedBits);
  1465. }
  1466. function useState(initialState) {
  1467. var dispatcher = resolveDispatcher();
  1468. return dispatcher.useState(initialState);
  1469. }
  1470. function useReducer(reducer, initialArg, init) {
  1471. var dispatcher = resolveDispatcher();
  1472. return dispatcher.useReducer(reducer, initialArg, init);
  1473. }
  1474. function useRef(initialValue) {
  1475. var dispatcher = resolveDispatcher();
  1476. return dispatcher.useRef(initialValue);
  1477. }
  1478. function useEffect(create, inputs) {
  1479. var dispatcher = resolveDispatcher();
  1480. return dispatcher.useEffect(create, inputs);
  1481. }
  1482. function useLayoutEffect(create, inputs) {
  1483. var dispatcher = resolveDispatcher();
  1484. return dispatcher.useLayoutEffect(create, inputs);
  1485. }
  1486. function useCallback(callback, inputs) {
  1487. var dispatcher = resolveDispatcher();
  1488. return dispatcher.useCallback(callback, inputs);
  1489. }
  1490. function useMemo(create, inputs) {
  1491. var dispatcher = resolveDispatcher();
  1492. return dispatcher.useMemo(create, inputs);
  1493. }
  1494. function useImperativeHandle(ref, create, inputs) {
  1495. var dispatcher = resolveDispatcher();
  1496. return dispatcher.useImperativeHandle(ref, create, inputs);
  1497. }
  1498. function useDebugValue(value, formatterFn) {
  1499. {
  1500. var dispatcher = resolveDispatcher();
  1501. return dispatcher.useDebugValue(value, formatterFn);
  1502. }
  1503. }
  1504. var emptyObject$1 = {};
  1505. function useResponder(responder, listenerProps) {
  1506. var dispatcher = resolveDispatcher();
  1507. {
  1508. if (responder == null || responder.$$typeof !== REACT_RESPONDER_TYPE) {
  1509. warning$1(false, 'useResponder: invalid first argument. Expected an event responder, but instead got %s', responder);
  1510. return;
  1511. }
  1512. }
  1513. return dispatcher.useResponder(responder, listenerProps || emptyObject$1);
  1514. }
  1515. // Within the scope of the callback, mark all updates as being allowed to suspend.
  1516. function withSuspenseConfig(scope, config) {
  1517. var previousConfig = ReactCurrentBatchConfig.suspense;
  1518. ReactCurrentBatchConfig.suspense = config === undefined ? null : config;
  1519. try {
  1520. scope();
  1521. } finally {
  1522. ReactCurrentBatchConfig.suspense = previousConfig;
  1523. }
  1524. }
  1525. /**
  1526. * Copyright (c) 2013-present, Facebook, Inc.
  1527. *
  1528. * This source code is licensed under the MIT license found in the
  1529. * LICENSE file in the root directory of this source tree.
  1530. */
  1531. var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
  1532. var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
  1533. /**
  1534. * Copyright (c) 2013-present, Facebook, Inc.
  1535. *
  1536. * This source code is licensed under the MIT license found in the
  1537. * LICENSE file in the root directory of this source tree.
  1538. */
  1539. var printWarning$1 = function() {};
  1540. {
  1541. var ReactPropTypesSecret = ReactPropTypesSecret_1;
  1542. var loggedTypeFailures = {};
  1543. printWarning$1 = function(text) {
  1544. var message = 'Warning: ' + text;
  1545. if (typeof console !== 'undefined') {
  1546. console.error(message);
  1547. }
  1548. try {
  1549. // --- Welcome to debugging React ---
  1550. // This error was thrown as a convenience so that you can use this stack
  1551. // to find the callsite that caused this warning to fire.
  1552. throw new Error(message);
  1553. } catch (x) {}
  1554. };
  1555. }
  1556. /**
  1557. * Assert that the values match with the type specs.
  1558. * Error messages are memorized and will only be shown once.
  1559. *
  1560. * @param {object} typeSpecs Map of name to a ReactPropType
  1561. * @param {object} values Runtime values that need to be type-checked
  1562. * @param {string} location e.g. "prop", "context", "child context"
  1563. * @param {string} componentName Name of the component for error messages.
  1564. * @param {?Function} getStack Returns the component stack.
  1565. * @private
  1566. */
  1567. function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
  1568. {
  1569. for (var typeSpecName in typeSpecs) {
  1570. if (typeSpecs.hasOwnProperty(typeSpecName)) {
  1571. var error;
  1572. // Prop type validation may throw. In case they do, we don't want to
  1573. // fail the render phase where it didn't fail before. So we log it.
  1574. // After these have been cleaned up, we'll let them throw.
  1575. try {
  1576. // This is intentionally an invariant that gets caught. It's the same
  1577. // behavior as without this statement except with a better message.
  1578. if (typeof typeSpecs[typeSpecName] !== 'function') {
  1579. var err = Error(
  1580. (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
  1581. 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
  1582. );
  1583. err.name = 'Invariant Violation';
  1584. throw err;
  1585. }
  1586. error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
  1587. } catch (ex) {
  1588. error = ex;
  1589. }
  1590. if (error && !(error instanceof Error)) {
  1591. printWarning$1(
  1592. (componentName || 'React class') + ': type specification of ' +
  1593. location + ' `' + typeSpecName + '` is invalid; the type checker ' +
  1594. 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
  1595. 'You may have forgotten to pass an argument to the type checker ' +
  1596. 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
  1597. 'shape all require an argument).'
  1598. );
  1599. }
  1600. if (error instanceof Error && !(error.message in loggedTypeFailures)) {
  1601. // Only monitor this failure once because there tends to be a lot of the
  1602. // same error.
  1603. loggedTypeFailures[error.message] = true;
  1604. var stack = getStack ? getStack() : '';
  1605. printWarning$1(
  1606. 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
  1607. );
  1608. }
  1609. }
  1610. }
  1611. }
  1612. }
  1613. var checkPropTypes_1 = checkPropTypes;
  1614. /**
  1615. * ReactElementValidator provides a wrapper around a element factory
  1616. * which validates the props passed to the element. This is intended to be
  1617. * used only in DEV and could be replaced by a static type checker for languages
  1618. * that support it.
  1619. */
  1620. var propTypesMisspellWarningShown = void 0;
  1621. {
  1622. propTypesMisspellWarningShown = false;
  1623. }
  1624. function getDeclarationErrorAddendum() {
  1625. if (ReactCurrentOwner.current) {
  1626. var name = getComponentName(ReactCurrentOwner.current.type);
  1627. if (name) {
  1628. return '\n\nCheck the render method of `' + name + '`.';
  1629. }
  1630. }
  1631. return '';
  1632. }
  1633. function getSourceInfoErrorAddendum(source) {
  1634. if (source !== undefined) {
  1635. var fileName = source.fileName.replace(/^.*[\\\/]/, '');
  1636. var lineNumber = source.lineNumber;
  1637. return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
  1638. }
  1639. return '';
  1640. }
  1641. function getSourceInfoErrorAddendumForProps(elementProps) {
  1642. if (elementProps !== null && elementProps !== undefined) {
  1643. return getSourceInfoErrorAddendum(elementProps.__source);
  1644. }
  1645. return '';
  1646. }
  1647. /**
  1648. * Warn if there's no key explicitly set on dynamic arrays of children or
  1649. * object keys are not valid. This allows us to keep track of children between
  1650. * updates.
  1651. */
  1652. var ownerHasKeyUseWarning = {};
  1653. function getCurrentComponentErrorInfo(parentType) {
  1654. var info = getDeclarationErrorAddendum();
  1655. if (!info) {
  1656. var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
  1657. if (parentName) {
  1658. info = '\n\nCheck the top-level render call using <' + parentName + '>.';
  1659. }
  1660. }
  1661. return info;
  1662. }
  1663. /**
  1664. * Warn if the element doesn't have an explicit key assigned to it.
  1665. * This element is in an array. The array could grow and shrink or be
  1666. * reordered. All children that haven't already been validated are required to
  1667. * have a "key" property assigned to it. Error statuses are cached so a warning
  1668. * will only be shown once.
  1669. *
  1670. * @internal
  1671. * @param {ReactElement} element Element that requires a key.
  1672. * @param {*} parentType element's parent's type.
  1673. */
  1674. function validateExplicitKey(element, parentType) {
  1675. if (!element._store || element._store.validated || element.key != null) {
  1676. return;
  1677. }
  1678. element._store.validated = true;
  1679. var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
  1680. if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
  1681. return;
  1682. }
  1683. ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
  1684. // Usually the current owner is the offender, but if it accepts children as a
  1685. // property, it may be the creator of the child that's responsible for
  1686. // assigning it a key.
  1687. var childOwner = '';
  1688. if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
  1689. // Give the component that originally created this child.
  1690. childOwner = ' It was passed a child from ' + getComponentName(element._owner.type) + '.';
  1691. }
  1692. setCurrentlyValidatingElement(element);
  1693. {
  1694. warning$1(false, 'Each child in a list should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.', currentComponentErrorInfo, childOwner);
  1695. }
  1696. setCurrentlyValidatingElement(null);
  1697. }
  1698. /**
  1699. * Ensure that every element either is passed in a static location, in an
  1700. * array with an explicit keys property defined, or in an object literal
  1701. * with valid key property.
  1702. *
  1703. * @internal
  1704. * @param {ReactNode} node Statically passed child of any type.
  1705. * @param {*} parentType node's parent's type.
  1706. */
  1707. function validateChildKeys(node, parentType) {
  1708. if (typeof node !== 'object') {
  1709. return;
  1710. }
  1711. if (Array.isArray(node)) {
  1712. for (var i = 0; i < node.length; i++) {
  1713. var child = node[i];
  1714. if (isValidElement(child)) {
  1715. validateExplicitKey(child, parentType);
  1716. }
  1717. }
  1718. } else if (isValidElement(node)) {
  1719. // This element was passed in a valid location.
  1720. if (node._store) {
  1721. node._store.validated = true;
  1722. }
  1723. } else if (node) {
  1724. var iteratorFn = getIteratorFn(node);
  1725. if (typeof iteratorFn === 'function') {
  1726. // Entry iterators used to provide implicit keys,
  1727. // but now we print a separate warning for them later.
  1728. if (iteratorFn !== node.entries) {
  1729. var iterator = iteratorFn.call(node);
  1730. var step = void 0;
  1731. while (!(step = iterator.next()).done) {
  1732. if (isValidElement(step.value)) {
  1733. validateExplicitKey(step.value, parentType);
  1734. }
  1735. }
  1736. }
  1737. }
  1738. }
  1739. }
  1740. /**
  1741. * Given an element, validate that its props follow the propTypes definition,
  1742. * provided by the type.
  1743. *
  1744. * @param {ReactElement} element
  1745. */
  1746. function validatePropTypes(element) {
  1747. var type = element.type;
  1748. if (type === null || type === undefined || typeof type === 'string') {
  1749. return;
  1750. }
  1751. var name = getComponentName(type);
  1752. var propTypes = void 0;
  1753. if (typeof type === 'function') {
  1754. propTypes = type.propTypes;
  1755. } else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE ||
  1756. // Note: Memo only checks outer props here.
  1757. // Inner props are checked in the reconciler.
  1758. type.$$typeof === REACT_MEMO_TYPE)) {
  1759. propTypes = type.propTypes;
  1760. } else {
  1761. return;
  1762. }
  1763. if (propTypes) {
  1764. setCurrentlyValidatingElement(element);
  1765. checkPropTypes_1(propTypes, element.props, 'prop', name, ReactDebugCurrentFrame.getStackAddendum);
  1766. setCurrentlyValidatingElement(null);
  1767. } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
  1768. propTypesMisspellWarningShown = true;
  1769. warningWithoutStack$1(false, 'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', name || 'Unknown');
  1770. }
  1771. if (typeof type.getDefaultProps === 'function') {
  1772. !type.getDefaultProps.isReactClassApproved ? warningWithoutStack$1(false, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : void 0;
  1773. }
  1774. }
  1775. /**
  1776. * Given a fragment, validate that it can only be provided with fragment props
  1777. * @param {ReactElement} fragment
  1778. */
  1779. function validateFragmentProps(fragment) {
  1780. setCurrentlyValidatingElement(fragment);
  1781. var keys = Object.keys(fragment.props);
  1782. for (var i = 0; i < keys.length; i++) {
  1783. var key = keys[i];
  1784. if (key !== 'children' && key !== 'key') {
  1785. warning$1(false, 'Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
  1786. break;
  1787. }
  1788. }
  1789. if (fragment.ref !== null) {
  1790. warning$1(false, 'Invalid attribute `ref` supplied to `React.Fragment`.');
  1791. }
  1792. setCurrentlyValidatingElement(null);
  1793. }
  1794. function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
  1795. var validType = isValidElementType(type);
  1796. // We warn in this case but don't throw. We expect the element creation to
  1797. // succeed and there will likely be errors in render.
  1798. if (!validType) {
  1799. var info = '';
  1800. if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
  1801. info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
  1802. }
  1803. var sourceInfo = getSourceInfoErrorAddendum(source);
  1804. if (sourceInfo) {
  1805. info += sourceInfo;
  1806. } else {
  1807. info += getDeclarationErrorAddendum();
  1808. }
  1809. var typeString = void 0;
  1810. if (type === null) {
  1811. typeString = 'null';
  1812. } else if (Array.isArray(type)) {
  1813. typeString = 'array';
  1814. } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
  1815. typeString = '<' + (getComponentName(type.type) || 'Unknown') + ' />';
  1816. info = ' Did you accidentally export a JSX literal instead of a component?';
  1817. } else {
  1818. typeString = typeof type;
  1819. }
  1820. warning$1(false, 'React.jsx: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
  1821. }
  1822. var element = jsxDEV(type, props, key, source, self);
  1823. // The result can be nullish if a mock or a custom function is used.
  1824. // TODO: Drop this when these are no longer allowed as the type argument.
  1825. if (element == null) {
  1826. return element;
  1827. }
  1828. // Skip key warning if the type isn't valid since our key validation logic
  1829. // doesn't expect a non-string/function type and can throw confusing errors.
  1830. // We don't want exception behavior to differ between dev and prod.
  1831. // (Rendering will throw with a helpful message and as soon as the type is
  1832. // fixed, the key warnings will appear.)
  1833. if (validType) {
  1834. var children = props.children;
  1835. if (children !== undefined) {
  1836. if (isStaticChildren) {
  1837. for (var i = 0; i < children.length; i++) {
  1838. validateChildKeys(children[i], type);
  1839. }
  1840. } else {
  1841. validateChildKeys(children, type);
  1842. }
  1843. }
  1844. }
  1845. if (props.key !== undefined) {
  1846. warning$1(false, 'React.jsx: Spreading a key to JSX is a deprecated pattern. ' + 'Explicitly pass a key after spreading props in your JSX call. ' + 'E.g. <ComponentName {...props} key={key} />');
  1847. }
  1848. if (type === REACT_FRAGMENT_TYPE) {
  1849. validateFragmentProps(element);
  1850. } else {
  1851. validatePropTypes(element);
  1852. }
  1853. return element;
  1854. }
  1855. // These two functions exist to still get child warnings in dev
  1856. // even with the prod transform. This means that jsxDEV is purely
  1857. // opt-in behavior for better messages but that we won't stop
  1858. // giving you warnings if you use production apis.
  1859. function jsxWithValidationStatic(type, props, key) {
  1860. return jsxWithValidation(type, props, key, true);
  1861. }
  1862. function jsxWithValidationDynamic(type, props, key) {
  1863. return jsxWithValidation(type, props, key, false);
  1864. }
  1865. function createElementWithValidation(type, props, children) {
  1866. var validType = isValidElementType(type);
  1867. // We warn in this case but don't throw. We expect the element creation to
  1868. // succeed and there will likely be errors in render.
  1869. if (!validType) {
  1870. var info = '';
  1871. if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
  1872. info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
  1873. }
  1874. var sourceInfo = getSourceInfoErrorAddendumForProps(props);
  1875. if (sourceInfo) {
  1876. info += sourceInfo;
  1877. } else {
  1878. info += getDeclarationErrorAddendum();
  1879. }
  1880. var typeString = void 0;
  1881. if (type === null) {
  1882. typeString = 'null';
  1883. } else if (Array.isArray(type)) {
  1884. typeString = 'array';
  1885. } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
  1886. typeString = '<' + (getComponentName(type.type) || 'Unknown') + ' />';
  1887. info = ' Did you accidentally export a JSX literal instead of a component?';
  1888. } else {
  1889. typeString = typeof type;
  1890. }
  1891. warning$1(false, 'React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
  1892. }
  1893. var element = createElement.apply(this, arguments);
  1894. // The result can be nullish if a mock or a custom function is used.
  1895. // TODO: Drop this when these are no longer allowed as the type argument.
  1896. if (element == null) {
  1897. return element;
  1898. }
  1899. // Skip key warning if the type isn't valid since our key validation logic
  1900. // doesn't expect a non-string/function type and can throw confusing errors.
  1901. // We don't want exception behavior to differ between dev and prod.
  1902. // (Rendering will throw with a helpful message and as soon as the type is
  1903. // fixed, the key warnings will appear.)
  1904. if (validType) {
  1905. for (var i = 2; i < arguments.length; i++) {
  1906. validateChildKeys(arguments[i], type);
  1907. }
  1908. }
  1909. if (type === REACT_FRAGMENT_TYPE) {
  1910. validateFragmentProps(element);
  1911. } else {
  1912. validatePropTypes(element);
  1913. }
  1914. return element;
  1915. }
  1916. function createFactoryWithValidation(type) {
  1917. var validatedFactory = createElementWithValidation.bind(null, type);
  1918. validatedFactory.type = type;
  1919. // Legacy hook: remove it
  1920. {
  1921. Object.defineProperty(validatedFactory, 'type', {
  1922. enumerable: false,
  1923. get: function () {
  1924. lowPriorityWarning$1(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.');
  1925. Object.defineProperty(this, 'type', {
  1926. value: type
  1927. });
  1928. return type;
  1929. }
  1930. });
  1931. }
  1932. return validatedFactory;
  1933. }
  1934. function cloneElementWithValidation(element, props, children) {
  1935. var newElement = cloneElement.apply(this, arguments);
  1936. for (var i = 2; i < arguments.length; i++) {
  1937. validateChildKeys(arguments[i], newElement.type);
  1938. }
  1939. validatePropTypes(newElement);
  1940. return newElement;
  1941. }
  1942. var enableSchedulerDebugging = false;
  1943. var enableIsInputPending = false;
  1944. var requestIdleCallbackBeforeFirstFrame = false;
  1945. var requestTimerEventBeforeFirstFrame = false;
  1946. var enableMessageLoopImplementation = false;
  1947. // The DOM Scheduler implementation is similar to requestIdleCallback. It
  1948. // works by scheduling a requestAnimationFrame, storing the time for the start
  1949. // of the frame, then scheduling a postMessage which gets scheduled after paint.
  1950. // Within the postMessage handler do as much work as possible until time + frame
  1951. // rate. By separating the idle call into a separate event tick we ensure that
  1952. // layout, paint and other browser work is counted against the available time.
  1953. // The frame rate is dynamically adjusted.
  1954. var requestHostCallback = void 0;
  1955. var requestHostTimeout = void 0;
  1956. var cancelHostTimeout = void 0;
  1957. var shouldYieldToHost = void 0;
  1958. var requestPaint = void 0;
  1959. var getCurrentTime = void 0;
  1960. var forceFrameRate = void 0;
  1961. if (
  1962. // If Scheduler runs in a non-DOM environment, it falls back to a naive
  1963. // implementation using setTimeout.
  1964. typeof window === 'undefined' ||
  1965. // Check if MessageChannel is supported, too.
  1966. typeof MessageChannel !== 'function') {
  1967. // If this accidentally gets imported in a non-browser environment, e.g. JavaScriptCore,
  1968. // fallback to a naive implementation.
  1969. var _callback = null;
  1970. var _timeoutID = null;
  1971. var _flushCallback = function () {
  1972. if (_callback !== null) {
  1973. try {
  1974. var currentTime = getCurrentTime();
  1975. var hasRemainingTime = true;
  1976. _callback(hasRemainingTime, currentTime);
  1977. _callback = null;
  1978. } catch (e) {
  1979. setTimeout(_flushCallback, 0);
  1980. throw e;
  1981. }
  1982. }
  1983. };
  1984. getCurrentTime = function () {
  1985. return Date.now();
  1986. };
  1987. requestHostCallback = function (cb) {
  1988. if (_callback !== null) {
  1989. // Protect against re-entrancy.
  1990. setTimeout(requestHostCallback, 0, cb);
  1991. } else {
  1992. _callback = cb;
  1993. setTimeout(_flushCallback, 0);
  1994. }
  1995. };
  1996. requestHostTimeout = function (cb, ms) {
  1997. _timeoutID = setTimeout(cb, ms);
  1998. };
  1999. cancelHostTimeout = function () {
  2000. clearTimeout(_timeoutID);
  2001. };
  2002. shouldYieldToHost = function () {
  2003. return false;
  2004. };
  2005. requestPaint = forceFrameRate = function () {};
  2006. } else {
  2007. // Capture local references to native APIs, in case a polyfill overrides them.
  2008. var performance = window.performance;
  2009. var _Date = window.Date;
  2010. var _setTimeout = window.setTimeout;
  2011. var _clearTimeout = window.clearTimeout;
  2012. var requestAnimationFrame = window.requestAnimationFrame;
  2013. var cancelAnimationFrame = window.cancelAnimationFrame;
  2014. var requestIdleCallback = window.requestIdleCallback;
  2015. if (typeof console !== 'undefined') {
  2016. // TODO: Remove fb.me link
  2017. if (typeof requestAnimationFrame !== 'function') {
  2018. console.error("This browser doesn't support requestAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');
  2019. }
  2020. if (typeof cancelAnimationFrame !== 'function') {
  2021. console.error("This browser doesn't support cancelAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');
  2022. }
  2023. }
  2024. var requestIdleCallbackBeforeFirstFrame$1 = requestIdleCallbackBeforeFirstFrame && typeof requestIdleCallback === 'function' && typeof cancelIdleCallback === 'function';
  2025. getCurrentTime = typeof performance === 'object' && typeof performance.now === 'function' ? function () {
  2026. return performance.now();
  2027. } : function () {
  2028. return _Date.now();
  2029. };
  2030. var isRAFLoopRunning = false;
  2031. var isMessageLoopRunning = false;
  2032. var scheduledHostCallback = null;
  2033. var rAFTimeoutID = -1;
  2034. var taskTimeoutID = -1;
  2035. var frameLength = enableMessageLoopImplementation ? // We won't attempt to align with the vsync. Instead we'll yield multiple
  2036. // times per frame, often enough to keep it responsive even at really
  2037. // high frame rates > 120.
  2038. 5 : // Use a heuristic to measure the frame rate and yield at the end of the
  2039. // frame. We start out assuming that we run at 30fps but then the
  2040. // heuristic tracking will adjust this value to a faster fps if we get
  2041. // more frequent animation frames.
  2042. 33.33;
  2043. var prevRAFTime = -1;
  2044. var prevRAFInterval = -1;
  2045. var frameDeadline = 0;
  2046. var fpsLocked = false;
  2047. // TODO: Make this configurable
  2048. // TODO: Adjust this based on priority?
  2049. var maxFrameLength = 300;
  2050. var needsPaint = false;
  2051. if (enableIsInputPending && navigator !== undefined && navigator.scheduling !== undefined && navigator.scheduling.isInputPending !== undefined) {
  2052. var scheduling = navigator.scheduling;
  2053. shouldYieldToHost = function () {
  2054. var currentTime = getCurrentTime();
  2055. if (currentTime >= frameDeadline) {
  2056. // There's no time left in the frame. We may want to yield control of
  2057. // the main thread, so the browser can perform high priority tasks. The
  2058. // main ones are painting and user input. If there's a pending paint or
  2059. // a pending input, then we should yield. But if there's neither, then
  2060. // we can yield less often while remaining responsive. We'll eventually
  2061. // yield regardless, since there could be a pending paint that wasn't
  2062. // accompanied by a call to `requestPaint`, or other main thread tasks
  2063. // like network events.
  2064. if (needsPaint || scheduling.isInputPending()) {
  2065. // There is either a pending paint or a pending input.
  2066. return true;
  2067. }
  2068. // There's no pending input. Only yield if we've reached the max
  2069. // frame length.
  2070. return currentTime >= frameDeadline + maxFrameLength;
  2071. } else {
  2072. // There's still time left in the frame.
  2073. return false;
  2074. }
  2075. };
  2076. requestPaint = function () {
  2077. needsPaint = true;
  2078. };
  2079. } else {
  2080. // `isInputPending` is not available. Since we have no way of knowing if
  2081. // there's pending input, always yield at the end of the frame.
  2082. shouldYieldToHost = function () {
  2083. return getCurrentTime() >= frameDeadline;
  2084. };
  2085. // Since we yield every frame regardless, `requestPaint` has no effect.
  2086. requestPaint = function () {};
  2087. }
  2088. forceFrameRate = function (fps) {
  2089. if (fps < 0 || fps > 125) {
  2090. console.error('forceFrameRate takes a positive int between 0 and 125, ' + 'forcing framerates higher than 125 fps is not unsupported');
  2091. return;
  2092. }
  2093. if (fps > 0) {
  2094. frameLength = Math.floor(1000 / fps);
  2095. fpsLocked = true;
  2096. } else {
  2097. // reset the framerate
  2098. frameLength = 33.33;
  2099. fpsLocked = false;
  2100. }
  2101. };
  2102. var performWorkUntilDeadline = function () {
  2103. if (enableMessageLoopImplementation) {
  2104. if (scheduledHostCallback !== null) {
  2105. var currentTime = getCurrentTime();
  2106. // Yield after `frameLength` ms, regardless of where we are in the vsync
  2107. // cycle. This means there's always time remaining at the beginning of
  2108. // the message event.
  2109. frameDeadline = currentTime + frameLength;
  2110. var hasTimeRemaining = true;
  2111. try {
  2112. var hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime);
  2113. if (!hasMoreWork) {
  2114. isMessageLoopRunning = false;
  2115. scheduledHostCallback = null;
  2116. } else {
  2117. // If there's more work, schedule the next message event at the end
  2118. // of the preceding one.
  2119. port.postMessage(null);
  2120. }
  2121. } catch (error) {
  2122. // If a scheduler task throws, exit the current browser task so the
  2123. // error can be observed.
  2124. port.postMessage(null);
  2125. throw error;
  2126. }
  2127. }
  2128. // Yielding to the browser will give it a chance to paint, so we can
  2129. // reset this.
  2130. needsPaint = false;
  2131. } else {
  2132. if (scheduledHostCallback !== null) {
  2133. var _currentTime = getCurrentTime();
  2134. var _hasTimeRemaining = frameDeadline - _currentTime > 0;
  2135. try {
  2136. var _hasMoreWork = scheduledHostCallback(_hasTimeRemaining, _currentTime);
  2137. if (!_hasMoreWork) {
  2138. scheduledHostCallback = null;
  2139. }
  2140. } catch (error) {
  2141. // If a scheduler task throws, exit the current browser task so the
  2142. // error can be observed, and post a new task as soon as possible
  2143. // so we can continue where we left off.
  2144. port.postMessage(null);
  2145. throw error;
  2146. }
  2147. }
  2148. // Yielding to the browser will give it a chance to paint, so we can
  2149. // reset this.
  2150. needsPaint = false;
  2151. }
  2152. };
  2153. var channel = new MessageChannel();
  2154. var port = channel.port2;
  2155. channel.port1.onmessage = performWorkUntilDeadline;
  2156. var onAnimationFrame = function (rAFTime) {
  2157. if (scheduledHostCallback === null) {
  2158. // No scheduled work. Exit.
  2159. prevRAFTime = -1;
  2160. prevRAFInterval = -1;
  2161. isRAFLoopRunning = false;
  2162. return;
  2163. }
  2164. // Eagerly schedule the next animation callback at the beginning of the
  2165. // frame. If the scheduler queue is not empty at the end of the frame, it
  2166. // will continue flushing inside that callback. If the queue *is* empty,
  2167. // then it will exit immediately. Posting the callback at the start of the
  2168. // frame ensures it's fired within the earliest possible frame. If we
  2169. // waited until the end of the frame to post the callback, we risk the
  2170. // browser skipping a frame and not firing the callback until the frame
  2171. // after that.
  2172. isRAFLoopRunning = true;
  2173. requestAnimationFrame(function (nextRAFTime) {
  2174. _clearTimeout(rAFTimeoutID);
  2175. onAnimationFrame(nextRAFTime);
  2176. });
  2177. // requestAnimationFrame is throttled when the tab is backgrounded. We
  2178. // don't want to stop working entirely. So we'll fallback to a timeout loop.
  2179. // TODO: Need a better heuristic for backgrounded work.
  2180. var onTimeout = function () {
  2181. frameDeadline = getCurrentTime() + frameLength / 2;
  2182. performWorkUntilDeadline();
  2183. rAFTimeoutID = _setTimeout(onTimeout, frameLength * 3);
  2184. };
  2185. rAFTimeoutID = _setTimeout(onTimeout, frameLength * 3);
  2186. if (prevRAFTime !== -1 &&
  2187. // Make sure this rAF time is different from the previous one. This check
  2188. // could fail if two rAFs fire in the same frame.
  2189. rAFTime - prevRAFTime > 0.1) {
  2190. var rAFInterval = rAFTime - prevRAFTime;
  2191. if (!fpsLocked && prevRAFInterval !== -1) {
  2192. // We've observed two consecutive frame intervals. We'll use this to
  2193. // dynamically adjust the frame rate.
  2194. //
  2195. // If one frame goes long, then the next one can be short to catch up.
  2196. // If two frames are short in a row, then that's an indication that we
  2197. // actually have a higher frame rate than what we're currently
  2198. // optimizing. For example, if we're running on 120hz display or 90hz VR
  2199. // display. Take the max of the two in case one of them was an anomaly
  2200. // due to missed frame deadlines.
  2201. if (rAFInterval < frameLength && prevRAFInterval < frameLength) {
  2202. frameLength = rAFInterval < prevRAFInterval ? prevRAFInterval : rAFInterval;
  2203. if (frameLength < 8.33) {
  2204. // Defensive coding. We don't support higher frame rates than 120hz.
  2205. // If the calculated frame length gets lower than 8, it is probably
  2206. // a bug.
  2207. frameLength = 8.33;
  2208. }
  2209. }
  2210. }
  2211. prevRAFInterval = rAFInterval;
  2212. }
  2213. prevRAFTime = rAFTime;
  2214. frameDeadline = rAFTime + frameLength;
  2215. // We use the postMessage trick to defer idle work until after the repaint.
  2216. port.postMessage(null);
  2217. };
  2218. requestHostCallback = function (callback) {
  2219. scheduledHostCallback = callback;
  2220. if (enableMessageLoopImplementation) {
  2221. if (!isMessageLoopRunning) {
  2222. isMessageLoopRunning = true;
  2223. port.postMessage(null);
  2224. }
  2225. } else {
  2226. if (!isRAFLoopRunning) {
  2227. // Start a rAF loop.
  2228. isRAFLoopRunning = true;
  2229. requestAnimationFrame(function (rAFTime) {
  2230. if (requestIdleCallbackBeforeFirstFrame$1) {
  2231. cancelIdleCallback(idleCallbackID);
  2232. }
  2233. if (requestTimerEventBeforeFirstFrame) {
  2234. _clearTimeout(idleTimeoutID);
  2235. }
  2236. onAnimationFrame(rAFTime);
  2237. });
  2238. // If we just missed the last vsync, the next rAF might not happen for
  2239. // another frame. To claim as much idle time as possible, post a
  2240. // callback with `requestIdleCallback`, which should fire if there's
  2241. // idle time left in the frame.
  2242. //
  2243. // This should only be an issue for the first rAF in the loop;
  2244. // subsequent rAFs are scheduled at the beginning of the
  2245. // preceding frame.
  2246. var idleCallbackID = void 0;
  2247. if (requestIdleCallbackBeforeFirstFrame$1) {
  2248. idleCallbackID = requestIdleCallback(function onIdleCallbackBeforeFirstFrame() {
  2249. if (requestTimerEventBeforeFirstFrame) {
  2250. _clearTimeout(idleTimeoutID);
  2251. }
  2252. frameDeadline = getCurrentTime() + frameLength;
  2253. performWorkUntilDeadline();
  2254. });
  2255. }
  2256. // Alternate strategy to address the same problem. Scheduler a timer
  2257. // with no delay. If this fires before the rAF, that likely indicates
  2258. // that there's idle time before the next vsync. This isn't always the
  2259. // case, but we'll be aggressive and assume it is, as a trade off to
  2260. // prevent idle periods.
  2261. var idleTimeoutID = void 0;
  2262. if (requestTimerEventBeforeFirstFrame) {
  2263. idleTimeoutID = _setTimeout(function onTimerEventBeforeFirstFrame() {
  2264. if (requestIdleCallbackBeforeFirstFrame$1) {
  2265. cancelIdleCallback(idleCallbackID);
  2266. }
  2267. frameDeadline = getCurrentTime() + frameLength;
  2268. performWorkUntilDeadline();
  2269. }, 0);
  2270. }
  2271. }
  2272. }
  2273. };
  2274. requestHostTimeout = function (callback, ms) {
  2275. taskTimeoutID = _setTimeout(function () {
  2276. callback(getCurrentTime());
  2277. }, ms);
  2278. };
  2279. cancelHostTimeout = function () {
  2280. _clearTimeout(taskTimeoutID);
  2281. taskTimeoutID = -1;
  2282. };
  2283. }
  2284. /* eslint-disable no-var */
  2285. // TODO: Use symbols?
  2286. var ImmediatePriority = 1;
  2287. var UserBlockingPriority = 2;
  2288. var NormalPriority = 3;
  2289. var LowPriority = 4;
  2290. var IdlePriority = 5;
  2291. // Max 31 bit integer. The max integer size in V8 for 32-bit systems.
  2292. // Math.pow(2, 30) - 1
  2293. // 0b111111111111111111111111111111
  2294. var maxSigned31BitInt = 1073741823;
  2295. // Times out immediately
  2296. var IMMEDIATE_PRIORITY_TIMEOUT = -1;
  2297. // Eventually times out
  2298. var USER_BLOCKING_PRIORITY = 250;
  2299. var NORMAL_PRIORITY_TIMEOUT = 5000;
  2300. var LOW_PRIORITY_TIMEOUT = 10000;
  2301. // Never times out
  2302. var IDLE_PRIORITY = maxSigned31BitInt;
  2303. // Tasks are stored as a circular, doubly linked list.
  2304. var firstTask = null;
  2305. var firstDelayedTask = null;
  2306. // Pausing the scheduler is useful for debugging.
  2307. var isSchedulerPaused = false;
  2308. var currentTask = null;
  2309. var currentPriorityLevel = NormalPriority;
  2310. // This is set while performing work, to prevent re-entrancy.
  2311. var isPerformingWork = false;
  2312. var isHostCallbackScheduled = false;
  2313. var isHostTimeoutScheduled = false;
  2314. function scheduler_flushTaskAtPriority_Immediate(callback, didTimeout) {
  2315. return callback(didTimeout);
  2316. }
  2317. function scheduler_flushTaskAtPriority_UserBlocking(callback, didTimeout) {
  2318. return callback(didTimeout);
  2319. }
  2320. function scheduler_flushTaskAtPriority_Normal(callback, didTimeout) {
  2321. return callback(didTimeout);
  2322. }
  2323. function scheduler_flushTaskAtPriority_Low(callback, didTimeout) {
  2324. return callback(didTimeout);
  2325. }
  2326. function scheduler_flushTaskAtPriority_Idle(callback, didTimeout) {
  2327. return callback(didTimeout);
  2328. }
  2329. function flushTask(task, currentTime) {
  2330. // Remove the task from the list before calling the callback. That way the
  2331. // list is in a consistent state even if the callback throws.
  2332. var next = task.next;
  2333. if (next === task) {
  2334. // This is the only scheduled task. Clear the list.
  2335. firstTask = null;
  2336. } else {
  2337. // Remove the task from its position in the list.
  2338. if (task === firstTask) {
  2339. firstTask = next;
  2340. }
  2341. var previous = task.previous;
  2342. previous.next = next;
  2343. next.previous = previous;
  2344. }
  2345. task.next = task.previous = null;
  2346. // Now it's safe to execute the task.
  2347. var callback = task.callback;
  2348. var previousPriorityLevel = currentPriorityLevel;
  2349. var previousTask = currentTask;
  2350. currentPriorityLevel = task.priorityLevel;
  2351. currentTask = task;
  2352. var continuationCallback;
  2353. try {
  2354. var didUserCallbackTimeout = task.expirationTime <= currentTime;
  2355. // Add an extra function to the callstack. Profiling tools can use this
  2356. // to infer the priority of work that appears higher in the stack.
  2357. switch (currentPriorityLevel) {
  2358. case ImmediatePriority:
  2359. continuationCallback = scheduler_flushTaskAtPriority_Immediate(callback, didUserCallbackTimeout);
  2360. break;
  2361. case UserBlockingPriority:
  2362. continuationCallback = scheduler_flushTaskAtPriority_UserBlocking(callback, didUserCallbackTimeout);
  2363. break;
  2364. case NormalPriority:
  2365. continuationCallback = scheduler_flushTaskAtPriority_Normal(callback, didUserCallbackTimeout);
  2366. break;
  2367. case LowPriority:
  2368. continuationCallback = scheduler_flushTaskAtPriority_Low(callback, didUserCallbackTimeout);
  2369. break;
  2370. case IdlePriority:
  2371. continuationCallback = scheduler_flushTaskAtPriority_Idle(callback, didUserCallbackTimeout);
  2372. break;
  2373. }
  2374. } catch (error) {
  2375. throw error;
  2376. } finally {
  2377. currentPriorityLevel = previousPriorityLevel;
  2378. currentTask = previousTask;
  2379. }
  2380. // A callback may return a continuation. The continuation should be scheduled
  2381. // with the same priority and expiration as the just-finished callback.
  2382. if (typeof continuationCallback === 'function') {
  2383. var expirationTime = task.expirationTime;
  2384. var continuationTask = task;
  2385. continuationTask.callback = continuationCallback;
  2386. // Insert the new callback into the list, sorted by its timeout. This is
  2387. // almost the same as the code in `scheduleCallback`, except the callback
  2388. // is inserted into the list *before* callbacks of equal timeout instead
  2389. // of after.
  2390. if (firstTask === null) {
  2391. // This is the first callback in the list.
  2392. firstTask = continuationTask.next = continuationTask.previous = continuationTask;
  2393. } else {
  2394. var nextAfterContinuation = null;
  2395. var t = firstTask;
  2396. do {
  2397. if (expirationTime <= t.expirationTime) {
  2398. // This task times out at or after the continuation. We will insert
  2399. // the continuation *before* this task.
  2400. nextAfterContinuation = t;
  2401. break;
  2402. }
  2403. t = t.next;
  2404. } while (t !== firstTask);
  2405. if (nextAfterContinuation === null) {
  2406. // No equal or lower priority task was found, which means the new task
  2407. // is the lowest priority task in the list.
  2408. nextAfterContinuation = firstTask;
  2409. } else if (nextAfterContinuation === firstTask) {
  2410. // The new task is the highest priority task in the list.
  2411. firstTask = continuationTask;
  2412. }
  2413. var _previous = nextAfterContinuation.previous;
  2414. _previous.next = nextAfterContinuation.previous = continuationTask;
  2415. continuationTask.next = nextAfterContinuation;
  2416. continuationTask.previous = _previous;
  2417. }
  2418. }
  2419. }
  2420. function advanceTimers(currentTime) {
  2421. // Check for tasks that are no longer delayed and add them to the queue.
  2422. if (firstDelayedTask !== null && firstDelayedTask.startTime <= currentTime) {
  2423. do {
  2424. var task = firstDelayedTask;
  2425. var next = task.next;
  2426. if (task === next) {
  2427. firstDelayedTask = null;
  2428. } else {
  2429. firstDelayedTask = next;
  2430. var previous = task.previous;
  2431. previous.next = next;
  2432. next.previous = previous;
  2433. }
  2434. task.next = task.previous = null;
  2435. insertScheduledTask(task, task.expirationTime);
  2436. } while (firstDelayedTask !== null && firstDelayedTask.startTime <= currentTime);
  2437. }
  2438. }
  2439. function handleTimeout(currentTime) {
  2440. isHostTimeoutScheduled = false;
  2441. advanceTimers(currentTime);
  2442. if (!isHostCallbackScheduled) {
  2443. if (firstTask !== null) {
  2444. isHostCallbackScheduled = true;
  2445. requestHostCallback(flushWork);
  2446. } else if (firstDelayedTask !== null) {
  2447. requestHostTimeout(handleTimeout, firstDelayedTask.startTime - currentTime);
  2448. }
  2449. }
  2450. }
  2451. function flushWork(hasTimeRemaining, initialTime) {
  2452. // Exit right away if we're currently paused
  2453. if (enableSchedulerDebugging && isSchedulerPaused) {
  2454. return;
  2455. }
  2456. // We'll need a host callback the next time work is scheduled.
  2457. isHostCallbackScheduled = false;
  2458. if (isHostTimeoutScheduled) {
  2459. // We scheduled a timeout but it's no longer needed. Cancel it.
  2460. isHostTimeoutScheduled = false;
  2461. cancelHostTimeout();
  2462. }
  2463. var currentTime = initialTime;
  2464. advanceTimers(currentTime);
  2465. isPerformingWork = true;
  2466. try {
  2467. if (!hasTimeRemaining) {
  2468. // Flush all the expired callbacks without yielding.
  2469. // TODO: Split flushWork into two separate functions instead of using
  2470. // a boolean argument?
  2471. while (firstTask !== null && firstTask.expirationTime <= currentTime && !(enableSchedulerDebugging && isSchedulerPaused)) {
  2472. flushTask(firstTask, currentTime);
  2473. currentTime = getCurrentTime();
  2474. advanceTimers(currentTime);
  2475. }
  2476. } else {
  2477. // Keep flushing callbacks until we run out of time in the frame.
  2478. if (firstTask !== null) {
  2479. do {
  2480. flushTask(firstTask, currentTime);
  2481. currentTime = getCurrentTime();
  2482. advanceTimers(currentTime);
  2483. } while (firstTask !== null && !shouldYieldToHost() && !(enableSchedulerDebugging && isSchedulerPaused));
  2484. }
  2485. }
  2486. // Return whether there's additional work
  2487. if (firstTask !== null) {
  2488. return true;
  2489. } else {
  2490. if (firstDelayedTask !== null) {
  2491. requestHostTimeout(handleTimeout, firstDelayedTask.startTime - currentTime);
  2492. }
  2493. return false;
  2494. }
  2495. } finally {
  2496. isPerformingWork = false;
  2497. }
  2498. }
  2499. function unstable_runWithPriority(priorityLevel, eventHandler) {
  2500. switch (priorityLevel) {
  2501. case ImmediatePriority:
  2502. case UserBlockingPriority:
  2503. case NormalPriority:
  2504. case LowPriority:
  2505. case IdlePriority:
  2506. break;
  2507. default:
  2508. priorityLevel = NormalPriority;
  2509. }
  2510. var previousPriorityLevel = currentPriorityLevel;
  2511. currentPriorityLevel = priorityLevel;
  2512. try {
  2513. return eventHandler();
  2514. } finally {
  2515. currentPriorityLevel = previousPriorityLevel;
  2516. }
  2517. }
  2518. function unstable_next(eventHandler) {
  2519. var priorityLevel;
  2520. switch (currentPriorityLevel) {
  2521. case ImmediatePriority:
  2522. case UserBlockingPriority:
  2523. case NormalPriority:
  2524. // Shift down to normal priority
  2525. priorityLevel = NormalPriority;
  2526. break;
  2527. default:
  2528. // Anything lower than normal priority should remain at the current level.
  2529. priorityLevel = currentPriorityLevel;
  2530. break;
  2531. }
  2532. var previousPriorityLevel = currentPriorityLevel;
  2533. currentPriorityLevel = priorityLevel;
  2534. try {
  2535. return eventHandler();
  2536. } finally {
  2537. currentPriorityLevel = previousPriorityLevel;
  2538. }
  2539. }
  2540. function unstable_wrapCallback(callback) {
  2541. var parentPriorityLevel = currentPriorityLevel;
  2542. return function () {
  2543. // This is a fork of runWithPriority, inlined for performance.
  2544. var previousPriorityLevel = currentPriorityLevel;
  2545. currentPriorityLevel = parentPriorityLevel;
  2546. try {
  2547. return callback.apply(this, arguments);
  2548. } finally {
  2549. currentPriorityLevel = previousPriorityLevel;
  2550. }
  2551. };
  2552. }
  2553. function timeoutForPriorityLevel(priorityLevel) {
  2554. switch (priorityLevel) {
  2555. case ImmediatePriority:
  2556. return IMMEDIATE_PRIORITY_TIMEOUT;
  2557. case UserBlockingPriority:
  2558. return USER_BLOCKING_PRIORITY;
  2559. case IdlePriority:
  2560. return IDLE_PRIORITY;
  2561. case LowPriority:
  2562. return LOW_PRIORITY_TIMEOUT;
  2563. case NormalPriority:
  2564. default:
  2565. return NORMAL_PRIORITY_TIMEOUT;
  2566. }
  2567. }
  2568. function unstable_scheduleCallback(priorityLevel, callback, options) {
  2569. var currentTime = getCurrentTime();
  2570. var startTime;
  2571. var timeout;
  2572. if (typeof options === 'object' && options !== null) {
  2573. var delay = options.delay;
  2574. if (typeof delay === 'number' && delay > 0) {
  2575. startTime = currentTime + delay;
  2576. } else {
  2577. startTime = currentTime;
  2578. }
  2579. timeout = typeof options.timeout === 'number' ? options.timeout : timeoutForPriorityLevel(priorityLevel);
  2580. } else {
  2581. timeout = timeoutForPriorityLevel(priorityLevel);
  2582. startTime = currentTime;
  2583. }
  2584. var expirationTime = startTime + timeout;
  2585. var newTask = {
  2586. callback: callback,
  2587. priorityLevel: priorityLevel,
  2588. startTime: startTime,
  2589. expirationTime: expirationTime,
  2590. next: null,
  2591. previous: null
  2592. };
  2593. if (startTime > currentTime) {
  2594. // This is a delayed task.
  2595. insertDelayedTask(newTask, startTime);
  2596. if (firstTask === null && firstDelayedTask === newTask) {
  2597. // All tasks are delayed, and this is the task with the earliest delay.
  2598. if (isHostTimeoutScheduled) {
  2599. // Cancel an existing timeout.
  2600. cancelHostTimeout();
  2601. } else {
  2602. isHostTimeoutScheduled = true;
  2603. }
  2604. // Schedule a timeout.
  2605. requestHostTimeout(handleTimeout, startTime - currentTime);
  2606. }
  2607. } else {
  2608. insertScheduledTask(newTask, expirationTime);
  2609. // Schedule a host callback, if needed. If we're already performing work,
  2610. // wait until the next time we yield.
  2611. if (!isHostCallbackScheduled && !isPerformingWork) {
  2612. isHostCallbackScheduled = true;
  2613. requestHostCallback(flushWork);
  2614. }
  2615. }
  2616. return newTask;
  2617. }
  2618. function insertScheduledTask(newTask, expirationTime) {
  2619. // Insert the new task into the list, ordered first by its timeout, then by
  2620. // insertion. So the new task is inserted after any other task the
  2621. // same timeout
  2622. if (firstTask === null) {
  2623. // This is the first task in the list.
  2624. firstTask = newTask.next = newTask.previous = newTask;
  2625. } else {
  2626. var next = null;
  2627. var task = firstTask;
  2628. do {
  2629. if (expirationTime < task.expirationTime) {
  2630. // The new task times out before this one.
  2631. next = task;
  2632. break;
  2633. }
  2634. task = task.next;
  2635. } while (task !== firstTask);
  2636. if (next === null) {
  2637. // No task with a later timeout was found, which means the new task has
  2638. // the latest timeout in the list.
  2639. next = firstTask;
  2640. } else if (next === firstTask) {
  2641. // The new task has the earliest expiration in the entire list.
  2642. firstTask = newTask;
  2643. }
  2644. var previous = next.previous;
  2645. previous.next = next.previous = newTask;
  2646. newTask.next = next;
  2647. newTask.previous = previous;
  2648. }
  2649. }
  2650. function insertDelayedTask(newTask, startTime) {
  2651. // Insert the new task into the list, ordered by its start time.
  2652. if (firstDelayedTask === null) {
  2653. // This is the first task in the list.
  2654. firstDelayedTask = newTask.next = newTask.previous = newTask;
  2655. } else {
  2656. var next = null;
  2657. var task = firstDelayedTask;
  2658. do {
  2659. if (startTime < task.startTime) {
  2660. // The new task times out before this one.
  2661. next = task;
  2662. break;
  2663. }
  2664. task = task.next;
  2665. } while (task !== firstDelayedTask);
  2666. if (next === null) {
  2667. // No task with a later timeout was found, which means the new task has
  2668. // the latest timeout in the list.
  2669. next = firstDelayedTask;
  2670. } else if (next === firstDelayedTask) {
  2671. // The new task has the earliest expiration in the entire list.
  2672. firstDelayedTask = newTask;
  2673. }
  2674. var previous = next.previous;
  2675. previous.next = next.previous = newTask;
  2676. newTask.next = next;
  2677. newTask.previous = previous;
  2678. }
  2679. }
  2680. function unstable_pauseExecution() {
  2681. isSchedulerPaused = true;
  2682. }
  2683. function unstable_continueExecution() {
  2684. isSchedulerPaused = false;
  2685. if (!isHostCallbackScheduled && !isPerformingWork) {
  2686. isHostCallbackScheduled = true;
  2687. requestHostCallback(flushWork);
  2688. }
  2689. }
  2690. function unstable_getFirstCallbackNode() {
  2691. return firstTask;
  2692. }
  2693. function unstable_cancelCallback(task) {
  2694. var next = task.next;
  2695. if (next === null) {
  2696. // Already cancelled.
  2697. return;
  2698. }
  2699. if (task === next) {
  2700. if (task === firstTask) {
  2701. firstTask = null;
  2702. } else if (task === firstDelayedTask) {
  2703. firstDelayedTask = null;
  2704. }
  2705. } else {
  2706. if (task === firstTask) {
  2707. firstTask = next;
  2708. } else if (task === firstDelayedTask) {
  2709. firstDelayedTask = next;
  2710. }
  2711. var previous = task.previous;
  2712. previous.next = next;
  2713. next.previous = previous;
  2714. }
  2715. task.next = task.previous = null;
  2716. }
  2717. function unstable_getCurrentPriorityLevel() {
  2718. return currentPriorityLevel;
  2719. }
  2720. function unstable_shouldYield() {
  2721. var currentTime = getCurrentTime();
  2722. advanceTimers(currentTime);
  2723. return currentTask !== null && firstTask !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost();
  2724. }
  2725. var unstable_requestPaint = requestPaint;
  2726. var Scheduler = Object.freeze({
  2727. unstable_ImmediatePriority: ImmediatePriority,
  2728. unstable_UserBlockingPriority: UserBlockingPriority,
  2729. unstable_NormalPriority: NormalPriority,
  2730. unstable_IdlePriority: IdlePriority,
  2731. unstable_LowPriority: LowPriority,
  2732. unstable_runWithPriority: unstable_runWithPriority,
  2733. unstable_next: unstable_next,
  2734. unstable_scheduleCallback: unstable_scheduleCallback,
  2735. unstable_cancelCallback: unstable_cancelCallback,
  2736. unstable_wrapCallback: unstable_wrapCallback,
  2737. unstable_getCurrentPriorityLevel: unstable_getCurrentPriorityLevel,
  2738. unstable_shouldYield: unstable_shouldYield,
  2739. unstable_requestPaint: unstable_requestPaint,
  2740. unstable_continueExecution: unstable_continueExecution,
  2741. unstable_pauseExecution: unstable_pauseExecution,
  2742. unstable_getFirstCallbackNode: unstable_getFirstCallbackNode,
  2743. get unstable_now () { return getCurrentTime; },
  2744. get unstable_forceFrameRate () { return forceFrameRate; }
  2745. });
  2746. // Helps identify side effects in begin-phase lifecycle hooks and setState reducers:
  2747. // In some cases, StrictMode should also double-render lifecycles.
  2748. // This can be confusing for tests though,
  2749. // And it can be bad for performance in production.
  2750. // This feature flag can be used to control the behavior:
  2751. // To preserve the "Pause on caught exceptions" behavior of the debugger, we
  2752. // replay the begin phase of a failed component inside invokeGuardedCallback.
  2753. // Warn about deprecated, async-unsafe lifecycles; relates to RFC #6:
  2754. // Gather advanced timing metrics for Profiler subtrees.
  2755. // Trace which interactions trigger each commit.
  2756. var enableSchedulerTracing = true;
  2757. // Only used in www builds.
  2758. // TODO: true? Here it might just be false.
  2759. // Only used in www builds.
  2760. // Only used in www builds.
  2761. // Disable javascript: URL strings in href for XSS protection.
  2762. // React Fire: prevent the value and checked attributes from syncing
  2763. // with their related DOM properties
  2764. // These APIs will no longer be "unstable" in the upcoming 16.7 release,
  2765. // Control this behavior with a flag to support 16.6 minor releases in the meanwhile.
  2766. // See https://github.com/react-native-community/discussions-and-proposals/issues/72 for more information
  2767. // This is a flag so we can fix warnings in RN core before turning it on
  2768. // Experimental React Flare event system and event components support.
  2769. var enableFlareAPI = false;
  2770. // Experimental Host Component support.
  2771. var enableFundamentalAPI = false;
  2772. // New API for JSX transforms to target - https://github.com/reactjs/rfcs/pull/107
  2773. var enableJSXTransformAPI = false;
  2774. // We will enforce mocking scheduler with scheduler/unstable_mock at some point. (v17?)
  2775. // Till then, we warn about the missing mock, but still fallback to a sync mode compatible version
  2776. // Temporary flag to revert the fix in #15650
  2777. // For tests, we flush suspense fallbacks in an act scope;
  2778. // *except* in some of our own tests, where we test incremental loading states.
  2779. // Changes priority of some events like mousemove to user-blocking priority,
  2780. // but without making them discrete. The flag exists in case it causes
  2781. // starvation problems.
  2782. // Add a callback property to suspense to notify which promises are currently
  2783. // in the update queue. This allows reporting and tracing of what is causing
  2784. // the user to see a loading state.
  2785. // Part of the simplification of React.createElement so we can eventually move
  2786. // from React.createElement to React.jsx
  2787. // https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md
  2788. var DEFAULT_THREAD_ID = 0;
  2789. // Counters used to generate unique IDs.
  2790. var interactionIDCounter = 0;
  2791. var threadIDCounter = 0;
  2792. // Set of currently traced interactions.
  2793. // Interactions "stack"–
  2794. // Meaning that newly traced interactions are appended to the previously active set.
  2795. // When an interaction goes out of scope, the previous set (if any) is restored.
  2796. var interactionsRef = null;
  2797. // Listener(s) to notify when interactions begin and end.
  2798. var subscriberRef = null;
  2799. if (enableSchedulerTracing) {
  2800. interactionsRef = {
  2801. current: new Set()
  2802. };
  2803. subscriberRef = {
  2804. current: null
  2805. };
  2806. }
  2807. function unstable_clear(callback) {
  2808. if (!enableSchedulerTracing) {
  2809. return callback();
  2810. }
  2811. var prevInteractions = interactionsRef.current;
  2812. interactionsRef.current = new Set();
  2813. try {
  2814. return callback();
  2815. } finally {
  2816. interactionsRef.current = prevInteractions;
  2817. }
  2818. }
  2819. function unstable_getCurrent() {
  2820. if (!enableSchedulerTracing) {
  2821. return null;
  2822. } else {
  2823. return interactionsRef.current;
  2824. }
  2825. }
  2826. function unstable_getThreadID() {
  2827. return ++threadIDCounter;
  2828. }
  2829. function unstable_trace(name, timestamp, callback) {
  2830. var threadID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_THREAD_ID;
  2831. if (!enableSchedulerTracing) {
  2832. return callback();
  2833. }
  2834. var interaction = {
  2835. __count: 1,
  2836. id: interactionIDCounter++,
  2837. name: name,
  2838. timestamp: timestamp
  2839. };
  2840. var prevInteractions = interactionsRef.current;
  2841. // Traced interactions should stack/accumulate.
  2842. // To do that, clone the current interactions.
  2843. // The previous set will be restored upon completion.
  2844. var interactions = new Set(prevInteractions);
  2845. interactions.add(interaction);
  2846. interactionsRef.current = interactions;
  2847. var subscriber = subscriberRef.current;
  2848. var returnValue = void 0;
  2849. try {
  2850. if (subscriber !== null) {
  2851. subscriber.onInteractionTraced(interaction);
  2852. }
  2853. } finally {
  2854. try {
  2855. if (subscriber !== null) {
  2856. subscriber.onWorkStarted(interactions, threadID);
  2857. }
  2858. } finally {
  2859. try {
  2860. returnValue = callback();
  2861. } finally {
  2862. interactionsRef.current = prevInteractions;
  2863. try {
  2864. if (subscriber !== null) {
  2865. subscriber.onWorkStopped(interactions, threadID);
  2866. }
  2867. } finally {
  2868. interaction.__count--;
  2869. // If no async work was scheduled for this interaction,
  2870. // Notify subscribers that it's completed.
  2871. if (subscriber !== null && interaction.__count === 0) {
  2872. subscriber.onInteractionScheduledWorkCompleted(interaction);
  2873. }
  2874. }
  2875. }
  2876. }
  2877. }
  2878. return returnValue;
  2879. }
  2880. function unstable_wrap(callback) {
  2881. var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID;
  2882. if (!enableSchedulerTracing) {
  2883. return callback;
  2884. }
  2885. var wrappedInteractions = interactionsRef.current;
  2886. var subscriber = subscriberRef.current;
  2887. if (subscriber !== null) {
  2888. subscriber.onWorkScheduled(wrappedInteractions, threadID);
  2889. }
  2890. // Update the pending async work count for the current interactions.
  2891. // Update after calling subscribers in case of error.
  2892. wrappedInteractions.forEach(function (interaction) {
  2893. interaction.__count++;
  2894. });
  2895. var hasRun = false;
  2896. function wrapped() {
  2897. var prevInteractions = interactionsRef.current;
  2898. interactionsRef.current = wrappedInteractions;
  2899. subscriber = subscriberRef.current;
  2900. try {
  2901. var returnValue = void 0;
  2902. try {
  2903. if (subscriber !== null) {
  2904. subscriber.onWorkStarted(wrappedInteractions, threadID);
  2905. }
  2906. } finally {
  2907. try {
  2908. returnValue = callback.apply(undefined, arguments);
  2909. } finally {
  2910. interactionsRef.current = prevInteractions;
  2911. if (subscriber !== null) {
  2912. subscriber.onWorkStopped(wrappedInteractions, threadID);
  2913. }
  2914. }
  2915. }
  2916. return returnValue;
  2917. } finally {
  2918. if (!hasRun) {
  2919. // We only expect a wrapped function to be executed once,
  2920. // But in the event that it's executed more than once–
  2921. // Only decrement the outstanding interaction counts once.
  2922. hasRun = true;
  2923. // Update pending async counts for all wrapped interactions.
  2924. // If this was the last scheduled async work for any of them,
  2925. // Mark them as completed.
  2926. wrappedInteractions.forEach(function (interaction) {
  2927. interaction.__count--;
  2928. if (subscriber !== null && interaction.__count === 0) {
  2929. subscriber.onInteractionScheduledWorkCompleted(interaction);
  2930. }
  2931. });
  2932. }
  2933. }
  2934. }
  2935. wrapped.cancel = function cancel() {
  2936. subscriber = subscriberRef.current;
  2937. try {
  2938. if (subscriber !== null) {
  2939. subscriber.onWorkCanceled(wrappedInteractions, threadID);
  2940. }
  2941. } finally {
  2942. // Update pending async counts for all wrapped interactions.
  2943. // If this was the last scheduled async work for any of them,
  2944. // Mark them as completed.
  2945. wrappedInteractions.forEach(function (interaction) {
  2946. interaction.__count--;
  2947. if (subscriber && interaction.__count === 0) {
  2948. subscriber.onInteractionScheduledWorkCompleted(interaction);
  2949. }
  2950. });
  2951. }
  2952. };
  2953. return wrapped;
  2954. }
  2955. var subscribers = null;
  2956. if (enableSchedulerTracing) {
  2957. subscribers = new Set();
  2958. }
  2959. function unstable_subscribe(subscriber) {
  2960. if (enableSchedulerTracing) {
  2961. subscribers.add(subscriber);
  2962. if (subscribers.size === 1) {
  2963. subscriberRef.current = {
  2964. onInteractionScheduledWorkCompleted: onInteractionScheduledWorkCompleted,
  2965. onInteractionTraced: onInteractionTraced,
  2966. onWorkCanceled: onWorkCanceled,
  2967. onWorkScheduled: onWorkScheduled,
  2968. onWorkStarted: onWorkStarted,
  2969. onWorkStopped: onWorkStopped
  2970. };
  2971. }
  2972. }
  2973. }
  2974. function unstable_unsubscribe(subscriber) {
  2975. if (enableSchedulerTracing) {
  2976. subscribers.delete(subscriber);
  2977. if (subscribers.size === 0) {
  2978. subscriberRef.current = null;
  2979. }
  2980. }
  2981. }
  2982. function onInteractionTraced(interaction) {
  2983. var didCatchError = false;
  2984. var caughtError = null;
  2985. subscribers.forEach(function (subscriber) {
  2986. try {
  2987. subscriber.onInteractionTraced(interaction);
  2988. } catch (error) {
  2989. if (!didCatchError) {
  2990. didCatchError = true;
  2991. caughtError = error;
  2992. }
  2993. }
  2994. });
  2995. if (didCatchError) {
  2996. throw caughtError;
  2997. }
  2998. }
  2999. function onInteractionScheduledWorkCompleted(interaction) {
  3000. var didCatchError = false;
  3001. var caughtError = null;
  3002. subscribers.forEach(function (subscriber) {
  3003. try {
  3004. subscriber.onInteractionScheduledWorkCompleted(interaction);
  3005. } catch (error) {
  3006. if (!didCatchError) {
  3007. didCatchError = true;
  3008. caughtError = error;
  3009. }
  3010. }
  3011. });
  3012. if (didCatchError) {
  3013. throw caughtError;
  3014. }
  3015. }
  3016. function onWorkScheduled(interactions, threadID) {
  3017. var didCatchError = false;
  3018. var caughtError = null;
  3019. subscribers.forEach(function (subscriber) {
  3020. try {
  3021. subscriber.onWorkScheduled(interactions, threadID);
  3022. } catch (error) {
  3023. if (!didCatchError) {
  3024. didCatchError = true;
  3025. caughtError = error;
  3026. }
  3027. }
  3028. });
  3029. if (didCatchError) {
  3030. throw caughtError;
  3031. }
  3032. }
  3033. function onWorkStarted(interactions, threadID) {
  3034. var didCatchError = false;
  3035. var caughtError = null;
  3036. subscribers.forEach(function (subscriber) {
  3037. try {
  3038. subscriber.onWorkStarted(interactions, threadID);
  3039. } catch (error) {
  3040. if (!didCatchError) {
  3041. didCatchError = true;
  3042. caughtError = error;
  3043. }
  3044. }
  3045. });
  3046. if (didCatchError) {
  3047. throw caughtError;
  3048. }
  3049. }
  3050. function onWorkStopped(interactions, threadID) {
  3051. var didCatchError = false;
  3052. var caughtError = null;
  3053. subscribers.forEach(function (subscriber) {
  3054. try {
  3055. subscriber.onWorkStopped(interactions, threadID);
  3056. } catch (error) {
  3057. if (!didCatchError) {
  3058. didCatchError = true;
  3059. caughtError = error;
  3060. }
  3061. }
  3062. });
  3063. if (didCatchError) {
  3064. throw caughtError;
  3065. }
  3066. }
  3067. function onWorkCanceled(interactions, threadID) {
  3068. var didCatchError = false;
  3069. var caughtError = null;
  3070. subscribers.forEach(function (subscriber) {
  3071. try {
  3072. subscriber.onWorkCanceled(interactions, threadID);
  3073. } catch (error) {
  3074. if (!didCatchError) {
  3075. didCatchError = true;
  3076. caughtError = error;
  3077. }
  3078. }
  3079. });
  3080. if (didCatchError) {
  3081. throw caughtError;
  3082. }
  3083. }
  3084. var SchedulerTracing = Object.freeze({
  3085. get __interactionsRef () { return interactionsRef; },
  3086. get __subscriberRef () { return subscriberRef; },
  3087. unstable_clear: unstable_clear,
  3088. unstable_getCurrent: unstable_getCurrent,
  3089. unstable_getThreadID: unstable_getThreadID,
  3090. unstable_trace: unstable_trace,
  3091. unstable_wrap: unstable_wrap,
  3092. unstable_subscribe: unstable_subscribe,
  3093. unstable_unsubscribe: unstable_unsubscribe
  3094. });
  3095. var ReactSharedInternals$2 = {
  3096. ReactCurrentDispatcher: ReactCurrentDispatcher,
  3097. ReactCurrentOwner: ReactCurrentOwner,
  3098. IsSomeRendererActing: IsSomeRendererActing,
  3099. // Used by renderers to avoid bundling object-assign twice in UMD bundles:
  3100. assign: objectAssign
  3101. };
  3102. {
  3103. objectAssign(ReactSharedInternals$2, {
  3104. // These should not be included in production.
  3105. ReactDebugCurrentFrame: ReactDebugCurrentFrame,
  3106. // Shim for React DOM 16.0.0 which still destructured (but not used) this.
  3107. // TODO: remove in React 17.0.
  3108. ReactComponentTreeHook: {}
  3109. });
  3110. }
  3111. // Re-export the schedule API(s) for UMD bundles.
  3112. // This avoids introducing a dependency on a new UMD global in a minor update,
  3113. // Since that would be a breaking change (e.g. for all existing CodeSandboxes).
  3114. // This re-export is only required for UMD bundles;
  3115. // CJS bundles use the shared NPM package.
  3116. objectAssign(ReactSharedInternals$2, {
  3117. Scheduler: Scheduler,
  3118. SchedulerTracing: SchedulerTracing
  3119. });
  3120. var hasBadMapPolyfill = void 0;
  3121. {
  3122. hasBadMapPolyfill = false;
  3123. try {
  3124. var frozenObject = Object.freeze({});
  3125. var testMap = new Map([[frozenObject, null]]);
  3126. var testSet = new Set([frozenObject]);
  3127. // This is necessary for Rollup to not consider these unused.
  3128. // https://github.com/rollup/rollup/issues/1771
  3129. // TODO: we can remove these if Rollup fixes the bug.
  3130. testMap.set(0, 0);
  3131. testSet.add(0);
  3132. } catch (e) {
  3133. // TODO: Consider warning about bad polyfills
  3134. hasBadMapPolyfill = true;
  3135. }
  3136. }
  3137. function createFundamentalComponent(impl) {
  3138. // We use responder as a Map key later on. When we have a bad
  3139. // polyfill, then we can't use it as a key as the polyfill tries
  3140. // to add a property to the object.
  3141. if (true && !hasBadMapPolyfill) {
  3142. Object.freeze(impl);
  3143. }
  3144. var fundamantalComponent = {
  3145. $$typeof: REACT_FUNDAMENTAL_TYPE,
  3146. impl: impl
  3147. };
  3148. {
  3149. Object.freeze(fundamantalComponent);
  3150. }
  3151. return fundamantalComponent;
  3152. }
  3153. function createEventResponder(displayName, responderConfig) {
  3154. var getInitialState = responderConfig.getInitialState,
  3155. onEvent = responderConfig.onEvent,
  3156. onMount = responderConfig.onMount,
  3157. onUnmount = responderConfig.onUnmount,
  3158. onOwnershipChange = responderConfig.onOwnershipChange,
  3159. onRootEvent = responderConfig.onRootEvent,
  3160. rootEventTypes = responderConfig.rootEventTypes,
  3161. targetEventTypes = responderConfig.targetEventTypes;
  3162. var eventResponder = {
  3163. $$typeof: REACT_RESPONDER_TYPE,
  3164. displayName: displayName,
  3165. getInitialState: getInitialState || null,
  3166. onEvent: onEvent || null,
  3167. onMount: onMount || null,
  3168. onOwnershipChange: onOwnershipChange || null,
  3169. onRootEvent: onRootEvent || null,
  3170. onUnmount: onUnmount || null,
  3171. rootEventTypes: rootEventTypes || null,
  3172. targetEventTypes: targetEventTypes || null
  3173. };
  3174. // We use responder as a Map key later on. When we have a bad
  3175. // polyfill, then we can't use it as a key as the polyfill tries
  3176. // to add a property to the object.
  3177. if (true && !hasBadMapPolyfill) {
  3178. Object.freeze(eventResponder);
  3179. }
  3180. return eventResponder;
  3181. }
  3182. var React = {
  3183. Children: {
  3184. map: mapChildren,
  3185. forEach: forEachChildren,
  3186. count: countChildren,
  3187. toArray: toArray,
  3188. only: onlyChild
  3189. },
  3190. createRef: createRef,
  3191. Component: Component,
  3192. PureComponent: PureComponent,
  3193. createContext: createContext,
  3194. forwardRef: forwardRef,
  3195. lazy: lazy,
  3196. memo: memo,
  3197. useCallback: useCallback,
  3198. useContext: useContext,
  3199. useEffect: useEffect,
  3200. useImperativeHandle: useImperativeHandle,
  3201. useDebugValue: useDebugValue,
  3202. useLayoutEffect: useLayoutEffect,
  3203. useMemo: useMemo,
  3204. useReducer: useReducer,
  3205. useRef: useRef,
  3206. useState: useState,
  3207. Fragment: REACT_FRAGMENT_TYPE,
  3208. Profiler: REACT_PROFILER_TYPE,
  3209. StrictMode: REACT_STRICT_MODE_TYPE,
  3210. Suspense: REACT_SUSPENSE_TYPE,
  3211. unstable_SuspenseList: REACT_SUSPENSE_LIST_TYPE,
  3212. createElement: createElementWithValidation,
  3213. cloneElement: cloneElementWithValidation,
  3214. createFactory: createFactoryWithValidation,
  3215. isValidElement: isValidElement,
  3216. version: ReactVersion,
  3217. unstable_withSuspenseConfig: withSuspenseConfig,
  3218. __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactSharedInternals$2
  3219. };
  3220. if (enableFlareAPI) {
  3221. React.unstable_useResponder = useResponder;
  3222. React.unstable_createResponder = createEventResponder;
  3223. }
  3224. if (enableFundamentalAPI) {
  3225. React.unstable_createFundamental = createFundamentalComponent;
  3226. }
  3227. // Note: some APIs are added with feature flags.
  3228. // Make sure that stable builds for open source
  3229. // don't modify the React object to avoid deopts.
  3230. // Also let's not expose their names in stable builds.
  3231. if (enableJSXTransformAPI) {
  3232. {
  3233. React.jsxDEV = jsxWithValidation;
  3234. React.jsx = jsxWithValidationDynamic;
  3235. React.jsxs = jsxWithValidationStatic;
  3236. }
  3237. }
  3238. var React$2 = Object.freeze({
  3239. default: React
  3240. });
  3241. var React$3 = ( React$2 && React ) || React$2;
  3242. // TODO: decide on the top-level export form.
  3243. // This is hacky but makes it work with both Rollup and Jest.
  3244. var react = React$3.default || React$3;
  3245. return react;
  3246. })));