analytica-frontend-lib 1.2.8 → 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.
package/dist/index.mjs CHANGED
@@ -1864,11 +1864,16 @@ var TextArea = forwardRef7(
1864
1864
  onChange,
1865
1865
  placeholder,
1866
1866
  required,
1867
+ showCharacterCount = false,
1868
+ maxLength,
1869
+ value,
1867
1870
  ...props
1868
1871
  }, ref) => {
1869
1872
  const generatedId = useId4();
1870
1873
  const inputId = id ?? `textarea-${generatedId}`;
1871
1874
  const [isFocused, setIsFocused] = useState5(false);
1875
+ const currentLength = typeof value === "string" ? value.length : 0;
1876
+ const isNearLimit = maxLength && currentLength >= maxLength * 0.8;
1872
1877
  const handleChange = (event) => {
1873
1878
  onChange?.(event);
1874
1879
  };
@@ -1923,6 +1928,8 @@ var TextArea = forwardRef7(
1923
1928
  className: textareaClasses,
1924
1929
  placeholder,
1925
1930
  required,
1931
+ maxLength,
1932
+ value,
1926
1933
  ...props
1927
1934
  }
1928
1935
  ),
@@ -1931,7 +1938,21 @@ var TextArea = forwardRef7(
1931
1938
  " ",
1932
1939
  errorMessage
1933
1940
  ] }),
1934
- helperMessage && !errorMessage && /* @__PURE__ */ jsx14(Text_default, { size: "sm", weight: "normal", className: "mt-1.5 text-text-500", children: helperMessage })
1941
+ !errorMessage && showCharacterCount && maxLength && /* @__PURE__ */ jsxs10(
1942
+ Text_default,
1943
+ {
1944
+ size: "sm",
1945
+ weight: "normal",
1946
+ className: `mt-1.5 ${isNearLimit ? "text-indicator-warning" : "text-text-500"}`,
1947
+ children: [
1948
+ currentLength,
1949
+ "/",
1950
+ maxLength,
1951
+ " caracteres"
1952
+ ]
1953
+ }
1954
+ ),
1955
+ !errorMessage && helperMessage && !(showCharacterCount && maxLength) && /* @__PURE__ */ jsx14(Text_default, { size: "sm", weight: "normal", className: "mt-1.5 text-text-500", children: helperMessage })
1935
1956
  ] });
1936
1957
  }
1937
1958
  );
@@ -6512,6 +6533,75 @@ import {
6512
6533
  } from "react";
6513
6534
  import { CaretUp, CaretDown } from "phosphor-react";
6514
6535
  import { jsx as jsx39, jsxs as jsxs28 } from "react/jsx-runtime";
6536
+ function useTableSort(data, options = {}) {
6537
+ const { syncWithUrl = false } = options;
6538
+ const getInitialState = () => {
6539
+ if (!syncWithUrl || globalThis.window === void 0) {
6540
+ return { column: null, direction: null };
6541
+ }
6542
+ const params = new URLSearchParams(globalThis.location.search);
6543
+ const sortBy = params.get("sortBy");
6544
+ const sort = params.get("sort");
6545
+ if (sortBy && sort && (sort === "ASC" || sort === "DESC")) {
6546
+ return {
6547
+ column: sortBy,
6548
+ direction: sort.toLowerCase()
6549
+ };
6550
+ }
6551
+ return { column: null, direction: null };
6552
+ };
6553
+ const initialState = getInitialState();
6554
+ const [sortColumn, setSortColumn] = useState13(
6555
+ initialState.column
6556
+ );
6557
+ const [sortDirection, setSortDirection] = useState13(
6558
+ initialState.direction
6559
+ );
6560
+ useEffect13(() => {
6561
+ if (!syncWithUrl || globalThis.window === void 0) return;
6562
+ const url = new URL(globalThis.location.href);
6563
+ const params = url.searchParams;
6564
+ if (sortColumn && sortDirection) {
6565
+ params.set("sortBy", sortColumn);
6566
+ params.set("sort", sortDirection.toUpperCase());
6567
+ } else {
6568
+ params.delete("sortBy");
6569
+ params.delete("sort");
6570
+ }
6571
+ globalThis.history.replaceState({}, "", url.toString());
6572
+ }, [sortColumn, sortDirection, syncWithUrl]);
6573
+ const handleSort = (column) => {
6574
+ if (sortColumn === column) {
6575
+ if (sortDirection === "asc") {
6576
+ setSortDirection("desc");
6577
+ } else if (sortDirection === "desc") {
6578
+ setSortColumn(null);
6579
+ setSortDirection(null);
6580
+ }
6581
+ } else {
6582
+ setSortColumn(column);
6583
+ setSortDirection("asc");
6584
+ }
6585
+ };
6586
+ const sortedData = useMemo5(() => {
6587
+ if (!sortColumn || !sortDirection) {
6588
+ return data;
6589
+ }
6590
+ return [...data].sort((a, b) => {
6591
+ const aValue = a[sortColumn];
6592
+ const bValue = b[sortColumn];
6593
+ if (typeof aValue === "string" && typeof bValue === "string") {
6594
+ const comparison = aValue.localeCompare(bValue);
6595
+ return sortDirection === "asc" ? comparison : -comparison;
6596
+ }
6597
+ if (typeof aValue === "number" && typeof bValue === "number") {
6598
+ return sortDirection === "asc" ? aValue - bValue : bValue - aValue;
6599
+ }
6600
+ return 0;
6601
+ });
6602
+ }, [data, sortColumn, sortDirection]);
6603
+ return { sortedData, sortColumn, sortDirection, handleSort };
6604
+ }
6515
6605
  var Table = forwardRef14(
6516
6606
  ({ variant = "default", className, children, ...props }, ref) => /* @__PURE__ */ jsx39(
6517
6607
  "div",
@@ -11125,6 +11215,7 @@ var useQuizStore = create10()(
11125
11215
  userId: "",
11126
11216
  variant: "default",
11127
11217
  minuteCallback: null,
11218
+ dissertativeCharLimit: void 0,
11128
11219
  questionsResult: null,
11129
11220
  currentQuestionResult: null,
11130
11221
  // Setters
@@ -11134,6 +11225,8 @@ var useQuizStore = create10()(
11134
11225
  getUserId: () => get().userId,
11135
11226
  setVariant: (variant) => set({ variant }),
11136
11227
  setQuestionResult: (questionsResult) => set({ questionsResult }),
11228
+ setDissertativeCharLimit: (limit) => set({ dissertativeCharLimit: limit }),
11229
+ getDissertativeCharLimit: () => get().dissertativeCharLimit,
11137
11230
  // Navigation
11138
11231
  goToNextQuestion: () => {
11139
11232
  const { currentQuestionIndex, getTotalQuestions } = get();
@@ -11223,7 +11316,7 @@ var useQuizStore = create10()(
11223
11316
  });
11224
11317
  },
11225
11318
  selectDissertativeAnswer: (questionId, answer) => {
11226
- const { quiz, userAnswers } = get();
11319
+ const { quiz, userAnswers, dissertativeCharLimit } = get();
11227
11320
  if (!quiz) return;
11228
11321
  const activityId = quiz.id;
11229
11322
  const userId = get().getUserId();
@@ -11234,6 +11327,10 @@ var useQuizStore = create10()(
11234
11327
  if (!question || question.questionType !== "DISSERTATIVA" /* DISSERTATIVA */) {
11235
11328
  return;
11236
11329
  }
11330
+ let validatedAnswer = answer;
11331
+ if (dissertativeCharLimit !== void 0 && answer.length > dissertativeCharLimit) {
11332
+ validatedAnswer = answer.substring(0, dissertativeCharLimit);
11333
+ }
11237
11334
  const existingAnswerIndex = userAnswers.findIndex(
11238
11335
  (answerItem) => answerItem.questionId === questionId
11239
11336
  );
@@ -11241,7 +11338,7 @@ var useQuizStore = create10()(
11241
11338
  questionId,
11242
11339
  activityId,
11243
11340
  userId,
11244
- answer,
11341
+ answer: validatedAnswer,
11245
11342
  optionId: null,
11246
11343
  questionType: "DISSERTATIVA" /* DISSERTATIVA */,
11247
11344
  answerStatus: "PENDENTE_AVALIACAO" /* PENDENTE_AVALIACAO */
@@ -11354,6 +11451,7 @@ var useQuizStore = create10()(
11354
11451
  userId: "",
11355
11452
  variant: "default",
11356
11453
  minuteCallback: null,
11454
+ dissertativeCharLimit: void 0,
11357
11455
  questionsResult: null,
11358
11456
  currentQuestionResult: null
11359
11457
  });
@@ -11968,7 +12066,8 @@ var QuizDissertative = ({ paddingBottom }) => {
11968
12066
  getCurrentAnswer,
11969
12067
  selectDissertativeAnswer,
11970
12068
  getQuestionResultByQuestionId,
11971
- variant
12069
+ variant,
12070
+ getDissertativeCharLimit
11972
12071
  } = useQuizStore();
11973
12072
  const currentQuestion = getCurrentQuestion();
11974
12073
  const currentQuestionResult = getQuestionResultByQuestionId(
@@ -11976,6 +12075,7 @@ var QuizDissertative = ({ paddingBottom }) => {
11976
12075
  );
11977
12076
  const currentAnswer = getCurrentAnswer();
11978
12077
  const textareaRef = useRef14(null);
12078
+ const charLimit = getDissertativeCharLimit();
11979
12079
  const handleAnswerChange = (value) => {
11980
12080
  if (currentQuestion) {
11981
12081
  selectDissertativeAnswer(currentQuestion.id, value);
@@ -12008,7 +12108,9 @@ var QuizDissertative = ({ paddingBottom }) => {
12008
12108
  value: localAnswer,
12009
12109
  onChange: (e) => handleAnswerChange(e.target.value),
12010
12110
  rows: 4,
12011
- className: "min-h-[120px] max-h-[400px] resize-none overflow-y-auto"
12111
+ className: "min-h-[120px] max-h-[400px] resize-none overflow-y-auto",
12112
+ maxLength: charLimit,
12113
+ showCharacterCount: !!charLimit
12012
12114
  }
12013
12115
  ) }) : /* @__PURE__ */ jsx54("div", { className: "space-y-4", children: /* @__PURE__ */ jsx54("p", { className: "text-text-600 text-md whitespace-pre-wrap", children: localAnswer || "Nenhuma resposta fornecida" }) }) }) }),
12014
12116
  variant === "result" && currentQuestionResult?.answerStatus == "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */ && /* @__PURE__ */ jsxs39(Fragment11, { children: [
@@ -14149,6 +14251,7 @@ export {
14149
14251
  useMobile,
14150
14252
  useQuizStore,
14151
14253
  useRouteAuth,
14254
+ useTableSort,
14152
14255
  useTheme,
14153
14256
  useThemeStore,
14154
14257
  ToastStore_default as useToastStore,