@kkkarsss/ui 1.4.8 → 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,29 +32,59 @@ 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 now = new Date();
36
- const hours = now.getHours();
37
- const minutes = now.getMinutes();
38
- const totalMinutes = hours * 60 + minutes;
39
- // 15 минут = 20 пикселей (высота слота)
40
- const topOffset = totalMinutes * (20 / 15);
41
- // Находим ближайший скроллируемый родитель или используем окно
42
- const scrollParent = (node) => {
43
- if (!node)
44
- return null;
45
- const style = window.getComputedStyle(node);
46
- if (/(auto|scroll)/.test(style.overflow + style.overflowY))
47
- return node;
48
- return scrollParent(node.parentElement);
35
+ const scroll = (retryCount = 0) => {
36
+ if (!containerRef.current)
37
+ return;
38
+ const now = new Date();
39
+ const hours = now.getHours();
40
+ const minutes = now.getMinutes();
41
+ const totalMinutes = hours * 60 + minutes;
42
+ // 15 минут = 20 пикселей (высота слота)
43
+ const topOffset = totalMinutes * (20 / 15);
44
+ // Находим ближайший скроллируемый родитель или используем окно
45
+ const scrollParent = (node) => {
46
+ if (!node)
47
+ return null;
48
+ const style = window.getComputedStyle(node);
49
+ const overflow = style.overflow + style.overflowY + style.overflowX;
50
+ if (/(auto|scroll)/.test(overflow))
51
+ return node;
52
+ return scrollParent(node.parentElement);
53
+ };
54
+ const parent = scrollParent(containerRef.current);
55
+ if (parent) {
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
+ });
80
+ parent.scrollTo({
81
+ top: relativeTop + topOffset - parent.clientHeight / 2,
82
+ behavior: 'smooth',
83
+ });
84
+ }
49
85
  };
50
- const parent = scrollParent(containerRef.current);
51
- if (parent) {
52
- const containerTop = containerRef.current.getBoundingClientRect().top + parent.scrollTop;
53
- parent.scrollTo({
54
- top: containerTop + topOffset - parent.clientHeight / 2,
55
- behavior: 'smooth',
56
- });
57
- }
86
+ const timeoutId = setTimeout(() => scroll(0), 100);
87
+ return () => clearTimeout(timeoutId);
58
88
  }
59
89
  }, [showCurrentTime, autoScrollToCurrentTime]);
60
90
  const handleDragStart = (e, task) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kkkarsss/ui",
3
- "version": "1.4.8",
3
+ "version": "1.4.10",
4
4
  "description": "UI Kit for kkkarsss projects",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",