catchup-library-web 1.21.3 → 1.21.5

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,7 @@ 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);
5779
5780
  (0, import_react21.useEffect)(() => {
5780
5781
  const shuffleArray2 = (array) => {
5781
5782
  if (!isShuffled) {
@@ -5801,17 +5802,35 @@ var MatchingActivityMaterialContent = ({
5801
5802
  (answerData) => answerData.type === "MATCHING"
5802
5803
  ).answerMap = materialMap;
5803
5804
  }, [showCorrectAnswer, answer, materialMap]);
5804
- (0, import_react21.useEffect)(() => {
5805
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5806
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5807
- if (dropZoneElement) {
5808
- dropZoneElement.scrollIntoView({
5809
- behavior: "smooth",
5810
- block: "center"
5811
- });
5812
- }
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);
5813
5821
  }
5814
- }, [dropTargetKey]);
5822
+ };
5823
+ const stopAutoScroll = () => {
5824
+ if (scrollIntervalRef.current) {
5825
+ clearInterval(scrollIntervalRef.current);
5826
+ scrollIntervalRef.current = null;
5827
+ }
5828
+ };
5829
+ (0, import_react21.useEffect)(() => {
5830
+ return () => {
5831
+ stopAutoScroll();
5832
+ };
5833
+ }, []);
5815
5834
  const retrieveAnswerMap = () => {
5816
5835
  const foundIndex = answer.data.findIndex(
5817
5836
  (answerData) => answerData.type === "MATCHING"
@@ -5845,6 +5864,7 @@ var MatchingActivityMaterialContent = ({
5845
5864
  const handleMouseMove = (e) => {
5846
5865
  if (!draggedValue) return;
5847
5866
  setMousePosition({ x: e.clientX, y: e.clientY });
5867
+ handleAutoScroll(e.clientY);
5848
5868
  const elementUnder = document.elementFromPoint(e.clientX, e.clientY);
5849
5869
  const dropZone = elementUnder == null ? void 0 : elementUnder.closest("[data-matching-drop-zone]");
5850
5870
  if (dropZone) {
@@ -5855,6 +5875,7 @@ var MatchingActivityMaterialContent = ({
5855
5875
  }
5856
5876
  };
5857
5877
  const handleMouseUp = () => {
5878
+ stopAutoScroll();
5858
5879
  if (dropTargetKey !== null && draggedValue !== null) {
5859
5880
  onChange(answer, dropTargetKey, draggedValue);
5860
5881
  }
@@ -5874,6 +5895,7 @@ var MatchingActivityMaterialContent = ({
5874
5895
  if (!draggedValue) return;
5875
5896
  const touch = e.touches[0];
5876
5897
  setTouchPosition({ x: touch.clientX, y: touch.clientY });
5898
+ handleAutoScroll(touch.clientY);
5877
5899
  const elementUnder = document.elementFromPoint(
5878
5900
  touch.clientX,
5879
5901
  touch.clientY
@@ -5887,6 +5909,7 @@ var MatchingActivityMaterialContent = ({
5887
5909
  }
5888
5910
  };
5889
5911
  const handleTouchEnd = () => {
5912
+ stopAutoScroll();
5890
5913
  if (dropTargetKey !== null && draggedValue !== null) {
5891
5914
  onChange(answer, dropTargetKey, draggedValue);
5892
5915
  }
package/dist/index.mjs CHANGED
@@ -5560,6 +5560,7 @@ var MatchingActivityMaterialContent = ({
5560
5560
  });
5561
5561
  const itemsRef = useRef6(null);
5562
5562
  const dropZoneRefs = useRef6({});
5563
+ const scrollIntervalRef = useRef6(null);
5563
5564
  useEffect11(() => {
5564
5565
  const shuffleArray2 = (array) => {
5565
5566
  if (!isShuffled) {
@@ -5585,17 +5586,35 @@ var MatchingActivityMaterialContent = ({
5585
5586
  (answerData) => answerData.type === "MATCHING"
5586
5587
  ).answerMap = materialMap;
5587
5588
  }, [showCorrectAnswer, answer, materialMap]);
5588
- useEffect11(() => {
5589
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5590
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5591
- if (dropZoneElement) {
5592
- dropZoneElement.scrollIntoView({
5593
- behavior: "smooth",
5594
- block: "center"
5595
- });
5596
- }
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);
5597
5605
  }
5598
- }, [dropTargetKey]);
5606
+ };
5607
+ const stopAutoScroll = () => {
5608
+ if (scrollIntervalRef.current) {
5609
+ clearInterval(scrollIntervalRef.current);
5610
+ scrollIntervalRef.current = null;
5611
+ }
5612
+ };
5613
+ useEffect11(() => {
5614
+ return () => {
5615
+ stopAutoScroll();
5616
+ };
5617
+ }, []);
5599
5618
  const retrieveAnswerMap = () => {
5600
5619
  const foundIndex = answer.data.findIndex(
5601
5620
  (answerData) => answerData.type === "MATCHING"
@@ -5629,6 +5648,7 @@ var MatchingActivityMaterialContent = ({
5629
5648
  const handleMouseMove = (e) => {
5630
5649
  if (!draggedValue) return;
5631
5650
  setMousePosition({ x: e.clientX, y: e.clientY });
5651
+ handleAutoScroll(e.clientY);
5632
5652
  const elementUnder = document.elementFromPoint(e.clientX, e.clientY);
5633
5653
  const dropZone = elementUnder == null ? void 0 : elementUnder.closest("[data-matching-drop-zone]");
5634
5654
  if (dropZone) {
@@ -5639,6 +5659,7 @@ var MatchingActivityMaterialContent = ({
5639
5659
  }
5640
5660
  };
5641
5661
  const handleMouseUp = () => {
5662
+ stopAutoScroll();
5642
5663
  if (dropTargetKey !== null && draggedValue !== null) {
5643
5664
  onChange(answer, dropTargetKey, draggedValue);
5644
5665
  }
@@ -5658,6 +5679,7 @@ var MatchingActivityMaterialContent = ({
5658
5679
  if (!draggedValue) return;
5659
5680
  const touch = e.touches[0];
5660
5681
  setTouchPosition({ x: touch.clientX, y: touch.clientY });
5682
+ handleAutoScroll(touch.clientY);
5661
5683
  const elementUnder = document.elementFromPoint(
5662
5684
  touch.clientX,
5663
5685
  touch.clientY
@@ -5671,6 +5693,7 @@ var MatchingActivityMaterialContent = ({
5671
5693
  }
5672
5694
  };
5673
5695
  const handleTouchEnd = () => {
5696
+ stopAutoScroll();
5674
5697
  if (dropTargetKey !== null && draggedValue !== null) {
5675
5698
  onChange(answer, dropTargetKey, draggedValue);
5676
5699
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "1.21.03",
3
+ "version": "1.21.05",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,6 +34,7 @@ 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);
37
38
 
38
39
  useEffect(() => {
39
40
  const shuffleArray = (array: any) => {
@@ -62,18 +63,45 @@ const MatchingActivityMaterialContent = ({
62
63
  ).answerMap = materialMap;
63
64
  }, [showCorrectAnswer, answer, materialMap]);
64
65
 
65
- // Auto-scroll to center the drop zone when hovering
66
- useEffect(() => {
67
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
68
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
69
- if (dropZoneElement) {
70
- dropZoneElement.scrollIntoView({
71
- behavior: "smooth",
72
- block: "center",
73
- });
74
- }
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);
75
89
  }
76
- }, [dropTargetKey]);
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
+ useEffect(() => {
101
+ return () => {
102
+ stopAutoScroll();
103
+ };
104
+ }, []);
77
105
 
78
106
  const retrieveAnswerMap = () => {
79
107
  const foundIndex = answer.data.findIndex(
@@ -121,6 +149,9 @@ const MatchingActivityMaterialContent = ({
121
149
 
122
150
  setMousePosition({ x: e.clientX, y: e.clientY });
123
151
 
152
+ // Handle auto-scroll
153
+ handleAutoScroll(e.clientY);
154
+
124
155
  // Find the element under the mouse point
125
156
  const elementUnder = document.elementFromPoint(e.clientX, e.clientY);
126
157
  const dropZone = elementUnder?.closest("[data-matching-drop-zone]");
@@ -134,6 +165,7 @@ const MatchingActivityMaterialContent = ({
134
165
  };
135
166
 
136
167
  const handleMouseUp = (): void => {
168
+ stopAutoScroll();
137
169
  if (dropTargetKey !== null && draggedValue !== null) {
138
170
  onChange(answer, dropTargetKey, draggedValue);
139
171
  }
@@ -162,6 +194,9 @@ const MatchingActivityMaterialContent = ({
162
194
  const touch = e.touches[0];
163
195
  setTouchPosition({ x: touch.clientX, y: touch.clientY });
164
196
 
197
+ // Handle auto-scroll
198
+ handleAutoScroll(touch.clientY);
199
+
165
200
  // Find the element under the touch point
166
201
  const elementUnder = document.elementFromPoint(
167
202
  touch.clientX,
@@ -178,6 +213,7 @@ const MatchingActivityMaterialContent = ({
178
213
  };
179
214
 
180
215
  const handleTouchEnd = (): void => {
216
+ stopAutoScroll();
181
217
  if (dropTargetKey !== null && draggedValue !== null) {
182
218
  onChange(answer, dropTargetKey, draggedValue);
183
219
  }