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