@lets-events/react 12.1.9 → 12.1.10

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