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