@kkkarsss/ui 1.4.9 → 1.4.10

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.
@@ -32,7 +32,7 @@ export const CalendarLike = ({ tasks, slots = DEFAULT_SLOTS, showCurrentTime = t
32
32
  const tasksBySlot = useMemo(() => groupTasksBySlot(tasksWithPosition), [tasksWithPosition]);
33
33
  useEffect(() => {
34
34
  if (showCurrentTime && autoScrollToCurrentTime && containerRef.current) {
35
- const scroll = () => {
35
+ const scroll = (retryCount = 0) => {
36
36
  if (!containerRef.current)
37
37
  return;
38
38
  const now = new Date();
@@ -46,22 +46,44 @@ export const CalendarLike = ({ tasks, slots = DEFAULT_SLOTS, showCurrentTime = t
46
46
  if (!node)
47
47
  return null;
48
48
  const style = window.getComputedStyle(node);
49
- if (/(auto|scroll)/.test(style.overflow + style.overflowY))
49
+ const overflow = style.overflow + style.overflowY + style.overflowX;
50
+ if (/(auto|scroll)/.test(overflow))
50
51
  return node;
51
52
  return scrollParent(node.parentElement);
52
53
  };
53
54
  const parent = scrollParent(containerRef.current);
54
55
  if (parent) {
55
- const containerRect = containerRef.current.getBoundingClientRect();
56
- const parentRect = parent.getBoundingClientRect();
57
- const relativeTop = containerRect.top - parentRect.top + parent.scrollTop;
56
+ const getRelativeOffsetTop = (target, ancestor) => {
57
+ let offset = 0;
58
+ let current = target;
59
+ while (current && current !== ancestor) {
60
+ offset += current.offsetTop;
61
+ current = current.offsetParent;
62
+ }
63
+ return offset;
64
+ };
65
+ const relativeTop = getRelativeOffsetTop(containerRef.current, parent);
66
+ // Если relativeTop равен 0 и это не начало дня, возможно DOM еще не готов
67
+ if (relativeTop === 0 && totalMinutes > 60 && retryCount < 5) {
68
+ setTimeout(() => scroll(retryCount + 1), 100);
69
+ return;
70
+ }
71
+ console.log('CalendarLike scroll:', {
72
+ totalMinutes,
73
+ topOffset,
74
+ parentScrollTop: parent.scrollTop,
75
+ parentClientHeight: parent.clientHeight,
76
+ relativeTop,
77
+ retryCount,
78
+ scrollTarget: relativeTop + topOffset - parent.clientHeight / 2,
79
+ });
58
80
  parent.scrollTo({
59
81
  top: relativeTop + topOffset - parent.clientHeight / 2,
60
82
  behavior: 'smooth',
61
83
  });
62
84
  }
63
85
  };
64
- const timeoutId = setTimeout(scroll, 100);
86
+ const timeoutId = setTimeout(() => scroll(0), 100);
65
87
  return () => clearTimeout(timeoutId);
66
88
  }
67
89
  }, [showCurrentTime, autoScrollToCurrentTime]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kkkarsss/ui",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "description": "UI Kit for kkkarsss projects",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",