es-grid-template 1.8.50 → 1.8.52

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.
@@ -487,8 +487,8 @@ const TableContainerEdit = props => {
487
487
  const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
488
488
  const valuePasteFormat = detectSeparators(cellValue.trim());
489
489
  const cellFormat = getFormat(colFormat, format);
490
- const thousandSeparator = valuePasteFormat?.thousandSeparator ?? cellFormat?.thousandSeparator;
491
- const decimalSeparator = valuePasteFormat?.decimalSeparator ?? cellFormat?.decimalSeparator;
490
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
491
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
492
492
  const dec = cellFormat?.decimalScale;
493
493
  const numericFormatProps = {
494
494
  thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
@@ -558,12 +558,55 @@ const TableContainerEdit = props => {
558
558
 
559
559
  const columnOri = columnTarget.columnDef.meta ?? {};
560
560
  const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
561
+
562
+ // if (isEdit) {
563
+
564
+ // const columnKey = allCols[targetCol].id
565
+
566
+ // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
567
+
568
+ // pastedColumns.add(columnKey)
569
+ // }
570
+
561
571
  if (isEdit) {
562
572
  const columnKey = allCols[targetCol].id;
563
- childData[targetRow] = {
564
- ...childData[targetRow],
565
- [columnKey]: cellValue.trim()
566
- };
573
+
574
+ // if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
575
+ if (columnOri.type === 'number') {
576
+ if (cellValue.trim() === '') {
577
+ childData[targetRow] = {
578
+ ...childData[targetRow],
579
+ [columnKey]: null
580
+ };
581
+ }
582
+ if (isFormattedNumber(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
583
+ const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
584
+ const valuePasteFormat = detectSeparators(cellValue.trim());
585
+ const cellFormat = getFormat(colFormat, format);
586
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
587
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
588
+ const dec = cellFormat?.decimalScale;
589
+ const numericFormatProps = {
590
+ thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
591
+ decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
592
+ allowNegative: cellFormat?.allowNegative ?? true,
593
+ prefix: cellFormat?.prefix,
594
+ suffix: cellFormat?.suffix,
595
+ decimalScale: dec,
596
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
597
+ };
598
+ const val = removeNumericFormat(cellValue.trim(), undefined, numericFormatProps);
599
+ childData[targetRow] = {
600
+ ...childData[targetRow],
601
+ [columnKey]: Number(val)
602
+ };
603
+ }
604
+ } else {
605
+ childData[targetRow] = {
606
+ ...childData[targetRow],
607
+ [columnKey]: cellValue.trim()
608
+ };
609
+ }
567
610
  pastedColumns.add(columnKey);
568
611
  }
569
612
  });
@@ -677,7 +677,7 @@ export const isFormattedNumber = str => {
677
677
  const regexEU = /^\d{1,3}(\.\d{3})*(,\d+)?$/; // 100.000,111
678
678
 
679
679
  // Không có dấu hàng nghìn, chỉ dấu thập phân: 100000.1 hoặc 100000,01
680
- const regexDecimalOnly = /^\d+([.,]\d{1,})$/;
680
+ const regexDecimalOnly = /^-?\d+([.,]\d{1,})$/;
681
681
  return regexUS.test(str) || regexEU.test(str) || regexDecimalOnly.test(str);
682
682
  };
683
683
  export const detectSeparators = str => {
@@ -704,9 +704,9 @@ export const detectSeparators = str => {
704
704
  if (parts.length === 2) {
705
705
  return parts[1].length === 3 ? {
706
706
  thousandSeparator: ',',
707
- decimalSeparator: null
707
+ decimalSeparator: undefined
708
708
  } : {
709
- thousandSeparator: null,
709
+ thousandSeparator: undefined,
710
710
  decimalSeparator: ','
711
711
  };
712
712
  }
@@ -718,9 +718,9 @@ export const detectSeparators = str => {
718
718
  if (parts.length === 2) {
719
719
  return parts[1].length === 3 ? {
720
720
  thousandSeparator: '.',
721
- decimalSeparator: null
721
+ decimalSeparator: undefined
722
722
  } : {
723
- thousandSeparator: null,
723
+ thousandSeparator: undefined,
724
724
  decimalSeparator: '.'
725
725
  };
726
726
  }
@@ -494,8 +494,8 @@ const TableContainerEdit = props => {
494
494
  const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
495
495
  const valuePasteFormat = (0, _utils.detectSeparators)(cellValue.trim());
496
496
  const cellFormat = (0, _utils.getFormat)(colFormat, format);
497
- const thousandSeparator = valuePasteFormat?.thousandSeparator ?? cellFormat?.thousandSeparator;
498
- const decimalSeparator = valuePasteFormat?.decimalSeparator ?? cellFormat?.decimalSeparator;
497
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
498
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
499
499
  const dec = cellFormat?.decimalScale;
500
500
  const numericFormatProps = {
501
501
  thousandSeparator: (0, _utils.checkThousandSeparator)(thousandSeparator, decimalSeparator),
@@ -565,12 +565,55 @@ const TableContainerEdit = props => {
565
565
 
566
566
  const columnOri = columnTarget.columnDef.meta ?? {};
567
567
  const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
568
+
569
+ // if (isEdit) {
570
+
571
+ // const columnKey = allCols[targetCol].id
572
+
573
+ // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
574
+
575
+ // pastedColumns.add(columnKey)
576
+ // }
577
+
568
578
  if (isEdit) {
569
579
  const columnKey = allCols[targetCol].id;
570
- childData[targetRow] = {
571
- ...childData[targetRow],
572
- [columnKey]: cellValue.trim()
573
- };
580
+
581
+ // if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
582
+ if (columnOri.type === 'number') {
583
+ if (cellValue.trim() === '') {
584
+ childData[targetRow] = {
585
+ ...childData[targetRow],
586
+ [columnKey]: null
587
+ };
588
+ }
589
+ if ((0, _utils.isFormattedNumber)(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
590
+ const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
591
+ const valuePasteFormat = (0, _utils.detectSeparators)(cellValue.trim());
592
+ const cellFormat = (0, _utils.getFormat)(colFormat, format);
593
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
594
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
595
+ const dec = cellFormat?.decimalScale;
596
+ const numericFormatProps = {
597
+ thousandSeparator: (0, _utils.checkThousandSeparator)(thousandSeparator, decimalSeparator),
598
+ decimalSeparator: (0, _utils.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
599
+ allowNegative: cellFormat?.allowNegative ?? true,
600
+ prefix: cellFormat?.prefix,
601
+ suffix: cellFormat?.suffix,
602
+ decimalScale: dec,
603
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
604
+ };
605
+ const val = (0, _reactNumericComponent.removeNumericFormat)(cellValue.trim(), undefined, numericFormatProps);
606
+ childData[targetRow] = {
607
+ ...childData[targetRow],
608
+ [columnKey]: Number(val)
609
+ };
610
+ }
611
+ } else {
612
+ childData[targetRow] = {
613
+ ...childData[targetRow],
614
+ [columnKey]: cellValue.trim()
615
+ };
616
+ }
574
617
  pastedColumns.add(columnKey);
575
618
  }
576
619
  });
@@ -769,7 +769,7 @@ const isFormattedNumber = str => {
769
769
  const regexEU = /^\d{1,3}(\.\d{3})*(,\d+)?$/; // 100.000,111
770
770
 
771
771
  // Không có dấu hàng nghìn, chỉ dấu thập phân: 100000.1 hoặc 100000,01
772
- const regexDecimalOnly = /^\d+([.,]\d{1,})$/;
772
+ const regexDecimalOnly = /^-?\d+([.,]\d{1,})$/;
773
773
  return regexUS.test(str) || regexEU.test(str) || regexDecimalOnly.test(str);
774
774
  };
775
775
  exports.isFormattedNumber = isFormattedNumber;
@@ -797,9 +797,9 @@ const detectSeparators = str => {
797
797
  if (parts.length === 2) {
798
798
  return parts[1].length === 3 ? {
799
799
  thousandSeparator: ',',
800
- decimalSeparator: null
800
+ decimalSeparator: undefined
801
801
  } : {
802
- thousandSeparator: null,
802
+ thousandSeparator: undefined,
803
803
  decimalSeparator: ','
804
804
  };
805
805
  }
@@ -811,9 +811,9 @@ const detectSeparators = str => {
811
811
  if (parts.length === 2) {
812
812
  return parts[1].length === 3 ? {
813
813
  thousandSeparator: '.',
814
- decimalSeparator: null
814
+ decimalSeparator: undefined
815
815
  } : {
816
- thousandSeparator: null,
816
+ thousandSeparator: undefined,
817
817
  decimalSeparator: '.'
818
818
  };
819
819
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.8.50",
3
+ "version": "1.8.52",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",