@lets-events/react 12.2.2 → 12.2.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.
Files changed (99) hide show
  1. package/.eslintrc.json +2 -2
  2. package/.turbo/turbo-build.log +19 -21
  3. package/CHANGELOG.md +6 -0
  4. package/dist/index.css +138 -1023
  5. package/dist/index.js +3 -1
  6. package/dist/index.mjs +3 -1
  7. package/package.json +1 -1
  8. package/src/components/Alert.tsx +303 -303
  9. package/src/components/Avatar.tsx +55 -55
  10. package/src/components/Badge.tsx +125 -125
  11. package/src/components/Box.tsx +3 -3
  12. package/src/components/Button/index.tsx +16 -16
  13. package/src/components/Button/styledComponents.ts +290 -288
  14. package/src/components/ButtonGroup.tsx +484 -484
  15. package/src/components/Calendar/index.tsx +146 -146
  16. package/src/components/Calendar/styledComponents.ts +250 -250
  17. package/src/components/Card.tsx +48 -48
  18. package/src/components/CheckboxGroup.tsx +176 -176
  19. package/src/components/Container.tsx +39 -39
  20. package/src/components/Drawer/index.tsx +138 -138
  21. package/src/components/Drawer/styledComponents.ts +52 -52
  22. package/src/components/Dropdown.tsx +302 -302
  23. package/src/components/Filter.tsx +164 -164
  24. package/src/components/Flex.tsx +118 -118
  25. package/src/components/FormFields/AddressFormFields/CityFormField.tsx +111 -111
  26. package/src/components/FormFields/AddressFormFields/CountryFormField.tsx +33 -33
  27. package/src/components/FormFields/AddressFormFields/PostalCodeFormField.tsx +39 -39
  28. package/src/components/FormFields/AddressFormFields/StateFormField.tsx +32 -32
  29. package/src/components/FormFields/AddressFormFields/index.tsx +141 -141
  30. package/src/components/FormFields/BirthDateFormField.tsx +84 -84
  31. package/src/components/FormFields/CNPJFormField.tsx +87 -87
  32. package/src/components/FormFields/CPFFormField.tsx +78 -78
  33. package/src/components/FormFields/CalendarFormField.tsx +92 -92
  34. package/src/components/FormFields/CheckboxGroupFormField.tsx +91 -91
  35. package/src/components/FormFields/EmailFormField.tsx +27 -27
  36. package/src/components/FormFields/Form.tsx +39 -39
  37. package/src/components/FormFields/IdentityDocumentNumberFormField.tsx +32 -32
  38. package/src/components/FormFields/MultiSelectFormField.tsx +64 -64
  39. package/src/components/FormFields/PhoneFormField.tsx +40 -40
  40. package/src/components/FormFields/RadioGroupFormField.tsx +84 -84
  41. package/src/components/FormFields/RichEditorFormField.tsx +98 -98
  42. package/src/components/FormFields/SelectFormField.tsx +93 -93
  43. package/src/components/FormFields/SwitchFormField.tsx +46 -46
  44. package/src/components/FormFields/TextAreaFormField.tsx +57 -57
  45. package/src/components/FormFields/TextFormField.tsx +112 -112
  46. package/src/components/FormFields/TimePickerFormField.tsx +88 -88
  47. package/src/components/FormFields/subComponents/ErrorFormMessage.tsx +36 -36
  48. package/src/components/FormFields/subComponents/FormLabel.tsx +29 -29
  49. package/src/components/FormFields/utils/validation.ts +23 -23
  50. package/src/components/Grid.tsx +137 -137
  51. package/src/components/Icon.tsx +47 -47
  52. package/src/components/MenuDropdown/index.tsx +38 -38
  53. package/src/components/MenuDropdown/styledComponents.ts +31 -31
  54. package/src/components/Modal.tsx +90 -90
  55. package/src/components/MultiSelect/index.tsx +243 -243
  56. package/src/components/MultiSelect/styledComponents.ts +160 -160
  57. package/src/components/RadioGroup.tsx +210 -210
  58. package/src/components/RichEditor/QuillComponent.tsx +444 -444
  59. package/src/components/RichEditor/RichEditor.tsx +48 -48
  60. package/src/components/RichEditor/index.ts +2 -2
  61. package/src/components/RichEditor/styledComponents.ts +1151 -1151
  62. package/src/components/Section.tsx +33 -33
  63. package/src/components/Step.tsx +164 -164
  64. package/src/components/Switch.tsx +108 -108
  65. package/src/components/Text.tsx +38 -38
  66. package/src/components/TextField.tsx +372 -372
  67. package/src/components/TextareaField.tsx +127 -127
  68. package/src/components/TimePicker.tsx +328 -328
  69. package/src/components/Toast/components/ToastItem.tsx +41 -41
  70. package/src/components/Toast/components/ToastProvider.tsx +63 -63
  71. package/src/components/Toast/hooks/useToast.ts +12 -12
  72. package/src/components/Toast/index.tsx +5 -5
  73. package/src/components/Toast/styles/index.ts +135 -135
  74. package/src/components/Toast/types/index.ts +46 -46
  75. package/src/components/Tooltip/index.tsx +66 -66
  76. package/src/components/Tooltip/styles.ts +77 -77
  77. package/src/hooks/useCountries.ts +41 -41
  78. package/src/hooks/useImageUpload.ts +139 -139
  79. package/src/hooks/useOnClickOutside.tsx +42 -42
  80. package/src/index.tsx +68 -68
  81. package/src/styles/index.ts +38 -38
  82. package/src/types/typographyValues.ts +178 -178
  83. package/src/utils/getNestedValue.ts +3 -3
  84. package/src/utils/states.ts +29 -29
  85. package/src/utils/uploadService.ts +180 -180
  86. package/tsconfig.json +3 -3
  87. package/tsup.config.ts +38 -38
  88. package/dist/QuillComponent-2YO26WOT.mjs +0 -458
  89. package/dist/QuillComponent-36H54CRL.mjs +0 -451
  90. package/dist/QuillComponent-A5KIFPCL.mjs +0 -438
  91. package/dist/QuillComponent-C2NXFWIZ.mjs +0 -459
  92. package/dist/QuillComponent-EIWPUIIH.mjs +0 -456
  93. package/dist/QuillComponent-FPVFLYUK.mjs +0 -448
  94. package/dist/QuillComponent-O5RSHCDS.mjs +0 -459
  95. package/dist/QuillComponent-PPWKGS74.mjs +0 -452
  96. package/dist/QuillComponent-QFVVQA6K.mjs +0 -459
  97. package/dist/QuillComponent-TLIZCM6V.mjs +0 -458
  98. package/dist/QuillComponent-ZLQ2VKPD.mjs +0 -457
  99. package/dist/chunk-TU7LKUXZ.mjs +0 -1927
@@ -1,444 +1,444 @@
1
- import React, { useState, useRef, useEffect, useCallback } from "react";
2
- import { useQuill } from "react-quilljs";
3
- import { Flex } from "../Flex";
4
- import { Text } from "../Text";
5
- import { RichEditorProps } from "./RichEditor";
6
- import { useToast } from "../Toast/hooks/useToast";
7
- import { UploadService } from "../../utils/uploadService";
8
- import { QuillContainer, QuillEditor } from "./styledComponents";
9
-
10
- const QuillComponent: React.FC<RichEditorProps> = ({
11
- value = "",
12
- onChange,
13
- placeholder = "Digite seu texto aqui...",
14
- disabled = false,
15
- className,
16
- uploadConfig,
17
- simpleVersion = false,
18
- onCharacterCountChange,
19
- maxLength,
20
- }) => {
21
- const [showVideoModal, setShowVideoModal] = useState(false);
22
- const [videoUrl, setVideoUrl] = useState("");
23
- const [showLinkModal, setShowLinkModal] = useState(false);
24
- const [linkUrl, setLinkUrl] = useState("");
25
-
26
- const videoModalRef = useRef<HTMLDivElement>(null);
27
- const linkModalRef = useRef<HTMLDivElement>(null);
28
- const { addToast, removeToast } = useToast();
29
- const formatHTML = (html: string) => {
30
- const parser = new DOMParser();
31
- const doc = parser.parseFromString(html, "text/html");
32
-
33
- doc.querySelectorAll("h1").forEach((h1) => {
34
- h1.setAttribute("style", `${h1.getAttribute("style") || ""}line-height: 2em;`);
35
- });
36
-
37
- doc.querySelectorAll("img").forEach((img) => {
38
- img.setAttribute("style", `${img.getAttribute("style") || ""}max-width: 100%; height: auto; width: auto;`);
39
- });
40
-
41
- return doc.body.innerHTML;
42
- };
43
- const modules = simpleVersion
44
- ? {
45
- toolbar: [
46
- ["bold", "italic", "underline"],
47
- [{ list: "ordered" }, { list: "bullet" }],
48
- ["link"],
49
- ],
50
- clipboard: {
51
- matchVisual: false,
52
- },
53
- }
54
- : {
55
- toolbar: [
56
- [{ header: [1, 2, false] }],
57
- ["bold", "italic", "underline", "strike"],
58
- [{ color: [] }, { background: [] }],
59
- [{ align: [] }],
60
- [{ list: "ordered" }, { list: "bullet" }],
61
- ["link", "image", "video"],
62
- ],
63
- clipboard: {
64
- matchVisual: false,
65
- },
66
- };
67
-
68
- const formats = simpleVersion
69
- ? ["bold", "italic", "underline", "list", "link"]
70
- : [
71
- "header",
72
- "bold",
73
- "italic",
74
- "underline",
75
- "strike",
76
- "color",
77
- "background",
78
- "align",
79
- "list",
80
- "link",
81
- "image",
82
- "video",
83
- ];
84
-
85
- const { quill, quillRef } = useQuill({
86
- theme: "snow",
87
- modules,
88
- formats,
89
- placeholder,
90
- readOnly: disabled,
91
- });
92
-
93
- const handleImageUpload = useCallback(
94
- async (file: File) => {
95
- if (disabled || !quill || !uploadConfig) return;
96
-
97
- try {
98
- addToast({
99
- type: "info",
100
- message: "Carregando imagem...",
101
- duration: 2000,
102
- });
103
-
104
- const uploadedFile = await UploadService.uploadToS3(file, uploadConfig);
105
- removeToast("info");
106
- addToast({
107
- type: "success",
108
- message: "Imagem adicionada com sucesso!",
109
- });
110
-
111
- const selection = quill.getSelection();
112
- const index = selection ? selection.index : quill.getLength();
113
- quill.insertEmbed(index, "image", uploadedFile.url);
114
- quill.setSelection(index + 1, 0);
115
- onChange?.(formatHTML(quill.root.innerHTML));
116
- } catch (error) {
117
- console.error("Erro no upload:", error);
118
- addToast({
119
- type: "error",
120
- message:
121
- "Erro no upload: Não foi possível enviar a imagem. Tente novamente.",
122
- });
123
- }
124
- },
125
- [disabled, quill, addToast, removeToast, uploadConfig]
126
- );
127
-
128
- useEffect(() => {
129
- if (quill && value) {
130
- const currentContent = quill.root.innerHTML;
131
- if (currentContent !== value) {
132
- const selection = quill.getSelection();
133
- quill.clipboard.dangerouslyPasteHTML(value);
134
-
135
- if (selection) {
136
- quill.setSelection(selection.index, selection.length);
137
- } else {
138
- quill.setSelection(quill.getLength(), 0);
139
- }
140
- }
141
- }
142
- }, [quill, value]);
143
-
144
- useEffect(() => {
145
- if (quill) {
146
- quill.on("text-change", (delta: any, oldDelta: any, source: string) => {
147
- if (source === "user") {
148
- const text = quill.getText().trim()
149
- const count = text.length
150
-
151
- if (maxLength !== undefined && count > maxLength) {
152
- quill.deleteText(maxLength, count - maxLength)
153
- return
154
- }
155
- onChange?.(formatHTML(quill.root.innerHTML))
156
- onCharacterCountChange?.(count)
157
- }
158
- });
159
-
160
- const toolbar = quill.getModule("toolbar") as any;
161
- if (toolbar) {
162
- toolbar.addHandler("link", () => setShowLinkModal(true));
163
- toolbar.addHandler("video", () => setShowVideoModal(true));
164
- toolbar.addHandler("image", () => {
165
- const input = document.createElement("input");
166
- input.setAttribute("type", "file");
167
- input.setAttribute("accept", "image/*");
168
- input.click();
169
-
170
- input.onchange = async () => {
171
- const file = input.files?.[0];
172
- if (file) {
173
- await handleImageUpload(file);
174
- }
175
- };
176
- });
177
- }
178
-
179
- setTimeout(() => {
180
- const toolbarElement =
181
- quillRef.current?.parentElement?.querySelector(".ql-toolbar");
182
- if (toolbarElement) {
183
- const headerSelect = toolbarElement.querySelector(
184
- "select[data-value]"
185
- ) as HTMLSelectElement;
186
- if (headerSelect) {
187
- const options = headerSelect.querySelectorAll("option");
188
- options.forEach((option) => {
189
- if (option.value === "1") {
190
- option.textContent = "Título 1";
191
- } else if (option.value === "2") {
192
- option.textContent = "Título 2";
193
- } else if (option.value === "") {
194
- option.textContent = "Normal";
195
- }
196
- });
197
- }
198
- }
199
- }, 2000);
200
- }
201
- }, [quill, onChange, handleImageUpload, onCharacterCountChange]);
202
-
203
- useEffect(() => {
204
- if (quill) {
205
- quill.enable(!disabled);
206
-
207
- if (!disabled) {
208
- if (quill.getLength() <= 1) {
209
- quill.focus();
210
- quill.setSelection(0, 0);
211
- }
212
- }
213
- }
214
- }, [quill, disabled]);
215
-
216
- const handleLinkCancel = useCallback(() => {
217
- setLinkUrl("");
218
- setShowLinkModal(false);
219
- }, []);
220
-
221
- const handleLinkSubmit = useCallback(() => {
222
- if (!linkUrl.trim() || !quill) return;
223
-
224
- const url = linkUrl.trim();
225
- const selection = quill.getSelection();
226
-
227
- if (selection && selection.length > 0) {
228
- quill.format("link", url);
229
- } else {
230
- const index = quill.getLength();
231
- quill.insertText(index, url, "link", url);
232
- quill.setSelection(index + url.length, 0);
233
- }
234
-
235
- setLinkUrl("");
236
- setShowLinkModal(false);
237
- }, [linkUrl, quill]);
238
-
239
- const handleVideoCancel = useCallback(() => {
240
- setVideoUrl("");
241
- setShowVideoModal(false);
242
- }, []);
243
-
244
- const handleVideoSubmit = useCallback(() => {
245
- if (!videoUrl.trim() || !quill) return;
246
-
247
- let processedUrl = videoUrl.trim();
248
-
249
- if (processedUrl.includes("youtube.com/watch")) {
250
- const videoId = processedUrl.match(/[?&]v=([^&]+)/)?.[1];
251
- if (videoId) {
252
- processedUrl = `https://www.youtube.com/embed/${videoId}`;
253
- }
254
- } else if (processedUrl.includes("youtu.be/")) {
255
- const videoId = processedUrl.split("youtu.be/")[1]?.split("?")[0];
256
- if (videoId) {
257
- processedUrl = `https://www.youtube.com/embed/${videoId}`;
258
- }
259
- }
260
-
261
- const videoHTML = `
262
- <iframe
263
- src="${processedUrl}"
264
- style="max-width:100%; height:315px; border:0;"
265
- title="Video player"
266
- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
267
- allowfullscreen>
268
- </iframe>
269
- <br/>
270
- `;
271
-
272
- const selection = quill.getSelection();
273
- const insertIndex = selection ? selection.index : quill.getLength();
274
- quill.clipboard.dangerouslyPasteHTML(insertIndex, videoHTML);
275
- quill.setSelection(insertIndex + 1, 0);
276
-
277
- setVideoUrl("");
278
- setShowVideoModal(false);
279
- }, [videoUrl, quill]);
280
-
281
- useEffect(() => {
282
- const handleClickOutside = (event: MouseEvent) => {
283
- if (
284
- showVideoModal &&
285
- videoModalRef.current &&
286
- !videoModalRef.current.contains(event.target as Node)
287
- ) {
288
- handleVideoCancel();
289
- }
290
-
291
- if (
292
- showLinkModal &&
293
- linkModalRef.current &&
294
- !linkModalRef.current.contains(event.target as Node)
295
- ) {
296
- handleLinkCancel();
297
- }
298
- };
299
-
300
- document.addEventListener("mousedown", handleClickOutside);
301
- return () => document.removeEventListener("mousedown", handleClickOutside);
302
- }, [showVideoModal, showLinkModal, handleVideoCancel, handleLinkCancel]);
303
-
304
- return (
305
- <QuillContainer className={className}>
306
- <QuillEditor style={{ position: "relative" }}>
307
- <div ref={quillRef} />
308
-
309
- {/* Video Modal */}
310
- {showVideoModal && (
311
- <div
312
- ref={videoModalRef}
313
- style={{
314
- position: "absolute",
315
- top: "20px",
316
- left: "20px",
317
- right: "20px",
318
- backgroundColor: "white",
319
- border: "1px solid #e0e0e0",
320
- borderRadius: "4px",
321
- padding: "12px",
322
- boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
323
- zIndex: 1000,
324
- width: "fit-content",
325
- }}
326
- >
327
- <Flex gap={8} align="center">
328
- <Text
329
- style={{ fontSize: "14px", fontWeight: "500", color: "#333" }}
330
- >
331
- Vídeo:
332
- </Text>
333
- <input
334
- type="text"
335
- value={videoUrl}
336
- onChange={(e) => setVideoUrl(e.target.value)}
337
- placeholder="Embed URL"
338
- style={{
339
- padding: "8px 12px",
340
- border: "1px solid #d0d0d0",
341
- borderRadius: "4px",
342
- fontSize: "14px",
343
- backgroundColor: "#f8f8f8",
344
- }}
345
- onKeyDown={(e) => {
346
- if (e.key === "Enter") {
347
- handleVideoSubmit();
348
- } else if (e.key === "Escape") {
349
- handleVideoCancel();
350
- }
351
- }}
352
- autoFocus
353
- />
354
- <button
355
- onClick={handleVideoSubmit}
356
- disabled={!videoUrl.trim()}
357
- style={{
358
- padding: "8px 16px",
359
- backgroundColor: "#007bff",
360
- color: "white",
361
- border: "none",
362
- borderRadius: "4px",
363
- fontSize: "14px",
364
- cursor: videoUrl.trim() ? "pointer" : "not-allowed",
365
- opacity: videoUrl.trim() ? 1 : 0.6,
366
- }}
367
- >
368
- Ok
369
- </button>
370
- </Flex>
371
- </div>
372
- )}
373
-
374
- {/* Link Modal */}
375
- {showLinkModal && (
376
- <div
377
- ref={linkModalRef}
378
- style={{
379
- position: "absolute",
380
- top: "20px",
381
- left: "20px",
382
- right: "20px",
383
- backgroundColor: "white",
384
- border: "1px solid #e0e0e0",
385
- borderRadius: "4px",
386
- padding: "12px",
387
- boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
388
- zIndex: 1000,
389
- width: "fit-content",
390
- }}
391
- >
392
- <Flex gap={8} align="center">
393
- <Text
394
- style={{ fontSize: "14px", fontWeight: "500", color: "#333" }}
395
- >
396
- Link:
397
- </Text>
398
- <input
399
- type="text"
400
- value={linkUrl}
401
- onChange={(e) => setLinkUrl(e.target.value)}
402
- placeholder="URL do link"
403
- style={{
404
- padding: "8px 12px",
405
- border: "1px solid #d0d0d0",
406
- borderRadius: "4px",
407
- fontSize: "14px",
408
- backgroundColor: "#f8f8f8",
409
- width: "300px",
410
- }}
411
- onKeyDown={(e) => {
412
- if (e.key === "Enter") {
413
- handleLinkSubmit();
414
- } else if (e.key === "Escape") {
415
- handleLinkCancel();
416
- }
417
- }}
418
- autoFocus
419
- />
420
- <button
421
- onClick={handleLinkSubmit}
422
- disabled={!linkUrl.trim()}
423
- style={{
424
- padding: "8px 16px",
425
- backgroundColor: "#007bff",
426
- color: "white",
427
- border: "none",
428
- borderRadius: "4px",
429
- fontSize: "14px",
430
- cursor: linkUrl.trim() ? "pointer" : "not-allowed",
431
- opacity: linkUrl.trim() ? 1 : 0.6,
432
- }}
433
- >
434
- Ok
435
- </button>
436
- </Flex>
437
- </div>
438
- )}
439
- </QuillEditor>
440
- </QuillContainer>
441
- );
442
- };
443
-
444
- export default QuillComponent;
1
+ import React, { useState, useRef, useEffect, useCallback } from "react";
2
+ import { useQuill } from "react-quilljs";
3
+ import { Flex } from "../Flex";
4
+ import { Text } from "../Text";
5
+ import { RichEditorProps } from "./RichEditor";
6
+ import { useToast } from "../Toast/hooks/useToast";
7
+ import { UploadService } from "../../utils/uploadService";
8
+ import { QuillContainer, QuillEditor } from "./styledComponents";
9
+
10
+ const QuillComponent: React.FC<RichEditorProps> = ({
11
+ value = "",
12
+ onChange,
13
+ placeholder = "Digite seu texto aqui...",
14
+ disabled = false,
15
+ className,
16
+ uploadConfig,
17
+ simpleVersion = false,
18
+ onCharacterCountChange,
19
+ maxLength,
20
+ }) => {
21
+ const [showVideoModal, setShowVideoModal] = useState(false);
22
+ const [videoUrl, setVideoUrl] = useState("");
23
+ const [showLinkModal, setShowLinkModal] = useState(false);
24
+ const [linkUrl, setLinkUrl] = useState("");
25
+
26
+ const videoModalRef = useRef<HTMLDivElement>(null);
27
+ const linkModalRef = useRef<HTMLDivElement>(null);
28
+ const { addToast, removeToast } = useToast();
29
+ const formatHTML = (html: string) => {
30
+ const parser = new DOMParser();
31
+ const doc = parser.parseFromString(html, "text/html");
32
+
33
+ doc.querySelectorAll("h1").forEach((h1) => {
34
+ h1.setAttribute("style", `${h1.getAttribute("style") || ""}line-height: 2em;`);
35
+ });
36
+
37
+ doc.querySelectorAll("img").forEach((img) => {
38
+ img.setAttribute("style", `${img.getAttribute("style") || ""}max-width: 100%; height: auto; width: auto;`);
39
+ });
40
+
41
+ return doc.body.innerHTML;
42
+ };
43
+ const modules = simpleVersion
44
+ ? {
45
+ toolbar: [
46
+ ["bold", "italic", "underline"],
47
+ [{ list: "ordered" }, { list: "bullet" }],
48
+ ["link"],
49
+ ],
50
+ clipboard: {
51
+ matchVisual: false,
52
+ },
53
+ }
54
+ : {
55
+ toolbar: [
56
+ [{ header: [1, 2, false] }],
57
+ ["bold", "italic", "underline", "strike"],
58
+ [{ color: [] }, { background: [] }],
59
+ [{ align: [] }],
60
+ [{ list: "ordered" }, { list: "bullet" }],
61
+ ["link", "image", "video"],
62
+ ],
63
+ clipboard: {
64
+ matchVisual: false,
65
+ },
66
+ };
67
+
68
+ const formats = simpleVersion
69
+ ? ["bold", "italic", "underline", "list", "link"]
70
+ : [
71
+ "header",
72
+ "bold",
73
+ "italic",
74
+ "underline",
75
+ "strike",
76
+ "color",
77
+ "background",
78
+ "align",
79
+ "list",
80
+ "link",
81
+ "image",
82
+ "video",
83
+ ];
84
+
85
+ const { quill, quillRef } = useQuill({
86
+ theme: "snow",
87
+ modules,
88
+ formats,
89
+ placeholder,
90
+ readOnly: disabled,
91
+ });
92
+
93
+ const handleImageUpload = useCallback(
94
+ async (file: File) => {
95
+ if (disabled || !quill || !uploadConfig) return;
96
+
97
+ try {
98
+ addToast({
99
+ type: "info",
100
+ message: "Carregando imagem...",
101
+ duration: 2000,
102
+ });
103
+
104
+ const uploadedFile = await UploadService.uploadToS3(file, uploadConfig);
105
+ removeToast("info");
106
+ addToast({
107
+ type: "success",
108
+ message: "Imagem adicionada com sucesso!",
109
+ });
110
+
111
+ const selection = quill.getSelection();
112
+ const index = selection ? selection.index : quill.getLength();
113
+ quill.insertEmbed(index, "image", uploadedFile.url);
114
+ quill.setSelection(index + 1, 0);
115
+ onChange?.(formatHTML(quill.root.innerHTML));
116
+ } catch (error) {
117
+ console.error("Erro no upload:", error);
118
+ addToast({
119
+ type: "error",
120
+ message:
121
+ "Erro no upload: Não foi possível enviar a imagem. Tente novamente.",
122
+ });
123
+ }
124
+ },
125
+ [disabled, quill, addToast, removeToast, uploadConfig]
126
+ );
127
+
128
+ useEffect(() => {
129
+ if (quill && value) {
130
+ const currentContent = quill.root.innerHTML;
131
+ if (currentContent !== value) {
132
+ const selection = quill.getSelection();
133
+ quill.clipboard.dangerouslyPasteHTML(value);
134
+
135
+ if (selection) {
136
+ quill.setSelection(selection.index, selection.length);
137
+ } else {
138
+ quill.setSelection(quill.getLength(), 0);
139
+ }
140
+ }
141
+ }
142
+ }, [quill, value]);
143
+
144
+ useEffect(() => {
145
+ if (quill) {
146
+ quill.on("text-change", (delta: any, oldDelta: any, source: string) => {
147
+ if (source === "user") {
148
+ const text = quill.getText().trim()
149
+ const count = text.length
150
+
151
+ if (maxLength !== undefined && count > maxLength) {
152
+ quill.deleteText(maxLength, count - maxLength)
153
+ return
154
+ }
155
+ onChange?.(formatHTML(quill.root.innerHTML))
156
+ onCharacterCountChange?.(count)
157
+ }
158
+ });
159
+
160
+ const toolbar = quill.getModule("toolbar") as any;
161
+ if (toolbar) {
162
+ toolbar.addHandler("link", () => setShowLinkModal(true));
163
+ toolbar.addHandler("video", () => setShowVideoModal(true));
164
+ toolbar.addHandler("image", () => {
165
+ const input = document.createElement("input");
166
+ input.setAttribute("type", "file");
167
+ input.setAttribute("accept", "image/*");
168
+ input.click();
169
+
170
+ input.onchange = async () => {
171
+ const file = input.files?.[0];
172
+ if (file) {
173
+ await handleImageUpload(file);
174
+ }
175
+ };
176
+ });
177
+ }
178
+
179
+ setTimeout(() => {
180
+ const toolbarElement =
181
+ quillRef.current?.parentElement?.querySelector(".ql-toolbar");
182
+ if (toolbarElement) {
183
+ const headerSelect = toolbarElement.querySelector(
184
+ "select[data-value]"
185
+ ) as HTMLSelectElement;
186
+ if (headerSelect) {
187
+ const options = headerSelect.querySelectorAll("option");
188
+ options.forEach((option) => {
189
+ if (option.value === "1") {
190
+ option.textContent = "Título 1";
191
+ } else if (option.value === "2") {
192
+ option.textContent = "Título 2";
193
+ } else if (option.value === "") {
194
+ option.textContent = "Normal";
195
+ }
196
+ });
197
+ }
198
+ }
199
+ }, 2000);
200
+ }
201
+ }, [quill, onChange, handleImageUpload, onCharacterCountChange]);
202
+
203
+ useEffect(() => {
204
+ if (quill) {
205
+ quill.enable(!disabled);
206
+
207
+ if (!disabled) {
208
+ if (quill.getLength() <= 1) {
209
+ quill.focus();
210
+ quill.setSelection(0, 0);
211
+ }
212
+ }
213
+ }
214
+ }, [quill, disabled]);
215
+
216
+ const handleLinkCancel = useCallback(() => {
217
+ setLinkUrl("");
218
+ setShowLinkModal(false);
219
+ }, []);
220
+
221
+ const handleLinkSubmit = useCallback(() => {
222
+ if (!linkUrl.trim() || !quill) return;
223
+
224
+ const url = linkUrl.trim();
225
+ const selection = quill.getSelection();
226
+
227
+ if (selection && selection.length > 0) {
228
+ quill.format("link", url);
229
+ } else {
230
+ const index = quill.getLength();
231
+ quill.insertText(index, url, "link", url);
232
+ quill.setSelection(index + url.length, 0);
233
+ }
234
+
235
+ setLinkUrl("");
236
+ setShowLinkModal(false);
237
+ }, [linkUrl, quill]);
238
+
239
+ const handleVideoCancel = useCallback(() => {
240
+ setVideoUrl("");
241
+ setShowVideoModal(false);
242
+ }, []);
243
+
244
+ const handleVideoSubmit = useCallback(() => {
245
+ if (!videoUrl.trim() || !quill) return;
246
+
247
+ let processedUrl = videoUrl.trim();
248
+
249
+ if (processedUrl.includes("youtube.com/watch")) {
250
+ const videoId = processedUrl.match(/[?&]v=([^&]+)/)?.[1];
251
+ if (videoId) {
252
+ processedUrl = `https://www.youtube.com/embed/${videoId}`;
253
+ }
254
+ } else if (processedUrl.includes("youtu.be/")) {
255
+ const videoId = processedUrl.split("youtu.be/")[1]?.split("?")[0];
256
+ if (videoId) {
257
+ processedUrl = `https://www.youtube.com/embed/${videoId}`;
258
+ }
259
+ }
260
+
261
+ const videoHTML = `
262
+ <iframe
263
+ src="${processedUrl}"
264
+ style="max-width:100%; height:315px; border:0;"
265
+ title="Video player"
266
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
267
+ allowfullscreen>
268
+ </iframe>
269
+ <br/>
270
+ `;
271
+
272
+ const selection = quill.getSelection();
273
+ const insertIndex = selection ? selection.index : quill.getLength();
274
+ quill.clipboard.dangerouslyPasteHTML(insertIndex, videoHTML);
275
+ quill.setSelection(insertIndex + 1, 0);
276
+
277
+ setVideoUrl("");
278
+ setShowVideoModal(false);
279
+ }, [videoUrl, quill]);
280
+
281
+ useEffect(() => {
282
+ const handleClickOutside = (event: MouseEvent) => {
283
+ if (
284
+ showVideoModal &&
285
+ videoModalRef.current &&
286
+ !videoModalRef.current.contains(event.target as Node)
287
+ ) {
288
+ handleVideoCancel();
289
+ }
290
+
291
+ if (
292
+ showLinkModal &&
293
+ linkModalRef.current &&
294
+ !linkModalRef.current.contains(event.target as Node)
295
+ ) {
296
+ handleLinkCancel();
297
+ }
298
+ };
299
+
300
+ document.addEventListener("mousedown", handleClickOutside);
301
+ return () => document.removeEventListener("mousedown", handleClickOutside);
302
+ }, [showVideoModal, showLinkModal, handleVideoCancel, handleLinkCancel]);
303
+
304
+ return (
305
+ <QuillContainer className={className}>
306
+ <QuillEditor style={{ position: "relative" }}>
307
+ <div ref={quillRef} />
308
+
309
+ {/* Video Modal */}
310
+ {showVideoModal && (
311
+ <div
312
+ ref={videoModalRef}
313
+ style={{
314
+ position: "absolute",
315
+ top: "20px",
316
+ left: "20px",
317
+ right: "20px",
318
+ backgroundColor: "white",
319
+ border: "1px solid #e0e0e0",
320
+ borderRadius: "4px",
321
+ padding: "12px",
322
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
323
+ zIndex: 1000,
324
+ width: "fit-content",
325
+ }}
326
+ >
327
+ <Flex gap={8} align="center">
328
+ <Text
329
+ style={{ fontSize: "14px", fontWeight: "500", color: "#333" }}
330
+ >
331
+ Vídeo:
332
+ </Text>
333
+ <input
334
+ type="text"
335
+ value={videoUrl}
336
+ onChange={(e) => setVideoUrl(e.target.value)}
337
+ placeholder="Embed URL"
338
+ style={{
339
+ padding: "8px 12px",
340
+ border: "1px solid #d0d0d0",
341
+ borderRadius: "4px",
342
+ fontSize: "14px",
343
+ backgroundColor: "#f8f8f8",
344
+ }}
345
+ onKeyDown={(e) => {
346
+ if (e.key === "Enter") {
347
+ handleVideoSubmit();
348
+ } else if (e.key === "Escape") {
349
+ handleVideoCancel();
350
+ }
351
+ }}
352
+ autoFocus
353
+ />
354
+ <button
355
+ onClick={handleVideoSubmit}
356
+ disabled={!videoUrl.trim()}
357
+ style={{
358
+ padding: "8px 16px",
359
+ backgroundColor: "#007bff",
360
+ color: "white",
361
+ border: "none",
362
+ borderRadius: "4px",
363
+ fontSize: "14px",
364
+ cursor: videoUrl.trim() ? "pointer" : "not-allowed",
365
+ opacity: videoUrl.trim() ? 1 : 0.6,
366
+ }}
367
+ >
368
+ Ok
369
+ </button>
370
+ </Flex>
371
+ </div>
372
+ )}
373
+
374
+ {/* Link Modal */}
375
+ {showLinkModal && (
376
+ <div
377
+ ref={linkModalRef}
378
+ style={{
379
+ position: "absolute",
380
+ top: "20px",
381
+ left: "20px",
382
+ right: "20px",
383
+ backgroundColor: "white",
384
+ border: "1px solid #e0e0e0",
385
+ borderRadius: "4px",
386
+ padding: "12px",
387
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
388
+ zIndex: 1000,
389
+ width: "fit-content",
390
+ }}
391
+ >
392
+ <Flex gap={8} align="center">
393
+ <Text
394
+ style={{ fontSize: "14px", fontWeight: "500", color: "#333" }}
395
+ >
396
+ Link:
397
+ </Text>
398
+ <input
399
+ type="text"
400
+ value={linkUrl}
401
+ onChange={(e) => setLinkUrl(e.target.value)}
402
+ placeholder="URL do link"
403
+ style={{
404
+ padding: "8px 12px",
405
+ border: "1px solid #d0d0d0",
406
+ borderRadius: "4px",
407
+ fontSize: "14px",
408
+ backgroundColor: "#f8f8f8",
409
+ width: "300px",
410
+ }}
411
+ onKeyDown={(e) => {
412
+ if (e.key === "Enter") {
413
+ handleLinkSubmit();
414
+ } else if (e.key === "Escape") {
415
+ handleLinkCancel();
416
+ }
417
+ }}
418
+ autoFocus
419
+ />
420
+ <button
421
+ onClick={handleLinkSubmit}
422
+ disabled={!linkUrl.trim()}
423
+ style={{
424
+ padding: "8px 16px",
425
+ backgroundColor: "#007bff",
426
+ color: "white",
427
+ border: "none",
428
+ borderRadius: "4px",
429
+ fontSize: "14px",
430
+ cursor: linkUrl.trim() ? "pointer" : "not-allowed",
431
+ opacity: linkUrl.trim() ? 1 : 0.6,
432
+ }}
433
+ >
434
+ Ok
435
+ </button>
436
+ </Flex>
437
+ </div>
438
+ )}
439
+ </QuillEditor>
440
+ </QuillContainer>
441
+ );
442
+ };
443
+
444
+ export default QuillComponent;