hi-tm 0.10.6 → 0.10.7

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,19 +1,46 @@
1
1
  "use strict";
2
- "use client";
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
+ })();
3
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
37
  };
6
38
  Object.defineProperty(exports, "__esModule", { value: true });
7
- const react_1 = __importDefault(require("react"));
8
- const react_2 = require("react");
39
+ const react_1 = __importStar(require("react"));
9
40
  const image_1 = __importDefault(require("next/image"));
10
41
  const SafeImage_1 = __importDefault(require("../../../elements/SafeImage"));
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
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" })));
17
44
  const formatWithCommas = (value) => {
18
45
  if (value === undefined || value === null)
19
46
  return "";
@@ -22,28 +49,48 @@ const formatWithCommas = (value) => {
22
49
  return value.toString();
23
50
  return numValue.toLocaleString();
24
51
  };
25
- // Helper function to handle modal styles
26
52
  const modalStyleOperationHandler = (classType) => {
27
- if (classType === "delete") {
28
- return "hover:bg-red-500/20 text-red-700";
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
+ });
29
67
  }
30
- else {
31
- return "hover:bg-gray-500/10";
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;
32
78
  }
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));
33
84
  };
34
- const ModernTable = ({ rows = [], onEdit, loadingProps = {
85
+ const ModernTable = ({ rows = [], selectedItems = [], onEdit, onView, onAction, selectable, onSelectionChange, actions, ShowActionModal = true, modalActions, noItemFoundProps, iconsSRC, loadingProps = {
35
86
  isLoading: false,
36
87
  loadingText: "درحال دریافت اطلاعات",
37
88
  loadingIcon: react_1.default.createElement(Loader, null),
38
- }, onView, onAction, selectable, onSelectionChange, actions, ShowActionModal = true, modalActions, noItemFoundProps, selectedItems = [], iconsSRC,
39
- // Child row configuration with defaults
40
- childRowConfig = {
89
+ }, childRowConfig = {
41
90
  expandByDefault: false,
42
91
  indentSize: "1.5rem",
43
92
  childRowClass: "bg-blue-300 bg-opacity-10",
44
- },
45
- // Mobile card view configuration props
46
- mobileCardConfig = {
93
+ }, mobileCardConfig = {
47
94
  enabled: true,
48
95
  showFolderIcon: true,
49
96
  folderIconPath: "",
@@ -63,102 +110,71 @@ mobileCardConfig = {
63
110
  marginBottom: "mb-4",
64
111
  },
65
112
  gridLayoutClassName: "grid-cols-1 sm:grid-cols-2 gap-4",
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
- }
118
- }
119
- else {
120
- // If no defined width, set a responsive width
121
- widths[colIndex] = `${100 / maxColumns}%`;
122
- }
123
- }
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;
124
128
  }, [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)(() => {
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
+ });
138
+ }
139
+ });
140
+ return states;
141
+ }, [rows, selectedRowsSet, descendantIdsMap]);
142
+ // مدیریت کلیک خارج از مودال
143
+ (0, react_1.useEffect)(() => {
135
144
  const handleClickOutside = (event) => {
136
145
  const target = event.target;
137
- if (target.closest(".modal-content")) {
146
+ if (target.closest(".modal-content"))
138
147
  return;
139
- }
140
148
  if (modalRef.current &&
141
149
  !modalRef.current.contains(event.target)) {
142
150
  setActiveModal(null);
143
151
  }
144
152
  };
145
153
  document.addEventListener("mousedown", handleClickOutside);
146
- return () => {
147
- document.removeEventListener("mousedown", handleClickOutside);
148
- };
154
+ return () => document.removeEventListener("mousedown", handleClickOutside);
149
155
  }, []);
150
- (0, react_2.useEffect)(() => {
156
+ // مدیریت اسکرول
157
+ (0, react_1.useEffect)(() => {
151
158
  const handleScroll = () => {
152
- if (activeModal !== null) {
159
+ if (activeModal !== null)
153
160
  setActiveModal(null);
154
- }
155
161
  };
156
162
  window.addEventListener("scroll", handleScroll, { passive: true });
157
- return () => {
158
- window.removeEventListener("scroll", handleScroll);
159
- };
163
+ return () => window.removeEventListener("scroll", handleScroll);
160
164
  }, [activeModal]);
161
- const [mousePosition, setMousePosition] = (0, react_2.useState)({ x: 0, y: 0 });
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]);
162
178
  const handleModalToggle = (id, e) => {
163
179
  e.stopPropagation();
164
180
  e.preventDefault();
@@ -168,9 +184,8 @@ pageIndex = 0, // Default to first page (0-indexed)
168
184
  const handleActionClick = (actionId, rowId, e) => {
169
185
  e.stopPropagation();
170
186
  setActiveModal(null);
171
- if (onAction) {
187
+ if (onAction)
172
188
  onAction(actionId, rowId);
173
- }
174
189
  };
175
190
  const handleRowExpandToggle = (rowId, e) => {
176
191
  e.stopPropagation();
@@ -178,6 +193,20 @@ pageIndex = 0, // Default to first page (0-indexed)
178
193
  ? prev.filter((id) => id !== rowId)
179
194
  : [...prev, rowId]);
180
195
  };
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
+ };
181
210
  const getStatusClass = (statusClass) => {
182
211
  switch (statusClass) {
183
212
  case "success":
@@ -203,231 +232,11 @@ pageIndex = 0, // Default to first page (0-indexed)
203
232
  case "price":
204
233
  return (react_1.default.createElement("p", { className: `${item.contentClass || "text-start"} text-sm w-full truncate ` }, formatWithCommas(item.value)));
205
234
  default:
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" }),
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" }),
214
237
  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))));
215
238
  }
216
239
  };
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: number): boolean => {
304
- // // Find the row in the data
305
- // const findRow = (
306
- // rows: TableRowData[] | undefined,
307
- // id: number
308
- // ): TableRowData | null => {
309
- // if (!rows) return null;
310
- // for (const row of rows) {
311
- // if (row.id === id) return row;
312
- // if (row.hasChildren && row.childRows) {
313
- // const found = findRow(row.childRows, id);
314
- // if (found) 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 (
322
- // !row ||
323
- // !row.hasChildren ||
324
- // !row.childRows ||
325
- // row.childRows.length === 0
326
- // ) {
327
- // return false;
328
- // }
329
- // // Check if the row itself is selected
330
- // const isRowSelected = selectedRows.includes(rowId);
331
- // // Recursively check if any descendant is selected
332
- // const hasSelectedDescendant = (children: TableRowData[]): boolean => {
333
- // for (const child of children) {
334
- // // If any child is selected
335
- // if (selectedRows.includes(child.id)) {
336
- // return true;
337
- // }
338
- // // Check grandchildren if they exist
339
- // if (
340
- // child.hasChildren &&
341
- // child.childRows &&
342
- // child.childRows.length > 0
343
- // ) {
344
- // if (hasSelectedDescendant(child.childRows)) {
345
- // return true;
346
- // }
347
- // }
348
- // }
349
- // return false;
350
- // };
351
- // // Check if all descendants are selected
352
- // const areAllDescendantsSelected = (children: TableRowData[]): boolean => {
353
- // for (const child of children) {
354
- // // If any child is not selected
355
- // if (!selectedRows.includes(child.id)) {
356
- // return false;
357
- // }
358
- // // Check grandchildren if they exist
359
- // if (
360
- // child.hasChildren &&
361
- // child.childRows &&
362
- // child.childRows.length > 0
363
- // ) {
364
- // if (!areAllDescendantsSelected(child.childRows)) {
365
- // return false;
366
- // }
367
- // }
368
- // }
369
- // return true;
370
- // };
371
- // const hasAnySelected = hasSelectedDescendant(row.childRows);
372
- // const hasAllSelected = areAllDescendantsSelected(row.childRows);
373
- // // Indeterminate if some but not all descendants are selected
374
- // // Or if the parent is not selected but some children are
375
- // return (
376
- // (hasAnySelected && !hasAllSelected) || (!isRowSelected && hasAnySelected)
377
- // );
378
- // };
379
- const isIndeterminate = (rowId) => {
380
- // ذخیره نتایج برای هر ردیف تا دوباره محاسبه نشه
381
- const memo = new Map();
382
- const checkIndeterminate = (row) => {
383
- if (!row.childRows?.length)
384
- return false;
385
- if (memo.has(row.id))
386
- return memo.get(row.id);
387
- let total = 0;
388
- let selected = 0;
389
- for (const child of row.childRows) {
390
- total += 1;
391
- if (selectedRows.includes(child.id))
392
- selected += 1;
393
- // بررسی بازگشتی فرزندان
394
- if (child.childRows?.length) {
395
- const childIndeterminate = checkIndeterminate(child);
396
- if (childIndeterminate) {
397
- // اگر هر descendant indeterminate بود، خود row هم indeterminate است
398
- memo.set(row.id, true);
399
- return true;
400
- }
401
- }
402
- }
403
- const isIndet = selected > 0 && selected < total;
404
- memo.set(row.id, isIndet);
405
- return isIndet;
406
- };
407
- const row = rows?.find((r) => r.id === rowId);
408
- if (!row)
409
- return false;
410
- return checkIndeterminate(row);
411
- };
412
- // Function to check if a row is selected
413
- const isSelected = (rowId) => {
414
- return selectedRows.includes(rowId);
415
- };
416
- const handleCheckboxChange = (id) => {
417
- // Call your existing handleSelectionChange function
418
- // This will handle the hierarchical selection logic
419
- if (onSelectionChange) {
420
- onSelectionChange(id);
421
- }
422
- else {
423
- // Fallback to simple selection if no onSelectionChange is provided
424
- const updatedSelection = selectedRows.includes(id)
425
- ? selectedRows.filter((rowId) => rowId !== id)
426
- : [...selectedRows, id];
427
- setSelectedRows(updatedSelection);
428
- }
429
- };
430
- // Extract title and subtitle from row data
431
240
  const extractCardData = (row) => {
432
241
  let title = "";
433
242
  let subtitle = "";
@@ -437,58 +246,46 @@ pageIndex = 0, // Default to first page (0-indexed)
437
246
  let price = "";
438
247
  if (!row.data)
439
248
  return { title, subtitle, icon, status, statusClass, price };
440
- // Find title (usually first text item)
441
249
  const titleItem = row.data.find((item) => item.type === "text" && item.value);
442
250
  if (titleItem) {
443
251
  title = titleItem.value;
444
252
  }
445
253
  else if (row.data.length > 0) {
446
- // Fallback to first item
447
254
  title = String(row.data[0].value || "");
448
255
  }
449
- // Find subtitle (usually size or description)
450
256
  const subtitleItem = row.data.find((item) => item.type === "text" && item.isSubtitle);
451
257
  if (subtitleItem) {
452
258
  subtitle = subtitleItem.value;
453
259
  }
454
260
  else if (row.data.length > 1) {
455
- // Fallback to second item
456
261
  subtitle = String(row.data[1].value || "");
457
262
  }
458
- // Find status
459
263
  const statusItem = row.data.find((item) => item.type === "status");
460
264
  if (statusItem) {
461
265
  status = String(statusItem.value || "");
462
266
  statusClass = statusItem.statusClass || "";
463
267
  }
464
- // Find price (look for item with isPrice flag)
465
268
  const priceItem = row.data.find((item) => item.isPrice);
466
269
  if (priceItem) {
467
270
  price = String(priceItem.value || "");
468
271
  }
469
- // Find icon (usually avatar or image)
470
272
  const iconItem = row.data.find((item) => item.hasImage);
471
273
  if (iconItem && iconItem.value) {
472
274
  icon = String(iconItem.imageUrl || "");
473
275
  }
474
276
  return { title, subtitle, icon, status, statusClass, price };
475
277
  };
476
- // Find avatar items in row data
477
278
  const findAvatarItems = (row) => {
478
279
  if (!row.data)
479
280
  return [];
480
281
  return row.data.filter((item) => item.type === "avatar" && item.isUserAvatar);
481
282
  };
482
- // Get all rows and their children for mobile view - updated for multi-level nesting
483
283
  const getAllMobileRows = () => {
484
284
  const result = [];
485
- // Helper function to add parent rows and child rows that should be visible at any depth
486
285
  const processRows = (rows, level = 0) => {
487
286
  rows?.forEach((row) => {
488
- // Add level information to the row for proper indentation
489
287
  const rowWithLevel = { ...row, level, isChild: level > 0 };
490
288
  result.push(rowWithLevel);
491
- // Add child rows if this row is expanded - recursively check all levels
492
289
  if (row.hasChildren &&
493
290
  expandedRows.includes(row.id) &&
494
291
  row.childRows &&
@@ -497,12 +294,10 @@ pageIndex = 0, // Default to first page (0-indexed)
497
294
  }
498
295
  });
499
296
  };
500
- if (rows) {
297
+ if (rows)
501
298
  processRows(rows);
502
- }
503
299
  return result;
504
300
  };
505
- // Mobile card view
506
301
  const renderMobileCard = (row) => {
507
302
  if (!row || !row.data)
508
303
  return null;
@@ -511,10 +306,7 @@ pageIndex = 0, // Default to first page (0-indexed)
511
306
  const isFavorited = row.data.some((item) => item.isFavorite);
512
307
  const hasChildren = row.hasChildren && row.childRows && row?.childRows?.length > 0;
513
308
  const level = row.level || 0;
514
- const { cardStyle, showFolderIcon, folderIconPath, isMobileCardSelectable, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath,
515
- // showMoreOptions,
516
- moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
517
- // Calculate card classes - add special styling for child cards
309
+ const { cardStyle, showFolderIcon, folderIconPath, isMobileCardSelectable, showFavoriteIcon, favoriteFilledIconPath, favoriteOutlineIconPath, showMoreOptions, moreOptionsIconPath, showAvatars, maxVisibleAvatars = 0, } = mobileCardConfig;
518
310
  const cardClasses = `
519
311
  ${cardStyle?.backgroundColor || "bg-white"}
520
312
  ${cardStyle?.borderRadius || "rounded-lg"}
@@ -536,7 +328,7 @@ pageIndex = 0, // Default to first page (0-indexed)
536
328
  react_1.default.createElement("div", null, isMobileCardSelectable && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
537
329
  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) => {
538
330
  if (el) {
539
- el.indeterminate = isIndeterminate(row.id);
331
+ el.indeterminate = indeterminateStates[row.id];
540
332
  }
541
333
  } })))),
542
334
  react_1.default.createElement("div", { className: "flex-1 min-w-0" },
@@ -546,42 +338,37 @@ pageIndex = 0, // Default to first page (0-indexed)
546
338
  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` })),
547
339
  react_1.default.createElement("h3", { className: "text-sm font-medium truncate" }, title)),
548
340
  react_1.default.createElement("p", { className: "text-xs text-gray-500 mt-1 truncate" }, subtitle),
549
- price && (react_1.default.createElement("p", { className: "text-sm font-semibold mt-1" }, price)),
341
+ price && react_1.default.createElement("p", { className: "text-sm font-semibold mt-1" }, price),
550
342
  status && (react_1.default.createElement("div", { className: "mt-2" },
551
343
  react_1.default.createElement("span", { className: `text-xs font-medium px-2 py-1 rounded-full ${getStatusClass(statusClass)} bg-opacity-10` }, status)))),
552
344
  react_1.default.createElement("div", { className: "flex items-center flex-shrink-0 ml-2" },
553
- hasChildren && (react_1.default.createElement("button", { onClick: (e) => {
554
- e.stopPropagation();
555
- handleRowExpandToggle(row.id, e);
556
- }, className: "p-2 hover:bg-gray-100 rounded" },
345
+ hasChildren && (react_1.default.createElement("button", { onClick: (e) => handleRowExpandToggle(row.id, e), className: "p-2 hover:bg-gray-100 rounded" },
557
346
  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" : ""}` },
558
347
  react_1.default.createElement("path", { d: "M15 5L8 12L15 19", stroke: "rgba(0, 0, 0, 0.40)", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })))),
559
348
  showFavoriteIcon && (react_1.default.createElement("button", { className: "p-2 hover:bg-gray-100 rounded" },
560
349
  react_1.default.createElement(image_1.default, { src: isFavorited
561
350
  ? favoriteFilledIconPath ?? "/defaultFilledIcon.svg"
562
351
  : favoriteOutlineIconPath ?? "/defaultOutlineIcon.svg", alt: "favorite", width: 20, height: 20, className: isFavorited ? "text-yellow-400" : "text-gray-400" }))),
563
- (typeof mobileCardConfig.showMoreOptions === "function"
564
- ? mobileCardConfig.showMoreOptions(row)
565
- : mobileCardConfig.showMoreOptions) &&
352
+ (typeof showMoreOptions === "function"
353
+ ? showMoreOptions(row)
354
+ : showMoreOptions) &&
566
355
  modalActions &&
567
356
  modalActions.length > 0 &&
568
357
  (typeof showModalIcon === "function"
569
358
  ? showModalIcon(row)
570
359
  : showModalIcon) && (react_1.default.createElement("div", { className: "relative" },
571
- react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: `p-2 hover:bg-gray-100 rounded ${ShowActionModal
572
- ? ""
573
- : "opacity-50 cursor-not-allowed "} ` },
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"}` },
574
361
  react_1.default.createElement(image_1.default, { src: moreOptionsIconPath || "/placeholder.svg", alt: "menu", width: 20, height: 20, className: `${ShowActionModal
575
362
  ? ""
576
363
  : "opacity-50 cursor-not-allowed"}` })),
577
364
  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: {
578
365
  position: "fixed",
579
366
  top: `${mousePosition.y}px`,
580
- left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80) + 35)}px `, // Ensure modal stays within screen
367
+ left: `${Math.max(0, Math.min(window.innerWidth - 160, mousePosition.x - 80)) + 35}px`,
581
368
  }, onClick: (e) => e.stopPropagation() },
582
369
  react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
583
370
  ? modalActions(row)
584
- : 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)))))))))),
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)))))))))),
585
372
  showAvatars && avatarItems.length > 0 && (react_1.default.createElement("div", { className: "flex items-center mt-3" },
586
373
  react_1.default.createElement("div", { className: "flex -space-x-2" },
587
374
  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" },
@@ -590,9 +377,7 @@ pageIndex = 0, // Default to first page (0-indexed)
590
377
  "+",
591
378
  avatarItems.length - maxVisibleAvatars)))))))));
592
379
  };
593
- // Render a single table row (parent or child)
594
380
  const renderTableRow = (row, index, isLastRow) => {
595
- // Width for the expand/collapse control column
596
381
  return (react_1.default.createElement("div", { key: `row-container-${row.id}` },
597
382
  react_1.default.createElement("div", { className: `grid w-full items-center ${row.isChild
598
383
  ? childRowConfig.childRowClass || "bg-blue-300 bg-opacity-10"
@@ -604,26 +389,20 @@ pageIndex = 0, // Default to first page (0-indexed)
604
389
  gridTemplateColumns: isMobileView && mobileViewGridClassName
605
390
  ? mobileViewGridClassName
606
391
  : gridClassName || "repeat(auto-fit, minmax(100px, 1fr))",
607
- }, onClick: () => {
608
- if (onView) {
609
- onView(row.id);
610
- }
611
- } },
392
+ }, onClick: () => onView && onView(row.id) },
612
393
  react_1.default.createElement("div", { className: `flex items-center justify-center gap-2 ${!row.hasChildren && "mr-[4px]"}`, style: { width: "55px" } },
613
- !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)),
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)),
614
395
  react_1.default.createElement("div", { className: "flex items-center justify-center gap-1" },
615
396
  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" },
616
397
  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" : ""}` },
617
- 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 ? (
618
- // Child row indicator
619
- react_1.default.createElement("div", { className: "h-2 w-2 rounded-full bg-black/20 flex-shrink-0" })) : null,
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,
620
399
  selectable === true && !row.isChild && (react_1.default.createElement("div", { className: "relative flex-shrink-0 flex" },
621
400
  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) => {
622
401
  if (el) {
623
- el.indeterminate = isIndeterminate(row.id);
402
+ el.indeterminate = indeterminateStates[row.id];
624
403
  }
625
404
  } }),
626
- 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" },
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" },
627
406
  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" }))))))),
628
407
  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" ||
629
408
  item.type === "operation" ||
@@ -639,16 +418,14 @@ pageIndex = 0, // Default to first page (0-indexed)
639
418
  : "flex-start",
640
419
  } },
641
420
  colIndex === 0 && row.isChild && selectable && (react_1.default.createElement("div", { className: "flex items-center" },
642
- react_1.default.createElement("div", { style: {
643
- paddingLeft: `${(row.level || 1) * 7}px`,
644
- }, className: "flex-shrink-0" }),
645
- react_1.default.createElement("div", { className: "relative flex items-center justify-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" },
646
423
  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) => {
647
424
  if (el) {
648
- el.indeterminate = isIndeterminate(row.id);
425
+ el.indeterminate = indeterminateStates[row.id];
649
426
  }
650
427
  } }),
651
- 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" },
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" },
652
429
  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" })))))),
653
430
  renderCellContent(item)))),
654
431
  actions && (react_1.default.createElement("div", { className: `w-24 py-4 flex items-center justify-end text-sm font-medium ${actionButtonsStyle || ""}` },
@@ -664,21 +441,15 @@ pageIndex = 0, // Default to first page (0-indexed)
664
441
  (typeof showModalIcon === "function"
665
442
  ? showModalIcon(row)
666
443
  : showModalIcon) ? (react_1.default.createElement("button", { onClick: (e) => handleModalToggle(row.id, e), className: "", "data-row-id": row.id },
667
- react_1.default.createElement(image_1.default, { src: iconsSRC?.moreIcon || "/placeholder.svg", alt: "menu", width: 18, height: 18, className: iconsSRC?.moreIconTailwindStyle || "" }))) : (
668
- // Render an invisible placeholder to maintain spacing when icon is hidden
669
- react_1.default.createElement("div", { className: "w-[18px] h-[18px]" })),
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]" })),
670
445
  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: {
671
446
  position: "fixed",
672
447
  top: (() => {
673
- // Get all visible rows for the current view
674
448
  const allRows = isMobileView
675
449
  ? getAllMobileRows()
676
450
  : rows;
677
- // Find the index of the current row
678
451
  const currentRowIndex = allRows?.findIndex((r) => r.id === row.id);
679
- // Check if this is one of the last 3 rows
680
452
  const isLastThreeRows = allRows && currentRowIndex >= allRows.length - 3;
681
- // If it's one of the last 3 rows, reduce the top position by 100px
682
453
  return isLastThreeRows
683
454
  ? `${mousePosition.y - 110}px`
684
455
  : `${mousePosition.y}px`;
@@ -687,31 +458,24 @@ pageIndex = 0, // Default to first page (0-indexed)
687
458
  }, onClick: (e) => e.stopPropagation() },
688
459
  react_1.default.createElement("ul", { className: "flex flex-col items-start justify-center gap-1 p-2" }, (typeof modalActions === "function"
689
460
  ? modalActions(row)
690
- : 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))))))))))),
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))))))))))),
691
462
  row.hasChildren &&
692
463
  expandedRows.includes(row.id) &&
693
464
  row.childRows &&
694
465
  row.childRows.map((childRow, childIndex) => renderTableRow(childRow, childIndex, childIndex === row.childRows.length - 1 && isLastRow))));
695
466
  };
696
- // Prepare all mobile rows
697
467
  const mobileRows = getAllMobileRows();
698
- // Show loading state if loading is true
699
468
  if (loadingProps.isLoading) {
700
469
  return (react_1.default.createElement("div", { className: "w-full flex justify-center items-center py-8 gap-3" },
701
470
  loadingProps.loadingIcon,
702
471
  loadingProps.loadingText && loadingProps.loadingText));
703
472
  }
704
- // Show no items found if rows are empty or null and not loading
705
473
  if (!loadingProps.isLoading && rows?.length === 0) {
706
474
  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,
707
475
  react_1.default.createElement(image_1.default, { src: noItemFoundProps?.imagePath || "/icons/no-data.svg", alt: "No items found", width: 120, height: 120 }),
708
- react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
709
- noItemFoundProps?.title,
710
- " "))) : (react_1.default.createElement(react_1.default.Fragment, null,
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,
711
477
  noItemFoundProps?.imagePath,
712
- react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" },
713
- noItemFoundProps?.title,
714
- " ")))));
478
+ react_1.default.createElement("p", { className: "mt-4 text-gray-500 text-sm" }, noItemFoundProps?.title)))));
715
479
  }
716
480
  return (react_1.default.createElement(react_1.default.Fragment, null,
717
481
  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.6",
3
+ "version": "0.10.7",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {