@nualang/nualang-ui-components 0.1.1142 → 0.1.1143

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.
@@ -66,7 +66,7 @@ function Exercises({
66
66
  }, []);
67
67
  return /*#__PURE__*/_react.default.createElement("div", null, !showTable ? /*#__PURE__*/_react.default.createElement(_reactChartjs.Bar, {
68
68
  "aria-label": alt ? alt : "Exercises Completed Chart",
69
- "aria-role": "img",
69
+ role: "img",
70
70
  data: exercisesData,
71
71
  options: {
72
72
  indexAxis: "y",
@@ -101,7 +101,7 @@ function CourseInformation({
101
101
  variant: "outlined",
102
102
  fullWidth: true,
103
103
  required: true
104
- }, difficultyOptions)), " ", /*#__PURE__*/_react.default.createElement(_material.Grid, {
104
+ }, difficultyOptions)), " ", /*#__PURE__*/_react.default.createElement(_material.Grid, {
105
105
  item: true,
106
106
  xs: 12
107
107
  }, /*#__PURE__*/_react.default.createElement(_LanguageSelector.default, {
@@ -271,40 +271,42 @@ function useExerciseState({
271
271
  (0, _react.useEffect)(() => {
272
272
  if (["translation"].includes(exerciseName)) {
273
273
  if (currentTranslations && currentTranslations.length > 0) {
274
- // Create an array of the needed words for the translation
275
274
  const currentTranslationArray = currentTranslations[0].split(" ");
276
- let wordLibraryCopy = [];
277
- for (let i = 0; i < wordLibrary.length; i++) {
278
- if (i === 0) {
279
- if (!wordLibrary.includes(`${wordLibrary[i]}-${wordLibrary[i + 1]}`)) {
280
- wordLibraryCopy.push(wordLibrary[i]);
281
- }
282
- } else if (i === wordLibrary.length - 1) {
283
- if (!wordLibrary.includes(`${wordLibrary[i - 1]}-${wordLibrary[i]}`)) {
284
- wordLibraryCopy.push(wordLibrary[i]);
285
- }
286
- } else {
287
- if (i > 0 && i < wordLibrary.length - 1 && !wordLibrary.includes(`${wordLibrary[i]}-${wordLibrary[i + 1]}`) && !wordLibrary.includes(`${wordLibrary[i - 1]}-${wordLibrary[i]}`)) {
288
- wordLibraryCopy.push(wordLibrary[i]);
289
- }
290
- }
291
- }
292
- // Shuffle the word library
293
- (0, _index.shuffle)(wordLibraryCopy);
294
- // Create a unique list of words to prevent duplicates being used for additional options
295
- const wordSet = new Set([...currentTranslationArray, ...wordLibraryCopy]);
296
- // Take up to five additional words as additional options
297
- const additonalOptions = [...wordSet].slice(currentTranslationArray.length, currentTranslationArray.length + 5).filter(w => {
298
- if (currentTranslationArray.includes(w) || currentTranslationArray.includes(w.toLowerCase()) || currentTranslationArray.includes(w.toUpperCase()) || currentTranslationArray.includes((0, _index.capitalize)(w))) {
275
+ const normalizeWord = word => word.replace(/[.,!¡¿?;:]/g, "").toLowerCase();
276
+ const normalizedToOriginalMap = new Map();
277
+ currentTranslationArray.forEach(word => {
278
+ const normalized = normalizeWord(word);
279
+ normalizedToOriginalMap.set(normalized, word);
280
+ });
281
+ const wordLibraryCopy = wordLibrary.filter((word, i, arr) => {
282
+ const prevWord = i > 0 ? arr[i - 1] : null;
283
+ const nextWord = i < arr.length - 1 ? arr[i + 1] : null;
284
+ const prevPair = prevWord ? `${prevWord}-${word}` : null;
285
+ const nextPair = nextWord ? `${word}-${nextWord}` : null;
286
+ if (prevPair && arr.includes(prevPair) || nextPair && arr.includes(nextPair)) {
299
287
  return false;
300
- } else {
288
+ }
289
+ const normalized = normalizeWord(word);
290
+ if (!normalizedToOriginalMap.has(normalized)) {
291
+ normalizedToOriginalMap.set(normalized, word);
301
292
  return true;
302
293
  }
294
+ return false;
303
295
  });
304
- // Create the word options array
305
- const wordOptions = [...currentTranslationArray, ...additonalOptions].map((w, i) => ({
306
- text: w,
307
- id: i
296
+
297
+ // Shuffle the word library copy
298
+ (0, _index.shuffle)(wordLibraryCopy);
299
+
300
+ // Create a set for unique words
301
+ const wordSet = new Set(normalizedToOriginalMap.keys());
302
+
303
+ // Take up to five additional words as options
304
+ const additionalOptions = Array.from(wordSet).slice(currentTranslationArray.length, currentTranslationArray.length + 5);
305
+
306
+ // Create the word options array using the original formatting for display
307
+ const wordOptions = [...currentTranslationArray, ...additionalOptions.map(normalized => normalizedToOriginalMap.get(normalized))].map((text, id) => ({
308
+ text,
309
+ id
308
310
  }));
309
311
  (0, _index.shuffle)(wordOptions);
310
312
  setWordOptions(wordOptions);
@@ -314,40 +316,42 @@ function useExerciseState({
314
316
  (0, _react.useEffect)(() => {
315
317
  if (["listening"].includes(exerciseName)) {
316
318
  if (wordLibrary && wordLibrary.length > 0) {
317
- // Create an array of the needed words for the phrase
318
319
  const currentPhraseArray = currentPhrase.phrase.split(" ");
319
- let wordLibraryCopy = [];
320
- for (let i = 0; i < wordLibrary.length; i++) {
321
- if (i === 0) {
322
- if (!wordLibrary.includes(`${wordLibrary[i]}-${wordLibrary[i + 1]}`)) {
323
- wordLibraryCopy.push(wordLibrary[i]);
324
- }
325
- } else if (i === wordLibrary.length - 1) {
326
- if (!wordLibrary.includes(`${wordLibrary[i - 1]}-${wordLibrary[i]}`)) {
327
- wordLibraryCopy.push(wordLibrary[i]);
328
- }
329
- } else {
330
- if (i > 0 && i < wordLibrary.length - 1 && !wordLibrary.includes(`${wordLibrary[i]}-${wordLibrary[i + 1]}`) && !wordLibrary.includes(`${wordLibrary[i - 1]}-${wordLibrary[i]}`)) {
331
- wordLibraryCopy.push(wordLibrary[i]);
332
- }
333
- }
334
- }
335
- // Shuffle the word library
336
- (0, _index.shuffle)(wordLibraryCopy);
337
- // Create a unique list of words to prevent duplicates being used for additional options
338
- const wordSet = new Set([...currentPhraseArray, ...wordLibraryCopy]);
339
- // Take up to five additional words as additional options
340
- const additonalOptions = [...wordSet].slice(currentPhraseArray.length, currentPhraseArray.length + 5).filter(w => {
341
- if (currentPhraseArray.includes(w) || currentPhraseArray.includes(w.toLowerCase()) || currentPhraseArray.includes(w.toUpperCase()) || currentPhraseArray.includes((0, _index.capitalize)(w))) {
320
+ const normalizeWord = word => word.replace(/[.,!¡¿?;:]/g, "").toLowerCase();
321
+ const normalizedToOriginalMap = new Map();
322
+ currentPhraseArray.forEach(word => {
323
+ const normalized = normalizeWord(word);
324
+ normalizedToOriginalMap.set(normalized, word);
325
+ });
326
+ const wordLibraryCopy = wordLibrary.filter((word, i, arr) => {
327
+ const prevWord = i > 0 ? arr[i - 1] : null;
328
+ const nextWord = i < arr.length - 1 ? arr[i + 1] : null;
329
+ const prevPair = prevWord ? `${prevWord}-${word}` : null;
330
+ const nextPair = nextWord ? `${word}-${nextWord}` : null;
331
+ if (prevPair && arr.includes(prevPair) || nextPair && arr.includes(nextPair)) {
342
332
  return false;
343
- } else {
333
+ }
334
+ const normalized = normalizeWord(word);
335
+ if (!normalizedToOriginalMap.has(normalized)) {
336
+ normalizedToOriginalMap.set(normalized, word);
344
337
  return true;
345
338
  }
339
+ return false;
346
340
  });
347
- // Create the word options array
348
- const wordOptions = [...currentPhraseArray, ...additonalOptions].map((w, i) => ({
349
- text: w,
350
- id: i
341
+
342
+ // Shuffle the word library copy
343
+ (0, _index.shuffle)(wordLibraryCopy);
344
+
345
+ // Create a set of normalized words to ensure uniqueness
346
+ const wordSet = new Set(normalizedToOriginalMap.keys());
347
+
348
+ // Take up to five additional words as options
349
+ const additionalOptions = Array.from(wordSet).slice(currentPhraseArray.length, currentPhraseArray.length + 5);
350
+
351
+ // Create the word options array using the original formatting for display
352
+ const wordOptions = [...currentPhraseArray, ...additionalOptions.map(normalized => normalizedToOriginalMap.get(normalized))].map((text, id) => ({
353
+ text,
354
+ id
351
355
  }));
352
356
  (0, _index.shuffle)(wordOptions);
353
357
  setWordOptions(wordOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nualang/nualang-ui-components",
3
- "version": "0.1.1142",
3
+ "version": "0.1.1143",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist",