warqadui 0.0.39 → 0.0.41
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/index.js +63 -56
- package/dist/index.mjs +63 -56
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3248,7 +3248,7 @@ var TableCell = import_react16.default.memo(
|
|
|
3248
3248
|
);
|
|
3249
3249
|
},
|
|
3250
3250
|
(prev, next) => {
|
|
3251
|
-
return prev.cell.getValue() === next.cell.getValue() && prev.cell.row.getIsExpanded() === next.cell.row.getIsExpanded() && prev.cell.row.getIsSelected() === next.cell.row.getIsSelected() && prev.rowPadding === next.rowPadding && prev.verticalLines === next.verticalLines;
|
|
3251
|
+
return prev.cell.getValue() === next.cell.getValue() && prev.cell.row.original === next.cell.row.original && prev.cell.row.getIsExpanded() === next.cell.row.getIsExpanded() && prev.cell.row.getIsSelected() === next.cell.row.getIsSelected() && prev.rowPadding === next.rowPadding && prev.verticalLines === next.verticalLines;
|
|
3252
3252
|
}
|
|
3253
3253
|
);
|
|
3254
3254
|
var TableRow = import_react16.default.memo(
|
|
@@ -3335,7 +3335,9 @@ function PostTable({
|
|
|
3335
3335
|
}
|
|
3336
3336
|
return initialState;
|
|
3337
3337
|
});
|
|
3338
|
-
const [
|
|
3338
|
+
const [internalData, setInternalData] = (0, import_react16.useState)(controlledData || []);
|
|
3339
|
+
const isControlled = controlledData !== void 0;
|
|
3340
|
+
const data = isControlled ? controlledData : internalData;
|
|
3339
3341
|
const entryRowRef = (0, import_react16.useRef)(null);
|
|
3340
3342
|
const focusAndScrollEntryRow = () => {
|
|
3341
3343
|
setTimeout(() => {
|
|
@@ -3356,11 +3358,6 @@ function PostTable({
|
|
|
3356
3358
|
(0, import_react16.useEffect)(() => {
|
|
3357
3359
|
focusAndScrollEntryRow();
|
|
3358
3360
|
}, []);
|
|
3359
|
-
(0, import_react16.useEffect)(() => {
|
|
3360
|
-
if (controlledData) {
|
|
3361
|
-
setData(controlledData);
|
|
3362
|
-
}
|
|
3363
|
-
}, [controlledData]);
|
|
3364
3361
|
const [entryData, setEntryData] = (0, import_react16.useState)({});
|
|
3365
3362
|
const [editingIndex, setEditingIndex] = (0, import_react16.useState)(null);
|
|
3366
3363
|
const [isSavingAsync, setIsSavingAsync] = (0, import_react16.useState)(false);
|
|
@@ -3392,23 +3389,21 @@ function PostTable({
|
|
|
3392
3389
|
};
|
|
3393
3390
|
});
|
|
3394
3391
|
const handleSaveField = (0, import_react16.useCallback)(async () => {
|
|
3395
|
-
const {
|
|
3396
|
-
data: data2,
|
|
3397
|
-
entryData: entryData2,
|
|
3398
|
-
editingIndex: editingIndex2,
|
|
3399
|
-
isSavingAsync: isSavingAsync2,
|
|
3400
|
-
submitLoading: submitLoading2,
|
|
3401
|
-
onChange: onChange2
|
|
3402
|
-
} = latestStateRef.current;
|
|
3392
|
+
const { data: data2, entryData: entryData2, editingIndex: editingIndex2, onChange: onChange2 } = latestStateRef.current;
|
|
3403
3393
|
if (Object.keys(entryData2).length === 0) return;
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3394
|
+
const actionType = editingIndex2 !== null ? "edit" : "add";
|
|
3395
|
+
const entryToSave = { ...entryData2 };
|
|
3396
|
+
const updated = [...data2];
|
|
3397
|
+
let entryToPass;
|
|
3398
|
+
if (actionType === "edit" && editingIndex2 !== null) {
|
|
3399
|
+
updated[editingIndex2] = {
|
|
3400
|
+
...updated[editingIndex2],
|
|
3401
|
+
...entryToSave
|
|
3409
3402
|
};
|
|
3403
|
+
entryToPass = updated[editingIndex2];
|
|
3410
3404
|
} else {
|
|
3411
|
-
|
|
3405
|
+
updated.push(entryToSave);
|
|
3406
|
+
entryToPass = updated[updated.length - 1];
|
|
3412
3407
|
}
|
|
3413
3408
|
if (onChange2) {
|
|
3414
3409
|
setIsSavingAsync(true);
|
|
@@ -3434,12 +3429,11 @@ function PostTable({
|
|
|
3434
3429
|
}));
|
|
3435
3430
|
}
|
|
3436
3431
|
};
|
|
3437
|
-
const type = editingIndex2 !== null ? "edit" : "add";
|
|
3438
3432
|
const result = await onChange2({
|
|
3439
|
-
entryData:
|
|
3433
|
+
entryData: entryToPass,
|
|
3440
3434
|
actions,
|
|
3441
|
-
actionType
|
|
3442
|
-
fullData:
|
|
3435
|
+
actionType,
|
|
3436
|
+
fullData: updated
|
|
3443
3437
|
});
|
|
3444
3438
|
if (result === false) {
|
|
3445
3439
|
setIsSavingAsync(false);
|
|
@@ -3450,14 +3444,14 @@ function PostTable({
|
|
|
3450
3444
|
return;
|
|
3451
3445
|
}
|
|
3452
3446
|
}
|
|
3453
|
-
|
|
3447
|
+
setInternalData(updated);
|
|
3454
3448
|
setEntryData({});
|
|
3455
3449
|
setFieldErrors({});
|
|
3456
3450
|
setIsSavingAsync(false);
|
|
3457
3451
|
if (editingIndex2 !== null) {
|
|
3458
3452
|
setEditingIndex(null);
|
|
3459
3453
|
} else {
|
|
3460
|
-
focusAndScrollEntryRow();
|
|
3454
|
+
setTimeout(() => focusAndScrollEntryRow(), 0);
|
|
3461
3455
|
}
|
|
3462
3456
|
}, []);
|
|
3463
3457
|
const handleCancelEdit = (0, import_react16.useCallback)(() => {
|
|
@@ -3470,43 +3464,56 @@ function PostTable({
|
|
|
3470
3464
|
const handleEdit = (0, import_react16.useCallback)((index2, rowOriginal) => {
|
|
3471
3465
|
const { onEdit: onEdit2 } = latestStateRef.current;
|
|
3472
3466
|
setEditingIndex(index2);
|
|
3473
|
-
setEntryData(rowOriginal);
|
|
3467
|
+
setEntryData({ ...rowOriginal });
|
|
3474
3468
|
if (onEdit2) onEdit2(rowOriginal);
|
|
3475
3469
|
}, []);
|
|
3476
3470
|
const handleDelete = (0, import_react16.useCallback)(
|
|
3477
|
-
(index2) => {
|
|
3471
|
+
async (index2) => {
|
|
3478
3472
|
const { data: data2, editingIndex: editingIndex2, onChange: onChange2, onDelete: onDelete2 } = latestStateRef.current;
|
|
3479
3473
|
const rowToDelete = data2[index2];
|
|
3480
|
-
const
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3474
|
+
const updated = data2.filter((_, i) => i !== index2);
|
|
3475
|
+
if (onChange2) {
|
|
3476
|
+
setIsSavingAsync(true);
|
|
3477
|
+
try {
|
|
3478
|
+
const actions = {
|
|
3479
|
+
focus: (columnId) => {
|
|
3480
|
+
if (entryRowRef.current) {
|
|
3481
|
+
const td = entryRowRef.current.querySelector(
|
|
3482
|
+
`td[data-column-id="${columnId}"]`
|
|
3483
|
+
);
|
|
3484
|
+
if (td) {
|
|
3485
|
+
const input = td.querySelector(
|
|
3486
|
+
`input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
|
|
3487
|
+
);
|
|
3488
|
+
if (input) input.focus();
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
},
|
|
3492
|
+
setError: (columnId, error) => {
|
|
3493
|
+
setFieldErrors((prev) => ({
|
|
3494
|
+
...prev,
|
|
3495
|
+
[columnId]: error
|
|
3496
|
+
}));
|
|
3494
3497
|
}
|
|
3498
|
+
};
|
|
3499
|
+
const result = await onChange2({
|
|
3500
|
+
entryData: rowToDelete,
|
|
3501
|
+
actions,
|
|
3502
|
+
actionType: "delete",
|
|
3503
|
+
fullData: updated
|
|
3504
|
+
});
|
|
3505
|
+
if (result === false) {
|
|
3506
|
+
setIsSavingAsync(false);
|
|
3507
|
+
return;
|
|
3495
3508
|
}
|
|
3496
|
-
}
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
...prev,
|
|
3500
|
-
[columnId]: error
|
|
3501
|
-
}));
|
|
3509
|
+
} catch (error) {
|
|
3510
|
+
setIsSavingAsync(false);
|
|
3511
|
+
return;
|
|
3502
3512
|
}
|
|
3503
|
-
}
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
actionType: "delete",
|
|
3508
|
-
fullData: newData
|
|
3509
|
-
});
|
|
3513
|
+
}
|
|
3514
|
+
setInternalData(updated);
|
|
3515
|
+
if (onDelete2) onDelete2(rowToDelete);
|
|
3516
|
+
setIsSavingAsync(false);
|
|
3510
3517
|
if (editingIndex2 === index2) {
|
|
3511
3518
|
handleCancelEdit();
|
|
3512
3519
|
} else if (editingIndex2 !== null && editingIndex2 > index2) {
|
package/dist/index.mjs
CHANGED
|
@@ -3219,7 +3219,7 @@ var TableCell = React9.memo(
|
|
|
3219
3219
|
);
|
|
3220
3220
|
},
|
|
3221
3221
|
(prev, next) => {
|
|
3222
|
-
return prev.cell.getValue() === next.cell.getValue() && prev.cell.row.getIsExpanded() === next.cell.row.getIsExpanded() && prev.cell.row.getIsSelected() === next.cell.row.getIsSelected() && prev.rowPadding === next.rowPadding && prev.verticalLines === next.verticalLines;
|
|
3222
|
+
return prev.cell.getValue() === next.cell.getValue() && prev.cell.row.original === next.cell.row.original && prev.cell.row.getIsExpanded() === next.cell.row.getIsExpanded() && prev.cell.row.getIsSelected() === next.cell.row.getIsSelected() && prev.rowPadding === next.rowPadding && prev.verticalLines === next.verticalLines;
|
|
3223
3223
|
}
|
|
3224
3224
|
);
|
|
3225
3225
|
var TableRow = React9.memo(
|
|
@@ -3306,7 +3306,9 @@ function PostTable({
|
|
|
3306
3306
|
}
|
|
3307
3307
|
return initialState;
|
|
3308
3308
|
});
|
|
3309
|
-
const [
|
|
3309
|
+
const [internalData, setInternalData] = useState15(controlledData || []);
|
|
3310
|
+
const isControlled = controlledData !== void 0;
|
|
3311
|
+
const data = isControlled ? controlledData : internalData;
|
|
3310
3312
|
const entryRowRef = useRef5(null);
|
|
3311
3313
|
const focusAndScrollEntryRow = () => {
|
|
3312
3314
|
setTimeout(() => {
|
|
@@ -3327,11 +3329,6 @@ function PostTable({
|
|
|
3327
3329
|
useEffect10(() => {
|
|
3328
3330
|
focusAndScrollEntryRow();
|
|
3329
3331
|
}, []);
|
|
3330
|
-
useEffect10(() => {
|
|
3331
|
-
if (controlledData) {
|
|
3332
|
-
setData(controlledData);
|
|
3333
|
-
}
|
|
3334
|
-
}, [controlledData]);
|
|
3335
3332
|
const [entryData, setEntryData] = useState15({});
|
|
3336
3333
|
const [editingIndex, setEditingIndex] = useState15(null);
|
|
3337
3334
|
const [isSavingAsync, setIsSavingAsync] = useState15(false);
|
|
@@ -3363,23 +3360,21 @@ function PostTable({
|
|
|
3363
3360
|
};
|
|
3364
3361
|
});
|
|
3365
3362
|
const handleSaveField = useCallback2(async () => {
|
|
3366
|
-
const {
|
|
3367
|
-
data: data2,
|
|
3368
|
-
entryData: entryData2,
|
|
3369
|
-
editingIndex: editingIndex2,
|
|
3370
|
-
isSavingAsync: isSavingAsync2,
|
|
3371
|
-
submitLoading: submitLoading2,
|
|
3372
|
-
onChange: onChange2
|
|
3373
|
-
} = latestStateRef.current;
|
|
3363
|
+
const { data: data2, entryData: entryData2, editingIndex: editingIndex2, onChange: onChange2 } = latestStateRef.current;
|
|
3374
3364
|
if (Object.keys(entryData2).length === 0) return;
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3365
|
+
const actionType = editingIndex2 !== null ? "edit" : "add";
|
|
3366
|
+
const entryToSave = { ...entryData2 };
|
|
3367
|
+
const updated = [...data2];
|
|
3368
|
+
let entryToPass;
|
|
3369
|
+
if (actionType === "edit" && editingIndex2 !== null) {
|
|
3370
|
+
updated[editingIndex2] = {
|
|
3371
|
+
...updated[editingIndex2],
|
|
3372
|
+
...entryToSave
|
|
3380
3373
|
};
|
|
3374
|
+
entryToPass = updated[editingIndex2];
|
|
3381
3375
|
} else {
|
|
3382
|
-
|
|
3376
|
+
updated.push(entryToSave);
|
|
3377
|
+
entryToPass = updated[updated.length - 1];
|
|
3383
3378
|
}
|
|
3384
3379
|
if (onChange2) {
|
|
3385
3380
|
setIsSavingAsync(true);
|
|
@@ -3405,12 +3400,11 @@ function PostTable({
|
|
|
3405
3400
|
}));
|
|
3406
3401
|
}
|
|
3407
3402
|
};
|
|
3408
|
-
const type = editingIndex2 !== null ? "edit" : "add";
|
|
3409
3403
|
const result = await onChange2({
|
|
3410
|
-
entryData:
|
|
3404
|
+
entryData: entryToPass,
|
|
3411
3405
|
actions,
|
|
3412
|
-
actionType
|
|
3413
|
-
fullData:
|
|
3406
|
+
actionType,
|
|
3407
|
+
fullData: updated
|
|
3414
3408
|
});
|
|
3415
3409
|
if (result === false) {
|
|
3416
3410
|
setIsSavingAsync(false);
|
|
@@ -3421,14 +3415,14 @@ function PostTable({
|
|
|
3421
3415
|
return;
|
|
3422
3416
|
}
|
|
3423
3417
|
}
|
|
3424
|
-
|
|
3418
|
+
setInternalData(updated);
|
|
3425
3419
|
setEntryData({});
|
|
3426
3420
|
setFieldErrors({});
|
|
3427
3421
|
setIsSavingAsync(false);
|
|
3428
3422
|
if (editingIndex2 !== null) {
|
|
3429
3423
|
setEditingIndex(null);
|
|
3430
3424
|
} else {
|
|
3431
|
-
focusAndScrollEntryRow();
|
|
3425
|
+
setTimeout(() => focusAndScrollEntryRow(), 0);
|
|
3432
3426
|
}
|
|
3433
3427
|
}, []);
|
|
3434
3428
|
const handleCancelEdit = useCallback2(() => {
|
|
@@ -3441,43 +3435,56 @@ function PostTable({
|
|
|
3441
3435
|
const handleEdit = useCallback2((index2, rowOriginal) => {
|
|
3442
3436
|
const { onEdit: onEdit2 } = latestStateRef.current;
|
|
3443
3437
|
setEditingIndex(index2);
|
|
3444
|
-
setEntryData(rowOriginal);
|
|
3438
|
+
setEntryData({ ...rowOriginal });
|
|
3445
3439
|
if (onEdit2) onEdit2(rowOriginal);
|
|
3446
3440
|
}, []);
|
|
3447
3441
|
const handleDelete = useCallback2(
|
|
3448
|
-
(index2) => {
|
|
3442
|
+
async (index2) => {
|
|
3449
3443
|
const { data: data2, editingIndex: editingIndex2, onChange: onChange2, onDelete: onDelete2 } = latestStateRef.current;
|
|
3450
3444
|
const rowToDelete = data2[index2];
|
|
3451
|
-
const
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3445
|
+
const updated = data2.filter((_, i) => i !== index2);
|
|
3446
|
+
if (onChange2) {
|
|
3447
|
+
setIsSavingAsync(true);
|
|
3448
|
+
try {
|
|
3449
|
+
const actions = {
|
|
3450
|
+
focus: (columnId) => {
|
|
3451
|
+
if (entryRowRef.current) {
|
|
3452
|
+
const td = entryRowRef.current.querySelector(
|
|
3453
|
+
`td[data-column-id="${columnId}"]`
|
|
3454
|
+
);
|
|
3455
|
+
if (td) {
|
|
3456
|
+
const input = td.querySelector(
|
|
3457
|
+
`input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
|
|
3458
|
+
);
|
|
3459
|
+
if (input) input.focus();
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
},
|
|
3463
|
+
setError: (columnId, error) => {
|
|
3464
|
+
setFieldErrors((prev) => ({
|
|
3465
|
+
...prev,
|
|
3466
|
+
[columnId]: error
|
|
3467
|
+
}));
|
|
3465
3468
|
}
|
|
3469
|
+
};
|
|
3470
|
+
const result = await onChange2({
|
|
3471
|
+
entryData: rowToDelete,
|
|
3472
|
+
actions,
|
|
3473
|
+
actionType: "delete",
|
|
3474
|
+
fullData: updated
|
|
3475
|
+
});
|
|
3476
|
+
if (result === false) {
|
|
3477
|
+
setIsSavingAsync(false);
|
|
3478
|
+
return;
|
|
3466
3479
|
}
|
|
3467
|
-
}
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
...prev,
|
|
3471
|
-
[columnId]: error
|
|
3472
|
-
}));
|
|
3480
|
+
} catch (error) {
|
|
3481
|
+
setIsSavingAsync(false);
|
|
3482
|
+
return;
|
|
3473
3483
|
}
|
|
3474
|
-
}
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
actionType: "delete",
|
|
3479
|
-
fullData: newData
|
|
3480
|
-
});
|
|
3484
|
+
}
|
|
3485
|
+
setInternalData(updated);
|
|
3486
|
+
if (onDelete2) onDelete2(rowToDelete);
|
|
3487
|
+
setIsSavingAsync(false);
|
|
3481
3488
|
if (editingIndex2 === index2) {
|
|
3482
3489
|
handleCancelEdit();
|
|
3483
3490
|
} else if (editingIndex2 !== null && editingIndex2 > index2) {
|