shineout 1.12.24 → 1.12.25-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ exports.default = void 0;
6
6
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
7
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
8
8
  var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _react = _interopRequireWildcard(require("react"));
10
11
  var _classnames = _interopRequireDefault(require("classnames"));
11
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -15,12 +16,45 @@ var _Lazyload = _interopRequireDefault(require("../Lazyload"));
15
16
  var _excluded = ["style", "className", "container", "children", "placeholder", "value"];
16
17
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
17
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
21
  var Item = /*#__PURE__*/function (_React$Component) {
19
- function Item() {
20
- return _React$Component.apply(this, arguments) || this;
22
+ function Item(props) {
23
+ var _this;
24
+ _this = _React$Component.call(this, props) || this;
25
+ (0, _defineProperty2.default)(_this, "observerIns", null);
26
+ _this.state = {
27
+ isInView: true
28
+ };
29
+ _this.containerRef = /*#__PURE__*/_react.default.createRef();
30
+ return _this;
21
31
  }
22
32
  (0, _inheritsLoose2.default)(Item, _React$Component);
23
33
  var _proto = Item.prototype;
34
+ _proto.componentDidMount = function componentDidMount() {
35
+ var _this2 = this,
36
+ _this$props$container;
37
+ if (typeof window === 'undefined' || !window.IntersectionObserver || !this.containerRef.current) {
38
+ return;
39
+ }
40
+ this.observerIns = new IntersectionObserver(function (_ref) {
41
+ var entry = _ref[0];
42
+ var inView = entry.isIntersecting;
43
+ _this2.setState({
44
+ isInView: inView
45
+ });
46
+ }, {
47
+ root: this.props.container,
48
+ rootMargin: (((_this$props$container = this.props.container) == null ? void 0 : _this$props$container.offsetHeight) || 0) + "px",
49
+ threshold: [0, 1]
50
+ });
51
+ this.observerIns.observe(this.containerRef.current);
52
+ };
53
+ _proto.componentWillUnmount = function componentWillUnmount() {
54
+ if (this.observerIns) {
55
+ this.observerIns.disconnect();
56
+ }
57
+ };
24
58
  _proto.handleChange = function handleChange(value, _, checked) {
25
59
  var onChange = this.props.onChange;
26
60
  if (onChange) onChange(checked, value);
@@ -32,7 +66,8 @@ var Item = /*#__PURE__*/function (_React$Component) {
32
66
  if (!placeholder) return content;
33
67
  return /*#__PURE__*/_react.default.createElement(_Lazyload.default, {
34
68
  container: container,
35
- placeholder: placeholder
69
+ placeholder: placeholder,
70
+ isInView: this.state.isInView
36
71
  }, content);
37
72
  };
38
73
  _proto.render = function render() {
@@ -50,9 +85,14 @@ var Item = /*#__PURE__*/function (_React$Component) {
50
85
  onChange: this.handleChange.bind(this, value),
51
86
  className: (0, _styles.cardGroupClass)('checkbox')
52
87
  })));
88
+ var hiddenStyle = this.state.isInView ? undefined : {
89
+ visibility: 'hidden'
90
+ };
91
+ var itemStyle = _objectSpread(_objectSpread({}, style), hiddenStyle);
53
92
  return /*#__PURE__*/_react.default.createElement("div", {
54
- style: style,
55
- className: cls
93
+ style: itemStyle,
94
+ className: cls,
95
+ ref: this.containerRef
56
96
  }, this.renderChildren(content));
57
97
  };
58
98
  return Item;
@@ -73,6 +73,7 @@ var Image = /*#__PURE__*/function (_PureComponent) {
73
73
  this.element = el;
74
74
  };
75
75
  _proto.fetchImage = function fetchImage() {
76
+ var _this2 = this;
76
77
  if (this.lazyId) (0, _lazyload.removeStack)(this.lazyId);
77
78
  if (!this.props.lazy) {
78
79
  this.markToRender();
@@ -82,12 +83,18 @@ var Image = /*#__PURE__*/function (_PureComponent) {
82
83
  offset: typeof this.props.lazy === 'number' ? this.props.lazy : 0,
83
84
  element: this.element,
84
85
  render: this.markToRender,
86
+ offscreen: function offscreen() {
87
+ _this2.setState({
88
+ status: PLACEHOLDER
89
+ });
90
+ },
91
+ noRemove: this.props.inViewOnly,
85
92
  container: typeof container === 'string' ? document.querySelector(container) : container
86
93
  });
87
94
  }
88
95
  };
89
96
  _proto.markToRender = function markToRender() {
90
- var _this2 = this;
97
+ var _this3 = this;
91
98
  var src = this.props.src;
92
99
  if (!src) {
93
100
  this.handleAlt();
@@ -96,7 +103,7 @@ var Image = /*#__PURE__*/function (_PureComponent) {
96
103
  delete this.image;
97
104
  var image = new window.Image();
98
105
  image.onload = function () {
99
- return _this2.setState({
106
+ return _this3.setState({
100
107
  status: SRC
101
108
  });
102
109
  };
@@ -112,7 +119,7 @@ var Image = /*#__PURE__*/function (_PureComponent) {
112
119
  });
113
120
  };
114
121
  _proto.handleAlt = function handleAlt() {
115
- var _this3 = this;
122
+ var _this4 = this;
116
123
  var alt = this.props.alt;
117
124
  if (!alt) {
118
125
  this.setState({
@@ -122,7 +129,7 @@ var Image = /*#__PURE__*/function (_PureComponent) {
122
129
  }
123
130
  var image = new window.Image();
124
131
  image.onload = function () {
125
- return _this3.setState({
132
+ return _this4.setState({
126
133
  status: ALT
127
134
  });
128
135
  };
@@ -248,7 +255,8 @@ Image.propTypes = {
248
255
  container: _propTypes.default.string,
249
256
  error: _propTypes.default.node,
250
257
  autoSSL: _propTypes.default.bool,
251
- onError: _propTypes.default.func
258
+ onError: _propTypes.default.func,
259
+ inViewOnly: _propTypes.default.bool
252
260
  };
253
261
  Image.defaultProps = {
254
262
  lazy: false,
@@ -170,6 +170,15 @@ export interface ImageGroupProps {
170
170
  */
171
171
  lazy?: boolean;
172
172
 
173
+ /**
174
+ * whether to only load images in view
175
+ *
176
+ * 是否仅加载在视图内的图片
177
+ *
178
+ * default: false
179
+ */
180
+ inViewOnly?: boolean
181
+
173
182
  /**
174
183
  * whether to stack
175
184
  *
@@ -46,8 +46,10 @@ var Lazyload = /*#__PURE__*/function (_PureComponent) {
46
46
  var ready = this.state.ready;
47
47
  var _this$props2 = this.props,
48
48
  children = _this$props2.children,
49
- placeholder = _this$props2.placeholder;
50
- if (ready) return children;
49
+ placeholder = _this$props2.placeholder,
50
+ _this$props2$isInView = _this$props2.isInView,
51
+ isInView = _this$props2$isInView === void 0 ? true : _this$props2$isInView;
52
+ if (ready && isInView) return children;
51
53
  return /*#__PURE__*/_react.default.createElement("span", {
52
54
  ref: this.placeholderRef,
53
55
  className: (0, _styles.lazyloadClass)('_')
@@ -59,7 +61,8 @@ Lazyload.propTypes = {
59
61
  children: _propTypes.default.any,
60
62
  placeholder: _propTypes.default.element,
61
63
  container: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.object]),
62
- offset: _propTypes.default.number
64
+ offset: _propTypes.default.number,
65
+ isInView: _propTypes.default.bool
63
66
  };
64
67
  Lazyload.defaultProps = {
65
68
  offset: 0
package/css/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as utils from './utils'
3
3
 
4
4
  declare const __default: {
5
5
  utils: typeof utils,
6
- version: '1.12.24'
6
+ version: '1.12.25-beta.1'
7
7
  }
8
8
 
9
9
  export default __default
package/css/index.js CHANGED
@@ -117,5 +117,5 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
117
117
  // Created by scripts/src-index.js.
118
118
  var _default = exports.default = {
119
119
  utils: utils,
120
- version: '1.12.24'
120
+ version: '1.12.25-beta.1'
121
121
  };
@@ -69,12 +69,15 @@ function getObserver(obj, id) {
69
69
  container = _obj$container === void 0 ? null : _obj$container,
70
70
  offset = obj.offset,
71
71
  render = obj.render,
72
+ offscreen = obj.offscreen,
72
73
  noRemove = obj.noRemove;
73
74
  var observer = new IntersectionObserver(function (entries) {
74
75
  entries.forEach(function (en) {
75
76
  if (en.isIntersecting || en.intersectionRatio > 0) {
76
77
  render();
77
78
  if (!noRemove) removeStack(id);
79
+ } else if (offscreen) {
80
+ offscreen();
78
81
  }
79
82
  });
80
83
  }, {