shineout 3.8.0-beta.13 → 3.8.0-beta.15

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/index.js CHANGED
@@ -522,5 +522,5 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
522
522
  // 此文件由脚本自动生成,请勿直接修改。
523
523
  // This file was generated automatically by a script. Please do not modify it directly.
524
524
  var _default = exports.default = {
525
- version: '3.8.0-beta.13'
525
+ version: '3.8.0-beta.15'
526
526
  };
package/dist/shineout.js CHANGED
@@ -12234,7 +12234,7 @@ var handleStyle = function handleStyle(style) {
12234
12234
  };
12235
12235
  /* harmony default export */ var jss_style_handleStyle = (handleStyle);
12236
12236
  ;// CONCATENATED MODULE: ../shineout-style/src/version.ts
12237
- /* harmony default export */ var version = ('3.8.0-beta.13');
12237
+ /* harmony default export */ var version = ('3.8.0-beta.15');
12238
12238
  ;// CONCATENATED MODULE: ../shineout-style/src/jss-style/index.tsx
12239
12239
 
12240
12240
 
@@ -61403,23 +61403,16 @@ var sticky_cssSupport = cssSupport,
61403
61403
  var supportSticky = sticky_cssSupport('position', 'sticky');
61404
61404
  var defaultZIndex = 900;
61405
61405
  var events = ['scroll', 'pageshow', 'load', 'resize'];
61406
-
61407
- // const getFirstScrollParent = (el: HTMLElement) => {
61408
- // let parent = el.parentNode as HTMLElement;
61409
- // while (parent) {
61410
- // if (parent === document.body || parent === document.documentElement) {
61411
- // parent = document.body;
61412
- // break;
61413
- // }
61414
- // const { overflowY } = window.getComputedStyle(parent);
61415
- // if (overflowY === 'scroll' || overflowY === 'auto') {
61416
- // break;
61417
- // }
61418
- // parent = parent.parentNode as HTMLElement;
61419
- // }
61420
- // return parent;
61421
- // };
61422
-
61406
+ function getStaticTop(el) {
61407
+ var stopper = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;
61408
+ var top = 0;
61409
+ var currentEl = el;
61410
+ while (currentEl && currentEl !== stopper) {
61411
+ top += currentEl.offsetTop;
61412
+ currentEl = currentEl.offsetParent;
61413
+ }
61414
+ return top;
61415
+ }
61423
61416
  var Sticky = function Sticky(props) {
61424
61417
  if (props.target) {
61425
61418
  sticky_devUseWarning.deprecated('target', 'scrollContainer', 'Sticky');
@@ -61430,13 +61423,16 @@ var Sticky = function Sticky(props) {
61430
61423
  // 是否使用css sticky
61431
61424
  var css = (props.css || props.target) && supportSticky;
61432
61425
  var forceUpdate = useRender();
61426
+ var fixedStickyElRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
61433
61427
  var _useRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)({
61434
61428
  target: null,
61435
61429
  div: null,
61436
61430
  position: '',
61437
61431
  targetObserver: null,
61438
61432
  parentObserver: null,
61439
- fixedObserver: null
61433
+ fixedObserver: null,
61434
+ stoped: false,
61435
+ originPosition: null
61440
61436
  }),
61441
61437
  context = _useRef.current;
61442
61438
  var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)({}),
@@ -61452,6 +61448,77 @@ var Sticky = function Sticky(props) {
61452
61448
  parentVisible = _useState6[0],
61453
61449
  setParentVisible = _useState6[1];
61454
61450
  var elementRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
61451
+ var onStickyBoundaryChange = usePersistFn(function (e) {
61452
+ var target = e.target;
61453
+ var isDocument = !context.target || context.target === document.documentElement;
61454
+ var scrollTop = isDocument ? window.scrollY : target.scrollTop;
61455
+ if (!target || typeof scrollTop !== 'number') return;
61456
+ var stopStickyPoint = -1;
61457
+ var baseTop = 0;
61458
+ var absoluteTop = 0;
61459
+ var absoluteLeft = 0;
61460
+ var stopStickyElement = null;
61461
+ if (typeof props.stickyBoundary === 'number') {
61462
+ stopStickyPoint = props.stickyBoundary;
61463
+ } else if (typeof props.stickyBoundary === 'function') {
61464
+ stopStickyElement = props.stickyBoundary();
61465
+ if (!stopStickyElement) return;
61466
+ var stopStickyRect = stopStickyElement.getBoundingClientRect();
61467
+ var targetRect = elementRef.current.getBoundingClientRect();
61468
+ if (context.target === document.documentElement || !context.target) {
61469
+ baseTop = getStaticTop(elementRef.current) - (props.top || 0);
61470
+ absoluteTop = stopStickyRect.bottom - targetRect.bottom;
61471
+ absoluteLeft = stopStickyRect.left - targetRect.left;
61472
+ }
61473
+ stopStickyPoint = stopStickyRect.bottom - targetRect.bottom + baseTop;
61474
+ }
61475
+ if (stopStickyPoint < 0) return;
61476
+ if (scrollTop > stopStickyPoint) {
61477
+ if (context.stoped) return;
61478
+ context.stoped = true;
61479
+
61480
+ // 把 div 移动到 target 内部,使用 absolute 定位跟随滚动
61481
+ if (context.div && context.target) {
61482
+ context.target.insertBefore(context.div, context.target.firstChild);
61483
+ var paddingLeft = Number(window.getComputedStyle(context.target).paddingLeft.replace('px', '')) || 0;
61484
+ var borderLeftWidth = Number(window.getComputedStyle(context.target).borderLeftWidth.replace('px', '')) || 0;
61485
+ var left = paddingLeft + borderLeftWidth;
61486
+ context.div.style.transform = "translate(-".concat(left, "px, ").concat(stopStickyPoint, "px)");
61487
+ } else {
61488
+ if (stopStickyElement) {
61489
+ if (!fixedStickyElRef.current) return;
61490
+ // 存储原始位置到 context 中
61491
+ if (!context.originPosition) {
61492
+ var originStyle = window.getComputedStyle(fixedStickyElRef.current);
61493
+ context.originPosition = {
61494
+ top: originStyle.top,
61495
+ left: originStyle.left
61496
+ };
61497
+ }
61498
+
61499
+ // 直接操作DOM的原因是:不闪烁且性能更好
61500
+ stopStickyElement.style.transform = "translateZ(0)";
61501
+ fixedStickyElRef.current.style.top = "".concat(absoluteTop, "px");
61502
+ fixedStickyElRef.current.style.left = "".concat(absoluteLeft, "px");
61503
+ }
61504
+ // 暂不支持 props.stickyBoundary 为 number 的fixed定位情况
61505
+ }
61506
+ } else {
61507
+ if (!context.stoped) return;
61508
+ context.stoped = false;
61509
+
61510
+ // 恢复正常吸附模式:把 div 移动到 target 外部
61511
+ if (context.div && context.target && context.target.parentNode) {
61512
+ context.target.parentNode.insertBefore(context.div, context.target);
61513
+ context.div.style.transform = 'none';
61514
+ } else if (stopStickyElement && fixedStickyElRef.current && context.originPosition) {
61515
+ stopStickyElement.style.transform = "none";
61516
+ fixedStickyElRef.current.style.top = context.originPosition.top;
61517
+ fixedStickyElRef.current.style.left = context.originPosition.left;
61518
+ context.originPosition = null; // 清理状态
61519
+ }
61520
+ }
61521
+ });
61455
61522
  var getTarget = function getTarget() {
61456
61523
  var scrollContainer = props.scrollContainer;
61457
61524
  if (typeof scrollContainer === 'string') {
@@ -61693,6 +61760,10 @@ var Sticky = function Sticky(props) {
61693
61760
  context.div.remove();
61694
61761
  context.div = null;
61695
61762
  }
61763
+ if (props.stickyBoundary) {
61764
+ var _context$target;
61765
+ (_context$target = context.target) === null || _context$target === void 0 || _context$target.removeEventListener('scroll', onStickyBoundaryChange);
61766
+ }
61696
61767
  };
61697
61768
  var createFixedEvents = function createFixedEvents() {
61698
61769
  createFixedObserver();
@@ -61705,6 +61776,10 @@ var Sticky = function Sticky(props) {
61705
61776
  events.forEach(function (event) {
61706
61777
  window.removeEventListener(event, handleFixedPosition);
61707
61778
  });
61779
+ if (props.stickyBoundary) {
61780
+ var _context$target2;
61781
+ (_context$target2 = context.target) === null || _context$target2 === void 0 || _context$target2.removeEventListener('scroll', onStickyBoundaryChange);
61782
+ }
61708
61783
  };
61709
61784
  var handleElementRef = function handleElementRef(el) {
61710
61785
  if (el) {
@@ -61732,7 +61807,15 @@ var Sticky = function Sticky(props) {
61732
61807
  context.target = target;
61733
61808
  forceUpdate();
61734
61809
  }
61735
- if (context.target) {
61810
+ if (props.stickyBoundary) {
61811
+ if (!context.target || context.target === document.documentElement) {
61812
+ window.addEventListener('scroll', onStickyBoundaryChange);
61813
+ } else {
61814
+ var _context$target3;
61815
+ (_context$target3 = context.target) === null || _context$target3 === void 0 || _context$target3.addEventListener('scroll', onStickyBoundaryChange);
61816
+ }
61817
+ }
61818
+ if (context.target && context.target !== document.documentElement) {
61736
61819
  createTargetEvents();
61737
61820
  return cancelTargetEvents;
61738
61821
  } else {
@@ -61753,7 +61836,6 @@ var Sticky = function Sticky(props) {
61753
61836
  if (props.onChange) {
61754
61837
  props.onChange(show);
61755
61838
  }
61756
- ;
61757
61839
  }, [show]);
61758
61840
 
61759
61841
  // 纯css方法 直接使用css
@@ -61778,6 +61860,7 @@ var Sticky = function Sticky(props) {
61778
61860
  style: objectSpread2_default()(objectSpread2_default()({
61779
61861
  zIndex: defaultZIndex
61780
61862
  }, style), elementSize),
61863
+ ref: fixedStickyElRef,
61781
61864
  children: /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
61782
61865
  className: props.className,
61783
61866
  style: props.style,
@@ -72008,7 +72091,7 @@ var upload_interface = __webpack_require__(8821);
72008
72091
 
72009
72092
 
72010
72093
  /* harmony default export */ var src_0 = ({
72011
- version: '3.8.0-beta.13'
72094
+ version: '3.8.0-beta.15'
72012
72095
  });
72013
72096
  }();
72014
72097
  /******/ return __webpack_exports__;