catchup-library-web 2.1.1 → 2.1.2

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.d.mts CHANGED
@@ -135,7 +135,6 @@ interface IOrderingActivityProps {
135
135
  changeAnswer: (e: any) => void;
136
136
  isPreview: boolean;
137
137
  showCorrectAnswer: boolean;
138
- isFullScreen: boolean;
139
138
  }
140
139
  interface IDropdownActivityProps {
141
140
  answerMap: any;
@@ -255,7 +254,7 @@ declare const MCSAActivityContent: ({ answerMap, data, canAnswerQuestion, change
255
254
 
256
255
  declare const OpenEndedActivityContent: ({ answerMap, data, changeAnswer, canAnswerQuestion, showMaterialContent, isPreview, isFullScreen, }: IOpenEndedActivityProps) => react_jsx_runtime.JSX.Element;
257
256
 
258
- declare const OrderingActivityContent: ({ answerMap, data, canAnswerQuestion, changeAnswer, isPreview, showCorrectAnswer, isFullScreen, }: IOrderingActivityProps) => react_jsx_runtime.JSX.Element;
257
+ declare const OrderingActivityContent: ({ answerMap, data, canAnswerQuestion, changeAnswer, isPreview, showCorrectAnswer, }: IOrderingActivityProps) => react_jsx_runtime.JSX.Element;
259
258
 
260
259
  declare const TrueFalseActivityContent: ({ answerMap, data, canAnswerQuestion, changeAnswer, isPreview, showCorrectAnswer, isFullScreen, }: ITrueFalseActivityProps) => react_jsx_runtime.JSX.Element;
261
260
 
package/dist/index.d.ts CHANGED
@@ -135,7 +135,6 @@ interface IOrderingActivityProps {
135
135
  changeAnswer: (e: any) => void;
136
136
  isPreview: boolean;
137
137
  showCorrectAnswer: boolean;
138
- isFullScreen: boolean;
139
138
  }
140
139
  interface IDropdownActivityProps {
141
140
  answerMap: any;
@@ -255,7 +254,7 @@ declare const MCSAActivityContent: ({ answerMap, data, canAnswerQuestion, change
255
254
 
256
255
  declare const OpenEndedActivityContent: ({ answerMap, data, changeAnswer, canAnswerQuestion, showMaterialContent, isPreview, isFullScreen, }: IOpenEndedActivityProps) => react_jsx_runtime.JSX.Element;
257
256
 
258
- declare const OrderingActivityContent: ({ answerMap, data, canAnswerQuestion, changeAnswer, isPreview, showCorrectAnswer, isFullScreen, }: IOrderingActivityProps) => react_jsx_runtime.JSX.Element;
257
+ declare const OrderingActivityContent: ({ answerMap, data, canAnswerQuestion, changeAnswer, isPreview, showCorrectAnswer, }: IOrderingActivityProps) => react_jsx_runtime.JSX.Element;
259
258
 
260
259
  declare const TrueFalseActivityContent: ({ answerMap, data, canAnswerQuestion, changeAnswer, isPreview, showCorrectAnswer, isFullScreen, }: ITrueFalseActivityProps) => react_jsx_runtime.JSX.Element;
261
260
 
package/dist/index.js CHANGED
@@ -2298,7 +2298,19 @@ var retrieveActivityTemplateDTOOptionList = (activityTemplateSet) => {
2298
2298
  };
2299
2299
  var retrieveDefaultOrderingDataMap = (orderingMaterialMap) => {
2300
2300
  const dataMap = {};
2301
- Object.keys(orderingMaterialMap).sort(() => 0.5 - Math.random()).forEach((key, index) => {
2301
+ const originalKeys = Object.keys(orderingMaterialMap);
2302
+ const shuffledKeys = [...originalKeys];
2303
+ for (let i = shuffledKeys.length - 1; i > 0; i--) {
2304
+ const j = Math.floor(Math.random() * (i + 1));
2305
+ [shuffledKeys[i], shuffledKeys[j]] = [shuffledKeys[j], shuffledKeys[i]];
2306
+ }
2307
+ const isSameOrder = shuffledKeys.every(
2308
+ (key, index) => key === originalKeys[index]
2309
+ );
2310
+ if (isSameOrder && shuffledKeys.length >= 2) {
2311
+ [shuffledKeys[0], shuffledKeys[1]] = [shuffledKeys[1], shuffledKeys[0]];
2312
+ }
2313
+ shuffledKeys.forEach((key, index) => {
2302
2314
  dataMap[index] = key;
2303
2315
  });
2304
2316
  return dataMap;
@@ -5227,7 +5239,6 @@ var GroupingActivityMaterialContent = ({
5227
5239
  const [draggedElement, setDraggedElement] = (0, import_react20.useState)(
5228
5240
  null
5229
5241
  );
5230
- const [isShuffled, setIsShuffled] = (0, import_react20.useState)(false);
5231
5242
  const [shuffledMaterialList, setShuffledMaterialList] = (0, import_react20.useState)([]);
5232
5243
  const dragElementRef = (0, import_react20.useRef)(null);
5233
5244
  const [mousePosition, setMousePosition] = (0, import_react20.useState)({
@@ -5240,18 +5251,16 @@ var GroupingActivityMaterialContent = ({
5240
5251
  });
5241
5252
  const ref = (0, import_react20.useRef)(null);
5242
5253
  const dropZoneRefs = (0, import_react20.useRef)({});
5254
+ const hasShuffledRef = (0, import_react20.useRef)(false);
5243
5255
  (0, import_react20.useEffect)(() => {
5256
+ if (hasShuffledRef.current) return;
5244
5257
  const shuffleArray2 = (array) => {
5245
- if (!isShuffled) {
5246
- const copyArray = JSON.parse(JSON.stringify(array));
5247
- for (let i = copyArray.length - 1; i > 0; i--) {
5248
- const j = Math.floor(Math.random() * (i + 1));
5249
- [copyArray[i], copyArray[j]] = [copyArray[j], copyArray[i]];
5250
- }
5251
- setIsShuffled(true);
5252
- return copyArray;
5258
+ const copyArray = JSON.parse(JSON.stringify(array));
5259
+ for (let i = copyArray.length - 1; i > 0; i--) {
5260
+ const j = Math.floor(Math.random() * (i + 1));
5261
+ [copyArray[i], copyArray[j]] = [copyArray[j], copyArray[i]];
5253
5262
  }
5254
- return array;
5263
+ return copyArray;
5255
5264
  };
5256
5265
  const materialList = [];
5257
5266
  Object.keys(materialMap).forEach((materialKey) => {
@@ -5260,7 +5269,8 @@ var GroupingActivityMaterialContent = ({
5260
5269
  }
5261
5270
  });
5262
5271
  setShuffledMaterialList(shuffleArray2(materialList));
5263
- }, [materialMap, isShuffled]);
5272
+ hasShuffledRef.current = true;
5273
+ }, [materialMap]);
5264
5274
  (0, import_react20.useEffect)(() => {
5265
5275
  if (!showCorrectAnswer) return;
5266
5276
  answerMap = materialMap;
@@ -6825,8 +6835,7 @@ var OrderingActivityContent = ({
6825
6835
  canAnswerQuestion,
6826
6836
  changeAnswer,
6827
6837
  isPreview,
6828
- showCorrectAnswer,
6829
- isFullScreen
6838
+ showCorrectAnswer
6830
6839
  }) => {
6831
6840
  const contentMap = parseContentMapFromData(data);
6832
6841
  const orderingBodyMap = parseBodyMapFromData(data, "ORDERING");
@@ -7301,8 +7310,7 @@ var ActivityPreviewByData = ({
7301
7310
  },
7302
7311
  data,
7303
7312
  isPreview: true,
7304
- showCorrectAnswer: true,
7305
- isFullScreen
7313
+ showCorrectAnswer: true
7306
7314
  }
7307
7315
  ) : selectedType === "DROPDOWN" && data["dropdownBodyMap"] != null && data["dropdownMaterialMap"] != null ? /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
7308
7316
  DropdownActivityContent_default,
package/dist/index.mjs CHANGED
@@ -2074,7 +2074,19 @@ var retrieveActivityTemplateDTOOptionList = (activityTemplateSet) => {
2074
2074
  };
2075
2075
  var retrieveDefaultOrderingDataMap = (orderingMaterialMap) => {
2076
2076
  const dataMap = {};
2077
- Object.keys(orderingMaterialMap).sort(() => 0.5 - Math.random()).forEach((key, index) => {
2077
+ const originalKeys = Object.keys(orderingMaterialMap);
2078
+ const shuffledKeys = [...originalKeys];
2079
+ for (let i = shuffledKeys.length - 1; i > 0; i--) {
2080
+ const j = Math.floor(Math.random() * (i + 1));
2081
+ [shuffledKeys[i], shuffledKeys[j]] = [shuffledKeys[j], shuffledKeys[i]];
2082
+ }
2083
+ const isSameOrder = shuffledKeys.every(
2084
+ (key, index) => key === originalKeys[index]
2085
+ );
2086
+ if (isSameOrder && shuffledKeys.length >= 2) {
2087
+ [shuffledKeys[0], shuffledKeys[1]] = [shuffledKeys[1], shuffledKeys[0]];
2088
+ }
2089
+ shuffledKeys.forEach((key, index) => {
2078
2090
  dataMap[index] = key;
2079
2091
  });
2080
2092
  return dataMap;
@@ -5003,7 +5015,6 @@ var GroupingActivityMaterialContent = ({
5003
5015
  const [draggedElement, setDraggedElement] = useState19(
5004
5016
  null
5005
5017
  );
5006
- const [isShuffled, setIsShuffled] = useState19(false);
5007
5018
  const [shuffledMaterialList, setShuffledMaterialList] = useState19([]);
5008
5019
  const dragElementRef = useRef5(null);
5009
5020
  const [mousePosition, setMousePosition] = useState19({
@@ -5016,18 +5027,16 @@ var GroupingActivityMaterialContent = ({
5016
5027
  });
5017
5028
  const ref = useRef5(null);
5018
5029
  const dropZoneRefs = useRef5({});
5030
+ const hasShuffledRef = useRef5(false);
5019
5031
  useEffect10(() => {
5032
+ if (hasShuffledRef.current) return;
5020
5033
  const shuffleArray2 = (array) => {
5021
- if (!isShuffled) {
5022
- const copyArray = JSON.parse(JSON.stringify(array));
5023
- for (let i = copyArray.length - 1; i > 0; i--) {
5024
- const j = Math.floor(Math.random() * (i + 1));
5025
- [copyArray[i], copyArray[j]] = [copyArray[j], copyArray[i]];
5026
- }
5027
- setIsShuffled(true);
5028
- return copyArray;
5034
+ const copyArray = JSON.parse(JSON.stringify(array));
5035
+ for (let i = copyArray.length - 1; i > 0; i--) {
5036
+ const j = Math.floor(Math.random() * (i + 1));
5037
+ [copyArray[i], copyArray[j]] = [copyArray[j], copyArray[i]];
5029
5038
  }
5030
- return array;
5039
+ return copyArray;
5031
5040
  };
5032
5041
  const materialList = [];
5033
5042
  Object.keys(materialMap).forEach((materialKey) => {
@@ -5036,7 +5045,8 @@ var GroupingActivityMaterialContent = ({
5036
5045
  }
5037
5046
  });
5038
5047
  setShuffledMaterialList(shuffleArray2(materialList));
5039
- }, [materialMap, isShuffled]);
5048
+ hasShuffledRef.current = true;
5049
+ }, [materialMap]);
5040
5050
  useEffect10(() => {
5041
5051
  if (!showCorrectAnswer) return;
5042
5052
  answerMap = materialMap;
@@ -6601,8 +6611,7 @@ var OrderingActivityContent = ({
6601
6611
  canAnswerQuestion,
6602
6612
  changeAnswer,
6603
6613
  isPreview,
6604
- showCorrectAnswer,
6605
- isFullScreen
6614
+ showCorrectAnswer
6606
6615
  }) => {
6607
6616
  const contentMap = parseContentMapFromData(data);
6608
6617
  const orderingBodyMap = parseBodyMapFromData(data, "ORDERING");
@@ -7077,8 +7086,7 @@ var ActivityPreviewByData = ({
7077
7086
  },
7078
7087
  data,
7079
7088
  isPreview: true,
7080
- showCorrectAnswer: true,
7081
- isFullScreen
7089
+ showCorrectAnswer: true
7082
7090
  }
7083
7091
  ) : selectedType === "DROPDOWN" && data["dropdownBodyMap"] != null && data["dropdownMaterialMap"] != null ? /* @__PURE__ */ jsx47(
7084
7092
  DropdownActivityContent_default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catchup-library-web",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -120,7 +120,6 @@ const ActivityPreviewByData = ({
120
120
  data={data}
121
121
  isPreview={true}
122
122
  showCorrectAnswer={true}
123
- isFullScreen={isFullScreen}
124
123
  />
125
124
  ) : selectedType === "DROPDOWN" &&
126
125
  data["dropdownBodyMap"] != null &&
@@ -15,7 +15,6 @@ const OrderingActivityContent = ({
15
15
  changeAnswer,
16
16
  isPreview,
17
17
  showCorrectAnswer,
18
- isFullScreen,
19
18
  }: IOrderingActivityProps) => {
20
19
  const contentMap = parseContentMapFromData(data);
21
20
  const orderingBodyMap = parseBodyMapFromData(data, "ORDERING");
@@ -21,7 +21,6 @@ const GroupingActivityMaterialContent = ({
21
21
  const [draggedElement, setDraggedElement] = useState<HTMLElement | null>(
22
22
  null
23
23
  );
24
- const [isShuffled, setIsShuffled] = useState(false);
25
24
  const [shuffledMaterialList, setShuffledMaterialList] = useState<any[]>([]);
26
25
  const dragElementRef = useRef<HTMLDivElement>(null);
27
26
  const [mousePosition, setMousePosition] = useState<{ x: number; y: number }>({
@@ -34,28 +33,30 @@ const GroupingActivityMaterialContent = ({
34
33
  });
35
34
  const ref = useRef<HTMLDivElement>(null);
36
35
  const dropZoneRefs = useRef<{ [key: string]: HTMLDivElement | null }>({});
36
+ const hasShuffledRef = useRef<boolean>(false);
37
37
 
38
38
  useEffect(() => {
39
+ if (hasShuffledRef.current) return;
40
+
39
41
  const shuffleArray = (array: any) => {
40
- if (!isShuffled) {
41
- const copyArray = JSON.parse(JSON.stringify(array));
42
- for (let i = copyArray.length - 1; i > 0; i--) {
43
- const j = Math.floor(Math.random() * (i + 1));
44
- [copyArray[i], copyArray[j]] = [copyArray[j], copyArray[i]];
45
- }
46
- setIsShuffled(true);
47
- return copyArray;
42
+ const copyArray = JSON.parse(JSON.stringify(array));
43
+ for (let i = copyArray.length - 1; i > 0; i--) {
44
+ const j = Math.floor(Math.random() * (i + 1));
45
+ [copyArray[i], copyArray[j]] = [copyArray[j], copyArray[i]];
48
46
  }
49
- return array;
47
+ return copyArray;
50
48
  };
49
+
51
50
  const materialList: any = [];
52
51
  Object.keys(materialMap).forEach((materialKey) => {
53
52
  for (const materialValue of materialMap[materialKey]) {
54
53
  materialList.push(materialValue);
55
54
  }
56
55
  });
56
+
57
57
  setShuffledMaterialList(shuffleArray(materialList));
58
- }, [materialMap, isShuffled]);
58
+ hasShuffledRef.current = true;
59
+ }, [materialMap]);
59
60
 
60
61
  useEffect(() => {
61
62
  if (!showCorrectAnswer) return;
@@ -68,7 +69,6 @@ const GroupingActivityMaterialContent = ({
68
69
  const dropZoneElement = dropZoneRefs.current[dropTargetKey];
69
70
  if (!dropZoneElement) return;
70
71
 
71
- // Find the scrollable parent container
72
72
  const findScrollableParent = (element: HTMLElement): HTMLElement | null => {
73
73
  let parent = element.parentElement;
74
74
 
@@ -155,7 +155,6 @@ const GroupingActivityMaterialContent = ({
155
155
  return "INCORRECT";
156
156
  };
157
157
 
158
- // Mouse drag handlers
159
158
  const handleMouseDown = (
160
159
  e: React.MouseEvent,
161
160
  materialValue: string
@@ -172,7 +171,6 @@ const GroupingActivityMaterialContent = ({
172
171
 
173
172
  setMousePosition({ x: e.clientX, y: e.clientY });
174
173
 
175
- // Find the element under the mouse point
176
174
  const elementUnder = document.elementFromPoint(e.clientX, e.clientY);
177
175
  const dropZone = elementUnder?.closest("[data-grouping-drop-zone]");
178
176
 
@@ -193,7 +191,6 @@ const GroupingActivityMaterialContent = ({
193
191
  setMousePosition({ x: 0, y: 0 });
194
192
  };
195
193
 
196
- // Touch drag handlers
197
194
  const handleTouchStart = (
198
195
  e: React.TouchEvent,
199
196
  materialValue: string,
@@ -213,7 +210,6 @@ const GroupingActivityMaterialContent = ({
213
210
  const touch = e.touches[0];
214
211
  setTouchPosition({ x: touch.clientX, y: touch.clientY });
215
212
 
216
- // Find the element under the touch point
217
213
  const elementUnder = document.elementFromPoint(
218
214
  touch.clientX,
219
215
  touch.clientY
@@ -238,7 +234,6 @@ const GroupingActivityMaterialContent = ({
238
234
  setTouchPosition({ x: 0, y: 0 });
239
235
  };
240
236
 
241
- // Click/tap to select (for easier mobile interaction)
242
237
  const handleSelectItem = (materialValue: string): void => {
243
238
  if (!checkCanAnswerQuestion()) return;
244
239
  setSelectedValue(materialValue);
@@ -78,7 +78,6 @@ const OrderingActivityMaterialContent = ({
78
78
  return 0;
79
79
  };
80
80
 
81
- // Mouse drag handlers
82
81
  const handleMouseDown = (e: React.MouseEvent, materialKey: string): void => {
83
82
  if (!checkCanAnswerQuestion()) return;
84
83
  e.preventDefault();
@@ -117,7 +116,6 @@ const OrderingActivityMaterialContent = ({
117
116
  setMousePosition({ x: 0, y: 0 });
118
117
  };
119
118
 
120
- // Touch drag handlers
121
119
  const handleTouchStart = (
122
120
  e: React.TouchEvent,
123
121
  materialKey: string,
@@ -166,7 +164,6 @@ const OrderingActivityMaterialContent = ({
166
164
  setTouchPosition({ x: 0, y: 0 });
167
165
  };
168
166
 
169
- // Click/tap to select (for easier mobile interaction)
170
167
  const handleSelectItem = (materialKey: string): void => {
171
168
  if (!checkCanAnswerQuestion()) return;
172
169
 
@@ -187,7 +184,6 @@ const OrderingActivityMaterialContent = ({
187
184
  onMouseMove={handleMouseMove}
188
185
  onMouseUp={handleMouseUp}
189
186
  >
190
- {/* Floating drag preview for mouse */}
191
187
  {draggedKey && mousePosition.x > 0 && (
192
188
  <div
193
189
  className="fixed pointer-events-none z-50 opacity-80"
@@ -233,7 +229,6 @@ const OrderingActivityMaterialContent = ({
233
229
  </div>
234
230
  )}
235
231
 
236
- {/* Floating drag preview for touch */}
237
232
  {draggedKey && touchPosition.x > 0 && (
238
233
  <div
239
234
  className="fixed pointer-events-none z-50 opacity-80"
@@ -26,7 +26,6 @@ export interface IOrderingActivityProps {
26
26
  changeAnswer: (e: any) => void;
27
27
  isPreview: boolean;
28
28
  showCorrectAnswer: boolean;
29
- isFullScreen: boolean;
30
29
  }
31
30
 
32
31
  export interface IOrderingActivityMaterialProps {
@@ -1112,11 +1112,25 @@ export const retrieveActivityTemplateDTOOptionList = (
1112
1112
 
1113
1113
  const retrieveDefaultOrderingDataMap = (orderingMaterialMap: any) => {
1114
1114
  const dataMap: any = {};
1115
- Object.keys(orderingMaterialMap)
1116
- .sort(() => 0.5 - Math.random())
1117
- .forEach((key, index) => {
1118
- dataMap[index] = key;
1119
- });
1115
+ const originalKeys = Object.keys(orderingMaterialMap);
1116
+ const shuffledKeys = [...originalKeys];
1117
+
1118
+ for (let i = shuffledKeys.length - 1; i > 0; i--) {
1119
+ const j = Math.floor(Math.random() * (i + 1));
1120
+ [shuffledKeys[i], shuffledKeys[j]] = [shuffledKeys[j], shuffledKeys[i]];
1121
+ }
1122
+
1123
+ const isSameOrder = shuffledKeys.every(
1124
+ (key, index) => key === originalKeys[index]
1125
+ );
1126
+
1127
+ if (isSameOrder && shuffledKeys.length >= 2) {
1128
+ [shuffledKeys[0], shuffledKeys[1]] = [shuffledKeys[1], shuffledKeys[0]];
1129
+ }
1130
+
1131
+ shuffledKeys.forEach((key, index) => {
1132
+ dataMap[index] = key;
1133
+ });
1120
1134
 
1121
1135
  return dataMap;
1122
1136
  };