@lets-events/react 12.1.5 → 12.1.7

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