hi-tm 0.10.8 → 0.10.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.
@@ -1,46 +1,19 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
2
+ "use client";
35
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
5
  };
38
6
  Object.defineProperty(exports, "__esModule", { value: true });
39
- const react_1 = __importStar(require("react"));
7
+ const react_1 = __importDefault(require("react"));
8
+ const react_2 = require("react");
40
9
  const image_1 = __importDefault(require("next/image"));
41
10
  const SafeImage_1 = __importDefault(require("../../../elements/SafeImage"));
42
- const Loader = () => (react_1.default.createElement("div", { className: "flex items-center justify-center" },
43
- react_1.default.createElement("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-gray-900" })));
11
+ // Simple Loader component defined inline to avoid import issues
12
+ const Loader = () => {
13
+ return (react_1.default.createElement("div", { className: "flex items-center justify-center" },
14
+ react_1.default.createElement("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-gray-900" })));
15
+ };
16
+ // Helper function to format numbers with commas
44
17
  const formatWithCommas = (value) => {
45
18
  if (value === undefined || value === null)
46
19
  return "";
@@ -49,48 +22,28 @@ const formatWithCommas = (value) => {
49
22
  return value.toString();
50
23
  return numValue.toLocaleString();
51
24
  };
25
+ // Helper function to handle modal styles
52
26
  const modalStyleOperationHandler = (classType) => {
53
- return classType === "delete"
54
- ? "hover:bg-red-500/20 text-red-700"
55
- : "hover:bg-gray-500/10";
56
- };
57
- // تابع برای محاسبه تمام IDهای فرزندان یک ردیف
58
- const getDescendantIds = (row) => {
59
- let ids = [];
60
- if (row.hasChildren && row.childRows) {
61
- row.childRows.forEach((child) => {
62
- ids.push(child.id);
63
- if (child.hasChildren && child.childRows) {
64
- ids = [...ids, ...getDescendantIds(child)];
65
- }
66
- });
27
+ if (classType === "delete") {
28
+ return "hover:bg-red-500/20 text-red-700";
67
29
  }
68
- return ids;
69
- };
70
- // تابع بهینه‌شده isIndeterminate
71
- const isIndeterminate = (rowId, rows, selectedRowsSet, descendantIdsMap) => {
72
- const row = rows?.find((r) => r.id === rowId);
73
- if (!row ||
74
- !row.hasChildren ||
75
- !row.childRows ||
76
- row.childRows.length === 0) {
77
- return false;
30
+ else {
31
+ return "hover:bg-gray-500/10";
78
32
  }
79
- const descendantIds = descendantIdsMap[rowId] || [];
80
- const selectedCount = descendantIds.filter((id) => selectedRowsSet.has(id)).length;
81
- const isRowSelected = selectedRowsSet.has(rowId);
82
- return ((selectedCount > 0 && selectedCount < descendantIds.length) ||
83
- (!isRowSelected && selectedCount > 0));
84
33
  };
85
- const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction, selectable, onSelectionChange, actions, ShowActionModal = true, modalActions, noItemFoundProps, iconsSRC, loadingProps = {
34
+ const ModernTable = ({ rows = [], onEdit, loadingProps = {
86
35
  isLoading: false,
87
36
  loadingText: "درحال دریافت اطلاعات",
88
37
  loadingIcon: react_1.default.createElement(Loader, null),
89
- }, childRowConfig = {
38
+ }, onView, onAction, selectable, onSelectionChange, actions, ShowActionModal = true, modalActions, noItemFoundProps, selectedItems = [], iconsSRC,
39
+ // Child row configuration with defaults
40
+ childRowConfig = {
90
41
  expandByDefault: false,
91
42
  indentSize: "1.5rem",
92
43
  childRowClass: "bg-blue-300 bg-opacity-10",
93
- }, mobileCardConfig = {
44
+ },
45
+ // Mobile card view configuration props
46
+ mobileCardConfig = {
94
47
  enabled: true,
95
48
  showFolderIcon: true,
96
49
  folderIconPath: "",
@@ -110,71 +63,102 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
110
63
  marginBottom: "mb-4",
111
64
  },
112
65
  gridLayoutClassName: "grid-cols-1 sm:grid-cols-2 gap-4",
113
- }, showModalIcon = true, actionButtonsStyle, gridClassName, isMobileView = false, mobileViewGridClassName, itemsPerPage = 10, pageIndex = 0, }) => {
114
- const [expandedRows, setExpandedRows] = (0, react_1.useState)([]);
115
- const [activeModal, setActiveModal] = (0, react_1.useState)(null);
116
- const [selectedRows, setSelectedRows] = (0, react_1.useState)(selectedItems);
117
- const modalRef = (0, react_1.useRef)(null);
118
- const [mousePosition, setMousePosition] = (0, react_1.useState)({ x: 0, y: 0 });
119
- // تبدیل selectedRows به Set برای جستجوی سریع‌تر
120
- const selectedRowsSet = (0, react_1.useMemo)(() => new Set(selectedRows), [selectedRows]);
121
- // محاسبه descendantIds برای هر ردیف
122
- const descendantIdsMap = (0, react_1.useMemo)(() => {
123
- const map = {};
124
- rows?.forEach((row) => {
125
- map[row.id] = getDescendantIds(row);
126
- });
127
- return map;
128
- }, [rows]);
129
- // Memoize کردن نتایج isIndeterminate
130
- const indeterminateStates = (0, react_1.useMemo)(() => {
131
- const states = {};
132
- rows?.forEach((row) => {
133
- states[row.id] = isIndeterminate(row.id, rows, selectedRowsSet, descendantIdsMap);
134
- if (row.hasChildren && row.childRows) {
135
- row.childRows.forEach((childRow) => {
136
- states[childRow.id] = isIndeterminate(childRow.id, rows, selectedRowsSet, descendantIdsMap);
137
- });
66
+ }, showModalIcon = true, actionButtonsStyle, gridClassName, isMobileView = false, // Default to false
67
+ mobileViewGridClassName, itemsPerPage = 10, // Default to 10 items per page
68
+ pageIndex = 0, // Default to first page (0-indexed)
69
+ }) => {
70
+ // Track which rows are expanded to show their children
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);
74
+ // Store calculated column widths
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);
90
+ }
91
+ });
92
+ };
93
+ if (rows) {
94
+ collectRows(rows);
95
+ }
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
+ }
138
118
  }
139
- });
140
- return states;
141
- }, [rows, selectedRowsSet, descendantIdsMap]);
142
- // مدیریت کلیک خارج از مودال
143
- (0, react_1.useEffect)(() => {
119
+ else {
120
+ // If no defined width, set a responsive width
121
+ widths[colIndex] = `${100 / maxColumns}%`;
122
+ }
123
+ }
124
+ }, [rows]);
125
+ // Initialize expanded rows if specified in config
126
+ (0, react_2.useEffect)(() => {
127
+ if (childRowConfig.expandByDefault && rows) {
128
+ const parentIds = rows
129
+ .filter((row) => row.hasChildren && row.childRows && row.childRows.length > 0)
130
+ .map((row) => row.id);
131
+ setExpandedRows(parentIds);
132
+ }
133
+ }, [rows, childRowConfig.expandByDefault]);
134
+ (0, react_2.useEffect)(() => {
144
135
  const handleClickOutside = (event) => {
145
136
  const target = event.target;
146
- if (target.closest(".modal-content"))
137
+ if (target.closest(".modal-content")) {
147
138
  return;
139
+ }
148
140
  if (modalRef.current &&
149
141
  !modalRef.current.contains(event.target)) {
150
142
  setActiveModal(null);
151
143
  }
152
144
  };
153
145
  document.addEventListener("mousedown", handleClickOutside);
154
- return () => document.removeEventListener("mousedown", handleClickOutside);
146
+ return () => {
147
+ document.removeEventListener("mousedown", handleClickOutside);
148
+ };
155
149
  }, []);
156
- // مدیریت اسکرول
157
- (0, react_1.useEffect)(() => {
150
+ (0, react_2.useEffect)(() => {
158
151
  const handleScroll = () => {
159
- if (activeModal !== null)
152
+ if (activeModal !== null) {
160
153
  setActiveModal(null);
154
+ }
161
155
  };
162
156
  window.addEventListener("scroll", handleScroll, { passive: true });
163
- return () => window.removeEventListener("scroll", handleScroll);
157
+ return () => {
158
+ window.removeEventListener("scroll", handleScroll);
159
+ };
164
160
  }, [activeModal]);
165
- // به‌روزرسانی selectedRows با تغییر selectedItems
166
- (0, react_1.useEffect)(() => {
167
- setSelectedRows(selectedItems || []);
168
- }, [selectedItems]);
169
- // مدیریت گسترش ردیف‌ها
170
- (0, react_1.useEffect)(() => {
171
- if (childRowConfig.expandByDefault && rows) {
172
- const parentIds = rows
173
- .filter((row) => row.hasChildren && row.childRows && row.childRows.length > 0)
174
- .map((row) => row.id);
175
- setExpandedRows(parentIds);
176
- }
177
- }, [rows, childRowConfig.expandByDefault]);
161
+ const [mousePosition, setMousePosition] = (0, react_2.useState)({ x: 0, y: 0 });
178
162
  const handleModalToggle = (id, e) => {
179
163
  e.stopPropagation();
180
164
  e.preventDefault();
@@ -184,8 +168,9 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
184
168
  const handleActionClick = (actionId, rowId, e) => {
185
169
  e.stopPropagation();
186
170
  setActiveModal(null);
187
- if (onAction)
171
+ if (onAction) {
188
172
  onAction(actionId, rowId);
173
+ }
189
174
  };
190
175
  const handleRowExpandToggle = (rowId, e) => {
191
176
  e.stopPropagation();
@@ -193,20 +178,6 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
193
178
  ? prev.filter((id) => id !== rowId)
194
179
  : [...prev, rowId]);
195
180
  };
196
- const handleCheckboxChange = (id) => {
197
- if (onSelectionChange) {
198
- onSelectionChange(id);
199
- }
200
- else {
201
- const updatedSelection = selectedRows.includes(id)
202
- ? selectedRows.filter((rowId) => rowId !== id)
203
- : [...selectedRows, id];
204
- setSelectedRows(updatedSelection);
205
- }
206
- };
207
- const isSelected = (rowId) => {
208
- return selectedRowsSet.has(rowId);
209
- };
210
181
  const getStatusClass = (statusClass) => {
211
182
  switch (statusClass) {
212
183
  case "success":
@@ -232,11 +203,190 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
232
203
  case "price":
233
204
  return (react_1.default.createElement("p", { className: `${item.contentClass || "text-start"} text-sm w-full truncate ` }, formatWithCommas(item.value)));
234
205
  default:
235
- return (react_1.default.createElement("div", { onClick: () => item.onClick && item.onClick(item.id), className: "flex items-center gap-2 w-full" }, item.hasImage && item.imageUrl !== null ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full" },
236
- react_1.default.createElement(SafeImage_1.default, { src: item.imageUrl || "/defaultImage.jpg", alt: item.value?.toString() || "Table item", width: item.imageWidth || 24, height: item.imageHeight || 24, className: item.imageClass || "h-6 w-6 object-cover" }),
206
+ return (react_1.default.createElement("div", { onClick: () => {
207
+ if (item.onClick) {
208
+ item.onClick(item.id);
209
+ }
210
+ }, className: "flex items-center gap-2 w-full" }, item.hasImage && item.imageUrl !== null ? (react_1.default.createElement("div", { className: "flex items-center gap-2 w-full" },
211
+ react_1.default.createElement(SafeImage_1.default, { src: ((item.imageUrl !== null || item.imageUrl !== "") &&
212
+ item.imageUrl) ||
213
+ "/defaultImage.jpg", alt: item.value?.toString() || "Table item", width: item.imageWidth || 24, height: item.imageHeight || 24, className: item.imageClass || "h-6 w-6 object-cover" }),
237
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))));
238
215
  }
239
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) => {
376
+ // Call your existing handleSelectionChange function
377
+ // This will handle the hierarchical selection logic
378
+ if (onSelectionChange) {
379
+ onSelectionChange(id);
380
+ }
381
+ else {
382
+ // Fallback to simple selection if no onSelectionChange is provided
383
+ const updatedSelection = selectedRows.includes(id)
384
+ ? selectedRows.filter((rowId) => rowId !== id)
385
+ : [...selectedRows, id];
386
+ setSelectedRows(updatedSelection);
387
+ }
388
+ };
389
+ // Extract title and subtitle from row data
240
390
  const extractCardData = (row) => {
241
391
  let title = "";
242
392
  let subtitle = "";
@@ -246,46 +396,58 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
246
396
  let price = "";
247
397
  if (!row.data)
248
398
  return { title, subtitle, icon, status, statusClass, price };
399
+ // Find title (usually first text item)
249
400
  const titleItem = row.data.find((item) => item.type === "text" && item.value);
250
401
  if (titleItem) {
251
402
  title = titleItem.value;
252
403
  }
253
404
  else if (row.data.length > 0) {
405
+ // Fallback to first item
254
406
  title = String(row.data[0].value || "");
255
407
  }
408
+ // Find subtitle (usually size or description)
256
409
  const subtitleItem = row.data.find((item) => item.type === "text" && item.isSubtitle);
257
410
  if (subtitleItem) {
258
411
  subtitle = subtitleItem.value;
259
412
  }
260
413
  else if (row.data.length > 1) {
414
+ // Fallback to second item
261
415
  subtitle = String(row.data[1].value || "");
262
416
  }
417
+ // Find status
263
418
  const statusItem = row.data.find((item) => item.type === "status");
264
419
  if (statusItem) {
265
420
  status = String(statusItem.value || "");
266
421
  statusClass = statusItem.statusClass || "";
267
422
  }
423
+ // Find price (look for item with isPrice flag)
268
424
  const priceItem = row.data.find((item) => item.isPrice);
269
425
  if (priceItem) {
270
426
  price = String(priceItem.value || "");
271
427
  }
428
+ // Find icon (usually avatar or image)
272
429
  const iconItem = row.data.find((item) => item.hasImage);
273
430
  if (iconItem && iconItem.value) {
274
431
  icon = String(iconItem.imageUrl || "");
275
432
  }
276
433
  return { title, subtitle, icon, status, statusClass, price };
277
434
  };
435
+ // Find avatar items in row data
278
436
  const findAvatarItems = (row) => {
279
437
  if (!row.data)
280
438
  return [];
281
439
  return row.data.filter((item) => item.type === "avatar" && item.isUserAvatar);
282
440
  };
441
+ // Get all rows and their children for mobile view - updated for multi-level nesting
283
442
  const getAllMobileRows = () => {
284
443
  const result = [];
444
+ // Helper function to add parent rows and child rows that should be visible at any depth
285
445
  const processRows = (rows, level = 0) => {
286
446
  rows?.forEach((row) => {
447
+ // Add level information to the row for proper indentation
287
448
  const rowWithLevel = { ...row, level, isChild: level > 0 };
288
449
  result.push(rowWithLevel);
450
+ // Add child rows if this row is expanded - recursively check all levels
289
451
  if (row.hasChildren &&
290
452
  expandedRows.includes(row.id) &&
291
453
  row.childRows &&
@@ -294,10 +456,12 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
294
456
  }
295
457
  });
296
458
  };
297
- if (rows)
459
+ if (rows) {
298
460
  processRows(rows);
461
+ }
299
462
  return result;
300
463
  };
464
+ // Mobile card view
301
465
  const renderMobileCard = (row) => {
302
466
  if (!row || !row.data)
303
467
  return null;
@@ -306,7 +470,10 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
306
470
  const isFavorited = row.data.some((item) => item.isFavorite);
307
471
  const hasChildren = row.hasChildren && row.childRows && row?.childRows?.length > 0;
308
472
  const level = row.level || 0;
309
- const { cardStyle, showFolderIcon, folderIconPath, isMobileCardSelectable, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath, showMoreOptions, moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
473
+ const { cardStyle, showFolderIcon, folderIconPath, isMobileCardSelectable, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath,
474
+ // showMoreOptions,
475
+ moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
476
+ // Calculate card classes - add special styling for child cards
310
477
  const cardClasses = `
311
478
  ${cardStyle?.backgroundColor || "bg-white"}
312
479
  ${cardStyle?.borderRadius || "rounded-lg"}
@@ -328,7 +495,7 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
328
495
  react_1.default.createElement("div", null, isMobileCardSelectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
329
496
  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) => {
330
497
  if (el) {
331
- el.indeterminate = indeterminateStates[row.id];
498
+ el.indeterminate = isIndeterminate(row.id);
332
499
  }
333
500
  } })))),
334
501
  react_1.default.createElement("div", { className: "flex-1 min-w-0" },
@@ -338,37 +505,42 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
338
505
  level > 0 && (react_1.default.createElement("div", { className: `h-2 w-2 rounded-full bg-blue-${Math.min(400 + level * 100, 900)} mr-2 flex-shrink-0` })),
339
506
  react_1.default.createElement("h3", { className: "text-sm font-medium truncate" }, title)),
340
507
  react_1.default.createElement("p", { className: "text-xs text-gray-500 mt-1 truncate" }, subtitle),
341
- price && react_1.default.createElement("p", { className: "text-sm font-semibold mt-1" }, price),
508
+ price && (react_1.default.createElement("p", { className: "text-sm font-semibold mt-1" }, price)),
342
509
  status && (react_1.default.createElement("div", { className: "mt-2" },
343
510
  react_1.default.createElement("span", { className: `text-xs font-medium px-2 py-1 rounded-full ${getStatusClass(statusClass)} bg-opacity-10` }, status)))),
344
511
  react_1.default.createElement("div", { className: "flex items-center flex-shrink-0 ml-2" },
345
- hasChildren && (react_1.default.createElement("button", { onClick: (e) => handleRowExpandToggle(row.id, e), className: "p-2 hover:bg-gray-100 rounded" },
512
+ hasChildren && (react_1.default.createElement("button", { onClick: (e) => {
513
+ e.stopPropagation();
514
+ handleRowExpandToggle(row.id, e);
515
+ }, className: "p-2 hover:bg-gray-100 rounded" },
346
516
  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" : ""}` },
347
517
  react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))),
348
518
  showFavoriteIcon && (react_1.default.createElement("button", { className: "p-2 hover:bg-gray-100 rounded" },
349
519
  react_1.default.createElement(image_1.default, { src: isFavorited
350
520
  ? favoriteFilledIconPath ?? "/defaultFilledIcon.svg"
351
521
  : favoriteOutlineIconPath ?? "/defaultOutlineIcon.svg", alt: "favorite", width: 20, height: 20, className: isFavorited ? "text-yellow-400" : "text-gray-400" }))),
352
- (typeof showMoreOptions === "function"
353
- ? showMoreOptions(row)
354
- : showMoreOptions) &&
522
+ (typeof mobileCardConfig.showMoreOptions === "function"
523
+ ? mobileCardConfig.showMoreOptions(row)
524
+ : mobileCardConfig.showMoreOptions) &&
355
525
  modalActions &&
356
526
  modalActions.length > 0 &&
357
527
  (typeof showModalIcon === "function"
358
528
  ? showModalIcon(row)
359
529
  : showModalIcon) && (react_1.default.createElement("div", { className: "relative" },
360
- react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: `p-2 hover:bg-gray-100 rounded ${ShowActionModal ? "" : "opacity-50 cursor-not-allowed"}` },
530
+ react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: `p-2 hover:bg-gray-100 rounded ${ShowActionModal
531
+ ? ""
532
+ : "opacity-50 cursor-not-allowed "} ` },
361
533
  react_1.default.createElement(image_1.default, { src: moreOptionsIconPath || "/placeholder.svg", alt: "menu", width: 20, height: 20, className: `${ShowActionModal
362
534
  ? ""
363
535
  : "opacity-50 cursor-not-allowed"}` })),
364
536
  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: {
365
537
  position: "fixed",
366
538
  top: `${mousePosition.y}px`,
367
- left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80)) + 35}px`,
539
+ left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `, // Ensure modal stays within screen
368
540
  }, onClick: (e) => e.stopPropagation() },
369
541
  react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
370
542
  ? modalActions(row)
371
- : modalActions).map((action) => (react_1.default.createElement("li", { key: action.id, onClick: (e) => handleActionClick(action.id, row.id, e), className: `rounded-md p-2 text-sm font-normal text-opacity-70 w-full customTransition ${modalStyleOperationHandler(action.class)} ${action.tailwindClassName || ""}` }, action.text)))))))))),
543
+ : modalActions).map((action) => (react_1.default.createElement("li", { key: action.id, onClick: (e) => handleActionClick(action.id, row.id, e), className: `rounded-md p-2 text-sm font-normal text-opacity-70 w-full customTransition ${modalStyleOperationHandler(action.class)} ${action.tailwindClassName || ""} ` }, action.text)))))))))),
372
544
  showAvatars && avatarItems.length > 0 && (react_1.default.createElement("div", { className: "flex items-center mt-3" },
373
545
  react_1.default.createElement("div", { className: "flex -space-x-2" },
374
546
  avatarItems.slice(0, maxVisibleAvatars).map((item, idx) => (react_1.default.createElement("div", { key: idx, className: "h-6 w-6 rounded-full border border-white overflow-hidden" },
@@ -377,7 +549,9 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
377
549
  "+",
378
550
  avatarItems.length - maxVisibleAvatars)))))))));
379
551
  };
552
+ // Render a single table row (parent or child)
380
553
  const renderTableRow = (row, index, isLastRow) => {
554
+ // Width for the expand/collapse control column
381
555
  return (react_1.default.createElement("div", { key: `row-container-${row.id}` },
382
556
  react_1.default.createElement("div", { className: `grid w-full items-center ${row.isChild
383
557
  ? childRowConfig.childRowClass || "bg-blue-300 bg-opacity-10"
@@ -389,20 +563,26 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
389
563
  gridTemplateColumns: isMobileView && mobileViewGridClassName
390
564
  ? mobileViewGridClassName
391
565
  : gridClassName || "repeat(auto-fit, minmax(100px, 1fr))",
392
- }, onClick: () => onView && onView(row.id) },
566
+ }, onClick: () => {
567
+ if (onView) {
568
+ onView(row.id);
569
+ }
570
+ } },
393
571
  react_1.default.createElement("div", { className: `flex items-center justify-center gap-2 ${!row.hasChildren && "mr-[4px]"}`, style: { width: "55px" } },
394
- !row.hasChildren && !row.isChild && (react_1.default.createElement("span", { className: "text-xs text-gray-500 font-semibold flex-shrink-0 mr-1" }, ((pageIndex || 1) - 1) * (itemsPerPage || 10) + index + 1)),
572
+ !row.hasChildren && !row.isChild && (react_1.default.createElement("span", { className: "text-xs text-gray-500 font-semibold flex-shrink-0 mr-1 " }, ((pageIndex || 1) - 1) * (itemsPerPage || 10) + index + 1)),
395
573
  react_1.default.createElement("div", { className: "flex items-center justify-center gap-1" },
396
574
  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" },
397
575
  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" : ""}` },
398
- 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,
576
+ 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 ? (
577
+ // Child row indicator
578
+ react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
399
579
  selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
400
580
  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) => {
401
581
  if (el) {
402
- el.indeterminate = indeterminateStates[row.id];
582
+ el.indeterminate = isIndeterminate(row.id);
403
583
  }
404
584
  } }),
405
- indeterminateStates[row.id] ? (react_1.default.createElement("div", { className: "pointer-events-none absolute left-[5px] top-[9px] w-2.5 h-0.5 bg-blue-500" })) : (react_1.default.createElement("svg", { className: "pointer-events-none absolute left-[5px] top-[5px] h-2.5 w-2.5 fill-white opacity-0 transition-opacity peer-checked:opacity-100", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" },
585
+ isIndeterminate(row.id) ? (react_1.default.createElement("div", { className: "pointer-events-none absolute left-[5px] top-[9px] w-2.5 h-0.5 bg-blue-500" })) : (react_1.default.createElement("svg", { className: "pointer-events-none absolute left-[5px] top-[5px] h-2.5 w-2.5 fill-white opacity-0 transition-opacity peer-checked:opacity-100", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" },
406
586
  react_1.default.createElement("path", { d: "M20.285 2l-11.285 11.567-5.286-5.011-3.714 3.716 9 8.728 15-15.285z" }))))))),
407
587
  row?.data?.map((item, colIndex) => (react_1.default.createElement("div", { key: `${item.id}-${colIndex}`, className: `h-full select-none text-xs font-medium min-w-0 flex items-center ${item.type === "avatar" ||
408
588
  item.type === "operation" ||
@@ -418,14 +598,16 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
418
598
  : "flex-start",
419
599
  } },
420
600
  colIndex === 0 && row.isChild && selectable && (react_1.default.createElement("div", { className: "flex items-center" },
421
- react_1.default.createElement("div", { style: { paddingLeft: `${(row.level || 1) * 7}px` }, className: "flex-shrink-0" }),
422
- react_1.default.createElement("div", { className: "relative flex items-center justify-center" },
601
+ react_1.default.createElement("div", { style: {
602
+ paddingLeft: `${(row.level || 1) * 7}px`,
603
+ }, className: "flex-shrink-0" }),
604
+ react_1.default.createElement("div", { className: "relative flex items-center justify-center " },
423
605
  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) => {
424
606
  if (el) {
425
- el.indeterminate = indeterminateStates[row.id];
607
+ el.indeterminate = isIndeterminate(row.id);
426
608
  }
427
609
  } }),
428
- indeterminateStates[row.id] ? (react_1.default.createElement("div", { className: "pointer-events-none absolute left-[5px] top-[9px] w-2.5 h-0.5 bg-blue-500" })) : (react_1.default.createElement("svg", { className: "pointer-events-none absolute left-[5px] top-[5px] h-2.5 w-2.5 fill-white opacity-0 transition-opacity peer-checked:opacity-100", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" },
610
+ isIndeterminate(row.id) ? (react_1.default.createElement("div", { className: "pointer-events-none absolute left-[5px] top-[9px] w-2.5 h-0.5 bg-blue-500" })) : (react_1.default.createElement("svg", { className: "pointer-events-none absolute left-[5px] top-[5px] h-2.5 w-2.5 fill-white opacity-0 transition-opacity peer-checked:opacity-100", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24" },
429
611
  react_1.default.createElement("path", { d: "M20.285 2l-11.285 11.567-5.286-5.011-3.714 3.716 9 8.728 15-15.285z" })))))),
430
612
  renderCellContent(item)))),
431
613
  actions && (react_1.default.createElement("div", { className: `w-24 py-4 flex items-center justify-end text-sm font-medium ${actionButtonsStyle || ""}` },
@@ -441,15 +623,21 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
441
623
  (typeof showModalIcon === "function"
442
624
  ? showModalIcon(row)
443
625
  : showModalIcon) ? (react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: "", "data-row-id": row.id },
444
- 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]" })),
626
+ react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
627
+ // Render an invisible placeholder to maintain spacing when icon is hidden
628
+ react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
445
629
  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: {
446
630
  position: "fixed",
447
631
  top: (() => {
632
+ // Get all visible rows for the current view
448
633
  const allRows = isMobileView
449
634
  ? getAllMobileRows()
450
635
  : rows;
636
+ // Find the index of the current row
451
637
  const currentRowIndex = allRows?.findIndex((r) => r.id === row.id);
638
+ // Check if this is one of the last 3 rows
452
639
  const isLastThreeRows = allRows && currentRowIndex >= allRows.length - 3;
640
+ // If it's one of the last 3 rows, reduce the top position by 100px
453
641
  return isLastThreeRows
454
642
  ? `${mousePosition.y - 110}px`
455
643
  : `${mousePosition.y}px`;
@@ -458,24 +646,31 @@ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction,
458
646
  }, onClick: (e) => e.stopPropagation() },
459
647
  react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
460
648
  ? modalActions(row)
461
- : modalActions).map((action) => (react_1.default.createElement("li", { key: action.id, onClick: (e) => handleActionClick(action.id, row.id, e), className: `rounded-md p-2 text-sm font-normal text-opacity-70 w-full cursor-pointer ${modalStyleOperationHandler(action.class)} ${action.tailwindClassName || ""}` }, action.text))))))))))),
649
+ : modalActions).map((action) => (react_1.default.createElement("li", { key: action.id, onClick: (e) => handleActionClick(action.id, row.id, e), className: `rounded-md p-2 text-sm font-normal text-opacity-70 w-full cursor-pointer ${modalStyleOperationHandler(action.class)} customTransition ${action.tailwindClassName || ""} ` }, action.text))))))))))),
462
650
  row.hasChildren &&
463
651
  expandedRows.includes(row.id) &&
464
652
  row.childRows &&
465
653
  row.childRows.map((childRow, childIndex) => renderTableRow(childRow, childIndex, childIndex === row.childRows.length - 1 && isLastRow))));
466
654
  };
655
+ // Prepare all mobile rows
467
656
  const mobileRows = getAllMobileRows();
657
+ // Show loading state if loading is true
468
658
  if (loadingProps.isLoading) {
469
659
  return (react_1.default.createElement("div", { className: "w-full flex justify-center items-center py-8 gap-3" },
470
660
  loadingProps.loadingIcon,
471
661
  loadingProps.loadingText && loadingProps.loadingText));
472
662
  }
663
+ // Show no items found if rows are empty or null and not loading
473
664
  if (!loadingProps.isLoading && rows?.length === 0) {
474
665
  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,
475
666
  react_1.default.createElement(image_1.default, { src: noItemFoundProps?.imagePath || "/icons/no-data.svg", alt: "No items found", width: 120, height: 120 }),
476
- react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" }, noItemFoundProps?.title))) : (react_1.default.createElement(react_1.default.Fragment, null,
667
+ react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
668
+ noItemFoundProps?.title,
669
+ " "))) : (react_1.default.createElement(react_1.default.Fragment, null,
477
670
  noItemFoundProps?.imagePath,
478
- react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" }, noItemFoundProps?.title)))));
671
+ react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
672
+ noItemFoundProps?.title,
673
+ " ")))));
479
674
  }
480
675
  return (react_1.default.createElement(react_1.default.Fragment, null,
481
676
  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)))))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.10.8",
3
+ "version": "0.10.9",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {