@lets-events/react 12.10.5 → 12.10.7

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- > @lets-events/react@12.10.5 build
3
+ > @lets-events/react@12.10.7 build
4
4
  > tsup src/index.tsx --format esm,cjs --dts --external react
5
5
 
6
6
  CLI Building entry: src/index.tsx
@@ -10,12 +10,12 @@
10
10
  CLI Target: es6
11
11
  ESM Build start
12
12
  CJS Build start
13
- ESM dist/index.mjs 413.82 KB
14
- ESM ⚡️ Build success in 395ms
15
- CJS dist/index.js 429.48 KB
16
- CJS ⚡️ Build success in 395ms
13
+ ESM dist/index.mjs 415.81 KB
14
+ ESM ⚡️ Build success in 569ms
15
+ CJS dist/index.js 431.44 KB
16
+ CJS ⚡️ Build success in 570ms
17
17
  DTS Build start
18
- DTS ⚡️ Build success in 8590ms
18
+ DTS ⚡️ Build success in 58622ms
19
19
  DTS dist/index.d.mts 405.26 KB
20
20
  DTS dist/index.d.ts 405.26 KB
21
21
  ⠙
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @lets-events/react
2
2
 
3
+ ## 12.10.7
4
+
5
+ ### Patch Changes
6
+
7
+ - update counter at initial values
8
+
9
+ ## 12.10.6
10
+
11
+ ### Patch Changes
12
+
13
+ - RichEditorFormField props
14
+
3
15
  ## 12.10.5
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -2812,7 +2812,10 @@ var TextField = import_react3.default.forwardRef(
2812
2812
  textAlign = "left",
2813
2813
  mask,
2814
2814
  maxLength,
2815
- hasError
2815
+ hasError,
2816
+ value,
2817
+ defaultValue,
2818
+ onInput
2816
2819
  } = _b, props = __objRest(_b, [
2817
2820
  "children",
2818
2821
  "isValid",
@@ -2824,21 +2827,58 @@ var TextField = import_react3.default.forwardRef(
2824
2827
  "textAlign",
2825
2828
  "mask",
2826
2829
  "maxLength",
2827
- "hasError"
2830
+ "hasError",
2831
+ "value",
2832
+ "defaultValue",
2833
+ "onInput"
2828
2834
  ]);
2835
+ const _a2 = props, { ref: propRef } = _a2, restProps = __objRest(_a2, ["ref"]);
2829
2836
  const maskRef = mask ? (0, import_mask.useMask)(mask) : void 0;
2830
2837
  const inputRef = import_react3.default.useRef(null);
2831
- const badgeRef = import_react3.default.useRef(null);
2832
- const updateCharCountBadge = () => {
2833
- var _a2, _b2;
2834
- if (!maxLength || !badgeRef.current) return;
2835
- const currentLength = (_b2 = (_a2 = inputRef.current) == null ? void 0 : _a2.value.length) != null ? _b2 : 0;
2836
- badgeRef.current.textContent = String(maxLength - currentLength);
2838
+ const getTextLength = (text) => String(text != null ? text : "").length;
2839
+ const updateRemaining = (currentLength) => {
2840
+ if (maxLength !== void 0) {
2841
+ setRemaining(maxLength - currentLength);
2842
+ }
2843
+ };
2844
+ const getCurrentLength = (inputElement) => {
2845
+ var _a3, _b2, _c;
2846
+ if (value !== void 0 && value !== null) {
2847
+ return getTextLength(value);
2848
+ }
2849
+ return (_c = (_b2 = inputElement == null ? void 0 : inputElement.value.length) != null ? _b2 : (_a3 = inputRef.current) == null ? void 0 : _a3.value.length) != null ? _c : getTextLength(defaultValue);
2850
+ };
2851
+ const [remaining, setRemaining] = (0, import_react3.useState)(
2852
+ () => maxLength !== void 0 ? maxLength - getTextLength(value != null ? value : defaultValue) : 0
2853
+ );
2854
+ (0, import_react3.useLayoutEffect)(() => {
2855
+ if (maxLength === void 0) return;
2856
+ updateRemaining(getCurrentLength());
2857
+ }, [maxLength, value, defaultValue]);
2858
+ const assignRef = (element) => {
2859
+ inputRef.current = element;
2860
+ if (maskRef && element) {
2861
+ maskRef.current = element;
2862
+ }
2863
+ if (typeof propRef === "function") {
2864
+ propRef(element);
2865
+ } else if (propRef) {
2866
+ propRef.current = element;
2867
+ }
2868
+ if (typeof fowardedRef === "function") {
2869
+ fowardedRef(element);
2870
+ } else if (fowardedRef) {
2871
+ fowardedRef.current = element;
2872
+ }
2873
+ if (element && maxLength !== void 0) {
2874
+ updateRemaining(getCurrentLength(element));
2875
+ }
2837
2876
  };
2838
2877
  const handleInput = (e) => {
2839
- var _a2;
2840
- updateCharCountBadge();
2841
- (_a2 = props.onInput) == null ? void 0 : _a2.call(props, e);
2878
+ if (maxLength !== void 0) {
2879
+ updateRemaining(e.currentTarget.value.length);
2880
+ }
2881
+ onInput == null ? void 0 : onInput(e);
2842
2882
  };
2843
2883
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Flex, { direction: "column", css: { width: "100%", position: "relative" }, children: [
2844
2884
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Flex, { gap: "0", css: { width: "100%" }, children: [
@@ -2852,7 +2892,7 @@ var TextField = import_react3.default.forwardRef(
2852
2892
  ),
2853
2893
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2854
2894
  TextFieldStyled,
2855
- __spreadProps(__spreadValues({
2895
+ __spreadProps(__spreadValues({}, restProps), {
2856
2896
  color: hasError ? "error" : color || "default",
2857
2897
  isValid: isValid2,
2858
2898
  name,
@@ -2860,17 +2900,10 @@ var TextField = import_react3.default.forwardRef(
2860
2900
  fontWeight,
2861
2901
  textAlign,
2862
2902
  maxLength,
2863
- ref: (r) => {
2864
- if (!r) return;
2865
- inputRef.current = r;
2866
- if (maskRef) maskRef.current = r;
2867
- if (fowardedRef) {
2868
- if (typeof fowardedRef === "function") fowardedRef(r);
2869
- else fowardedRef.current = r;
2870
- }
2871
- },
2872
- onInput: handleInput
2873
- }, props), {
2903
+ ref: assignRef,
2904
+ onInput: handleInput,
2905
+ value,
2906
+ defaultValue,
2874
2907
  style: addon ? {
2875
2908
  borderTopLeftRadius: "0px",
2876
2909
  borderBottomLeftRadius: "0px"
@@ -2893,7 +2926,7 @@ var TextField = import_react3.default.forwardRef(
2893
2926
  })
2894
2927
  )
2895
2928
  ] }),
2896
- maxLength && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextFieldLimitIndicator, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { ref: badgeRef, children: maxLength }) })
2929
+ maxLength && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextFieldLimitIndicator, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: remaining }) })
2897
2930
  ] });
2898
2931
  }
2899
2932
  );
@@ -13128,7 +13161,8 @@ var QuillComponent = ({
13128
13161
  [disabled, quill, addToast, removeToast, uploadConfig, onChange]
13129
13162
  );
13130
13163
  (0, import_react23.useEffect)(() => {
13131
- if (quill && value) {
13164
+ if (!quill) return;
13165
+ if (value !== void 0 && value !== null) {
13132
13166
  const currentContent = quill.root.innerHTML;
13133
13167
  if (currentContent !== value) {
13134
13168
  const selection = quill.getSelection();
@@ -13140,7 +13174,8 @@ var QuillComponent = ({
13140
13174
  }
13141
13175
  }
13142
13176
  }
13143
- }, [quill, value]);
13177
+ onCharacterCountChange == null ? void 0 : onCharacterCountChange(quill.getText().trim().length);
13178
+ }, [quill, value, onCharacterCountChange]);
13144
13179
  (0, import_react23.useEffect)(() => {
13145
13180
  if (quill) {
13146
13181
  quill.on("text-change", (delta, oldDelta, source) => {
@@ -13456,6 +13491,19 @@ var RichTextPresenter_default = RichTextPresenter;
13456
13491
  // src/components/FormFields/RichEditorFormField.tsx
13457
13492
  var import_react25 = require("react");
13458
13493
  var import_jsx_runtime56 = require("react/jsx-runtime");
13494
+ var getPlainTextLengthFromHtml = (html) => {
13495
+ var _a, _b;
13496
+ if (!html.trim()) return 0;
13497
+ if (typeof document === "undefined") {
13498
+ return html.replace(/<[^>]*>/g, "").trim().length;
13499
+ }
13500
+ const doc = new DOMParser().parseFromString(html, "text/html");
13501
+ return (_b = (_a = doc.body.textContent) == null ? void 0 : _a.trim().length) != null ? _b : 0;
13502
+ };
13503
+ var getRemainingCharacters = (maxLength, value) => {
13504
+ if (maxLength === void 0) return maxLength;
13505
+ return Math.max(0, maxLength - getPlainTextLengthFromHtml(value != null ? value : ""));
13506
+ };
13459
13507
  var RichEditorFormField = (_a) => {
13460
13508
  var _b = _a, {
13461
13509
  name,
@@ -13488,15 +13536,19 @@ var RichEditorFormField = (_a) => {
13488
13536
  return true;
13489
13537
  return (_a2 = validate == null ? void 0 : validate(value)) != null ? _a2 : true;
13490
13538
  }
13491
- },
13492
- defaultValue: ""
13539
+ }
13493
13540
  });
13494
- const [caracterQuantity, setCaracterQuantity] = (0, import_react25.useState)(maxLength);
13541
+ const [caracterQuantity, setCaracterQuantity] = (0, import_react25.useState)(
13542
+ () => getRemainingCharacters(maxLength, field.value)
13543
+ );
13495
13544
  const handleCharacterCountChange = (count) => {
13496
13545
  if (maxLength !== void 0) {
13497
13546
  setCaracterQuantity(Math.max(0, maxLength - count));
13498
13547
  }
13499
13548
  };
13549
+ (0, import_react25.useEffect)(() => {
13550
+ setCaracterQuantity(getRemainingCharacters(maxLength, field.value));
13551
+ }, [field.value, maxLength]);
13500
13552
  const fieldError = fieldState.error;
13501
13553
  const haveError = !!fieldError;
13502
13554
  const errorMsg = fieldError == null ? void 0 : fieldError.message;
@@ -13530,7 +13582,8 @@ var RichEditorFormField = (_a) => {
13530
13582
  onCharacterCountChange: handleCharacterCountChange,
13531
13583
  maxLength,
13532
13584
  disableVideo,
13533
- simpleVersion
13585
+ simpleVersion,
13586
+ richEditorElements
13534
13587
  })
13535
13588
  ),
13536
13589
  /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(ErrorFormMessage, { message: errorMsg })
package/dist/index.mjs CHANGED
@@ -2484,7 +2484,7 @@ function Avatar(_a) {
2484
2484
  }
2485
2485
 
2486
2486
  // src/components/TextField.tsx
2487
- import React from "react";
2487
+ import React, { useLayoutEffect, useState } from "react";
2488
2488
  import { TextField as TextFieldRadix } from "@radix-ui/themes";
2489
2489
  import { format, useMask, unformat } from "@react-input/mask";
2490
2490
  import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
@@ -2691,7 +2691,10 @@ var TextField = React.forwardRef(
2691
2691
  textAlign = "left",
2692
2692
  mask,
2693
2693
  maxLength,
2694
- hasError
2694
+ hasError,
2695
+ value,
2696
+ defaultValue,
2697
+ onInput
2695
2698
  } = _b, props = __objRest(_b, [
2696
2699
  "children",
2697
2700
  "isValid",
@@ -2703,21 +2706,58 @@ var TextField = React.forwardRef(
2703
2706
  "textAlign",
2704
2707
  "mask",
2705
2708
  "maxLength",
2706
- "hasError"
2709
+ "hasError",
2710
+ "value",
2711
+ "defaultValue",
2712
+ "onInput"
2707
2713
  ]);
2714
+ const _a2 = props, { ref: propRef } = _a2, restProps = __objRest(_a2, ["ref"]);
2708
2715
  const maskRef = mask ? useMask(mask) : void 0;
2709
2716
  const inputRef = React.useRef(null);
2710
- const badgeRef = React.useRef(null);
2711
- const updateCharCountBadge = () => {
2712
- var _a2, _b2;
2713
- if (!maxLength || !badgeRef.current) return;
2714
- const currentLength = (_b2 = (_a2 = inputRef.current) == null ? void 0 : _a2.value.length) != null ? _b2 : 0;
2715
- badgeRef.current.textContent = String(maxLength - currentLength);
2717
+ const getTextLength = (text) => String(text != null ? text : "").length;
2718
+ const updateRemaining = (currentLength) => {
2719
+ if (maxLength !== void 0) {
2720
+ setRemaining(maxLength - currentLength);
2721
+ }
2722
+ };
2723
+ const getCurrentLength = (inputElement) => {
2724
+ var _a3, _b2, _c;
2725
+ if (value !== void 0 && value !== null) {
2726
+ return getTextLength(value);
2727
+ }
2728
+ return (_c = (_b2 = inputElement == null ? void 0 : inputElement.value.length) != null ? _b2 : (_a3 = inputRef.current) == null ? void 0 : _a3.value.length) != null ? _c : getTextLength(defaultValue);
2729
+ };
2730
+ const [remaining, setRemaining] = useState(
2731
+ () => maxLength !== void 0 ? maxLength - getTextLength(value != null ? value : defaultValue) : 0
2732
+ );
2733
+ useLayoutEffect(() => {
2734
+ if (maxLength === void 0) return;
2735
+ updateRemaining(getCurrentLength());
2736
+ }, [maxLength, value, defaultValue]);
2737
+ const assignRef = (element) => {
2738
+ inputRef.current = element;
2739
+ if (maskRef && element) {
2740
+ maskRef.current = element;
2741
+ }
2742
+ if (typeof propRef === "function") {
2743
+ propRef(element);
2744
+ } else if (propRef) {
2745
+ propRef.current = element;
2746
+ }
2747
+ if (typeof fowardedRef === "function") {
2748
+ fowardedRef(element);
2749
+ } else if (fowardedRef) {
2750
+ fowardedRef.current = element;
2751
+ }
2752
+ if (element && maxLength !== void 0) {
2753
+ updateRemaining(getCurrentLength(element));
2754
+ }
2716
2755
  };
2717
2756
  const handleInput = (e) => {
2718
- var _a2;
2719
- updateCharCountBadge();
2720
- (_a2 = props.onInput) == null ? void 0 : _a2.call(props, e);
2757
+ if (maxLength !== void 0) {
2758
+ updateRemaining(e.currentTarget.value.length);
2759
+ }
2760
+ onInput == null ? void 0 : onInput(e);
2721
2761
  };
2722
2762
  return /* @__PURE__ */ jsxs2(Flex, { direction: "column", css: { width: "100%", position: "relative" }, children: [
2723
2763
  /* @__PURE__ */ jsxs2(Flex, { gap: "0", css: { width: "100%" }, children: [
@@ -2731,7 +2771,7 @@ var TextField = React.forwardRef(
2731
2771
  ),
2732
2772
  /* @__PURE__ */ jsxs2(
2733
2773
  TextFieldStyled,
2734
- __spreadProps(__spreadValues({
2774
+ __spreadProps(__spreadValues({}, restProps), {
2735
2775
  color: hasError ? "error" : color || "default",
2736
2776
  isValid: isValid2,
2737
2777
  name,
@@ -2739,17 +2779,10 @@ var TextField = React.forwardRef(
2739
2779
  fontWeight,
2740
2780
  textAlign,
2741
2781
  maxLength,
2742
- ref: (r) => {
2743
- if (!r) return;
2744
- inputRef.current = r;
2745
- if (maskRef) maskRef.current = r;
2746
- if (fowardedRef) {
2747
- if (typeof fowardedRef === "function") fowardedRef(r);
2748
- else fowardedRef.current = r;
2749
- }
2750
- },
2751
- onInput: handleInput
2752
- }, props), {
2782
+ ref: assignRef,
2783
+ onInput: handleInput,
2784
+ value,
2785
+ defaultValue,
2753
2786
  style: addon ? {
2754
2787
  borderTopLeftRadius: "0px",
2755
2788
  borderBottomLeftRadius: "0px"
@@ -2772,7 +2805,7 @@ var TextField = React.forwardRef(
2772
2805
  })
2773
2806
  )
2774
2807
  ] }),
2775
- maxLength && /* @__PURE__ */ jsx7(TextFieldLimitIndicator, { children: /* @__PURE__ */ jsx7("span", { ref: badgeRef, children: maxLength }) })
2808
+ maxLength && /* @__PURE__ */ jsx7(TextFieldLimitIndicator, { children: /* @__PURE__ */ jsx7("span", { children: remaining }) })
2776
2809
  ] });
2777
2810
  }
2778
2811
  );
@@ -3301,7 +3334,7 @@ function FilterItem(_a) {
3301
3334
 
3302
3335
  // src/components/Dropdown.tsx
3303
3336
  import React2, {
3304
- useState,
3337
+ useState as useState2,
3305
3338
  useRef,
3306
3339
  useEffect
3307
3340
  } from "react";
@@ -3435,7 +3468,7 @@ function DropdownMenu2(_a) {
3435
3468
  "onOpenChange",
3436
3469
  "defaultOpen"
3437
3470
  ]);
3438
- const [internalOpen, setInternalOpen] = useState(defaultOpen);
3471
+ const [internalOpen, setInternalOpen] = useState2(defaultOpen);
3439
3472
  const dropdownRef = useRef(null);
3440
3473
  const isControlled = controlledOpen !== void 0;
3441
3474
  const isOpen = isControlled ? controlledOpen : internalOpen;
@@ -3859,7 +3892,7 @@ function MenuDropdown({
3859
3892
  }
3860
3893
 
3861
3894
  // src/components/Calendar/index.tsx
3862
- import { useRef as useRef3, useEffect as useEffect3, useState as useState2 } from "react";
3895
+ import { useRef as useRef3, useEffect as useEffect3, useState as useState3 } from "react";
3863
3896
  import { DayPicker } from "react-day-picker";
3864
3897
 
3865
3898
  // ../../node_modules/date-fns/locale/_lib/buildFormatLongFn.js
@@ -8255,8 +8288,8 @@ function Calendar(_a) {
8255
8288
  "maxYearsFromNow",
8256
8289
  "disabled"
8257
8290
  ]);
8258
- const [inputValue, setInputValue] = useState2("");
8259
- const [showContainer, setShowCalendar] = useState2(false);
8291
+ const [inputValue, setInputValue] = useState3("");
8292
+ const [showContainer, setShowCalendar] = useState3(false);
8260
8293
  const dropdownRef = useRef3(null);
8261
8294
  useOnClickOutside(dropdownRef, () => {
8262
8295
  setShowCalendar(false);
@@ -8352,7 +8385,7 @@ function Calendar(_a) {
8352
8385
  }
8353
8386
 
8354
8387
  // src/components/DoubleCalendar/index.tsx
8355
- import { useRef as useRef4, useEffect as useEffect4, useState as useState3 } from "react";
8388
+ import { useRef as useRef4, useEffect as useEffect4, useState as useState4 } from "react";
8356
8389
  import { DayPicker as DayPicker2 } from "react-day-picker";
8357
8390
  import { jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
8358
8391
  function DoubleCalendar(_a) {
@@ -8385,9 +8418,9 @@ function DoubleCalendar(_a) {
8385
8418
  "maxDate",
8386
8419
  "disabled"
8387
8420
  ]);
8388
- const [startValue, setStartValue] = useState3("");
8389
- const [endValue, setEndValue] = useState3("");
8390
- const [showContainer, setShowCalendar] = useState3(false);
8421
+ const [startValue, setStartValue] = useState4("");
8422
+ const [endValue, setEndValue] = useState4("");
8423
+ const [showContainer, setShowCalendar] = useState4(false);
8391
8424
  const initialSelectedRef = useRef4(void 0);
8392
8425
  const dropdownRef = useRef4(null);
8393
8426
  useOnClickOutside(dropdownRef, () => {
@@ -8684,7 +8717,7 @@ function Drawer({
8684
8717
  }
8685
8718
 
8686
8719
  // src/components/TimePicker.tsx
8687
- import { useCallback, useEffect as useEffect6, useRef as useRef6, useState as useState4 } from "react";
8720
+ import { useCallback, useEffect as useEffect6, useRef as useRef6, useState as useState5 } from "react";
8688
8721
  import { jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
8689
8722
  var TimePickerStyled = styled("div", {
8690
8723
  position: "relative",
@@ -8823,11 +8856,11 @@ function TimePicker({
8823
8856
  expand = false,
8824
8857
  disabled = false
8825
8858
  }) {
8826
- const [hours, setHours] = useState4("00");
8827
- const [minutes, setMinutes] = useState4("00");
8828
- const [rawHours, setRawHours] = useState4("00");
8829
- const [rawMinutes, setRawMinutes] = useState4("00");
8830
- const [isOpen, setIsOpen] = useState4(false);
8859
+ const [hours, setHours] = useState5("00");
8860
+ const [minutes, setMinutes] = useState5("00");
8861
+ const [rawHours, setRawHours] = useState5("00");
8862
+ const [rawMinutes, setRawMinutes] = useState5("00");
8863
+ const [isOpen, setIsOpen] = useState5(false);
8831
8864
  const dropdownRef = useRef6(null);
8832
8865
  useOnClickOutside(dropdownRef, () => setIsOpen(false));
8833
8866
  useEffect6(() => {
@@ -9571,7 +9604,7 @@ function Card(_a) {
9571
9604
 
9572
9605
  // src/components/TextareaField.tsx
9573
9606
  import { TextArea as TextAreaRadix } from "@radix-ui/themes";
9574
- import React9, { useRef as useRef7, useState as useState5, useEffect as useEffect7 } from "react";
9607
+ import React9, { useRef as useRef7, useState as useState6, useEffect as useEffect7 } from "react";
9575
9608
  import { jsx as jsx23, jsxs as jsxs12 } from "react/jsx-runtime";
9576
9609
  var TextareaFieldStyle = styled(TextAreaRadix, {
9577
9610
  display: "flex",
@@ -9625,7 +9658,7 @@ var TextareaContainer = styled("div", {
9625
9658
  var TextareaField = React9.forwardRef((_a, forwardedRef) => {
9626
9659
  var _b = _a, { maxLength, color, top = "-1.75rem" } = _b, props = __objRest(_b, ["maxLength", "color", "top"]);
9627
9660
  const inputRef = useRef7(null);
9628
- const [remaining, setRemaining] = useState5(maxLength);
9661
+ const [remaining, setRemaining] = useState6(maxLength);
9629
9662
  useEffect7(() => {
9630
9663
  var _a2;
9631
9664
  if (maxLength && inputRef.current) {
@@ -9661,7 +9694,7 @@ var TextareaField = React9.forwardRef((_a, forwardedRef) => {
9661
9694
  });
9662
9695
 
9663
9696
  // src/components/Toast/components/ToastItem.tsx
9664
- import { useState as useState6 } from "react";
9697
+ import { useState as useState7 } from "react";
9665
9698
 
9666
9699
  // src/components/Toast/styles/index.ts
9667
9700
  import { keyframes as keyframes2 } from "@stitches/react";
@@ -9792,7 +9825,7 @@ function ToastItem({
9792
9825
  toast,
9793
9826
  onRemove
9794
9827
  }) {
9795
- const [open, setOpen] = useState6(true);
9828
+ const [open, setOpen] = useState7(true);
9796
9829
  const handleOpenChange = (open2) => {
9797
9830
  setOpen(open2);
9798
9831
  if (!open2) {
@@ -9816,7 +9849,7 @@ function ToastItem({
9816
9849
  }
9817
9850
 
9818
9851
  // src/components/Toast/components/ToastProvider.tsx
9819
- import { createContext, useState as useState7 } from "react";
9852
+ import { createContext, useState as useState8 } from "react";
9820
9853
  import * as ToastPrimitive2 from "@radix-ui/react-toast";
9821
9854
  import { jsx as jsx25, jsxs as jsxs14 } from "react/jsx-runtime";
9822
9855
  var ToastContext = createContext(null);
@@ -9826,7 +9859,7 @@ function ToastProvider({
9826
9859
  maxToasts = 5,
9827
9860
  swipeDirection = "right"
9828
9861
  }) {
9829
- const [toasts, setToasts] = useState7([]);
9862
+ const [toasts, setToasts] = useState8([]);
9830
9863
  const addToast = (toastData) => {
9831
9864
  const id = Math.random().toString(36).substr(2, 9);
9832
9865
  const newToast = __spreadProps(__spreadValues({
@@ -9922,7 +9955,7 @@ function Tooltip({
9922
9955
  }
9923
9956
 
9924
9957
  // src/components/MultiSelect/index.tsx
9925
- import React10, { useCallback as useCallback2, useRef as useRef8, useState as useState8 } from "react";
9958
+ import React10, { useCallback as useCallback2, useRef as useRef8, useState as useState9 } from "react";
9926
9959
  import { DropdownMenu as DropdownMenu4, Theme as Theme3 } from "@radix-ui/themes";
9927
9960
  import { FontAwesomeIcon as FontAwesomeIcon3 } from "@fortawesome/react-fontawesome";
9928
9961
  import {
@@ -10101,9 +10134,9 @@ var MultiSelect = React10.forwardRef(
10101
10134
  showMoreButtonLabel = "Carregar mais",
10102
10135
  showMoreButtonOnClick
10103
10136
  }, fowardedRef) => {
10104
- const [isOpen, setIsOpen] = useState8(false);
10137
+ const [isOpen, setIsOpen] = useState9(false);
10105
10138
  const triggerRef = useRef8(null);
10106
- const [allOptionsSelected, setAllOptionsSelected] = useState8(false);
10139
+ const [allOptionsSelected, setAllOptionsSelected] = useState9(false);
10107
10140
  const labelByValue = useMemo2(() => {
10108
10141
  return options.reduce((prev, curr) => {
10109
10142
  return __spreadProps(__spreadValues({}, prev), {
@@ -10361,7 +10394,7 @@ var Divider = styled("div", {
10361
10394
  });
10362
10395
 
10363
10396
  // src/components/ToggleElement/index.tsx
10364
- import { useState as useState9 } from "react";
10397
+ import { useState as useState10 } from "react";
10365
10398
  import { Fragment as Fragment3, jsx as jsx28, jsxs as jsxs17 } from "react/jsx-runtime";
10366
10399
  function ToggleElement({
10367
10400
  children,
@@ -10373,7 +10406,7 @@ function ToggleElement({
10373
10406
  buttonProps,
10374
10407
  onOpenChange
10375
10408
  }) {
10376
- const [internalOpen, setInternalOpen] = useState9(defaultOpen);
10409
+ const [internalOpen, setInternalOpen] = useState10(defaultOpen);
10377
10410
  const isControlled = open !== void 0;
10378
10411
  const isOpen = isControlled ? open : internalOpen;
10379
10412
  const handleClick = () => {
@@ -11357,7 +11390,7 @@ function StateFormField({
11357
11390
  }
11358
11391
 
11359
11392
  // src/components/FormFields/AddressFormFields/CityFormField.tsx
11360
- import { useEffect as useEffect8, useState as useState10 } from "react";
11393
+ import { useEffect as useEffect8, useState as useState11 } from "react";
11361
11394
  import { useFormContext as useFormContext5, Controller as Controller2 } from "react-hook-form";
11362
11395
  import { Fragment as Fragment5, jsx as jsx47 } from "react/jsx-runtime";
11363
11396
  function CityFormField({
@@ -11370,8 +11403,8 @@ function CityFormField({
11370
11403
  }) {
11371
11404
  const { control, watch } = useFormContext5();
11372
11405
  const selectedState = watch(stateName);
11373
- const [cities, setCities] = useState10([]);
11374
- const [loading, setLoading] = useState10(false);
11406
+ const [cities, setCities] = useState11([]);
11407
+ const [loading, setLoading] = useState11(false);
11375
11408
  useEffect8(() => {
11376
11409
  if (!isBrazil) {
11377
11410
  setCities([]);
@@ -11757,10 +11790,10 @@ var EmailFormField = ({
11757
11790
  import { useController as useController3 } from "react-hook-form";
11758
11791
 
11759
11792
  // src/components/RichEditor/RichEditor.tsx
11760
- import { useEffect as useEffect10, useState as useState12 } from "react";
11793
+ import { useEffect as useEffect10, useState as useState13 } from "react";
11761
11794
 
11762
11795
  // src/components/RichEditor/QuillComponent.tsx
11763
- import { useState as useState11, useRef as useRef9, useEffect as useEffect9, useCallback as useCallback4 } from "react";
11796
+ import { useState as useState12, useRef as useRef9, useEffect as useEffect9, useCallback as useCallback4 } from "react";
11764
11797
  import { useQuill } from "react-quilljs";
11765
11798
 
11766
11799
  // src/utils/uploadService.ts
@@ -12963,10 +12996,10 @@ var QuillComponent = ({
12963
12996
  onCharacterCountChange,
12964
12997
  maxLength
12965
12998
  }) => {
12966
- const [showVideoModal, setShowVideoModal] = useState11(false);
12967
- const [videoUrl, setVideoUrl] = useState11("");
12968
- const [showLinkModal, setShowLinkModal] = useState11(false);
12969
- const [linkUrl, setLinkUrl] = useState11("");
12999
+ const [showVideoModal, setShowVideoModal] = useState12(false);
13000
+ const [videoUrl, setVideoUrl] = useState12("");
13001
+ const [showLinkModal, setShowLinkModal] = useState12(false);
13002
+ const [linkUrl, setLinkUrl] = useState12("");
12970
13003
  const videoModalRef = useRef9(null);
12971
13004
  const linkModalRef = useRef9(null);
12972
13005
  const { addToast, removeToast } = useToast();
@@ -13020,7 +13053,8 @@ var QuillComponent = ({
13020
13053
  [disabled, quill, addToast, removeToast, uploadConfig, onChange]
13021
13054
  );
13022
13055
  useEffect9(() => {
13023
- if (quill && value) {
13056
+ if (!quill) return;
13057
+ if (value !== void 0 && value !== null) {
13024
13058
  const currentContent = quill.root.innerHTML;
13025
13059
  if (currentContent !== value) {
13026
13060
  const selection = quill.getSelection();
@@ -13032,7 +13066,8 @@ var QuillComponent = ({
13032
13066
  }
13033
13067
  }
13034
13068
  }
13035
- }, [quill, value]);
13069
+ onCharacterCountChange == null ? void 0 : onCharacterCountChange(quill.getText().trim().length);
13070
+ }, [quill, value, onCharacterCountChange]);
13036
13071
  useEffect9(() => {
13037
13072
  if (quill) {
13038
13073
  quill.on("text-change", (delta, oldDelta, source) => {
@@ -13323,7 +13358,7 @@ var QuillComponent_default = QuillComponent;
13323
13358
  // src/components/RichEditor/RichEditor.tsx
13324
13359
  import { jsx as jsx54 } from "react/jsx-runtime";
13325
13360
  var RichEditor = (props) => {
13326
- const [isClient, setIsClient] = useState12(false);
13361
+ const [isClient, setIsClient] = useState13(false);
13327
13362
  useEffect10(() => {
13328
13363
  setIsClient(typeof window !== "undefined");
13329
13364
  }, []);
@@ -13346,8 +13381,21 @@ var RichTextPresenter = ({ richText }) => {
13346
13381
  var RichTextPresenter_default = RichTextPresenter;
13347
13382
 
13348
13383
  // src/components/FormFields/RichEditorFormField.tsx
13349
- import { useState as useState13 } from "react";
13384
+ import { useEffect as useEffect11, useState as useState14 } from "react";
13350
13385
  import { Fragment as Fragment6, jsx as jsx56, jsxs as jsxs30 } from "react/jsx-runtime";
13386
+ var getPlainTextLengthFromHtml = (html) => {
13387
+ var _a, _b;
13388
+ if (!html.trim()) return 0;
13389
+ if (typeof document === "undefined") {
13390
+ return html.replace(/<[^>]*>/g, "").trim().length;
13391
+ }
13392
+ const doc = new DOMParser().parseFromString(html, "text/html");
13393
+ return (_b = (_a = doc.body.textContent) == null ? void 0 : _a.trim().length) != null ? _b : 0;
13394
+ };
13395
+ var getRemainingCharacters = (maxLength, value) => {
13396
+ if (maxLength === void 0) return maxLength;
13397
+ return Math.max(0, maxLength - getPlainTextLengthFromHtml(value != null ? value : ""));
13398
+ };
13351
13399
  var RichEditorFormField = (_a) => {
13352
13400
  var _b = _a, {
13353
13401
  name,
@@ -13380,15 +13428,19 @@ var RichEditorFormField = (_a) => {
13380
13428
  return true;
13381
13429
  return (_a2 = validate == null ? void 0 : validate(value)) != null ? _a2 : true;
13382
13430
  }
13383
- },
13384
- defaultValue: ""
13431
+ }
13385
13432
  });
13386
- const [caracterQuantity, setCaracterQuantity] = useState13(maxLength);
13433
+ const [caracterQuantity, setCaracterQuantity] = useState14(
13434
+ () => getRemainingCharacters(maxLength, field.value)
13435
+ );
13387
13436
  const handleCharacterCountChange = (count) => {
13388
13437
  if (maxLength !== void 0) {
13389
13438
  setCaracterQuantity(Math.max(0, maxLength - count));
13390
13439
  }
13391
13440
  };
13441
+ useEffect11(() => {
13442
+ setCaracterQuantity(getRemainingCharacters(maxLength, field.value));
13443
+ }, [field.value, maxLength]);
13392
13444
  const fieldError = fieldState.error;
13393
13445
  const haveError = !!fieldError;
13394
13446
  const errorMsg = fieldError == null ? void 0 : fieldError.message;
@@ -13422,7 +13474,8 @@ var RichEditorFormField = (_a) => {
13422
13474
  onCharacterCountChange: handleCharacterCountChange,
13423
13475
  maxLength,
13424
13476
  disableVideo,
13425
- simpleVersion
13477
+ simpleVersion,
13478
+ richEditorElements
13426
13479
  })
13427
13480
  ),
13428
13481
  /* @__PURE__ */ jsx56(ErrorFormMessage, { message: errorMsg })
@@ -13659,7 +13712,7 @@ var TimePickerFormField = (_a) => {
13659
13712
 
13660
13713
  // src/components/FormFields/DateAndTimeFormField.tsx
13661
13714
  import { useController as useController7 } from "react-hook-form";
13662
- import { useCallback as useCallback8, useEffect as useEffect11, useMemo as useMemo4, useState as useState14 } from "react";
13715
+ import { useCallback as useCallback8, useEffect as useEffect12, useMemo as useMemo4, useState as useState15 } from "react";
13663
13716
  import { jsx as jsx60, jsxs as jsxs34 } from "react/jsx-runtime";
13664
13717
  var DateAndTimeFormField = (_a) => {
13665
13718
  var _b = _a, {
@@ -13747,9 +13800,9 @@ var DateAndTimeFormField = (_a) => {
13747
13800
  return { selectedDateFromIso: void 0, selectedTimeFromIso: void 0 };
13748
13801
  }
13749
13802
  }, [isoValue]);
13750
- const [draftDate, setDraftDate] = useState14(selectedDateFromIso);
13751
- const [draftTime, setDraftTime] = useState14(selectedTimeFromIso);
13752
- useEffect11(() => {
13803
+ const [draftDate, setDraftDate] = useState15(selectedDateFromIso);
13804
+ const [draftTime, setDraftTime] = useState15(selectedTimeFromIso);
13805
+ useEffect12(() => {
13753
13806
  setDraftDate(selectedDateFromIso);
13754
13807
  setDraftTime(selectedTimeFromIso);
13755
13808
  }, [selectedDateFromIso, selectedTimeFromIso]);
@@ -13840,11 +13893,11 @@ var DateAndTimeFormField = (_a) => {
13840
13893
  };
13841
13894
 
13842
13895
  // src/hooks/useImageUpload.ts
13843
- import { useState as useState15, useCallback as useCallback9 } from "react";
13896
+ import { useState as useState16, useCallback as useCallback9 } from "react";
13844
13897
  var useImageUpload = (options) => {
13845
- const [isUploading, setIsUploading] = useState15(false);
13846
- const [progress, setProgress] = useState15(null);
13847
- const [error, setError] = useState15(null);
13898
+ const [isUploading, setIsUploading] = useState16(false);
13899
+ const [progress, setProgress] = useState16(null);
13900
+ const [error, setError] = useState16(null);
13848
13901
  const {
13849
13902
  onSuccess,
13850
13903
  onError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lets-events/react",
3
- "version": "12.10.5",
3
+ "version": "12.10.7",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -3,9 +3,25 @@ import { Flex } from "../Flex";
3
3
  import { FormLabel } from "./subComponents/FormLabel";
4
4
  import { ErrorFormMessage } from "./subComponents/ErrorFormMessage";
5
5
  import { RichEditor, RichEditorProps } from "../RichEditor";
6
- import { useState } from "react";
6
+ import { useEffect, useState } from "react";
7
7
  import { Badge } from "../Badge";
8
8
  import { RichEditorElement } from "../RichEditor/types";
9
+
10
+ const getPlainTextLengthFromHtml = (html: string) => {
11
+ if (!html.trim()) return 0;
12
+
13
+ if (typeof document === "undefined") {
14
+ return html.replace(/<[^>]*>/g, "").trim().length;
15
+ }
16
+
17
+ const doc = new DOMParser().parseFromString(html, "text/html");
18
+ return doc.body.textContent?.trim().length ?? 0;
19
+ };
20
+
21
+ const getRemainingCharacters = (maxLength: number | undefined, value?: string) => {
22
+ if (maxLength === undefined) return maxLength;
23
+ return Math.max(0, maxLength - getPlainTextLengthFromHtml(value ?? ""));
24
+ };
9
25
  export type RichEditorFormFieldProps = Omit<
10
26
  RichEditorProps,
11
27
  "value" | "onChange"
@@ -48,14 +64,20 @@ export const RichEditorFormField = ({
48
64
  return validate?.(value) ?? true;
49
65
  },
50
66
  },
51
- defaultValue: "",
52
67
  });
53
- const [caracterQuantity, setCaracterQuantity] = useState(maxLength)
68
+ const [caracterQuantity, setCaracterQuantity] = useState(() =>
69
+ getRemainingCharacters(maxLength, field.value),
70
+ );
71
+
54
72
  const handleCharacterCountChange = (count: number) => {
55
73
  if (maxLength !== undefined) {
56
74
  setCaracterQuantity(Math.max(0, maxLength - count));
57
75
  }
58
76
  };
77
+
78
+ useEffect(() => {
79
+ setCaracterQuantity(getRemainingCharacters(maxLength, field.value));
80
+ }, [field.value, maxLength]);
59
81
  const fieldError = fieldState.error;
60
82
  const haveError = !!fieldError;
61
83
  const errorMsg = fieldError?.message;
@@ -98,6 +120,7 @@ export const RichEditorFormField = ({
98
120
  maxLength={maxLength}
99
121
  disableVideo={disableVideo}
100
122
  simpleVersion={simpleVersion}
123
+ richEditorElements={richEditorElements}
101
124
  />
102
125
  <ErrorFormMessage message={errorMsg} />
103
126
  </Flex>
@@ -90,7 +90,9 @@ const QuillComponent: React.FC<RichEditorProps> = ({
90
90
  );
91
91
 
92
92
  useEffect(() => {
93
- if (quill && value) {
93
+ if (!quill) return;
94
+
95
+ if (value !== undefined && value !== null) {
94
96
  const currentContent = quill.root.innerHTML;
95
97
  if (currentContent !== value) {
96
98
  const selection = quill.getSelection();
@@ -103,7 +105,9 @@ const QuillComponent: React.FC<RichEditorProps> = ({
103
105
  }
104
106
  }
105
107
  }
106
- }, [quill, value]);
108
+
109
+ onCharacterCountChange?.(quill.getText().trim().length);
110
+ }, [quill, value, onCharacterCountChange]);
107
111
 
108
112
  useEffect(() => {
109
113
  if (quill) {
@@ -1,4 +1,4 @@
1
- import React, { ComponentProps, ReactNode } from "react";
1
+ import React, { ComponentProps, ReactNode, useLayoutEffect, useState } from "react";
2
2
  import { styled } from "../styles";
3
3
  import { TextField as TextFieldRadix } from "@radix-ui/themes";
4
4
  import Icon from "./Icon";
@@ -250,23 +250,81 @@ export const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
250
250
  mask,
251
251
  maxLength,
252
252
  hasError,
253
+ value,
254
+ defaultValue,
255
+ onInput,
253
256
  ...props
254
257
  },
255
258
  fowardedRef
256
259
  ) => {
260
+ const { ref: propRef, ...restProps } = props as typeof props & {
261
+ ref?: React.Ref<HTMLInputElement>;
262
+ };
257
263
  const maskRef = mask ? useMask(mask) : undefined;
258
264
  const inputRef = React.useRef<HTMLInputElement>(null);
259
- const badgeRef = React.useRef<HTMLSpanElement>(null);
260
265
 
261
- const updateCharCountBadge = () => {
262
- if (!maxLength || !badgeRef.current) return;
263
- const currentLength = inputRef.current?.value.length ?? 0;
264
- badgeRef.current.textContent = String(maxLength - currentLength);
266
+ const getTextLength = (
267
+ text?: string | number | readonly string[] | null,
268
+ ) => String(text ?? "").length;
269
+
270
+ const updateRemaining = (currentLength: number) => {
271
+ if (maxLength !== undefined) {
272
+ setRemaining(maxLength - currentLength);
273
+ }
274
+ };
275
+
276
+ const getCurrentLength = (inputElement?: HTMLInputElement | null) => {
277
+ if (value !== undefined && value !== null) {
278
+ return getTextLength(value);
279
+ }
280
+
281
+ return (
282
+ inputElement?.value.length ??
283
+ inputRef.current?.value.length ??
284
+ getTextLength(defaultValue)
285
+ );
286
+ };
287
+
288
+ const [remaining, setRemaining] = useState(() =>
289
+ maxLength !== undefined
290
+ ? maxLength - getTextLength(value ?? defaultValue)
291
+ : 0,
292
+ );
293
+
294
+ useLayoutEffect(() => {
295
+ if (maxLength === undefined) return;
296
+ updateRemaining(getCurrentLength());
297
+ }, [maxLength, value, defaultValue]);
298
+
299
+ const assignRef = (element: HTMLInputElement | null) => {
300
+ inputRef.current = element;
301
+
302
+ if (maskRef && element) {
303
+ maskRef.current = element;
304
+ }
305
+
306
+ if (typeof propRef === "function") {
307
+ propRef(element);
308
+ } else if (propRef) {
309
+ propRef.current = element;
310
+ }
311
+
312
+ if (typeof fowardedRef === "function") {
313
+ fowardedRef(element);
314
+ } else if (fowardedRef) {
315
+ fowardedRef.current = element;
316
+ }
317
+
318
+ if (element && maxLength !== undefined) {
319
+ updateRemaining(getCurrentLength(element));
320
+ }
265
321
  };
266
322
 
267
323
  const handleInput = (e: React.FormEvent<HTMLInputElement>) => {
268
- updateCharCountBadge();
269
- props.onInput?.(e);
324
+ if (maxLength !== undefined) {
325
+ updateRemaining(e.currentTarget.value.length);
326
+ }
327
+ onInput?.(e);
270
328
  };
271
329
 
272
330
  return (
@@ -282,6 +340,7 @@ export const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
282
340
  )}
283
341
 
284
342
  <TextFieldStyled
343
+ {...restProps}
285
344
  color={hasError ? "error" : color || "default"}
286
345
  isValid={isValid}
287
346
  name={name}
@@ -289,18 +348,10 @@ export const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
289
348
  fontWeight={fontWeight}
290
349
  textAlign={textAlign}
291
350
  maxLength={maxLength}
292
- ref={(r) => {
293
- if (!r) return;
294
- inputRef.current = r;
295
- if (maskRef) maskRef.current = r;
296
-
297
- if (fowardedRef) {
298
- if (typeof fowardedRef === "function") fowardedRef(r);
299
- else fowardedRef.current = r;
300
- }
301
- }}
351
+ ref={assignRef}
302
352
  onInput={handleInput}
303
- {...props}
353
+ value={value}
354
+ defaultValue={defaultValue}
304
355
  style={
305
356
  addon
306
357
  ? {
@@ -329,7 +380,7 @@ export const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
329
380
  </Flex>
330
381
  {maxLength && (
331
382
  <TextFieldLimitIndicator>
332
- <span ref={badgeRef}>{maxLength}</span>
383
+ <span>{remaining}</span>
333
384
  </TextFieldLimitIndicator>
334
385
  )}
335
386
  </Flex>