hi-tm 0.18.9 → 0.19.1

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 @@ mobileCardConfig = {
66
66
  }, showModalIcon = true, actionButtonsStyle, gridClassName, isMobileView = false, // Default to false
67
67
  mobileViewGridClassName, itemsPerPage = 10, // Default to 10 items per page
68
68
  pageIndex = 0, // Default to first page (0-indexed)
69
- }) => {
69
+ largeDatasetThreshold = 200, }) => {
70
70
  // Track which rows are expanded to show their children
71
71
  const [expandedRows, setExpandedRows] = (0, react_2.useState)([]);
72
72
  const [activeModal, setActiveModal] = (0, react_2.useState)(null);
@@ -214,87 +214,6 @@ pageIndex = 0, // Default to first page (0-indexed)
214
214
  (0, react_2.useEffect)(() => {
215
215
  setSelectedRows(selectedItems || []);
216
216
  }, [selectedItems]);
217
- // Handle checkbox change for row selection
218
- // const handleCheckboxChange = (id: number) => {
219
- // console.log(`Processing ID: ${id}`);
220
- // // Create a new copy of the current selection
221
- // let updatedSelection = [...selectedRows];
222
- // // Check if the row is currently selected
223
- // const isSelected = updatedSelection.includes(id);
224
- // console.log(`ID ${id} is currently selected: ${isSelected}`);
225
- // // Find the item in the rows data
226
- // const findItemById = (items: TableRowData[] | undefined, itemId: number): TableRowData | null => {
227
- // if (!items) return null;
228
- // for (const item of items) {
229
- // if (item.id === itemId) {
230
- // return item;
231
- // }
232
- // if (item.hasChildren && item.childRows && item.childRows.length > 0) {
233
- // const foundInChildren = findItemById(item.childRows, itemId);
234
- // if (foundInChildren) return foundInChildren;
235
- // }
236
- // }
237
- // return null;
238
- // };
239
- // const item = findItemById(rows!, id);
240
- // console.log(`Found item for ID ${id}:`, item);
241
- // if (isSelected) {
242
- // // DESELECTION LOGIC
243
- // console.log(`Deselecting ID ${id}`);
244
- // // Remove the item itself
245
- // updatedSelection = updatedSelection.filter(itemId => itemId !== id);
246
- // // If item exists and has children, remove all children too
247
- // if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
248
- // // Function to collect all descendant IDs
249
- // const getAllDescendantIds = (items: TableRowData[]): number[] => {
250
- // let allIds: number[] = [];
251
- // for (const childItem of items) {
252
- // allIds.push(childItem.id);
253
- // if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
254
- // allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
255
- // }
256
- // }
257
- // return allIds;
258
- // };
259
- // const descendantIds = getAllDescendantIds(item.childRows);
260
- // console.log(`Descendant IDs to remove:`, descendantIds);
261
- // // Remove all descendant IDs from the selection
262
- // updatedSelection = updatedSelection.filter(itemId => !descendantIds.includes(itemId));
263
- // }
264
- // } else {
265
- // // SELECTION LOGIC
266
- // console.log(`Selecting ID ${id}`);
267
- // // Add the item itself
268
- // updatedSelection.push(id);
269
- // // If item exists and has children, add all children too
270
- // if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
271
- // // Function to collect all descendant IDs
272
- // const getAllDescendantIds = (items: TableRowData[]): number[] => {
273
- // let allIds: number[] = [];
274
- // for (const childItem of items) {
275
- // allIds.push(childItem.id);
276
- // if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
277
- // allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
278
- // }
279
- // }
280
- // return allIds;
281
- // };
282
- // const descendantIds = getAllDescendantIds(item.childRows);
283
- // console.log(`Descendant IDs to add:`, descendantIds);
284
- // // Add all descendant IDs to the selection if not already included
285
- // for (const descendantId of descendantIds) {
286
- // if (!updatedSelection.includes(descendantId)) {
287
- // updatedSelection.push(descendantId);
288
- // }
289
- // }
290
- // }
291
- // }
292
- // console.log("New selection:", updatedSelection);
293
- // setSelectedRows(updatedSelection);
294
- // if (onSelectionChange) {
295
- // onSelectionChange([...updatedSelection]);
296
- // }
297
- // };
298
217
  // Function to determine if a row has any descendants selected (not just direct children)
299
218
  const isIndeterminate = (rowId) => {
300
219
  // Find the row in the data
@@ -363,7 +282,7 @@ pageIndex = 0, // Default to first page (0-indexed)
363
282
  };
364
283
  // const handleCheckboxChange = (id: number) => {
365
284
  // // Call your existing handleSelectionChange function
366
- // // This will handle the hierarchical selection logic
285
+ // // This will handle the hierarchical selection logic
367
286
  // if (onSelectionChange) {
368
287
  // onSelectionChange(id);
369
288
  // } else {
@@ -406,19 +325,24 @@ pageIndex = 0, // Default to first page (0-indexed)
406
325
  return;
407
326
  const descendantIds = getAllDescendantIds(row);
408
327
  await new Promise((resolve) => setTimeout(resolve, 300));
328
+ let nextSelected = [];
409
329
  if (selectedRows.includes(id)) {
410
330
  const idsToRemove = [id, ...descendantIds];
411
- setSelectedRows(updatedSelection.filter((itemId) => !idsToRemove.includes(itemId)));
331
+ nextSelected = updatedSelection.filter((itemId) => !idsToRemove.includes(itemId));
332
+ setSelectedRows(nextSelected);
412
333
  }
413
334
  else {
414
335
  const idsToAdd = [id, ...descendantIds];
415
- setSelectedRows([
336
+ nextSelected = [
416
337
  ...updatedSelection,
417
338
  ...idsToAdd.filter((i) => !updatedSelection.includes(i)),
418
- ]);
339
+ ];
340
+ setSelectedRows(nextSelected);
419
341
  }
420
342
  if (onSelectionChange) {
421
- onSelectionChange(id);
343
+ const totalRows = Array.isArray(rows) ? rows.length : 0;
344
+ const isLargeDataset = totalRows >= largeDatasetThreshold;
345
+ onSelectionChange(id, { totalRows, selectedIds: nextSelected, isLargeDataset });
422
346
  }
423
347
  }
424
348
  finally {
@@ -654,16 +578,13 @@ pageIndex = 0, // Default to first page (0-indexed)
654
578
  ShowActionModal && activeModal === row.id && (react_1.default.createElement("div", { ref: modalRef, className: "modal-content fixed z-[9999] w-40 rounded-md bg-white shadow-lg", style: {
655
579
  position: 'fixed',
656
580
  top: (() => {
657
- // Get all visible rows for the current view
581
+ const offset = actionModalTopClassName || '0px';
658
582
  const allRows = isMobileView ? getAllMobileRows() : rows;
659
- // Find the index of the current row
660
583
  const currentRowIndex = allRows?.findIndex((r) => r.id === row.id);
661
- // Check if this is one of the last 3 rows
662
584
  const isLastThreeRows = allRows && currentRowIndex >= allRows.length - 3;
663
- // If it's one of the last 3 rows, reduce the top position by 100px
664
585
  return isLastThreeRows
665
- ? `${mousePosition.y - 110}px`
666
- : `${mousePosition.y}px`;
586
+ ? `calc(${mousePosition.y - 110}px + ${offset})`
587
+ : `calc(${mousePosition.y}px + ${offset})`;
667
588
  })(),
668
589
  left: `${mousePosition.x + 20}px`,
669
590
  }, onClick: (e) => e.stopPropagation() },
@@ -71,7 +71,11 @@ export interface ModernTableProps {
71
71
  onView?: (id: number) => void;
72
72
  onAction?: (actionId: number, rowId: number) => void;
73
73
  selectable: boolean;
74
- onSelectionChange?: (id: number | number[]) => void;
74
+ onSelectionChange?: (id: number | number[], context?: {
75
+ totalRows: number;
76
+ selectedIds: number[];
77
+ isLargeDataset: boolean;
78
+ }) => void;
75
79
  checkBoxDisable?: boolean;
76
80
  actions?: boolean;
77
81
  actionModalTopClassName?: string;
@@ -107,4 +111,9 @@ export interface ModernTableProps {
107
111
  * @default 0
108
112
  */
109
113
  pageIndex?: number;
114
+ /**
115
+ * Threshold above which datasets are considered large for selection logic context
116
+ * @default 200
117
+ */
118
+ largeDatasetThreshold?: number;
110
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.18.9",
3
+ "version": "0.19.1",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {