@lets-events/react 12.1.4 → 12.1.6

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.
@@ -0,0 +1,451 @@
1
+ import {
2
+ Flex,
3
+ Text,
4
+ UploadService,
5
+ __async,
6
+ styled,
7
+ useToast
8
+ } from "./chunk-TU7LKUXZ.mjs";
9
+
10
+ // src/components/RichEditor/QuillComponent.tsx
11
+ import { useState, useRef, useEffect, useCallback } from "react";
12
+ import { useQuill } from "react-quilljs";
13
+ import "quill/dist/quill.snow.css";
14
+
15
+ // src/components/RichEditor/styledComponents.ts
16
+ var QuillContainer = styled("div", {
17
+ display: "flex",
18
+ flexDirection: "column"
19
+ });
20
+ var QuillEditor = styled("div", {
21
+ "& .ql-editor": {
22
+ minHeight: "200px",
23
+ padding: "$12",
24
+ fontSize: "$14",
25
+ lineHeight: "$base",
26
+ fontFamily: "$default",
27
+ color: "$neutral900",
28
+ backgroundColor: "$white",
29
+ border: "none",
30
+ outline: "none",
31
+ cursor: "text",
32
+ caretColor: "$primary500",
33
+ "&:focus": {
34
+ borderColor: "$primary500",
35
+ boxShadow: "0 0 0 1px $primary500"
36
+ },
37
+ "& p": {
38
+ margin: "0 0 $8 0"
39
+ },
40
+ "& p:last-child": {
41
+ marginBottom: 0
42
+ },
43
+ "& .ql-cursor": {
44
+ borderLeft: "2px solid $primary500"
45
+ }
46
+ },
47
+ "& .ql-toolbar": {
48
+ backgroundColor: "$grey100",
49
+ border: "1px solid $neutral300",
50
+ borderBottom: "none",
51
+ borderTopLeftRadius: "$sm",
52
+ borderTopRightRadius: "$sm",
53
+ padding: "$8 $12"
54
+ },
55
+ "& .ql-container": {
56
+ border: "1px solid $neutral300",
57
+ borderTop: "none",
58
+ borderBottomLeftRadius: "$sm",
59
+ borderBottomRightRadius: "$sm",
60
+ fontFamily: "$default"
61
+ },
62
+ "& .ql-snow .ql-picker.ql-header .ql-picker-item[data-value='1']::before": {
63
+ content: "T\xEDtulo 1"
64
+ },
65
+ "& .ql-snow .ql-picker.ql-header .ql-picker-item[data-value='2']::before": {
66
+ content: "T\xEDtulo 2"
67
+ }
68
+ });
69
+
70
+ // src/components/RichEditor/QuillComponent.tsx
71
+ import { jsx, jsxs } from "react/jsx-runtime";
72
+ var QuillComponent = ({
73
+ value = "",
74
+ onChange,
75
+ placeholder = "Digite seu texto aqui...",
76
+ disabled = false,
77
+ className,
78
+ uploadConfig,
79
+ simpleVersion = false,
80
+ onCharacterCountChange
81
+ }) => {
82
+ const [showVideoModal, setShowVideoModal] = useState(false);
83
+ const [videoUrl, setVideoUrl] = useState("");
84
+ const [showLinkModal, setShowLinkModal] = useState(false);
85
+ const [linkUrl, setLinkUrl] = useState("");
86
+ const videoModalRef = useRef(null);
87
+ const linkModalRef = useRef(null);
88
+ const { addToast, removeToast } = useToast();
89
+ const modules = simpleVersion ? {
90
+ toolbar: [
91
+ ["bold", "italic", "underline"],
92
+ [{ list: "ordered" }, { list: "bullet" }],
93
+ ["link"]
94
+ ],
95
+ clipboard: {
96
+ matchVisual: false
97
+ }
98
+ } : {
99
+ toolbar: [
100
+ [{ header: [1, 2, false] }],
101
+ ["bold", "italic", "underline", "strike"],
102
+ [{ color: [] }, { background: [] }],
103
+ [{ align: [] }],
104
+ [{ list: "ordered" }, { list: "bullet" }],
105
+ ["link", "image", "video"]
106
+ ],
107
+ clipboard: {
108
+ matchVisual: false
109
+ }
110
+ };
111
+ const formats = simpleVersion ? ["bold", "italic", "underline", "list", "link"] : [
112
+ "header",
113
+ "bold",
114
+ "italic",
115
+ "underline",
116
+ "strike",
117
+ "color",
118
+ "background",
119
+ "align",
120
+ "list",
121
+ "link",
122
+ "image",
123
+ "video"
124
+ ];
125
+ const { quill, quillRef } = useQuill({
126
+ theme: "snow",
127
+ modules,
128
+ formats,
129
+ placeholder,
130
+ readOnly: disabled
131
+ });
132
+ const handleImageUpload = useCallback(
133
+ (file) => __async(null, null, function* () {
134
+ if (disabled || !quill || !uploadConfig) return;
135
+ try {
136
+ addToast({
137
+ type: "info",
138
+ message: "Carregando imagem...",
139
+ duration: 2e3
140
+ });
141
+ const uploadedFile = yield UploadService.uploadToS3(file, uploadConfig);
142
+ removeToast("info");
143
+ addToast({
144
+ type: "success",
145
+ message: "Imagem adicionada com sucesso!"
146
+ });
147
+ const selection = quill.getSelection();
148
+ const index = selection ? selection.index : quill.getLength();
149
+ quill.insertEmbed(index, "image", uploadedFile.url);
150
+ quill.setSelection(index + 1, 0);
151
+ } catch (error) {
152
+ console.error("Erro no upload:", error);
153
+ addToast({
154
+ type: "error",
155
+ message: "Erro no upload: N\xE3o foi poss\xEDvel enviar a imagem. Tente novamente."
156
+ });
157
+ }
158
+ }),
159
+ [disabled, quill, addToast, removeToast, uploadConfig]
160
+ );
161
+ useEffect(() => {
162
+ if (quill && value) {
163
+ const currentContent = quill.root.innerHTML;
164
+ if (currentContent !== value) {
165
+ const selection = quill.getSelection();
166
+ quill.clipboard.dangerouslyPasteHTML(value);
167
+ if (selection) {
168
+ quill.setSelection(selection.index, selection.length);
169
+ } else {
170
+ quill.setSelection(quill.getLength(), 0);
171
+ }
172
+ }
173
+ }
174
+ }, [quill, value]);
175
+ useEffect(() => {
176
+ if (quill) {
177
+ quill.on("text-change", (delta, oldDelta, source) => {
178
+ if (source === "user") {
179
+ const html = quill.root.innerHTML;
180
+ onChange == null ? void 0 : onChange(html);
181
+ const text = quill.getText();
182
+ onCharacterCountChange == null ? void 0 : onCharacterCountChange(text.trim().length);
183
+ }
184
+ });
185
+ const toolbar = quill.getModule("toolbar");
186
+ if (toolbar) {
187
+ toolbar.addHandler("link", () => setShowLinkModal(true));
188
+ toolbar.addHandler("video", () => setShowVideoModal(true));
189
+ toolbar.addHandler("image", () => {
190
+ const input = document.createElement("input");
191
+ input.setAttribute("type", "file");
192
+ input.setAttribute("accept", "image/*");
193
+ input.click();
194
+ input.onchange = () => __async(null, null, function* () {
195
+ var _a;
196
+ const file = (_a = input.files) == null ? void 0 : _a[0];
197
+ if (file) {
198
+ yield handleImageUpload(file);
199
+ }
200
+ });
201
+ });
202
+ }
203
+ setTimeout(() => {
204
+ var _a, _b;
205
+ const toolbarElement = (_b = (_a = quillRef.current) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.querySelector(".ql-toolbar");
206
+ if (toolbarElement) {
207
+ const headerSelect = toolbarElement.querySelector(
208
+ "select[data-value]"
209
+ );
210
+ if (headerSelect) {
211
+ const options = headerSelect.querySelectorAll("option");
212
+ options.forEach((option) => {
213
+ if (option.value === "1") {
214
+ option.textContent = "T\xEDtulo 1";
215
+ } else if (option.value === "2") {
216
+ option.textContent = "T\xEDtulo 2";
217
+ } else if (option.value === "") {
218
+ option.textContent = "Normal";
219
+ }
220
+ });
221
+ }
222
+ }
223
+ }, 2e3);
224
+ }
225
+ }, [quill, onChange, handleImageUpload, onCharacterCountChange]);
226
+ useEffect(() => {
227
+ if (quill) {
228
+ quill.enable(!disabled);
229
+ if (!disabled) {
230
+ if (quill.getLength() <= 1) {
231
+ quill.focus();
232
+ quill.setSelection(0, 0);
233
+ }
234
+ }
235
+ }
236
+ }, [quill, disabled]);
237
+ const handleLinkCancel = useCallback(() => {
238
+ setLinkUrl("");
239
+ setShowLinkModal(false);
240
+ }, []);
241
+ const handleLinkSubmit = useCallback(() => {
242
+ if (!linkUrl.trim() || !quill) return;
243
+ const url = linkUrl.trim();
244
+ const selection = quill.getSelection();
245
+ if (selection && selection.length > 0) {
246
+ quill.format("link", url);
247
+ } else {
248
+ const index = quill.getLength();
249
+ quill.insertText(index, url, "link", url);
250
+ quill.setSelection(index + url.length, 0);
251
+ }
252
+ setLinkUrl("");
253
+ setShowLinkModal(false);
254
+ }, [linkUrl, quill]);
255
+ const handleVideoCancel = useCallback(() => {
256
+ setVideoUrl("");
257
+ setShowVideoModal(false);
258
+ }, []);
259
+ const handleVideoSubmit = useCallback(() => {
260
+ var _a, _b;
261
+ if (!videoUrl.trim() || !quill) return;
262
+ let processedUrl = videoUrl.trim();
263
+ if (processedUrl.includes("youtube.com/watch")) {
264
+ const videoId = (_a = processedUrl.match(/[?&]v=([^&]+)/)) == null ? void 0 : _a[1];
265
+ if (videoId) {
266
+ processedUrl = `https://www.youtube.com/embed/${videoId}`;
267
+ }
268
+ } else if (processedUrl.includes("youtu.be/")) {
269
+ const videoId = (_b = processedUrl.split("youtu.be/")[1]) == null ? void 0 : _b.split("?")[0];
270
+ if (videoId) {
271
+ processedUrl = `https://www.youtube.com/embed/${videoId}`;
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
+ const selection = quill.getSelection();
285
+ const insertIndex = selection ? selection.index : quill.getLength();
286
+ quill.clipboard.dangerouslyPasteHTML(insertIndex, videoHTML);
287
+ quill.setSelection(insertIndex + 1, 0);
288
+ setVideoUrl("");
289
+ setShowVideoModal(false);
290
+ }, [videoUrl, quill]);
291
+ useEffect(() => {
292
+ const handleClickOutside = (event) => {
293
+ if (showVideoModal && videoModalRef.current && !videoModalRef.current.contains(event.target)) {
294
+ handleVideoCancel();
295
+ }
296
+ if (showLinkModal && linkModalRef.current && !linkModalRef.current.contains(event.target)) {
297
+ handleLinkCancel();
298
+ }
299
+ };
300
+ document.addEventListener("mousedown", handleClickOutside);
301
+ return () => document.removeEventListener("mousedown", handleClickOutside);
302
+ }, [showVideoModal, showLinkModal, handleVideoCancel, handleLinkCancel]);
303
+ return /* @__PURE__ */ jsx(QuillContainer, { className, children: /* @__PURE__ */ jsxs(QuillEditor, { style: { position: "relative" }, children: [
304
+ /* @__PURE__ */ jsx("div", { ref: quillRef }),
305
+ showVideoModal && /* @__PURE__ */ jsx(
306
+ "div",
307
+ {
308
+ ref: videoModalRef,
309
+ style: {
310
+ position: "absolute",
311
+ top: "20px",
312
+ left: "20px",
313
+ right: "20px",
314
+ backgroundColor: "white",
315
+ border: "1px solid #e0e0e0",
316
+ borderRadius: "4px",
317
+ padding: "12px",
318
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
319
+ zIndex: 1e3,
320
+ width: "fit-content"
321
+ },
322
+ children: /* @__PURE__ */ jsxs(Flex, { gap: 8, align: "center", children: [
323
+ /* @__PURE__ */ jsx(
324
+ Text,
325
+ {
326
+ style: { fontSize: "14px", fontWeight: "500", color: "#333" },
327
+ children: "V\xEDdeo:"
328
+ }
329
+ ),
330
+ /* @__PURE__ */ jsx(
331
+ "input",
332
+ {
333
+ type: "text",
334
+ value: videoUrl,
335
+ onChange: (e) => setVideoUrl(e.target.value),
336
+ placeholder: "Embed URL",
337
+ style: {
338
+ padding: "8px 12px",
339
+ border: "1px solid #d0d0d0",
340
+ borderRadius: "4px",
341
+ fontSize: "14px",
342
+ backgroundColor: "#f8f8f8"
343
+ },
344
+ onKeyDown: (e) => {
345
+ if (e.key === "Enter") {
346
+ handleVideoSubmit();
347
+ } else if (e.key === "Escape") {
348
+ handleVideoCancel();
349
+ }
350
+ },
351
+ autoFocus: true
352
+ }
353
+ ),
354
+ /* @__PURE__ */ jsx(
355
+ "button",
356
+ {
357
+ onClick: handleVideoSubmit,
358
+ disabled: !videoUrl.trim(),
359
+ style: {
360
+ padding: "8px 16px",
361
+ backgroundColor: "#007bff",
362
+ color: "white",
363
+ border: "none",
364
+ borderRadius: "4px",
365
+ fontSize: "14px",
366
+ cursor: videoUrl.trim() ? "pointer" : "not-allowed",
367
+ opacity: videoUrl.trim() ? 1 : 0.6
368
+ },
369
+ children: "Ok"
370
+ }
371
+ )
372
+ ] })
373
+ }
374
+ ),
375
+ showLinkModal && /* @__PURE__ */ jsx(
376
+ "div",
377
+ {
378
+ ref: linkModalRef,
379
+ style: {
380
+ position: "absolute",
381
+ top: "20px",
382
+ left: "20px",
383
+ right: "20px",
384
+ backgroundColor: "white",
385
+ border: "1px solid #e0e0e0",
386
+ borderRadius: "4px",
387
+ padding: "12px",
388
+ boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
389
+ zIndex: 1e3,
390
+ width: "fit-content"
391
+ },
392
+ children: /* @__PURE__ */ jsxs(Flex, { gap: 8, align: "center", children: [
393
+ /* @__PURE__ */ jsx(
394
+ Text,
395
+ {
396
+ style: { fontSize: "14px", fontWeight: "500", color: "#333" },
397
+ children: "Link:"
398
+ }
399
+ ),
400
+ /* @__PURE__ */ jsx(
401
+ "input",
402
+ {
403
+ type: "text",
404
+ value: linkUrl,
405
+ onChange: (e) => setLinkUrl(e.target.value),
406
+ placeholder: "URL do link",
407
+ style: {
408
+ padding: "8px 12px",
409
+ border: "1px solid #d0d0d0",
410
+ borderRadius: "4px",
411
+ fontSize: "14px",
412
+ backgroundColor: "#f8f8f8",
413
+ width: "300px"
414
+ },
415
+ onKeyDown: (e) => {
416
+ if (e.key === "Enter") {
417
+ handleLinkSubmit();
418
+ } else if (e.key === "Escape") {
419
+ handleLinkCancel();
420
+ }
421
+ },
422
+ autoFocus: true
423
+ }
424
+ ),
425
+ /* @__PURE__ */ jsx(
426
+ "button",
427
+ {
428
+ onClick: handleLinkSubmit,
429
+ disabled: !linkUrl.trim(),
430
+ style: {
431
+ padding: "8px 16px",
432
+ backgroundColor: "#007bff",
433
+ color: "white",
434
+ border: "none",
435
+ borderRadius: "4px",
436
+ fontSize: "14px",
437
+ cursor: linkUrl.trim() ? "pointer" : "not-allowed",
438
+ opacity: linkUrl.trim() ? 1 : 0.6
439
+ },
440
+ children: "Ok"
441
+ }
442
+ )
443
+ ] })
444
+ }
445
+ )
446
+ ] }) });
447
+ };
448
+ var QuillComponent_default = QuillComponent;
449
+ export {
450
+ QuillComponent_default as default
451
+ };