analytica-frontend-lib 1.2.9 → 1.2.10

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.
@@ -1004,6 +1004,7 @@ var useQuizStore = create2()(
1004
1004
  userId: "",
1005
1005
  variant: "default",
1006
1006
  minuteCallback: null,
1007
+ dissertativeCharLimit: void 0,
1007
1008
  questionsResult: null,
1008
1009
  currentQuestionResult: null,
1009
1010
  // Setters
@@ -1013,6 +1014,8 @@ var useQuizStore = create2()(
1013
1014
  getUserId: () => get().userId,
1014
1015
  setVariant: (variant) => set({ variant }),
1015
1016
  setQuestionResult: (questionsResult) => set({ questionsResult }),
1017
+ setDissertativeCharLimit: (limit) => set({ dissertativeCharLimit: limit }),
1018
+ getDissertativeCharLimit: () => get().dissertativeCharLimit,
1016
1019
  // Navigation
1017
1020
  goToNextQuestion: () => {
1018
1021
  const { currentQuestionIndex, getTotalQuestions } = get();
@@ -1102,7 +1105,7 @@ var useQuizStore = create2()(
1102
1105
  });
1103
1106
  },
1104
1107
  selectDissertativeAnswer: (questionId, answer) => {
1105
- const { quiz, userAnswers } = get();
1108
+ const { quiz, userAnswers, dissertativeCharLimit } = get();
1106
1109
  if (!quiz) return;
1107
1110
  const activityId = quiz.id;
1108
1111
  const userId = get().getUserId();
@@ -1113,6 +1116,10 @@ var useQuizStore = create2()(
1113
1116
  if (!question || question.questionType !== "DISSERTATIVA" /* DISSERTATIVA */) {
1114
1117
  return;
1115
1118
  }
1119
+ let validatedAnswer = answer;
1120
+ if (dissertativeCharLimit !== void 0 && answer.length > dissertativeCharLimit) {
1121
+ validatedAnswer = answer.substring(0, dissertativeCharLimit);
1122
+ }
1116
1123
  const existingAnswerIndex = userAnswers.findIndex(
1117
1124
  (answerItem) => answerItem.questionId === questionId
1118
1125
  );
@@ -1120,7 +1127,7 @@ var useQuizStore = create2()(
1120
1127
  questionId,
1121
1128
  activityId,
1122
1129
  userId,
1123
- answer,
1130
+ answer: validatedAnswer,
1124
1131
  optionId: null,
1125
1132
  questionType: "DISSERTATIVA" /* DISSERTATIVA */,
1126
1133
  answerStatus: "PENDENTE_AVALIACAO" /* PENDENTE_AVALIACAO */
@@ -1233,6 +1240,7 @@ var useQuizStore = create2()(
1233
1240
  userId: "",
1234
1241
  variant: "default",
1235
1242
  minuteCallback: null,
1243
+ dissertativeCharLimit: void 0,
1236
1244
  questionsResult: null,
1237
1245
  currentQuestionResult: null
1238
1246
  });
@@ -2295,11 +2303,16 @@ var TextArea = forwardRef6(
2295
2303
  onChange,
2296
2304
  placeholder,
2297
2305
  required,
2306
+ showCharacterCount = false,
2307
+ maxLength,
2308
+ value,
2298
2309
  ...props
2299
2310
  }, ref) => {
2300
2311
  const generatedId = useId5();
2301
2312
  const inputId = id ?? `textarea-${generatedId}`;
2302
2313
  const [isFocused, setIsFocused] = useState3(false);
2314
+ const currentLength = typeof value === "string" ? value.length : 0;
2315
+ const isNearLimit = maxLength && currentLength >= maxLength * 0.8;
2303
2316
  const handleChange = (event) => {
2304
2317
  onChange?.(event);
2305
2318
  };
@@ -2354,6 +2367,8 @@ var TextArea = forwardRef6(
2354
2367
  className: textareaClasses,
2355
2368
  placeholder,
2356
2369
  required,
2370
+ maxLength,
2371
+ value,
2357
2372
  ...props
2358
2373
  }
2359
2374
  ),
@@ -2362,7 +2377,21 @@ var TextArea = forwardRef6(
2362
2377
  " ",
2363
2378
  errorMessage
2364
2379
  ] }),
2365
- helperMessage && !errorMessage && /* @__PURE__ */ jsx10(Text_default, { size: "sm", weight: "normal", className: "mt-1.5 text-text-500", children: helperMessage })
2380
+ !errorMessage && showCharacterCount && maxLength && /* @__PURE__ */ jsxs8(
2381
+ Text_default,
2382
+ {
2383
+ size: "sm",
2384
+ weight: "normal",
2385
+ className: `mt-1.5 ${isNearLimit ? "text-indicator-warning" : "text-text-500"}`,
2386
+ children: [
2387
+ currentLength,
2388
+ "/",
2389
+ maxLength,
2390
+ " caracteres"
2391
+ ]
2392
+ }
2393
+ ),
2394
+ !errorMessage && helperMessage && !(showCharacterCount && maxLength) && /* @__PURE__ */ jsx10(Text_default, { size: "sm", weight: "normal", className: "mt-1.5 text-text-500", children: helperMessage })
2366
2395
  ] });
2367
2396
  }
2368
2397
  );
@@ -3068,7 +3097,8 @@ var QuizDissertative = ({ paddingBottom }) => {
3068
3097
  getCurrentAnswer,
3069
3098
  selectDissertativeAnswer,
3070
3099
  getQuestionResultByQuestionId,
3071
- variant
3100
+ variant,
3101
+ getDissertativeCharLimit
3072
3102
  } = useQuizStore();
3073
3103
  const currentQuestion = getCurrentQuestion();
3074
3104
  const currentQuestionResult = getQuestionResultByQuestionId(
@@ -3076,6 +3106,7 @@ var QuizDissertative = ({ paddingBottom }) => {
3076
3106
  );
3077
3107
  const currentAnswer = getCurrentAnswer();
3078
3108
  const textareaRef = useRef4(null);
3109
+ const charLimit = getDissertativeCharLimit();
3079
3110
  const handleAnswerChange = (value) => {
3080
3111
  if (currentQuestion) {
3081
3112
  selectDissertativeAnswer(currentQuestion.id, value);
@@ -3108,7 +3139,9 @@ var QuizDissertative = ({ paddingBottom }) => {
3108
3139
  value: localAnswer,
3109
3140
  onChange: (e) => handleAnswerChange(e.target.value),
3110
3141
  rows: 4,
3111
- className: "min-h-[120px] max-h-[400px] resize-none overflow-y-auto"
3142
+ className: "min-h-[120px] max-h-[400px] resize-none overflow-y-auto",
3143
+ maxLength: charLimit,
3144
+ showCharacterCount: !!charLimit
3112
3145
  }
3113
3146
  ) }) : /* @__PURE__ */ jsx14("div", { className: "space-y-4", children: /* @__PURE__ */ jsx14("p", { className: "text-text-600 text-md whitespace-pre-wrap", children: localAnswer || "Nenhuma resposta fornecida" }) }) }) }),
3114
3147
  variant === "result" && currentQuestionResult?.answerStatus == "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */ && /* @__PURE__ */ jsxs11(Fragment3, { children: [