@sheinx/base 3.4.5-beta.1 → 3.4.5-beta.3

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.
package/cjs/card/card.js CHANGED
@@ -27,7 +27,9 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
27
27
  var Card = function Card(props) {
28
28
  var _props$jssStyle, _props$jssStyle$card, _props$id;
29
29
  var _props$style = props.style,
30
- style = _props$style === void 0 ? {} : _props$style;
30
+ style = _props$style === void 0 ? {} : _props$style,
31
+ _props$defaultCollaps = props.defaultCollapsed,
32
+ defaultCollapsed = _props$defaultCollaps === void 0 ? true : _props$defaultCollaps;
31
33
  var cardClasses = (_props$jssStyle = props.jssStyle) === null || _props$jssStyle === void 0 || (_props$jssStyle$card = _props$jssStyle.card) === null || _props$jssStyle$card === void 0 ? void 0 : _props$jssStyle$card.call(_props$jssStyle);
32
34
  var panelRef = (0, _react.useRef)(null);
33
35
  var forceUpdate = (0, _hooks.useRender)();
@@ -35,7 +37,7 @@ var Card = function Card(props) {
35
37
  id: undefined
36
38
  }),
37
39
  context = _useRef.current;
38
- var _useState = (0, _react.useState)(props.defaultCollapsed),
40
+ var _useState = (0, _react.useState)(defaultCollapsed),
39
41
  _useState2 = _slicedToArray(_useState, 2),
40
42
  collapsed = _useState2[0],
41
43
  setCollapsed = _useState2[1];
@@ -1 +1 @@
1
- {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["item.tsx"],"names":[],"mappings":";AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,QAAA,MAAM,IAAI,kDAiDT,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["item.tsx"],"names":[],"mappings":";AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,QAAA,MAAM,IAAI,kDAiET,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
@@ -14,20 +15,32 @@ var _jsxRuntime = require("react/jsx-runtime");
14
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
16
  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); }
16
17
  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 && Object.prototype.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; }
17
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
18
18
  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; }
19
19
  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) { _defineProperty(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; }
20
20
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
22
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
24
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
26
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
27
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
28
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
29
  var Item = function Item(props) {
24
30
  var _props$jssStyle, _props$jssStyle$cardG;
25
31
  var _useContext = (0, _react.useContext)(_cardGroupContext.CardGroupContext),
26
32
  container = _useContext.container;
27
33
  var classes = (_props$jssStyle = props.jssStyle) === null || _props$jssStyle === void 0 || (_props$jssStyle$cardG = _props$jssStyle.cardGroup) === null || _props$jssStyle$cardG === void 0 ? void 0 : _props$jssStyle$cardG.call(_props$jssStyle);
28
- var _useInView = (0, _hooks.useInView)(),
34
+ var _useInView = (0, _hooks.useInView)({
35
+ root: container,
36
+ rootMargin: "".concat((container === null || container === void 0 ? void 0 : container.clientHeight) || 100, "px")
37
+ }),
29
38
  itemRef = _useInView.ref,
30
39
  isInView = _useInView.isInView;
40
+ var _useState = (0, _react.useState)(0),
41
+ _useState2 = _slicedToArray(_useState, 2),
42
+ itemHeight = _useState2[0],
43
+ setItemHeight = _useState2[1];
31
44
  var handleChange = (0, _hooks.usePersistFn)(function (_, checked) {
32
45
  if (props.onChange) props.onChange(checked, props.value);
33
46
  });
@@ -37,6 +50,7 @@ var Item = function Item(props) {
37
50
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_lazyload.default, {
38
51
  container: container,
39
52
  placeholder: props.placeholder,
53
+ isInView: isInView,
40
54
  children: content
41
55
  });
42
56
  };
@@ -51,11 +65,22 @@ var Item = function Item(props) {
51
65
  className: classes === null || classes === void 0 ? void 0 : classes.checkbox
52
66
  })]
53
67
  });
54
- var itemStyle = (0, _react.useMemo)(function () {
55
- return _objectSpread(_objectSpread({}, props.style), {}, {
68
+ (0, _react.useEffect)(function () {
69
+ if (isInView) {
70
+ var _itemRef$current;
71
+ setItemHeight(((_itemRef$current = itemRef.current) === null || _itemRef$current === void 0 ? void 0 : _itemRef$current.clientHeight) || 0);
72
+ }
73
+ }, [isInView]);
74
+ var hiddenStyle = (0, _react.useMemo)(function () {
75
+ return isInView ? {} : {
76
+ height: itemHeight,
77
+ overflow: 'hidden',
56
78
  visibility: isInView ? 'visible' : 'hidden'
57
- });
58
- }, [isInView, props.style]);
79
+ };
80
+ }, [isInView, itemHeight]);
81
+ var itemStyle = (0, _react.useMemo)(function () {
82
+ return _objectSpread(_objectSpread({}, props.style), hiddenStyle);
83
+ }, [hiddenStyle, props.style]);
59
84
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
60
85
  ref: itemRef,
61
86
  className: cls,
@@ -4,6 +4,7 @@ export interface LazyloadProps {
4
4
  placeholder?: React.ReactNode;
5
5
  container?: HTMLElement;
6
6
  offset?: number;
7
+ isInView?: boolean;
7
8
  }
8
9
  declare const Lazyload: (props: LazyloadProps) => JSX.Element;
9
10
  export default Lazyload;
@@ -1 +1 @@
1
- {"version":3,"file":"lazyload.d.ts","sourceRoot":"","sources":["lazyload.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAK3D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,QAAA,MAAM,QAAQ,UAAW,aAAa,gBAyBrC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"lazyload.d.ts","sourceRoot":"","sources":["lazyload.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAK3D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,QAAA,MAAM,QAAQ,UAAW,aAAa,gBAyBrC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -38,7 +38,7 @@ var Lazyload = function Lazyload(props) {
38
38
  removeStack(lazyId);
39
39
  };
40
40
  }, []);
41
- if (ready) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
41
+ if (ready && props.isInView) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
42
42
  children: props.children
43
43
  });
44
44
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
package/esm/card/card.js CHANGED
@@ -22,7 +22,9 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
22
22
  var Card = function Card(props) {
23
23
  var _props$jssStyle, _props$jssStyle$card, _props$id;
24
24
  var _props$style = props.style,
25
- style = _props$style === void 0 ? {} : _props$style;
25
+ style = _props$style === void 0 ? {} : _props$style,
26
+ _props$defaultCollaps = props.defaultCollapsed,
27
+ defaultCollapsed = _props$defaultCollaps === void 0 ? true : _props$defaultCollaps;
26
28
  var cardClasses = (_props$jssStyle = props.jssStyle) === null || _props$jssStyle === void 0 || (_props$jssStyle$card = _props$jssStyle.card) === null || _props$jssStyle$card === void 0 ? void 0 : _props$jssStyle$card.call(_props$jssStyle);
27
29
  var panelRef = useRef(null);
28
30
  var forceUpdate = useRender();
@@ -30,7 +32,7 @@ var Card = function Card(props) {
30
32
  id: undefined
31
33
  }),
32
34
  context = _useRef.current;
33
- var _useState = useState(props.defaultCollapsed),
35
+ var _useState = useState(defaultCollapsed),
34
36
  _useState2 = _slicedToArray(_useState, 2),
35
37
  collapsed = _useState2[0],
36
38
  setCollapsed = _useState2[1];
@@ -1 +1 @@
1
- {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["item.tsx"],"names":[],"mappings":";AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,QAAA,MAAM,IAAI,kDAiDT,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["item.tsx"],"names":[],"mappings":";AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,QAAA,MAAM,IAAI,kDAiET,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -4,7 +4,13 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import React, { useContext, useMemo } from 'react';
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import React, { useContext, useEffect, useMemo, useState } from 'react';
8
14
  import { useInView, usePersistFn } from '@sheinx/hooks';
9
15
  import classNames from 'classnames';
10
16
  import { CardGroupContext } from "./card-group-context";
@@ -18,9 +24,16 @@ var Item = function Item(props) {
18
24
  var _useContext = useContext(CardGroupContext),
19
25
  container = _useContext.container;
20
26
  var classes = (_props$jssStyle = props.jssStyle) === null || _props$jssStyle === void 0 || (_props$jssStyle$cardG = _props$jssStyle.cardGroup) === null || _props$jssStyle$cardG === void 0 ? void 0 : _props$jssStyle$cardG.call(_props$jssStyle);
21
- var _useInView = useInView(),
27
+ var _useInView = useInView({
28
+ root: container,
29
+ rootMargin: "".concat((container === null || container === void 0 ? void 0 : container.clientHeight) || 100, "px")
30
+ }),
22
31
  itemRef = _useInView.ref,
23
32
  isInView = _useInView.isInView;
33
+ var _useState = useState(0),
34
+ _useState2 = _slicedToArray(_useState, 2),
35
+ itemHeight = _useState2[0],
36
+ setItemHeight = _useState2[1];
24
37
  var handleChange = usePersistFn(function (_, checked) {
25
38
  if (props.onChange) props.onChange(checked, props.value);
26
39
  });
@@ -30,6 +43,7 @@ var Item = function Item(props) {
30
43
  return /*#__PURE__*/_jsx(Lazyload, {
31
44
  container: container,
32
45
  placeholder: props.placeholder,
46
+ isInView: isInView,
33
47
  children: content
34
48
  });
35
49
  };
@@ -44,11 +58,22 @@ var Item = function Item(props) {
44
58
  className: classes === null || classes === void 0 ? void 0 : classes.checkbox
45
59
  })]
46
60
  });
47
- var itemStyle = useMemo(function () {
48
- return _objectSpread(_objectSpread({}, props.style), {}, {
61
+ useEffect(function () {
62
+ if (isInView) {
63
+ var _itemRef$current;
64
+ setItemHeight(((_itemRef$current = itemRef.current) === null || _itemRef$current === void 0 ? void 0 : _itemRef$current.clientHeight) || 0);
65
+ }
66
+ }, [isInView]);
67
+ var hiddenStyle = useMemo(function () {
68
+ return isInView ? {} : {
69
+ height: itemHeight,
70
+ overflow: 'hidden',
49
71
  visibility: isInView ? 'visible' : 'hidden'
50
- });
51
- }, [isInView, props.style]);
72
+ };
73
+ }, [isInView, itemHeight]);
74
+ var itemStyle = useMemo(function () {
75
+ return _objectSpread(_objectSpread({}, props.style), hiddenStyle);
76
+ }, [hiddenStyle, props.style]);
52
77
  return /*#__PURE__*/_jsx("div", {
53
78
  ref: itemRef,
54
79
  className: cls,
@@ -4,6 +4,7 @@ export interface LazyloadProps {
4
4
  placeholder?: React.ReactNode;
5
5
  container?: HTMLElement;
6
6
  offset?: number;
7
+ isInView?: boolean;
7
8
  }
8
9
  declare const Lazyload: (props: LazyloadProps) => JSX.Element;
9
10
  export default Lazyload;
@@ -1 +1 @@
1
- {"version":3,"file":"lazyload.d.ts","sourceRoot":"","sources":["lazyload.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAK3D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,QAAA,MAAM,QAAQ,UAAW,aAAa,gBAyBrC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"lazyload.d.ts","sourceRoot":"","sources":["lazyload.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAK3D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,QAAA,MAAM,QAAQ,UAAW,aAAa,gBAyBrC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -30,7 +30,7 @@ var Lazyload = function Lazyload(props) {
30
30
  removeStack(lazyId);
31
31
  };
32
32
  }, []);
33
- if (ready) return /*#__PURE__*/_jsx(_Fragment, {
33
+ if (ready && props.isInView) return /*#__PURE__*/_jsx(_Fragment, {
34
34
  children: props.children
35
35
  });
36
36
  return /*#__PURE__*/_jsx("span", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/base",
3
- "version": "3.4.5-beta.1",
3
+ "version": "3.4.5-beta.3",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "module": "./esm/index.js",
11
11
  "typings": "./cjs/index.d.ts",
12
12
  "dependencies": {
13
- "@sheinx/hooks": "3.4.5-beta.1",
13
+ "@sheinx/hooks": "3.4.5-beta.3",
14
14
  "immer": "^10.0.0",
15
15
  "classnames": "^2.0.0",
16
16
  "@shined/reactive": "^0.1.3-alpha.0"