erp-pos-ecommerce-shared 0.1.0 → 0.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.
@@ -6,7 +6,7 @@ import { s as TblProductsImage, o as ITableFilterConfig, g as IFilterSelectOptio
6
6
  import * as z from 'zod';
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
8
  import { ColumnDef, Row, useReactTable } from '@tanstack/react-table';
9
- import { D as DataTableConfig, S as ServerTableState } from './datatable.interface-BObLVL2e.js';
9
+ import { D as DataTableConfig, S as ServerTableState } from './datatable.interface-DFSQWdXd.js';
10
10
 
11
11
  interface CreateEditFormProps<T> {
12
12
  fields: IField[];
@@ -123,38 +123,36 @@ interface BottomPaginationProps {
123
123
  declare const BottomPagination: ({ total, pageSize, pageIndex, onPageSizeChange, onPageIndexChange, }: BottomPaginationProps) => react_jsx_runtime.JSX.Element | null;
124
124
 
125
125
  interface DataTableProps$1<TData> {
126
- /** Data to display in the table */
126
+ /** Data to display in the table (current page, already paginated by server) */
127
127
  data: TData[];
128
128
  /** Columns to display in the table */
129
129
  columns: ColumnDef<TData>[];
130
130
  /** Configuration for the table */
131
131
  config?: Partial<DataTableConfig>;
132
- /** Dynamic filters (selects for category, role, etc.) */
132
+ /** Dynamic filters (selects, dates, etc.) */
133
133
  filters?: ITableFilterConfig[];
134
- /** Enable server-side mode: pagination, filters, search handled by backend */
135
- serverSide?: boolean;
136
- /** Total row count from server (required when serverSide) */
134
+ /** Total row count from server (used for pagination) */
137
135
  totalRowCount?: number;
138
- /** Called when table state changes. Use for API calls. */
136
+ /** Called when table state changes (page, search, filters, sort). Use to call your API. */
139
137
  onStateChange?: (state: ServerTableState) => void;
140
- /** Whether the table is loading (shows TableSkeleton) */
138
+ /** Whether the table is loading (shows skeleton) */
141
139
  loading?: boolean;
142
140
  /** Whether to enable row selection */
143
141
  enableRowCheck?: boolean;
144
- /** Called when row selection changes (only when canCheck is true) */
142
+ /** Called when row selection changes */
145
143
  onSelectionChange?: (selectedRows: TData[]) => void;
146
144
  /** Header background color. Use light-dark(light, dark) for theme-aware colors */
147
145
  headerBgColor?: string;
148
- /** Column actions to display in the table */
146
+ /** Column actions to display per row */
149
147
  columnActions?: (row: TData) => React.ReactNode;
150
- /** List menu actions to display in the table */
148
+ /** List menu actions to display per row */
151
149
  listMenuActions?: (row: TData) => {
152
150
  label: string;
153
151
  onClick: () => void;
154
152
  Icon?: React.ElementType;
155
153
  }[];
156
154
  }
157
- declare const DataTable: <TData>({ data, columns, config, filters, serverSide, totalRowCount, onStateChange, loading, enableRowCheck: canCheck, onSelectionChange, headerBgColor, columnActions, listMenuActions, }: DataTableProps$1<TData>) => react_jsx_runtime.JSX.Element;
155
+ declare const DataTable: <TData>({ data, columns, config, filters, totalRowCount, onStateChange, loading, enableRowCheck: canCheck, onSelectionChange, headerBgColor, columnActions, listMenuActions, }: DataTableProps$1<TData>) => react_jsx_runtime.JSX.Element;
158
156
 
159
157
  interface EmptyStateProps {
160
158
  title?: string;
@@ -9,7 +9,7 @@ import { modals } from '@mantine/modals';
9
9
  import { notifications } from '@mantine/notifications';
10
10
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
11
11
  import * as z from 'zod';
12
- import { flexRender, useReactTable, getPaginationRowModel, getSortedRowModel, getFilteredRowModel, getCoreRowModel } from '@tanstack/react-table';
12
+ import { flexRender, useReactTable, getPaginationRowModel, getCoreRowModel } from '@tanstack/react-table';
13
13
  import { ArrowDown, ArrowUp, ArrowUpDown, FileX, X, Search, ChevronUp, ChevronDown, ListFilter, Check, CalendarDays, MoreVertical } from 'lucide-react';
14
14
 
15
15
  // src/components/form/CreateEditForm.tsx
@@ -1196,8 +1196,7 @@ var defaultDataTableConfig = {
1196
1196
  pageSizeOptions: [5, 10, 15, 20, 50],
1197
1197
  defaultPageSize: 10,
1198
1198
  searchPlaceholder: "Buscar...",
1199
- enableGlobalFilter: true,
1200
- pageSizeLabel: (size) => `${size} / p\xE1g`
1199
+ enableGlobalFilter: true
1201
1200
  };
1202
1201
 
1203
1202
  // src/hooks/useDataTable.ts
@@ -1206,15 +1205,11 @@ function useDataTable({
1206
1205
  columns,
1207
1206
  config: configOverride,
1208
1207
  enableRowSelection = false,
1209
- serverSide = false,
1210
1208
  totalRowCount,
1211
1209
  onStateChange
1212
1210
  }) {
1213
1211
  const mergedConfig = useMemo(
1214
- () => ({
1215
- ...defaultDataTableConfig,
1216
- ...configOverride
1217
- }),
1212
+ () => ({ ...defaultDataTableConfig, ...configOverride }),
1218
1213
  [configOverride]
1219
1214
  );
1220
1215
  const [pagination, setPagination] = useState({
@@ -1229,14 +1224,15 @@ function useDataTable({
1229
1224
  () => (columnId, value) => {
1230
1225
  setColumnFilters((prev) => {
1231
1226
  const rest = prev.filter((f) => f.id !== columnId);
1232
- if (value === void 0 || value === null || value === "") {
1233
- return rest;
1234
- }
1227
+ if (value === void 0 || value === null || value === "") return rest;
1235
1228
  return [...rest, { id: columnId, value }];
1236
1229
  });
1237
1230
  },
1238
1231
  []
1239
1232
  );
1233
+ useEffect(() => {
1234
+ setPagination((prev) => ({ ...prev, pageIndex: 0 }));
1235
+ }, [globalFilter, columnFilters]);
1240
1236
  const serverState = useMemo(
1241
1237
  () => ({
1242
1238
  pageIndex: pagination.pageIndex,
@@ -1245,19 +1241,11 @@ function useDataTable({
1245
1241
  columnFilters,
1246
1242
  sorting
1247
1243
  }),
1248
- [
1249
- pagination.pageIndex,
1250
- pagination.pageSize,
1251
- globalFilter,
1252
- columnFilters,
1253
- sorting
1254
- ]
1244
+ [pagination.pageIndex, pagination.pageSize, globalFilter, columnFilters, sorting]
1255
1245
  );
1256
1246
  useEffect(() => {
1257
- if (serverSide && onStateChange) {
1258
- onStateChange(serverState);
1259
- }
1260
- }, [serverSide, onStateChange, serverState]);
1247
+ onStateChange?.(serverState);
1248
+ }, [onStateChange, serverState]);
1261
1249
  const table = useReactTable({
1262
1250
  data,
1263
1251
  columns,
@@ -1265,7 +1253,7 @@ function useDataTable({
1265
1253
  pagination,
1266
1254
  sorting,
1267
1255
  rowSelection: enableRowSelection ? rowSelection : void 0,
1268
- globalFilter: mergedConfig.enableGlobalFilter ? globalFilter : void 0,
1256
+ globalFilter,
1269
1257
  columnFilters
1270
1258
  },
1271
1259
  onPaginationChange: setPagination,
@@ -1274,14 +1262,12 @@ function useDataTable({
1274
1262
  onGlobalFilterChange: setGlobalFilter,
1275
1263
  onColumnFiltersChange: setColumnFilters,
1276
1264
  getCoreRowModel: getCoreRowModel(),
1277
- getFilteredRowModel: getFilteredRowModel(),
1278
- getSortedRowModel: getSortedRowModel(),
1279
1265
  getPaginationRowModel: getPaginationRowModel(),
1280
1266
  enableRowSelection,
1281
- manualPagination: serverSide,
1282
- manualFiltering: serverSide,
1283
- manualSorting: serverSide,
1284
- pageCount: serverSide && totalRowCount != null ? Math.max(1, Math.ceil(totalRowCount / pagination.pageSize)) : void 0
1267
+ manualPagination: true,
1268
+ manualFiltering: true,
1269
+ manualSorting: true,
1270
+ pageCount: totalRowCount != null ? Math.max(1, Math.ceil(totalRowCount / pagination.pageSize)) : void 0
1285
1271
  });
1286
1272
  const selectedRows = useMemo(
1287
1273
  () => enableRowSelection ? table.getSelectedRowModel().rows.map((row) => row.original) : [],
@@ -1795,7 +1781,6 @@ var DataTable = ({
1795
1781
  columns,
1796
1782
  config,
1797
1783
  filters,
1798
- serverSide = false,
1799
1784
  totalRowCount,
1800
1785
  onStateChange,
1801
1786
  loading = false,
@@ -1818,7 +1803,6 @@ var DataTable = ({
1818
1803
  columns,
1819
1804
  config,
1820
1805
  enableRowSelection: canCheck,
1821
- serverSide,
1822
1806
  totalRowCount,
1823
1807
  onStateChange
1824
1808
  });
@@ -1875,13 +1859,7 @@ var DataTable = ({
1875
1859
  ),
1876
1860
  /* @__PURE__ */ jsx(Table.Tbody, { children: Array.from({ length: mergedConfig.defaultPageSize }).map(
1877
1861
  (_, rowIdx) => /* @__PURE__ */ jsxs(Table.Tr, { children: [
1878
- canCheck && /* @__PURE__ */ jsx(
1879
- Table.Td,
1880
- {
1881
- style: { minHeight: 40, verticalAlign: "middle" },
1882
- children: /* @__PURE__ */ jsx(Skeleton, { height: 16, width: 18, radius: "sm" })
1883
- }
1884
- ),
1862
+ canCheck && /* @__PURE__ */ jsx(Table.Td, { style: { minHeight: 40, verticalAlign: "middle" }, children: /* @__PURE__ */ jsx(Skeleton, { height: 16, width: 18, radius: "sm" }) }),
1885
1863
  Array.from({ length: columns.length }).map((_2, colIdx) => /* @__PURE__ */ jsx(
1886
1864
  Table.Td,
1887
1865
  {
@@ -1897,13 +1875,7 @@ var DataTable = ({
1897
1875
  },
1898
1876
  colIdx
1899
1877
  )),
1900
- (columnActions ?? listMenuActions) && /* @__PURE__ */ jsx(
1901
- Table.Td,
1902
- {
1903
- style: { minHeight: 40, verticalAlign: "middle" },
1904
- children: /* @__PURE__ */ jsx(Skeleton, { height: 16, width: 32, radius: "sm" })
1905
- }
1906
- )
1878
+ (columnActions ?? listMenuActions) && /* @__PURE__ */ jsx(Table.Td, { style: { minHeight: 40, verticalAlign: "middle" }, children: /* @__PURE__ */ jsx(Skeleton, { height: 16, width: 32, radius: "sm" }) })
1907
1879
  ] }, rowIdx)
1908
1880
  ) })
1909
1881
  ] }) }) : /* @__PURE__ */ jsxs(Paper, { withBorder: true, radius: "md", style: { overflow: "hidden" }, children: [
@@ -1920,7 +1892,7 @@ var DataTable = ({
1920
1892
  /* @__PURE__ */ jsx(
1921
1893
  BottomPagination,
1922
1894
  {
1923
- total: serverSide && totalRowCount != null ? totalRowCount : table.getRowCount(),
1895
+ total: totalRowCount ?? 0,
1924
1896
  pageSize: table.getState().pagination.pageSize,
1925
1897
  pageIndex: table.getState().pagination.pageIndex,
1926
1898
  onPageSizeChange: (value) => table.setPageSize(value),