react-mail-inbox 1.0.2 → 1.0.4

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.
package/dist/index.mjs CHANGED
@@ -1,2258 +1,3 @@
1
- import { createContext, useContext, useState, useEffect, useRef, useCallback, useMemo } from 'react';
2
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin';
4
- import { LexicalComposer } from '@lexical/react/LexicalComposer';
5
- import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
6
- import { ContentEditable } from '@lexical/react/LexicalContentEditable';
7
- import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
8
- import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
9
- import { createPortal } from 'react-dom';
10
- import { MdClose, MdEdit, MdTextFields, MdCheck, MdImage, MdLink, MdAttachFile, MdTextFormat, MdArrowDropDown, MdFormatQuote, MdStrikethroughS, MdFormatClear, MdOutlineFormatIndentIncrease, MdFormatIndentDecrease, MdFormatListNumbered, MdFormatListBulleted, MdFormatAlignCenter, MdFormatAlignRight, MdFormatAlignLeft, MdFormatUnderlined, MdFormatItalic, MdFormatBold, MdRedo, MdUndo } from 'react-icons/md';
11
- import Popup from 'reactjs-popup';
12
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
13
- import { $getRoot, $getSelection, $isRangeSelection, SELECTION_CHANGE_COMMAND, REDO_COMMAND, UNDO_COMMAND, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, OUTDENT_CONTENT_COMMAND, INDENT_CONTENT_COMMAND } from 'lexical';
14
- import { ListNode, ListItemNode, $isListNode, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND } from '@lexical/list';
15
- import { LinkNode, AutoLinkNode, $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
16
- import { $getNearestNodeOfType, mergeRegister } from '@lexical/utils';
17
- import { $isAtNodeEnd, $patchStyleText } from '@lexical/selection';
18
- import { useDropzone } from 'react-dropzone';
19
- import heic2any from 'heic2any';
20
- import { ListPlugin } from '@lexical/react/LexicalListPlugin';
21
- import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
22
- import { $generateNodesFromDOM, $generateHtmlFromNodes } from '@lexical/html';
23
-
24
- var ThemeContext = createContext(void 0);
25
- var useTheme = () => {
26
- const context = useContext(ThemeContext);
27
- if (!context) {
28
- throw new Error("useTheme must be used within a ThemeProvider");
29
- }
30
- return context;
31
- };
32
- var ThemeProvider = ({
33
- children,
34
- initialTheme = "dark",
35
- onThemeChange
36
- }) => {
37
- const [theme, setTheme] = useState(initialTheme);
38
- useEffect(() => {
39
- if (onThemeChange) {
40
- onThemeChange(theme);
41
- }
42
- }, [theme, onThemeChange]);
43
- const toggleTheme = () => {
44
- setTheme((prev) => prev === "light" ? "dark" : "light");
45
- };
46
- return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: { theme, toggleTheme }, children });
47
- };
48
- var EmailContext = createContext(void 0);
49
- var useEmailContext = () => {
50
- const context = useContext(EmailContext);
51
- if (!context) {
52
- throw new Error("useEmailContext must be used within an EmailProvider");
53
- }
54
- return context;
55
- };
56
- var EmailProvider = ({ children }) => {
57
- const [emails, setEmails] = useState({
58
- to: [],
59
- cc: [],
60
- bcc: []
61
- });
62
- const [isReply, setIsReply] = useState(false);
63
- const [subject, setSubject] = useState("");
64
- const [showCC, setShowCC] = useState(false);
65
- const [showBCC, setShowBCC] = useState(false);
66
- const [attachments, setAttachments] = useState([]);
67
- useEffect(() => {
68
- console.log("EmailProvider emails updated:", emails);
69
- }, [emails]);
70
- return /* @__PURE__ */ jsx(
71
- EmailContext.Provider,
72
- {
73
- value: {
74
- emails,
75
- setEmails,
76
- subject,
77
- setSubject,
78
- showCC,
79
- setShowCC,
80
- showBCC,
81
- setShowBCC,
82
- attachments,
83
- setAttachments,
84
- isReply,
85
- setIsReply
86
- },
87
- children
88
- }
89
- );
90
- };
91
-
92
- // src/utils/toolbar.ts
93
- var eventTypes = {
94
- undo: "undo",
95
- redo: "redo",
96
- bold: "bold",
97
- italic: "italic",
98
- underline: "underline",
99
- color: {
100
- base: "colors"},
101
- code: "code",
102
- link: "link",
103
- listNumber: "listNumber",
104
- listBullet: "listBullet",
105
- align: {
106
- base: "align"},
107
- indent: "indent",
108
- indentDecrease: "indentDecrease",
109
- strike: "strike",
110
- attachFile: "attachFile",
111
- fontSize: "fontSize",
112
- fontFamily: "fontFamily"
113
- };
114
- var toolbarComponentType = {
115
- styling: "styling",
116
- divider: "divider",
117
- component: "component"
118
- };
119
- var pluginList = [
120
- {
121
- type: toolbarComponentType["styling"],
122
- icon: "Styling",
123
- id: "4bc66ea9-2e35-4a7b-a674-be7e4ee163c5",
124
- options: [
125
- {
126
- name: eventTypes["undo"],
127
- type: toolbarComponentType["component"],
128
- icon: "Undo",
129
- id: "29cf5eb3-37cd-482f-9a15-c358faf19cc2"
130
- },
131
- {
132
- name: eventTypes["redo"],
133
- type: toolbarComponentType["component"],
134
- icon: "Redo",
135
- id: "8744f7ab-5818-46ce-9417-2fec87123afe"
136
- },
137
- {
138
- type: toolbarComponentType["divider"],
139
- id: "ed0104fd-3507-43f6-80c1-813fbdf04479"
140
- },
141
- {
142
- name: eventTypes["fontFamily"],
143
- type: toolbarComponentType["component"],
144
- id: "1c12d7e2-aa6a-42b4-b25c-b55fe3bcf524"
145
- },
146
- {
147
- type: toolbarComponentType["divider"],
148
- id: "d0f67d01-0731-411a-b448-e1dca47014f4"
149
- },
150
- {
151
- name: eventTypes["fontSize"],
152
- type: toolbarComponentType["component"],
153
- id: "82e31b62-5441-4052-887c-faa02d0b7075"
154
- },
155
- {
156
- type: toolbarComponentType["divider"],
157
- id: "2e3558e4-3ad4-422b-8502-ea3c58fb8c2e"
158
- },
159
- {
160
- name: eventTypes["bold"],
161
- type: toolbarComponentType["component"],
162
- icon: "Bold",
163
- id: "ac2b5b54-7323-44a4-bc6d-8bae6e48efe2"
164
- },
165
- {
166
- name: eventTypes["italic"],
167
- type: toolbarComponentType["component"],
168
- icon: "Italic",
169
- id: "6a927c2a-2230-4dc7-af71-47fbe9fb784d"
170
- },
171
- {
172
- name: eventTypes["underline"],
173
- type: toolbarComponentType["component"],
174
- icon: "Underline",
175
- id: "f07b3a6f-ffaa-4153-beae-79a36acb6a08"
176
- },
177
- {
178
- name: eventTypes["color"].base,
179
- type: toolbarComponentType["component"],
180
- icon: "Color",
181
- id: "e14ec25f-3dd3-4ed5-b33a-a033684d248b"
182
- },
183
- {
184
- type: toolbarComponentType["divider"],
185
- id: "93e60297-206f-4f31-bc29-11daff2052bd"
186
- },
187
- {
188
- name: eventTypes.align.base,
189
- type: toolbarComponentType["component"],
190
- id: "30da93ea-efa6-4642-bfa5-28fd4dc9c5b3"
191
- },
192
- {
193
- type: toolbarComponentType["divider"],
194
- id: "9bad0563-6118-4855-9286-402bf98e00ad"
195
- },
196
- {
197
- name: eventTypes["listNumber"],
198
- type: toolbarComponentType["component"],
199
- icon: "OrderedList",
200
- id: "d37865e1-ff54-4118-a5cc-fa147d222471"
201
- },
202
- {
203
- name: eventTypes["listBullet"],
204
- type: toolbarComponentType["component"],
205
- icon: "UnOrderedList",
206
- id: "ed77e7c9-b89c-41c5-a749-e68ea0b30497"
207
- },
208
- {
209
- type: toolbarComponentType["divider"],
210
- id: "e5ecd77b-44cc-42fe-badb-48cadf3ddfb1"
211
- },
212
- {
213
- name: eventTypes["indentDecrease"],
214
- type: toolbarComponentType["component"],
215
- icon: "IndentLess",
216
- id: "2dc6a5e4-b1b5-47d1-ac2f-5d0becb02d33"
217
- },
218
- {
219
- name: eventTypes["indent"],
220
- type: toolbarComponentType["component"],
221
- icon: "IndentMore",
222
- id: "6903a3d1-a83f-4bc6-9bd9-f673feffe84f"
223
- }
224
- ]
225
- },
226
- {
227
- type: "component",
228
- name: eventTypes["attachFile"],
229
- icon: "Attach",
230
- id: "f43a284e-113e-4095-b001-9d00a1dddc4c"
231
- },
232
- {
233
- type: "component",
234
- name: eventTypes["link"],
235
- icon: "Link",
236
- id: "580db61e-7939-4efe-914c-304b271998ec"
237
- }
238
- // {
239
- // type: "component",
240
- // name: eventTypes["insertPhoto"],
241
- // icon: "Image",
242
- // id: "d032ba91-3e78-4ed5-8561-033cd1c49cae",
243
- // },
244
- ];
245
- var icons = {
246
- Undo: MdUndo,
247
- Redo: MdRedo,
248
- Bold: MdFormatBold,
249
- Italic: MdFormatItalic,
250
- Underline: MdFormatUnderlined,
251
- Color: MdTextFormat,
252
- LeftAlign: MdFormatAlignLeft,
253
- RightAlign: MdFormatAlignRight,
254
- CenterAlign: MdFormatAlignCenter,
255
- UnOrderedList: MdFormatListBulleted,
256
- OrderedList: MdFormatListNumbered,
257
- IndentLess: MdFormatIndentDecrease,
258
- IndentMore: MdOutlineFormatIndentIncrease,
259
- RemoveFormat: MdFormatClear,
260
- StrikeThrough: MdStrikethroughS,
261
- CodeQuote: MdFormatQuote,
262
- DownArrow: MdArrowDropDown,
263
- Styling: MdTextFormat,
264
- Attach: MdAttachFile,
265
- Link: MdLink,
266
- Image: MdImage,
267
- Check: MdCheck,
268
- TextFields: MdTextFields,
269
- Edit: MdEdit,
270
- Close: MdClose
271
- };
272
- var helper_default = icons;
273
- var Icon = ({ name, size = 24, color, className }) => {
274
- const IconComponent = helper_default[name];
275
- if (!IconComponent) {
276
- console.warn(`Icon "${name}" not found.`);
277
- return null;
278
- }
279
- return /* @__PURE__ */ jsx(IconComponent, { size, color, className });
280
- };
281
- var Icon_default = Icon;
282
- var MyPopup = ({
283
- trigger,
284
- children,
285
- popUpDirection = "top center"
286
- }) => {
287
- const popupRef = useRef(null);
288
- const handleClose = () => {
289
- if (popupRef.current && typeof popupRef.current.close === "function") {
290
- popupRef.current.close();
291
- }
292
- };
293
- const renderContent = (close) => {
294
- const combinedClose = () => {
295
- close?.();
296
- handleClose();
297
- };
298
- return children({ close: combinedClose });
299
- };
300
- return /* @__PURE__ */ jsx(
301
- Popup,
302
- {
303
- ref: popupRef,
304
- trigger,
305
- closeOnDocumentClick: true,
306
- repositionOnResize: true,
307
- position: popUpDirection,
308
- className: "filter-popup",
309
- children: renderContent
310
- }
311
- );
312
- };
313
- var MyPopup_default = MyPopup;
314
-
315
- // src/utils/core.ts
316
- var fontOptions = [
317
- {
318
- label: "Sans Serif",
319
- value: "sans-serif",
320
- style: { fontFamily: "sans-serif" }
321
- },
322
- { label: "Serif", value: "serif", style: { fontFamily: "serif" } },
323
- {
324
- label: "Fixed Width",
325
- value: "monospace",
326
- style: { fontFamily: "monospace" }
327
- },
328
- {
329
- label: "Wide",
330
- value: "wide",
331
- style: { fontWeight: "bold", letterSpacing: "0.05em" }
332
- },
333
- { label: "Narrow", value: "narrow", style: { fontStretch: "condensed" } },
334
- {
335
- label: "Comic Sans MS",
336
- value: "Comic Sans MS",
337
- style: { fontFamily: "Comic Sans MS, cursive" }
338
- },
339
- {
340
- label: "Garamond",
341
- value: "Garamond",
342
- style: { fontFamily: "Garamond, serif" }
343
- },
344
- {
345
- label: "Georgia",
346
- value: "Georgia",
347
- style: { fontFamily: "Georgia, serif" }
348
- },
349
- {
350
- label: "Tahoma",
351
- value: "Tahoma",
352
- style: { fontFamily: "Tahoma, sans-serif" }
353
- },
354
- {
355
- label: "Trebuchet MS",
356
- value: "Trebuchet MS",
357
- style: { fontFamily: "Trebuchet MS, sans-serif" }
358
- },
359
- {
360
- label: "Verdana",
361
- value: "Verdana",
362
- style: { fontFamily: "Verdana, sans-serif" }
363
- }
364
- ];
365
- var OPTIONS = [
366
- { key: "small", label: "Small", sizePx: 12 },
367
- { key: "normal", label: "Normal", sizePx: 18 },
368
- { key: "large", label: "Large", sizePx: 28 },
369
- { key: "huge", label: "Huge", sizePx: 56 }
370
- ];
371
- var GREYS = [
372
- "#000000",
373
- "#3a3a3a",
374
- "#5a5a5a",
375
- "#8a8a8a",
376
- "#bfbfbf",
377
- "#dedede",
378
- "#f3f3f3",
379
- "#ffffff"
380
- ];
381
- var ACCENTS = [
382
- "#e53935",
383
- "#fb8c00",
384
- "#ffee58",
385
- "#66ff66",
386
- "#4dd0e1",
387
- "#1e88e5",
388
- "#9c27b0",
389
- "#ff3bd6"
390
- ];
391
- var PALETTE = [
392
- [
393
- "#f7d7d7",
394
- "#f3d0c8",
395
- "#f0c5c5",
396
- "#efc9d8",
397
- "#f7e6e9",
398
- "#f3edf7",
399
- "#f0eaf6",
400
- "#f8f0f6"
401
- ],
402
- [
403
- "#f0b9b9",
404
- "#f0d4c2",
405
- "#e6f0d2",
406
- "#e4f7e8",
407
- "#d8eef8",
408
- "#dbe1ff",
409
- "#e9d9f6",
410
- "#f5d9f7"
411
- ],
412
- [
413
- "#e69a9a",
414
- "#e6caa3",
415
- "#d7e6b0",
416
- "#c8f0e6",
417
- "#bfe3ff",
418
- "#cbd8ff",
419
- "#d6c3f3",
420
- "#f0c2f3"
421
- ],
422
- [
423
- "#d16464",
424
- "#d09a6a",
425
- "#a8cf7b",
426
- "#7fd6c0",
427
- "#73b7ff",
428
- "#7a9cff",
429
- "#b483f1",
430
- "#f08cf2"
431
- ],
432
- [
433
- "#b23a3a",
434
- "#b26a3a",
435
- "#7aa04a",
436
- "#3fb092",
437
- "#296f94",
438
- "#2a4177",
439
- "#452a68",
440
- "#6e1f4d"
441
- ],
442
- [
443
- "#7a1d1d",
444
- "#7a4a1e",
445
- "#556a2a",
446
- "#195b47",
447
- "#123f5a",
448
- "#182840",
449
- "#2a1836",
450
- "#3a1026"
451
- ]
452
- ];
453
- var core_default = fontOptions;
454
- function FontSelect({ value = "serif", onChange }) {
455
- return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
456
- MyPopup_default,
457
- {
458
- trigger: /* @__PURE__ */ jsxs("button", { className: "font-option heading", children: [
459
- core_default?.find((o) => o.value === value)?.label,
460
- /* @__PURE__ */ jsx(Icon_default, { name: "DownArrow" })
461
- ] }),
462
- children: ({ close }) => /* @__PURE__ */ jsx("div", { className: "p-4", children: /* @__PURE__ */ jsx("div", { className: "font-options", children: core_default.map((font) => /* @__PURE__ */ jsx(
463
- "button",
464
- {
465
- className: "btn",
466
- onClick: () => {
467
- onChange(font.value);
468
- close();
469
- },
470
- style: { ...font.style },
471
- children: /* @__PURE__ */ jsxs("div", { className: "font-option", children: [
472
- value === font.value && /* @__PURE__ */ jsx(Icon_default, { name: "Check" }),
473
- font.label
474
- ] })
475
- },
476
- font.value
477
- )) }) })
478
- }
479
- ) });
480
- }
481
- function FontSizePicker({
482
- value = "normal",
483
- onChange = () => {
484
- }
485
- }) {
486
- return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
487
- MyPopup_default,
488
- {
489
- trigger: /* @__PURE__ */ jsxs("button", { className: "font-option heading", children: [
490
- /* @__PURE__ */ jsx(Icon_default, { name: "TextFields" }),
491
- /* @__PURE__ */ jsx(Icon_default, { name: "DownArrow" })
492
- ] }),
493
- children: ({ close }) => /* @__PURE__ */ jsx("div", { className: "p-4", children: /* @__PURE__ */ jsx("div", { className: "font-options", children: OPTIONS.map((font) => /* @__PURE__ */ jsx(
494
- "button",
495
- {
496
- className: "btn",
497
- onClick: () => {
498
- onChange(font.key);
499
- close();
500
- },
501
- style: { fontSize: `${font.sizePx}px` },
502
- children: /* @__PURE__ */ jsxs("div", { className: "font-option", children: [
503
- value === font.key && /* @__PURE__ */ jsx(Icon_default, { name: "Check" }),
504
- font.label
505
- ] })
506
- },
507
- font.key
508
- )) }) })
509
- }
510
- ) });
511
- }
512
- function Swatch({ color, selected, onClick, label }) {
513
- return /* @__PURE__ */ jsx(
514
- "button",
515
- {
516
- className: "swatch",
517
- title: label || color,
518
- "aria-pressed": selected,
519
- onClick: () => onClick(color),
520
- style: { background: color },
521
- children: selected && /* @__PURE__ */ jsx("svg", { className: "check", viewBox: "0 0 24 24", "aria-hidden": true, children: /* @__PURE__ */ jsx(
522
- "path",
523
- {
524
- d: "M20 6L9 17l-5-5",
525
- stroke: "white",
526
- strokeWidth: "2",
527
- strokeLinecap: "round",
528
- strokeLinejoin: "round",
529
- fill: "none"
530
- }
531
- ) })
532
- }
533
- );
534
- }
535
- function ColorPicker({
536
- value = { background: "#ffffff", text: "#000000" },
537
- onChange = () => {
538
- }
539
- }) {
540
- function update(which, color) {
541
- onChange({ ...value, [which]: color });
542
- }
543
- return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
544
- MyPopup_default,
545
- {
546
- trigger: /* @__PURE__ */ jsxs("button", { className: "font-option heading", children: [
547
- /* @__PURE__ */ jsx(Icon_default, { name: "Styling" }),
548
- /* @__PURE__ */ jsx(Icon_default, { name: "DownArrow" })
549
- ] }),
550
- children: ({ close }) => /* @__PURE__ */ jsx(
551
- "div",
552
- {
553
- className: "color-popover",
554
- role: "dialog",
555
- "aria-label": "Choose colors",
556
- children: /* @__PURE__ */ jsxs("div", { className: "color-columns", children: [
557
- /* @__PURE__ */ jsxs("section", { className: "color-column", "aria-labelledby": "bg-label", children: [
558
- /* @__PURE__ */ jsx("h4", { id: "bg-label", children: "Background color" }),
559
- /* @__PURE__ */ jsx("div", { className: "row", children: GREYS.map((c) => /* @__PURE__ */ jsx(
560
- Swatch,
561
- {
562
- color: c,
563
- selected: value.background === c,
564
- onClick: (col) => {
565
- update("background", col);
566
- close();
567
- },
568
- label: c
569
- },
570
- c + "bg"
571
- )) }),
572
- /* @__PURE__ */ jsx("div", { className: "row accent-row", children: ACCENTS.map((c) => /* @__PURE__ */ jsx(
573
- Swatch,
574
- {
575
- color: c,
576
- selected: value.background === c,
577
- onClick: (col) => {
578
- update("background", col);
579
- close();
580
- },
581
- label: c
582
- },
583
- c + "bgacc"
584
- )) }),
585
- /* @__PURE__ */ jsx("div", { className: "palette", children: PALETTE.map((r, i) => /* @__PURE__ */ jsx("div", { className: "palette-row", children: r.map((c) => /* @__PURE__ */ jsx(
586
- Swatch,
587
- {
588
- color: c,
589
- selected: value.background === c,
590
- onClick: (col) => {
591
- update("background", col);
592
- close();
593
- },
594
- label: c
595
- },
596
- c + "bgp" + i
597
- )) }, "row" + i)) })
598
- ] }),
599
- /* @__PURE__ */ jsxs("section", { className: "color-column", "aria-labelledby": "text-label", children: [
600
- /* @__PURE__ */ jsx("h4", { id: "text-label", children: "Text color" }),
601
- /* @__PURE__ */ jsx("div", { className: "row", children: GREYS.map((c) => /* @__PURE__ */ jsx(
602
- Swatch,
603
- {
604
- color: c,
605
- selected: value.text === c,
606
- onClick: (col) => {
607
- update("text", col);
608
- close();
609
- },
610
- label: c
611
- },
612
- c + "tx"
613
- )) }),
614
- /* @__PURE__ */ jsx("div", { className: "row accent-row", children: ACCENTS.map((c) => /* @__PURE__ */ jsx(
615
- Swatch,
616
- {
617
- color: c,
618
- selected: value.text === c,
619
- onClick: (col) => {
620
- update("text", col);
621
- close();
622
- },
623
- label: c
624
- },
625
- c + "txacc"
626
- )) }),
627
- /* @__PURE__ */ jsx("div", { className: "palette", children: PALETTE.map((r, i) => /* @__PURE__ */ jsx("div", { className: "palette-row", children: r.map((c) => /* @__PURE__ */ jsx(
628
- Swatch,
629
- {
630
- color: c,
631
- selected: value.text === c,
632
- onClick: (col) => {
633
- update("text", col);
634
- close();
635
- },
636
- label: c
637
- },
638
- c + "txp" + i
639
- )) }, "txrow" + i)) })
640
- ] })
641
- ] })
642
- }
643
- )
644
- }
645
- ) });
646
- }
647
- var OPTIONS2 = [
648
- { key: "left", iconName: "LeftAlign", label: "Left align" },
649
- { key: "center", iconName: "CenterAlign", label: "Center align" },
650
- { key: "right", iconName: "RightAlign", label: "Right align" }
651
- ];
652
- function AlignmentSelect({
653
- value = "left",
654
- onChange = () => {
655
- }
656
- }) {
657
- function onSelect(key) {
658
- onChange(key);
659
- }
660
- return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
661
- MyPopup_default,
662
- {
663
- trigger: /* @__PURE__ */ jsxs("button", { className: "font-option heading", children: [
664
- /* @__PURE__ */ jsx(Icon_default, { name: OPTIONS2?.find((o) => o.key === value)?.iconName || "LeftAlign" }),
665
- /* @__PURE__ */ jsx(Icon_default, { name: "DownArrow" })
666
- ] }),
667
- children: ({ close }) => /* @__PURE__ */ jsx("div", { className: "wrapper-alignment", children: OPTIONS2.map((opt) => {
668
- const active = opt.key === value;
669
- return /* @__PURE__ */ jsxs(
670
- "button",
671
- {
672
- role: "menuitemradio",
673
- "aria-checked": active,
674
- tabIndex: 0,
675
- className: `alignment-option ${active ? "active" : ""}`,
676
- onClick: () => {
677
- onSelect(opt.key);
678
- close();
679
- },
680
- children: [
681
- /* @__PURE__ */ jsx("div", { className: "option-icon", children: /* @__PURE__ */ jsx(Icon_default, { name: opt.iconName, size: 20 }) }),
682
- /* @__PURE__ */ jsx(
683
- "div",
684
- {
685
- className: `option-check ${active ? "" : "hidden"}`,
686
- "aria-hidden": true,
687
- children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx(
688
- "path",
689
- {
690
- d: "M20 6L9 17l-5-5",
691
- fill: "none",
692
- stroke: "currentColor",
693
- strokeWidth: "2",
694
- strokeLinecap: "round",
695
- strokeLinejoin: "round"
696
- }
697
- ) })
698
- }
699
- )
700
- ]
701
- },
702
- opt.key
703
- );
704
- }) })
705
- }
706
- ) });
707
- }
708
- var LowPriority = 1;
709
- function rgbToHex(rgb) {
710
- if (!rgb) return rgb;
711
- if (rgb.startsWith("#")) return rgb;
712
- if (rgb.startsWith("rgba")) {
713
- const match2 = rgb.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*([\d.]+)?\)/);
714
- if (match2) {
715
- const [, r, g, b, a] = match2;
716
- if (a === "0") return "transparent";
717
- return "#" + [r, g, b].map((x) => {
718
- const hex = parseInt(x).toString(16);
719
- return hex.length === 1 ? "0" + hex : hex;
720
- }).join("");
721
- }
722
- }
723
- const match = rgb.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
724
- if (match) {
725
- const [, r, g, b] = match;
726
- return "#" + [r, g, b].map((x) => {
727
- const hex = parseInt(x).toString(16);
728
- return hex.length === 1 ? "0" + hex : hex;
729
- }).join("");
730
- }
731
- return rgb;
732
- }
733
- function useOnClickListener() {
734
- const [editor] = useLexicalComposerContext();
735
- const [blockType, setBlockType] = useState("paragraph");
736
- const [selectedEventTypes, setSelectedEventTypes] = useState({
737
- [eventTypes.fontFamily]: "sans-serif",
738
- [eventTypes.fontSize]: 16,
739
- [eventTypes.align.base]: "left"
740
- });
741
- const [isLink, setIsLink] = useState(false);
742
- const updateToolbar = useCallback(() => {
743
- const selection = $getSelection();
744
- const newState = {
745
- // Set default values
746
- [eventTypes.fontFamily]: "sans-serif",
747
- [eventTypes.fontSize]: 16,
748
- [eventTypes.align.base]: "left"
749
- };
750
- if ($isRangeSelection(selection)) {
751
- const anchorNode = selection.anchor.getNode();
752
- const element = anchorNode.getKey() === "root" ? anchorNode : anchorNode.getTopLevelElementOrThrow();
753
- const elementKey = element.getKey();
754
- const elementDOM = editor.getElementByKey(elementKey);
755
- if (elementDOM !== null) {
756
- if ($isListNode(element)) {
757
- const parentList = $getNearestNodeOfType(anchorNode, ListNode);
758
- const type = parentList ? parentList.getTag() : element.getTag();
759
- setBlockType(type);
760
- } else {
761
- const type = element.getType();
762
- setBlockType(type);
763
- }
764
- }
765
- newState[eventTypes.bold] = selection.hasFormat("bold");
766
- newState[eventTypes.italic] = selection.hasFormat("italic");
767
- newState[eventTypes.underline] = selection.hasFormat("underline");
768
- newState[eventTypes.strike] = selection.hasFormat("strikethrough");
769
- newState[eventTypes.code] = selection.hasFormat("code");
770
- const node = getSelectedNode2(selection);
771
- const parent = node.getParent();
772
- if ($isLinkNode(parent) || $isLinkNode(node)) {
773
- newState[eventTypes.link] = true;
774
- setIsLink(true);
775
- } else {
776
- newState[eventTypes.link] = false;
777
- setIsLink(false);
778
- }
779
- const textNodeDOM = editor.getElementByKey(node.getKey());
780
- const parentElement = editor.getElementByKey(parent.getKey());
781
- const styleElement = textNodeDOM || parentElement || elementDOM;
782
- if (styleElement) {
783
- const computedStyle = window.getComputedStyle(styleElement);
784
- const fontFamily = computedStyle.getPropertyValue("font-family");
785
- if (fontFamily) {
786
- let firstFont = fontFamily.split(",")[0].trim().replace(/['"]/g, "");
787
- if (firstFont === "-apple-system" || firstFont === "BlinkMacSystemFont" || firstFont === "system-ui") {
788
- firstFont = "sans-serif";
789
- }
790
- newState[eventTypes.fontFamily] = firstFont;
791
- }
792
- const fontSize = computedStyle.getPropertyValue("font-size");
793
- if (fontSize) {
794
- const fontSizeNum = parseInt(fontSize, 10);
795
- newState[eventTypes.fontSize] = fontSizeNum || 16;
796
- }
797
- let color = null;
798
- let backgroundColor = null;
799
- if (styleElement instanceof HTMLElement && styleElement.style) {
800
- color = styleElement.style.color || null;
801
- backgroundColor = styleElement.style.backgroundColor || null;
802
- }
803
- if (!color) {
804
- color = computedStyle.getPropertyValue("color");
805
- }
806
- if (!backgroundColor) {
807
- backgroundColor = computedStyle.getPropertyValue("background-color");
808
- }
809
- console.log("\u{1F3A8} Color detection:", {
810
- inlineColor: styleElement instanceof HTMLElement ? styleElement.style.color : "N/A",
811
- inlineBg: styleElement instanceof HTMLElement ? styleElement.style.backgroundColor : "N/A",
812
- computedColor: color,
813
- computedBg: backgroundColor,
814
- element: styleElement
815
- });
816
- const hexColor = color ? rgbToHex(color) : null;
817
- const hexBgColor = backgroundColor && backgroundColor !== "rgba(0, 0, 0, 0)" && backgroundColor !== "transparent" ? rgbToHex(backgroundColor) : null;
818
- if (hexColor || hexBgColor) {
819
- newState[eventTypes.color.base] = {
820
- text: hexColor || "#000000",
821
- background: hexBgColor || "#ffffff"
822
- };
823
- }
824
- let textAlign = computedStyle.getPropertyValue("text-align") || "left";
825
- if (textAlign === "start") {
826
- textAlign = "left";
827
- }
828
- newState[eventTypes.align.base] = textAlign;
829
- }
830
- setSelectedEventTypes(newState);
831
- }
832
- }, [editor]);
833
- useEffect(() => {
834
- return mergeRegister(
835
- editor.registerUpdateListener(({ editorState }) => {
836
- editorState.read(() => {
837
- updateToolbar();
838
- });
839
- }),
840
- editor.registerCommand(
841
- SELECTION_CHANGE_COMMAND,
842
- () => {
843
- updateToolbar();
844
- return false;
845
- },
846
- LowPriority
847
- )
848
- );
849
- }, [editor, updateToolbar]);
850
- function onChange(type, event) {
851
- switch (type) {
852
- case eventTypes.bold:
853
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, "bold");
854
- break;
855
- case eventTypes.italic:
856
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, "italic");
857
- break;
858
- case eventTypes.underline:
859
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, "underline");
860
- break;
861
- case eventTypes.align.base:
862
- editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, event);
863
- break;
864
- case eventTypes.undo:
865
- editor.dispatchCommand(UNDO_COMMAND, void 0);
866
- break;
867
- case eventTypes.redo:
868
- editor.dispatchCommand(REDO_COMMAND, void 0);
869
- break;
870
- case eventTypes.listNumber:
871
- formatNumberedList();
872
- break;
873
- case eventTypes.listBullet:
874
- formatBulletList();
875
- break;
876
- case eventTypes.indent:
877
- addIndent();
878
- break;
879
- case eventTypes.indentDecrease:
880
- removeIndent();
881
- break;
882
- case eventTypes.color.base:
883
- applyFontColor(event);
884
- break;
885
- case eventTypes.fontFamily:
886
- applyFontFamily(event);
887
- break;
888
- case eventTypes.fontSize:
889
- applyFontSize(event);
890
- break;
891
- case eventTypes.link:
892
- insertLink();
893
- break;
894
- }
895
- }
896
- const addIndent = () => {
897
- editor.dispatchCommand(INDENT_CONTENT_COMMAND, void 0);
898
- };
899
- const applyFontFamily = (fontFamily) => {
900
- editor.update(() => {
901
- const selection = $getSelection();
902
- if ($isRangeSelection(selection)) {
903
- $patchStyleText(selection, { "font-family": fontFamily });
904
- }
905
- });
906
- };
907
- const applyFontSize = (fontSize) => {
908
- const selectedFontSize = OPTIONS.find((i) => i.key === fontSize)?.sizePx ?? 16;
909
- editor.update(() => {
910
- const selection = $getSelection();
911
- if ($isRangeSelection(selection)) {
912
- $patchStyleText(selection, { "font-size": `${selectedFontSize}px` });
913
- }
914
- });
915
- };
916
- const applyFontColor = (colorObj) => {
917
- editor.update(() => {
918
- const selection = $getSelection();
919
- if ($isRangeSelection(selection)) {
920
- $patchStyleText(selection, {
921
- "background-color": colorObj.background,
922
- color: colorObj.text
923
- });
924
- }
925
- });
926
- };
927
- const insertLink = useCallback(() => {
928
- if (!isLink) {
929
- editor.dispatchCommand(TOGGLE_LINK_COMMAND, "https://");
930
- } else {
931
- editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
932
- }
933
- }, [editor, isLink]);
934
- const removeIndent = () => {
935
- editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, void 0);
936
- };
937
- const formatBulletList = () => {
938
- if (blockType !== "ul") {
939
- editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, void 0);
940
- } else {
941
- editor.dispatchCommand(REMOVE_LIST_COMMAND, void 0);
942
- }
943
- };
944
- const formatNumberedList = () => {
945
- if (blockType !== "ol") {
946
- editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, void 0);
947
- } else {
948
- editor.dispatchCommand(REMOVE_LIST_COMMAND, void 0);
949
- }
950
- };
951
- function getSelectedNode2(selection) {
952
- const anchor = selection.anchor;
953
- const focus = selection.focus;
954
- const anchorNode = selection.anchor.getNode();
955
- const focusNode = selection.focus.getNode();
956
- if (anchorNode === focusNode) {
957
- return anchorNode;
958
- }
959
- const isBackward = selection.isBackward();
960
- if (isBackward) {
961
- return $isAtNodeEnd(focus) ? anchorNode : focusNode;
962
- } else {
963
- return $isAtNodeEnd(anchor) ? focusNode : anchorNode;
964
- }
965
- }
966
- return { onChange, isLink, editor, selectedEventTypes, blockType };
967
- }
968
- var useOnClickListener_default = useOnClickListener;
969
- function FloatingLinkEditor({ editor }) {
970
- const editorRef = useRef(null);
971
- const inputRef = useRef(null);
972
- const mouseDownRef = useRef(false);
973
- const [linkUrl, setLinkUrl] = useState("");
974
- const [isEditMode, setEditMode] = useState(false);
975
- const [lastSelection, setLastSelection] = useState(null);
976
- const updateLinkEditor = useCallback(() => {
977
- const nativeSelection = window.getSelection();
978
- const selection = $getSelection();
979
- if ($isRangeSelection(selection)) {
980
- const node = getSelectedNode(selection);
981
- const parent = node.getParent();
982
- if ($isLinkNode(parent)) {
983
- setLinkUrl(parent.getURL());
984
- } else if ($isLinkNode(node)) {
985
- setLinkUrl(node.getURL());
986
- } else {
987
- setLinkUrl("");
988
- }
989
- }
990
- const editorElem = editorRef.current;
991
- const activeElement = document.activeElement;
992
- if (!editorElem) return;
993
- const rootElement = editor.getRootElement();
994
- if (selection && nativeSelection && !nativeSelection.isCollapsed && rootElement && rootElement.contains(nativeSelection.anchorNode)) {
995
- const domRange = nativeSelection.getRangeAt(0);
996
- let rect;
997
- if (nativeSelection.anchorNode === rootElement) {
998
- let inner = rootElement;
999
- while (inner.firstElementChild != null) inner = inner.firstElementChild;
1000
- rect = inner.getBoundingClientRect();
1001
- } else {
1002
- rect = domRange.getBoundingClientRect();
1003
- }
1004
- if (!mouseDownRef.current) {
1005
- positionEditorElement(editorElem, rect);
1006
- }
1007
- setLastSelection(selection);
1008
- } else if (!activeElement || activeElement.className !== "link-input") {
1009
- positionEditorElement(editorElem, null);
1010
- setLastSelection(null);
1011
- setEditMode(false);
1012
- setLinkUrl("");
1013
- }
1014
- return true;
1015
- }, [editor]);
1016
- useEffect(() => {
1017
- return mergeRegister(
1018
- editor.registerUpdateListener(({ editorState }) => {
1019
- editorState.read(() => {
1020
- updateLinkEditor();
1021
- });
1022
- }),
1023
- editor.registerCommand(
1024
- SELECTION_CHANGE_COMMAND,
1025
- () => {
1026
- updateLinkEditor();
1027
- return true;
1028
- },
1029
- 1
1030
- )
1031
- );
1032
- }, [editor, updateLinkEditor]);
1033
- useEffect(() => {
1034
- editor.getEditorState().read(() => {
1035
- updateLinkEditor();
1036
- });
1037
- }, [editor, updateLinkEditor]);
1038
- useEffect(() => {
1039
- if (isEditMode && inputRef.current) {
1040
- inputRef.current.focus();
1041
- }
1042
- }, [isEditMode]);
1043
- return /* @__PURE__ */ jsxs("div", { className: "floating-link-editor", ref: editorRef, children: [
1044
- isEditMode ? /* @__PURE__ */ jsx(
1045
- "input",
1046
- {
1047
- ref: inputRef,
1048
- className: "link-input",
1049
- value: linkUrl,
1050
- onChange: (e) => setLinkUrl(e.target.value),
1051
- onKeyDown: (e) => {
1052
- if (e.key === "Enter") {
1053
- e.preventDefault();
1054
- if (lastSelection && linkUrl !== "") {
1055
- editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkUrl);
1056
- }
1057
- setEditMode(false);
1058
- } else if (e.key === "Escape") {
1059
- e.preventDefault();
1060
- setEditMode(false);
1061
- }
1062
- },
1063
- placeholder: "Enter link..."
1064
- }
1065
- ) : /* @__PURE__ */ jsx("div", { className: "link-display", children: /* @__PURE__ */ jsx("a", { href: linkUrl, target: "_blank", rel: "noopener noreferrer", children: linkUrl || "No link selected" }) }),
1066
- /* @__PURE__ */ jsx(
1067
- "button",
1068
- {
1069
- className: "link-button",
1070
- onMouseDown: (e) => e.preventDefault(),
1071
- onClick: () => {
1072
- console.log("floating link editor", isEditMode);
1073
- if (isEditMode) editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkUrl);
1074
- setEditMode((prev) => !prev);
1075
- },
1076
- children: /* @__PURE__ */ jsx(Icon_default, { name: isEditMode ? "Check" : "Edit" })
1077
- }
1078
- )
1079
- ] });
1080
- }
1081
- function getSelectedNode(selection) {
1082
- const anchorNode = selection.anchor.getNode();
1083
- const focusNode = selection.focus.getNode();
1084
- if (anchorNode === focusNode) return anchorNode;
1085
- const isBackward = selection.isBackward();
1086
- return isBackward ? $isAtNodeEnd(selection.focus) ? anchorNode : focusNode : $isAtNodeEnd(selection.anchor) ? focusNode : anchorNode;
1087
- }
1088
- function positionEditorElement(editor, rect) {
1089
- if (!rect) {
1090
- editor.style.opacity = "0";
1091
- editor.style.top = "-1000px";
1092
- editor.style.left = "-1000px";
1093
- return;
1094
- }
1095
- const editorWidth = editor.offsetWidth;
1096
- const editorHeight = editor.offsetHeight;
1097
- const viewportWidth = window.innerWidth;
1098
- const viewportHeight = window.innerHeight;
1099
- let top = rect.top + rect.height + window.pageYOffset + 10;
1100
- let left = rect.left + window.pageXOffset - editorWidth / 2 + rect.width / 2;
1101
- if (left < 8) left = 8;
1102
- if (left + editorWidth > viewportWidth - 8)
1103
- left = viewportWidth - editorWidth - 8;
1104
- if (top + editorHeight > viewportHeight - 8) {
1105
- top = rect.top + window.pageYOffset - editorHeight - 10;
1106
- }
1107
- if (top < 8) top = 8;
1108
- editor.style.opacity = "1";
1109
- editor.style.top = `${top}px`;
1110
- editor.style.left = `${left}px`;
1111
- }
1112
- var FloatingLinkEditor_default = FloatingLinkEditor;
1113
- var FILE_UPLOAD_ERROR = {
1114
- FILE_INVALID_TYPE: "file-invalid-type",
1115
- FILE_TOO_LARGE: "file-too-large",
1116
- TOO_MANY_FILES: "too-many-files",
1117
- HEIC_CONVERSION_ERROR: "heic-conversion-error"
1118
- };
1119
- var MAX_NUMBER_OF_FILES_ALLOWED = 10;
1120
- var MAX_SIZE_OF_FILE_ALLOWED_MB = 10;
1121
- var getId = () => Math.random().toString(36).substring(2, 10) + Date.now().toString(36);
1122
- var getMBs = (bytes) => {
1123
- if (bytes < 1024) return { value: bytes.toString(), type: "bytes" };
1124
- const kb = bytes / 1024;
1125
- if (kb < 1024) return { value: kb.toFixed(1), type: "KB" };
1126
- const mb = kb / 1024;
1127
- if (mb < 1024) return { value: mb.toFixed(1), type: "MB" };
1128
- const gb = mb / 1024;
1129
- return { value: gb.toFixed(1), type: "GB" };
1130
- };
1131
- var useFileUpload = ({
1132
- accept = {
1133
- "image/*": [".png", ".gif", ".jpeg", ".jpg"],
1134
- "application/pdf": [".pdf"]
1135
- },
1136
- maxSize = MAX_SIZE_OF_FILE_ALLOWED_MB * 1024 * 1024,
1137
- maxFiles = MAX_NUMBER_OF_FILES_ALLOWED,
1138
- multiple = true,
1139
- isDisabled = false,
1140
- replaceAfterUpload = false,
1141
- files = [],
1142
- handleFileChange = () => {
1143
- }
1144
- }) => {
1145
- const [isFileDialogOpen, setIsFileDialogOpen] = useState(false);
1146
- const [fileUploaded, setFileUploaded] = useState(files ?? []);
1147
- const [rejectedFiles, setRejectedFile] = useState(
1148
- []
1149
- );
1150
- const getErrorText = (errorCode) => {
1151
- switch (errorCode) {
1152
- case FILE_UPLOAD_ERROR.FILE_INVALID_TYPE:
1153
- return "Invalid file type. Please upload a supported format.";
1154
- case FILE_UPLOAD_ERROR.FILE_TOO_LARGE: {
1155
- const { value, type } = getMBs(maxSize);
1156
- return `File too large. Maximum allowed size is ${value} ${type}.`;
1157
- }
1158
- case FILE_UPLOAD_ERROR.TOO_MANY_FILES:
1159
- return `Too many files selected. Maximum allowed: ${maxFiles}.`;
1160
- case FILE_UPLOAD_ERROR.HEIC_CONVERSION_ERROR:
1161
- return "Failed to convert HEIC image. Please upload a JPEG or PNG instead.";
1162
- default:
1163
- return "An unknown file error occurred.";
1164
- }
1165
- };
1166
- useEffect(() => {
1167
- handleFileChange(fileUploaded);
1168
- }, [fileUploaded]);
1169
- const { getRootProps, getInputProps, isDragActive, open } = useDropzone({
1170
- accept,
1171
- maxSize,
1172
- multiple,
1173
- maxFiles,
1174
- disabled: isDisabled,
1175
- noClick: true,
1176
- onFileDialogCancel: () => setIsFileDialogOpen(false),
1177
- onFileDialogOpen: () => {
1178
- if (!isDisabled) setIsFileDialogOpen(true);
1179
- },
1180
- onDrop: async (_acceptedFiles, fileRejections) => {
1181
- const acceptedFiles = await Promise.all(
1182
- _acceptedFiles.map(async (file) => {
1183
- if (!file) return null;
1184
- if (file.type === "image/heic") {
1185
- try {
1186
- const blob = await heic2any({ blob: file, toType: "image/jpeg" });
1187
- const blobArray = Array.isArray(blob) ? blob[0] : blob;
1188
- const convertedFile = new File(
1189
- [blobArray],
1190
- `${file.name.replace(/\.heic$/i, "")}.jpeg`,
1191
- { type: "image/jpeg" }
1192
- );
1193
- return Object.assign(convertedFile, {
1194
- uuid: getId(),
1195
- preview: URL.createObjectURL(convertedFile)
1196
- });
1197
- } catch (err) {
1198
- console.error("HEIC conversion error:", err);
1199
- const msg = getErrorText(FILE_UPLOAD_ERROR.HEIC_CONVERSION_ERROR);
1200
- setRejectedFile((prev) => [
1201
- ...prev,
1202
- {
1203
- file,
1204
- preview: URL.createObjectURL(file),
1205
- readableErrors: [msg],
1206
- errors: [
1207
- {
1208
- code: FILE_UPLOAD_ERROR.HEIC_CONVERSION_ERROR,
1209
- message: msg
1210
- }
1211
- ]
1212
- }
1213
- ]);
1214
- return null;
1215
- }
1216
- }
1217
- return Object.assign(file, {
1218
- uuid: getId(),
1219
- preview: URL.createObjectURL(file)
1220
- });
1221
- })
1222
- );
1223
- const validFiles = acceptedFiles.filter(Boolean);
1224
- if (!isDisabled) {
1225
- let newFiles = replaceAfterUpload ? [] : [...fileUploaded];
1226
- newFiles = [...newFiles, ...validFiles];
1227
- const mappedRejections = fileRejections.map(
1228
- (item) => {
1229
- const readableErrors = item.errors.map(
1230
- (err) => getErrorText(err.code)
1231
- );
1232
- return {
1233
- file: item.file,
1234
- errors: item.errors.map((err) => ({ code: err.code, message: err.message })),
1235
- preview: URL.createObjectURL(item.file),
1236
- readableErrors
1237
- };
1238
- }
1239
- );
1240
- setRejectedFile((prev) => [...prev, ...mappedRejections]);
1241
- setFileUploaded(newFiles);
1242
- return newFiles;
1243
- }
1244
- return fileUploaded;
1245
- },
1246
- validator: (item) => {
1247
- const { name: fileName, type } = item;
1248
- if (fileName) {
1249
- const ext = fileName.split(".").pop()?.toLowerCase();
1250
- if (accept && accept?.[type] && accept?.[type].length && !accept?.[type].includes(`.${ext}`)) {
1251
- return {
1252
- code: FILE_UPLOAD_ERROR.FILE_INVALID_TYPE,
1253
- message: getErrorText(FILE_UPLOAD_ERROR.FILE_INVALID_TYPE)
1254
- };
1255
- }
1256
- }
1257
- return null;
1258
- }
1259
- });
1260
- const removeFile = useCallback(
1261
- (uuid) => {
1262
- setFileUploaded((prev) => prev.filter((file) => file.uuid !== uuid));
1263
- },
1264
- [setFileUploaded]
1265
- );
1266
- const clearRejectedFiles = useCallback(() => {
1267
- setRejectedFile([]);
1268
- }, []);
1269
- useEffect(() => {
1270
- return () => {
1271
- fileUploaded.forEach((f) => f.preview && URL.revokeObjectURL(f.preview));
1272
- rejectedFiles.forEach((r) => r.preview && URL.revokeObjectURL(r.preview));
1273
- };
1274
- }, []);
1275
- return {
1276
- getRootProps,
1277
- getInputProps,
1278
- isDragActive,
1279
- isFileDialogOpen,
1280
- rejectedFiles,
1281
- openFileDialog: open,
1282
- removeFile,
1283
- clearRejectedFiles
1284
- };
1285
- };
1286
- var FileUploader = ({ handleFileChange }) => {
1287
- const {
1288
- getRootProps,
1289
- getInputProps,
1290
- openFileDialog
1291
- } = useFileUpload({
1292
- multiple: true,
1293
- maxFiles: 5,
1294
- maxSize: 5 * 1024 * 1024,
1295
- // 5 MB
1296
- handleFileChange: (files) => {
1297
- handleFileChange(files);
1298
- }
1299
- });
1300
- return /* @__PURE__ */ jsx("div", { className: "uploader-container", children: /* @__PURE__ */ jsxs("div", { ...getRootProps(), children: [
1301
- /* @__PURE__ */ jsx("input", { ...getInputProps() }),
1302
- /* @__PURE__ */ jsx("button", { onClick: openFileDialog, children: /* @__PURE__ */ jsx(Icon_default, { className: "upload-icon", name: "Attach" }) })
1303
- ] }) });
1304
- };
1305
- var FileUploader_default = FileUploader;
1306
- function FilePreview({ file, index, onRemove, onView }) {
1307
- if (!file) return null;
1308
- const name = file?.name ?? "unknown";
1309
- const sizeBytes = file instanceof File ? file.size : "size" in file && file.size !== void 0 ? file.size : "bytes" in file && file.bytes !== void 0 ? file.bytes : null;
1310
- const urlFromProp = ("url" in file ? file?.url : null) ?? null;
1311
- const url = useMemo(() => {
1312
- if (urlFromProp) return urlFromProp;
1313
- if (typeof window !== "undefined" && file instanceof File) {
1314
- try {
1315
- return URL.createObjectURL(file);
1316
- } catch (e) {
1317
- return null;
1318
- }
1319
- }
1320
- return null;
1321
- }, [file, urlFromProp]);
1322
- const formatSizeShort = (bytes) => {
1323
- if (!bytes && bytes !== 0) return "";
1324
- const kb = Math.round(bytes / 1024);
1325
- if (kb < 1024) return `${kb}K`;
1326
- const mb = Math.round(bytes / 1024 / 1024 * 10) / 10;
1327
- return `${mb}M`;
1328
- };
1329
- const handleView = (e) => {
1330
- e.preventDefault();
1331
- if (onView) return onView(url ?? null);
1332
- if (url) window.open(url, "_blank", "noopener");
1333
- };
1334
- const handleRemove = (index2) => {
1335
- if (onRemove) onRemove(index2);
1336
- };
1337
- return /* @__PURE__ */ jsxs("div", { className: "fps-row", role: "group", "aria-label": `Attachment ${name}`, children: [
1338
- /* @__PURE__ */ jsxs("div", { className: "fps-left", children: [
1339
- /* @__PURE__ */ jsx(
1340
- "a",
1341
- {
1342
- href: url ?? "#",
1343
- className: "fps-filename",
1344
- onClick: handleView,
1345
- title: name,
1346
- target: "_blank",
1347
- rel: "noopener noreferrer",
1348
- children: name
1349
- }
1350
- ),
1351
- sizeBytes != null && /* @__PURE__ */ jsxs("span", { className: "fps-size", children: [
1352
- "\xA0(",
1353
- formatSizeShort(sizeBytes),
1354
- ")"
1355
- ] })
1356
- ] }),
1357
- /* @__PURE__ */ jsx(
1358
- "button",
1359
- {
1360
- type: "button",
1361
- className: "fps-close",
1362
- "aria-label": `Remove ${name}`,
1363
- onClick: () => handleRemove(index),
1364
- children: "\xD7"
1365
- }
1366
- )
1367
- ] });
1368
- }
1369
- var getToolbarComponent = (plugin, { onChange, state, setState, selectedEventTypes, blockType, setAttachments }) => {
1370
- switch (plugin.name) {
1371
- case eventTypes.undo:
1372
- case eventTypes.redo:
1373
- case eventTypes.bold:
1374
- case eventTypes.italic:
1375
- case eventTypes.underline:
1376
- case eventTypes.indentDecrease:
1377
- case eventTypes.indent:
1378
- case eventTypes.link:
1379
- return /* @__PURE__ */ jsx(
1380
- "button",
1381
- {
1382
- className: `tool-bar-button ${selectedEventTypes?.[plugin.name] ? "active-btn-toolbar" : ""}`,
1383
- onClick: () => {
1384
- onChange(plugin.name, true);
1385
- },
1386
- children: /* @__PURE__ */ jsx(Icon_default, { className: "tool-bar-button-icon", name: plugin.icon })
1387
- },
1388
- `${plugin.name}-${plugin.icon}`
1389
- );
1390
- case eventTypes.listNumber:
1391
- return /* @__PURE__ */ jsx(
1392
- "button",
1393
- {
1394
- className: blockType === "ol" ? "active-btn-toolbar" : "",
1395
- onClick: () => {
1396
- onChange(plugin.name, true);
1397
- },
1398
- children: /* @__PURE__ */ jsx(Icon_default, { className: "tool-bar-button-icon", name: plugin.icon })
1399
- },
1400
- `${plugin.name}-${plugin.icon}`
1401
- );
1402
- case eventTypes.listBullet:
1403
- return /* @__PURE__ */ jsx(
1404
- "button",
1405
- {
1406
- className: blockType === "ul" ? "active-btn-toolbar" : "",
1407
- onClick: () => {
1408
- onChange(plugin.name, true);
1409
- },
1410
- children: /* @__PURE__ */ jsx(Icon_default, { className: "tool-bar-button-icon", name: plugin.icon })
1411
- },
1412
- `${plugin.name}-${plugin.icon}`
1413
- );
1414
- case eventTypes.attachFile:
1415
- return /* @__PURE__ */ jsx(
1416
- FileUploader_default,
1417
- {
1418
- value: state?.[plugin.name],
1419
- handleFileChange: (e) => {
1420
- console.log("\u{1F680} ~ getToolbarComponent ~ e:", e);
1421
- setState((prev) => {
1422
- return { ...prev, [plugin.name]: e };
1423
- });
1424
- setAttachments(e);
1425
- }
1426
- }
1427
- );
1428
- case eventTypes.fontFamily:
1429
- return /* @__PURE__ */ jsx(
1430
- FontSelect,
1431
- {
1432
- value: selectedEventTypes?.[plugin.name] || state?.[plugin.name],
1433
- onChange: (e) => {
1434
- onChange(plugin.name, e);
1435
- }
1436
- }
1437
- );
1438
- case eventTypes.fontSize:
1439
- return /* @__PURE__ */ jsx(
1440
- FontSizePicker,
1441
- {
1442
- value: selectedEventTypes?.[plugin.name] || state?.[plugin.name],
1443
- onChange: (e) => {
1444
- onChange(plugin.name, e);
1445
- }
1446
- }
1447
- );
1448
- case eventTypes.color.base:
1449
- return /* @__PURE__ */ jsx(
1450
- ColorPicker,
1451
- {
1452
- value: selectedEventTypes?.[plugin.name] || state?.[plugin.name],
1453
- onChange: (e) => {
1454
- onChange(plugin.name, e);
1455
- }
1456
- }
1457
- );
1458
- case eventTypes.align.base:
1459
- return /* @__PURE__ */ jsx(
1460
- AlignmentSelect,
1461
- {
1462
- value: selectedEventTypes?.[plugin.name] || state?.[plugin.name],
1463
- onChange: (e) => {
1464
- onChange(plugin.name, e);
1465
- }
1466
- }
1467
- );
1468
- }
1469
- if (plugin.type === toolbarComponentType.divider)
1470
- return /* @__PURE__ */ jsx("span", { className: "divider" });
1471
- else return "-";
1472
- };
1473
- var getComponent = (plugin, {
1474
- setToggle,
1475
- toggle,
1476
- onChange,
1477
- state,
1478
- setState,
1479
- selectedEventTypes,
1480
- blockType,
1481
- setAttachments
1482
- }) => {
1483
- switch (plugin.type) {
1484
- case toolbarComponentType.divider:
1485
- return /* @__PURE__ */ jsx(
1486
- "div",
1487
- {
1488
- className: "divider"
1489
- },
1490
- `divider-${plugin.type}-${plugin.icon}`
1491
- );
1492
- case toolbarComponentType.component:
1493
- return getToolbarComponent(plugin, {
1494
- onChange,
1495
- state,
1496
- setState,
1497
- selectedEventTypes,
1498
- blockType,
1499
- setAttachments
1500
- });
1501
- case toolbarComponentType.styling:
1502
- return /* @__PURE__ */ jsxs(
1503
- "div",
1504
- {
1505
- className: "styling-toolbar",
1506
- children: [
1507
- toggle ? /* @__PURE__ */ jsx("div", { className: "styling-options", children: plugin.options?.length && Array.isArray(plugin.options) ? plugin.options?.map(
1508
- (option) => getToolbarComponent(option, {
1509
- onChange,
1510
- state,
1511
- setState,
1512
- selectedEventTypes,
1513
- blockType,
1514
- setAttachments
1515
- })
1516
- ) : null }) : null,
1517
- /* @__PURE__ */ jsx("button", { onClick: () => setToggle((prev) => !prev), children: /* @__PURE__ */ jsx(Icon_default, { className: "tool-bar-button-icon", name: plugin.icon }) })
1518
- ]
1519
- },
1520
- `divider-${plugin.type}-${plugin.icon}`
1521
- );
1522
- }
1523
- return "-";
1524
- };
1525
- function ToolBar({ rightChildren, leftChildren }) {
1526
- const [toggle, setToggle] = useState(true);
1527
- const [state, setState] = useState({});
1528
- const { setAttachments } = useEmailContext();
1529
- const { onChange, isLink, editor, selectedEventTypes, blockType } = useOnClickListener_default();
1530
- console.log("\u{1F680} ~ ToolBar ~ selectedEventTypes:", selectedEventTypes);
1531
- return /* @__PURE__ */ jsxs("div", { className: "toolbar-container", children: [
1532
- state[eventTypes.attachFile]?.length ? /* @__PURE__ */ jsx("div", { className: "file-upload-container", children: state[eventTypes.attachFile]?.map((item, index) => /* @__PURE__ */ jsx(
1533
- FilePreview,
1534
- {
1535
- file: item,
1536
- index,
1537
- onRemove: (index2) => {
1538
- setState((prev) => {
1539
- const updatedFiles = prev[eventTypes.attachFile].filter(
1540
- (_file, i) => i !== index2
1541
- );
1542
- setAttachments(updatedFiles);
1543
- return {
1544
- ...prev,
1545
- [eventTypes.attachFile]: updatedFiles
1546
- };
1547
- });
1548
- }
1549
- },
1550
- index
1551
- )) }) : null,
1552
- /* @__PURE__ */ jsxs("div", { className: "toolbar-wrapper", children: [
1553
- leftChildren,
1554
- pluginList?.map(
1555
- (plugin) => getComponent(plugin, {
1556
- setToggle,
1557
- state,
1558
- setState,
1559
- toggle,
1560
- onChange,
1561
- selectedEventTypes,
1562
- blockType,
1563
- setAttachments
1564
- })
1565
- ),
1566
- rightChildren,
1567
- isLink ? createPortal(/* @__PURE__ */ jsx(FloatingLinkEditor_default, { editor }), document.body) : null
1568
- ] })
1569
- ] });
1570
- }
1571
- var Toolbar_default = ToolBar;
1572
-
1573
- // src/Themes/lexicalEditortheme.ts
1574
- var lexicalEditorTheme = {
1575
- ltr: "ltr",
1576
- rtl: "rtl",
1577
- placeholder: "editor-placeholder",
1578
- paragraph: "editor-paragraph",
1579
- quote: "editor-quote",
1580
- heading: {
1581
- h1: "editor-heading-h1",
1582
- h2: "editor-heading-h2",
1583
- h3: "editor-heading-h3",
1584
- h4: "editor-heading-h4",
1585
- h5: "editor-heading-h5"
1586
- },
1587
- list: {
1588
- nested: {
1589
- listitem: "editor-nested-listitem"
1590
- },
1591
- ol: "editor-list-ol",
1592
- ul: "editor-list-ul",
1593
- listitem: "editor-listitem"
1594
- },
1595
- image: "editor-image",
1596
- link: "editor-link",
1597
- text: {
1598
- bold: "editor-text-bold",
1599
- italic: "editor-text-italic",
1600
- overflowed: "editor-text-overflowed",
1601
- hashtag: "editor-text-hashtag",
1602
- underline: "editor-text-underline",
1603
- strikethrough: "editor-text-strikethrough",
1604
- underlineStrikethrough: "editor-text-underlineStrikethrough",
1605
- code: "editor-text-code"
1606
- },
1607
- code: "editor-code",
1608
- codeHighlight: {
1609
- atrule: "editor-tokenAttr",
1610
- attr: "editor-tokenAttr",
1611
- boolean: "editor-tokenProperty",
1612
- builtin: "editor-tokenSelector",
1613
- cdata: "editor-tokenComment",
1614
- char: "editor-tokenSelector",
1615
- class: "editor-tokenFunction",
1616
- "class-name": "editor-tokenFunction",
1617
- comment: "editor-tokenComment",
1618
- constant: "editor-tokenProperty",
1619
- deleted: "editor-tokenProperty",
1620
- doctype: "editor-tokenComment",
1621
- entity: "editor-tokenOperator",
1622
- function: "editor-tokenFunction",
1623
- important: "editor-tokenVariable",
1624
- inserted: "editor-tokenSelector",
1625
- keyword: "editor-tokenAttr",
1626
- namespace: "editor-tokenVariable",
1627
- number: "editor-tokenProperty",
1628
- operator: "editor-tokenOperator",
1629
- prolog: "editor-tokenComment",
1630
- property: "editor-tokenProperty",
1631
- punctuation: "editor-tokenPunctuation",
1632
- regex: "editor-tokenVariable",
1633
- selector: "editor-tokenSelector",
1634
- string: "editor-tokenSelector",
1635
- symbol: "editor-tokenProperty",
1636
- tag: "editor-tokenProperty",
1637
- url: "editor-tokenOperator",
1638
- variable: "editor-tokenVariable"
1639
- }
1640
- };
1641
- var lexicalEditortheme_default = lexicalEditorTheme;
1642
- function SetInitialHTML({ initialHTML }) {
1643
- const [editor] = useLexicalComposerContext();
1644
- useEffect(() => {
1645
- editor.update(() => {
1646
- const parser = new DOMParser();
1647
- const dom = parser.parseFromString(initialHTML, "text/html");
1648
- const nodes = $generateNodesFromDOM(editor, dom);
1649
- const root = $getRoot();
1650
- root.clear();
1651
- root.append(...nodes);
1652
- });
1653
- }, [editor, initialHTML]);
1654
- return null;
1655
- }
1656
- var SetInitialHTML_default = SetInitialHTML;
1657
- function OnChangePlugin({
1658
- onChange
1659
- }) {
1660
- const [editor] = useLexicalComposerContext();
1661
- useEffect(() => {
1662
- return editor.registerUpdateListener(({ editorState }) => {
1663
- editorState.read(() => {
1664
- const html = $generateHtmlFromNodes(editor, null);
1665
- onChange(html);
1666
- });
1667
- });
1668
- }, [editor, onChange]);
1669
- return null;
1670
- }
1671
- function onError(error) {
1672
- console.error(error);
1673
- }
1674
- function EditorWrapper({
1675
- placeholder = "Enter some text here",
1676
- initialHTML = "",
1677
- rightChildren,
1678
- leftChildren,
1679
- minHeight = "",
1680
- onChange,
1681
- editorChildren,
1682
- isEditorVisible = true
1683
- }) {
1684
- const initialConfig = {
1685
- namespace: "MyEditor",
1686
- theme: lexicalEditortheme_default,
1687
- nodes: [LinkNode, ListNode, ListItemNode, AutoLinkNode],
1688
- onError
1689
- };
1690
- return /* @__PURE__ */ jsx("div", { className: "my-editor-wrapper", children: /* @__PURE__ */ jsxs(LexicalComposer, { initialConfig, children: [
1691
- isEditorVisible ? /* @__PURE__ */ jsx(
1692
- RichTextPlugin,
1693
- {
1694
- contentEditable: /* @__PURE__ */ jsx(
1695
- ContentEditable,
1696
- {
1697
- style: { minHeight },
1698
- className: "my-editor-content",
1699
- "aria-placeholder": placeholder,
1700
- placeholder: /* @__PURE__ */ jsx("div", { className: "my-editor-placeholder", children: placeholder })
1701
- }
1702
- ),
1703
- ErrorBoundary: LexicalErrorBoundary
1704
- }
1705
- ) : editorChildren,
1706
- /* @__PURE__ */ jsx(Toolbar_default, { rightChildren, leftChildren }),
1707
- /* @__PURE__ */ jsx(HistoryPlugin, {}),
1708
- /* @__PURE__ */ jsx(SetInitialHTML_default, { initialHTML }),
1709
- /* @__PURE__ */ jsx(AutoFocusPlugin, {}),
1710
- /* @__PURE__ */ jsx(ListPlugin, {}),
1711
- /* @__PURE__ */ jsx(LinkPlugin, {}),
1712
- onChange && /* @__PURE__ */ jsx(OnChangePlugin, { onChange })
1713
- ] }) });
1714
- }
1715
- var EditorWrapper_default = EditorWrapper;
1716
-
1717
- // src/utils/common.ts
1718
- function isValidEmail(email) {
1719
- return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
1720
- }
1721
- function InputWithDropDown({ emails = [], setEmails, fetchOptions }) {
1722
- const popupRef = useRef(null);
1723
- const inputRef = useRef(null);
1724
- const [currentEmail, setCurrentEmail] = useState("");
1725
- const [popupOpen, setPopupOpen] = useState(false);
1726
- const [selectedIndex, setSelectedIndex] = useState(-1);
1727
- const [options, setOptions] = useState([]);
1728
- const [loading, setLoading] = useState(false);
1729
- const emailRefs = useRef([]);
1730
- const optionRefs = useRef([]);
1731
- useEffect(() => {
1732
- emailRefs.current = emailRefs.current.slice(0, emails.length);
1733
- }, [emails.length]);
1734
- useEffect(() => {
1735
- optionRefs.current = optionRefs.current.slice(0, options.length);
1736
- }, [options.length]);
1737
- useEffect(() => {
1738
- if (isValidEmail(currentEmail)) {
1739
- const loadOptions = async () => {
1740
- setLoading(true);
1741
- try {
1742
- const data = await fetchOptions(currentEmail);
1743
- setOptions(data);
1744
- } catch (err) {
1745
- console.error("Error fetching email options:", err);
1746
- setOptions([]);
1747
- } finally {
1748
- setLoading(false);
1749
- }
1750
- };
1751
- loadOptions();
1752
- } else {
1753
- setOptions([]);
1754
- setLoading(false);
1755
- }
1756
- }, [currentEmail, fetchOptions]);
1757
- useEffect(() => {
1758
- if (!popupOpen) {
1759
- setSelectedIndex(-1);
1760
- }
1761
- }, [popupOpen]);
1762
- useEffect(() => {
1763
- if (selectedIndex >= 0 && selectedIndex < optionRefs.current.length) {
1764
- optionRefs.current[selectedIndex]?.scrollIntoView({
1765
- block: "nearest",
1766
- behavior: "smooth"
1767
- });
1768
- }
1769
- }, [selectedIndex]);
1770
- const focusInput = () => {
1771
- inputRef.current?.focus();
1772
- };
1773
- const addEmail = (option) => {
1774
- popupRef.current?.close();
1775
- setCurrentEmail("");
1776
- setEmails((prev) => [...prev, option]);
1777
- setSelectedIndex(-1);
1778
- requestAnimationFrame(() => inputRef.current?.focus());
1779
- };
1780
- const handleInputKeyDown = (e) => {
1781
- if (popupOpen && isValidEmail(currentEmail) && options.length > 0) {
1782
- if (e.key === "ArrowDown") {
1783
- e.preventDefault();
1784
- setSelectedIndex(
1785
- (prev) => prev < options.length - 1 ? prev + 1 : prev
1786
- );
1787
- return;
1788
- }
1789
- if (e.key === "ArrowUp") {
1790
- e.preventDefault();
1791
- setSelectedIndex((prev) => prev > 0 ? prev - 1 : -1);
1792
- return;
1793
- }
1794
- if (e.key === "Enter" && selectedIndex >= 0) {
1795
- e.preventDefault();
1796
- addEmail(options[selectedIndex]);
1797
- return;
1798
- }
1799
- if (e.key === "Escape") {
1800
- e.preventDefault();
1801
- popupRef.current?.close();
1802
- setSelectedIndex(-1);
1803
- return;
1804
- }
1805
- }
1806
- if (e.key === "Backspace" && currentEmail === "") {
1807
- const lastIdx = emails.length - 1;
1808
- const lastChip = emailRefs.current[lastIdx];
1809
- if (lastChip) {
1810
- lastChip.focus();
1811
- e.preventDefault();
1812
- }
1813
- }
1814
- };
1815
- const removeEmailAt = (index) => {
1816
- setEmails((prev) => {
1817
- const next = [...prev];
1818
- next.splice(index, 1);
1819
- return next;
1820
- });
1821
- requestAnimationFrame(() => {
1822
- const prevIdx = Math.min(Math.max(0, index - 1), emails.length - 2);
1823
- const prevChip = emailRefs.current[prevIdx];
1824
- if (prevChip) prevChip.focus();
1825
- else focusInput();
1826
- });
1827
- };
1828
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
1829
- Popup,
1830
- {
1831
- ref: popupRef,
1832
- trigger: /* @__PURE__ */ jsxs("div", { className: "container-receipts", children: [
1833
- emails?.length ? /* @__PURE__ */ jsx("div", { className: "emails-container", children: emails.map((email, idx) => /* @__PURE__ */ jsxs(
1834
- "div",
1835
- {
1836
- className: "emails",
1837
- tabIndex: 0,
1838
- ref: (el) => {
1839
- emailRefs.current[idx] = el;
1840
- },
1841
- onKeyDown: (e) => {
1842
- if (e.key === "Backspace") {
1843
- e.preventDefault();
1844
- removeEmailAt(idx);
1845
- }
1846
- if (e.key === "Enter") {
1847
- e.preventDefault();
1848
- removeEmailAt(idx);
1849
- focusInput();
1850
- }
1851
- },
1852
- role: "button",
1853
- "aria-label": `Email ${email.email}`,
1854
- children: [
1855
- /* @__PURE__ */ jsx("span", { style: { marginRight: 8 }, children: email.email }),
1856
- /* @__PURE__ */ jsx(
1857
- "button",
1858
- {
1859
- className: "emails-close",
1860
- onClick: (ev) => {
1861
- ev.stopPropagation();
1862
- removeEmailAt(idx);
1863
- },
1864
- "aria-label": `Remove ${email.email}`,
1865
- children: /* @__PURE__ */ jsx(Icon_default, { name: "Close" })
1866
- }
1867
- )
1868
- ]
1869
- },
1870
- email.email ?? idx
1871
- )) }) : null,
1872
- /* @__PURE__ */ jsx(
1873
- "input",
1874
- {
1875
- ref: inputRef,
1876
- type: "text",
1877
- className: "input-header",
1878
- value: currentEmail,
1879
- autoFocus: true,
1880
- onKeyDown: handleInputKeyDown,
1881
- onChange: (e) => {
1882
- const val = e.target.value;
1883
- if (isValidEmail(val)) {
1884
- popupRef.current?.open();
1885
- }
1886
- setCurrentEmail(val);
1887
- }
1888
- }
1889
- )
1890
- ] }),
1891
- closeOnDocumentClick: true,
1892
- repositionOnResize: true,
1893
- position: "bottom left",
1894
- className: "filter-popup",
1895
- onOpen: () => {
1896
- setPopupOpen(true);
1897
- requestAnimationFrame(() => inputRef.current?.focus());
1898
- },
1899
- onClose: () => {
1900
- setPopupOpen(false);
1901
- },
1902
- children: isValidEmail(currentEmail) ? /* @__PURE__ */ jsx("div", { className: "options-dropdown", children: loading ? (
1903
- // Skeleton loader
1904
- /* @__PURE__ */ jsx(Fragment, { children: [1, 2, 3].map((i) => /* @__PURE__ */ jsxs("div", { className: "option-dropdown skeleton-loader", children: [
1905
- /* @__PURE__ */ jsx("div", { className: "skeleton-line skeleton-name" }),
1906
- /* @__PURE__ */ jsx("div", { className: "skeleton-line skeleton-email" })
1907
- ] }, i)) })
1908
- ) : options.length > 0 ? options.map((opt, idx) => {
1909
- return /* @__PURE__ */ jsxs(
1910
- "button",
1911
- {
1912
- ref: (el) => {
1913
- optionRefs.current[idx] = el;
1914
- },
1915
- className: `option-dropdown ${selectedIndex === idx ? "selected" : ""}`,
1916
- onBlur: (e) => {
1917
- e.stopPropagation();
1918
- },
1919
- onFocus: (e) => {
1920
- e.stopPropagation();
1921
- },
1922
- onMouseEnter: () => setSelectedIndex(idx),
1923
- onMouseLeave: () => setSelectedIndex(-1),
1924
- onClick: (e) => {
1925
- e.stopPropagation();
1926
- addEmail(opt);
1927
- },
1928
- "aria-selected": selectedIndex === idx,
1929
- children: [
1930
- /* @__PURE__ */ jsx("h4", { children: opt.name }),
1931
- opt.email
1932
- ]
1933
- },
1934
- idx
1935
- );
1936
- }) : null }) : null
1937
- }
1938
- ) });
1939
- }
1940
- var InputWIthDropDown_default = InputWithDropDown;
1941
- function InputForEmail({
1942
- name,
1943
- needCCAndBCC,
1944
- setShowCC,
1945
- setShowBCC,
1946
- showBCC,
1947
- showCC,
1948
- emails,
1949
- handleChange,
1950
- fetchOptions
1951
- }) {
1952
- return /* @__PURE__ */ jsxs("div", { className: "container-receipts", children: [
1953
- /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium text-gray-700", children: name }),
1954
- /* @__PURE__ */ jsx(
1955
- InputWIthDropDown_default,
1956
- {
1957
- emails,
1958
- setEmails: handleChange,
1959
- fetchOptions
1960
- }
1961
- ),
1962
- needCCAndBCC && !showCC ? /* @__PURE__ */ jsx("button", { className: "btn", onClick: () => setShowCC?.((prev) => !prev), children: "CC" }) : null,
1963
- needCCAndBCC && !showBCC ? /* @__PURE__ */ jsx("button", { className: "btn", onClick: () => setShowBCC?.((prev) => !prev), children: "BCC" }) : null
1964
- ] });
1965
- }
1966
- var InputForEmail_default = InputForEmail;
1967
- function ReceiptsHeading({ fetchEmailOptions }) {
1968
- const [open, setOpen] = useState(false);
1969
- const wrapperRef = useRef(null);
1970
- const { emails, setEmails, showCC, setShowCC, showBCC, setShowBCC } = useEmailContext();
1971
- useEffect(() => {
1972
- if (open) {
1973
- setShowCC(emails.cc.length > 0);
1974
- setShowBCC(emails.bcc.length > 0);
1975
- }
1976
- }, [open, emails.cc.length, emails.bcc.length]);
1977
- useEffect(() => {
1978
- const wrapper = wrapperRef.current;
1979
- if (!wrapper) return;
1980
- const handleFocusIn = () => {
1981
- setOpen(true);
1982
- };
1983
- const handleFocusOut = (e) => {
1984
- console.log("\u{1F680} ~ handleFocusOut ~ e:", e);
1985
- const next = e.relatedTarget;
1986
- if (next && next.classList && next.classList.contains("option-dropdown") || next && wrapper.contains(next))
1987
- return;
1988
- console.log("why this ", next?.classList);
1989
- setOpen(false);
1990
- };
1991
- wrapper.addEventListener("focusin", handleFocusIn);
1992
- wrapper.addEventListener("focusout", handleFocusOut);
1993
- return () => {
1994
- wrapper.removeEventListener("focusin", handleFocusIn);
1995
- wrapper.removeEventListener("focusout", handleFocusOut);
1996
- };
1997
- }, []);
1998
- const getDisplayText = () => {
1999
- if (emails.to.length === 0 && emails.cc.length === 0 && emails.bcc.length === 0) {
2000
- return "Recipients";
2001
- }
2002
- const parts = [];
2003
- if (emails.to.length > 0) {
2004
- parts.push(emails.to.map((e) => e.email).join(", "));
2005
- }
2006
- if (emails.cc.length > 0) {
2007
- parts.push(emails.cc.map((e) => e.email).join(", "));
2008
- }
2009
- if (emails.bcc.length > 0) {
2010
- parts.push("bcc: " + emails.bcc.map((e) => e.email).join(", "));
2011
- }
2012
- return parts.join(", ");
2013
- };
2014
- return /* @__PURE__ */ jsx("div", { ref: wrapperRef, tabIndex: -1, className: "relative", children: !open ? /* @__PURE__ */ jsx(
2015
- "input",
2016
- {
2017
- type: "text",
2018
- placeholder: "Recipients",
2019
- className: "input-header",
2020
- value: getDisplayText(),
2021
- readOnly: true
2022
- }
2023
- ) : /* @__PURE__ */ jsxs("div", { children: [
2024
- /* @__PURE__ */ jsx(
2025
- InputForEmail_default,
2026
- {
2027
- name: "To",
2028
- needCCAndBCC: true,
2029
- setShowCC,
2030
- setShowBCC,
2031
- showBCC,
2032
- showCC,
2033
- emails: emails.to,
2034
- handleChange: (value) => {
2035
- setEmails((prev) => ({
2036
- ...prev,
2037
- to: typeof value === "function" ? value(prev.to) : value
2038
- }));
2039
- },
2040
- fetchOptions: fetchEmailOptions
2041
- }
2042
- ),
2043
- showCC ? /* @__PURE__ */ jsx(
2044
- InputForEmail_default,
2045
- {
2046
- name: "CC",
2047
- needCCAndBCC: false,
2048
- setShowCC,
2049
- setShowBCC,
2050
- showBCC,
2051
- showCC,
2052
- emails: emails.cc,
2053
- handleChange: (value) => {
2054
- setEmails((prev) => ({
2055
- ...prev,
2056
- cc: typeof value === "function" ? value(prev.cc) : value
2057
- }));
2058
- },
2059
- fetchOptions: fetchEmailOptions
2060
- }
2061
- ) : null,
2062
- showBCC ? /* @__PURE__ */ jsx(
2063
- InputForEmail_default,
2064
- {
2065
- name: "BCC",
2066
- needCCAndBCC: false,
2067
- setShowCC,
2068
- setShowBCC,
2069
- showBCC,
2070
- showCC,
2071
- emails: emails.bcc,
2072
- handleChange: (value) => {
2073
- setEmails((prev) => ({
2074
- ...prev,
2075
- bcc: typeof value === "function" ? value(prev.bcc) : value
2076
- }));
2077
- },
2078
- fetchOptions: fetchEmailOptions
2079
- }
2080
- ) : null
2081
- ] }) });
2082
- }
2083
- var ReceiptsHeading_default = ReceiptsHeading;
2084
- function GmailHeading({
2085
- fetchEmailOptions
2086
- }) {
2087
- const { subject, setSubject, isReply } = useEmailContext();
2088
- return /* @__PURE__ */ jsxs("div", { className: "gmail-header", children: [
2089
- /* @__PURE__ */ jsx(ReceiptsHeading_default, { fetchEmailOptions }),
2090
- /* @__PURE__ */ jsx(
2091
- "input",
2092
- {
2093
- type: "text",
2094
- placeholder: "Subject",
2095
- className: "input-header",
2096
- value: isReply && !subject.startsWith("Re: ") ? `Re: ${subject}` : subject,
2097
- onChange: (e) => setSubject(e.target.value)
2098
- }
2099
- )
2100
- ] });
2101
- }
2102
- var GmailHeading_default = GmailHeading;
2103
- function GmailWrapperContent({
2104
- initialData,
2105
- isReply,
2106
- fetchEmailOptions,
2107
- handleChange,
2108
- leftChildren,
2109
- rightChildren,
2110
- editorChildren,
2111
- isEditorVisible = true
2112
- }) {
2113
- const {
2114
- emails,
2115
- subject,
2116
- attachments,
2117
- setEmails,
2118
- setSubject,
2119
- setAttachments,
2120
- setIsReply
2121
- } = useEmailContext();
2122
- const { theme } = useTheme();
2123
- const [bodyHTML, setBodyHTML] = useState(initialData?.body || "");
2124
- const [emailData, setEmailData] = useState({
2125
- to: initialData?.to || [],
2126
- cc: initialData?.cc || [],
2127
- bcc: initialData?.bcc || [],
2128
- subject: initialData?.subject || "",
2129
- body: initialData?.body || "",
2130
- attachments: initialData?.attachments || [],
2131
- isReply: isReply || false
2132
- });
2133
- useEffect(() => {
2134
- if (initialData) {
2135
- if (initialData.to || initialData.cc || initialData.bcc) {
2136
- setEmails({
2137
- to: initialData.to || [],
2138
- cc: initialData.cc || [],
2139
- bcc: initialData.bcc || []
2140
- });
2141
- }
2142
- if (initialData.subject) {
2143
- setSubject(initialData.subject);
2144
- }
2145
- if (initialData.attachments) {
2146
- setAttachments(initialData.attachments);
2147
- }
2148
- if (initialData.body) {
2149
- setBodyHTML(initialData.body);
2150
- }
2151
- }
2152
- if (isReply !== void 0) {
2153
- setIsReply(isReply);
2154
- }
2155
- }, []);
2156
- const handleEditorChange = (html) => {
2157
- setBodyHTML(html);
2158
- };
2159
- useEffect(() => {
2160
- setEmailData((prev) => ({
2161
- ...prev,
2162
- to: emails.to,
2163
- cc: emails.cc,
2164
- bcc: emails.bcc
2165
- }));
2166
- }, [emails]);
2167
- useEffect(() => {
2168
- setEmailData((prev) => ({
2169
- ...prev,
2170
- subject
2171
- }));
2172
- }, [subject]);
2173
- useEffect(() => {
2174
- setEmailData((prev) => ({
2175
- ...prev,
2176
- body: bodyHTML
2177
- }));
2178
- }, [bodyHTML]);
2179
- useEffect(() => {
2180
- setEmailData((prev) => ({
2181
- ...prev,
2182
- attachments
2183
- }));
2184
- }, [attachments]);
2185
- useEffect(() => {
2186
- setEmailData((prev) => ({
2187
- ...prev,
2188
- isReply
2189
- }));
2190
- }, [isReply]);
2191
- useEffect(() => {
2192
- handleChange(emailData);
2193
- }, [emailData, handleChange]);
2194
- return /* @__PURE__ */ jsxs("div", { className: "react-mail-inbox-root gmail-wrapper", "data-theme": theme, children: [
2195
- leftChildren,
2196
- /* @__PURE__ */ jsx(GmailHeading_default, { fetchEmailOptions }),
2197
- /* @__PURE__ */ jsx(
2198
- EditorWrapper_default,
2199
- {
2200
- initialHTML: initialData?.body,
2201
- onChange: handleEditorChange,
2202
- editorChildren,
2203
- isEditorVisible
2204
- }
2205
- ),
2206
- rightChildren
2207
- ] });
2208
- }
2209
- var GmailWrapperContent_default = GmailWrapperContent;
2210
- function GmailWrapper({
2211
- fetchEmailOptions,
2212
- handleChange,
2213
- initialData,
2214
- leftChildren,
2215
- rightChildren,
2216
- isReply
2217
- }) {
2218
- return /* @__PURE__ */ jsx(EmailProvider, { children: /* @__PURE__ */ jsx(
2219
- GmailWrapperContent_default,
2220
- {
2221
- fetchEmailOptions,
2222
- handleChange,
2223
- initialData,
2224
- isReply,
2225
- leftChildren,
2226
- rightChildren
2227
- }
2228
- ) });
2229
- }
2230
- var GmailWrapper_default = GmailWrapper;
2231
- function GmailInbox({
2232
- fetchEmailOptions,
2233
- handleChange,
2234
- initialData,
2235
- initialTheme = "dark",
2236
- onThemeChange,
2237
- leftChildren,
2238
- rightChildren
2239
- }) {
2240
- return /* @__PURE__ */ jsx(ThemeProvider, { initialTheme, onThemeChange, children: /* @__PURE__ */ jsx(
2241
- GmailWrapper_default,
2242
- {
2243
- fetchEmailOptions,
2244
- handleChange,
2245
- initialData,
2246
- leftChildren,
2247
- rightChildren
2248
- }
2249
- ) });
2250
- }
2251
- var GmailInbox_default = GmailInbox;
2252
-
2253
- // src/index.tsx
2254
- var index_default = GmailInbox_default;
2255
-
2256
- export { GmailInbox_default as GmailInbox, index_default as default, useTheme };
2257
- //# sourceMappingURL=index.mjs.map
1
+ import {createContext,useContext,useState,useEffect,useRef,useCallback,useMemo}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {AutoFocusPlugin}from'@lexical/react/LexicalAutoFocusPlugin';import {LexicalComposer}from'@lexical/react/LexicalComposer';import {RichTextPlugin}from'@lexical/react/LexicalRichTextPlugin';import {ContentEditable}from'@lexical/react/LexicalContentEditable';import {HistoryPlugin}from'@lexical/react/LexicalHistoryPlugin';import {LexicalErrorBoundary}from'@lexical/react/LexicalErrorBoundary';import {createPortal}from'react-dom';import {MdClose,MdEdit,MdTextFields,MdCheck,MdImage,MdLink,MdAttachFile,MdTextFormat,MdArrowDropDown,MdFormatQuote,MdStrikethroughS,MdFormatClear,MdOutlineFormatIndentIncrease,MdFormatIndentDecrease,MdFormatListNumbered,MdFormatListBulleted,MdFormatAlignCenter,MdFormatAlignRight,MdFormatAlignLeft,MdFormatUnderlined,MdFormatItalic,MdFormatBold,MdRedo,MdUndo}from'react-icons/md';import po from'reactjs-popup';import {useLexicalComposerContext}from'@lexical/react/LexicalComposerContext';import {$getRoot,$getSelection,$isRangeSelection,SELECTION_CHANGE_COMMAND,REDO_COMMAND,UNDO_COMMAND,FORMAT_ELEMENT_COMMAND,FORMAT_TEXT_COMMAND,OUTDENT_CONTENT_COMMAND,INDENT_CONTENT_COMMAND}from'lexical';import {ListNode,ListItemNode,$isListNode,INSERT_UNORDERED_LIST_COMMAND,REMOVE_LIST_COMMAND,INSERT_ORDERED_LIST_COMMAND}from'@lexical/list';import {LinkNode,AutoLinkNode,$isLinkNode,TOGGLE_LINK_COMMAND}from'@lexical/link';import {$getNearestNodeOfType,mergeRegister}from'@lexical/utils';import {$isAtNodeEnd,$patchStyleText}from'@lexical/selection';import {useDropzone}from'react-dropzone';import Uo from'heic2any';import {ListPlugin}from'@lexical/react/LexicalListPlugin';import {LinkPlugin}from'@lexical/react/LexicalLinkPlugin';import {$generateNodesFromDOM,$generateHtmlFromNodes}from'@lexical/html';var Ae=createContext(void 0),te=()=>{let e=useContext(Ae);if(!e)throw new Error("useTheme must be used within a ThemeProvider");return e},Ie=({children:e,initialTheme:o="dark",onThemeChange:n})=>{let[r,t]=useState(o);useEffect(()=>{n&&n(r);},[r,n]);let i=()=>{t(l=>l==="light"?"dark":"light");};return jsx(Ae.Provider,{value:{theme:r,toggleTheme:i},children:e})};var De=createContext(void 0),B=()=>{let e=useContext(De);if(!e)throw new Error("useEmailContext must be used within an EmailProvider");return e},ze=({children:e})=>{let[o,n]=useState({to:[],cc:[],bcc:[]}),[r,t]=useState(false),[i,l]=useState(""),[d,h]=useState(false),[u,x]=useState(false),[a,m]=useState([]);return useEffect(()=>{console.log("EmailProvider emails updated:",o);},[o]),jsx(De.Provider,{value:{emails:o,setEmails:n,subject:i,setSubject:l,showCC:d,setShowCC:h,showBCC:u,setShowBCC:x,attachments:a,setAttachments:m,isReply:r,setIsReply:t},children:e})};var s={undo:"undo",redo:"redo",bold:"bold",italic:"italic",underline:"underline",color:{base:"colors"},code:"code",link:"link",listNumber:"listNumber",listBullet:"listBullet",align:{base:"align"},indent:"indent",indentDecrease:"indentDecrease",strike:"strike",attachFile:"attachFile",fontSize:"fontSize",fontFamily:"fontFamily"},y={styling:"styling",divider:"divider",component:"component"},Be=[{type:y.styling,icon:"Styling",id:"4bc66ea9-2e35-4a7b-a674-be7e4ee163c5",options:[{name:s.undo,type:y.component,icon:"Undo",id:"29cf5eb3-37cd-482f-9a15-c358faf19cc2"},{name:s.redo,type:y.component,icon:"Redo",id:"8744f7ab-5818-46ce-9417-2fec87123afe"},{type:y.divider,id:"ed0104fd-3507-43f6-80c1-813fbdf04479"},{name:s.fontFamily,type:y.component,id:"1c12d7e2-aa6a-42b4-b25c-b55fe3bcf524"},{type:y.divider,id:"d0f67d01-0731-411a-b448-e1dca47014f4"},{name:s.fontSize,type:y.component,id:"82e31b62-5441-4052-887c-faa02d0b7075"},{type:y.divider,id:"2e3558e4-3ad4-422b-8502-ea3c58fb8c2e"},{name:s.bold,type:y.component,icon:"Bold",id:"ac2b5b54-7323-44a4-bc6d-8bae6e48efe2"},{name:s.italic,type:y.component,icon:"Italic",id:"6a927c2a-2230-4dc7-af71-47fbe9fb784d"},{name:s.underline,type:y.component,icon:"Underline",id:"f07b3a6f-ffaa-4153-beae-79a36acb6a08"},{name:s.color.base,type:y.component,icon:"Color",id:"e14ec25f-3dd3-4ed5-b33a-a033684d248b"},{type:y.divider,id:"93e60297-206f-4f31-bc29-11daff2052bd"},{name:s.align.base,type:y.component,id:"30da93ea-efa6-4642-bfa5-28fd4dc9c5b3"},{type:y.divider,id:"9bad0563-6118-4855-9286-402bf98e00ad"},{name:s.listNumber,type:y.component,icon:"OrderedList",id:"d37865e1-ff54-4118-a5cc-fa147d222471"},{name:s.listBullet,type:y.component,icon:"UnOrderedList",id:"ed77e7c9-b89c-41c5-a749-e68ea0b30497"},{type:y.divider,id:"e5ecd77b-44cc-42fe-badb-48cadf3ddfb1"},{name:s.indentDecrease,type:y.component,icon:"IndentLess",id:"2dc6a5e4-b1b5-47d1-ac2f-5d0becb02d33"},{name:s.indent,type:y.component,icon:"IndentMore",id:"6903a3d1-a83f-4bc6-9bd9-f673feffe84f"}]},{type:"component",name:s.attachFile,icon:"Attach",id:"f43a284e-113e-4095-b001-9d00a1dddc4c"},{type:"component",name:s.link,icon:"Link",id:"580db61e-7939-4efe-914c-304b271998ec"}];var ao={Undo:MdUndo,Redo:MdRedo,Bold:MdFormatBold,Italic:MdFormatItalic,Underline:MdFormatUnderlined,Color:MdTextFormat,LeftAlign:MdFormatAlignLeft,RightAlign:MdFormatAlignRight,CenterAlign:MdFormatAlignCenter,UnOrderedList:MdFormatListBulleted,OrderedList:MdFormatListNumbered,IndentLess:MdFormatIndentDecrease,IndentMore:MdOutlineFormatIndentIncrease,RemoveFormat:MdFormatClear,StrikeThrough:MdStrikethroughS,CodeQuote:MdFormatQuote,DownArrow:MdArrowDropDown,Styling:MdTextFormat,Attach:MdAttachFile,Link:MdLink,Image:MdImage,Check:MdCheck,TextFields:MdTextFields,Edit:MdEdit,Close:MdClose},Ue=ao;var lo=({name:e,size:o=24,color:n,className:r})=>{let t=Ue[e];return t?jsx(t,{size:o,color:n,className:r}):(console.warn(`Icon "${e}" not found.`),null)},k=lo;var mo=({trigger:e,children:o,popUpDirection:n="top center"})=>{let r=useRef(null),t=()=>{r.current&&typeof r.current.close=="function"&&r.current.close();};return jsx(po,{ref:r,trigger:e,closeOnDocumentClick:true,repositionOnResize:true,position:n,className:"filter-popup",children:l=>o({close:()=>{l?.(),t();}})})},_=mo;var uo=[{label:"Sans Serif",value:"sans-serif",style:{fontFamily:"sans-serif"}},{label:"Serif",value:"serif",style:{fontFamily:"serif"}},{label:"Fixed Width",value:"monospace",style:{fontFamily:"monospace"}},{label:"Wide",value:"wide",style:{fontWeight:"bold",letterSpacing:"0.05em"}},{label:"Narrow",value:"narrow",style:{fontStretch:"condensed"}},{label:"Comic Sans MS",value:"Comic Sans MS",style:{fontFamily:"Comic Sans MS, cursive"}},{label:"Garamond",value:"Garamond",style:{fontFamily:"Garamond, serif"}},{label:"Georgia",value:"Georgia",style:{fontFamily:"Georgia, serif"}},{label:"Tahoma",value:"Tahoma",style:{fontFamily:"Tahoma, sans-serif"}},{label:"Trebuchet MS",value:"Trebuchet MS",style:{fontFamily:"Trebuchet MS, sans-serif"}},{label:"Verdana",value:"Verdana",style:{fontFamily:"Verdana, sans-serif"}}],oe=[{key:"small",label:"Small",sizePx:12},{key:"normal",label:"Normal",sizePx:18},{key:"large",label:"Large",sizePx:28},{key:"huge",label:"Huge",sizePx:56}],me=["#000000","#3a3a3a","#5a5a5a","#8a8a8a","#bfbfbf","#dedede","#f3f3f3","#ffffff"],fe=["#e53935","#fb8c00","#ffee58","#66ff66","#4dd0e1","#1e88e5","#9c27b0","#ff3bd6"],ue=[["#f7d7d7","#f3d0c8","#f0c5c5","#efc9d8","#f7e6e9","#f3edf7","#f0eaf6","#f8f0f6"],["#f0b9b9","#f0d4c2","#e6f0d2","#e4f7e8","#d8eef8","#dbe1ff","#e9d9f6","#f5d9f7"],["#e69a9a","#e6caa3","#d7e6b0","#c8f0e6","#bfe3ff","#cbd8ff","#d6c3f3","#f0c2f3"],["#d16464","#d09a6a","#a8cf7b","#7fd6c0","#73b7ff","#7a9cff","#b483f1","#f08cf2"],["#b23a3a","#b26a3a","#7aa04a","#3fb092","#296f94","#2a4177","#452a68","#6e1f4d"],["#7a1d1d","#7a4a1e","#556a2a","#195b47","#123f5a","#182840","#2a1836","#3a1026"]],ge=uo;function be({value:e="serif",onChange:o}){return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[ge?.find(n=>n.value===e)?.label,jsx(k,{name:"DownArrow"})]}),children:({close:n})=>jsx("div",{className:"p-4",children:jsx("div",{className:"font-options",children:ge.map(r=>jsx("button",{className:"btn",onClick:()=>{o(r.value),n();},style:{...r.style},children:jsxs("div",{className:"font-option",children:[e===r.value&&jsx(k,{name:"Check"}),r.label]})},r.value))})})})})}function he({value:e="normal",onChange:o=()=>{}}){return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:"TextFields"}),jsx(k,{name:"DownArrow"})]}),children:({close:n})=>jsx("div",{className:"p-4",children:jsx("div",{className:"font-options",children:oe.map(r=>jsx("button",{className:"btn",onClick:()=>{o(r.key),n();},style:{fontSize:`${r.sizePx}px`},children:jsxs("div",{className:"font-option",children:[e===r.key&&jsx(k,{name:"Check"}),r.label]})},r.key))})})})})}function Y({color:e,selected:o,onClick:n,label:r}){return jsx("button",{className:"swatch",title:r||e,"aria-pressed":o,onClick:()=>n(e),style:{background:e},children:o&&jsx("svg",{className:"check",viewBox:"0 0 24 24","aria-hidden":true,children:jsx("path",{d:"M20 6L9 17l-5-5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})})})}function xe({value:e={background:"#ffffff",text:"#000000"},onChange:o=()=>{}}){function n(r,t){o({...e,[r]:t});}return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:"Styling"}),jsx(k,{name:"DownArrow"})]}),children:({close:r})=>jsx("div",{className:"color-popover",role:"dialog","aria-label":"Choose colors",children:jsxs("div",{className:"color-columns",children:[jsxs("section",{className:"color-column","aria-labelledby":"bg-label",children:[jsx("h4",{id:"bg-label",children:"Background color"}),jsx("div",{className:"row",children:me.map(t=>jsx(Y,{color:t,selected:e.background===t,onClick:i=>{n("background",i),r();},label:t},t+"bg"))}),jsx("div",{className:"row accent-row",children:fe.map(t=>jsx(Y,{color:t,selected:e.background===t,onClick:i=>{n("background",i),r();},label:t},t+"bgacc"))}),jsx("div",{className:"palette",children:ue.map((t,i)=>jsx("div",{className:"palette-row",children:t.map(l=>jsx(Y,{color:l,selected:e.background===l,onClick:d=>{n("background",d),r();},label:l},l+"bgp"+i))},"row"+i))})]}),jsxs("section",{className:"color-column","aria-labelledby":"text-label",children:[jsx("h4",{id:"text-label",children:"Text color"}),jsx("div",{className:"row",children:me.map(t=>jsx(Y,{color:t,selected:e.text===t,onClick:i=>{n("text",i),r();},label:t},t+"tx"))}),jsx("div",{className:"row accent-row",children:fe.map(t=>jsx(Y,{color:t,selected:e.text===t,onClick:i=>{n("text",i),r();},label:t},t+"txacc"))}),jsx("div",{className:"palette",children:ue.map((t,i)=>jsx("div",{className:"palette-row",children:t.map(l=>jsx(Y,{color:l,selected:e.text===l,onClick:d=>{n("text",d),r();},label:l},l+"txp"+i))},"txrow"+i))})]})]})})})})}var Ge=[{key:"left",iconName:"LeftAlign",label:"Left align"},{key:"center",iconName:"CenterAlign",label:"Center align"},{key:"right",iconName:"RightAlign",label:"Right align"}];function ve({value:e="left",onChange:o=()=>{}}){function n(r){o(r);}return jsx("div",{children:jsx(_,{trigger:jsxs("button",{className:"font-option heading",children:[jsx(k,{name:Ge?.find(r=>r.key===e)?.iconName||"LeftAlign"}),jsx(k,{name:"DownArrow"})]}),children:({close:r})=>jsx("div",{className:"wrapper-alignment",children:Ge.map(t=>{let i=t.key===e;return jsxs("button",{role:"menuitemradio","aria-checked":i,tabIndex:0,className:`alignment-option ${i?"active":""}`,onClick:()=>{n(t.key),r();},children:[jsx("div",{className:"option-icon",children:jsx(k,{name:t.iconName,size:20})}),jsx("div",{className:`option-check ${i?"":"hidden"}`,"aria-hidden":true,children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",children:jsx("path",{d:"M20 6L9 17l-5-5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]},t.key)})})})})}var Oo=1;function Xe(e){if(!e||e.startsWith("#"))return e;if(e.startsWith("rgba")){let n=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*([\d.]+)?\)/);if(n){let[,r,t,i,l]=n;return l==="0"?"transparent":"#"+[r,t,i].map(d=>{let h=parseInt(d).toString(16);return h.length===1?"0"+h:h}).join("")}}let o=e.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(o){let[,n,r,t]=o;return "#"+[n,r,t].map(i=>{let l=parseInt(i).toString(16);return l.length===1?"0"+l:l}).join("")}return e}function Po(){let[e]=useLexicalComposerContext(),[o,n]=useState("paragraph"),[r,t]=useState({[s.fontFamily]:"sans-serif",[s.fontSize]:16,[s.align.base]:"left"}),[i,l]=useState(false),d=useCallback(()=>{let f=$getSelection(),b={[s.fontFamily]:"sans-serif",[s.fontSize]:16,[s.align.base]:"left"};if($isRangeSelection(f)){let F=f.anchor.getNode(),c=F.getKey()==="root"?F:F.getTopLevelElementOrThrow(),p=c.getKey(),g=e.getElementByKey(p);if(g!==null)if($isListNode(c)){let L=$getNearestNodeOfType(F,ListNode),ee=L?L.getTag():c.getTag();n(ee);}else {let L=c.getType();n(L);}b[s.bold]=f.hasFormat("bold"),b[s.italic]=f.hasFormat("italic"),b[s.underline]=f.hasFormat("underline"),b[s.strike]=f.hasFormat("strikethrough"),b[s.code]=f.hasFormat("code");let H=O(f),P=H.getParent();$isLinkNode(P)||$isLinkNode(H)?(b[s.link]=true,l(true)):(b[s.link]=false,l(false));let D=e.getElementByKey(H.getKey()),T=e.getElementByKey(P.getKey()),S=D||T||g;if(S){let L=window.getComputedStyle(S),ee=L.getPropertyValue("font-family");if(ee){let G=ee.split(",")[0].trim().replace(/['"]/g,"");(G==="-apple-system"||G==="BlinkMacSystemFont"||G==="system-ui")&&(G="sans-serif"),b[s.fontFamily]=G;}let Le=L.getPropertyValue("font-size");if(Le){let G=parseInt(Le,10);b[s.fontSize]=G||16;}let W=null,z=null;S instanceof HTMLElement&&S.style&&(W=S.style.color||null,z=S.style.backgroundColor||null),W||(W=L.getPropertyValue("color")),z||(z=L.getPropertyValue("background-color")),console.log("\u{1F3A8} Color detection:",{inlineColor:S instanceof HTMLElement?S.style.color:"N/A",inlineBg:S instanceof HTMLElement?S.style.backgroundColor:"N/A",computedColor:W,computedBg:z,element:S});let Te=W?Xe(W):null,Me=z&&z!=="rgba(0, 0, 0, 0)"&&z!=="transparent"?Xe(z):null;(Te||Me)&&(b[s.color.base]={text:Te||"#000000",background:Me||"#ffffff"});let pe=L.getPropertyValue("text-align")||"left";pe==="start"&&(pe="left"),b[s.align.base]=pe;}t(b);}},[e]);useEffect(()=>mergeRegister(e.registerUpdateListener(({editorState:f})=>{f.read(()=>{d();});}),e.registerCommand(SELECTION_CHANGE_COMMAND,()=>(d(),false),Oo)),[e,d]);function h(f,b){switch(f){case s.bold:e.dispatchCommand(FORMAT_TEXT_COMMAND,"bold");break;case s.italic:e.dispatchCommand(FORMAT_TEXT_COMMAND,"italic");break;case s.underline:e.dispatchCommand(FORMAT_TEXT_COMMAND,"underline");break;case s.align.base:e.dispatchCommand(FORMAT_ELEMENT_COMMAND,b);break;case s.undo:e.dispatchCommand(UNDO_COMMAND,void 0);break;case s.redo:e.dispatchCommand(REDO_COMMAND,void 0);break;case s.listNumber:w();break;case s.listBullet:v();break;case s.indent:u();break;case s.indentDecrease:N();break;case s.color.base:m(b);break;case s.fontFamily:x(b);break;case s.fontSize:a(b);break;case s.link:E();break;}}let u=()=>{e.dispatchCommand(INDENT_CONTENT_COMMAND,void 0);},x=f=>{e.update(()=>{let b=$getSelection();$isRangeSelection(b)&&$patchStyleText(b,{"font-family":f});});},a=f=>{let b=oe.find(F=>F.key===f)?.sizePx??16;e.update(()=>{let F=$getSelection();$isRangeSelection(F)&&$patchStyleText(F,{"font-size":`${b}px`});});},m=f=>{e.update(()=>{let b=$getSelection();$isRangeSelection(b)&&$patchStyleText(b,{"background-color":f.background,color:f.text});});},E=useCallback(()=>{i?e.dispatchCommand(TOGGLE_LINK_COMMAND,null):e.dispatchCommand(TOGGLE_LINK_COMMAND,"https://");},[e,i]),N=()=>{e.dispatchCommand(OUTDENT_CONTENT_COMMAND,void 0);},v=()=>{o!=="ul"?e.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND,void 0):e.dispatchCommand(REMOVE_LIST_COMMAND,void 0);},w=()=>{o!=="ol"?e.dispatchCommand(INSERT_ORDERED_LIST_COMMAND,void 0):e.dispatchCommand(REMOVE_LIST_COMMAND,void 0);};function O(f){let b=f.anchor,F=f.focus,c=f.anchor.getNode(),p=f.focus.getNode();return c===p?c:f.isBackward()?$isAtNodeEnd(F)?c:p:$isAtNodeEnd(b)?p:c}return {onChange:h,isLink:i,editor:e,selectedEventTypes:r,blockType:o}}var Qe=Po;function Do({editor:e}){let o=useRef(null),n=useRef(null),r=useRef(false),[t,i]=useState(""),[l,d]=useState(false),[h,u]=useState(null),x=useCallback(()=>{let a=window.getSelection(),m=$getSelection();if($isRangeSelection(m)){let w=zo(m),O=w.getParent();$isLinkNode(O)?i(O.getURL()):$isLinkNode(w)?i(w.getURL()):i("");}let E=o.current,N=document.activeElement;if(!E)return;let v=e.getRootElement();if(m&&a&&!a.isCollapsed&&v&&v.contains(a.anchorNode)){let w=a.getRangeAt(0),O;if(a.anchorNode===v){let f=v;for(;f.firstElementChild!=null;)f=f.firstElementChild;O=f.getBoundingClientRect();}else O=w.getBoundingClientRect();r.current||tt(E,O),u(m);}else (!N||N.className!=="link-input")&&(tt(E,null),u(null),d(false),i(""));return true},[e]);return useEffect(()=>mergeRegister(e.registerUpdateListener(({editorState:a})=>{a.read(()=>{x();});}),e.registerCommand(SELECTION_CHANGE_COMMAND,()=>(x(),true),1)),[e,x]),useEffect(()=>{e.getEditorState().read(()=>{x();});},[e,x]),useEffect(()=>{l&&n.current&&n.current.focus();},[l]),jsxs("div",{className:"floating-link-editor",ref:o,children:[l?jsx("input",{ref:n,className:"link-input",value:t,onChange:a=>i(a.target.value),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),h&&t!==""&&e.dispatchCommand(TOGGLE_LINK_COMMAND,t),d(false)):a.key==="Escape"&&(a.preventDefault(),d(false));},placeholder:"Enter link..."}):jsx("div",{className:"link-display",children:jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:t||"No link selected"})}),jsx("button",{className:"link-button",onMouseDown:a=>a.preventDefault(),onClick:()=>{console.log("floating link editor",l),l&&e.dispatchCommand(TOGGLE_LINK_COMMAND,t),d(a=>!a);},children:jsx(k,{name:l?"Check":"Edit"})})]})}function zo(e){let o=e.anchor.getNode(),n=e.focus.getNode();return o===n?o:e.isBackward()?$isAtNodeEnd(e.focus)?o:n:$isAtNodeEnd(e.anchor)?n:o}function tt(e,o){if(!o){e.style.opacity="0",e.style.top="-1000px",e.style.left="-1000px";return}let n=e.offsetWidth,r=e.offsetHeight,t=window.innerWidth,i=window.innerHeight,l=o.top+o.height+window.pageYOffset+10,d=o.left+window.pageXOffset-n/2+o.width/2;d<8&&(d=8),d+n>t-8&&(d=t-n-8),l+r>i-8&&(l=o.top+window.pageYOffset-r-10),l<8&&(l=8),e.style.opacity="1",e.style.top=`${l}px`,e.style.left=`${d}px`;}var ot=Do;var $={FILE_INVALID_TYPE:"file-invalid-type",FILE_TOO_LARGE:"file-too-large",TOO_MANY_FILES:"too-many-files",HEIC_CONVERSION_ERROR:"heic-conversion-error"},$o=10,Ho=10,it=()=>Math.random().toString(36).substring(2,10)+Date.now().toString(36),Go=e=>{if(e<1024)return {value:e.toString(),type:"bytes"};let o=e/1024;if(o<1024)return {value:o.toFixed(1),type:"KB"};let n=o/1024;return n<1024?{value:n.toFixed(1),type:"MB"}:{value:(n/1024).toFixed(1),type:"GB"}},at=({accept:e={"image/*":[".png",".gif",".jpeg",".jpg"],"application/pdf":[".pdf"]},maxSize:o=Ho*1024*1024,maxFiles:n=$o,multiple:r=true,isDisabled:t=false,replaceAfterUpload:i=false,files:l=[],handleFileChange:d=()=>{}})=>{let[h,u]=useState(false),[x,a]=useState(l??[]),[m,E]=useState([]),N=c=>{switch(c){case $.FILE_INVALID_TYPE:return "Invalid file type. Please upload a supported format.";case $.FILE_TOO_LARGE:{let{value:p,type:g}=Go(o);return `File too large. Maximum allowed size is ${p} ${g}.`}case $.TOO_MANY_FILES:return `Too many files selected. Maximum allowed: ${n}.`;case $.HEIC_CONVERSION_ERROR:return "Failed to convert HEIC image. Please upload a JPEG or PNG instead.";default:return "An unknown file error occurred."}};useEffect(()=>{d(x);},[x]);let{getRootProps:v,getInputProps:w,isDragActive:O,open:f}=useDropzone({accept:e,maxSize:o,multiple:r,maxFiles:n,disabled:t,noClick:true,onFileDialogCancel:()=>u(false),onFileDialogOpen:()=>{t||u(true);},onDrop:async(c,p)=>{let H=(await Promise.all(c.map(async P=>{if(!P)return null;if(P.type==="image/heic")try{let D=await Uo({blob:P,toType:"image/jpeg"}),T=Array.isArray(D)?D[0]:D,S=new File([T],`${P.name.replace(/\.heic$/i,"")}.jpeg`,{type:"image/jpeg"});return Object.assign(S,{uuid:it(),preview:URL.createObjectURL(S)})}catch(D){console.error("HEIC conversion error:",D);let T=N($.HEIC_CONVERSION_ERROR);return E(S=>[...S,{file:P,preview:URL.createObjectURL(P),readableErrors:[T],errors:[{code:$.HEIC_CONVERSION_ERROR,message:T}]}]),null}return Object.assign(P,{uuid:it(),preview:URL.createObjectURL(P)})}))).filter(Boolean);if(!t){let P=i?[]:[...x];P=[...P,...H];let D=p.map(T=>{let S=T.errors.map(L=>N(L.code));return {file:T.file,errors:T.errors.map(L=>({code:L.code,message:L.message})),preview:URL.createObjectURL(T.file),readableErrors:S}});return E(T=>[...T,...D]),a(P),P}return x},validator:c=>{let{name:p,type:g}=c;if(p){let H=p.split(".").pop()?.toLowerCase();if(e&&e?.[g]&&e?.[g].length&&!e?.[g].includes(`.${H}`))return {code:$.FILE_INVALID_TYPE,message:N($.FILE_INVALID_TYPE)}}return null}}),b=useCallback(c=>{a(p=>p.filter(g=>g.uuid!==c));},[a]),F=useCallback(()=>{E([]);},[]);return useEffect(()=>()=>{x.forEach(c=>c.preview&&URL.revokeObjectURL(c.preview)),m.forEach(c=>c.preview&&URL.revokeObjectURL(c.preview));},[]),{getRootProps:v,getInputProps:w,isDragActive:O,isFileDialogOpen:h,rejectedFiles:m,openFileDialog:f,removeFile:b,clearRejectedFiles:F}};var jo=({handleFileChange:e})=>{let{getRootProps:o,getInputProps:n,openFileDialog:r}=at({multiple:true,maxFiles:5,maxSize:5242880,handleFileChange:t=>{e(t);}});return jsx("div",{className:"uploader-container",children:jsxs("div",{...o(),children:[jsx("input",{...n()}),jsx("button",{onClick:r,children:jsx(k,{className:"upload-icon",name:"Attach"})})]})})},lt=jo;function Se({file:e,index:o,onRemove:n,onView:r}){if(!e)return null;let t=e?.name??"unknown",i=e instanceof File||"size"in e&&e.size!==void 0?e.size:"bytes"in e&&e.bytes!==void 0?e.bytes:null,l=("url"in e?e?.url:null)??null,d=useMemo(()=>{if(l)return l;if(typeof window<"u"&&e instanceof File)try{return URL.createObjectURL(e)}catch{return null}return null},[e,l]),h=a=>{if(!a&&a!==0)return "";let m=Math.round(a/1024);return m<1024?`${m}K`:`${Math.round(a/1024/1024*10)/10}M`},u=a=>{if(a.preventDefault(),r)return r(d??null);d&&window.open(d,"_blank","noopener");},x=a=>{n&&n(a);};return jsxs("div",{className:"fps-row",role:"group","aria-label":`Attachment ${t}`,children:[jsxs("div",{className:"fps-left",children:[jsx("a",{href:d??"#",className:"fps-filename",onClick:u,title:t,target:"_blank",rel:"noopener noreferrer",children:t}),i!=null&&jsxs("span",{className:"fps-size",children:["\xA0(",h(i),")"]})]}),jsx("button",{type:"button",className:"fps-close","aria-label":`Remove ${t}`,onClick:()=>x(o),children:"\xD7"})]})}var dt=(e,{onChange:o,state:n,setState:r,selectedEventTypes:t,blockType:i,setAttachments:l})=>{switch(e.name){case s.undo:case s.redo:case s.bold:case s.italic:case s.underline:case s.indentDecrease:case s.indent:case s.link:return jsx("button",{className:`tool-bar-button ${t?.[e.name]?"active-btn-toolbar":""}`,onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.listNumber:return jsx("button",{className:i==="ol"?"active-btn-toolbar":"",onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.listBullet:return jsx("button",{className:i==="ul"?"active-btn-toolbar":"",onClick:()=>{o(e.name,true);},children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})},`${e.name}-${e.icon}`);case s.attachFile:return jsx(lt,{value:n?.[e.name],handleFileChange:d=>{console.log("\u{1F680} ~ getToolbarComponent ~ e:",d),r(h=>({...h,[e.name]:d})),l(d);}});case s.fontFamily:return jsx(be,{value:t?.[e.name]||n?.[e.name],onChange:d=>{o(e.name,d);}});case s.fontSize:return jsx(he,{value:t?.[e.name]||n?.[e.name],onChange:d=>{o(e.name,d);}});case s.color.base:return jsx(xe,{value:t?.[e.name]||n?.[e.name],onChange:d=>{o(e.name,d);}});case s.align.base:return jsx(ve,{value:t?.[e.name]||n?.[e.name],onChange:d=>{o(e.name,d);}});}return e.type===y.divider?jsx("span",{className:"divider"}):"-"},Yo=(e,{setToggle:o,toggle:n,onChange:r,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h})=>{switch(e.type){case y.divider:return jsx("div",{className:"divider"},`divider-${e.type}-${e.icon}`);case y.component:return dt(e,{onChange:r,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h});case y.styling:return jsxs("div",{className:"styling-toolbar",children:[n?jsx("div",{className:"styling-options",children:e.options?.length&&Array.isArray(e.options)?e.options?.map(u=>dt(u,{onChange:r,state:t,setState:i,selectedEventTypes:l,blockType:d,setAttachments:h})):null}):null,jsx("button",{onClick:()=>o(u=>!u),children:jsx(k,{className:"tool-bar-button-icon",name:e.icon})})]},`divider-${e.type}-${e.icon}`);}return "-"};function qo({rightChildren:e,leftChildren:o}){let[n,r]=useState(true),[t,i]=useState({}),{setAttachments:l}=B(),{onChange:d,isLink:h,editor:u,selectedEventTypes:x,blockType:a}=Qe();return console.log("\u{1F680} ~ ToolBar ~ selectedEventTypes:",x),jsxs("div",{className:"toolbar-container",children:[t[s.attachFile]?.length?jsx("div",{className:"file-upload-container",children:t[s.attachFile]?.map((m,E)=>jsx(Se,{file:m,index:E,onRemove:N=>{i(v=>{let w=v[s.attachFile].filter((O,f)=>f!==N);return l(w),{...v,[s.attachFile]:w}});}},E))}):null,jsxs("div",{className:"toolbar-wrapper",children:[o,Be?.map(m=>Yo(m,{setToggle:r,state:t,setState:i,toggle:n,onChange:d,selectedEventTypes:x,blockType:a,setAttachments:l})),e,h?createPortal(jsx(ot,{editor:u}),document.body):null]})]})}var pt=qo;var Xo={ltr:"ltr",rtl:"rtl",placeholder:"editor-placeholder",paragraph:"editor-paragraph",quote:"editor-quote",heading:{h1:"editor-heading-h1",h2:"editor-heading-h2",h3:"editor-heading-h3",h4:"editor-heading-h4",h5:"editor-heading-h5"},list:{nested:{listitem:"editor-nested-listitem"},ol:"editor-list-ol",ul:"editor-list-ul",listitem:"editor-listitem"},image:"editor-image",link:"editor-link",text:{bold:"editor-text-bold",italic:"editor-text-italic",overflowed:"editor-text-overflowed",hashtag:"editor-text-hashtag",underline:"editor-text-underline",strikethrough:"editor-text-strikethrough",underlineStrikethrough:"editor-text-underlineStrikethrough",code:"editor-text-code"},code:"editor-code",codeHighlight:{atrule:"editor-tokenAttr",attr:"editor-tokenAttr",boolean:"editor-tokenProperty",builtin:"editor-tokenSelector",cdata:"editor-tokenComment",char:"editor-tokenSelector",class:"editor-tokenFunction","class-name":"editor-tokenFunction",comment:"editor-tokenComment",constant:"editor-tokenProperty",deleted:"editor-tokenProperty",doctype:"editor-tokenComment",entity:"editor-tokenOperator",function:"editor-tokenFunction",important:"editor-tokenVariable",inserted:"editor-tokenSelector",keyword:"editor-tokenAttr",namespace:"editor-tokenVariable",number:"editor-tokenProperty",operator:"editor-tokenOperator",prolog:"editor-tokenComment",property:"editor-tokenProperty",punctuation:"editor-tokenPunctuation",regex:"editor-tokenVariable",selector:"editor-tokenSelector",string:"editor-tokenSelector",symbol:"editor-tokenProperty",tag:"editor-tokenProperty",url:"editor-tokenOperator",variable:"editor-tokenVariable"}},mt=Xo;function tr({initialHTML:e}){let[o]=useLexicalComposerContext();return useEffect(()=>{o.update(()=>{let r=new DOMParser().parseFromString(e,"text/html"),t=$generateNodesFromDOM(o,r),i=$getRoot();i.clear(),i.append(...t);});},[o,e]),null}var ft=tr;function Pe({onChange:e}){let[o]=useLexicalComposerContext();return useEffect(()=>o.registerUpdateListener(({editorState:n})=>{n.read(()=>{let r=$generateHtmlFromNodes(o,null);e(r);});}),[o,e]),null}function hr(e){console.error(e);}function xr({placeholder:e="Enter some text here",initialHTML:o="",rightChildren:n,leftChildren:r,minHeight:t="",onChange:i,editorChildren:l,isEditorVisible:d=true}){return jsx("div",{className:"my-editor-wrapper",children:jsxs(LexicalComposer,{initialConfig:{namespace:"MyEditor",theme:mt,nodes:[LinkNode,ListNode,ListItemNode,AutoLinkNode],onError:hr},children:[d?jsx(RichTextPlugin,{contentEditable:jsx(ContentEditable,{style:{minHeight:t},className:"my-editor-content","aria-placeholder":e,placeholder:jsx("div",{className:"my-editor-placeholder",children:e})}),ErrorBoundary:LexicalErrorBoundary}):l,jsx(pt,{rightChildren:n,leftChildren:r}),jsx(HistoryPlugin,{}),jsx(ft,{initialHTML:o}),jsx(AutoFocusPlugin,{}),jsx(ListPlugin,{}),jsx(LinkPlugin,{}),i&&jsx(Pe,{onChange:i})]})})}var ut=xr;function X(e){return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function kr({emails:e=[],setEmails:o,fetchOptions:n}){let r=useRef(null),t=useRef(null),[i,l]=useState(""),[d,h]=useState(false),[u,x]=useState(-1),[a,m]=useState([]),[E,N]=useState(false),v=useRef([]),w=useRef([]);useEffect(()=>{v.current=v.current.slice(0,e.length);},[e.length]),useEffect(()=>{w.current=w.current.slice(0,a.length);},[a.length]),useEffect(()=>{X(i)?(async()=>{N(true);try{let p=await n(i);m(p);}catch(p){console.error("Error fetching email options:",p),m([]);}finally{N(false);}})():(m([]),N(false));},[i,n]),useEffect(()=>{d||x(-1);},[d]),useEffect(()=>{u>=0&&u<w.current.length&&w.current[u]?.scrollIntoView({block:"nearest",behavior:"smooth"});},[u]);let O=()=>{t.current?.focus();},f=c=>{r.current?.close(),l(""),o(p=>[...p,c]),x(-1),requestAnimationFrame(()=>t.current?.focus());},b=c=>{if(d&&X(i)&&a.length>0){if(c.key==="ArrowDown"){c.preventDefault(),x(p=>p<a.length-1?p+1:p);return}if(c.key==="ArrowUp"){c.preventDefault(),x(p=>p>0?p-1:-1);return}if(c.key==="Enter"&&u>=0){c.preventDefault(),f(a[u]);return}if(c.key==="Escape"){c.preventDefault(),r.current?.close(),x(-1);return}}if(c.key==="Backspace"&&i===""){let p=e.length-1,g=v.current[p];g&&(g.focus(),c.preventDefault());}},F=c=>{o(p=>{let g=[...p];return g.splice(c,1),g}),requestAnimationFrame(()=>{let p=Math.min(Math.max(0,c-1),e.length-2),g=v.current[p];g?g.focus():O();});};return jsx(Fragment,{children:jsx(po,{ref:r,trigger:jsxs("div",{className:"container-receipts",children:[e?.length?jsx("div",{className:"emails-container",children:e.map((c,p)=>jsxs("div",{className:"emails",tabIndex:0,ref:g=>{v.current[p]=g;},onKeyDown:g=>{g.key==="Backspace"&&(g.preventDefault(),F(p)),g.key==="Enter"&&(g.preventDefault(),F(p),O());},role:"button","aria-label":`Email ${c.email}`,children:[jsx("span",{style:{marginRight:8},children:c.email}),jsx("button",{className:"emails-close",onClick:g=>{g.stopPropagation(),F(p);},"aria-label":`Remove ${c.email}`,children:jsx(k,{name:"Close"})})]},c.email??p))}):null,jsx("input",{ref:t,type:"text",className:"input-header",value:i,autoFocus:true,onKeyDown:b,onChange:c=>{let p=c.target.value;X(p)&&r.current?.open(),l(p);}})]}),closeOnDocumentClick:true,repositionOnResize:true,position:"bottom left",className:"filter-popup",onOpen:()=>{h(true),requestAnimationFrame(()=>t.current?.focus());},onClose:()=>{h(false);},children:X(i)?jsx("div",{className:"options-dropdown",children:E?jsx(Fragment,{children:[1,2,3].map(c=>jsxs("div",{className:"option-dropdown skeleton-loader",children:[jsx("div",{className:"skeleton-line skeleton-name"}),jsx("div",{className:"skeleton-line skeleton-email"})]},c))}):a.length>0?a.map((c,p)=>jsxs("button",{ref:g=>{w.current[p]=g;},className:`option-dropdown ${u===p?"selected":""}`,onBlur:g=>{g.stopPropagation();},onFocus:g=>{g.stopPropagation();},onMouseEnter:()=>x(p),onMouseLeave:()=>x(-1),onClick:g=>{g.stopPropagation(),f(c);},"aria-selected":u===p,children:[jsx("h4",{children:c.name}),c.email]},p)):null}):null})})}var bt=kr;function Cr({name:e,needCCAndBCC:o,setShowCC:n,setShowBCC:r,showBCC:t,showCC:i,emails:l,handleChange:d,fetchOptions:h}){return jsxs("div",{className:"container-receipts",children:[jsx("label",{className:"block text-sm font-medium text-gray-700",children:e}),jsx(bt,{emails:l,setEmails:d,fetchOptions:h}),o&&!i?jsx("button",{className:"btn",onClick:()=>n?.(u=>!u),children:"CC"}):null,o&&!t?jsx("button",{className:"btn",onClick:()=>r?.(u=>!u),children:"BCC"}):null]})}var de=Cr;function Fr({fetchEmailOptions:e}){let[o,n]=useState(false),r=useRef(null),{emails:t,setEmails:i,showCC:l,setShowCC:d,showBCC:h,setShowBCC:u}=B();return useEffect(()=>{o&&(d(t.cc.length>0),u(t.bcc.length>0));},[o,t.cc.length,t.bcc.length]),useEffect(()=>{let a=r.current;if(!a)return;let m=()=>{n(true);},E=N=>{console.log("\u{1F680} ~ handleFocusOut ~ e:",N);let v=N.relatedTarget;v&&v.classList&&v.classList.contains("option-dropdown")||v&&a.contains(v)||(console.log("why this ",v?.classList),n(false));};return a.addEventListener("focusin",m),a.addEventListener("focusout",E),()=>{a.removeEventListener("focusin",m),a.removeEventListener("focusout",E);}},[]),jsx("div",{ref:r,tabIndex:-1,className:"relative",children:o?jsxs("div",{children:[jsx(de,{name:"To",needCCAndBCC:true,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.to,handleChange:a=>{i(m=>({...m,to:typeof a=="function"?a(m.to):a}));},fetchOptions:e}),l?jsx(de,{name:"CC",needCCAndBCC:false,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.cc,handleChange:a=>{i(m=>({...m,cc:typeof a=="function"?a(m.cc):a}));},fetchOptions:e}):null,h?jsx(de,{name:"BCC",needCCAndBCC:false,setShowCC:d,setShowBCC:u,showBCC:h,showCC:l,emails:t.bcc,handleChange:a=>{i(m=>({...m,bcc:typeof a=="function"?a(m.bcc):a}));},fetchOptions:e}):null]}):jsx("input",{type:"text",placeholder:"Recipients",className:"input-header",value:(()=>{if(t.to.length===0&&t.cc.length===0&&t.bcc.length===0)return "Recipients";let a=[];return t.to.length>0&&a.push(t.to.map(m=>m.email).join(", ")),t.cc.length>0&&a.push(t.cc.map(m=>m.email).join(", ")),t.bcc.length>0&&a.push("bcc: "+t.bcc.map(m=>m.email).join(", ")),a.join(", ")})(),readOnly:true})})}var xt=Fr;function Sr({fetchEmailOptions:e}){let{subject:o,setSubject:n,isReply:r}=B();return jsxs("div",{className:"gmail-header",children:[jsx(xt,{fetchEmailOptions:e}),jsx("input",{type:"text",placeholder:"Subject",className:"input-header",value:r&&!o.startsWith("Re: ")?`Re: ${o}`:o,onChange:t=>n(t.target.value)})]})}var yt=Sr;function Pr({initialData:e,isReply:o,fetchEmailOptions:n,handleChange:r,leftChildren:t,rightChildren:i,editorChildren:l,isEditorVisible:d=true}){let{emails:h,subject:u,attachments:x,setEmails:a,setSubject:m,setAttachments:E,setIsReply:N}=B(),{theme:v}=te(),[w,O]=useState(e?.body||""),[f,b]=useState({to:e?.to||[],cc:e?.cc||[],bcc:e?.bcc||[],subject:e?.subject||"",body:e?.body||"",attachments:e?.attachments||[],isReply:o||false});useEffect(()=>{e&&((e.to||e.cc||e.bcc)&&a({to:e.to||[],cc:e.cc||[],bcc:e.bcc||[]}),e.subject&&m(e.subject),e.attachments&&E(e.attachments),e.body&&O(e.body)),o!==void 0&&N(o);},[]);let F=c=>{O(c);};return useEffect(()=>{b(c=>({...c,to:h.to,cc:h.cc,bcc:h.bcc}));},[h]),useEffect(()=>{b(c=>({...c,subject:u}));},[u]),useEffect(()=>{b(c=>({...c,body:w}));},[w]),useEffect(()=>{b(c=>({...c,attachments:x}));},[x]),useEffect(()=>{b(c=>({...c,isReply:o}));},[o]),useEffect(()=>{r(f);},[f,r]),jsxs("div",{className:"react-mail-inbox-root gmail-wrapper","data-theme":v,children:[t,jsx(yt,{fetchEmailOptions:n}),jsx(ut,{initialHTML:e?.body,onChange:F,editorChildren:l,isEditorVisible:d}),i]})}var wt=Pr;function Tr({fetchEmailOptions:e,handleChange:o,initialData:n,leftChildren:r,rightChildren:t,isReply:i}){return jsx(ze,{children:jsx(wt,{fetchEmailOptions:e,handleChange:o,initialData:n,isReply:i,leftChildren:r,rightChildren:t})})}var Nt=Tr;function Mr({fetchEmailOptions:e,handleChange:o,initialData:n,initialTheme:r="dark",onThemeChange:t,leftChildren:i,rightChildren:l}){return jsx(Ie,{initialTheme:r,onThemeChange:t,children:jsx(Nt,{fetchEmailOptions:e,handleChange:o,initialData:n,leftChildren:i,rightChildren:l})})}var Rt=Mr;var Ba=Rt;
2
+ export{Rt as GmailInbox,Ba as default,te as useTheme};//# sourceMappingURL=index.mjs.map
2258
3
  //# sourceMappingURL=index.mjs.map