catchup-library-web 1.21.13 → 1.21.15

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
@@ -5388,15 +5388,48 @@ var GroupingActivityMaterialContent = ({
5388
5388
  ).answerMap = materialMap;
5389
5389
  }, [showCorrectAnswer, answer, materialMap]);
5390
5390
  (0, import_react20.useEffect)(() => {
5391
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5392
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5393
- if (dropZoneElement) {
5394
- dropZoneElement.scrollIntoView({
5395
- behavior: "smooth",
5396
- block: "center"
5397
- });
5391
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
5392
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5393
+ if (!dropZoneElement) return;
5394
+ const findScrollableParent = (element) => {
5395
+ let parent = element.parentElement;
5396
+ while (parent) {
5397
+ const { overflow, overflowY } = window.getComputedStyle(parent);
5398
+ if (overflow === "auto" || overflow === "scroll" || overflowY === "auto" || overflowY === "scroll") {
5399
+ return parent;
5400
+ }
5401
+ parent = parent.parentElement;
5398
5402
  }
5399
- }
5403
+ return document.documentElement;
5404
+ };
5405
+ const scrollContainer = findScrollableParent(dropZoneElement);
5406
+ if (!scrollContainer) return;
5407
+ const containerRect = scrollContainer.getBoundingClientRect();
5408
+ const elementRect = dropZoneElement.getBoundingClientRect();
5409
+ const elementTop = elementRect.top - containerRect.top + scrollContainer.scrollTop;
5410
+ const elementHeight = elementRect.height;
5411
+ const containerHeight = containerRect.height;
5412
+ const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
5413
+ const startScroll = scrollContainer.scrollTop;
5414
+ const distance = targetScroll - startScroll;
5415
+ if (Math.abs(distance) < 10) return;
5416
+ const duration = 800;
5417
+ let startTime = null;
5418
+ const easeInOutQuad = (t) => {
5419
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5420
+ };
5421
+ const animate = (currentTime) => {
5422
+ if (startTime === null) startTime = currentTime;
5423
+ const elapsed = currentTime - startTime;
5424
+ const progress = Math.min(elapsed / duration, 1);
5425
+ const easedProgress = easeInOutQuad(progress);
5426
+ const newScrollTop = startScroll + distance * easedProgress;
5427
+ scrollContainer.scrollTop = newScrollTop;
5428
+ if (progress < 1) {
5429
+ requestAnimationFrame(animate);
5430
+ }
5431
+ };
5432
+ requestAnimationFrame(animate);
5400
5433
  }, [dropTargetKey]);
5401
5434
  const retrieveAnswerMap = () => {
5402
5435
  const foundIndex = answer.data.findIndex(
@@ -5826,11 +5859,6 @@ var MatchingActivityMaterialContent = ({
5826
5859
  const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
5827
5860
  const startScroll = scrollContainer.scrollTop;
5828
5861
  const distance = targetScroll - startScroll;
5829
- console.log("Scrolling to element:", dropTargetKey);
5830
- console.log("Scroll container:", scrollContainer);
5831
- console.log("Current scroll:", startScroll);
5832
- console.log("Target scroll:", targetScroll);
5833
- console.log("Distance:", distance);
5834
5862
  if (Math.abs(distance) < 10) return;
5835
5863
  const duration = 800;
5836
5864
  let startTime = null;
@@ -5844,7 +5872,6 @@ var MatchingActivityMaterialContent = ({
5844
5872
  const easedProgress = easeInOutQuad(progress);
5845
5873
  const newScrollTop = startScroll + distance * easedProgress;
5846
5874
  scrollContainer.scrollTop = newScrollTop;
5847
- console.log("Scrolling to:", newScrollTop);
5848
5875
  if (progress < 1) {
5849
5876
  requestAnimationFrame(animate);
5850
5877
  }
package/dist/index.mjs CHANGED
@@ -5172,15 +5172,48 @@ var GroupingActivityMaterialContent = ({
5172
5172
  ).answerMap = materialMap;
5173
5173
  }, [showCorrectAnswer, answer, materialMap]);
5174
5174
  useEffect10(() => {
5175
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
5176
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5177
- if (dropZoneElement) {
5178
- dropZoneElement.scrollIntoView({
5179
- behavior: "smooth",
5180
- block: "center"
5181
- });
5175
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
5176
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
5177
+ if (!dropZoneElement) return;
5178
+ const findScrollableParent = (element) => {
5179
+ let parent = element.parentElement;
5180
+ while (parent) {
5181
+ const { overflow, overflowY } = window.getComputedStyle(parent);
5182
+ if (overflow === "auto" || overflow === "scroll" || overflowY === "auto" || overflowY === "scroll") {
5183
+ return parent;
5184
+ }
5185
+ parent = parent.parentElement;
5182
5186
  }
5183
- }
5187
+ return document.documentElement;
5188
+ };
5189
+ const scrollContainer = findScrollableParent(dropZoneElement);
5190
+ if (!scrollContainer) return;
5191
+ const containerRect = scrollContainer.getBoundingClientRect();
5192
+ const elementRect = dropZoneElement.getBoundingClientRect();
5193
+ const elementTop = elementRect.top - containerRect.top + scrollContainer.scrollTop;
5194
+ const elementHeight = elementRect.height;
5195
+ const containerHeight = containerRect.height;
5196
+ const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
5197
+ const startScroll = scrollContainer.scrollTop;
5198
+ const distance = targetScroll - startScroll;
5199
+ if (Math.abs(distance) < 10) return;
5200
+ const duration = 800;
5201
+ let startTime = null;
5202
+ const easeInOutQuad = (t) => {
5203
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
5204
+ };
5205
+ const animate = (currentTime) => {
5206
+ if (startTime === null) startTime = currentTime;
5207
+ const elapsed = currentTime - startTime;
5208
+ const progress = Math.min(elapsed / duration, 1);
5209
+ const easedProgress = easeInOutQuad(progress);
5210
+ const newScrollTop = startScroll + distance * easedProgress;
5211
+ scrollContainer.scrollTop = newScrollTop;
5212
+ if (progress < 1) {
5213
+ requestAnimationFrame(animate);
5214
+ }
5215
+ };
5216
+ requestAnimationFrame(animate);
5184
5217
  }, [dropTargetKey]);
5185
5218
  const retrieveAnswerMap = () => {
5186
5219
  const foundIndex = answer.data.findIndex(
@@ -5610,11 +5643,6 @@ var MatchingActivityMaterialContent = ({
5610
5643
  const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
5611
5644
  const startScroll = scrollContainer.scrollTop;
5612
5645
  const distance = targetScroll - startScroll;
5613
- console.log("Scrolling to element:", dropTargetKey);
5614
- console.log("Scroll container:", scrollContainer);
5615
- console.log("Current scroll:", startScroll);
5616
- console.log("Target scroll:", targetScroll);
5617
- console.log("Distance:", distance);
5618
5646
  if (Math.abs(distance) < 10) return;
5619
5647
  const duration = 800;
5620
5648
  let startTime = null;
@@ -5628,7 +5656,6 @@ var MatchingActivityMaterialContent = ({
5628
5656
  const easedProgress = easeInOutQuad(progress);
5629
5657
  const newScrollTop = startScroll + distance * easedProgress;
5630
5658
  scrollContainer.scrollTop = newScrollTop;
5631
- console.log("Scrolling to:", newScrollTop);
5632
5659
  if (progress < 1) {
5633
5660
  requestAnimationFrame(animate);
5634
5661
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "1.21.13",
3
+ "version": "1.21.15",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -64,17 +64,70 @@ 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
- if (dropTargetKey && dropZoneRefs.current[dropTargetKey]) {
70
- const dropZoneElement = dropZoneRefs.current[dropTargetKey];
71
- if (dropZoneElement) {
72
- dropZoneElement.scrollIntoView({
73
- behavior: "smooth",
74
- block: "center",
75
- });
68
+ if (!dropTargetKey || !dropZoneRefs.current[dropTargetKey]) return;
69
+
70
+ const dropZoneElement = dropZoneRefs.current[dropTargetKey];
71
+ if (!dropZoneElement) return;
72
+
73
+ // Find the scrollable parent container
74
+ const findScrollableParent = (element: HTMLElement): HTMLElement | null => {
75
+ let parent = element.parentElement;
76
+
77
+ while (parent) {
78
+ const { overflow, overflowY } = window.getComputedStyle(parent);
79
+ if (
80
+ overflow === "auto" ||
81
+ overflow === "scroll" ||
82
+ overflowY === "auto" ||
83
+ overflowY === "scroll"
84
+ ) {
85
+ return parent;
86
+ }
87
+ parent = parent.parentElement;
76
88
  }
77
- }
89
+
90
+ return document.documentElement;
91
+ };
92
+
93
+ const scrollContainer = findScrollableParent(dropZoneElement);
94
+ if (!scrollContainer) return;
95
+
96
+ const containerRect = scrollContainer.getBoundingClientRect();
97
+ const elementRect = dropZoneElement.getBoundingClientRect();
98
+
99
+ const elementTop =
100
+ elementRect.top - containerRect.top + scrollContainer.scrollTop;
101
+ const elementHeight = elementRect.height;
102
+ const containerHeight = containerRect.height;
103
+
104
+ const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
105
+ const startScroll = scrollContainer.scrollTop;
106
+ const distance = targetScroll - startScroll;
107
+ if (Math.abs(distance) < 10) return;
108
+
109
+ const duration = 800;
110
+ let startTime: number | null = null;
111
+
112
+ const easeInOutQuad = (t: number): number => {
113
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
114
+ };
115
+
116
+ const animate = (currentTime: number) => {
117
+ if (startTime === null) startTime = currentTime;
118
+
119
+ const elapsed = currentTime - startTime;
120
+ const progress = Math.min(elapsed / duration, 1);
121
+ const easedProgress = easeInOutQuad(progress);
122
+
123
+ const newScrollTop = startScroll + distance * easedProgress;
124
+ scrollContainer.scrollTop = newScrollTop;
125
+ if (progress < 1) {
126
+ requestAnimationFrame(animate);
127
+ }
128
+ };
129
+
130
+ requestAnimationFrame(animate);
78
131
  }, [dropTargetKey]);
79
132
 
80
133
  const retrieveAnswerMap = () => {
@@ -85,13 +85,12 @@ const MatchingActivityMaterialContent = ({
85
85
  parent = parent.parentElement;
86
86
  }
87
87
 
88
- return document.documentElement; // Fallback to document scroll
88
+ return document.documentElement;
89
89
  };
90
90
 
91
91
  const scrollContainer = findScrollableParent(dropZoneElement);
92
92
  if (!scrollContainer) return;
93
93
 
94
- // Get the element's position relative to the scroll container
95
94
  const containerRect = scrollContainer.getBoundingClientRect();
96
95
  const elementRect = dropZoneElement.getBoundingClientRect();
97
96
 
@@ -100,18 +99,9 @@ const MatchingActivityMaterialContent = ({
100
99
  const elementHeight = elementRect.height;
101
100
  const containerHeight = containerRect.height;
102
101
 
103
- // Calculate target scroll position (center the element in the container)
104
102
  const targetScroll = elementTop - containerHeight / 2 + elementHeight / 2;
105
103
  const startScroll = scrollContainer.scrollTop;
106
104
  const distance = targetScroll - startScroll;
107
-
108
- console.log("Scrolling to element:", dropTargetKey);
109
- console.log("Scroll container:", scrollContainer);
110
- console.log("Current scroll:", startScroll);
111
- console.log("Target scroll:", targetScroll);
112
- console.log("Distance:", distance);
113
-
114
- // Don't animate if already roughly in position
115
105
  if (Math.abs(distance) < 10) return;
116
106
 
117
107
  const duration = 800;
@@ -130,9 +120,6 @@ const MatchingActivityMaterialContent = ({
130
120
 
131
121
  const newScrollTop = startScroll + distance * easedProgress;
132
122
  scrollContainer.scrollTop = newScrollTop;
133
-
134
- console.log("Scrolling to:", newScrollTop);
135
-
136
123
  if (progress < 1) {
137
124
  requestAnimationFrame(animate);
138
125
  }