catchup-library-web 1.21.8 → 1.21.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.
package/dist/index.js CHANGED
@@ -5391,10 +5391,27 @@ var GroupingActivityMaterialContent = ({
5391
5391
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5392
5392
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5393
5393
  if (dropZoneElement) {
5394
- dropZoneElement.scrollIntoView({
5395
- behavior: "smooth",
5396
- block: "center"
5397
- });
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);
5398
5415
  }
5399
5416
  }
5400
5417
  }, [dropTargetKey]);
@@ -5776,8 +5793,6 @@ var MatchingActivityMaterialContent = ({
5776
5793
  });
5777
5794
  const itemsRef = (0, import_react21.useRef)(null);
5778
5795
  const dropZoneRefs = (0, import_react21.useRef)({});
5779
- const scrollAnimationRef = (0, import_react21.useRef)(null);
5780
- const lastScrollTimeRef = (0, import_react21.useRef)(0);
5781
5796
  (0, import_react21.useEffect)(() => {
5782
5797
  const shuffleArray2 = (array) => {
5783
5798
  if (!isShuffled) {
@@ -5804,45 +5819,38 @@ var MatchingActivityMaterialContent = ({
5804
5819
  ).answerMap = materialMap;
5805
5820
  }, [showCorrectAnswer, answer, materialMap]);
5806
5821
  (0, import_react21.useEffect)(() => {
5807
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5808
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5809
- const currentTime = Date.now();
5810
- if (currentTime - lastScrollTimeRef.current < 300) {
5811
- return;
5812
- }
5813
- lastScrollTimeRef.current = currentTime;
5814
- if (dropZoneElement) {
5815
- if (scrollAnimationRef.current) {
5816
- cancelAnimationFrame(scrollAnimationRef.current);
5817
- }
5818
- const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5819
- const startPosition = window.pageYOffset;
5820
- const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5821
- const duration = 800;
5822
- let start = null;
5823
- const animation = (currentTime2) => {
5824
- if (start === null) start = currentTime2;
5825
- const timeElapsed = currentTime2 - start;
5826
- const progress = Math.min(timeElapsed / duration, 1);
5827
- const ease = (t) => 1 - Math.pow(1 - t, 3);
5828
- window.scrollTo(0, startPosition + distance * ease(progress));
5829
- if (timeElapsed < duration) {
5830
- scrollAnimationRef.current = requestAnimationFrame(animation);
5831
- } else {
5832
- scrollAnimationRef.current = null;
5833
- }
5834
- };
5835
- scrollAnimationRef.current = requestAnimationFrame(animation);
5836
- }
5837
- }
5838
- }, [dropTargetKey]);
5839
- (0, import_react21.useEffect)(() => {
5840
- return () => {
5841
- if (scrollAnimationRef.current) {
5842
- cancelAnimationFrame(scrollAnimationRef.current);
5822
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
5823
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5824
+ 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;
5831
+ const distance = targetScroll - startScroll;
5832
+ console.log("Scrolling to element:", dropTargetKey);
5833
+ console.log("Current scroll:", startScroll);
5834
+ console.log("Target scroll:", targetScroll);
5835
+ console.log("Distance:", distance);
5836
+ if (Math.abs(distance) < 10) return;
5837
+ const duration = 800;
5838
+ let startTime = null;
5839
+ const easeInOutQuad = (t) => {
5840
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5841
+ };
5842
+ const animate = (currentTime) => {
5843
+ if (startTime === null) startTime = currentTime;
5844
+ const elapsed = currentTime - startTime;
5845
+ const progress = Math.min(elapsed / duration, 1);
5846
+ const easedProgress = easeInOutQuad(progress);
5847
+ window.scrollTo(0, startScroll + distance * easedProgress);
5848
+ if (progress < 1) {
5849
+ requestAnimationFrame(animate);
5843
5850
  }
5844
5851
  };
5845
- }, []);
5852
+ requestAnimationFrame(animate);
5853
+ }, [dropTargetKey]);
5846
5854
  const retrieveAnswerMap = () => {
5847
5855
  const foundIndex = answer.data.findIndex(
5848
5856
  (answerData) => answerData.type === "MATCHING"
package/dist/index.mjs CHANGED
@@ -5175,10 +5175,27 @@ var GroupingActivityMaterialContent = ({
5175
5175
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5176
5176
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5177
5177
  if (dropZoneElement) {
5178
- dropZoneElement.scrollIntoView({
5179
- behavior: "smooth",
5180
- block: "center"
5181
- });
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);
5182
5199
  }
5183
5200
  }
5184
5201
  }, [dropTargetKey]);
@@ -5560,8 +5577,6 @@ var MatchingActivityMaterialContent = ({
5560
5577
  });
5561
5578
  const itemsRef = useRef6(null);
5562
5579
  const dropZoneRefs = useRef6({});
5563
- const scrollAnimationRef = useRef6(null);
5564
- const lastScrollTimeRef = useRef6(0);
5565
5580
  useEffect11(() => {
5566
5581
  const shuffleArray2 = (array) => {
5567
5582
  if (!isShuffled) {
@@ -5588,45 +5603,38 @@ var MatchingActivityMaterialContent = ({
5588
5603
  ).answerMap = materialMap;
5589
5604
  }, [showCorrectAnswer, answer, materialMap]);
5590
5605
  useEffect11(() => {
5591
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5592
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5593
- const currentTime = Date.now();
5594
- if (currentTime - lastScrollTimeRef.current < 300) {
5595
- return;
5596
- }
5597
- lastScrollTimeRef.current = currentTime;
5598
- if (dropZoneElement) {
5599
- if (scrollAnimationRef.current) {
5600
- cancelAnimationFrame(scrollAnimationRef.current);
5601
- }
5602
- const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5603
- const startPosition = window.pageYOffset;
5604
- const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5605
- const duration = 800;
5606
- let start = null;
5607
- const animation = (currentTime2) => {
5608
- if (start === null) start = currentTime2;
5609
- const timeElapsed = currentTime2 - start;
5610
- const progress = Math.min(timeElapsed / duration, 1);
5611
- const ease = (t) => 1 - Math.pow(1 - t, 3);
5612
- window.scrollTo(0, startPosition + distance * ease(progress));
5613
- if (timeElapsed < duration) {
5614
- scrollAnimationRef.current = requestAnimationFrame(animation);
5615
- } else {
5616
- scrollAnimationRef.current = null;
5617
- }
5618
- };
5619
- scrollAnimationRef.current = requestAnimationFrame(animation);
5620
- }
5621
- }
5622
- }, [dropTargetKey]);
5623
- useEffect11(() => {
5624
- return () => {
5625
- if (scrollAnimationRef.current) {
5626
- cancelAnimationFrame(scrollAnimationRef.current);
5606
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
5607
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5608
+ 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;
5615
+ const distance = targetScroll - startScroll;
5616
+ console.log("Scrolling to element:", dropTargetKey);
5617
+ console.log("Current scroll:", startScroll);
5618
+ console.log("Target scroll:", targetScroll);
5619
+ console.log("Distance:", distance);
5620
+ if (Math.abs(distance) < 10) return;
5621
+ const duration = 800;
5622
+ let startTime = null;
5623
+ const easeInOutQuad = (t) => {
5624
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5625
+ };
5626
+ const animate = (currentTime) => {
5627
+ if (startTime === null) startTime = currentTime;
5628
+ const elapsed = currentTime - startTime;
5629
+ const progress = Math.min(elapsed / duration, 1);
5630
+ const easedProgress = easeInOutQuad(progress);
5631
+ window.scrollTo(0, startScroll + distance * easedProgress);
5632
+ if (progress < 1) {
5633
+ requestAnimationFrame(animate);
5627
5634
  }
5628
5635
  };
5629
- }, []);
5636
+ requestAnimationFrame(animate);
5637
+ }, [dropTargetKey]);
5630
5638
  const retrieveAnswerMap = () => {
5631
5639
  const foundIndex = answer.data.findIndex(
5632
5640
  (answerData) => answerData.type === "MATCHING"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "1.21.08",
3
+ "version": "1.21.10",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -64,15 +64,41 @@ const GroupingActivityMaterialContent = ({
64
64
  ).answerMap = materialMap;
65
65
  }, [showCorrectAnswer, answer, materialMap]);
66
66
 
67
- // Auto-scroll to center the drop zone when hovering
68
67
  useEffect(() => {
69
68
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
70
69
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
71
70
  if (dropZoneElement) {
72
- dropZoneElement.scrollIntoView({
73
- behavior: "smooth",
74
- block: "center",
75
- });
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);
76
102
  }
77
103
  }
78
104
  }, [dropTargetKey]);
@@ -34,8 +34,6 @@ const MatchingActivityMaterialContent = ({
34
34
  });
35
35
  const itemsRef = useRef<HTMLDivElement>(null);
36
36
  const dropZoneRefs = useRef<{ [key: string]: HTMLDivElement | null }>({});
37
- const scrollAnimationRef = useRef<number | null>(null);
38
- const lastScrollTimeRef = useRef<number>(0);
39
37
 
40
38
  useEffect(() => {
41
39
  const shuffleArray = (array: any) => {
@@ -64,66 +62,54 @@ const MatchingActivityMaterialContent = ({
64
62
  ).answerMap = materialMap;
65
63
  }, [showCorrectAnswer, answer, materialMap]);
66
64
 
67
- // Replace the useEffect with this version
68
65
  useEffect(() => {
69
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
70
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
71
- const currentTime = Date.now();
66
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
72
67
 
73
- // Throttle: only scroll every 300ms to slow it down
74
- if (currentTime - lastScrollTimeRef.current < 300) {
75
- return;
76
- }
68
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
69
+ if (!dropZoneElement) return;
77
70
 
78
- lastScrollTimeRef.current = currentTime;
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;
79
76
 
80
- if (dropZoneElement) {
81
- // Cancel any existing animation
82
- if (scrollAnimationRef.current) {
83
- cancelAnimationFrame(scrollAnimationRef.current);
84
- }
77
+ // Calculate target scroll position (center the element in viewport)
78
+ const targetScroll = elementTop - viewportHeight / 2 + elementHeight / 2;
79
+ const startScroll = window.scrollY;
80
+ const distance = targetScroll - startScroll;
85
81
 
86
- const targetPosition =
87
- dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
88
- const startPosition = window.pageYOffset;
89
- const distance =
90
- targetPosition -
91
- startPosition -
92
- window.innerHeight / 2 +
93
- dropZoneElement.offsetHeight / 2;
94
- const duration = 800; // Slower duration
95
- let start: number | null = null;
96
-
97
- const animation = (currentTime: number) => {
98
- if (start === null) start = currentTime;
99
- const timeElapsed = currentTime - start;
100
- const progress = Math.min(timeElapsed / duration, 1);
101
-
102
- // Gentler easing function
103
- const ease = (t: number) => 1 - Math.pow(1 - t, 3);
104
-
105
- window.scrollTo(0, startPosition + distance * ease(progress));
106
-
107
- if (timeElapsed < duration) {
108
- scrollAnimationRef.current = requestAnimationFrame(animation);
109
- } else {
110
- scrollAnimationRef.current = null;
111
- }
112
- };
113
-
114
- scrollAnimationRef.current = requestAnimationFrame(animation);
115
- }
116
- }
117
- }, [dropTargetKey]);
82
+ console.log("Scrolling to element:", dropTargetKey);
83
+ console.log("Current scroll:", startScroll);
84
+ console.log("Target scroll:", targetScroll);
85
+ console.log("Distance:", distance);
118
86
 
119
- // Add cleanup on unmount
120
- useEffect(() => {
121
- return () => {
122
- if (scrollAnimationRef.current) {
123
- cancelAnimationFrame(scrollAnimationRef.current);
87
+ // Don't animate if already roughly in position
88
+ if (Math.abs(distance) < 10) return;
89
+
90
+ const duration = 800;
91
+ let startTime: number | null = null;
92
+
93
+ const easeInOutQuad = (t: number): number => {
94
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
95
+ };
96
+
97
+ const animate = (currentTime: number) => {
98
+ if (startTime === null) startTime = currentTime;
99
+
100
+ const elapsed = currentTime - startTime;
101
+ const progress = Math.min(elapsed / duration, 1);
102
+ const easedProgress = easeInOutQuad(progress);
103
+
104
+ window.scrollTo(0, startScroll + distance * easedProgress);
105
+
106
+ if (progress < 1) {
107
+ requestAnimationFrame(animate);
124
108
  }
125
109
  };
126
- }, []);
110
+
111
+ requestAnimationFrame(animate);
112
+ }, [dropTargetKey]);
127
113
 
128
114
  const retrieveAnswerMap = () => {
129
115
  const foundIndex = answer.data.findIndex(