@lets-events/react 12.4.1 → 12.5.0

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