@fonixtree/magic-design 2.0.30 → 2.0.31

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.
@@ -100,9 +100,11 @@ function (_super) {
100
100
 
101
101
  this.intersectionObserver = new IntersectionObserver(function (entries) {
102
102
  if (entries[0].isIntersecting) {
103
- _this.setState({
104
- show: true
105
- });
103
+ if (!_this.state.show) {
104
+ _this.setState({
105
+ show: true
106
+ });
107
+ }
106
108
  }
107
109
  }, {
108
110
  root: (_a = this.props) === null || _a === void 0 ? void 0 : _a.rootContainer(),
@@ -120,14 +122,13 @@ function (_super) {
120
122
  var _this = this;
121
123
 
122
124
  var _a = this.props,
123
- root = _a.root,
124
125
  _b = _a.lazy,
125
126
  lazy = _b === void 0 ? true : _b,
126
127
  src = _a.src,
127
128
  onLoadFunc = _a.onLoadFunc,
128
129
  style = _a.style,
129
130
  className = _a.className,
130
- rest = __rest(_a, ["root", "lazy", "src", "onLoadFunc", "style", "className"]);
131
+ rest = __rest(_a, ["lazy", "src", "onLoadFunc", "style", "className"]);
131
132
 
132
133
  var show = this.state.show;
133
134
  var isShow = lazy ? show : true;
@@ -15,6 +15,8 @@ var _defaultJSON = require("./defaultJSON");
15
15
 
16
16
  var _compositeDecorator = _interopRequireDefault(require("../../../../decorator/compositeDecorator"));
17
17
 
18
+ var _decorator = require("../../../../decorator");
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
21
 
20
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -68,40 +70,26 @@ function (_super) {
68
70
  var _this = _super !== null && _super.apply(this, arguments) || this;
69
71
 
70
72
  _this.state = {
71
- show: false
73
+ lazyShow: false
72
74
  };
73
75
  _this.carouselRef = /*#__PURE__*/_react["default"].createRef();
74
76
  _this.intersectionObserver = null;
75
77
  return _this;
76
78
  }
77
79
 
78
- Carousel.prototype.componentDidMount = function () {
79
- var _this = this;
80
+ Carousel.prototype.componentDidMount = function () {};
80
81
 
81
- this.intersectionObserver = new IntersectionObserver(function (entries) {
82
- if (entries[0].isIntersecting) {
83
- _this.setState({
84
- show: true
85
- });
86
- }
87
- }, {
88
- root: null,
89
- // threshold: 0.8,
90
- rootMargin: '0px 0px 100px 0px'
91
- });
92
- this.intersectionObserver.observe(this.carouselRef.current);
93
- };
94
-
95
- Carousel.prototype.componentWillUnmount = function () {
96
- this.intersectionObserver.disconnect(this.carouselRef.current);
97
- };
82
+ Carousel.prototype.componentWillUnmount = function () {};
98
83
 
99
84
  Carousel.prototype.render = function () {
100
85
  var nodeData = this.props.nodeData;
101
- var show = this.state.show;
86
+ var lazyShow = this.state.lazyShow;
102
87
  return /*#__PURE__*/_react["default"].createElement("div", {
103
- ref: this.carouselRef
104
- }, show && (window.magicDesign.device === 'pc' ? /*#__PURE__*/_react["default"].createElement(_pc["default"], {
88
+ ref: this.carouselRef,
89
+ style: {
90
+ height: lazyShow ? 'auto' : 300
91
+ }
92
+ }, lazyShow && (window.magicDesign.device === 'pc' ? /*#__PURE__*/_react["default"].createElement(_pc["default"], {
105
93
  data: nodeData
106
94
  }) : /*#__PURE__*/_react["default"].createElement(_mobile["default"], {
107
95
  data: nodeData
@@ -111,6 +99,11 @@ function (_super) {
111
99
  Carousel.defaultProps = {};
112
100
  Carousel.type = 'CAROUSEL';
113
101
  Carousel.getDefaultJSON = _defaultJSON.getDefaultJSON;
102
+
103
+ __decorate([(0, _decorator.lazy)('carouselRef')], Carousel.prototype, "componentDidMount", null);
104
+
105
+ __decorate([_decorator.lazyDestroy], Carousel.prototype, "componentWillUnmount", null);
106
+
114
107
  Carousel = __decorate([_compositeDecorator["default"]], Carousel);
115
108
  return Carousel;
116
109
  }(_react.Component);
@@ -73,24 +73,13 @@ var __assign = void 0 && (void 0).__assign || function () {
73
73
  return __assign.apply(this, arguments);
74
74
  };
75
75
 
76
- var MOBILE_IMG_SIZE = {
77
- 1: {
78
- maxH: 282
79
- },
80
- 2: {
81
- maxH: 137
82
- },
83
- 3: {
84
- maxH: 87
85
- },
86
- 4: {
87
- maxH: 66
88
- },
89
- 5: {
90
- maxH: 50
91
- }
92
- };
93
-
76
+ // const MOBILE_IMG_SIZE = {
77
+ // 1: { maxH: 282 },
78
+ // 2: { maxH: 137 },
79
+ // 3: { maxH: 87 },
80
+ // 4: { maxH: 66 },
81
+ // 5: { maxH: 50 },
82
+ // };
94
83
  var CarouselMobile =
95
84
  /** @class */
96
85
  function (_super) {
@@ -9,6 +9,18 @@ Object.defineProperty(exports, "compositeDecorator", {
9
9
  return _compositeDecorator["default"];
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "lazy", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _lazyLoadDecorator.lazy;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "lazyDestroy", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _lazyLoadDecorator.lazyDestroy;
22
+ }
23
+ });
12
24
  Object.defineProperty(exports, "metaDecorator", {
13
25
  enumerable: true,
14
26
  get: function get() {
@@ -28,4 +40,6 @@ var _metaDecorator = _interopRequireDefault(require("./metaDecorator"));
28
40
 
29
41
  var _updateConfigDecorator = _interopRequireDefault(require("./updateConfigDecorator"));
30
42
 
43
+ var _lazyLoadDecorator = require("./lazyLoadDecorator");
44
+
31
45
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.lazy = lazy;
7
+ exports.lazyDestroy = void 0;
8
+
9
+ /**
10
+ * 组件懒加载
11
+ * @param refName 所需懒加载的组件ref名
12
+ * @returns
13
+ */
14
+ function lazy(refName) {
15
+ return function (target, name, descriptor) {
16
+ var fn = descriptor.value;
17
+
18
+ descriptor.value = function () {
19
+ var _this = this;
20
+
21
+ var rest = [];
22
+
23
+ for (var _i = 0; _i < arguments.length; _i++) {
24
+ rest[_i] = arguments[_i];
25
+ }
26
+
27
+ this.intersectionObserver = new IntersectionObserver(function (entries) {
28
+ if (entries[0].isIntersecting) {
29
+ if (!_this.state.lazyShow) {
30
+ _this.setState({
31
+ lazyShow: true
32
+ });
33
+ }
34
+ }
35
+ }, {
36
+ root: null,
37
+ // threshold: 0.8,
38
+ rootMargin: '0px 0px 100px 0px'
39
+ });
40
+ this.intersectionObserver.observe(this[refName].current);
41
+ /** 监听状态变化 */
42
+
43
+ this._intersectionObserverDestroy = function () {
44
+ _this.intersectionObserver.disconnect(_this[refName].current);
45
+ };
46
+
47
+ fn.apply(this, rest);
48
+ };
49
+ };
50
+ }
51
+ /**
52
+ * 销毁lazy监听
53
+ */
54
+
55
+
56
+ var lazyDestroy = function lazyDestroy(target, name, descriptor) {
57
+ var fn = descriptor.value;
58
+
59
+ descriptor.value = function () {
60
+ var rest = [];
61
+
62
+ for (var _i = 0; _i < arguments.length; _i++) {
63
+ rest[_i] = arguments[_i];
64
+ }
65
+
66
+ if (this._intersectionObserverDestroy) {
67
+ this._intersectionObserverDestroy();
68
+ } // this._intersectionObserverDestroy && this._intersectionObserverDestroy();
69
+
70
+
71
+ fn.apply(this, rest);
72
+ };
73
+ };
74
+
75
+ exports.lazyDestroy = lazyDestroy;
@@ -100,9 +100,11 @@ function (_super) {
100
100
 
101
101
  this.intersectionObserver = new IntersectionObserver(function (entries) {
102
102
  if (entries[0].isIntersecting) {
103
- _this.setState({
104
- show: true
105
- });
103
+ if (!_this.state.show) {
104
+ _this.setState({
105
+ show: true
106
+ });
107
+ }
106
108
  }
107
109
  }, {
108
110
  root: (_a = this.props) === null || _a === void 0 ? void 0 : _a.rootContainer(),
@@ -120,14 +122,13 @@ function (_super) {
120
122
  var _this = this;
121
123
 
122
124
  var _a = this.props,
123
- root = _a.root,
124
125
  _b = _a.lazy,
125
126
  lazy = _b === void 0 ? true : _b,
126
127
  src = _a.src,
127
128
  onLoadFunc = _a.onLoadFunc,
128
129
  style = _a.style,
129
130
  className = _a.className,
130
- rest = __rest(_a, ["root", "lazy", "src", "onLoadFunc", "style", "className"]);
131
+ rest = __rest(_a, ["lazy", "src", "onLoadFunc", "style", "className"]);
131
132
 
132
133
  var show = this.state.show;
133
134
  var isShow = lazy ? show : true;
@@ -15,6 +15,8 @@ var _defaultJSON = require("./defaultJSON");
15
15
 
16
16
  var _compositeDecorator = _interopRequireDefault(require("../../../../decorator/compositeDecorator"));
17
17
 
18
+ var _decorator = require("../../../../decorator");
19
+
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
21
 
20
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -68,40 +70,26 @@ function (_super) {
68
70
  var _this = _super !== null && _super.apply(this, arguments) || this;
69
71
 
70
72
  _this.state = {
71
- show: false
73
+ lazyShow: false
72
74
  };
73
75
  _this.carouselRef = /*#__PURE__*/_react["default"].createRef();
74
76
  _this.intersectionObserver = null;
75
77
  return _this;
76
78
  }
77
79
 
78
- Carousel.prototype.componentDidMount = function () {
79
- var _this = this;
80
+ Carousel.prototype.componentDidMount = function () {};
80
81
 
81
- this.intersectionObserver = new IntersectionObserver(function (entries) {
82
- if (entries[0].isIntersecting) {
83
- _this.setState({
84
- show: true
85
- });
86
- }
87
- }, {
88
- root: null,
89
- // threshold: 0.8,
90
- rootMargin: '0px 0px 100px 0px'
91
- });
92
- this.intersectionObserver.observe(this.carouselRef.current);
93
- };
94
-
95
- Carousel.prototype.componentWillUnmount = function () {
96
- this.intersectionObserver.disconnect(this.carouselRef.current);
97
- };
82
+ Carousel.prototype.componentWillUnmount = function () {};
98
83
 
99
84
  Carousel.prototype.render = function () {
100
85
  var nodeData = this.props.nodeData;
101
- var show = this.state.show;
86
+ var lazyShow = this.state.lazyShow;
102
87
  return /*#__PURE__*/_react["default"].createElement("div", {
103
- ref: this.carouselRef
104
- }, show && (window.magicDesign.device === 'pc' ? /*#__PURE__*/_react["default"].createElement(_pc["default"], {
88
+ ref: this.carouselRef,
89
+ style: {
90
+ height: lazyShow ? 'auto' : 300
91
+ }
92
+ }, lazyShow && (window.magicDesign.device === 'pc' ? /*#__PURE__*/_react["default"].createElement(_pc["default"], {
105
93
  data: nodeData
106
94
  }) : /*#__PURE__*/_react["default"].createElement(_mobile["default"], {
107
95
  data: nodeData
@@ -111,6 +99,11 @@ function (_super) {
111
99
  Carousel.defaultProps = {};
112
100
  Carousel.type = 'CAROUSEL';
113
101
  Carousel.getDefaultJSON = _defaultJSON.getDefaultJSON;
102
+
103
+ __decorate([(0, _decorator.lazy)('carouselRef')], Carousel.prototype, "componentDidMount", null);
104
+
105
+ __decorate([_decorator.lazyDestroy], Carousel.prototype, "componentWillUnmount", null);
106
+
114
107
  Carousel = __decorate([_compositeDecorator["default"]], Carousel);
115
108
  return Carousel;
116
109
  }(_react.Component);
@@ -73,24 +73,13 @@ var __assign = void 0 && (void 0).__assign || function () {
73
73
  return __assign.apply(this, arguments);
74
74
  };
75
75
 
76
- var MOBILE_IMG_SIZE = {
77
- 1: {
78
- maxH: 282
79
- },
80
- 2: {
81
- maxH: 137
82
- },
83
- 3: {
84
- maxH: 87
85
- },
86
- 4: {
87
- maxH: 66
88
- },
89
- 5: {
90
- maxH: 50
91
- }
92
- };
93
-
76
+ // const MOBILE_IMG_SIZE = {
77
+ // 1: { maxH: 282 },
78
+ // 2: { maxH: 137 },
79
+ // 3: { maxH: 87 },
80
+ // 4: { maxH: 66 },
81
+ // 5: { maxH: 50 },
82
+ // };
94
83
  var CarouselMobile =
95
84
  /** @class */
96
85
  function (_super) {
@@ -9,6 +9,18 @@ Object.defineProperty(exports, "compositeDecorator", {
9
9
  return _compositeDecorator["default"];
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "lazy", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _lazyLoadDecorator.lazy;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "lazyDestroy", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _lazyLoadDecorator.lazyDestroy;
22
+ }
23
+ });
12
24
  Object.defineProperty(exports, "metaDecorator", {
13
25
  enumerable: true,
14
26
  get: function get() {
@@ -28,4 +40,6 @@ var _metaDecorator = _interopRequireDefault(require("./metaDecorator"));
28
40
 
29
41
  var _updateConfigDecorator = _interopRequireDefault(require("./updateConfigDecorator"));
30
42
 
43
+ var _lazyLoadDecorator = require("./lazyLoadDecorator");
44
+
31
45
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.lazy = lazy;
7
+ exports.lazyDestroy = void 0;
8
+
9
+ /**
10
+ * 组件懒加载
11
+ * @param refName 所需懒加载的组件ref名
12
+ * @returns
13
+ */
14
+ function lazy(refName) {
15
+ return function (target, name, descriptor) {
16
+ var fn = descriptor.value;
17
+
18
+ descriptor.value = function () {
19
+ var _this = this;
20
+
21
+ var rest = [];
22
+
23
+ for (var _i = 0; _i < arguments.length; _i++) {
24
+ rest[_i] = arguments[_i];
25
+ }
26
+
27
+ this.intersectionObserver = new IntersectionObserver(function (entries) {
28
+ if (entries[0].isIntersecting) {
29
+ if (!_this.state.lazyShow) {
30
+ _this.setState({
31
+ lazyShow: true
32
+ });
33
+ }
34
+ }
35
+ }, {
36
+ root: null,
37
+ // threshold: 0.8,
38
+ rootMargin: '0px 0px 100px 0px'
39
+ });
40
+ this.intersectionObserver.observe(this[refName].current);
41
+ /** 监听状态变化 */
42
+
43
+ this._intersectionObserverDestroy = function () {
44
+ _this.intersectionObserver.disconnect(_this[refName].current);
45
+ };
46
+
47
+ fn.apply(this, rest);
48
+ };
49
+ };
50
+ }
51
+ /**
52
+ * 销毁lazy监听
53
+ */
54
+
55
+
56
+ var lazyDestroy = function lazyDestroy(target, name, descriptor) {
57
+ var fn = descriptor.value;
58
+
59
+ descriptor.value = function () {
60
+ var rest = [];
61
+
62
+ for (var _i = 0; _i < arguments.length; _i++) {
63
+ rest[_i] = arguments[_i];
64
+ }
65
+
66
+ if (this._intersectionObserverDestroy) {
67
+ this._intersectionObserverDestroy();
68
+ } // this._intersectionObserverDestroy && this._intersectionObserverDestroy();
69
+
70
+
71
+ fn.apply(this, rest);
72
+ };
73
+ };
74
+
75
+ exports.lazyDestroy = lazyDestroy;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fonixtree/magic-design",
3
3
  "author": "Cylon Team",
4
- "version": "2.0.30",
4
+ "version": "2.0.31",
5
5
  "description": "Magic Design",
6
6
  "license": "MIT",
7
7
  "module": "es/index.js",
Binary file
Binary file