@lets-events/react 12.2.7 → 12.2.9

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