Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _offset = _interopRequireDefault(require("dom-helpers/query/offset"));
  5. var _listen = _interopRequireDefault(require("dom-helpers/events/listen"));
  6. var _requestAnimationFrame = _interopRequireDefault(require("dom-helpers/util/requestAnimationFrame"));
  7. var _propTypes = _interopRequireDefault(require("prop-types"));
  8. var _componentOrElement = _interopRequireDefault(require("prop-types-extra/lib/componentOrElement"));
  9. var _react = _interopRequireDefault(require("react"));
  10. var _Affix = _interopRequireDefault(require("./Affix"));
  11. var _getContainer = _interopRequireDefault(require("./utils/getContainer"));
  12. var _getDocumentHeight = _interopRequireDefault(require("./utils/getDocumentHeight"));
  13. var _ownerDocument = _interopRequireDefault(require("./utils/ownerDocument"));
  14. var _ownerWindow = _interopRequireDefault(require("./utils/ownerWindow"));
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  17. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  18. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  19. function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  20. var displayName = 'AutoAffix';
  21. var propTypes = _extends({}, _Affix.default.propTypes, {
  22. /**
  23. * The logical container node or component for determining offset from bottom
  24. * of viewport, or a function that returns it
  25. */
  26. container: _propTypes.default.oneOfType([_componentOrElement.default, _propTypes.default.func]),
  27. /**
  28. * Automatically set width when affixed
  29. */
  30. autoWidth: _propTypes.default.bool // This intentionally doesn't inherit default props from `<Affix>`, so that the
  31. // auto-calculated offsets can apply.
  32. });
  33. var defaultProps = {
  34. viewportOffsetTop: 0,
  35. autoWidth: true
  36. /**
  37. * The `<AutoAffix/>` component wraps `<Affix/>` to automatically calculate
  38. * offsets in many common cases.
  39. */
  40. };
  41. var AutoAffix =
  42. /*#__PURE__*/
  43. function (_React$Component) {
  44. _inheritsLoose(AutoAffix, _React$Component);
  45. function AutoAffix(props, context) {
  46. var _this;
  47. _this = _React$Component.call(this, props, context) || this;
  48. _this.onWindowScroll = function () {
  49. _this.onUpdate();
  50. };
  51. _this.onWindowResize = function () {
  52. if (_this.props.autoWidth) {
  53. (0, _requestAnimationFrame.default)(function () {
  54. return _this.onUpdate();
  55. });
  56. }
  57. };
  58. _this.onDocumentClick = function () {
  59. (0, _requestAnimationFrame.default)(function () {
  60. return _this.onUpdate();
  61. });
  62. };
  63. _this.onUpdate = function () {
  64. if (!_this._isMounted) {
  65. return;
  66. }
  67. var _getOffset = (0, _offset.default)(_this.positioner),
  68. offsetTop = _getOffset.top,
  69. width = _getOffset.width;
  70. var container = (0, _getContainer.default)(_this.props.container);
  71. var offsetBottom;
  72. if (container) {
  73. var documentHeight = (0, _getDocumentHeight.default)((0, _ownerDocument.default)(_assertThisInitialized(_assertThisInitialized(_this))));
  74. var _getOffset2 = (0, _offset.default)(container),
  75. top = _getOffset2.top,
  76. height = _getOffset2.height;
  77. offsetBottom = documentHeight - top - height;
  78. } else {
  79. offsetBottom = null;
  80. }
  81. _this.updateState(offsetTop, offsetBottom, width);
  82. };
  83. _this.updateState = function (offsetTop, offsetBottom, width) {
  84. if (offsetTop === _this.state.offsetTop && offsetBottom === _this.state.offsetBottom && width === _this.state.width) {
  85. return;
  86. }
  87. _this.setState({
  88. offsetTop: offsetTop,
  89. offsetBottom: offsetBottom,
  90. width: width
  91. });
  92. };
  93. _this.state = {
  94. offsetTop: null,
  95. offsetBottom: null,
  96. width: null
  97. };
  98. return _this;
  99. }
  100. var _proto = AutoAffix.prototype;
  101. _proto.componentDidMount = function componentDidMount() {
  102. var _this2 = this;
  103. this._isMounted = true;
  104. this.removeScrollListener = (0, _listen.default)((0, _ownerWindow.default)(this), 'scroll', function () {
  105. return _this2.onWindowScroll();
  106. });
  107. this.removeResizeListener = (0, _listen.default)((0, _ownerWindow.default)(this), 'resize', function () {
  108. return _this2.onWindowResize();
  109. });
  110. this.removeClickListener = (0, _listen.default)((0, _ownerDocument.default)(this), 'click', function () {
  111. return _this2.onDocumentClick();
  112. });
  113. this.onUpdate();
  114. };
  115. _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
  116. if (prevProps !== this.props) {
  117. this.onUpdate();
  118. }
  119. };
  120. _proto.componentWillUnmount = function componentWillUnmount() {
  121. this._isMounted = false;
  122. if (this.removeScrollListener) this.removeScrollListener();
  123. if (this.removeClickListener) this.removeClickListener();
  124. if (this.removeResizeListener) this.removeResizeListener();
  125. };
  126. _proto.render = function render() {
  127. var _this3 = this;
  128. var _this$props = this.props,
  129. autoWidth = _this$props.autoWidth,
  130. viewportOffsetTop = _this$props.viewportOffsetTop,
  131. children = _this$props.children,
  132. props = _objectWithoutPropertiesLoose(_this$props, ["autoWidth", "viewportOffsetTop", "children"]);
  133. var _this$state = this.state,
  134. offsetTop = _this$state.offsetTop,
  135. offsetBottom = _this$state.offsetBottom,
  136. width = _this$state.width;
  137. delete props.container;
  138. var effectiveOffsetTop = Math.max(offsetTop, viewportOffsetTop || 0);
  139. var _this$props2 = this.props,
  140. affixStyle = _this$props2.affixStyle,
  141. bottomStyle = _this$props2.bottomStyle;
  142. if (autoWidth) {
  143. affixStyle = _extends({
  144. width: width
  145. }, affixStyle);
  146. bottomStyle = _extends({
  147. width: width
  148. }, bottomStyle);
  149. }
  150. return _react.default.createElement("div", null, _react.default.createElement("div", {
  151. ref: function ref(c) {
  152. _this3.positioner = c;
  153. }
  154. }), _react.default.createElement(_Affix.default, _extends({}, props, {
  155. offsetTop: effectiveOffsetTop,
  156. viewportOffsetTop: viewportOffsetTop,
  157. offsetBottom: offsetBottom,
  158. affixStyle: affixStyle,
  159. bottomStyle: bottomStyle
  160. }), children));
  161. };
  162. return AutoAffix;
  163. }(_react.default.Component);
  164. AutoAffix.displayName = displayName;
  165. AutoAffix.propTypes = propTypes;
  166. AutoAffix.defaultProps = defaultProps;
  167. var _default = AutoAffix;
  168. exports.default = _default;
  169. module.exports = exports.default;