catchup-library-web 1.21.5 → 1.21.6

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,7 +5776,6 @@ var MatchingActivityMaterialContent = ({
5776
5776
  });
5777
5777
  const itemsRef = (0, import_react21.useRef)(null);
5778
5778
  const dropZoneRefs = (0, import_react21.useRef)({});
5779
- const scrollIntervalRef = (0, import_react21.useRef)(null);
5780
5779
  (0, import_react21.useEffect)(() => {
5781
5780
  const shuffleArray2 = (array) => {
5782
5781
  if (!isShuffled) {
@@ -5802,35 +5801,29 @@ var MatchingActivityMaterialContent = ({
5802
5801
  (answerData) => answerData.type === "MATCHING"
5803
5802
  ).answerMap = materialMap;
5804
5803
  }, [showCorrectAnswer, answer, materialMap]);
5805
- const handleAutoScroll = (clientY) => {
5806
- const scrollThreshold = 100;
5807
- const scrollSpeed = 10;
5808
- const viewportHeight = window.innerHeight;
5809
- if (scrollIntervalRef.current) {
5810
- clearInterval(scrollIntervalRef.current);
5811
- scrollIntervalRef.current = null;
5812
- }
5813
- if (clientY > viewportHeight - scrollThreshold) {
5814
- scrollIntervalRef.current = setInterval(() => {
5815
- window.scrollBy(0, scrollSpeed);
5816
- }, 16);
5817
- } else if (clientY < scrollThreshold) {
5818
- scrollIntervalRef.current = setInterval(() => {
5819
- window.scrollBy(0, -scrollSpeed);
5820
- }, 16);
5821
- }
5822
- };
5823
- const stopAutoScroll = () => {
5824
- if (scrollIntervalRef.current) {
5825
- clearInterval(scrollIntervalRef.current);
5826
- scrollIntervalRef.current = null;
5827
- }
5828
- };
5829
5804
  (0, import_react21.useEffect)(() => {
5830
- return () => {
5831
- stopAutoScroll();
5832
- };
5833
- }, []);
5805
+ if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5806
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5807
+ if (dropZoneElement) {
5808
+ const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5809
+ const startPosition = window.pageYOffset;
5810
+ const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5811
+ const duration = 1e3;
5812
+ let start = null;
5813
+ const animation = (currentTime) => {
5814
+ if (start === null) start = currentTime;
5815
+ const timeElapsed = currentTime - start;
5816
+ const progress = Math.min(timeElapsed / duration, 1);
5817
+ const ease = (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5818
+ window.scrollTo(0, startPosition + distance * ease(progress));
5819
+ if (timeElapsed < duration) {
5820
+ requestAnimationFrame(animation);
5821
+ }
5822
+ };
5823
+ requestAnimationFrame(animation);
5824
+ }
5825
+ }
5826
+ }, [dropTargetKey]);
5834
5827
  const retrieveAnswerMap = () => {
5835
5828
  const foundIndex = answer.data.findIndex(
5836
5829
  (answerData) => answerData.type === "MATCHING"
@@ -5864,7 +5857,6 @@ var MatchingActivityMaterialContent = ({
5864
5857
  const handleMouseMove = (e) => {
5865
5858
  if (!draggedValue) return;
5866
5859
  setMousePosition({ x: e.clientX, y: e.clientY });
5867
- handleAutoScroll(e.clientY);
5868
5860
  const elementUnder = document.elementFromPoint(e.clientX, e.clientY);
5869
5861
  const dropZone = elementUnder == null ? void 0 : elementUnder.closest("[data-matching-drop-zone]");
5870
5862
  if (dropZone) {
@@ -5875,7 +5867,6 @@ var MatchingActivityMaterialContent = ({
5875
5867
  }
5876
5868
  };
5877
5869
  const handleMouseUp = () => {
5878
- stopAutoScroll();
5879
5870
  if (dropTargetKey !== null && draggedValue !== null) {
5880
5871
  onChange(answer, dropTargetKey, draggedValue);
5881
5872
  }
@@ -5895,7 +5886,6 @@ var MatchingActivityMaterialContent = ({
5895
5886
  if (!draggedValue) return;
5896
5887
  const touch = e.touches[0];
5897
5888
  setTouchPosition({ x: touch.clientX, y: touch.clientY });
5898
- handleAutoScroll(touch.clientY);
5899
5889
  const elementUnder = document.elementFromPoint(
5900
5890
  touch.clientX,
5901
5891
  touch.clientY
@@ -5909,7 +5899,6 @@ var MatchingActivityMaterialContent = ({
5909
5899
  }
5910
5900
  };
5911
5901
  const handleTouchEnd = () => {
5912
- stopAutoScroll();
5913
5902
  if (dropTargetKey !== null && draggedValue !== null) {
5914
5903
  onChange(answer, dropTargetKey, draggedValue);
5915
5904
  }
package/dist/index.mjs CHANGED
@@ -5560,7 +5560,6 @@ var MatchingActivityMaterialContent = ({
5560
5560
  });
5561
5561
  const itemsRef = useRef6(null);
5562
5562
  const dropZoneRefs = useRef6({});
5563
- const scrollIntervalRef = useRef6(null);
5564
5563
  useEffect11(() => {
5565
5564
  const shuffleArray2 = (array) => {
5566
5565
  if (!isShuffled) {
@@ -5586,35 +5585,29 @@ var MatchingActivityMaterialContent = ({
5586
5585
  (answerData) => answerData.type === "MATCHING"
5587
5586
  ).answerMap = materialMap;
5588
5587
  }, [showCorrectAnswer, answer, materialMap]);
5589
- const handleAutoScroll = (clientY) => {
5590
- const scrollThreshold = 100;
5591
- const scrollSpeed = 10;
5592
- const viewportHeight = window.innerHeight;
5593
- if (scrollIntervalRef.current) {
5594
- clearInterval(scrollIntervalRef.current);
5595
- scrollIntervalRef.current = null;
5596
- }
5597
- if (clientY > viewportHeight - scrollThreshold) {
5598
- scrollIntervalRef.current = setInterval(() => {
5599
- window.scrollBy(0, scrollSpeed);
5600
- }, 16);
5601
- } else if (clientY < scrollThreshold) {
5602
- scrollIntervalRef.current = setInterval(() => {
5603
- window.scrollBy(0, -scrollSpeed);
5604
- }, 16);
5605
- }
5606
- };
5607
- const stopAutoScroll = () => {
5608
- if (scrollIntervalRef.current) {
5609
- clearInterval(scrollIntervalRef.current);
5610
- scrollIntervalRef.current = null;
5611
- }
5612
- };
5613
5588
  useEffect11(() => {
5614
- return () => {
5615
- stopAutoScroll();
5616
- };
5617
- }, []);
5589
+ if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5590
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5591
+ if (dropZoneElement) {
5592
+ const targetPosition = dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
5593
+ const startPosition = window.pageYOffset;
5594
+ const distance = targetPosition - startPosition - window.innerHeight / 2 + dropZoneElement.offsetHeight / 2;
5595
+ const duration = 1e3;
5596
+ let start = null;
5597
+ const animation = (currentTime) => {
5598
+ if (start === null) start = currentTime;
5599
+ const timeElapsed = currentTime - start;
5600
+ const progress = Math.min(timeElapsed / duration, 1);
5601
+ const ease = (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5602
+ window.scrollTo(0, startPosition + distance * ease(progress));
5603
+ if (timeElapsed < duration) {
5604
+ requestAnimationFrame(animation);
5605
+ }
5606
+ };
5607
+ requestAnimationFrame(animation);
5608
+ }
5609
+ }
5610
+ }, [dropTargetKey]);
5618
5611
  const retrieveAnswerMap = () => {
5619
5612
  const foundIndex = answer.data.findIndex(
5620
5613
  (answerData) => answerData.type === "MATCHING"
@@ -5648,7 +5641,6 @@ var MatchingActivityMaterialContent = ({
5648
5641
  const handleMouseMove = (e) => {
5649
5642
  if (!draggedValue) return;
5650
5643
  setMousePosition({ x: e.clientX, y: e.clientY });
5651
- handleAutoScroll(e.clientY);
5652
5644
  const elementUnder = document.elementFromPoint(e.clientX, e.clientY);
5653
5645
  const dropZone = elementUnder == null ? void 0 : elementUnder.closest("[data-matching-drop-zone]");
5654
5646
  if (dropZone) {
@@ -5659,7 +5651,6 @@ var MatchingActivityMaterialContent = ({
5659
5651
  }
5660
5652
  };
5661
5653
  const handleMouseUp = () => {
5662
- stopAutoScroll();
5663
5654
  if (dropTargetKey !== null && draggedValue !== null) {
5664
5655
  onChange(answer, dropTargetKey, draggedValue);
5665
5656
  }
@@ -5679,7 +5670,6 @@ var MatchingActivityMaterialContent = ({
5679
5670
  if (!draggedValue) return;
5680
5671
  const touch = e.touches[0];
5681
5672
  setTouchPosition({ x: touch.clientX, y: touch.clientY });
5682
- handleAutoScroll(touch.clientY);
5683
5673
  const elementUnder = document.elementFromPoint(
5684
5674
  touch.clientX,
5685
5675
  touch.clientY
@@ -5693,7 +5683,6 @@ var MatchingActivityMaterialContent = ({
5693
5683
  }
5694
5684
  };
5695
5685
  const handleTouchEnd = () => {
5696
- stopAutoScroll();
5697
5686
  if (dropTargetKey !== null && draggedValue !== null) {
5698
5687
  onChange(answer, dropTargetKey, draggedValue);
5699
5688
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "1.21.05",
3
+ "version": "1.21.06",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,7 +34,6 @@ const MatchingActivityMaterialContent = ({
34
34
  });
35
35
  const itemsRef = useRef<HTMLDivElement>(null);
36
36
  const dropZoneRefs = useRef<{ [key: string]: HTMLDivElement | null }>({});
37
- const scrollIntervalRef = useRef<number | null>(null);
38
37
 
39
38
  useEffect(() => {
40
39
  const shuffleArray = (array: any) => {
@@ -63,45 +62,41 @@ const MatchingActivityMaterialContent = ({
63
62
  ).answerMap = materialMap;
64
63
  }, [showCorrectAnswer, answer, materialMap]);
65
64
 
66
- // Auto-scroll function
67
- const handleAutoScroll = (clientY: number) => {
68
- const scrollThreshold = 100; // Distance from edge to trigger scroll
69
- const scrollSpeed = 10; // Pixels to scroll per interval
70
- const viewportHeight = window.innerHeight;
71
-
72
- // Clear existing interval
73
- if (scrollIntervalRef.current) {
74
- clearInterval(scrollIntervalRef.current);
75
- scrollIntervalRef.current = null;
76
- }
77
-
78
- // Scroll down when near bottom
79
- if (clientY > viewportHeight - scrollThreshold) {
80
- scrollIntervalRef.current = setInterval(() => {
81
- window.scrollBy(0, scrollSpeed);
82
- }, 16); // ~60fps
83
- }
84
- // Scroll up when near top
85
- else if (clientY < scrollThreshold) {
86
- scrollIntervalRef.current = setInterval(() => {
87
- window.scrollBy(0, -scrollSpeed);
88
- }, 16);
89
- }
90
- };
91
-
92
- const stopAutoScroll = () => {
93
- if (scrollIntervalRef.current) {
94
- clearInterval(scrollIntervalRef.current);
95
- scrollIntervalRef.current = null;
96
- }
97
- };
98
-
99
- // Cleanup on unmount
100
65
  useEffect(() => {
101
- return () => {
102
- stopAutoScroll();
103
- };
104
- }, []);
66
+ if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
67
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
68
+ if (dropZoneElement) {
69
+ const targetPosition =
70
+ dropZoneElement.getBoundingClientRect().top + window.pageYOffset;
71
+ const startPosition = window.pageYOffset;
72
+ const distance =
73
+ targetPosition -
74
+ startPosition -
75
+ window.innerHeight / 2 +
76
+ dropZoneElement.offsetHeight / 2;
77
+ const duration = 1000;
78
+ let start: number | null = null;
79
+
80
+ const animation = (currentTime: number) => {
81
+ if (start === null) start = currentTime;
82
+ const timeElapsed = currentTime - start;
83
+ const progress = Math.min(timeElapsed / duration, 1);
84
+
85
+ // Easing function for smooth animation
86
+ const ease = (t: number) =>
87
+ t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
88
+
89
+ window.scrollTo(0, startPosition + distance * ease(progress));
90
+
91
+ if (timeElapsed < duration) {
92
+ requestAnimationFrame(animation);
93
+ }
94
+ };
95
+
96
+ requestAnimationFrame(animation);
97
+ }
98
+ }
99
+ }, [dropTargetKey]);
105
100
 
106
101
  const retrieveAnswerMap = () => {
107
102
  const foundIndex = answer.data.findIndex(
@@ -149,9 +144,6 @@ const MatchingActivityMaterialContent = ({
149
144
 
150
145
  setMousePosition({ x: e.clientX, y: e.clientY });
151
146
 
152
- // Handle auto-scroll
153
- handleAutoScroll(e.clientY);
154
-
155
147
  // Find the element under the mouse point
156
148
  const elementUnder = document.elementFromPoint(e.clientX, e.clientY);
157
149
  const dropZone = elementUnder?.closest("[data-matching-drop-zone]");
@@ -165,7 +157,6 @@ const MatchingActivityMaterialContent = ({
165
157
  };
166
158
 
167
159
  const handleMouseUp = (): void => {
168
- stopAutoScroll();
169
160
  if (dropTargetKey !== null && draggedValue !== null) {
170
161
  onChange(answer, dropTargetKey, draggedValue);
171
162
  }
@@ -194,9 +185,6 @@ const MatchingActivityMaterialContent = ({
194
185
  const touch = e.touches[0];
195
186
  setTouchPosition({ x: touch.clientX, y: touch.clientY });
196
187
 
197
- // Handle auto-scroll
198
- handleAutoScroll(touch.clientY);
199
-
200
188
  // Find the element under the touch point
201
189
  const elementUnder = document.elementFromPoint(
202
190
  touch.clientX,
@@ -213,7 +201,6 @@ const MatchingActivityMaterialContent = ({
213
201
  };
214
202
 
215
203
  const handleTouchEnd = (): void => {
216
- stopAutoScroll();
217
204
  if (dropTargetKey !== null && draggedValue !== null) {
218
205
  onChange(answer, dropTargetKey, draggedValue);
219
206
  }