trotl-table 1.0.42 → 1.0.44
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.
- package/dist/Table.cjs.js +62 -6
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +62 -6
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/Table.cjs.js
CHANGED
|
@@ -10077,9 +10077,17 @@ function TableInner({
|
|
|
10077
10077
|
// perform deletion for a given row (shared by immediate & modal-confirm flows)
|
|
10078
10078
|
const doDelete = async row => {
|
|
10079
10079
|
if (!row) return;
|
|
10080
|
+
|
|
10081
|
+
// call callback if provided; only abort deletion if it explicitly
|
|
10082
|
+
// returns an object with success === false
|
|
10080
10083
|
if (deleteCallbackRef.current) {
|
|
10081
|
-
|
|
10082
|
-
|
|
10084
|
+
try {
|
|
10085
|
+
const res = await deleteCallbackRef.current(row);
|
|
10086
|
+
if (res && res.success === false) return;
|
|
10087
|
+
} catch (err) {
|
|
10088
|
+
// if callback throws, don't block deletion
|
|
10089
|
+
console.error('deleteCallback threw', err);
|
|
10090
|
+
}
|
|
10083
10091
|
}
|
|
10084
10092
|
setLocalData(prev => {
|
|
10085
10093
|
if (isGrouped) {
|
|
@@ -10331,6 +10339,50 @@ function TableInner({
|
|
|
10331
10339
|
});
|
|
10332
10340
|
}, [tableDataFlat, isGrouped, groupKey]);
|
|
10333
10341
|
|
|
10342
|
+
// DUPLICATE
|
|
10343
|
+
const doDuplicate = row => {
|
|
10344
|
+
if (!row) return;
|
|
10345
|
+
// try user callback first; if it returns an object with newRow use that
|
|
10346
|
+
let newRow = null;
|
|
10347
|
+
if (duplicateCallbackRef.current) {
|
|
10348
|
+
try {
|
|
10349
|
+
const res = duplicateCallbackRef.current(row);
|
|
10350
|
+
if (res && res.newRow) {
|
|
10351
|
+
newRow = res.newRow;
|
|
10352
|
+
}
|
|
10353
|
+
} catch (err) {
|
|
10354
|
+
console.error('duplicateCallback threw', err);
|
|
10355
|
+
}
|
|
10356
|
+
}
|
|
10357
|
+
// fallback simple clone if callback didn't provide newRow
|
|
10358
|
+
if (!newRow) {
|
|
10359
|
+
newRow = {
|
|
10360
|
+
...row
|
|
10361
|
+
};
|
|
10362
|
+
// give it a distinct id if possible
|
|
10363
|
+
if (newRow.id != null) {
|
|
10364
|
+
newRow.id = `${newRow.id}-dup-${Date.now()}`;
|
|
10365
|
+
}
|
|
10366
|
+
}
|
|
10367
|
+
setLocalData(prev => {
|
|
10368
|
+
if (isGrouped) {
|
|
10369
|
+
return prev.map(g => {
|
|
10370
|
+
const gid = g[groupKey] ?? g.groupId ?? g.groupName;
|
|
10371
|
+
// insert into same group as original row
|
|
10372
|
+
if (row[groupKey] === gid || g.rows.some(r => r.id === row.id)) {
|
|
10373
|
+
return {
|
|
10374
|
+
...g,
|
|
10375
|
+
rows: [...(g.rows || []), newRow]
|
|
10376
|
+
};
|
|
10377
|
+
}
|
|
10378
|
+
return g;
|
|
10379
|
+
});
|
|
10380
|
+
}
|
|
10381
|
+
return [...(prev || []), newRow];
|
|
10382
|
+
});
|
|
10383
|
+
refreshTriggerRef.current?.();
|
|
10384
|
+
};
|
|
10385
|
+
|
|
10334
10386
|
// ROW RENDERER
|
|
10335
10387
|
const rowRenderer = React.useCallback(({
|
|
10336
10388
|
index,
|
|
@@ -10542,8 +10594,12 @@ function TableInner({
|
|
|
10542
10594
|
}, "\u270F\uFE0F") : translate("edit")), showDuplicate && /*#__PURE__*/React.createElement("button", {
|
|
10543
10595
|
className: "action-btn-table",
|
|
10544
10596
|
onClick: e => {
|
|
10545
|
-
e.stopPropagation();
|
|
10546
|
-
|
|
10597
|
+
// e.stopPropagation();
|
|
10598
|
+
// always duplicate locally; user callback may also return newRow
|
|
10599
|
+
doDuplicate(row);
|
|
10600
|
+
try {
|
|
10601
|
+
duplicateCallbackRef.current(row);
|
|
10602
|
+
} catch {}
|
|
10547
10603
|
},
|
|
10548
10604
|
onDoubleClick: e => e.stopPropagation(),
|
|
10549
10605
|
"aria-label": translate("duplicate")
|
|
@@ -10557,7 +10613,7 @@ function TableInner({
|
|
|
10557
10613
|
}, "\uD83D\uDDD0") : translate("duplicate")), showDelete && /*#__PURE__*/React.createElement("button", {
|
|
10558
10614
|
className: "action-btn-table",
|
|
10559
10615
|
onClick: e => {
|
|
10560
|
-
e.stopPropagation();
|
|
10616
|
+
// e.stopPropagation();
|
|
10561
10617
|
// If prop set, skip integrated confirmation modal and delete immediately
|
|
10562
10618
|
if (disableDeleteModal) {
|
|
10563
10619
|
doDelete(row);
|
|
@@ -10575,7 +10631,7 @@ function TableInner({
|
|
|
10575
10631
|
}, "\uD83D\uDDD1\uFE0F") : translate("delete")), showShare && /*#__PURE__*/React.createElement("button", {
|
|
10576
10632
|
className: "action-btn-table",
|
|
10577
10633
|
onClick: e => {
|
|
10578
|
-
e.stopPropagation();
|
|
10634
|
+
// e.stopPropagation();
|
|
10579
10635
|
shareCallbackRef.current(row);
|
|
10580
10636
|
},
|
|
10581
10637
|
onDoubleClick: e => e.stopPropagation(),
|