hi-tm 0.12.4 → 0.12.6

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.
@@ -1,43 +1,11 @@
1
1
  "use strict";
2
2
  "use client";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
5
  };
39
6
  Object.defineProperty(exports, "__esModule", { value: true });
40
- const react_1 = __importStar(require("react"));
7
+ const react_1 = __importDefault(require("react"));
8
+ const react_2 = require("react");
41
9
  const image_1 = __importDefault(require("next/image"));
42
10
  const SafeImage_1 = __importDefault(require("../../../elements/SafeImage"));
43
11
  // Simple Loader component defined inline to avoid import issues
@@ -100,89 +68,62 @@ mobileViewGridClassName, itemsPerPage = 10, // Default to 10 items per page
100
68
  pageIndex = 0, // Default to first page (0-indexed)
101
69
  }) => {
102
70
  // Track which rows are expanded to show their children
103
- const [expandedRows, setExpandedRows] = (0, react_1.useState)([]);
104
- const [activeModal, setActiveModal] = (0, react_1.useState)(null);
105
- const modalRef = (0, react_1.useRef)(null);
71
+ const [expandedRows, setExpandedRows] = (0, react_2.useState)([]);
72
+ const [activeModal, setActiveModal] = (0, react_2.useState)(null);
73
+ const modalRef = (0, react_2.useRef)(null);
106
74
  // Store calculated column widths
107
- const [selectedRows, setSelectedRows] = (0, react_1.useState)(selectedItems || []);
108
- const [mousePosition, setMousePosition] = (0, react_1.useState)({ x: 0, y: 0 });
109
- // --- Optimized Maps ---
110
- const { rowsMap, descendantsMap } = (0, react_1.useMemo)(() => {
111
- const rowsMap = new Map();
112
- const descendantsMap = new Map();
113
- const buildMaps = (rows) => {
114
- rows?.forEach((row) => {
115
- rowsMap.set(row.id, row);
116
- const descendantIds = [];
117
- const collectDescendants = (children) => {
118
- children.forEach((child) => {
119
- descendantIds.push(child.id);
120
- if (child.hasChildren && child.childRows) {
121
- collectDescendants(child.childRows);
122
- }
123
- });
124
- };
125
- if (row.hasChildren && row.childRows) {
126
- collectDescendants(row.childRows);
75
+ const [selectedRows, setSelectedRows] = (0, react_2.useState)(selectedItems || []);
76
+ // Calculate and store column widths based on all rows (parents and children)
77
+ (0, react_2.useEffect)(() => {
78
+ // if (!rows || rows.length === 0) return;
79
+ // Get all rows including children
80
+ const allRows = [];
81
+ // Helper function to recursively collect all rows at any depth
82
+ const collectRows = (rowsArray, level = 0) => {
83
+ rowsArray?.forEach((row) => {
84
+ // Add level information to the row for proper indentation
85
+ const rowWithLevel = { ...row, level };
86
+ allRows.push(rowWithLevel);
87
+ // Recursively process children at any depth
88
+ if (row.hasChildren && row.childRows && row.childRows.length > 0) {
89
+ collectRows(row.childRows, level + 1);
127
90
  }
128
- descendantsMap.set(row.id, descendantIds);
129
91
  });
130
92
  };
131
- buildMaps(rows);
132
- return { rowsMap, descendantsMap };
133
- }, [rows]);
134
- // --- Optimized Functions ---
135
- const findRowById = (id) => {
136
- return rowsMap.get(id) || null;
137
- };
138
- const getAllDescendantIds = (id) => {
139
- return descendantsMap.get(id) || [];
140
- };
141
- const isSelected = (rowId) => {
142
- return selectedRows.includes(rowId);
143
- };
144
- const isIndeterminate = (rowId) => {
145
- const row = rowsMap.get(rowId);
146
- if (!row || !row.hasChildren || !descendantsMap.has(rowId)) {
147
- return false;
148
- }
149
- const descendantIds = descendantsMap.get(rowId) || [];
150
- const isRowSelected = selectedRows.includes(rowId);
151
- const hasAnySelected = descendantIds.some((id) => selectedRows.includes(id));
152
- const hasAllSelected = descendantIds.every((id) => selectedRows.includes(id));
153
- return ((hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected));
154
- };
155
- (0, react_1.useEffect)(() => {
156
- console.time("isIndeterminate-all-rows"); // شروع اندازه‌گیری زمان کل
157
- // اجرای تابع برای همه رکوردها
158
- rows?.forEach((row) => {
159
- isIndeterminate(row.id);
160
- });
161
- console.timeEnd("isIndeterminate-all-rows"); // پایان اندازه‌گیری زمان کل
162
- }, [rows, selectedRows]); // وابستگی‌ها: تغییر در داده‌ها یا انتخاب‌ها
163
- const handleCheckboxChange = (id) => {
164
- const row = findRowById(id);
165
- if (!row)
166
- return;
167
- const descendantIds = getAllDescendantIds(id);
168
- const updatedSelection = [...selectedRows];
169
- if (selectedRows.includes(id)) {
170
- const idsToRemove = [id, ...descendantIds];
171
- setSelectedRows(updatedSelection.filter((itemId) => !idsToRemove.includes(itemId)));
172
- }
173
- else {
174
- const idsToAdd = [id, ...descendantIds];
175
- setSelectedRows([
176
- ...updatedSelection,
177
- ...idsToAdd.filter((i) => !updatedSelection.includes(i)),
178
- ]);
93
+ if (rows) {
94
+ collectRows(rows);
179
95
  }
180
- if (onSelectionChange) {
181
- onSelectionChange(id);
96
+ // Find the maximum number of columns
97
+ const maxColumns = Math.max(...allRows.map((row) => (row.data ? row.data.length : 0)));
98
+ // Calculate the width for each column
99
+ const widths = [];
100
+ for (let colIndex = 0; colIndex < maxColumns; colIndex++) {
101
+ // Check if any row has a defined width for this column
102
+ const columnsWithWidth = allRows
103
+ .filter((row) => row.data &&
104
+ row.data[colIndex] &&
105
+ row.data[colIndex].inlineCSS &&
106
+ "width" in (row.data[colIndex].inlineCSS || {}))
107
+ .map((row) => row.data[colIndex]);
108
+ if (columnsWithWidth.length > 0) {
109
+ // Use the first defined width (could be enhanced to use max/average)
110
+ const firstWidth = columnsWithWidth[0].inlineCSS?.width;
111
+ if (firstWidth) {
112
+ widths[colIndex] =
113
+ typeof firstWidth === "string" ? firstWidth : `${firstWidth}px`;
114
+ }
115
+ else {
116
+ widths[colIndex] = "auto";
117
+ }
118
+ }
119
+ else {
120
+ // If no defined width, set a responsive width
121
+ widths[colIndex] = `${100 / maxColumns}%`;
122
+ }
182
123
  }
183
- };
184
- // --- Effects ---
185
- (0, react_1.useEffect)(() => {
124
+ }, [rows]);
125
+ // Initialize expanded rows if specified in config
126
+ (0, react_2.useEffect)(() => {
186
127
  if (childRowConfig.expandByDefault && rows) {
187
128
  const parentIds = rows
188
129
  .filter((row) => row.hasChildren && row.childRows && row.childRows.length > 0)
@@ -190,7 +131,7 @@ pageIndex = 0, // Default to first page (0-indexed)
190
131
  setExpandedRows(parentIds);
191
132
  }
192
133
  }, [rows, childRowConfig.expandByDefault]);
193
- (0, react_1.useEffect)(() => {
134
+ (0, react_2.useEffect)(() => {
194
135
  const handleClickOutside = (event) => {
195
136
  const target = event.target;
196
137
  if (target.closest(".modal-content")) {
@@ -206,7 +147,7 @@ pageIndex = 0, // Default to first page (0-indexed)
206
147
  document.removeEventListener("mousedown", handleClickOutside);
207
148
  };
208
149
  }, []);
209
- (0, react_1.useEffect)(() => {
150
+ (0, react_2.useEffect)(() => {
210
151
  const handleScroll = () => {
211
152
  if (activeModal !== null) {
212
153
  setActiveModal(null);
@@ -217,10 +158,7 @@ pageIndex = 0, // Default to first page (0-indexed)
217
158
  window.removeEventListener("scroll", handleScroll);
218
159
  };
219
160
  }, [activeModal]);
220
- (0, react_1.useEffect)(() => {
221
- setSelectedRows(selectedItems || []);
222
- }, [selectedItems]);
223
- // --- Handlers ---
161
+ const [mousePosition, setMousePosition] = (0, react_2.useState)({ x: 0, y: 0 });
224
162
  const handleModalToggle = (id, e) => {
225
163
  e.stopPropagation();
226
164
  e.preventDefault();
@@ -276,6 +214,229 @@ pageIndex = 0, // Default to first page (0-indexed)
276
214
  react_1.default.createElement("p", { className: `${item.contentClass || "text-start"} text-sm w-full truncate ` }, item.value))) : (react_1.default.createElement("p", { className: `${item.contentClass || "text-start"} text-sm mr-[5px] w-full truncate`, title: item.value?.toString() || "" }, item.value))));
277
215
  }
278
216
  };
217
+ // Update selectedRows when selectedItems prop changes
218
+ (0, react_2.useEffect)(() => {
219
+ setSelectedRows(selectedItems || []);
220
+ }, [selectedItems]);
221
+ // Handle checkbox change for row selection
222
+ // const handleCheckboxChange = (id: number) => {
223
+ // console.log(`Processing ID: ${id}`);
224
+ // // Create a new copy of the current selection
225
+ // let updatedSelection = [...selectedRows];
226
+ // // Check if the row is currently selected
227
+ // const isSelected = updatedSelection.includes(id);
228
+ // console.log(`ID ${id} is currently selected: ${isSelected}`);
229
+ // // Find the item in the rows data
230
+ // const findItemById = (items: TableRowData[] | undefined, itemId: number): TableRowData | null => {
231
+ // if (!items) return null;
232
+ // for (const item of items) {
233
+ // if (item.id === itemId) {
234
+ // return item;
235
+ // }
236
+ // if (item.hasChildren && item.childRows && item.childRows.length > 0) {
237
+ // const foundInChildren = findItemById(item.childRows, itemId);
238
+ // if (foundInChildren) return foundInChildren;
239
+ // }
240
+ // }
241
+ // return null;
242
+ // };
243
+ // const item = findItemById(rows!, id);
244
+ // console.log(`Found item for ID ${id}:`, item);
245
+ // if (isSelected) {
246
+ // // DESELECTION LOGIC
247
+ // console.log(`Deselecting ID ${id}`);
248
+ // // Remove the item itself
249
+ // updatedSelection = updatedSelection.filter(itemId => itemId !== id);
250
+ // // If item exists and has children, remove all children too
251
+ // if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
252
+ // // Function to collect all descendant IDs
253
+ // const getAllDescendantIds = (items: TableRowData[]): number[] => {
254
+ // let allIds: number[] = [];
255
+ // for (const childItem of items) {
256
+ // allIds.push(childItem.id);
257
+ // if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
258
+ // allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
259
+ // }
260
+ // }
261
+ // return allIds;
262
+ // };
263
+ // const descendantIds = getAllDescendantIds(item.childRows);
264
+ // console.log(`Descendant IDs to remove:`, descendantIds);
265
+ // // Remove all descendant IDs from the selection
266
+ // updatedSelection = updatedSelection.filter(itemId => !descendantIds.includes(itemId));
267
+ // }
268
+ // } else {
269
+ // // SELECTION LOGIC
270
+ // console.log(`Selecting ID ${id}`);
271
+ // // Add the item itself
272
+ // updatedSelection.push(id);
273
+ // // If item exists and has children, add all children too
274
+ // if (item && item.hasChildren && item.childRows && item.childRows.length > 0) {
275
+ // // Function to collect all descendant IDs
276
+ // const getAllDescendantIds = (items: TableRowData[]): number[] => {
277
+ // let allIds: number[] = [];
278
+ // for (const childItem of items) {
279
+ // allIds.push(childItem.id);
280
+ // if (childItem.hasChildren && childItem.childRows && childItem.childRows.length > 0) {
281
+ // allIds = [...allIds, ...getAllDescendantIds(childItem.childRows)];
282
+ // }
283
+ // }
284
+ // return allIds;
285
+ // };
286
+ // const descendantIds = getAllDescendantIds(item.childRows);
287
+ // console.log(`Descendant IDs to add:`, descendantIds);
288
+ // // Add all descendant IDs to the selection if not already included
289
+ // for (const descendantId of descendantIds) {
290
+ // if (!updatedSelection.includes(descendantId)) {
291
+ // updatedSelection.push(descendantId);
292
+ // }
293
+ // }
294
+ // }
295
+ // }
296
+ // console.log("New selection:", updatedSelection);
297
+ // setSelectedRows(updatedSelection);
298
+ // if (onSelectionChange) {
299
+ // onSelectionChange([...updatedSelection]);
300
+ // }
301
+ // };
302
+ // Function to determine if a row has any descendants selected (not just direct children)
303
+ const isIndeterminate = (rowId) => {
304
+ // Find the row in the data
305
+ const findRow = (rows, id) => {
306
+ if (!rows)
307
+ return null;
308
+ for (const row of rows) {
309
+ if (row.id === id)
310
+ return row;
311
+ if (row.hasChildren && row.childRows) {
312
+ const found = findRow(row.childRows, id);
313
+ if (found)
314
+ return found;
315
+ }
316
+ }
317
+ return null;
318
+ };
319
+ const row = findRow(rows, rowId);
320
+ // If row has no children, it can't be indeterminate
321
+ if (!row ||
322
+ !row.hasChildren ||
323
+ !row.childRows ||
324
+ row.childRows.length === 0) {
325
+ return false;
326
+ }
327
+ // Check if the row itself is selected
328
+ const isRowSelected = selectedRows.includes(rowId);
329
+ // Recursively check if any descendant is selected
330
+ const hasSelectedDescendant = (children) => {
331
+ for (const child of children) {
332
+ // If any child is selected
333
+ if (selectedRows.includes(child.id)) {
334
+ return true;
335
+ }
336
+ // Check grandchildren if they exist
337
+ if (child.hasChildren &&
338
+ child.childRows &&
339
+ child.childRows.length > 0) {
340
+ if (hasSelectedDescendant(child.childRows)) {
341
+ return true;
342
+ }
343
+ }
344
+ }
345
+ return false;
346
+ };
347
+ // Check if all descendants are selected
348
+ const areAllDescendantsSelected = (children) => {
349
+ for (const child of children) {
350
+ // If any child is not selected
351
+ if (!selectedRows.includes(child.id)) {
352
+ return false;
353
+ }
354
+ // Check grandchildren if they exist
355
+ if (child.hasChildren &&
356
+ child.childRows &&
357
+ child.childRows.length > 0) {
358
+ if (!areAllDescendantsSelected(child.childRows)) {
359
+ return false;
360
+ }
361
+ }
362
+ }
363
+ return true;
364
+ };
365
+ const hasAnySelected = hasSelectedDescendant(row.childRows);
366
+ const hasAllSelected = areAllDescendantsSelected(row.childRows);
367
+ // Indeterminate if some but not all descendants are selected
368
+ // Or if the parent is not selected but some children are
369
+ return ((hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected));
370
+ };
371
+ // Function to check if a row is selected
372
+ const isSelected = (rowId) => {
373
+ return selectedRows.includes(rowId);
374
+ };
375
+ // const handleCheckboxChange = (id: number) => {
376
+ // // Call your existing handleSelectionChange function
377
+ // // This will handle the hierarchical selection logic
378
+ // if (onSelectionChange) {
379
+ // onSelectionChange(id);
380
+ // } else {
381
+ // // Fallback to simple selection if no onSelectionChange is provided
382
+ // const updatedSelection = selectedRows.includes(id)
383
+ // ? selectedRows.filter((rowId) => rowId !== id)
384
+ // : [...selectedRows, id];
385
+ // setSelectedRows(updatedSelection);
386
+ // }
387
+ // };
388
+ const [isProcessing, setIsProcessing] = (0, react_2.useState)(false);
389
+ const handleCheckboxChange = async (id) => {
390
+ setIsProcessing(true);
391
+ try {
392
+ const findRowById = (rows, targetId) => {
393
+ for (const row of rows) {
394
+ if (row.id === targetId)
395
+ return row;
396
+ if (row.hasChildren && row.childRows) {
397
+ const found = findRowById(row.childRows, targetId);
398
+ if (found)
399
+ return found;
400
+ }
401
+ }
402
+ return null;
403
+ };
404
+ const getAllDescendantIds = (row) => {
405
+ let ids = [];
406
+ if (row.hasChildren && row.childRows) {
407
+ for (const child of row.childRows) {
408
+ ids.push(child.id);
409
+ ids = [...ids, ...getAllDescendantIds(child)];
410
+ }
411
+ }
412
+ return ids;
413
+ };
414
+ const updatedSelection = [...selectedRows];
415
+ const row = findRowById(rows, id);
416
+ if (!row)
417
+ return;
418
+ const descendantIds = getAllDescendantIds(row);
419
+ await new Promise((resolve) => setTimeout(resolve, 300));
420
+ if (selectedRows.includes(id)) {
421
+ const idsToRemove = [id, ...descendantIds];
422
+ setSelectedRows(updatedSelection.filter((itemId) => !idsToRemove.includes(itemId)));
423
+ }
424
+ else {
425
+ const idsToAdd = [id, ...descendantIds];
426
+ setSelectedRows([
427
+ ...updatedSelection,
428
+ ...idsToAdd.filter((i) => !updatedSelection.includes(i)),
429
+ ]);
430
+ }
431
+ if (onSelectionChange) {
432
+ onSelectionChange(id);
433
+ }
434
+ }
435
+ finally {
436
+ setIsProcessing(false);
437
+ }
438
+ };
439
+ // Extract title and subtitle from row data
279
440
  const extractCardData = (row) => {
280
441
  let title = "";
281
442
  let subtitle = "";
@@ -285,46 +446,58 @@ pageIndex = 0, // Default to first page (0-indexed)
285
446
  let price = "";
286
447
  if (!row.data)
287
448
  return { title, subtitle, icon, status, statusClass, price };
449
+ // Find title (usually first text item)
288
450
  const titleItem = row.data.find((item) => item.type === "text" && item.value);
289
451
  if (titleItem) {
290
452
  title = titleItem.value;
291
453
  }
292
454
  else if (row.data.length > 0) {
455
+ // Fallback to first item
293
456
  title = String(row.data[0].value || "");
294
457
  }
458
+ // Find subtitle (usually size or description)
295
459
  const subtitleItem = row.data.find((item) => item.type === "text" && item.isSubtitle);
296
460
  if (subtitleItem) {
297
461
  subtitle = subtitleItem.value;
298
462
  }
299
463
  else if (row.data.length > 1) {
464
+ // Fallback to second item
300
465
  subtitle = String(row.data[1].value || "");
301
466
  }
467
+ // Find status
302
468
  const statusItem = row.data.find((item) => item.type === "status");
303
469
  if (statusItem) {
304
470
  status = String(statusItem.value || "");
305
471
  statusClass = statusItem.statusClass || "";
306
472
  }
473
+ // Find price (look for item with isPrice flag)
307
474
  const priceItem = row.data.find((item) => item.isPrice);
308
475
  if (priceItem) {
309
476
  price = String(priceItem.value || "");
310
477
  }
478
+ // Find icon (usually avatar or image)
311
479
  const iconItem = row.data.find((item) => item.hasImage);
312
480
  if (iconItem && iconItem.value) {
313
481
  icon = String(iconItem.imageUrl || "");
314
482
  }
315
483
  return { title, subtitle, icon, status, statusClass, price };
316
484
  };
485
+ // Find avatar items in row data
317
486
  const findAvatarItems = (row) => {
318
487
  if (!row.data)
319
488
  return [];
320
489
  return row.data.filter((item) => item.type === "avatar" && item.isUserAvatar);
321
490
  };
491
+ // Get all rows and their children for mobile view - updated for multi-level nesting
322
492
  const getAllMobileRows = () => {
323
493
  const result = [];
494
+ // Helper function to add parent rows and child rows that should be visible at any depth
324
495
  const processRows = (rows, level = 0) => {
325
496
  rows?.forEach((row) => {
497
+ // Add level information to the row for proper indentation
326
498
  const rowWithLevel = { ...row, level, isChild: level > 0 };
327
499
  result.push(rowWithLevel);
500
+ // Add child rows if this row is expanded - recursively check all levels
328
501
  if (row.hasChildren &&
329
502
  expandedRows.includes(row.id) &&
330
503
  row.childRows &&
@@ -338,6 +511,7 @@ pageIndex = 0, // Default to first page (0-indexed)
338
511
  }
339
512
  return result;
340
513
  };
514
+ // Mobile card view
341
515
  const renderMobileCard = (row) => {
342
516
  if (!row || !row.data)
343
517
  return null;
@@ -346,7 +520,10 @@ pageIndex = 0, // Default to first page (0-indexed)
346
520
  const isFavorited = row.data.some((item) => item.isFavorite);
347
521
  const hasChildren = row.hasChildren && row.childRows && row?.childRows?.length > 0;
348
522
  const level = row.level || 0;
349
- const { cardStyle, showFolderIcon, folderIconPath, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath, moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
523
+ const { cardStyle, showFolderIcon, folderIconPath, isMobileCardSelectable, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath,
524
+ // showMoreOptions,
525
+ moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
526
+ // Calculate card classes - add special styling for child cards
350
527
  const cardClasses = `
351
528
  ${cardStyle?.backgroundColor || "bg-white"}
352
529
  ${cardStyle?.borderRadius || "rounded-lg"}
@@ -365,7 +542,7 @@ pageIndex = 0, // Default to first page (0-indexed)
365
542
  react_1.default.createElement("div", { className: "w-10 h-10 flex items-center justify-center" }, row.data &&
366
543
  row.data.find((item) => item.hasImage)?.imageUrl ? (react_1.default.createElement(image_1.default, { src: row.data.find((item) => item.hasImage)?.imageUrl ||
367
544
  "/placeholder.svg", alt: "folder", width: 40, height: 40, className: "h-full w-full object-cover" })) : (react_1.default.createElement(image_1.default, { src: folderIconPath || "/placeholder.svg", alt: "folder", width: 40, height: 40, className: "text-yellow-400" }))))),
368
- react_1.default.createElement("div", null, selectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
545
+ react_1.default.createElement("div", null, isMobileCardSelectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
369
546
  react_1.default.createElement("input", { type: "checkbox", checked: isSelected(row.id), onChange: () => handleCheckboxChange(row.id), className: "peer h-5 w-5 mr-2 cursor-pointer appearance-none rounded-md border-2 border-gray-300 transition-all checked:border-blue-500 checked:bg-blue-500 hover:border-blue-500", onClick: (e) => e.stopPropagation(), ref: (el) => {
370
547
  if (el) {
371
548
  el.indeterminate = isIndeterminate(row.id);
@@ -409,7 +586,7 @@ pageIndex = 0, // Default to first page (0-indexed)
409
586
  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: {
410
587
  position: "fixed",
411
588
  top: `${mousePosition.y}px`,
412
- left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `,
589
+ left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `, // Ensure modal stays within screen
413
590
  }, onClick: (e) => e.stopPropagation() },
414
591
  react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
415
592
  ? modalActions(row)
@@ -422,7 +599,9 @@ pageIndex = 0, // Default to first page (0-indexed)
422
599
  "+",
423
600
  avatarItems.length - maxVisibleAvatars)))))))));
424
601
  };
602
+ // Render a single table row (parent or child)
425
603
  const renderTableRow = (row, index, isLastRow) => {
604
+ // Width for the expand/collapse control column
426
605
  return (react_1.default.createElement("div", { key: `row-container-${row.id}` },
427
606
  react_1.default.createElement("div", { className: `grid w-full items-center ${row.isChild
428
607
  ? childRowConfig.childRowClass || "bg-blue-300 bg-opacity-10"
@@ -444,7 +623,9 @@ pageIndex = 0, // Default to first page (0-indexed)
444
623
  react_1.default.createElement("div", { className: "flex items-center justify-center gap-1" },
445
624
  row.hasChildren && row.childRows && row.childRows?.length > 0 ? (react_1.default.createElement("button", { onClick: (e) => handleRowExpandToggle(row.id, e), className: "transition-transform duration-200 flex-shrink-0" },
446
625
  react_1.default.createElement("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: `transition-transform ${expandedRows.includes(row.id) ? "-rotate-90" : ""}` },
447
- react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))) : row.isChild ? (react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
626
+ react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))) : row.isChild ? (
627
+ // Child row indicator
628
+ react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
448
629
  selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
449
630
  react_1.default.createElement("input", { type: "checkbox", checked: isSelected(row.id), onChange: () => handleCheckboxChange(row.id), className: "peer h-5 w-5 cursor-pointer appearance-none rounded-md border-2 border-gray-300 transition-all checked:border-blue-500 checked:bg-blue-500 hover:border-blue-500", onClick: (e) => e.stopPropagation(), ref: (el) => {
450
631
  if (el) {
@@ -492,15 +673,21 @@ pageIndex = 0, // Default to first page (0-indexed)
492
673
  (typeof showModalIcon === "function"
493
674
  ? showModalIcon(row)
494
675
  : showModalIcon) ? (react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: "", "data-row-id": row.id },
495
- react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
676
+ react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
677
+ // Render an invisible placeholder to maintain spacing when icon is hidden
678
+ react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
496
679
  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: {
497
680
  position: "fixed",
498
681
  top: (() => {
682
+ // Get all visible rows for the current view
499
683
  const allRows = isMobileView
500
684
  ? getAllMobileRows()
501
685
  : rows;
686
+ // Find the index of the current row
502
687
  const currentRowIndex = allRows?.findIndex((r) => r.id === row.id);
688
+ // Check if this is one of the last 3 rows
503
689
  const isLastThreeRows = allRows && currentRowIndex >= allRows.length - 3;
690
+ // If it's one of the last 3 rows, reduce the top position by 100px
504
691
  return isLastThreeRows
505
692
  ? `${mousePosition.y - 110}px`
506
693
  : `${mousePosition.y}px`;
@@ -515,12 +702,15 @@ pageIndex = 0, // Default to first page (0-indexed)
515
702
  row.childRows &&
516
703
  row.childRows.map((childRow, childIndex) => renderTableRow(childRow, childIndex, childIndex === row.childRows.length - 1 && isLastRow))));
517
704
  };
705
+ // Prepare all mobile rows
518
706
  const mobileRows = getAllMobileRows();
707
+ // Show loading state if loading is true
519
708
  if (loadingProps.isLoading) {
520
709
  return (react_1.default.createElement("div", { className: "w-full flex justify-center items-center py-8 gap-3" },
521
710
  loadingProps.loadingIcon,
522
711
  loadingProps.loadingText && loadingProps.loadingText));
523
712
  }
713
+ // Show no items found if rows are empty or null and not loading
524
714
  if (!loadingProps.isLoading && rows?.length === 0) {
525
715
  return (react_1.default.createElement("div", { className: "flex flex-col items-center justify-center p-8" }, typeof noItemFoundProps?.imagePath === "string" ? (react_1.default.createElement(react_1.default.Fragment, null,
526
716
  react_1.default.createElement(image_1.default, { src: noItemFoundProps?.imagePath || "/icons/no-data.svg", alt: "No items found", width: 120, height: 120 }),
@@ -533,6 +723,8 @@ pageIndex = 0, // Default to first page (0-indexed)
533
723
  " ")))));
534
724
  }
535
725
  return (react_1.default.createElement(react_1.default.Fragment, null,
726
+ isProcessing && (react_1.default.createElement("div", { className: "fixed inset-0 flex items-center justify-center bg-black bg-opacity-10 z-50" },
727
+ react_1.default.createElement(Loader, null))),
536
728
  mobileCardConfig.enabled && (react_1.default.createElement("div", { className: `lg:hidden grid ${mobileCardConfig.gridLayoutClassName}` }, mobileRows.map((row) => (react_1.default.createElement("div", { key: `mobile-grid-item-${row.id}`, className: `col-span-1 ${row.isChild ? "pl-2" : ""}` }, renderMobileCard(row)))))),
537
729
  react_1.default.createElement("div", { className: `${mobileCardConfig.enabled ? "hidden lg:block" : ""} w-full` }, rows?.map((row, index) => renderTableRow(row, index, index === rows.length - 1)))));
538
730
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.12.4",
3
+ "version": "0.12.6",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {