@lets-events/react 12.1.3 → 12.1.5

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