warqadui 0.0.38 → 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 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 [data, setData] = (0, import_react16.useState)(controlledData || []);
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
- let newData = [...data2];
3405
- if (editingIndex2 !== null) {
3406
- newData[editingIndex2] = {
3407
- ...newData[editingIndex2],
3408
- ...entryData2
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
- newData = [...newData, entryData2];
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: entryData2,
3433
+ entryData: entryToPass,
3440
3434
  actions,
3441
- actionType: type,
3442
- fullData: newData
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
- setData(newData);
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 newData = data2.filter((_, i) => i !== index2);
3481
- setData(newData);
3482
- if (onDelete2) onDelete2(rowToDelete);
3483
- const actions = {
3484
- focus: (columnId) => {
3485
- if (entryRowRef.current) {
3486
- const td = entryRowRef.current.querySelector(
3487
- `td[data-column-id="${columnId}"]`
3488
- );
3489
- if (td) {
3490
- const input = td.querySelector(
3491
- `input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
3492
- );
3493
- if (input) input.focus();
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
- setError: (columnId, error) => {
3498
- setFieldErrors((prev) => ({
3499
- ...prev,
3500
- [columnId]: error
3501
- }));
3509
+ } catch (error) {
3510
+ setIsSavingAsync(false);
3511
+ return;
3502
3512
  }
3503
- };
3504
- onChange2?.({
3505
- entryData: data2[index2],
3506
- actions,
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) {
@@ -4353,7 +4360,7 @@ var useA4StatementView = ({
4353
4360
  pageIndex === 0 && DisplayInfoGridEl,
4354
4361
  /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "grow w-full px-8 pb-8", children: [
4355
4362
  pageIndex === 0 && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "mb-4 border-b border-gray-200 dark:border-zinc-800 print:border-gray-200 pb-2 flex items-center gap-2 justify-between px-2 mt-2 print:hidden", children: [
4356
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("h3", { className: "text-sm font-bold text-gray-800 dark:text-gray-100 print:text-gray-800 uppercase tracking-wide shrink-0", children: "Recent Transactions" }),
4363
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("h3", { className: "text-sm font-bold text-gray-800 dark:text-gray-100 print:text-gray-800 uppercase tracking-wide shrink-0", children: tableTitle }),
4357
4364
  /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
4358
4365
  "input",
4359
4366
  {
@@ -4365,7 +4372,7 @@ var useA4StatementView = ({
4365
4372
  }
4366
4373
  )
4367
4374
  ] }),
4368
- pageIndex === 0 && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "hidden print:flex mb-4 border-b border-gray-200 print:border-gray-200 pb-2 items-center gap-2 justify-between px-2 mt-2", children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("h3", { className: "text-sm font-bold text-gray-800 print:text-gray-800 uppercase tracking-wide shrink-0", children: "Recent Transactions" }) }),
4375
+ pageIndex === 0 && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "hidden print:flex mb-4 border-b border-gray-200 print:border-gray-200 pb-2 items-center gap-2 justify-between px-2 mt-2", children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("h3", { className: "text-sm font-bold text-gray-800 print:text-gray-800 uppercase tracking-wide shrink-0", children: tableTitle }) }),
4369
4376
  pageIndex > 0 && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "h-5 print:h-0" }),
4370
4377
  /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
4371
4378
  SimpleTable,
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 [data, setData] = useState15(controlledData || []);
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
- let newData = [...data2];
3376
- if (editingIndex2 !== null) {
3377
- newData[editingIndex2] = {
3378
- ...newData[editingIndex2],
3379
- ...entryData2
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
- newData = [...newData, entryData2];
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: entryData2,
3404
+ entryData: entryToPass,
3411
3405
  actions,
3412
- actionType: type,
3413
- fullData: newData
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
- setData(newData);
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 newData = data2.filter((_, i) => i !== index2);
3452
- setData(newData);
3453
- if (onDelete2) onDelete2(rowToDelete);
3454
- const actions = {
3455
- focus: (columnId) => {
3456
- if (entryRowRef.current) {
3457
- const td = entryRowRef.current.querySelector(
3458
- `td[data-column-id="${columnId}"]`
3459
- );
3460
- if (td) {
3461
- const input = td.querySelector(
3462
- `input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex='0'], [id*='${columnId}']`
3463
- );
3464
- if (input) input.focus();
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
- setError: (columnId, error) => {
3469
- setFieldErrors((prev) => ({
3470
- ...prev,
3471
- [columnId]: error
3472
- }));
3480
+ } catch (error) {
3481
+ setIsSavingAsync(false);
3482
+ return;
3473
3483
  }
3474
- };
3475
- onChange2?.({
3476
- entryData: data2[index2],
3477
- actions,
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) {
@@ -4328,7 +4335,7 @@ var useA4StatementView = ({
4328
4335
  pageIndex === 0 && DisplayInfoGridEl,
4329
4336
  /* @__PURE__ */ jsxs20("div", { className: "grow w-full px-8 pb-8", children: [
4330
4337
  pageIndex === 0 && /* @__PURE__ */ jsxs20("div", { className: "mb-4 border-b border-gray-200 dark:border-zinc-800 print:border-gray-200 pb-2 flex items-center gap-2 justify-between px-2 mt-2 print:hidden", children: [
4331
- /* @__PURE__ */ jsx28("h3", { className: "text-sm font-bold text-gray-800 dark:text-gray-100 print:text-gray-800 uppercase tracking-wide shrink-0", children: "Recent Transactions" }),
4338
+ /* @__PURE__ */ jsx28("h3", { className: "text-sm font-bold text-gray-800 dark:text-gray-100 print:text-gray-800 uppercase tracking-wide shrink-0", children: tableTitle }),
4332
4339
  /* @__PURE__ */ jsx28(
4333
4340
  "input",
4334
4341
  {
@@ -4340,7 +4347,7 @@ var useA4StatementView = ({
4340
4347
  }
4341
4348
  )
4342
4349
  ] }),
4343
- pageIndex === 0 && /* @__PURE__ */ jsx28("div", { className: "hidden print:flex mb-4 border-b border-gray-200 print:border-gray-200 pb-2 items-center gap-2 justify-between px-2 mt-2", children: /* @__PURE__ */ jsx28("h3", { className: "text-sm font-bold text-gray-800 print:text-gray-800 uppercase tracking-wide shrink-0", children: "Recent Transactions" }) }),
4350
+ pageIndex === 0 && /* @__PURE__ */ jsx28("div", { className: "hidden print:flex mb-4 border-b border-gray-200 print:border-gray-200 pb-2 items-center gap-2 justify-between px-2 mt-2", children: /* @__PURE__ */ jsx28("h3", { className: "text-sm font-bold text-gray-800 print:text-gray-800 uppercase tracking-wide shrink-0", children: tableTitle }) }),
4344
4351
  pageIndex > 0 && /* @__PURE__ */ jsx28("div", { className: "h-5 print:h-0" }),
4345
4352
  /* @__PURE__ */ jsx28(
4346
4353
  SimpleTable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "warqadui",
3
- "version": "0.0.38",
3
+ "version": "0.0.41",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",