analytica-frontend-lib 1.2.8 → 1.2.9

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
@@ -34,7 +34,7 @@ export { ThemeToggle } from './ThemeToggle/index.mjs';
34
34
  export { d as SubjectData, e as SubjectEnum, I as SubjectIconProps, S as SubjectInfo, b as getSubjectColorClass, a as getSubjectIcon, g as getSubjectInfo, c as getSubjectName } from './SubjectInfo-Dvt0OodP.mjs';
35
35
  export { c as ThemeActions, T as ThemeMode, b as ThemeState, a as ThemeStore, u as useThemeStore } from './themeStore-P2X64zC-.mjs';
36
36
  export { default as DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, MenuLabel, ProfileMenuFooter, ProfileMenuHeader, ProfileMenuSection, ProfileMenuTrigger, ProfileToggleTheme } from './DropdownMenu/index.mjs';
37
- export { default as Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from './Table/index.mjs';
37
+ export { default as Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, useTableSort } from './Table/index.mjs';
38
38
  export { default as Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './Select/index.mjs';
39
39
  export { default as Menu, MenuContent, MenuItem, MenuOverflow } from './Menu/index.mjs';
40
40
  export { CardActivitiesResults, CardAudio, CardPerformance, CardProgress, CardQuestions, CardResults, CardSimulado, CardSimulationHistory, CardStatus, CardTest, CardTopic } from './Card/index.mjs';
package/dist/index.d.ts CHANGED
@@ -34,7 +34,7 @@ export { ThemeToggle } from './ThemeToggle/index.js';
34
34
  export { d as SubjectData, e as SubjectEnum, I as SubjectIconProps, S as SubjectInfo, b as getSubjectColorClass, a as getSubjectIcon, g as getSubjectInfo, c as getSubjectName } from './SubjectInfo-Dvt0OodP.js';
35
35
  export { c as ThemeActions, T as ThemeMode, b as ThemeState, a as ThemeStore, u as useThemeStore } from './themeStore-P2X64zC-.js';
36
36
  export { default as DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, MenuLabel, ProfileMenuFooter, ProfileMenuHeader, ProfileMenuSection, ProfileMenuTrigger, ProfileToggleTheme } from './DropdownMenu/index.js';
37
- export { default as Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow } from './Table/index.js';
37
+ export { default as Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, useTableSort } from './Table/index.js';
38
38
  export { default as Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './Select/index.js';
39
39
  export { default as Menu, MenuContent, MenuItem, MenuOverflow } from './Menu/index.js';
40
40
  export { CardActivitiesResults, CardAudio, CardPerformance, CardProgress, CardQuestions, CardResults, CardSimulado, CardSimulationHistory, CardStatus, CardTest, CardTopic } from './Card/index.js';
package/dist/index.js CHANGED
@@ -179,6 +179,7 @@ __export(src_exports, {
179
179
  useMobile: () => useMobile,
180
180
  useQuizStore: () => useQuizStore,
181
181
  useRouteAuth: () => useRouteAuth,
182
+ useTableSort: () => useTableSort,
182
183
  useTheme: () => useTheme,
183
184
  useThemeStore: () => useThemeStore,
184
185
  useToastStore: () => ToastStore_default,
@@ -6632,6 +6633,75 @@ var createNotificationsHook = (apiClient) => {
6632
6633
  var import_react23 = require("react");
6633
6634
  var import_phosphor_react16 = require("phosphor-react");
6634
6635
  var import_jsx_runtime39 = require("react/jsx-runtime");
6636
+ function useTableSort(data, options = {}) {
6637
+ const { syncWithUrl = false } = options;
6638
+ const getInitialState = () => {
6639
+ if (!syncWithUrl || globalThis.window === void 0) {
6640
+ return { column: null, direction: null };
6641
+ }
6642
+ const params = new URLSearchParams(globalThis.location.search);
6643
+ const sortBy = params.get("sortBy");
6644
+ const sort = params.get("sort");
6645
+ if (sortBy && sort && (sort === "ASC" || sort === "DESC")) {
6646
+ return {
6647
+ column: sortBy,
6648
+ direction: sort.toLowerCase()
6649
+ };
6650
+ }
6651
+ return { column: null, direction: null };
6652
+ };
6653
+ const initialState = getInitialState();
6654
+ const [sortColumn, setSortColumn] = (0, import_react23.useState)(
6655
+ initialState.column
6656
+ );
6657
+ const [sortDirection, setSortDirection] = (0, import_react23.useState)(
6658
+ initialState.direction
6659
+ );
6660
+ (0, import_react23.useEffect)(() => {
6661
+ if (!syncWithUrl || globalThis.window === void 0) return;
6662
+ const url = new URL(globalThis.location.href);
6663
+ const params = url.searchParams;
6664
+ if (sortColumn && sortDirection) {
6665
+ params.set("sortBy", sortColumn);
6666
+ params.set("sort", sortDirection.toUpperCase());
6667
+ } else {
6668
+ params.delete("sortBy");
6669
+ params.delete("sort");
6670
+ }
6671
+ globalThis.history.replaceState({}, "", url.toString());
6672
+ }, [sortColumn, sortDirection, syncWithUrl]);
6673
+ const handleSort = (column) => {
6674
+ if (sortColumn === column) {
6675
+ if (sortDirection === "asc") {
6676
+ setSortDirection("desc");
6677
+ } else if (sortDirection === "desc") {
6678
+ setSortColumn(null);
6679
+ setSortDirection(null);
6680
+ }
6681
+ } else {
6682
+ setSortColumn(column);
6683
+ setSortDirection("asc");
6684
+ }
6685
+ };
6686
+ const sortedData = (0, import_react23.useMemo)(() => {
6687
+ if (!sortColumn || !sortDirection) {
6688
+ return data;
6689
+ }
6690
+ return [...data].sort((a, b) => {
6691
+ const aValue = a[sortColumn];
6692
+ const bValue = b[sortColumn];
6693
+ if (typeof aValue === "string" && typeof bValue === "string") {
6694
+ const comparison = aValue.localeCompare(bValue);
6695
+ return sortDirection === "asc" ? comparison : -comparison;
6696
+ }
6697
+ if (typeof aValue === "number" && typeof bValue === "number") {
6698
+ return sortDirection === "asc" ? aValue - bValue : bValue - aValue;
6699
+ }
6700
+ return 0;
6701
+ });
6702
+ }, [data, sortColumn, sortDirection]);
6703
+ return { sortedData, sortColumn, sortDirection, handleSort };
6704
+ }
6635
6705
  var Table = (0, import_react23.forwardRef)(
6636
6706
  ({ variant = "default", className, children, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6637
6707
  "div",
@@ -14185,6 +14255,7 @@ function useAppContent(config) {
14185
14255
  useMobile,
14186
14256
  useQuizStore,
14187
14257
  useRouteAuth,
14258
+ useTableSort,
14188
14259
  useTheme,
14189
14260
  useThemeStore,
14190
14261
  useToastStore,