catchup-library-web 1.21.11 → 1.21.13

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/dist/index.js CHANGED
@@ -5391,27 +5391,10 @@ var GroupingActivityMaterialContent = ({
5391
5391
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5392
5392
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5393
5393
  if (dropZoneElement) {
5394
- const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5395
- const startPosition = window.pageYOffset;
5396
- const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5397
- const duration = 800;
5398
- let start = null;
5399
- const easeInOutQuad = (t) => {
5400
- return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5401
- };
5402
- const animation = (currentTime) => {
5403
- if (start === null) start = currentTime;
5404
- const timeElapsed = currentTime - start;
5405
- const progress = Math.min(timeElapsed / duration, 1);
5406
- window.scrollTo(
5407
- 0,
5408
- startPosition + distance * easeInOutQuad(progress)
5409
- );
5410
- if (timeElapsed < duration) {
5411
- requestAnimationFrame(animation);
5412
- }
5413
- };
5414
- requestAnimationFrame(animation);
5394
+ dropZoneElement.scrollIntoView({
5395
+ behavior: "smooth",
5396
+ block: "center"
5397
+ });
5415
5398
  }
5416
5399
  }
5417
5400
  }, [dropTargetKey]);
@@ -5822,14 +5805,29 @@ var MatchingActivityMaterialContent = ({
5822
5805
  if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
5823
5806
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5824
5807
  if (!dropZoneElement) return;
5825
- const rect = dropZoneElement.getBoundingClientRect();
5826
- const elementTop = rect.top + window.scrollY;
5827
- const elementHeight = rect.height;
5828
- const viewportHeight = window.innerHeight;
5829
- const targetScroll = elementTop - viewportHeight / 2 + elementHeight / 2;
5830
- const startScroll = window.scrollY;
5808
+ const findScrollableParent = (element) => {
5809
+ let parent = element.parentElement;
5810
+ while (parent) {
5811
+ const { overflow, overflowY } = window.getComputedStyle(parent);
5812
+ if (overflow === "auto" || overflow === "scroll" || overflowY === "auto" || overflowY === "scroll") {
5813
+ return parent;
5814
+ }
5815
+ parent = parent.parentElement;
5816
+ }
5817
+ return document.documentElement;
5818
+ };
5819
+ const scrollContainer = findScrollableParent(dropZoneElement);
5820
+ if (!scrollContainer) return;
5821
+ const containerRect = scrollContainer.getBoundingClientRect();
5822
+ const elementRect = dropZoneElement.getBoundingClientRect();
5823
+ const elementTop = elementRect.top - containerRect.top + scrollContainer.scrollTop;
5824
+ const elementHeight = elementRect.height;
5825
+ const containerHeight = containerRect.height;
5826
+ const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
5827
+ const startScroll = scrollContainer.scrollTop;
5831
5828
  const distance = targetScroll - startScroll;
5832
5829
  console.log("Scrolling to element:", dropTargetKey);
5830
+ console.log("Scroll container:", scrollContainer);
5833
5831
  console.log("Current scroll:", startScroll);
5834
5832
  console.log("Target scroll:", targetScroll);
5835
5833
  console.log("Distance:", distance);
@@ -5841,14 +5839,12 @@ var MatchingActivityMaterialContent = ({
5841
5839
  };
5842
5840
  const animate = (currentTime) => {
5843
5841
  if (startTime === null) startTime = currentTime;
5844
- console.log("startTime:", startTime);
5845
5842
  const elapsed = currentTime - startTime;
5846
- console.log("elapsed:", elapsed);
5847
5843
  const progress = Math.min(elapsed / duration, 1);
5848
- console.log("progress:", progress);
5849
5844
  const easedProgress = easeInOutQuad(progress);
5850
- console.log("eased progressed: ", easedProgress);
5851
- window.scrollTo(0, startScroll + distance * easedProgress);
5845
+ const newScrollTop = startScroll + distance * easedProgress;
5846
+ scrollContainer.scrollTop = newScrollTop;
5847
+ console.log("Scrolling to:", newScrollTop);
5852
5848
  if (progress < 1) {
5853
5849
  requestAnimationFrame(animate);
5854
5850
  }
package/dist/index.mjs CHANGED
@@ -5175,27 +5175,10 @@ var GroupingActivityMaterialContent = ({
5175
5175
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5176
5176
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5177
5177
  if (dropZoneElement) {
5178
- const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5179
- const startPosition = window.pageYOffset;
5180
- const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5181
- const duration = 800;
5182
- let start = null;
5183
- const easeInOutQuad = (t) => {
5184
- return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5185
- };
5186
- const animation = (currentTime) => {
5187
- if (start === null) start = currentTime;
5188
- const timeElapsed = currentTime - start;
5189
- const progress = Math.min(timeElapsed / duration, 1);
5190
- window.scrollTo(
5191
- 0,
5192
- startPosition + distance * easeInOutQuad(progress)
5193
- );
5194
- if (timeElapsed < duration) {
5195
- requestAnimationFrame(animation);
5196
- }
5197
- };
5198
- requestAnimationFrame(animation);
5178
+ dropZoneElement.scrollIntoView({
5179
+ behavior: "smooth",
5180
+ block: "center"
5181
+ });
5199
5182
  }
5200
5183
  }
5201
5184
  }, [dropTargetKey]);
@@ -5606,14 +5589,29 @@ var MatchingActivityMaterialContent = ({
5606
5589
  if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
5607
5590
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5608
5591
  if (!dropZoneElement) return;
5609
- const rect = dropZoneElement.getBoundingClientRect();
5610
- const elementTop = rect.top + window.scrollY;
5611
- const elementHeight = rect.height;
5612
- const viewportHeight = window.innerHeight;
5613
- const targetScroll = elementTop - viewportHeight / 2 + elementHeight / 2;
5614
- const startScroll = window.scrollY;
5592
+ const findScrollableParent = (element) => {
5593
+ let parent = element.parentElement;
5594
+ while (parent) {
5595
+ const { overflow, overflowY } = window.getComputedStyle(parent);
5596
+ if (overflow === "auto" || overflow === "scroll" || overflowY === "auto" || overflowY === "scroll") {
5597
+ return parent;
5598
+ }
5599
+ parent = parent.parentElement;
5600
+ }
5601
+ return document.documentElement;
5602
+ };
5603
+ const scrollContainer = findScrollableParent(dropZoneElement);
5604
+ if (!scrollContainer) return;
5605
+ const containerRect = scrollContainer.getBoundingClientRect();
5606
+ const elementRect = dropZoneElement.getBoundingClientRect();
5607
+ const elementTop = elementRect.top - containerRect.top + scrollContainer.scrollTop;
5608
+ const elementHeight = elementRect.height;
5609
+ const containerHeight = containerRect.height;
5610
+ const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
5611
+ const startScroll = scrollContainer.scrollTop;
5615
5612
  const distance = targetScroll - startScroll;
5616
5613
  console.log("Scrolling to element:", dropTargetKey);
5614
+ console.log("Scroll container:", scrollContainer);
5617
5615
  console.log("Current scroll:", startScroll);
5618
5616
  console.log("Target scroll:", targetScroll);
5619
5617
  console.log("Distance:", distance);
@@ -5625,14 +5623,12 @@ var MatchingActivityMaterialContent = ({
5625
5623
  };
5626
5624
  const animate = (currentTime) => {
5627
5625
  if (startTime === null) startTime = currentTime;
5628
- console.log("startTime:", startTime);
5629
5626
  const elapsed = currentTime - startTime;
5630
- console.log("elapsed:", elapsed);
5631
5627
  const progress = Math.min(elapsed / duration, 1);
5632
- console.log("progress:", progress);
5633
5628
  const easedProgress = easeInOutQuad(progress);
5634
- console.log("eased progressed: ", easedProgress);
5635
- window.scrollTo(0, startScroll + distance * easedProgress);
5629
+ const newScrollTop = startScroll + distance * easedProgress;
5630
+ scrollContainer.scrollTop = newScrollTop;
5631
+ console.log("Scrolling to:", newScrollTop);
5636
5632
  if (progress < 1) {
5637
5633
  requestAnimationFrame(animate);
5638
5634
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "1.21.11",
3
+ "version": "1.21.13",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -64,41 +64,15 @@ const GroupingActivityMaterialContent = ({
64
64
  ).answerMap = materialMap;
65
65
  }, [showCorrectAnswer, answer, materialMap]);
66
66
 
67
+ // Auto-scroll to center the drop zone when hovering
67
68
  useEffect(() => {
68
69
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
69
70
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
70
71
  if (dropZoneElement) {
71
- const targetPosition =
72
- dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
73
- const startPosition = window.pageYOffset;
74
- const distance =
75
- targetPosition -
76
- startPosition -
77
- window.innerHeight / 2 +
78
- dropZoneElement.offsetHeight / 2;
79
- const duration = 800; // Adjust this value (in milliseconds) to control speed
80
- let start: number | null = null;
81
-
82
- const easeInOutQuad = (t: number) => {
83
- return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
84
- };
85
-
86
- const animation = (currentTime: number) => {
87
- if (start === null) start = currentTime;
88
- const timeElapsed = currentTime - start;
89
- const progress = Math.min(timeElapsed / duration, 1);
90
-
91
- window.scrollTo(
92
- 0,
93
- startPosition + distance * easeInOutQuad(progress)
94
- );
95
-
96
- if (timeElapsed < duration) {
97
- requestAnimationFrame(animation);
98
- }
99
- };
100
-
101
- requestAnimationFrame(animation);
72
+ dropZoneElement.scrollIntoView({
73
+ behavior: "smooth",
74
+ block: "center",
75
+ });
102
76
  }
103
77
  }
104
78
  }, [dropTargetKey]);
@@ -68,18 +68,45 @@ const MatchingActivityMaterialContent = ({
68
68
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
69
69
  if (!dropZoneElement) return;
70
70
 
71
- // Get the element's position relative to the viewport
72
- const rect = dropZoneElement.getBoundingClientRect();
73
- const elementTop = rect.top + window.scrollY;
74
- const elementHeight = rect.height;
75
- const viewportHeight = window.innerHeight;
76
-
77
- // Calculate target scroll position (center the element in viewport)
78
- const targetScroll = elementTop - viewportHeight / 2 + elementHeight / 2;
79
- const startScroll = window.scrollY;
71
+ // Find the scrollable parent container
72
+ const findScrollableParent = (element: HTMLElement): HTMLElement | null => {
73
+ let parent = element.parentElement;
74
+
75
+ while (parent) {
76
+ const { overflow, overflowY } = window.getComputedStyle(parent);
77
+ if (
78
+ overflow === "auto" ||
79
+ overflow === "scroll" ||
80
+ overflowY === "auto" ||
81
+ overflowY === "scroll"
82
+ ) {
83
+ return parent;
84
+ }
85
+ parent = parent.parentElement;
86
+ }
87
+
88
+ return document.documentElement; // Fallback to document scroll
89
+ };
90
+
91
+ const scrollContainer = findScrollableParent(dropZoneElement);
92
+ if (!scrollContainer) return;
93
+
94
+ // Get the element's position relative to the scroll container
95
+ const containerRect = scrollContainer.getBoundingClientRect();
96
+ const elementRect = dropZoneElement.getBoundingClientRect();
97
+
98
+ const elementTop =
99
+ elementRect.top - containerRect.top + scrollContainer.scrollTop;
100
+ const elementHeight = elementRect.height;
101
+ const containerHeight = containerRect.height;
102
+
103
+ // Calculate target scroll position (center the element in the container)
104
+ const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
105
+ const startScroll = scrollContainer.scrollTop;
80
106
  const distance = targetScroll - startScroll;
81
107
 
82
108
  console.log("Scrolling to element:", dropTargetKey);
109
+ console.log("Scroll container:", scrollContainer);
83
110
  console.log("Current scroll:", startScroll);
84
111
  console.log("Target scroll:", targetScroll);
85
112
  console.log("Distance:", distance);
@@ -97,15 +124,14 @@ const MatchingActivityMaterialContent = ({
97
124
  const animate = (currentTime: number) => {
98
125
  if (startTime === null) startTime = currentTime;
99
126
 
100
- console.log("startTime:", startTime);
101
127
  const elapsed = currentTime - startTime;
102
- console.log("elapsed:", elapsed);
103
128
  const progress = Math.min(elapsed / duration, 1);
104
- console.log("progress:", progress);
105
129
  const easedProgress = easeInOutQuad(progress);
106
- console.log("eased progressed: ", easedProgress);
107
130
 
108
- window.scrollTo(0, startScroll + distance * easedProgress);
131
+ const newScrollTop = startScroll + distance * easedProgress;
132
+ scrollContainer.scrollTop = newScrollTop;
133
+
134
+ console.log("Scrolling to:", newScrollTop);
109
135
 
110
136
  if (progress < 1) {
111
137
  requestAnimationFrame(animate);