Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

1562 řádky
46 KiB

  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
  4. (factory((global.Recompose = {}),global.React));
  5. }(this, (function (exports,React) { 'use strict';
  6. var React__default = 'default' in React ? React['default'] : React;
  7. var setStatic = function setStatic(key, value) {
  8. return function (BaseComponent) {
  9. /* eslint-disable no-param-reassign */
  10. BaseComponent[key] = value;
  11. /* eslint-enable no-param-reassign */
  12. return BaseComponent;
  13. };
  14. };
  15. var setDisplayName = function setDisplayName(displayName) {
  16. return setStatic('displayName', displayName);
  17. };
  18. var getDisplayName = function getDisplayName(Component) {
  19. if (typeof Component === 'string') {
  20. return Component;
  21. }
  22. if (!Component) {
  23. return undefined;
  24. }
  25. return Component.displayName || Component.name || 'Component';
  26. };
  27. var wrapDisplayName = function wrapDisplayName(BaseComponent, hocName) {
  28. return hocName + "(" + getDisplayName(BaseComponent) + ")";
  29. };
  30. var mapProps = function mapProps(propsMapper) {
  31. return function (BaseComponent) {
  32. var factory = React.createFactory(BaseComponent);
  33. var MapProps = function MapProps(props) {
  34. return factory(propsMapper(props));
  35. };
  36. {
  37. return setDisplayName(wrapDisplayName(BaseComponent, 'mapProps'))(MapProps);
  38. }
  39. return MapProps;
  40. };
  41. };
  42. function _extends() {
  43. _extends = Object.assign || function (target) {
  44. for (var i = 1; i < arguments.length; i++) {
  45. var source = arguments[i];
  46. for (var key in source) {
  47. if (Object.prototype.hasOwnProperty.call(source, key)) {
  48. target[key] = source[key];
  49. }
  50. }
  51. }
  52. return target;
  53. };
  54. return _extends.apply(this, arguments);
  55. }
  56. var withProps = function withProps(input) {
  57. var hoc = mapProps(function (props) {
  58. return _extends({}, props, typeof input === 'function' ? input(props) : input);
  59. });
  60. {
  61. return function (BaseComponent) {
  62. return setDisplayName(wrapDisplayName(BaseComponent, 'withProps'))(hoc(BaseComponent));
  63. };
  64. }
  65. return hoc;
  66. };
  67. function _inheritsLoose(subClass, superClass) {
  68. subClass.prototype = Object.create(superClass.prototype);
  69. subClass.prototype.constructor = subClass;
  70. subClass.__proto__ = superClass;
  71. }
  72. /**
  73. * Copyright (c) 2013-present, Facebook, Inc.
  74. *
  75. * This source code is licensed under the MIT license found in the
  76. * LICENSE file in the root directory of this source tree.
  77. */
  78. function componentWillMount() {
  79. // Call this.constructor.gDSFP to support sub-classes.
  80. var state = this.constructor.getDerivedStateFromProps(this.props, this.state);
  81. if (state !== null && state !== undefined) {
  82. this.setState(state);
  83. }
  84. }
  85. function componentWillReceiveProps(nextProps) {
  86. // Call this.constructor.gDSFP to support sub-classes.
  87. var state = this.constructor.getDerivedStateFromProps(nextProps, this.state);
  88. if (state !== null && state !== undefined) {
  89. this.setState(state);
  90. }
  91. }
  92. function componentWillUpdate(nextProps, nextState) {
  93. try {
  94. var prevProps = this.props;
  95. var prevState = this.state;
  96. this.props = nextProps;
  97. this.state = nextState;
  98. this.__reactInternalSnapshotFlag = true;
  99. this.__reactInternalSnapshot = this.getSnapshotBeforeUpdate(
  100. prevProps,
  101. prevState
  102. );
  103. } finally {
  104. this.props = prevProps;
  105. this.state = prevState;
  106. }
  107. }
  108. // React may warn about cWM/cWRP/cWU methods being deprecated.
  109. // Add a flag to suppress these warnings for this special case.
  110. componentWillMount.__suppressDeprecationWarning = true;
  111. componentWillReceiveProps.__suppressDeprecationWarning = true;
  112. componentWillUpdate.__suppressDeprecationWarning = true;
  113. function polyfill(Component) {
  114. var prototype = Component.prototype;
  115. if (!prototype || !prototype.isReactComponent) {
  116. throw new Error('Can only polyfill class components');
  117. }
  118. if (
  119. typeof Component.getDerivedStateFromProps !== 'function' &&
  120. typeof prototype.getSnapshotBeforeUpdate !== 'function'
  121. ) {
  122. return Component;
  123. }
  124. // If new component APIs are defined, "unsafe" lifecycles won't be called.
  125. // Error if any of these lifecycles are present,
  126. // Because they would work differently between older and newer (16.3+) versions of React.
  127. var foundWillMountName = null;
  128. var foundWillReceivePropsName = null;
  129. var foundWillUpdateName = null;
  130. if (typeof prototype.componentWillMount === 'function') {
  131. foundWillMountName = 'componentWillMount';
  132. } else if (typeof prototype.UNSAFE_componentWillMount === 'function') {
  133. foundWillMountName = 'UNSAFE_componentWillMount';
  134. }
  135. if (typeof prototype.componentWillReceiveProps === 'function') {
  136. foundWillReceivePropsName = 'componentWillReceiveProps';
  137. } else if (typeof prototype.UNSAFE_componentWillReceiveProps === 'function') {
  138. foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
  139. }
  140. if (typeof prototype.componentWillUpdate === 'function') {
  141. foundWillUpdateName = 'componentWillUpdate';
  142. } else if (typeof prototype.UNSAFE_componentWillUpdate === 'function') {
  143. foundWillUpdateName = 'UNSAFE_componentWillUpdate';
  144. }
  145. if (
  146. foundWillMountName !== null ||
  147. foundWillReceivePropsName !== null ||
  148. foundWillUpdateName !== null
  149. ) {
  150. var componentName = Component.displayName || Component.name;
  151. var newApiName =
  152. typeof Component.getDerivedStateFromProps === 'function'
  153. ? 'getDerivedStateFromProps()'
  154. : 'getSnapshotBeforeUpdate()';
  155. throw Error(
  156. 'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
  157. componentName +
  158. ' uses ' +
  159. newApiName +
  160. ' but also contains the following legacy lifecycles:' +
  161. (foundWillMountName !== null ? '\n ' + foundWillMountName : '') +
  162. (foundWillReceivePropsName !== null
  163. ? '\n ' + foundWillReceivePropsName
  164. : '') +
  165. (foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '') +
  166. '\n\nThe above lifecycles should be removed. Learn more about this warning here:\n' +
  167. 'https://fb.me/react-async-component-lifecycle-hooks'
  168. );
  169. }
  170. // React <= 16.2 does not support static getDerivedStateFromProps.
  171. // As a workaround, use cWM and cWRP to invoke the new static lifecycle.
  172. // Newer versions of React will ignore these lifecycles if gDSFP exists.
  173. if (typeof Component.getDerivedStateFromProps === 'function') {
  174. prototype.componentWillMount = componentWillMount;
  175. prototype.componentWillReceiveProps = componentWillReceiveProps;
  176. }
  177. // React <= 16.2 does not support getSnapshotBeforeUpdate.
  178. // As a workaround, use cWU to invoke the new lifecycle.
  179. // Newer versions of React will ignore that lifecycle if gSBU exists.
  180. if (typeof prototype.getSnapshotBeforeUpdate === 'function') {
  181. if (typeof prototype.componentDidUpdate !== 'function') {
  182. throw new Error(
  183. 'Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype'
  184. );
  185. }
  186. prototype.componentWillUpdate = componentWillUpdate;
  187. var componentDidUpdate = prototype.componentDidUpdate;
  188. prototype.componentDidUpdate = function componentDidUpdatePolyfill(
  189. prevProps,
  190. prevState,
  191. maybeSnapshot
  192. ) {
  193. // 16.3+ will not execute our will-update method;
  194. // It will pass a snapshot value to did-update though.
  195. // Older versions will require our polyfilled will-update value.
  196. // We need to handle both cases, but can't just check for the presence of "maybeSnapshot",
  197. // Because for <= 15.x versions this might be a "prevContext" object.
  198. // We also can't just check "__reactInternalSnapshot",
  199. // Because get-snapshot might return a falsy value.
  200. // So check for the explicit __reactInternalSnapshotFlag flag to determine behavior.
  201. var snapshot = this.__reactInternalSnapshotFlag
  202. ? this.__reactInternalSnapshot
  203. : maybeSnapshot;
  204. componentDidUpdate.call(this, prevProps, prevState, snapshot);
  205. };
  206. }
  207. return Component;
  208. }
  209. var pick = function pick(obj, keys) {
  210. var result = {};
  211. for (var i = 0; i < keys.length; i++) {
  212. var key = keys[i];
  213. if (obj.hasOwnProperty(key)) {
  214. result[key] = obj[key];
  215. }
  216. }
  217. return result;
  218. };
  219. /**
  220. * Copyright (c) 2013-present, Facebook, Inc.
  221. * All rights reserved.
  222. *
  223. * This source code is licensed under the BSD-style license found in the
  224. * LICENSE file in the root directory of this source tree. An additional grant
  225. * of patent rights can be found in the PATENTS file in the same directory.
  226. *
  227. * @typechecks
  228. *
  229. */
  230. var hasOwnProperty = Object.prototype.hasOwnProperty;
  231. /**
  232. * inlined Object.is polyfill to avoid requiring consumers ship their own
  233. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  234. */
  235. function is(x, y) {
  236. // SameValue algorithm
  237. if (x === y) {
  238. // Steps 1-5, 7-10
  239. // Steps 6.b-6.e: +0 != -0
  240. // Added the nonzero y check to make Flow happy, but it is redundant
  241. return x !== 0 || y !== 0 || 1 / x === 1 / y;
  242. } else {
  243. // Step 6.a: NaN == NaN
  244. return x !== x && y !== y;
  245. }
  246. }
  247. /**
  248. * Performs equality by iterating through keys on an object and returning false
  249. * when any key has values which are not strictly equal between the arguments.
  250. * Returns true when the values of all keys are strictly equal.
  251. */
  252. function shallowEqual(objA, objB) {
  253. if (is(objA, objB)) {
  254. return true;
  255. }
  256. if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
  257. return false;
  258. }
  259. var keysA = Object.keys(objA);
  260. var keysB = Object.keys(objB);
  261. if (keysA.length !== keysB.length) {
  262. return false;
  263. }
  264. // Test for A's keys different from B.
  265. for (var i = 0; i < keysA.length; i++) {
  266. if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
  267. return false;
  268. }
  269. }
  270. return true;
  271. }
  272. var shallowEqual_1 = shallowEqual;
  273. var withPropsOnChange = function withPropsOnChange(shouldMapOrKeys, propsMapper) {
  274. return function (BaseComponent) {
  275. var factory = React.createFactory(BaseComponent);
  276. var shouldMap = typeof shouldMapOrKeys === 'function' ? shouldMapOrKeys : function (props, nextProps) {
  277. return !shallowEqual_1(pick(props, shouldMapOrKeys), pick(nextProps, shouldMapOrKeys));
  278. };
  279. var WithPropsOnChange =
  280. /*#__PURE__*/
  281. function (_Component) {
  282. _inheritsLoose(WithPropsOnChange, _Component);
  283. function WithPropsOnChange() {
  284. var _this;
  285. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  286. args[_key] = arguments[_key];
  287. }
  288. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  289. _this.state = {
  290. computedProps: propsMapper(_this.props),
  291. prevProps: _this.props
  292. };
  293. return _this;
  294. }
  295. WithPropsOnChange.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
  296. if (shouldMap(prevState.prevProps, nextProps)) {
  297. return {
  298. computedProps: propsMapper(nextProps),
  299. prevProps: nextProps
  300. };
  301. }
  302. return {
  303. prevProps: nextProps
  304. };
  305. };
  306. var _proto = WithPropsOnChange.prototype;
  307. _proto.render = function render() {
  308. return factory(_extends({}, this.props, this.state.computedProps));
  309. };
  310. return WithPropsOnChange;
  311. }(React.Component);
  312. polyfill(WithPropsOnChange);
  313. {
  314. return setDisplayName(wrapDisplayName(BaseComponent, 'withPropsOnChange'))(WithPropsOnChange);
  315. }
  316. return WithPropsOnChange;
  317. };
  318. };
  319. var mapValues = function mapValues(obj, func) {
  320. var result = {};
  321. /* eslint-disable no-restricted-syntax */
  322. for (var key in obj) {
  323. if (obj.hasOwnProperty(key)) {
  324. result[key] = func(obj[key], key);
  325. }
  326. }
  327. /* eslint-enable no-restricted-syntax */
  328. return result;
  329. };
  330. var withHandlers = function withHandlers(handlers) {
  331. return function (BaseComponent) {
  332. var factory = React.createFactory(BaseComponent);
  333. var WithHandlers =
  334. /*#__PURE__*/
  335. function (_Component) {
  336. _inheritsLoose(WithHandlers, _Component);
  337. function WithHandlers() {
  338. var _this;
  339. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  340. _args[_key] = arguments[_key];
  341. }
  342. _this = _Component.call.apply(_Component, [this].concat(_args)) || this;
  343. _this.handlers = mapValues(typeof handlers === 'function' ? handlers(_this.props) : handlers, function (createHandler) {
  344. return function () {
  345. var handler = createHandler(_this.props);
  346. if (typeof handler !== 'function') {
  347. console.error( // eslint-disable-line no-console
  348. 'withHandlers(): Expected a map of higher-order functions. ' + 'Refer to the docs for more info.');
  349. }
  350. return handler.apply(void 0, arguments);
  351. };
  352. });
  353. return _this;
  354. }
  355. var _proto = WithHandlers.prototype;
  356. _proto.render = function render() {
  357. return factory(_extends({}, this.props, this.handlers));
  358. };
  359. return WithHandlers;
  360. }(React.Component);
  361. {
  362. return setDisplayName(wrapDisplayName(BaseComponent, 'withHandlers'))(WithHandlers);
  363. }
  364. return WithHandlers;
  365. };
  366. };
  367. var defaultProps = function defaultProps(props) {
  368. return function (BaseComponent) {
  369. var factory = React.createFactory(BaseComponent);
  370. var DefaultProps = function DefaultProps(ownerProps) {
  371. return factory(ownerProps);
  372. };
  373. DefaultProps.defaultProps = props;
  374. {
  375. return setDisplayName(wrapDisplayName(BaseComponent, 'defaultProps'))(DefaultProps);
  376. }
  377. return DefaultProps;
  378. };
  379. };
  380. var omit = function omit(obj, keys) {
  381. var rest = _extends({}, obj);
  382. for (var i = 0; i < keys.length; i++) {
  383. var key = keys[i];
  384. if (rest.hasOwnProperty(key)) {
  385. delete rest[key];
  386. }
  387. }
  388. return rest;
  389. };
  390. var renameProp = function renameProp(oldName, newName) {
  391. var hoc = mapProps(function (props) {
  392. var _extends2;
  393. return _extends({}, omit(props, [oldName]), (_extends2 = {}, _extends2[newName] = props[oldName], _extends2));
  394. });
  395. {
  396. return function (BaseComponent) {
  397. return setDisplayName(wrapDisplayName(BaseComponent, 'renameProp'))(hoc(BaseComponent));
  398. };
  399. }
  400. return hoc;
  401. };
  402. var keys = Object.keys;
  403. var mapKeys = function mapKeys(obj, func) {
  404. return keys(obj).reduce(function (result, key) {
  405. var val = obj[key];
  406. /* eslint-disable no-param-reassign */
  407. result[func(val, key)] = val;
  408. /* eslint-enable no-param-reassign */
  409. return result;
  410. }, {});
  411. };
  412. var renameProps = function renameProps(nameMap) {
  413. var hoc = mapProps(function (props) {
  414. return _extends({}, omit(props, keys(nameMap)), mapKeys(pick(props, keys(nameMap)), function (_, oldName) {
  415. return nameMap[oldName];
  416. }));
  417. });
  418. {
  419. return function (BaseComponent) {
  420. return setDisplayName(wrapDisplayName(BaseComponent, 'renameProps'))(hoc(BaseComponent));
  421. };
  422. }
  423. return hoc;
  424. };
  425. var flattenProp = function flattenProp(propName) {
  426. return function (BaseComponent) {
  427. var factory = React.createFactory(BaseComponent);
  428. var FlattenProp = function FlattenProp(props) {
  429. return factory(_extends({}, props, props[propName]));
  430. };
  431. {
  432. return setDisplayName(wrapDisplayName(BaseComponent, 'flattenProp'))(FlattenProp);
  433. }
  434. return FlattenProp;
  435. };
  436. };
  437. var withState = function withState(stateName, stateUpdaterName, initialState) {
  438. return function (BaseComponent) {
  439. var factory = React.createFactory(BaseComponent);
  440. var WithState =
  441. /*#__PURE__*/
  442. function (_Component) {
  443. _inheritsLoose(WithState, _Component);
  444. function WithState() {
  445. var _this;
  446. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  447. args[_key] = arguments[_key];
  448. }
  449. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  450. _this.state = {
  451. stateValue: typeof initialState === 'function' ? initialState(_this.props) : initialState
  452. };
  453. _this.updateStateValue = function (updateFn, callback) {
  454. return _this.setState(function (_ref) {
  455. var stateValue = _ref.stateValue;
  456. return {
  457. stateValue: typeof updateFn === 'function' ? updateFn(stateValue) : updateFn
  458. };
  459. }, callback);
  460. };
  461. return _this;
  462. }
  463. var _proto = WithState.prototype;
  464. _proto.render = function render() {
  465. var _extends2;
  466. return factory(_extends({}, this.props, (_extends2 = {}, _extends2[stateName] = this.state.stateValue, _extends2[stateUpdaterName] = this.updateStateValue, _extends2)));
  467. };
  468. return WithState;
  469. }(React.Component);
  470. {
  471. return setDisplayName(wrapDisplayName(BaseComponent, 'withState'))(WithState);
  472. }
  473. return WithState;
  474. };
  475. };
  476. var withStateHandlers = function withStateHandlers(initialState, stateUpdaters) {
  477. return function (BaseComponent) {
  478. var factory = React.createFactory(BaseComponent);
  479. var WithStateHandlers =
  480. /*#__PURE__*/
  481. function (_Component) {
  482. _inheritsLoose(WithStateHandlers, _Component);
  483. function WithStateHandlers() {
  484. var _this;
  485. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  486. _args[_key] = arguments[_key];
  487. }
  488. _this = _Component.call.apply(_Component, [this].concat(_args)) || this;
  489. _this.state = typeof initialState === 'function' ? initialState(_this.props) : initialState;
  490. _this.stateUpdaters = mapValues(stateUpdaters, function (handler) {
  491. return function (mayBeEvent) {
  492. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  493. args[_key2 - 1] = arguments[_key2];
  494. }
  495. // Having that functional form of setState can be called async
  496. // we need to persist SyntheticEvent
  497. if (mayBeEvent && typeof mayBeEvent.persist === 'function') {
  498. mayBeEvent.persist();
  499. }
  500. _this.setState(function (state, props) {
  501. return handler(state, props).apply(void 0, [mayBeEvent].concat(args));
  502. });
  503. };
  504. });
  505. return _this;
  506. }
  507. var _proto = WithStateHandlers.prototype;
  508. _proto.render = function render() {
  509. return factory(_extends({}, this.props, this.state, this.stateUpdaters));
  510. };
  511. return WithStateHandlers;
  512. }(React.Component);
  513. {
  514. return setDisplayName(wrapDisplayName(BaseComponent, 'withStateHandlers'))(WithStateHandlers);
  515. }
  516. return WithStateHandlers;
  517. };
  518. };
  519. var noop = function noop() {};
  520. var withReducer = function withReducer(stateName, dispatchName, reducer, initialState) {
  521. return function (BaseComponent) {
  522. var factory = React.createFactory(BaseComponent);
  523. var WithReducer =
  524. /*#__PURE__*/
  525. function (_Component) {
  526. _inheritsLoose(WithReducer, _Component);
  527. function WithReducer() {
  528. var _this;
  529. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  530. args[_key] = arguments[_key];
  531. }
  532. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  533. _this.state = {
  534. stateValue: _this.initializeStateValue()
  535. };
  536. _this.dispatch = function (action, callback) {
  537. if (callback === void 0) {
  538. callback = noop;
  539. }
  540. return _this.setState(function (_ref) {
  541. var stateValue = _ref.stateValue;
  542. return {
  543. stateValue: reducer(stateValue, action)
  544. };
  545. }, function () {
  546. return callback(_this.state.stateValue);
  547. });
  548. };
  549. return _this;
  550. }
  551. var _proto = WithReducer.prototype;
  552. _proto.initializeStateValue = function initializeStateValue() {
  553. if (initialState !== undefined) {
  554. return typeof initialState === 'function' ? initialState(this.props) : initialState;
  555. }
  556. return reducer(undefined, {
  557. type: '@@recompose/INIT'
  558. });
  559. };
  560. _proto.render = function render() {
  561. var _extends2;
  562. return factory(_extends({}, this.props, (_extends2 = {}, _extends2[stateName] = this.state.stateValue, _extends2[dispatchName] = this.dispatch, _extends2)));
  563. };
  564. return WithReducer;
  565. }(React.Component);
  566. {
  567. return setDisplayName(wrapDisplayName(BaseComponent, 'withReducer'))(WithReducer);
  568. }
  569. return WithReducer;
  570. };
  571. };
  572. var identity = function identity(Component) {
  573. return Component;
  574. };
  575. var branch = function branch(test, left, right) {
  576. if (right === void 0) {
  577. right = identity;
  578. }
  579. return function (BaseComponent) {
  580. var leftFactory;
  581. var rightFactory;
  582. var Branch = function Branch(props) {
  583. if (test(props)) {
  584. leftFactory = leftFactory || React.createFactory(left(BaseComponent));
  585. return leftFactory(props);
  586. }
  587. rightFactory = rightFactory || React.createFactory(right(BaseComponent));
  588. return rightFactory(props);
  589. };
  590. {
  591. return setDisplayName(wrapDisplayName(BaseComponent, 'branch'))(Branch);
  592. }
  593. return Branch;
  594. };
  595. };
  596. var renderComponent = function renderComponent(Component) {
  597. return function (_) {
  598. var factory = React.createFactory(Component);
  599. var RenderComponent = function RenderComponent(props) {
  600. return factory(props);
  601. };
  602. {
  603. RenderComponent.displayName = wrapDisplayName(Component, 'renderComponent');
  604. }
  605. return RenderComponent;
  606. };
  607. };
  608. var Nothing =
  609. /*#__PURE__*/
  610. function (_Component) {
  611. _inheritsLoose(Nothing, _Component);
  612. function Nothing() {
  613. return _Component.apply(this, arguments) || this;
  614. }
  615. var _proto = Nothing.prototype;
  616. _proto.render = function render() {
  617. return null;
  618. };
  619. return Nothing;
  620. }(React.Component);
  621. var renderNothing = function renderNothing(_) {
  622. return Nothing;
  623. };
  624. var shouldUpdate = function shouldUpdate(test) {
  625. return function (BaseComponent) {
  626. var factory = React.createFactory(BaseComponent);
  627. var ShouldUpdate =
  628. /*#__PURE__*/
  629. function (_Component) {
  630. _inheritsLoose(ShouldUpdate, _Component);
  631. function ShouldUpdate() {
  632. return _Component.apply(this, arguments) || this;
  633. }
  634. var _proto = ShouldUpdate.prototype;
  635. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
  636. return test(this.props, nextProps);
  637. };
  638. _proto.render = function render() {
  639. return factory(this.props);
  640. };
  641. return ShouldUpdate;
  642. }(React.Component);
  643. {
  644. return setDisplayName(wrapDisplayName(BaseComponent, 'shouldUpdate'))(ShouldUpdate);
  645. }
  646. return ShouldUpdate;
  647. };
  648. };
  649. var pure = function pure(BaseComponent) {
  650. var hoc = shouldUpdate(function (props, nextProps) {
  651. return !shallowEqual_1(props, nextProps);
  652. });
  653. {
  654. return setDisplayName(wrapDisplayName(BaseComponent, 'pure'))(hoc(BaseComponent));
  655. }
  656. return hoc(BaseComponent);
  657. };
  658. var onlyUpdateForKeys = function onlyUpdateForKeys(propKeys) {
  659. var hoc = shouldUpdate(function (props, nextProps) {
  660. return !shallowEqual_1(pick(nextProps, propKeys), pick(props, propKeys));
  661. });
  662. {
  663. return function (BaseComponent) {
  664. return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForKeys'))(hoc(BaseComponent));
  665. };
  666. }
  667. return hoc;
  668. };
  669. var onlyUpdateForPropTypes = function onlyUpdateForPropTypes(BaseComponent) {
  670. var propTypes = BaseComponent.propTypes;
  671. {
  672. if (!propTypes) {
  673. /* eslint-disable */
  674. console.error('A component without any `propTypes` was passed to ' + '`onlyUpdateForPropTypes()`. Check the implementation of the ' + ("component with display name \"" + getDisplayName(BaseComponent) + "\"."));
  675. /* eslint-enable */
  676. }
  677. }
  678. var propKeys = Object.keys(propTypes || {});
  679. var OnlyUpdateForPropTypes = onlyUpdateForKeys(propKeys)(BaseComponent);
  680. {
  681. return setDisplayName(wrapDisplayName(BaseComponent, 'onlyUpdateForPropTypes'))(OnlyUpdateForPropTypes);
  682. }
  683. return OnlyUpdateForPropTypes;
  684. };
  685. var withContext = function withContext(childContextTypes, getChildContext) {
  686. return function (BaseComponent) {
  687. var factory = React.createFactory(BaseComponent);
  688. var WithContext =
  689. /*#__PURE__*/
  690. function (_Component) {
  691. _inheritsLoose(WithContext, _Component);
  692. function WithContext() {
  693. var _this;
  694. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  695. args[_key] = arguments[_key];
  696. }
  697. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  698. _this.getChildContext = function () {
  699. return getChildContext(_this.props);
  700. };
  701. return _this;
  702. }
  703. var _proto = WithContext.prototype;
  704. _proto.render = function render() {
  705. return factory(this.props);
  706. };
  707. return WithContext;
  708. }(React.Component);
  709. WithContext.childContextTypes = childContextTypes;
  710. {
  711. return setDisplayName(wrapDisplayName(BaseComponent, 'withContext'))(WithContext);
  712. }
  713. return WithContext;
  714. };
  715. };
  716. var getContext = function getContext(contextTypes) {
  717. return function (BaseComponent) {
  718. var factory = React.createFactory(BaseComponent);
  719. var GetContext = function GetContext(ownerProps, context) {
  720. return factory(_extends({}, ownerProps, context));
  721. };
  722. GetContext.contextTypes = contextTypes;
  723. {
  724. return setDisplayName(wrapDisplayName(BaseComponent, 'getContext'))(GetContext);
  725. }
  726. return GetContext;
  727. };
  728. };
  729. var lifecycle = function lifecycle(spec) {
  730. return function (BaseComponent) {
  731. var factory = React.createFactory(BaseComponent);
  732. if (spec.hasOwnProperty('render')) {
  733. console.error('lifecycle() does not support the render method; its behavior is to ' + 'pass all props and state to the base component.');
  734. }
  735. var Lifecycle =
  736. /*#__PURE__*/
  737. function (_Component) {
  738. _inheritsLoose(Lifecycle, _Component);
  739. function Lifecycle() {
  740. return _Component.apply(this, arguments) || this;
  741. }
  742. var _proto = Lifecycle.prototype;
  743. _proto.render = function render() {
  744. return factory(_extends({}, this.props, this.state));
  745. };
  746. return Lifecycle;
  747. }(React.Component);
  748. Object.keys(spec).forEach(function (hook) {
  749. return Lifecycle.prototype[hook] = spec[hook];
  750. });
  751. {
  752. return setDisplayName(wrapDisplayName(BaseComponent, 'lifecycle'))(Lifecycle);
  753. }
  754. return Lifecycle;
  755. };
  756. };
  757. var isClassComponent = function isClassComponent(Component) {
  758. return Boolean(Component && Component.prototype && typeof Component.prototype.render === 'function');
  759. };
  760. var toClass = function toClass(baseComponent) {
  761. var _class, _temp;
  762. return isClassComponent(baseComponent) ? baseComponent : (_temp = _class =
  763. /*#__PURE__*/
  764. function (_Component) {
  765. _inheritsLoose(ToClass, _Component);
  766. function ToClass() {
  767. return _Component.apply(this, arguments) || this;
  768. }
  769. var _proto = ToClass.prototype;
  770. _proto.render = function render() {
  771. if (typeof baseComponent === 'string') {
  772. return React__default.createElement(baseComponent, this.props);
  773. }
  774. return baseComponent(this.props, this.context);
  775. };
  776. return ToClass;
  777. }(React.Component), _class.displayName = getDisplayName(baseComponent), _class.propTypes = baseComponent.propTypes, _class.contextTypes = baseComponent.contextTypes, _class.defaultProps = baseComponent.defaultProps, _temp);
  778. };
  779. function toRenderProps(hoc) {
  780. var RenderPropsComponent = function RenderPropsComponent(props) {
  781. return props.children(props);
  782. };
  783. return hoc(RenderPropsComponent);
  784. }
  785. var fromRenderProps = function fromRenderProps(RenderPropsComponent, propsMapper, renderPropName) {
  786. if (renderPropName === void 0) {
  787. renderPropName = 'children';
  788. }
  789. return function (BaseComponent) {
  790. var baseFactory = React__default.createFactory(BaseComponent);
  791. var renderPropsFactory = React__default.createFactory(RenderPropsComponent);
  792. var FromRenderProps = function FromRenderProps(ownerProps) {
  793. var _renderPropsFactory;
  794. return renderPropsFactory((_renderPropsFactory = {}, _renderPropsFactory[renderPropName] = function () {
  795. return baseFactory(_extends({}, ownerProps, propsMapper.apply(void 0, arguments)));
  796. }, _renderPropsFactory));
  797. };
  798. {
  799. return setDisplayName(wrapDisplayName(BaseComponent, 'fromRenderProps'))(FromRenderProps);
  800. }
  801. return FromRenderProps;
  802. };
  803. };
  804. var setPropTypes = function setPropTypes(propTypes) {
  805. return setStatic('propTypes', propTypes);
  806. };
  807. var compose = function compose() {
  808. for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
  809. funcs[_key] = arguments[_key];
  810. }
  811. return funcs.reduce(function (a, b) {
  812. return function () {
  813. return a(b.apply(void 0, arguments));
  814. };
  815. }, function (arg) {
  816. return arg;
  817. });
  818. };
  819. var createSink = function createSink(callback) {
  820. var Sink =
  821. /*#__PURE__*/
  822. function (_Component) {
  823. _inheritsLoose(Sink, _Component);
  824. function Sink() {
  825. var _this;
  826. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  827. args[_key] = arguments[_key];
  828. }
  829. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  830. _this.state = {};
  831. return _this;
  832. }
  833. Sink.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps) {
  834. callback(nextProps);
  835. return null;
  836. };
  837. var _proto = Sink.prototype;
  838. _proto.render = function render() {
  839. return null;
  840. };
  841. return Sink;
  842. }(React.Component);
  843. polyfill(Sink);
  844. return Sink;
  845. };
  846. var componentFromProp = function componentFromProp(propName) {
  847. var Component = function Component(props) {
  848. return React.createElement(props[propName], omit(props, [propName]));
  849. };
  850. Component.displayName = "componentFromProp(" + propName + ")";
  851. return Component;
  852. };
  853. function _objectWithoutPropertiesLoose(source, excluded) {
  854. if (source == null) return {};
  855. var target = {};
  856. var sourceKeys = Object.keys(source);
  857. var key, i;
  858. for (i = 0; i < sourceKeys.length; i++) {
  859. key = sourceKeys[i];
  860. if (excluded.indexOf(key) >= 0) continue;
  861. target[key] = source[key];
  862. }
  863. return target;
  864. }
  865. var nest = function nest() {
  866. for (var _len = arguments.length, Components = new Array(_len), _key = 0; _key < _len; _key++) {
  867. Components[_key] = arguments[_key];
  868. }
  869. var factories = Components.map(React.createFactory);
  870. var Nest = function Nest(_ref) {
  871. var children = _ref.children,
  872. props = _objectWithoutPropertiesLoose(_ref, ["children"]);
  873. return factories.reduceRight(function (child, factory) {
  874. return factory(props, child);
  875. }, children);
  876. };
  877. {
  878. var displayNames = Components.map(getDisplayName);
  879. Nest.displayName = "nest(" + displayNames.join(', ') + ")";
  880. }
  881. return Nest;
  882. };
  883. /**
  884. * Copyright 2015, Yahoo! Inc.
  885. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  886. */
  887. var REACT_STATICS = {
  888. childContextTypes: true,
  889. contextTypes: true,
  890. defaultProps: true,
  891. displayName: true,
  892. getDefaultProps: true,
  893. mixins: true,
  894. propTypes: true,
  895. type: true
  896. };
  897. var KNOWN_STATICS = {
  898. name: true,
  899. length: true,
  900. prototype: true,
  901. caller: true,
  902. callee: true,
  903. arguments: true,
  904. arity: true
  905. };
  906. var defineProperty = Object.defineProperty;
  907. var getOwnPropertyNames = Object.getOwnPropertyNames;
  908. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  909. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  910. var getPrototypeOf = Object.getPrototypeOf;
  911. var objectPrototype = getPrototypeOf && getPrototypeOf(Object);
  912. var hoistNonReactStatics = function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
  913. if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components
  914. if (objectPrototype) {
  915. var inheritedComponent = getPrototypeOf(sourceComponent);
  916. if (inheritedComponent && inheritedComponent !== objectPrototype) {
  917. hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
  918. }
  919. }
  920. var keys = getOwnPropertyNames(sourceComponent);
  921. if (getOwnPropertySymbols) {
  922. keys = keys.concat(getOwnPropertySymbols(sourceComponent));
  923. }
  924. for (var i = 0; i < keys.length; ++i) {
  925. var key = keys[i];
  926. if (!REACT_STATICS[key] && !KNOWN_STATICS[key] && (!blacklist || !blacklist[key])) {
  927. var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
  928. try { // Avoid failures from read-only properties
  929. defineProperty(targetComponent, key, descriptor);
  930. } catch (e) {}
  931. }
  932. }
  933. return targetComponent;
  934. }
  935. return targetComponent;
  936. };
  937. var hoistStatics = function hoistStatics(higherOrderComponent, blacklist) {
  938. return function (BaseComponent) {
  939. var NewComponent = higherOrderComponent(BaseComponent);
  940. hoistNonReactStatics(NewComponent, BaseComponent, blacklist);
  941. return NewComponent;
  942. };
  943. };
  944. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  945. function unwrapExports (x) {
  946. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  947. }
  948. function createCommonjsModule(fn, module) {
  949. return module = { exports: {} }, fn(module, module.exports), module.exports;
  950. }
  951. var lib = createCommonjsModule(function (module, exports) {
  952. Object.defineProperty(exports, "__esModule", {
  953. value: true
  954. });
  955. var createChangeEmitter = exports.createChangeEmitter = function createChangeEmitter() {
  956. var currentListeners = [];
  957. var nextListeners = currentListeners;
  958. function ensureCanMutateNextListeners() {
  959. if (nextListeners === currentListeners) {
  960. nextListeners = currentListeners.slice();
  961. }
  962. }
  963. function listen(listener) {
  964. if (typeof listener !== 'function') {
  965. throw new Error('Expected listener to be a function.');
  966. }
  967. var isSubscribed = true;
  968. ensureCanMutateNextListeners();
  969. nextListeners.push(listener);
  970. return function () {
  971. if (!isSubscribed) {
  972. return;
  973. }
  974. isSubscribed = false;
  975. ensureCanMutateNextListeners();
  976. var index = nextListeners.indexOf(listener);
  977. nextListeners.splice(index, 1);
  978. };
  979. }
  980. function emit() {
  981. currentListeners = nextListeners;
  982. var listeners = currentListeners;
  983. for (var i = 0; i < listeners.length; i++) {
  984. listeners[i].apply(listeners, arguments);
  985. }
  986. }
  987. return {
  988. listen: listen,
  989. emit: emit
  990. };
  991. };
  992. });
  993. unwrapExports(lib);
  994. var lib_1 = lib.createChangeEmitter;
  995. var ponyfill = createCommonjsModule(function (module, exports) {
  996. Object.defineProperty(exports, "__esModule", {
  997. value: true
  998. });
  999. exports['default'] = symbolObservablePonyfill;
  1000. function symbolObservablePonyfill(root) {
  1001. var result;
  1002. var _Symbol = root.Symbol;
  1003. if (typeof _Symbol === 'function') {
  1004. if (_Symbol.observable) {
  1005. result = _Symbol.observable;
  1006. } else {
  1007. result = _Symbol('observable');
  1008. _Symbol.observable = result;
  1009. }
  1010. } else {
  1011. result = '@@observable';
  1012. }
  1013. return result;
  1014. }});
  1015. unwrapExports(ponyfill);
  1016. var lib$1 = createCommonjsModule(function (module, exports) {
  1017. Object.defineProperty(exports, "__esModule", {
  1018. value: true
  1019. });
  1020. var _ponyfill2 = _interopRequireDefault(ponyfill);
  1021. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  1022. var root; /* global window */
  1023. if (typeof self !== 'undefined') {
  1024. root = self;
  1025. } else if (typeof window !== 'undefined') {
  1026. root = window;
  1027. } else if (typeof commonjsGlobal !== 'undefined') {
  1028. root = commonjsGlobal;
  1029. } else {
  1030. root = module;
  1031. }
  1032. var result = (0, _ponyfill2['default'])(root);
  1033. exports['default'] = result;
  1034. });
  1035. unwrapExports(lib$1);
  1036. var symbolObservable = lib$1;
  1037. var _config = {
  1038. fromESObservable: null,
  1039. toESObservable: null
  1040. };
  1041. var configureObservable = function configureObservable(c) {
  1042. _config = c;
  1043. };
  1044. var config = {
  1045. fromESObservable: function fromESObservable(observable) {
  1046. return typeof _config.fromESObservable === 'function' ? _config.fromESObservable(observable) : observable;
  1047. },
  1048. toESObservable: function toESObservable(stream) {
  1049. return typeof _config.toESObservable === 'function' ? _config.toESObservable(stream) : stream;
  1050. }
  1051. };
  1052. var componentFromStreamWithConfig = function componentFromStreamWithConfig(config$$1) {
  1053. return function (propsToVdom) {
  1054. return (
  1055. /*#__PURE__*/
  1056. function (_Component) {
  1057. _inheritsLoose(ComponentFromStream, _Component);
  1058. function ComponentFromStream() {
  1059. var _config$fromESObserva;
  1060. var _this;
  1061. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  1062. args[_key] = arguments[_key];
  1063. }
  1064. _this = _Component.call.apply(_Component, [this].concat(args)) || this;
  1065. _this.state = {
  1066. vdom: null
  1067. };
  1068. _this.propsEmitter = lib_1();
  1069. _this.props$ = config$$1.fromESObservable((_config$fromESObserva = {
  1070. subscribe: function subscribe(observer) {
  1071. var unsubscribe = _this.propsEmitter.listen(function (props) {
  1072. if (props) {
  1073. observer.next(props);
  1074. } else {
  1075. observer.complete();
  1076. }
  1077. });
  1078. return {
  1079. unsubscribe: unsubscribe
  1080. };
  1081. }
  1082. }, _config$fromESObserva[symbolObservable] = function () {
  1083. return this;
  1084. }, _config$fromESObserva));
  1085. _this.vdom$ = config$$1.toESObservable(propsToVdom(_this.props$));
  1086. return _this;
  1087. }
  1088. var _proto = ComponentFromStream.prototype;
  1089. _proto.componentWillMount = function componentWillMount() {
  1090. var _this2 = this;
  1091. // Subscribe to child prop changes so we know when to re-render
  1092. this.subscription = this.vdom$.subscribe({
  1093. next: function next(vdom) {
  1094. _this2.setState({
  1095. vdom: vdom
  1096. });
  1097. }
  1098. });
  1099. this.propsEmitter.emit(this.props);
  1100. };
  1101. _proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  1102. // Receive new props from the owner
  1103. this.propsEmitter.emit(nextProps);
  1104. };
  1105. _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
  1106. return nextState.vdom !== this.state.vdom;
  1107. };
  1108. _proto.componentWillUnmount = function componentWillUnmount() {
  1109. // Call without arguments to complete stream
  1110. this.propsEmitter.emit(); // Clean-up subscription before un-mounting
  1111. this.subscription.unsubscribe();
  1112. };
  1113. _proto.render = function render() {
  1114. return this.state.vdom;
  1115. };
  1116. return ComponentFromStream;
  1117. }(React.Component)
  1118. );
  1119. };
  1120. };
  1121. var componentFromStream = function componentFromStream(propsToVdom) {
  1122. return componentFromStreamWithConfig(config)(propsToVdom);
  1123. };
  1124. var identity$1 = function identity(t) {
  1125. return t;
  1126. };
  1127. var mapPropsStreamWithConfig = function mapPropsStreamWithConfig(config$$1) {
  1128. var componentFromStream$$1 = componentFromStreamWithConfig({
  1129. fromESObservable: identity$1,
  1130. toESObservable: identity$1
  1131. });
  1132. return function (transform) {
  1133. return function (BaseComponent) {
  1134. var factory = React.createFactory(BaseComponent);
  1135. var fromESObservable = config$$1.fromESObservable,
  1136. toESObservable = config$$1.toESObservable;
  1137. return componentFromStream$$1(function (props$) {
  1138. var _ref;
  1139. return _ref = {
  1140. subscribe: function subscribe(observer) {
  1141. var subscription = toESObservable(transform(fromESObservable(props$))).subscribe({
  1142. next: function next(childProps) {
  1143. return observer.next(factory(childProps));
  1144. }
  1145. });
  1146. return {
  1147. unsubscribe: function unsubscribe() {
  1148. return subscription.unsubscribe();
  1149. }
  1150. };
  1151. }
  1152. }, _ref[symbolObservable] = function () {
  1153. return this;
  1154. }, _ref;
  1155. });
  1156. };
  1157. };
  1158. };
  1159. var mapPropsStream = function mapPropsStream(transform) {
  1160. var hoc = mapPropsStreamWithConfig(config)(transform);
  1161. {
  1162. return function (BaseComponent) {
  1163. return setDisplayName(wrapDisplayName(BaseComponent, 'mapPropsStream'))(hoc(BaseComponent));
  1164. };
  1165. }
  1166. return hoc;
  1167. };
  1168. var createEventHandlerWithConfig = function createEventHandlerWithConfig(config$$1) {
  1169. return function () {
  1170. var _config$fromESObserva;
  1171. var emitter = lib_1();
  1172. var stream = config$$1.fromESObservable((_config$fromESObserva = {
  1173. subscribe: function subscribe(observer) {
  1174. var unsubscribe = emitter.listen(function (value) {
  1175. return observer.next(value);
  1176. });
  1177. return {
  1178. unsubscribe: unsubscribe
  1179. };
  1180. }
  1181. }, _config$fromESObserva[symbolObservable] = function () {
  1182. return this;
  1183. }, _config$fromESObserva));
  1184. return {
  1185. handler: emitter.emit,
  1186. stream: stream
  1187. };
  1188. };
  1189. };
  1190. var createEventHandler = createEventHandlerWithConfig(config);
  1191. // Higher-order component helpers
  1192. exports.mapProps = mapProps;
  1193. exports.withProps = withProps;
  1194. exports.withPropsOnChange = withPropsOnChange;
  1195. exports.withHandlers = withHandlers;
  1196. exports.defaultProps = defaultProps;
  1197. exports.renameProp = renameProp;
  1198. exports.renameProps = renameProps;
  1199. exports.flattenProp = flattenProp;
  1200. exports.withState = withState;
  1201. exports.withStateHandlers = withStateHandlers;
  1202. exports.withReducer = withReducer;
  1203. exports.branch = branch;
  1204. exports.renderComponent = renderComponent;
  1205. exports.renderNothing = renderNothing;
  1206. exports.shouldUpdate = shouldUpdate;
  1207. exports.pure = pure;
  1208. exports.onlyUpdateForKeys = onlyUpdateForKeys;
  1209. exports.onlyUpdateForPropTypes = onlyUpdateForPropTypes;
  1210. exports.withContext = withContext;
  1211. exports.getContext = getContext;
  1212. exports.lifecycle = lifecycle;
  1213. exports.toClass = toClass;
  1214. exports.toRenderProps = toRenderProps;
  1215. exports.fromRenderProps = fromRenderProps;
  1216. exports.setStatic = setStatic;
  1217. exports.setPropTypes = setPropTypes;
  1218. exports.setDisplayName = setDisplayName;
  1219. exports.compose = compose;
  1220. exports.getDisplayName = getDisplayName;
  1221. exports.wrapDisplayName = wrapDisplayName;
  1222. exports.shallowEqual = shallowEqual_1;
  1223. exports.isClassComponent = isClassComponent;
  1224. exports.createSink = createSink;
  1225. exports.componentFromProp = componentFromProp;
  1226. exports.nest = nest;
  1227. exports.hoistStatics = hoistStatics;
  1228. exports.componentFromStream = componentFromStream;
  1229. exports.componentFromStreamWithConfig = componentFromStreamWithConfig;
  1230. exports.mapPropsStream = mapPropsStream;
  1231. exports.mapPropsStreamWithConfig = mapPropsStreamWithConfig;
  1232. exports.createEventHandler = createEventHandler;
  1233. exports.createEventHandlerWithConfig = createEventHandlerWithConfig;
  1234. exports.setObservableConfig = configureObservable;
  1235. Object.defineProperty(exports, '__esModule', { value: true });
  1236. })));