catchup-library-web 1.21.6 → 1.21.8

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
@@ -5776,6 +5776,8 @@ var MatchingActivityMaterialContent = ({
5776
5776
  });
5777
5777
  const itemsRef = (0, import_react21.useRef)(null);
5778
5778
  const dropZoneRefs = (0, import_react21.useRef)({});
5779
+ const scrollAnimationRef = (0, import_react21.useRef)(null);
5780
+ const lastScrollTimeRef = (0, import_react21.useRef)(0);
5779
5781
  (0, import_react21.useEffect)(() => {
5780
5782
  const shuffleArray2 = (array) => {
5781
5783
  if (!isShuffled) {
@@ -5804,26 +5806,43 @@ var MatchingActivityMaterialContent = ({
5804
5806
  (0, import_react21.useEffect)(() => {
5805
5807
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5806
5808
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5809
+ const currentTime = Date.now();
5810
+ if (currentTime - lastScrollTimeRef.current < 300) {
5811
+ return;
5812
+ }
5813
+ lastScrollTimeRef.current = currentTime;
5807
5814
  if (dropZoneElement) {
5815
+ if (scrollAnimationRef.current) {
5816
+ cancelAnimationFrame(scrollAnimationRef.current);
5817
+ }
5808
5818
  const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5809
5819
  const startPosition = window.pageYOffset;
5810
5820
  const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5811
- const duration = 1e3;
5821
+ const duration = 800;
5812
5822
  let start = null;
5813
- const animation = (currentTime) => {
5814
- if (start === null) start = currentTime;
5815
- const timeElapsed = currentTime - start;
5823
+ const animation = (currentTime2) => {
5824
+ if (start === null) start = currentTime2;
5825
+ const timeElapsed = currentTime2 - start;
5816
5826
  const progress = Math.min(timeElapsed / duration, 1);
5817
- const ease = (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5827
+ const ease = (t) => 1 - Math.pow(1 - t, 3);
5818
5828
  window.scrollTo(0, startPosition + distance * ease(progress));
5819
5829
  if (timeElapsed < duration) {
5820
- requestAnimationFrame(animation);
5830
+ scrollAnimationRef.current = requestAnimationFrame(animation);
5831
+ } else {
5832
+ scrollAnimationRef.current = null;
5821
5833
  }
5822
5834
  };
5823
- requestAnimationFrame(animation);
5835
+ scrollAnimationRef.current = requestAnimationFrame(animation);
5824
5836
  }
5825
5837
  }
5826
5838
  }, [dropTargetKey]);
5839
+ (0, import_react21.useEffect)(() => {
5840
+ return () => {
5841
+ if (scrollAnimationRef.current) {
5842
+ cancelAnimationFrame(scrollAnimationRef.current);
5843
+ }
5844
+ };
5845
+ }, []);
5827
5846
  const retrieveAnswerMap = () => {
5828
5847
  const foundIndex = answer.data.findIndex(
5829
5848
  (answerData) => answerData.type === "MATCHING"
package/dist/index.mjs CHANGED
@@ -5560,6 +5560,8 @@ var MatchingActivityMaterialContent = ({
5560
5560
  });
5561
5561
  const itemsRef = useRef6(null);
5562
5562
  const dropZoneRefs = useRef6({});
5563
+ const scrollAnimationRef = useRef6(null);
5564
+ const lastScrollTimeRef = useRef6(0);
5563
5565
  useEffect11(() => {
5564
5566
  const shuffleArray2 = (array) => {
5565
5567
  if (!isShuffled) {
@@ -5588,26 +5590,43 @@ var MatchingActivityMaterialContent = ({
5588
5590
  useEffect11(() => {
5589
5591
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5590
5592
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5593
+ const currentTime = Date.now();
5594
+ if (currentTime - lastScrollTimeRef.current < 300) {
5595
+ return;
5596
+ }
5597
+ lastScrollTimeRef.current = currentTime;
5591
5598
  if (dropZoneElement) {
5599
+ if (scrollAnimationRef.current) {
5600
+ cancelAnimationFrame(scrollAnimationRef.current);
5601
+ }
5592
5602
  const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5593
5603
  const startPosition = window.pageYOffset;
5594
5604
  const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5595
- const duration = 1e3;
5605
+ const duration = 800;
5596
5606
  let start = null;
5597
- const animation = (currentTime) => {
5598
- if (start === null) start = currentTime;
5599
- const timeElapsed = currentTime - start;
5607
+ const animation = (currentTime2) => {
5608
+ if (start === null) start = currentTime2;
5609
+ const timeElapsed = currentTime2 - start;
5600
5610
  const progress = Math.min(timeElapsed / duration, 1);
5601
- const ease = (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5611
+ const ease = (t) => 1 - Math.pow(1 - t, 3);
5602
5612
  window.scrollTo(0, startPosition + distance * ease(progress));
5603
5613
  if (timeElapsed < duration) {
5604
- requestAnimationFrame(animation);
5614
+ scrollAnimationRef.current = requestAnimationFrame(animation);
5615
+ } else {
5616
+ scrollAnimationRef.current = null;
5605
5617
  }
5606
5618
  };
5607
- requestAnimationFrame(animation);
5619
+ scrollAnimationRef.current = requestAnimationFrame(animation);
5608
5620
  }
5609
5621
  }
5610
5622
  }, [dropTargetKey]);
5623
+ useEffect11(() => {
5624
+ return () => {
5625
+ if (scrollAnimationRef.current) {
5626
+ cancelAnimationFrame(scrollAnimationRef.current);
5627
+ }
5628
+ };
5629
+ }, []);
5611
5630
  const retrieveAnswerMap = () => {
5612
5631
  const foundIndex = answer.data.findIndex(
5613
5632
  (answerData) => answerData.type === "MATCHING"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "1.21.06",
3
+ "version": "1.21.08",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,6 +34,8 @@ 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);
37
39
 
38
40
  useEffect(() => {
39
41
  const shuffleArray = (array: any) => {
@@ -62,10 +64,25 @@ const MatchingActivityMaterialContent = ({
62
64
  ).answerMap = materialMap;
63
65
  }, [showCorrectAnswer, answer, materialMap]);
64
66
 
67
+ // Replace the useEffect with this version
65
68
  useEffect(() => {
66
69
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
67
70
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
71
+ const currentTime = Date.now();
72
+
73
+ // Throttle: only scroll every 300ms to slow it down
74
+ if (currentTime - lastScrollTimeRef.current < 300) {
75
+ return;
76
+ }
77
+
78
+ lastScrollTimeRef.current = currentTime;
79
+
68
80
  if (dropZoneElement) {
81
+ // Cancel any existing animation
82
+ if (scrollAnimationRef.current) {
83
+ cancelAnimationFrame(scrollAnimationRef.current);
84
+ }
85
+
69
86
  const targetPosition =
70
87
  dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
71
88
  const startPosition = window.pageYOffset;
@@ -74,7 +91,7 @@ const MatchingActivityMaterialContent = ({
74
91
  startPosition -
75
92
  window.innerHeight / 2 +
76
93
  dropZoneElement.offsetHeight / 2;
77
- const duration = 1000;
94
+ const duration = 800; // Slower duration
78
95
  let start: number | null = null;
79
96
 
80
97
  const animation = (currentTime: number) => {
@@ -82,22 +99,32 @@ const MatchingActivityMaterialContent = ({
82
99
  const timeElapsed = currentTime - start;
83
100
  const progress = Math.min(timeElapsed / duration, 1);
84
101
 
85
- // Easing function for smooth animation
86
- const ease = (t: number) =>
87
- t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
102
+ // Gentler easing function
103
+ const ease = (t: number) => 1 - Math.pow(1 - t, 3);
88
104
 
89
105
  window.scrollTo(0, startPosition + distance * ease(progress));
90
106
 
91
107
  if (timeElapsed < duration) {
92
- requestAnimationFrame(animation);
108
+ scrollAnimationRef.current = requestAnimationFrame(animation);
109
+ } else {
110
+ scrollAnimationRef.current = null;
93
111
  }
94
112
  };
95
113
 
96
- requestAnimationFrame(animation);
114
+ scrollAnimationRef.current = requestAnimationFrame(animation);
97
115
  }
98
116
  }
99
117
  }, [dropTargetKey]);
100
118
 
119
+ // Add cleanup on unmount
120
+ useEffect(() => {
121
+ return () => {
122
+ if (scrollAnimationRef.current) {
123
+ cancelAnimationFrame(scrollAnimationRef.current);
124
+ }
125
+ };
126
+ }, []);
127
+
101
128
  const retrieveAnswerMap = () => {
102
129
  const foundIndex = answer.data.findIndex(
103
130
  (answerData: any) => answerData.type === "MATCHING"