@fctc/sme-widget-ui 2.3.1 → 2.3.3

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
@@ -31996,6 +31996,8 @@ var FloatField = (props) => {
31996
31996
  const [inputValue, setInputValue] = (0, import_react58.useState)(
31997
31997
  value !== void 0 && value !== null ? formatFloatNumber(value) : ""
31998
31998
  );
31999
+ const isDirtyRef = (0, import_react58.useRef)(false);
32000
+ const lastCommittedValueRef = (0, import_react58.useRef)(null);
31999
32001
  (0, import_react58.useEffect)(() => {
32000
32002
  if (isDirtyRef.current) return;
32001
32003
  const numericInput = parseFloat(inputValue?.replace(/,/g, ""));
@@ -32009,42 +32011,33 @@ var FloatField = (props) => {
32009
32011
  setInputValue("");
32010
32012
  }
32011
32013
  }, [value, name2, clearErrors, propValue]);
32012
- const isDirtyRef = (0, import_react58.useRef)(false);
32013
- const inputRef = (0, import_react58.useRef)(null);
32014
- const lastCommittedValueRef = (0, import_react58.useRef)(null);
32015
32014
  const handleInputChange = (e3) => {
32016
- const newValue = e3.target.value;
32017
- const valueWithoutCommas = newValue.replace(/,/g, "");
32018
- if (/^[0-9]*[.,]?[0-9]*$/.test(valueWithoutCommas) || newValue === "") {
32019
- const parts = valueWithoutCommas.split(".");
32020
- let integerPart = parts[0] || "";
32021
- const decimalPart = parts[1] || "";
32022
- if (decimalPart.length > 100) return;
32023
- if (integerPart) {
32024
- integerPart = Number(integerPart).toLocaleString("en-US");
32025
- }
32026
- const formattedValue = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
32027
- setInputValue(formattedValue);
32028
- const parsedValue = parseFloat(valueWithoutCommas.replace(",", "."));
32029
- if (!isNaN(parsedValue)) {
32030
- if (parsedValue < 0) {
32031
- setError(name2, {
32032
- type: "validate",
32033
- message: t3("invalid_number")
32034
- });
32035
- } else {
32036
- onChange2(parsedValue);
32037
- clearErrors(name2);
32038
- isDirtyRef.current = true;
32039
- }
32040
- } else {
32041
- onChange2(null);
32042
- clearErrors(name2);
32043
- }
32015
+ let newValue = e3.target.value;
32016
+ if (!/^[0-9.,]*$/.test(newValue)) return;
32017
+ if (newValue === ".") {
32018
+ newValue = "0.";
32019
+ }
32020
+ if (inputValue.startsWith("0") && !inputValue?.includes(".")) {
32021
+ newValue = newValue.replace(/^0+/, "");
32022
+ console.log("newValue", newValue);
32023
+ }
32024
+ if (inputValue === "0" && newValue === "0.") {
32025
+ newValue = "0.";
32026
+ }
32027
+ setInputValue(newValue);
32028
+ const parsedValue = parseFloat(
32029
+ newValue.replace(/,/g, "").replace(",", ".")
32030
+ );
32031
+ if (!isNaN(parsedValue)) {
32032
+ onChange2(parsedValue);
32033
+ clearErrors(name2);
32034
+ isDirtyRef.current = true;
32035
+ } else {
32036
+ onChange2(null);
32044
32037
  }
32045
32038
  };
32046
32039
  const handleInputMouseLeave = () => {
32047
- if (isDirtyRef?.current === false) return;
32040
+ if (!isDirtyRef.current) return;
32048
32041
  const rawValue = inputValue.replace(/,/g, "");
32049
32042
  const parsedValue = parseFloat(rawValue);
32050
32043
  if (rawValue === "" || rawValue === ".") {
@@ -32066,18 +32059,12 @@ var FloatField = (props) => {
32066
32059
  setInputValue("");
32067
32060
  lastCommittedValueRef.current = null;
32068
32061
  } else {
32069
- if (lastCommittedValueRef.current !== parsedValue) {
32070
- const parts = rawValue.split(".");
32071
- let integerPart = parts[0];
32072
- const decimalPart = parts[1] || "";
32073
- integerPart = Number(integerPart).toLocaleString("en-US");
32074
- const formattedValue = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
32075
- onChange2(parsedValue);
32076
- setInputValue(formattedValue);
32077
- handleOnchange?.(name2 ?? "", parsedValue);
32078
- clearErrors(name2);
32079
- lastCommittedValueRef.current = parsedValue;
32080
- }
32062
+ const formattedValue = formatFloatNumber(parsedValue);
32063
+ setInputValue(formattedValue);
32064
+ onChange2(parsedValue);
32065
+ handleOnchange?.(name2 ?? "", parsedValue);
32066
+ clearErrors(name2);
32067
+ lastCommittedValueRef.current = parsedValue;
32081
32068
  }
32082
32069
  } else {
32083
32070
  setError(name2, {
@@ -32093,7 +32080,6 @@ var FloatField = (props) => {
32093
32080
  /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
32094
32081
  "input",
32095
32082
  {
32096
- ref: inputRef,
32097
32083
  value: inputValue,
32098
32084
  onChange: !readonly ? handleInputChange : void 0,
32099
32085
  onMouseLeave: !readonly ? handleInputMouseLeave : void 0,
@@ -32106,7 +32092,7 @@ var FloatField = (props) => {
32106
32092
  className: `w-full h-full ring-0 focus:ring-0 focus:!outline-none outline-0 px-3 py-[12px] text-sm font-normal gap-2 opacity-100 leading-[1.5] resize-none overflow-hidden
32107
32093
  ${readonly ? "cursor-not-allowed border border-[rgba(66,66,66,0.12)] text-[#5c5a5a]" : "cursor-pointer border border-[rgba(66,66,66,0.12)] text-[#525866]"}
32108
32094
  ${!isEditTable ? isForm ? "bg-white border-input-primary rounded-[10px]" : "" : `border-transparent bg-transparent ${readonly ? "" : "border-b-primary"}`}
32109
- ${error2 && isEditTable && "focus:border-b-[1px] focus:border-[#de4747] hover:border-b-[1px] hover:border-[#de4747]"}
32095
+ ${error2 && isEditTable && "focus:border-b-[1px] focus:border-[#de4747] hover:border-b-[1px] hover:border-[#de4747]"}
32110
32096
  `
32111
32097
  }
32112
32098
  ),
@@ -32606,7 +32592,8 @@ var MonetaryField = (props) => {
32606
32592
  formValues,
32607
32593
  widget,
32608
32594
  placeholder,
32609
- isEditTable
32595
+ isEditTable,
32596
+ symbol = "VND"
32610
32597
  } = props;
32611
32598
  if (isForm && name2 === "amount_residual") {
32612
32599
  return /* @__PURE__ */ (0, import_jsx_runtime96.jsxs)("div", { className: "flex justify-end gap-x-4 gap-y-2 ml-auto mt-2 lg:mt-5", children: [
@@ -32614,15 +32601,15 @@ var MonetaryField = (props) => {
32614
32601
  string,
32615
32602
  ":"
32616
32603
  ] }),
32617
- /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: "text-lg leading-[21px] font-semibold text-[rgb(73,80,87)] text-right", children: `${formatNumberOnly(parseFloat(value ?? defaultValue))} VND` })
32604
+ /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: "text-lg leading-[21px] font-semibold text-[rgb(73,80,87)] text-right", children: `${formatNumberOnly(parseFloat(value ?? defaultValue))} ${symbol}` })
32618
32605
  ] });
32619
32606
  }
32620
32607
  if (!isForm) {
32621
- const currencySymbol = widget === "monetary" ? formValues?.currency_id?.symbol : "VND";
32608
+ const currencySymbol = widget === "monetary" ? formValues?.currency_id?.symbol : symbol;
32622
32609
  if (widget === "monetary" && !formValues?.currency_id) {
32623
32610
  return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { children: `${formatNumberOnly(
32624
32611
  parseFloat(String(value ?? defaultValue))
32625
- )} VND` });
32612
+ )} ${symbol}` });
32626
32613
  }
32627
32614
  return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { children: `${formatNumberOnly(
32628
32615
  parseFloat(value ?? defaultValue)
package/dist/index.mjs CHANGED
@@ -31870,6 +31870,8 @@ var FloatField = (props) => {
31870
31870
  const [inputValue, setInputValue] = useState18(
31871
31871
  value !== void 0 && value !== null ? formatFloatNumber(value) : ""
31872
31872
  );
31873
+ const isDirtyRef = useRef15(false);
31874
+ const lastCommittedValueRef = useRef15(null);
31873
31875
  useEffect19(() => {
31874
31876
  if (isDirtyRef.current) return;
31875
31877
  const numericInput = parseFloat(inputValue?.replace(/,/g, ""));
@@ -31883,42 +31885,33 @@ var FloatField = (props) => {
31883
31885
  setInputValue("");
31884
31886
  }
31885
31887
  }, [value, name2, clearErrors, propValue]);
31886
- const isDirtyRef = useRef15(false);
31887
- const inputRef = useRef15(null);
31888
- const lastCommittedValueRef = useRef15(null);
31889
31888
  const handleInputChange = (e3) => {
31890
- const newValue = e3.target.value;
31891
- const valueWithoutCommas = newValue.replace(/,/g, "");
31892
- if (/^[0-9]*[.,]?[0-9]*$/.test(valueWithoutCommas) || newValue === "") {
31893
- const parts = valueWithoutCommas.split(".");
31894
- let integerPart = parts[0] || "";
31895
- const decimalPart = parts[1] || "";
31896
- if (decimalPart.length > 100) return;
31897
- if (integerPart) {
31898
- integerPart = Number(integerPart).toLocaleString("en-US");
31899
- }
31900
- const formattedValue = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
31901
- setInputValue(formattedValue);
31902
- const parsedValue = parseFloat(valueWithoutCommas.replace(",", "."));
31903
- if (!isNaN(parsedValue)) {
31904
- if (parsedValue < 0) {
31905
- setError(name2, {
31906
- type: "validate",
31907
- message: t3("invalid_number")
31908
- });
31909
- } else {
31910
- onChange2(parsedValue);
31911
- clearErrors(name2);
31912
- isDirtyRef.current = true;
31913
- }
31914
- } else {
31915
- onChange2(null);
31916
- clearErrors(name2);
31917
- }
31889
+ let newValue = e3.target.value;
31890
+ if (!/^[0-9.,]*$/.test(newValue)) return;
31891
+ if (newValue === ".") {
31892
+ newValue = "0.";
31893
+ }
31894
+ if (inputValue.startsWith("0") && !inputValue?.includes(".")) {
31895
+ newValue = newValue.replace(/^0+/, "");
31896
+ console.log("newValue", newValue);
31897
+ }
31898
+ if (inputValue === "0" && newValue === "0.") {
31899
+ newValue = "0.";
31900
+ }
31901
+ setInputValue(newValue);
31902
+ const parsedValue = parseFloat(
31903
+ newValue.replace(/,/g, "").replace(",", ".")
31904
+ );
31905
+ if (!isNaN(parsedValue)) {
31906
+ onChange2(parsedValue);
31907
+ clearErrors(name2);
31908
+ isDirtyRef.current = true;
31909
+ } else {
31910
+ onChange2(null);
31918
31911
  }
31919
31912
  };
31920
31913
  const handleInputMouseLeave = () => {
31921
- if (isDirtyRef?.current === false) return;
31914
+ if (!isDirtyRef.current) return;
31922
31915
  const rawValue = inputValue.replace(/,/g, "");
31923
31916
  const parsedValue = parseFloat(rawValue);
31924
31917
  if (rawValue === "" || rawValue === ".") {
@@ -31940,18 +31933,12 @@ var FloatField = (props) => {
31940
31933
  setInputValue("");
31941
31934
  lastCommittedValueRef.current = null;
31942
31935
  } else {
31943
- if (lastCommittedValueRef.current !== parsedValue) {
31944
- const parts = rawValue.split(".");
31945
- let integerPart = parts[0];
31946
- const decimalPart = parts[1] || "";
31947
- integerPart = Number(integerPart).toLocaleString("en-US");
31948
- const formattedValue = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
31949
- onChange2(parsedValue);
31950
- setInputValue(formattedValue);
31951
- handleOnchange?.(name2 ?? "", parsedValue);
31952
- clearErrors(name2);
31953
- lastCommittedValueRef.current = parsedValue;
31954
- }
31936
+ const formattedValue = formatFloatNumber(parsedValue);
31937
+ setInputValue(formattedValue);
31938
+ onChange2(parsedValue);
31939
+ handleOnchange?.(name2 ?? "", parsedValue);
31940
+ clearErrors(name2);
31941
+ lastCommittedValueRef.current = parsedValue;
31955
31942
  }
31956
31943
  } else {
31957
31944
  setError(name2, {
@@ -31967,7 +31954,6 @@ var FloatField = (props) => {
31967
31954
  /* @__PURE__ */ jsx92(
31968
31955
  "input",
31969
31956
  {
31970
- ref: inputRef,
31971
31957
  value: inputValue,
31972
31958
  onChange: !readonly ? handleInputChange : void 0,
31973
31959
  onMouseLeave: !readonly ? handleInputMouseLeave : void 0,
@@ -31980,7 +31966,7 @@ var FloatField = (props) => {
31980
31966
  className: `w-full h-full ring-0 focus:ring-0 focus:!outline-none outline-0 px-3 py-[12px] text-sm font-normal gap-2 opacity-100 leading-[1.5] resize-none overflow-hidden
31981
31967
  ${readonly ? "cursor-not-allowed border border-[rgba(66,66,66,0.12)] text-[#5c5a5a]" : "cursor-pointer border border-[rgba(66,66,66,0.12)] text-[#525866]"}
31982
31968
  ${!isEditTable ? isForm ? "bg-white border-input-primary rounded-[10px]" : "" : `border-transparent bg-transparent ${readonly ? "" : "border-b-primary"}`}
31983
- ${error2 && isEditTable && "focus:border-b-[1px] focus:border-[#de4747] hover:border-b-[1px] hover:border-[#de4747]"}
31969
+ ${error2 && isEditTable && "focus:border-b-[1px] focus:border-[#de4747] hover:border-b-[1px] hover:border-[#de4747]"}
31984
31970
  `
31985
31971
  }
31986
31972
  ),
@@ -32480,7 +32466,8 @@ var MonetaryField = (props) => {
32480
32466
  formValues,
32481
32467
  widget,
32482
32468
  placeholder,
32483
- isEditTable
32469
+ isEditTable,
32470
+ symbol = "VND"
32484
32471
  } = props;
32485
32472
  if (isForm && name2 === "amount_residual") {
32486
32473
  return /* @__PURE__ */ jsxs65("div", { className: "flex justify-end gap-x-4 gap-y-2 ml-auto mt-2 lg:mt-5", children: [
@@ -32488,15 +32475,15 @@ var MonetaryField = (props) => {
32488
32475
  string,
32489
32476
  ":"
32490
32477
  ] }),
32491
- /* @__PURE__ */ jsx98("span", { className: "text-lg leading-[21px] font-semibold text-[rgb(73,80,87)] text-right", children: `${formatNumberOnly(parseFloat(value ?? defaultValue))} VND` })
32478
+ /* @__PURE__ */ jsx98("span", { className: "text-lg leading-[21px] font-semibold text-[rgb(73,80,87)] text-right", children: `${formatNumberOnly(parseFloat(value ?? defaultValue))} ${symbol}` })
32492
32479
  ] });
32493
32480
  }
32494
32481
  if (!isForm) {
32495
- const currencySymbol = widget === "monetary" ? formValues?.currency_id?.symbol : "VND";
32482
+ const currencySymbol = widget === "monetary" ? formValues?.currency_id?.symbol : symbol;
32496
32483
  if (widget === "monetary" && !formValues?.currency_id) {
32497
32484
  return /* @__PURE__ */ jsx98("span", { children: `${formatNumberOnly(
32498
32485
  parseFloat(String(value ?? defaultValue))
32499
- )} VND` });
32486
+ )} ${symbol}` });
32500
32487
  }
32501
32488
  return /* @__PURE__ */ jsx98("span", { children: `${formatNumberOnly(
32502
32489
  parseFloat(value ?? defaultValue)
@@ -318,6 +318,7 @@ declare const Many2ManyTagField: (props: IMany2ManyTagsProps) => JSX.Element;
318
318
 
319
319
  interface IMonetaryProps extends IInputFieldProps {
320
320
  placeholder?: string;
321
+ symbol?: string;
321
322
  }
322
323
 
323
324
  declare const MonetaryField: (props: IMonetaryProps) => JSX.Element;
package/dist/widgets.d.ts CHANGED
@@ -318,6 +318,7 @@ declare const Many2ManyTagField: (props: IMany2ManyTagsProps) => JSX.Element;
318
318
 
319
319
  interface IMonetaryProps extends IInputFieldProps {
320
320
  placeholder?: string;
321
+ symbol?: string;
321
322
  }
322
323
 
323
324
  declare const MonetaryField: (props: IMonetaryProps) => JSX.Element;
package/dist/widgets.js CHANGED
@@ -31245,6 +31245,8 @@ var FloatField = (props) => {
31245
31245
  const [inputValue, setInputValue] = (0, import_react58.useState)(
31246
31246
  value !== void 0 && value !== null ? formatFloatNumber(value) : ""
31247
31247
  );
31248
+ const isDirtyRef = (0, import_react58.useRef)(false);
31249
+ const lastCommittedValueRef = (0, import_react58.useRef)(null);
31248
31250
  (0, import_react58.useEffect)(() => {
31249
31251
  if (isDirtyRef.current) return;
31250
31252
  const numericInput = parseFloat(inputValue?.replace(/,/g, ""));
@@ -31258,42 +31260,33 @@ var FloatField = (props) => {
31258
31260
  setInputValue("");
31259
31261
  }
31260
31262
  }, [value, name2, clearErrors, propValue]);
31261
- const isDirtyRef = (0, import_react58.useRef)(false);
31262
- const inputRef = (0, import_react58.useRef)(null);
31263
- const lastCommittedValueRef = (0, import_react58.useRef)(null);
31264
31263
  const handleInputChange = (e3) => {
31265
- const newValue = e3.target.value;
31266
- const valueWithoutCommas = newValue.replace(/,/g, "");
31267
- if (/^[0-9]*[.,]?[0-9]*$/.test(valueWithoutCommas) || newValue === "") {
31268
- const parts = valueWithoutCommas.split(".");
31269
- let integerPart = parts[0] || "";
31270
- const decimalPart = parts[1] || "";
31271
- if (decimalPart.length > 100) return;
31272
- if (integerPart) {
31273
- integerPart = Number(integerPart).toLocaleString("en-US");
31274
- }
31275
- const formattedValue = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
31276
- setInputValue(formattedValue);
31277
- const parsedValue = parseFloat(valueWithoutCommas.replace(",", "."));
31278
- if (!isNaN(parsedValue)) {
31279
- if (parsedValue < 0) {
31280
- setError(name2, {
31281
- type: "validate",
31282
- message: t3("invalid_number")
31283
- });
31284
- } else {
31285
- onChange2(parsedValue);
31286
- clearErrors(name2);
31287
- isDirtyRef.current = true;
31288
- }
31289
- } else {
31290
- onChange2(null);
31291
- clearErrors(name2);
31292
- }
31264
+ let newValue = e3.target.value;
31265
+ if (!/^[0-9.,]*$/.test(newValue)) return;
31266
+ if (newValue === ".") {
31267
+ newValue = "0.";
31268
+ }
31269
+ if (inputValue.startsWith("0") && !inputValue?.includes(".")) {
31270
+ newValue = newValue.replace(/^0+/, "");
31271
+ console.log("newValue", newValue);
31272
+ }
31273
+ if (inputValue === "0" && newValue === "0.") {
31274
+ newValue = "0.";
31275
+ }
31276
+ setInputValue(newValue);
31277
+ const parsedValue = parseFloat(
31278
+ newValue.replace(/,/g, "").replace(",", ".")
31279
+ );
31280
+ if (!isNaN(parsedValue)) {
31281
+ onChange2(parsedValue);
31282
+ clearErrors(name2);
31283
+ isDirtyRef.current = true;
31284
+ } else {
31285
+ onChange2(null);
31293
31286
  }
31294
31287
  };
31295
31288
  const handleInputMouseLeave = () => {
31296
- if (isDirtyRef?.current === false) return;
31289
+ if (!isDirtyRef.current) return;
31297
31290
  const rawValue = inputValue.replace(/,/g, "");
31298
31291
  const parsedValue = parseFloat(rawValue);
31299
31292
  if (rawValue === "" || rawValue === ".") {
@@ -31315,18 +31308,12 @@ var FloatField = (props) => {
31315
31308
  setInputValue("");
31316
31309
  lastCommittedValueRef.current = null;
31317
31310
  } else {
31318
- if (lastCommittedValueRef.current !== parsedValue) {
31319
- const parts = rawValue.split(".");
31320
- let integerPart = parts[0];
31321
- const decimalPart = parts[1] || "";
31322
- integerPart = Number(integerPart).toLocaleString("en-US");
31323
- const formattedValue = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
31324
- onChange2(parsedValue);
31325
- setInputValue(formattedValue);
31326
- handleOnchange?.(name2 ?? "", parsedValue);
31327
- clearErrors(name2);
31328
- lastCommittedValueRef.current = parsedValue;
31329
- }
31311
+ const formattedValue = formatFloatNumber(parsedValue);
31312
+ setInputValue(formattedValue);
31313
+ onChange2(parsedValue);
31314
+ handleOnchange?.(name2 ?? "", parsedValue);
31315
+ clearErrors(name2);
31316
+ lastCommittedValueRef.current = parsedValue;
31330
31317
  }
31331
31318
  } else {
31332
31319
  setError(name2, {
@@ -31342,7 +31329,6 @@ var FloatField = (props) => {
31342
31329
  /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
31343
31330
  "input",
31344
31331
  {
31345
- ref: inputRef,
31346
31332
  value: inputValue,
31347
31333
  onChange: !readonly ? handleInputChange : void 0,
31348
31334
  onMouseLeave: !readonly ? handleInputMouseLeave : void 0,
@@ -31355,7 +31341,7 @@ var FloatField = (props) => {
31355
31341
  className: `w-full h-full ring-0 focus:ring-0 focus:!outline-none outline-0 px-3 py-[12px] text-sm font-normal gap-2 opacity-100 leading-[1.5] resize-none overflow-hidden
31356
31342
  ${readonly ? "cursor-not-allowed border border-[rgba(66,66,66,0.12)] text-[#5c5a5a]" : "cursor-pointer border border-[rgba(66,66,66,0.12)] text-[#525866]"}
31357
31343
  ${!isEditTable ? isForm ? "bg-white border-input-primary rounded-[10px]" : "" : `border-transparent bg-transparent ${readonly ? "" : "border-b-primary"}`}
31358
- ${error2 && isEditTable && "focus:border-b-[1px] focus:border-[#de4747] hover:border-b-[1px] hover:border-[#de4747]"}
31344
+ ${error2 && isEditTable && "focus:border-b-[1px] focus:border-[#de4747] hover:border-b-[1px] hover:border-[#de4747]"}
31359
31345
  `
31360
31346
  }
31361
31347
  ),
@@ -31855,7 +31841,8 @@ var MonetaryField = (props) => {
31855
31841
  formValues,
31856
31842
  widget,
31857
31843
  placeholder,
31858
- isEditTable
31844
+ isEditTable,
31845
+ symbol = "VND"
31859
31846
  } = props;
31860
31847
  if (isForm && name2 === "amount_residual") {
31861
31848
  return /* @__PURE__ */ (0, import_jsx_runtime96.jsxs)("div", { className: "flex justify-end gap-x-4 gap-y-2 ml-auto mt-2 lg:mt-5", children: [
@@ -31863,15 +31850,15 @@ var MonetaryField = (props) => {
31863
31850
  string,
31864
31851
  ":"
31865
31852
  ] }),
31866
- /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: "text-lg leading-[21px] font-semibold text-[rgb(73,80,87)] text-right", children: `${formatNumberOnly(parseFloat(value ?? defaultValue))} VND` })
31853
+ /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: "text-lg leading-[21px] font-semibold text-[rgb(73,80,87)] text-right", children: `${formatNumberOnly(parseFloat(value ?? defaultValue))} ${symbol}` })
31867
31854
  ] });
31868
31855
  }
31869
31856
  if (!isForm) {
31870
- const currencySymbol = widget === "monetary" ? formValues?.currency_id?.symbol : "VND";
31857
+ const currencySymbol = widget === "monetary" ? formValues?.currency_id?.symbol : symbol;
31871
31858
  if (widget === "monetary" && !formValues?.currency_id) {
31872
31859
  return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { children: `${formatNumberOnly(
31873
31860
  parseFloat(String(value ?? defaultValue))
31874
- )} VND` });
31861
+ )} ${symbol}` });
31875
31862
  }
31876
31863
  return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { children: `${formatNumberOnly(
31877
31864
  parseFloat(value ?? defaultValue)
package/dist/widgets.mjs CHANGED
@@ -31183,6 +31183,8 @@ var FloatField = (props) => {
31183
31183
  const [inputValue, setInputValue] = useState18(
31184
31184
  value !== void 0 && value !== null ? formatFloatNumber(value) : ""
31185
31185
  );
31186
+ const isDirtyRef = useRef15(false);
31187
+ const lastCommittedValueRef = useRef15(null);
31186
31188
  useEffect19(() => {
31187
31189
  if (isDirtyRef.current) return;
31188
31190
  const numericInput = parseFloat(inputValue?.replace(/,/g, ""));
@@ -31196,42 +31198,33 @@ var FloatField = (props) => {
31196
31198
  setInputValue("");
31197
31199
  }
31198
31200
  }, [value, name2, clearErrors, propValue]);
31199
- const isDirtyRef = useRef15(false);
31200
- const inputRef = useRef15(null);
31201
- const lastCommittedValueRef = useRef15(null);
31202
31201
  const handleInputChange = (e3) => {
31203
- const newValue = e3.target.value;
31204
- const valueWithoutCommas = newValue.replace(/,/g, "");
31205
- if (/^[0-9]*[.,]?[0-9]*$/.test(valueWithoutCommas) || newValue === "") {
31206
- const parts = valueWithoutCommas.split(".");
31207
- let integerPart = parts[0] || "";
31208
- const decimalPart = parts[1] || "";
31209
- if (decimalPart.length > 100) return;
31210
- if (integerPart) {
31211
- integerPart = Number(integerPart).toLocaleString("en-US");
31212
- }
31213
- const formattedValue = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
31214
- setInputValue(formattedValue);
31215
- const parsedValue = parseFloat(valueWithoutCommas.replace(",", "."));
31216
- if (!isNaN(parsedValue)) {
31217
- if (parsedValue < 0) {
31218
- setError(name2, {
31219
- type: "validate",
31220
- message: t3("invalid_number")
31221
- });
31222
- } else {
31223
- onChange2(parsedValue);
31224
- clearErrors(name2);
31225
- isDirtyRef.current = true;
31226
- }
31227
- } else {
31228
- onChange2(null);
31229
- clearErrors(name2);
31230
- }
31202
+ let newValue = e3.target.value;
31203
+ if (!/^[0-9.,]*$/.test(newValue)) return;
31204
+ if (newValue === ".") {
31205
+ newValue = "0.";
31206
+ }
31207
+ if (inputValue.startsWith("0") && !inputValue?.includes(".")) {
31208
+ newValue = newValue.replace(/^0+/, "");
31209
+ console.log("newValue", newValue);
31210
+ }
31211
+ if (inputValue === "0" && newValue === "0.") {
31212
+ newValue = "0.";
31213
+ }
31214
+ setInputValue(newValue);
31215
+ const parsedValue = parseFloat(
31216
+ newValue.replace(/,/g, "").replace(",", ".")
31217
+ );
31218
+ if (!isNaN(parsedValue)) {
31219
+ onChange2(parsedValue);
31220
+ clearErrors(name2);
31221
+ isDirtyRef.current = true;
31222
+ } else {
31223
+ onChange2(null);
31231
31224
  }
31232
31225
  };
31233
31226
  const handleInputMouseLeave = () => {
31234
- if (isDirtyRef?.current === false) return;
31227
+ if (!isDirtyRef.current) return;
31235
31228
  const rawValue = inputValue.replace(/,/g, "");
31236
31229
  const parsedValue = parseFloat(rawValue);
31237
31230
  if (rawValue === "" || rawValue === ".") {
@@ -31253,18 +31246,12 @@ var FloatField = (props) => {
31253
31246
  setInputValue("");
31254
31247
  lastCommittedValueRef.current = null;
31255
31248
  } else {
31256
- if (lastCommittedValueRef.current !== parsedValue) {
31257
- const parts = rawValue.split(".");
31258
- let integerPart = parts[0];
31259
- const decimalPart = parts[1] || "";
31260
- integerPart = Number(integerPart).toLocaleString("en-US");
31261
- const formattedValue = decimalPart ? `${integerPart}.${decimalPart}` : integerPart;
31262
- onChange2(parsedValue);
31263
- setInputValue(formattedValue);
31264
- handleOnchange?.(name2 ?? "", parsedValue);
31265
- clearErrors(name2);
31266
- lastCommittedValueRef.current = parsedValue;
31267
- }
31249
+ const formattedValue = formatFloatNumber(parsedValue);
31250
+ setInputValue(formattedValue);
31251
+ onChange2(parsedValue);
31252
+ handleOnchange?.(name2 ?? "", parsedValue);
31253
+ clearErrors(name2);
31254
+ lastCommittedValueRef.current = parsedValue;
31268
31255
  }
31269
31256
  } else {
31270
31257
  setError(name2, {
@@ -31280,7 +31267,6 @@ var FloatField = (props) => {
31280
31267
  /* @__PURE__ */ jsx92(
31281
31268
  "input",
31282
31269
  {
31283
- ref: inputRef,
31284
31270
  value: inputValue,
31285
31271
  onChange: !readonly ? handleInputChange : void 0,
31286
31272
  onMouseLeave: !readonly ? handleInputMouseLeave : void 0,
@@ -31293,7 +31279,7 @@ var FloatField = (props) => {
31293
31279
  className: `w-full h-full ring-0 focus:ring-0 focus:!outline-none outline-0 px-3 py-[12px] text-sm font-normal gap-2 opacity-100 leading-[1.5] resize-none overflow-hidden
31294
31280
  ${readonly ? "cursor-not-allowed border border-[rgba(66,66,66,0.12)] text-[#5c5a5a]" : "cursor-pointer border border-[rgba(66,66,66,0.12)] text-[#525866]"}
31295
31281
  ${!isEditTable ? isForm ? "bg-white border-input-primary rounded-[10px]" : "" : `border-transparent bg-transparent ${readonly ? "" : "border-b-primary"}`}
31296
- ${error2 && isEditTable && "focus:border-b-[1px] focus:border-[#de4747] hover:border-b-[1px] hover:border-[#de4747]"}
31282
+ ${error2 && isEditTable && "focus:border-b-[1px] focus:border-[#de4747] hover:border-b-[1px] hover:border-[#de4747]"}
31297
31283
  `
31298
31284
  }
31299
31285
  ),
@@ -31793,7 +31779,8 @@ var MonetaryField = (props) => {
31793
31779
  formValues,
31794
31780
  widget,
31795
31781
  placeholder,
31796
- isEditTable
31782
+ isEditTable,
31783
+ symbol = "VND"
31797
31784
  } = props;
31798
31785
  if (isForm && name2 === "amount_residual") {
31799
31786
  return /* @__PURE__ */ jsxs65("div", { className: "flex justify-end gap-x-4 gap-y-2 ml-auto mt-2 lg:mt-5", children: [
@@ -31801,15 +31788,15 @@ var MonetaryField = (props) => {
31801
31788
  string,
31802
31789
  ":"
31803
31790
  ] }),
31804
- /* @__PURE__ */ jsx98("span", { className: "text-lg leading-[21px] font-semibold text-[rgb(73,80,87)] text-right", children: `${formatNumberOnly(parseFloat(value ?? defaultValue))} VND` })
31791
+ /* @__PURE__ */ jsx98("span", { className: "text-lg leading-[21px] font-semibold text-[rgb(73,80,87)] text-right", children: `${formatNumberOnly(parseFloat(value ?? defaultValue))} ${symbol}` })
31805
31792
  ] });
31806
31793
  }
31807
31794
  if (!isForm) {
31808
- const currencySymbol = widget === "monetary" ? formValues?.currency_id?.symbol : "VND";
31795
+ const currencySymbol = widget === "monetary" ? formValues?.currency_id?.symbol : symbol;
31809
31796
  if (widget === "monetary" && !formValues?.currency_id) {
31810
31797
  return /* @__PURE__ */ jsx98("span", { children: `${formatNumberOnly(
31811
31798
  parseFloat(String(value ?? defaultValue))
31812
- )} VND` });
31799
+ )} ${symbol}` });
31813
31800
  }
31814
31801
  return /* @__PURE__ */ jsx98("span", { children: `${formatNumberOnly(
31815
31802
  parseFloat(value ?? defaultValue)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/sme-widget-ui",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",