@lets-events/react 12.1.6 → 12.1.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,7 +1,6 @@
1
1
 
2
- npm warn cli npm v11.5.1 does not support Node.js v20.10.0. This version of npm supports the following node versions: `^20.17.0 || >=22.9.0`. You can find the latest version at https://nodejs.org/.
3
2
 
4
- > @lets-events/react@12.1.6 build
3
+ > @lets-events/react@12.1.7 build
5
4
  > tsup src/index.tsx --format esm,cjs --dts --external react
6
5
 
7
6
  CLI Building entry: src/index.tsx
@@ -11,14 +10,14 @@
11
10
  CLI Target: es6
12
11
  ESM Build start
13
12
  CJS Build start
14
- ESM dist/QuillComponent-A5KIFPCL.mjs 13.19 KB
13
+ CJS dist/index.js 376.41 KB
14
+ CJS ⚡️ Build success in -12208ms
15
15
  ESM dist/chunk-TU7LKUXZ.mjs 61.98 KB
16
- ESM dist/index.mjs 277.16 KB
17
- ESM ⚡️ Build success in 396ms
18
- CJS dist/index.js 374.66 KB
19
- CJS ⚡️ Build success in 397ms
16
+ ESM dist/index.mjs 277.95 KB
17
+ ESM dist/QuillComponent-TLIZCM6V.mjs 13.97 KB
18
+ ESM ⚡️ Build success in -12206ms
20
19
  DTS Build start
21
- DTS ⚡️ Build success in 7341ms
22
- DTS dist/index.d.mts 388.73 KB
23
- DTS dist/index.d.ts 388.73 KB
20
+ DTS ⚡️ Build success in 5916ms
21
+ DTS dist/index.d.mts 388.87 KB
22
+ DTS dist/index.d.ts 388.87 KB
24
23
  ⠙
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lets-events/react
2
2
 
3
+ ## 12.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Richeditor simpleVersion and MaxLength
8
+
3
9
  ## 12.1.6
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -14724,7 +14724,10 @@ interface RichEditorProps {
14724
14724
  label?: string;
14725
14725
  disabled?: boolean;
14726
14726
  className?: string;
14727
- uploadConfig: UploadConfig$1;
14727
+ uploadConfig?: UploadConfig$1;
14728
+ simpleVersion?: boolean;
14729
+ onCharacterCountChange?: (count: number) => void;
14730
+ maxLength?: number;
14728
14731
  }
14729
14732
  declare const RichEditor: (props: RichEditorProps) => react_jsx_runtime.JSX.Element | null;
14730
14733
 
@@ -14733,10 +14736,11 @@ type RichEditorFormFieldProps = Omit<RichEditorProps, "value" | "onChange"> & {
14733
14736
  label?: string;
14734
14737
  required?: boolean;
14735
14738
  validate?: (value: string) => boolean | string;
14739
+ maxLength?: number;
14736
14740
  validationErrorMessage?: string;
14737
14741
  uploadConfig: RichEditorProps["uploadConfig"];
14738
14742
  };
14739
- declare const RichEditorFormField: ({ name, label, required, validate, validationErrorMessage, ...props }: RichEditorFormFieldProps) => react_jsx_runtime.JSX.Element;
14743
+ declare const RichEditorFormField: ({ name, label, required, validate, validationErrorMessage, maxLength, ...props }: RichEditorFormFieldProps) => react_jsx_runtime.JSX.Element;
14740
14744
 
14741
14745
  type CalendarFormFieldProps = Omit<CalendarProps, "selected" | "setSelected"> & {
14742
14746
  name: string;
package/dist/index.d.ts CHANGED
@@ -14724,7 +14724,10 @@ interface RichEditorProps {
14724
14724
  label?: string;
14725
14725
  disabled?: boolean;
14726
14726
  className?: string;
14727
- uploadConfig: UploadConfig$1;
14727
+ uploadConfig?: UploadConfig$1;
14728
+ simpleVersion?: boolean;
14729
+ onCharacterCountChange?: (count: number) => void;
14730
+ maxLength?: number;
14728
14731
  }
14729
14732
  declare const RichEditor: (props: RichEditorProps) => react_jsx_runtime.JSX.Element | null;
14730
14733
 
@@ -14733,10 +14736,11 @@ type RichEditorFormFieldProps = Omit<RichEditorProps, "value" | "onChange"> & {
14733
14736
  label?: string;
14734
14737
  required?: boolean;
14735
14738
  validate?: (value: string) => boolean | string;
14739
+ maxLength?: number;
14736
14740
  validationErrorMessage?: string;
14737
14741
  uploadConfig: RichEditorProps["uploadConfig"];
14738
14742
  };
14739
- declare const RichEditorFormField: ({ name, label, required, validate, validationErrorMessage, ...props }: RichEditorFormFieldProps) => react_jsx_runtime.JSX.Element;
14743
+ declare const RichEditorFormField: ({ name, label, required, validate, validationErrorMessage, maxLength, ...props }: RichEditorFormFieldProps) => react_jsx_runtime.JSX.Element;
14740
14744
 
14741
14745
  type CalendarFormFieldProps = Omit<CalendarProps, "selected" | "setSelected"> & {
14742
14746
  name: string;
package/dist/index.js CHANGED
@@ -152,7 +152,7 @@ var require_react_is_development = __commonJS({
152
152
  var ContextProvider = REACT_PROVIDER_TYPE;
153
153
  var Element = REACT_ELEMENT_TYPE;
154
154
  var ForwardRef = REACT_FORWARD_REF_TYPE;
155
- var Fragment5 = REACT_FRAGMENT_TYPE;
155
+ var Fragment6 = REACT_FRAGMENT_TYPE;
156
156
  var Lazy = REACT_LAZY_TYPE;
157
157
  var Memo = REACT_MEMO_TYPE;
158
158
  var Portal = REACT_PORTAL_TYPE;
@@ -211,7 +211,7 @@ var require_react_is_development = __commonJS({
211
211
  exports2.ContextProvider = ContextProvider;
212
212
  exports2.Element = Element;
213
213
  exports2.ForwardRef = ForwardRef;
214
- exports2.Fragment = Fragment5;
214
+ exports2.Fragment = Fragment6;
215
215
  exports2.Lazy = Lazy;
216
216
  exports2.Memo = Memo;
217
217
  exports2.Portal = Portal;
@@ -2053,7 +2053,10 @@ var init_QuillComponent = __esm({
2053
2053
  placeholder = "Digite seu texto aqui...",
2054
2054
  disabled = false,
2055
2055
  className,
2056
- uploadConfig
2056
+ uploadConfig,
2057
+ simpleVersion = false,
2058
+ onCharacterCountChange,
2059
+ maxLength
2057
2060
  }) => {
2058
2061
  const [showVideoModal, setShowVideoModal] = (0, import_react20.useState)(false);
2059
2062
  const [videoUrl, setVideoUrl] = (0, import_react20.useState)("");
@@ -2062,7 +2065,16 @@ var init_QuillComponent = __esm({
2062
2065
  const videoModalRef = (0, import_react20.useRef)(null);
2063
2066
  const linkModalRef = (0, import_react20.useRef)(null);
2064
2067
  const { addToast, removeToast } = useToast();
2065
- const modules = {
2068
+ const modules = simpleVersion ? {
2069
+ toolbar: [
2070
+ ["bold", "italic", "underline"],
2071
+ [{ list: "ordered" }, { list: "bullet" }],
2072
+ ["link"]
2073
+ ],
2074
+ clipboard: {
2075
+ matchVisual: false
2076
+ }
2077
+ } : {
2066
2078
  toolbar: [
2067
2079
  [{ header: [1, 2, false] }],
2068
2080
  ["bold", "italic", "underline", "strike"],
@@ -2075,7 +2087,7 @@ var init_QuillComponent = __esm({
2075
2087
  matchVisual: false
2076
2088
  }
2077
2089
  };
2078
- const formats = [
2090
+ const formats = simpleVersion ? ["bold", "italic", "underline", "list", "link"] : [
2079
2091
  "header",
2080
2092
  "bold",
2081
2093
  "italic",
@@ -2127,6 +2139,7 @@ var init_QuillComponent = __esm({
2127
2139
  );
2128
2140
  (0, import_react20.useEffect)(() => {
2129
2141
  if (quill && value) {
2142
+ console.log("entrou no quill && value");
2130
2143
  const currentContent = quill.root.innerHTML;
2131
2144
  if (currentContent !== value) {
2132
2145
  const selection = quill.getSelection();
@@ -2143,8 +2156,15 @@ var init_QuillComponent = __esm({
2143
2156
  if (quill) {
2144
2157
  quill.on("text-change", (delta, oldDelta, source) => {
2145
2158
  if (source === "user") {
2146
- const html = quill.root.innerHTML;
2147
- onChange == null ? void 0 : onChange(html);
2159
+ const text = quill.getText().trim();
2160
+ const count = text.length;
2161
+ console.log("entrou no quill && user", maxLength !== void 0, count, maxLength, "count > maxLength");
2162
+ if (maxLength !== void 0 && count > maxLength) {
2163
+ quill.deleteText(maxLength, count - maxLength);
2164
+ return;
2165
+ }
2166
+ onChange == null ? void 0 : onChange(quill.root.innerHTML);
2167
+ onCharacterCountChange == null ? void 0 : onCharacterCountChange(count);
2148
2168
  }
2149
2169
  });
2150
2170
  const toolbar = quill.getModule("toolbar");
@@ -2187,7 +2207,7 @@ var init_QuillComponent = __esm({
2187
2207
  }
2188
2208
  }, 2e3);
2189
2209
  }
2190
- }, [quill, onChange, handleImageUpload]);
2210
+ }, [quill, onChange, handleImageUpload, onCharacterCountChange]);
2191
2211
  (0, import_react20.useEffect)(() => {
2192
2212
  if (quill) {
2193
2213
  quill.enable(!disabled);
@@ -11746,6 +11766,7 @@ var RichEditor = (props) => {
11746
11766
  var RichEditor_default = RichEditor;
11747
11767
 
11748
11768
  // src/components/FormFields/RichEditorFormField.tsx
11769
+ var import_react22 = require("react");
11749
11770
  var import_jsx_runtime53 = require("react/jsx-runtime");
11750
11771
  var RichEditorFormField = (_a) => {
11751
11772
  var _b = _a, {
@@ -11753,13 +11774,15 @@ var RichEditorFormField = (_a) => {
11753
11774
  label,
11754
11775
  required,
11755
11776
  validate,
11756
- validationErrorMessage = "Este campo \xE9 obrigat\xF3rio."
11777
+ validationErrorMessage = "Este campo \xE9 obrigat\xF3rio.",
11778
+ maxLength
11757
11779
  } = _b, props = __objRest(_b, [
11758
11780
  "name",
11759
11781
  "label",
11760
11782
  "required",
11761
11783
  "validate",
11762
- "validationErrorMessage"
11784
+ "validationErrorMessage",
11785
+ "maxLength"
11763
11786
  ]);
11764
11787
  const { field, fieldState } = (0, import_react_hook_form12.useController)({
11765
11788
  name,
@@ -11774,11 +11797,28 @@ var RichEditorFormField = (_a) => {
11774
11797
  },
11775
11798
  defaultValue: ""
11776
11799
  });
11800
+ const [caracterQuantity, setCaracterQuantity] = (0, import_react22.useState)(maxLength);
11801
+ const handleCharacterCountChange = (count) => {
11802
+ if (maxLength !== void 0) {
11803
+ setCaracterQuantity(Math.max(0, maxLength - count));
11804
+ }
11805
+ };
11777
11806
  const fieldError = fieldState.error;
11778
11807
  const haveError = !!fieldError;
11779
11808
  const errorMsg = fieldError == null ? void 0 : fieldError.message;
11780
11809
  return /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)(Flex2, { direction: "column", children: [
11781
- label && /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
11810
+ maxLength ? /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)(Flex2, { direction: "row", justify: "between", children: [
11811
+ label && /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
11812
+ FormLabel,
11813
+ {
11814
+ name,
11815
+ label,
11816
+ required,
11817
+ haveError
11818
+ }
11819
+ ),
11820
+ /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(Badge, { color: "grey", size: "xs", children: caracterQuantity })
11821
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(import_jsx_runtime53.Fragment, { children: label && /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
11782
11822
  FormLabel,
11783
11823
  {
11784
11824
  name,
@@ -11786,13 +11826,15 @@ var RichEditorFormField = (_a) => {
11786
11826
  required,
11787
11827
  haveError
11788
11828
  }
11789
- ),
11829
+ ) }),
11790
11830
  /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(
11791
11831
  RichEditor_default,
11792
11832
  __spreadProps(__spreadValues({}, props), {
11793
11833
  value: field.value,
11794
11834
  onChange: field.onChange,
11795
- "aria-labelledby": `${name}-label`
11835
+ "aria-labelledby": `${name}-label`,
11836
+ onCharacterCountChange: handleCharacterCountChange,
11837
+ maxLength
11796
11838
  })
11797
11839
  ),
11798
11840
  /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(ErrorFormMessage, { message: errorMsg })
@@ -11802,7 +11844,7 @@ var RichEditorFormField = (_a) => {
11802
11844
  // src/components/FormFields/CalendarFormField.tsx
11803
11845
  var import_react_hook_form13 = require("react-hook-form");
11804
11846
  init_Flex();
11805
- var import_react22 = require("react");
11847
+ var import_react23 = require("react");
11806
11848
  var import_jsx_runtime54 = require("react/jsx-runtime");
11807
11849
  var CalendarFormField = (_a) => {
11808
11850
  var _b = _a, {
@@ -11824,7 +11866,7 @@ var CalendarFormField = (_a) => {
11824
11866
  "onChange",
11825
11867
  "allowPastDates"
11826
11868
  ]);
11827
- const handleValidate = (0, import_react22.useCallback)(
11869
+ const handleValidate = (0, import_react23.useCallback)(
11828
11870
  (value) => {
11829
11871
  var _a2;
11830
11872
  if (value === void 0 || value === null) {
@@ -11879,7 +11921,7 @@ var CalendarFormField = (_a) => {
11879
11921
  // src/components/FormFields/TimePickerFormField.tsx
11880
11922
  var import_react_hook_form14 = require("react-hook-form");
11881
11923
  init_Flex();
11882
- var import_react23 = require("react");
11924
+ var import_react24 = require("react");
11883
11925
  var import_jsx_runtime55 = require("react/jsx-runtime");
11884
11926
  var TimePickerFormField = (_a) => {
11885
11927
  var _b = _a, {
@@ -11897,7 +11939,7 @@ var TimePickerFormField = (_a) => {
11897
11939
  "validationErrorMessage",
11898
11940
  "rules"
11899
11941
  ]);
11900
- const handleValidate = (0, import_react23.useCallback)(
11942
+ const handleValidate = (0, import_react24.useCallback)(
11901
11943
  (value) => {
11902
11944
  var _a2;
11903
11945
  if (value === void 0 || value === null || value === "") {
@@ -11949,12 +11991,12 @@ var TimePickerFormField = (_a) => {
11949
11991
  };
11950
11992
 
11951
11993
  // src/hooks/useImageUpload.ts
11952
- var import_react24 = require("react");
11994
+ var import_react25 = require("react");
11953
11995
  init_uploadService();
11954
11996
  var useImageUpload = (options) => {
11955
- const [isUploading, setIsUploading] = (0, import_react24.useState)(false);
11956
- const [progress, setProgress] = (0, import_react24.useState)(null);
11957
- const [error, setError] = (0, import_react24.useState)(null);
11997
+ const [isUploading, setIsUploading] = (0, import_react25.useState)(false);
11998
+ const [progress, setProgress] = (0, import_react25.useState)(null);
11999
+ const [error, setError] = (0, import_react25.useState)(null);
11958
12000
  const {
11959
12001
  onSuccess,
11960
12002
  onError,
@@ -11964,7 +12006,7 @@ var useImageUpload = (options) => {
11964
12006
  allowedTypes = ["image/jpeg", "image/png", "image/gif", "image/webp"],
11965
12007
  uploadConfig
11966
12008
  } = options;
11967
- const validateFile = (0, import_react24.useCallback)(
12009
+ const validateFile = (0, import_react25.useCallback)(
11968
12010
  (file) => {
11969
12011
  if (!allowedTypes.includes(file.type)) {
11970
12012
  const errorMsg = "Tipo de arquivo n\xE3o suportado";
@@ -11982,7 +12024,7 @@ var useImageUpload = (options) => {
11982
12024
  },
11983
12025
  [allowedTypes, maxFileSize, onError]
11984
12026
  );
11985
- const uploadFile = (0, import_react24.useCallback)(
12027
+ const uploadFile = (0, import_react25.useCallback)(
11986
12028
  (file) => __async(null, null, function* () {
11987
12029
  if (!validateFile(file)) {
11988
12030
  return null;
@@ -12035,7 +12077,7 @@ var useImageUpload = (options) => {
12035
12077
  }),
12036
12078
  [validateFile, onSuccess, onError, onProgress]
12037
12079
  );
12038
- const reset = (0, import_react24.useCallback)(() => {
12080
+ const reset = (0, import_react25.useCallback)(() => {
12039
12081
  setIsUploading(false);
12040
12082
  setProgress(null);
12041
12083
  setError(null);
package/dist/index.mjs CHANGED
@@ -9161,7 +9161,7 @@ import { useController as useController3 } from "react-hook-form";
9161
9161
  // src/components/RichEditor/RichEditor.tsx
9162
9162
  import { lazy, useEffect as useEffect6, useState as useState7, Suspense } from "react";
9163
9163
  import { jsx as jsx46 } from "react/jsx-runtime";
9164
- var QuillComponent = lazy(() => import("./QuillComponent-A5KIFPCL.mjs"));
9164
+ var QuillComponent = lazy(() => import("./QuillComponent-TLIZCM6V.mjs"));
9165
9165
  var RichEditor = (props) => {
9166
9166
  const [isClient, setIsClient] = useState7(false);
9167
9167
  useEffect6(() => {
@@ -9173,20 +9173,23 @@ var RichEditor = (props) => {
9173
9173
  var RichEditor_default = RichEditor;
9174
9174
 
9175
9175
  // src/components/FormFields/RichEditorFormField.tsx
9176
- import { jsx as jsx47, jsxs as jsxs24 } from "react/jsx-runtime";
9176
+ import { useState as useState8 } from "react";
9177
+ import { Fragment as Fragment5, jsx as jsx47, jsxs as jsxs24 } from "react/jsx-runtime";
9177
9178
  var RichEditorFormField = (_a) => {
9178
9179
  var _b = _a, {
9179
9180
  name,
9180
9181
  label,
9181
9182
  required,
9182
9183
  validate,
9183
- validationErrorMessage = "Este campo \xE9 obrigat\xF3rio."
9184
+ validationErrorMessage = "Este campo \xE9 obrigat\xF3rio.",
9185
+ maxLength
9184
9186
  } = _b, props = __objRest(_b, [
9185
9187
  "name",
9186
9188
  "label",
9187
9189
  "required",
9188
9190
  "validate",
9189
- "validationErrorMessage"
9191
+ "validationErrorMessage",
9192
+ "maxLength"
9190
9193
  ]);
9191
9194
  const { field, fieldState } = useController3({
9192
9195
  name,
@@ -9201,11 +9204,28 @@ var RichEditorFormField = (_a) => {
9201
9204
  },
9202
9205
  defaultValue: ""
9203
9206
  });
9207
+ const [caracterQuantity, setCaracterQuantity] = useState8(maxLength);
9208
+ const handleCharacterCountChange = (count) => {
9209
+ if (maxLength !== void 0) {
9210
+ setCaracterQuantity(Math.max(0, maxLength - count));
9211
+ }
9212
+ };
9204
9213
  const fieldError = fieldState.error;
9205
9214
  const haveError = !!fieldError;
9206
9215
  const errorMsg = fieldError == null ? void 0 : fieldError.message;
9207
9216
  return /* @__PURE__ */ jsxs24(Flex, { direction: "column", children: [
9208
- label && /* @__PURE__ */ jsx47(
9217
+ maxLength ? /* @__PURE__ */ jsxs24(Flex, { direction: "row", justify: "between", children: [
9218
+ label && /* @__PURE__ */ jsx47(
9219
+ FormLabel,
9220
+ {
9221
+ name,
9222
+ label,
9223
+ required,
9224
+ haveError
9225
+ }
9226
+ ),
9227
+ /* @__PURE__ */ jsx47(Badge, { color: "grey", size: "xs", children: caracterQuantity })
9228
+ ] }) : /* @__PURE__ */ jsx47(Fragment5, { children: label && /* @__PURE__ */ jsx47(
9209
9229
  FormLabel,
9210
9230
  {
9211
9231
  name,
@@ -9213,13 +9233,15 @@ var RichEditorFormField = (_a) => {
9213
9233
  required,
9214
9234
  haveError
9215
9235
  }
9216
- ),
9236
+ ) }),
9217
9237
  /* @__PURE__ */ jsx47(
9218
9238
  RichEditor_default,
9219
9239
  __spreadProps(__spreadValues({}, props), {
9220
9240
  value: field.value,
9221
9241
  onChange: field.onChange,
9222
- "aria-labelledby": `${name}-label`
9242
+ "aria-labelledby": `${name}-label`,
9243
+ onCharacterCountChange: handleCharacterCountChange,
9244
+ maxLength
9223
9245
  })
9224
9246
  ),
9225
9247
  /* @__PURE__ */ jsx47(ErrorFormMessage, { message: errorMsg })
@@ -9374,11 +9396,11 @@ var TimePickerFormField = (_a) => {
9374
9396
  };
9375
9397
 
9376
9398
  // src/hooks/useImageUpload.ts
9377
- import { useState as useState8, useCallback as useCallback6 } from "react";
9399
+ import { useState as useState9, useCallback as useCallback6 } from "react";
9378
9400
  var useImageUpload = (options) => {
9379
- const [isUploading, setIsUploading] = useState8(false);
9380
- const [progress, setProgress] = useState8(null);
9381
- const [error, setError] = useState8(null);
9401
+ const [isUploading, setIsUploading] = useState9(false);
9402
+ const [progress, setProgress] = useState9(null);
9403
+ const [error, setError] = useState9(null);
9382
9404
  const {
9383
9405
  onSuccess,
9384
9406
  onError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lets-events/react",
3
- "version": "12.1.6",
3
+ "version": "12.1.7",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -3,6 +3,8 @@ 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";
7
+ import { Badge } from "../Badge";
6
8
 
7
9
  export type RichEditorFormFieldProps = Omit<
8
10
  RichEditorProps,
@@ -12,6 +14,7 @@ export type RichEditorFormFieldProps = Omit<
12
14
  label?: string;
13
15
  required?: boolean;
14
16
  validate?: (value: string) => boolean | string;
17
+ maxLength?: number;
15
18
  validationErrorMessage?: string;
16
19
  uploadConfig: RichEditorProps["uploadConfig"];
17
20
  };
@@ -22,6 +25,7 @@ export const RichEditorFormField = ({
22
25
  required,
23
26
  validate,
24
27
  validationErrorMessage = "Este campo é obrigatório.",
28
+ maxLength,
25
29
  ...props
26
30
  }: RichEditorFormFieldProps) => {
27
31
  const { field, fieldState } = useController({
@@ -40,27 +44,52 @@ export const RichEditorFormField = ({
40
44
  },
41
45
  defaultValue: "",
42
46
  });
43
-
47
+ const [caracterQuantity, setCaracterQuantity] = useState(maxLength)
48
+ const handleCharacterCountChange = (count: number) => {
49
+ if (maxLength !== undefined) {
50
+ setCaracterQuantity(Math.max(0, maxLength - count));
51
+ }
52
+ };
44
53
  const fieldError = fieldState.error;
45
54
  const haveError = !!fieldError;
46
55
  const errorMsg = fieldError?.message;
47
56
 
57
+
48
58
  return (
49
59
  <Flex direction="column">
50
- {label && (
51
- <FormLabel
52
- name={name}
53
- label={label}
54
- required={required}
55
- haveError={haveError}
56
- />
60
+ {maxLength ? (
61
+ <Flex direction="row" justify="between">
62
+ {label && (
63
+ <FormLabel
64
+ name={name}
65
+ label={label}
66
+ required={required}
67
+ haveError={haveError}
68
+ />
69
+ )}
70
+ <Badge color="grey" size="xs">
71
+ {caracterQuantity}
72
+ </Badge>
73
+ </Flex>
74
+ ) : (
75
+ <>
76
+ {label && (
77
+ <FormLabel
78
+ name={name}
79
+ label={label}
80
+ required={required}
81
+ haveError={haveError}
82
+ />
83
+ )}
84
+ </>
57
85
  )}
58
-
59
86
  <RichEditor
60
87
  {...props}
61
88
  value={field.value}
62
89
  onChange={field.onChange}
63
90
  aria-labelledby={`${name}-label`}
91
+ onCharacterCountChange={handleCharacterCountChange}
92
+ maxLength={maxLength}
64
93
  />
65
94
 
66
95
  <ErrorFormMessage message={errorMsg} />
@@ -6,20 +6,18 @@ import { Text } from "../Text";
6
6
  import { RichEditorProps } from "./RichEditor";
7
7
  import { useToast } from "../Toast/hooks/useToast";
8
8
  import { UploadService } from "../../utils/uploadService";
9
- import { UploadConfig } from "./RichEditor";
10
9
  import { QuillContainer, QuillEditor } from "./styledComponents";
11
10
 
12
- interface QuillComponentProps extends RichEditorProps {
13
- uploadConfig: UploadConfig;
14
- }
15
-
16
- const QuillComponent: React.FC<QuillComponentProps> = ({
11
+ const QuillComponent: React.FC<RichEditorProps> = ({
17
12
  value = "",
18
13
  onChange,
19
14
  placeholder = "Digite seu texto aqui...",
20
15
  disabled = false,
21
16
  className,
22
17
  uploadConfig,
18
+ simpleVersion = false,
19
+ onCharacterCountChange,
20
+ maxLength,
23
21
  }) => {
24
22
  const [showVideoModal, setShowVideoModal] = useState(false);
25
23
  const [videoUrl, setVideoUrl] = useState("");
@@ -30,34 +28,47 @@ const QuillComponent: React.FC<QuillComponentProps> = ({
30
28
  const linkModalRef = useRef<HTMLDivElement>(null);
31
29
  const { addToast, removeToast } = useToast();
32
30
 
33
- const modules = {
34
- toolbar: [
35
- [{ header: [1, 2, false] }],
36
- ["bold", "italic", "underline", "strike"],
37
- [{ color: [] }, { background: [] }],
38
- [{ align: [] }],
39
- [{ list: "ordered" }, { list: "bullet" }],
40
- ["link", "image", "video"],
41
- ],
42
- clipboard: {
43
- matchVisual: false,
44
- },
45
- };
46
-
47
- const formats = [
48
- "header",
49
- "bold",
50
- "italic",
51
- "underline",
52
- "strike",
53
- "color",
54
- "background",
55
- "align",
56
- "list",
57
- "link",
58
- "image",
59
- "video",
60
- ];
31
+ const modules = simpleVersion
32
+ ? {
33
+ toolbar: [
34
+ ["bold", "italic", "underline"],
35
+ [{ list: "ordered" }, { list: "bullet" }],
36
+ ["link"],
37
+ ],
38
+ clipboard: {
39
+ matchVisual: false,
40
+ },
41
+ }
42
+ : {
43
+ toolbar: [
44
+ [{ header: [1, 2, false] }],
45
+ ["bold", "italic", "underline", "strike"],
46
+ [{ color: [] }, { background: [] }],
47
+ [{ align: [] }],
48
+ [{ list: "ordered" }, { list: "bullet" }],
49
+ ["link", "image", "video"],
50
+ ],
51
+ clipboard: {
52
+ matchVisual: false,
53
+ },
54
+ };
55
+
56
+ const formats = simpleVersion
57
+ ? ["bold", "italic", "underline", "list", "link"]
58
+ : [
59
+ "header",
60
+ "bold",
61
+ "italic",
62
+ "underline",
63
+ "strike",
64
+ "color",
65
+ "background",
66
+ "align",
67
+ "list",
68
+ "link",
69
+ "image",
70
+ "video",
71
+ ];
61
72
 
62
73
  const { quill, quillRef } = useQuill({
63
74
  theme: "snow",
@@ -103,6 +114,7 @@ const QuillComponent: React.FC<QuillComponentProps> = ({
103
114
 
104
115
  useEffect(() => {
105
116
  if (quill && value) {
117
+ console.log('entrou no quill && value')
106
118
  const currentContent = quill.root.innerHTML;
107
119
  if (currentContent !== value) {
108
120
  const selection = quill.getSelection();
@@ -121,8 +133,16 @@ const QuillComponent: React.FC<QuillComponentProps> = ({
121
133
  if (quill) {
122
134
  quill.on("text-change", (delta: any, oldDelta: any, source: string) => {
123
135
  if (source === "user") {
124
- const html = quill.root.innerHTML;
125
- onChange?.(html);
136
+ const text = quill.getText().trim();
137
+ const count = text.length;
138
+ console.log('entrou no quill && user', maxLength !== undefined, count, maxLength, 'count > maxLength')
139
+
140
+ if (maxLength !== undefined && count > maxLength) {
141
+ quill.deleteText(maxLength, count - maxLength);
142
+ return;
143
+ }
144
+ onChange?.(quill.root.innerHTML);
145
+ onCharacterCountChange?.(count);
126
146
  }
127
147
  });
128
148
 
@@ -167,7 +187,7 @@ const QuillComponent: React.FC<QuillComponentProps> = ({
167
187
  }
168
188
  }, 2000);
169
189
  }
170
- }, [quill, onChange, handleImageUpload]);
190
+ }, [quill, onChange, handleImageUpload, onCharacterCountChange]);
171
191
 
172
192
  useEffect(() => {
173
193
  if (quill) {
@@ -23,7 +23,10 @@ export interface RichEditorProps {
23
23
  label?: string;
24
24
  disabled?: boolean;
25
25
  className?: string;
26
- uploadConfig: UploadConfig;
26
+ uploadConfig?: UploadConfig;
27
+ simpleVersion?: boolean;
28
+ onCharacterCountChange?: (count: number) => void;
29
+ maxLength?: number;
27
30
  }
28
31
 
29
32
  const RichEditor = (props: RichEditorProps) => {