catchup-library-web 1.21.8 → 1.21.9

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) {
@@ -5806,43 +5821,31 @@ var MatchingActivityMaterialContent = ({
5806
5821
  (0, import_react21.useEffect)(() => {
5807
5822
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5808
5823
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5809
- const currentTime = Date.now();
5810
- if (currentTime - lastScrollTimeRef.current < 300) {
5811
- return;
5812
- }
5813
- lastScrollTimeRef.current = currentTime;
5814
5824
  if (dropZoneElement) {
5815
- if (scrollAnimationRef.current) {
5816
- cancelAnimationFrame(scrollAnimationRef.current);
5817
- }
5818
5825
  const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5819
5826
  const startPosition = window.pageYOffset;
5820
5827
  const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5821
5828
  const duration = 800;
5822
5829
  let start = null;
5823
- const animation = (currentTime2) => {
5824
- if (start === null) start = currentTime2;
5825
- const timeElapsed = currentTime2 - start;
5830
+ const easeInOutQuad = (t) => {
5831
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5832
+ };
5833
+ const animation = (currentTime) => {
5834
+ if (start === null) start = currentTime;
5835
+ const timeElapsed = currentTime - start;
5826
5836
  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));
5837
+ window.scrollTo(
5838
+ 0,
5839
+ startPosition + distance * easeInOutQuad(progress)
5840
+ );
5829
5841
  if (timeElapsed < duration) {
5830
- scrollAnimationRef.current = requestAnimationFrame(animation);
5831
- } else {
5832
- scrollAnimationRef.current = null;
5842
+ requestAnimationFrame(animation);
5833
5843
  }
5834
5844
  };
5835
- scrollAnimationRef.current = requestAnimationFrame(animation);
5845
+ requestAnimationFrame(animation);
5836
5846
  }
5837
5847
  }
5838
5848
  }, [dropTargetKey]);
5839
- (0, import_react21.useEffect)(() => {
5840
- return () => {
5841
- if (scrollAnimationRef.current) {
5842
- cancelAnimationFrame(scrollAnimationRef.current);
5843
- }
5844
- };
5845
- }, []);
5846
5849
  const retrieveAnswerMap = () => {
5847
5850
  const foundIndex = answer.data.findIndex(
5848
5851
  (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) {
@@ -5590,43 +5605,31 @@ var MatchingActivityMaterialContent = ({
5590
5605
  useEffect11(() => {
5591
5606
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5592
5607
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5593
- const currentTime = Date.now();
5594
- if (currentTime - lastScrollTimeRef.current < 300) {
5595
- return;
5596
- }
5597
- lastScrollTimeRef.current = currentTime;
5598
5608
  if (dropZoneElement) {
5599
- if (scrollAnimationRef.current) {
5600
- cancelAnimationFrame(scrollAnimationRef.current);
5601
- }
5602
5609
  const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5603
5610
  const startPosition = window.pageYOffset;
5604
5611
  const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5605
5612
  const duration = 800;
5606
5613
  let start = null;
5607
- const animation = (currentTime2) => {
5608
- if (start === null) start = currentTime2;
5609
- const timeElapsed = currentTime2 - start;
5614
+ const easeInOutQuad = (t) => {
5615
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5616
+ };
5617
+ const animation = (currentTime) => {
5618
+ if (start === null) start = currentTime;
5619
+ const timeElapsed = currentTime - start;
5610
5620
  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));
5621
+ window.scrollTo(
5622
+ 0,
5623
+ startPosition + distance * easeInOutQuad(progress)
5624
+ );
5613
5625
  if (timeElapsed < duration) {
5614
- scrollAnimationRef.current = requestAnimationFrame(animation);
5615
- } else {
5616
- scrollAnimationRef.current = null;
5626
+ requestAnimationFrame(animation);
5617
5627
  }
5618
5628
  };
5619
- scrollAnimationRef.current = requestAnimationFrame(animation);
5629
+ requestAnimationFrame(animation);
5620
5630
  }
5621
5631
  }
5622
5632
  }, [dropTargetKey]);
5623
- useEffect11(() => {
5624
- return () => {
5625
- if (scrollAnimationRef.current) {
5626
- cancelAnimationFrame(scrollAnimationRef.current);
5627
- }
5628
- };
5629
- }, []);
5630
5633
  const retrieveAnswerMap = () => {
5631
5634
  const foundIndex = answer.data.findIndex(
5632
5635
  (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.09",
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,25 +62,10 @@ const MatchingActivityMaterialContent = ({
64
62
  ).answerMap = materialMap;
65
63
  }, [showCorrectAnswer, answer, materialMap]);
66
64
 
67
- // Replace the useEffect with this version
68
65
  useEffect(() => {
69
66
  if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
70
67
  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
-
80
68
  if (dropZoneElement) {
81
- // Cancel any existing animation
82
- if (scrollAnimationRef.current) {
83
- cancelAnimationFrame(scrollAnimationRef.current);
84
- }
85
-
86
69
  const targetPosition =
87
70
  dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
88
71
  const startPosition = window.pageYOffset;
@@ -91,40 +74,33 @@ const MatchingActivityMaterialContent = ({
91
74
  startPosition -
92
75
  window.innerHeight / 2 +
93
76
  dropZoneElement.offsetHeight / 2;
94
- const duration = 800; // Slower duration
77
+ const duration = 800; // Adjust this value (in milliseconds) to control speed
95
78
  let start: number | null = null;
96
79
 
80
+ const easeInOutQuad = (t: number) => {
81
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
82
+ };
83
+
97
84
  const animation = (currentTime: number) => {
98
85
  if (start === null) start = currentTime;
99
86
  const timeElapsed = currentTime - start;
100
87
  const progress = Math.min(timeElapsed / duration, 1);
101
88
 
102
- // Gentler easing function
103
- const ease = (t: number) => 1 - Math.pow(1 - t, 3);
104
-
105
- window.scrollTo(0, startPosition + distance * ease(progress));
89
+ window.scrollTo(
90
+ 0,
91
+ startPosition + distance * easeInOutQuad(progress)
92
+ );
106
93
 
107
94
  if (timeElapsed < duration) {
108
- scrollAnimationRef.current = requestAnimationFrame(animation);
109
- } else {
110
- scrollAnimationRef.current = null;
95
+ requestAnimationFrame(animation);
111
96
  }
112
97
  };
113
98
 
114
- scrollAnimationRef.current = requestAnimationFrame(animation);
99
+ requestAnimationFrame(animation);
115
100
  }
116
101
  }
117
102
  }, [dropTargetKey]);
118
103
 
119
- // Add cleanup on unmount
120
- useEffect(() => {
121
- return () => {
122
- if (scrollAnimationRef.current) {
123
- cancelAnimationFrame(scrollAnimationRef.current);
124
- }
125
- };
126
- }, []);
127
-
128
104
  const retrieveAnswerMap = () => {
129
105
  const foundIndex = answer.data.findIndex(
130
106
  (answerData: any) => answerData.type === "MATCHING"