@maily-to/core 0.0.22 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4178 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/editor/extensions/maily-kit.tsx
34
+ import { Extension } from "@tiptap/core";
35
+ import StarterKit from "@tiptap/starter-kit";
36
+ import ListItem from "@tiptap/extension-list-item";
37
+ import Paragraph from "@tiptap/extension-paragraph";
38
+ import Placeholder from "@tiptap/extension-placeholder";
39
+ import TextAlign from "@tiptap/extension-text-align";
40
+ import TextStyle from "@tiptap/extension-text-style";
41
+ import Heading from "@tiptap/extension-heading";
42
+ import Underline from "@tiptap/extension-underline";
43
+ import Document from "@tiptap/extension-document";
44
+ import Focus from "@tiptap/extension-focus";
45
+ import Dropcursor from "@tiptap/extension-dropcursor";
46
+
47
+ // src/editor/extensions/color.ts
48
+ import TiptapColor from "@tiptap/extension-color";
49
+ var Color = TiptapColor.extend({
50
+ addStorage() {
51
+ return {
52
+ colors: /* @__PURE__ */ new Set()
53
+ };
54
+ }
55
+ });
56
+
57
+ // src/editor/extensions/horizontal-rule.tsx
58
+ import { InputRule } from "@tiptap/core";
59
+ import { HorizontalRule as TipTapHorizontalRule } from "@tiptap/extension-horizontal-rule";
60
+ var HorizontalRule = TipTapHorizontalRule.extend({
61
+ addInputRules() {
62
+ return [
63
+ new InputRule({
64
+ find: /^(?:---|—-|___\s|\*\*\*\s)$/,
65
+ handler: ({ state, range }) => {
66
+ const attributes = {};
67
+ const { tr } = state;
68
+ const start = range.from;
69
+ const end = range.to;
70
+ tr.insert(start - 1, this.type.create(attributes)).delete(
71
+ tr.mapping.map(start),
72
+ tr.mapping.map(end)
73
+ );
74
+ }
75
+ })
76
+ ];
77
+ },
78
+ addOptions() {
79
+ return {
80
+ HTMLAttributes: {
81
+ class: "mly-relative"
82
+ }
83
+ };
84
+ }
85
+ });
86
+
87
+ // src/editor/nodes/footer.ts
88
+ import { mergeAttributes, Node } from "@tiptap/core";
89
+ var Footer = Node.create({
90
+ name: "footer",
91
+ group: "block",
92
+ content: "inline*",
93
+ addAttributes() {
94
+ return {
95
+ "maily-component": {
96
+ default: "footer",
97
+ renderHTML: (attributes) => {
98
+ return {
99
+ "data-maily-component": attributes["maily-component"]
100
+ };
101
+ },
102
+ parseHTML: (element) => element == null ? void 0 : element.getAttribute("data-maily-component")
103
+ }
104
+ };
105
+ },
106
+ addCommands() {
107
+ return {
108
+ setFooter: () => ({ commands }) => {
109
+ return commands.setNode(this.name);
110
+ }
111
+ };
112
+ },
113
+ parseHTML() {
114
+ return [{ tag: 'small[data-maily-component="footer"]' }];
115
+ },
116
+ renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
117
+ return [
118
+ "small",
119
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes2, {
120
+ class: "footer mly-block mly-text-[13px] mly-text-slate-500 mly-relative"
121
+ }),
122
+ 0
123
+ ];
124
+ }
125
+ });
126
+
127
+ // src/editor/nodes/spacer.ts
128
+ import { mergeAttributes as mergeAttributes3, Node as Node3 } from "@tiptap/core";
129
+
130
+ // src/editor/utils/update-attribute.ts
131
+ function updateAttributes(type, attrs) {
132
+ return ({ commands }) => commands.command(({ tr, state, dispatch }) => {
133
+ if (dispatch) {
134
+ let lastPos = null;
135
+ tr.selection.ranges.forEach((range) => {
136
+ state.doc.nodesBetween(
137
+ range.$from.pos,
138
+ range.$to.pos,
139
+ (node, pos) => {
140
+ if (node.type.name === type) {
141
+ lastPos = pos;
142
+ }
143
+ }
144
+ );
145
+ });
146
+ if (lastPos !== null) {
147
+ const node = state.doc.nodeAt(lastPos);
148
+ if (node) {
149
+ tr.setNodeMarkup(lastPos, null, __spreadValues(__spreadValues({}, node.attrs), attrs));
150
+ } else {
151
+ for (const [key, value] of Object.entries(attrs)) {
152
+ tr.setNodeAttribute(lastPos, key, value);
153
+ }
154
+ }
155
+ }
156
+ if (type === "button") {
157
+ tr.setSelection(tr.selection);
158
+ }
159
+ }
160
+ return true;
161
+ });
162
+ }
163
+
164
+ // src/editor/nodes/section/section.ts
165
+ import { mergeAttributes as mergeAttributes2, Node as Node2 } from "@tiptap/core";
166
+ var DEFAULT_SECTION_BACKGROUND_COLOR = "#f7f7f7";
167
+ var DEFAULT_SECTION_ALIGN = "left";
168
+ var DEFAULT_SECTION_BORDER_WIDTH = 2;
169
+ var DEFAULT_SECTION_BORDER_COLOR = "#e2e2e2";
170
+ var DEFAULT_SECTION_BORDER_RADIUS = 0;
171
+ var DEFAULT_SECTION_MARGIN_TOP = 0;
172
+ var DEFAULT_SECTION_MARGIN_RIGHT = 0;
173
+ var DEFAULT_SECTION_MARGIN_BOTTOM = 0;
174
+ var DEFAULT_SECTION_MARGIN_LEFT = 0;
175
+ var DEFAULT_SECTION_PADDING_TOP = 5;
176
+ var DEFAULT_SECTION_PADDING_RIGHT = 5;
177
+ var DEFAULT_SECTION_PADDING_BOTTOM = 5;
178
+ var DEFAULT_SECTION_PADDING_LEFT = 5;
179
+ var DEFAULT_SECTION_SHOW_IF_KEY = null;
180
+ var SectionExtension = Node2.create({
181
+ name: "section",
182
+ group: "block",
183
+ content: "(block|columns)+",
184
+ defining: true,
185
+ isolating: true,
186
+ addAttributes() {
187
+ return {
188
+ borderRadius: {
189
+ default: 0,
190
+ parseHTML: (element) => {
191
+ var _a, _b;
192
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.borderRadius) == null ? void 0 : _b.replace(/['"]+/g, ""));
193
+ },
194
+ renderHTML: (attributes) => {
195
+ if (!attributes.borderRadius) {
196
+ return {};
197
+ }
198
+ return {
199
+ style: `border-radius: ${attributes.borderRadius}px`
200
+ };
201
+ }
202
+ },
203
+ backgroundColor: {
204
+ default: DEFAULT_SECTION_BACKGROUND_COLOR,
205
+ parseHTML: (element) => {
206
+ return element.style.backgroundColor;
207
+ },
208
+ renderHTML: (attributes) => {
209
+ if (!attributes.backgroundColor) {
210
+ return {};
211
+ }
212
+ return {
213
+ style: `background-color: ${attributes.backgroundColor};--bg-color: ${attributes.backgroundColor}`
214
+ };
215
+ }
216
+ },
217
+ align: {
218
+ default: DEFAULT_SECTION_ALIGN,
219
+ parseHTML: (element) => {
220
+ return element.getAttribute("align") || DEFAULT_SECTION_ALIGN;
221
+ },
222
+ renderHTML(attributes) {
223
+ if (!attributes.align) {
224
+ return {};
225
+ }
226
+ return {
227
+ align: attributes.align
228
+ };
229
+ }
230
+ },
231
+ borderWidth: {
232
+ default: DEFAULT_SECTION_BORDER_WIDTH,
233
+ parseHTML: (element) => {
234
+ var _a, _b;
235
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.borderWidth) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
236
+ },
237
+ renderHTML: (attributes) => {
238
+ if (!attributes.borderWidth) {
239
+ return {};
240
+ }
241
+ return {
242
+ style: `border-width: ${attributes.borderWidth}px`
243
+ };
244
+ }
245
+ },
246
+ borderColor: {
247
+ default: DEFAULT_SECTION_BORDER_COLOR,
248
+ parseHTML: (element) => {
249
+ return element.style.borderColor;
250
+ },
251
+ renderHTML: (attributes) => {
252
+ if (!attributes.borderColor) {
253
+ return {};
254
+ }
255
+ return {
256
+ style: `border-color: ${attributes.borderColor}`
257
+ };
258
+ }
259
+ },
260
+ paddingTop: {
261
+ default: DEFAULT_SECTION_PADDING_TOP,
262
+ parseHTML: (element) => {
263
+ var _a, _b;
264
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.paddingTop) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
265
+ },
266
+ renderHTML: (attributes) => {
267
+ if (!attributes.paddingTop) {
268
+ return {};
269
+ }
270
+ return {
271
+ style: `padding-top: ${attributes.paddingTop}px`
272
+ };
273
+ }
274
+ },
275
+ paddingRight: {
276
+ default: DEFAULT_SECTION_PADDING_RIGHT,
277
+ parseHTML: (element) => {
278
+ var _a, _b;
279
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.paddingRight) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
280
+ },
281
+ renderHTML: (attributes) => {
282
+ if (!attributes.paddingRight) {
283
+ return {};
284
+ }
285
+ return {
286
+ style: `padding-right: ${attributes.paddingRight}px`
287
+ };
288
+ }
289
+ },
290
+ paddingBottom: {
291
+ default: DEFAULT_SECTION_PADDING_BOTTOM,
292
+ parseHTML: (element) => {
293
+ var _a, _b;
294
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.paddingBottom) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
295
+ },
296
+ renderHTML: (attributes) => {
297
+ if (!attributes.paddingBottom) {
298
+ return {};
299
+ }
300
+ return {
301
+ style: `padding-bottom: ${attributes.paddingBottom}px`
302
+ };
303
+ }
304
+ },
305
+ paddingLeft: {
306
+ default: DEFAULT_SECTION_PADDING_LEFT,
307
+ parseHTML: (element) => {
308
+ var _a, _b;
309
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.paddingLeft) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
310
+ },
311
+ renderHTML: (attributes) => {
312
+ if (!attributes.paddingLeft) {
313
+ return {};
314
+ }
315
+ return {
316
+ style: `padding-left: ${attributes.paddingLeft}px`
317
+ };
318
+ }
319
+ },
320
+ marginTop: {
321
+ default: DEFAULT_SECTION_MARGIN_TOP,
322
+ parseHTML: (element) => {
323
+ var _a, _b;
324
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.marginTop) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
325
+ },
326
+ renderHTML: (attributes) => {
327
+ if (!attributes.marginTop) {
328
+ return {};
329
+ }
330
+ return {
331
+ marginTop: attributes.marginTop
332
+ };
333
+ }
334
+ },
335
+ marginRight: {
336
+ default: DEFAULT_SECTION_MARGIN_RIGHT,
337
+ parseHTML: (element) => {
338
+ var _a, _b;
339
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.marginRight) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
340
+ },
341
+ renderHTML: (attributes) => {
342
+ if (!attributes.marginRight) {
343
+ return {};
344
+ }
345
+ return {
346
+ marginRight: attributes.marginRight
347
+ };
348
+ }
349
+ },
350
+ marginBottom: {
351
+ default: DEFAULT_SECTION_MARGIN_BOTTOM,
352
+ parseHTML: (element) => {
353
+ var _a, _b;
354
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.marginBottom) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
355
+ },
356
+ renderHTML: (attributes) => {
357
+ if (!attributes.marginBottom) {
358
+ return {};
359
+ }
360
+ return {
361
+ marginBottom: attributes.marginBottom
362
+ };
363
+ }
364
+ },
365
+ marginLeft: {
366
+ default: DEFAULT_SECTION_MARGIN_LEFT,
367
+ parseHTML: (element) => {
368
+ var _a, _b;
369
+ return Number((_b = (_a = element == null ? void 0 : element.style) == null ? void 0 : _a.marginLeft) == null ? void 0 : _b.replace(/['"]+/g, "")) || 0;
370
+ },
371
+ renderHTML: (attributes) => {
372
+ if (!attributes.marginLeft) {
373
+ return {};
374
+ }
375
+ return {
376
+ marginLeft: attributes.marginLeft
377
+ };
378
+ }
379
+ },
380
+ showIfKey: {
381
+ default: DEFAULT_SECTION_SHOW_IF_KEY,
382
+ parseHTML: (element) => {
383
+ return element.getAttribute("data-show-if-key") || DEFAULT_SECTION_SHOW_IF_KEY;
384
+ },
385
+ renderHTML(attributes) {
386
+ if (!attributes.showIfKey) {
387
+ return {};
388
+ }
389
+ return {
390
+ "data-show-if-key": attributes.showIfKey
391
+ };
392
+ }
393
+ }
394
+ };
395
+ },
396
+ addCommands() {
397
+ return {
398
+ setSection: () => ({ commands }) => {
399
+ return commands.insertContent({
400
+ type: this.name,
401
+ attrs: {
402
+ type: this.name
403
+ },
404
+ content: [
405
+ {
406
+ type: "paragraph"
407
+ }
408
+ ]
409
+ });
410
+ },
411
+ updateSection: (attrs) => updateAttributes(this.name, attrs)
412
+ };
413
+ },
414
+ renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
415
+ const {
416
+ marginTop = 0,
417
+ marginRight = 0,
418
+ marginBottom = 0,
419
+ marginLeft = 0
420
+ } = HTMLAttributes2;
421
+ return [
422
+ "table",
423
+ {
424
+ "data-type": this.name,
425
+ border: 0,
426
+ cellpadding: 0,
427
+ cellspacing: 0,
428
+ class: "mly-w-full mly-border-separate mly-relative mly-table-fixed",
429
+ style: `margin-top: ${marginTop}px; margin-right: ${marginRight}px; margin-bottom: ${marginBottom}px; margin-left: ${marginLeft}px;`
430
+ },
431
+ [
432
+ "tbody",
433
+ {
434
+ class: "mly-w-full"
435
+ },
436
+ [
437
+ "tr",
438
+ {
439
+ class: "mly-w-full"
440
+ },
441
+ [
442
+ "td",
443
+ mergeAttributes2(HTMLAttributes2, {
444
+ "data-type": "section-cell",
445
+ style: "border-style: solid",
446
+ class: "mly-w-full [text-align:revert-layer]"
447
+ }),
448
+ 0
449
+ ]
450
+ ]
451
+ ]
452
+ ];
453
+ },
454
+ parseHTML() {
455
+ return [
456
+ {
457
+ tag: 'table[data-type="section"]'
458
+ }
459
+ ];
460
+ }
461
+ });
462
+
463
+ // src/editor/nodes/spacer.ts
464
+ var allowedSpacerSize = ["sm", "md", "lg", "xl"];
465
+ var DEFAULT_HEIGHT = "sm";
466
+ function getHeightStyle(height) {
467
+ const heights = { sm: "8px", md: "16px", lg: "32px", xl: "64px" };
468
+ return `width: 100%; height: ${heights[height] || heights[DEFAULT_HEIGHT]}`;
469
+ }
470
+ var Spacer = Node3.create({
471
+ name: "spacer",
472
+ priority: 1e3,
473
+ group: "block",
474
+ draggable: true,
475
+ addAttributes() {
476
+ return {
477
+ height: {
478
+ default: null,
479
+ parseHTML: (element) => element.getAttribute("data-height"),
480
+ renderHTML: (attributes) => {
481
+ return {
482
+ "data-height": attributes.height
483
+ };
484
+ }
485
+ },
486
+ showIfKey: {
487
+ default: DEFAULT_SECTION_SHOW_IF_KEY,
488
+ parseHTML: (element) => {
489
+ return element.getAttribute("data-show-if-key") || DEFAULT_SECTION_SHOW_IF_KEY;
490
+ },
491
+ renderHTML(attributes) {
492
+ if (!attributes.showIfKey) {
493
+ return {};
494
+ }
495
+ return {
496
+ "data-show-if-key": attributes.showIfKey
497
+ };
498
+ }
499
+ }
500
+ };
501
+ },
502
+ addCommands() {
503
+ return {
504
+ setSpacer: (options) => ({ commands }) => {
505
+ return commands.insertContent({
506
+ type: this.name,
507
+ attrs: {
508
+ height: options.height
509
+ }
510
+ });
511
+ },
512
+ setSpacerSize: (height) => ({ commands }) => {
513
+ if (!allowedSpacerSize.includes(height)) {
514
+ throw new Error("Invalid spacer height");
515
+ }
516
+ return commands.updateAttributes("spacer", { height });
517
+ },
518
+ setSpacerShowIfKey: (showIfKey) => ({ commands }) => {
519
+ return commands.updateAttributes("spacer", { showIfKey });
520
+ },
521
+ unsetSpacer: () => ({ commands }) => {
522
+ return commands.deleteNode("spacer");
523
+ }
524
+ };
525
+ },
526
+ renderHTML({ HTMLAttributes: HTMLAttributes2, node }) {
527
+ const { height } = node.attrs;
528
+ HTMLAttributes2.style = getHeightStyle(height);
529
+ return [
530
+ "div",
531
+ mergeAttributes3(
532
+ {
533
+ "data-maily-component": this.name
534
+ },
535
+ this.options.HTMLAttributes,
536
+ HTMLAttributes2,
537
+ {
538
+ class: "spacer mly-relative mly-z-50",
539
+ contenteditable: false
540
+ }
541
+ )
542
+ ];
543
+ },
544
+ parseHTML() {
545
+ return [{ tag: `div[data-maily-component="${this.name}"]` }];
546
+ }
547
+ });
548
+
549
+ // src/editor/extensions/link-card.ts
550
+ import { mergeAttributes as mergeAttributes4, Node as Node4 } from "@tiptap/core";
551
+ import { ReactNodeViewRenderer } from "@tiptap/react";
552
+
553
+ // src/editor/nodes/link-card.tsx
554
+ import { NodeViewWrapper } from "@tiptap/react";
555
+
556
+ // src/editor/components/input.tsx
557
+ import * as React from "react";
558
+
559
+ // src/editor/utils/classname.ts
560
+ import { clsx } from "clsx";
561
+ import { extendTailwindMerge } from "tailwind-merge";
562
+ var twMerge = extendTailwindMerge({
563
+ prefix: "mly-"
564
+ });
565
+ function cn(...inputs) {
566
+ return twMerge(clsx(inputs));
567
+ }
568
+
569
+ // src/editor/utils/constants.ts
570
+ var AUTOCOMPLETE_PASSWORD_MANAGERS_OFF = Object.freeze({
571
+ autoComplete: "off",
572
+ "data-1p-ignore": true,
573
+ "data-form-type": "other"
574
+ });
575
+
576
+ // src/editor/components/input.tsx
577
+ import { jsx } from "react/jsx-runtime";
578
+ var Input = React.forwardRef(
579
+ (_a, ref) => {
580
+ var _b = _a, { className, type } = _b, props = __objRest(_b, ["className", "type"]);
581
+ return /* @__PURE__ */ jsx(
582
+ "input",
583
+ __spreadValues(__spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
584
+ type,
585
+ className: cn(
586
+ "mly-flex mly-h-10 mly-w-full mly-rounded-md mly-border mly-border-gray-200 mly-bg-white mly-px-3 mly-py-2 mly-text-sm mly-ring-offset-white file:mly-border-0 file:mly-bg-transparent file:mly-text-sm file:mly-font-medium placeholder:mly-text-gray-500 focus-visible:mly-outline-none focus-visible:mly-ring-2 focus-visible:mly-ring-gray-400 focus-visible:mly-ring-offset-2 disabled:mly-cursor-not-allowed disabled:mly-opacity-50",
587
+ "mly-editor",
588
+ className
589
+ ),
590
+ ref
591
+ }), props)
592
+ );
593
+ }
594
+ );
595
+ Input.displayName = "Input";
596
+
597
+ // src/editor/components/popover.tsx
598
+ import * as React2 from "react";
599
+ import * as PopoverPrimitive from "@radix-ui/react-popover";
600
+ import { jsx as jsx2 } from "react/jsx-runtime";
601
+ var Popover = PopoverPrimitive.Root;
602
+ var PopoverTrigger = PopoverPrimitive.Trigger;
603
+ var PopoverContent = React2.forwardRef((_a, ref) => {
604
+ var _b = _a, { className, align = "center", sideOffset = 4 } = _b, props = __objRest(_b, ["className", "align", "sideOffset"]);
605
+ return /* @__PURE__ */ jsx2(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx2(
606
+ PopoverPrimitive.Content,
607
+ __spreadValues({
608
+ ref,
609
+ align,
610
+ sideOffset,
611
+ className: cn(
612
+ "mly-z-[9999] mly-w-72 mly-rounded-md mly-border mly-border-gray-200 mly-bg-white mly-p-4 mly-text-gray-950 mly-shadow-md mly-outline-none",
613
+ "mly-editor",
614
+ className
615
+ )
616
+ }, props)
617
+ ) });
618
+ });
619
+ PopoverContent.displayName = PopoverPrimitive.Content.displayName;
620
+
621
+ // src/editor/components/textarea.tsx
622
+ import * as React3 from "react";
623
+ import { jsx as jsx3 } from "react/jsx-runtime";
624
+ var Textarea = React3.forwardRef(
625
+ (_a, ref) => {
626
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
627
+ return /* @__PURE__ */ jsx3(
628
+ "textarea",
629
+ __spreadValues({
630
+ className: cn(
631
+ "mly-flex mly-min-h-24 mly-w-full mly-rounded-md mly-border mly-border-gray-200 mly-bg-white mly-px-3 mly-py-2 mly-text-sm mly-ring-offset-white file:mly-border-0 file:mly-bg-transparent file:mly-text-sm file:mly-font-medium placeholder:mly-text-gray-500 focus-visible:mly-outline-none focus-visible:mly-ring-2 focus-visible:mly-ring-gray-400 focus-visible:mly-ring-offset-2 disabled:mly-cursor-not-allowed disabled:mly-opacity-50",
632
+ "mly-editor",
633
+ className
634
+ ),
635
+ ref
636
+ }, props)
637
+ );
638
+ }
639
+ );
640
+ Textarea.displayName = "Textarea";
641
+
642
+ // src/editor/nodes/link-card.tsx
643
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
644
+ function LinkCardComponent(props) {
645
+ const { title, description, link, linkTitle, image: image2, badgeText, subTitle } = props.node.attrs;
646
+ const { getPos, editor } = props;
647
+ return /* @__PURE__ */ jsx4(
648
+ NodeViewWrapper,
649
+ {
650
+ className: `react-component ${props.selected && "ProseMirror-selectednode"}`,
651
+ draggable: "true",
652
+ "data-drag-handle": "",
653
+ children: /* @__PURE__ */ jsxs(Popover, { open: props.selected, children: [
654
+ /* @__PURE__ */ jsx4(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx4(
655
+ "div",
656
+ {
657
+ tabIndex: -1,
658
+ onClick: (e) => {
659
+ e.preventDefault();
660
+ const pos = getPos();
661
+ editor.commands.setNodeSelection(pos);
662
+ },
663
+ children: /* @__PURE__ */ jsxs("div", { className: "mly-no-prose mly-flex mly-flex-col mly-rounded-lg mly-border mly-border-gray-300", children: [
664
+ image2 && /* @__PURE__ */ jsx4("div", { className: "mly-relative mly-mb-1.5 mly-w-full mly-shrink-0", children: /* @__PURE__ */ jsx4(
665
+ "img",
666
+ {
667
+ src: image2,
668
+ alt: "link-card",
669
+ className: "mly-no-prose !mly-mb-0 mly-h-full mly-w-full mly-rounded-t-lg"
670
+ }
671
+ ) }),
672
+ /* @__PURE__ */ jsx4("div", { className: "mly-flex mly-items-stretch mly-p-3", children: /* @__PURE__ */ jsxs("div", { className: cn("mly-flex mly-flex-col"), children: [
673
+ /* @__PURE__ */ jsxs("div", { className: "!mly-mb-1.5 mly-flex mly-items-center mly-gap-1.5", children: [
674
+ /* @__PURE__ */ jsx4("h2", { className: "!mly-mb-0 !mly-text-lg mly-font-semibold", children: title }),
675
+ badgeText && /* @__PURE__ */ jsx4("span", { className: "!mly-font-base text-xs mly-rounded-md mly-bg-yellow-200 mly-px-2 mly-py-1 mly-font-semibold mly-leading-none", children: badgeText }),
676
+ " ",
677
+ subTitle && !badgeText && /* @__PURE__ */ jsx4("span", { className: "!mly-font-base text-xs mly-font-regular mly-rounded-md mly-leading-none mly-text-gray-400", children: subTitle })
678
+ ] }),
679
+ /* @__PURE__ */ jsxs("p", { className: "!mly-my-0 !mly-text-base mly-text-gray-500", children: [
680
+ description,
681
+ " ",
682
+ linkTitle ? /* @__PURE__ */ jsx4("a", { href: link, className: "mly-font-semibold", children: linkTitle }) : null
683
+ ] })
684
+ ] }) })
685
+ ] })
686
+ }
687
+ ) }),
688
+ /* @__PURE__ */ jsxs(
689
+ PopoverContent,
690
+ {
691
+ align: "end",
692
+ className: "mly-flex mly-w-96 mly-flex-col mly-gap-2",
693
+ sideOffset: 10,
694
+ onOpenAutoFocus: (e) => e.preventDefault(),
695
+ onCloseAutoFocus: (e) => e.preventDefault(),
696
+ children: [
697
+ /* @__PURE__ */ jsxs("label", { className: "mly-w-full mly-space-y-1", children: [
698
+ /* @__PURE__ */ jsx4("span", { className: "mly-text-xs mly-font-normal mly-text-slate-400", children: "Image" }),
699
+ /* @__PURE__ */ jsx4(
700
+ Input,
701
+ {
702
+ placeholder: "Add Image",
703
+ type: "url",
704
+ value: image2,
705
+ onChange: (e) => {
706
+ props.updateAttributes({
707
+ image: e.target.value
708
+ });
709
+ }
710
+ }
711
+ )
712
+ ] }),
713
+ /* @__PURE__ */ jsxs("label", { className: "mly-w-full mly-space-y-1", children: [
714
+ /* @__PURE__ */ jsx4("span", { className: "mly-text-xs mly-font-normal mly-text-slate-400", children: "Title" }),
715
+ /* @__PURE__ */ jsx4(
716
+ Input,
717
+ {
718
+ placeholder: "Add title",
719
+ value: title,
720
+ onChange: (e) => {
721
+ props.updateAttributes({
722
+ title: e.target.value
723
+ });
724
+ }
725
+ }
726
+ )
727
+ ] }),
728
+ /* @__PURE__ */ jsxs("label", { className: "mly-w-full mly-space-y-1", children: [
729
+ /* @__PURE__ */ jsx4("span", { className: "mly-text-xs mly-font-normal mly-text-slate-400", children: "Description" }),
730
+ /* @__PURE__ */ jsx4(
731
+ Textarea,
732
+ {
733
+ placeholder: "Add description here",
734
+ value: description,
735
+ onChange: (e) => {
736
+ props.updateAttributes({
737
+ description: e.target.value
738
+ });
739
+ }
740
+ }
741
+ )
742
+ ] }),
743
+ /* @__PURE__ */ jsxs("div", { className: "mly-grid mly-grid-cols-2 mly-gap-2", children: [
744
+ /* @__PURE__ */ jsxs("label", { className: "mly-w-full mly-space-y-1", children: [
745
+ /* @__PURE__ */ jsx4("span", { className: "mly-text-xs mly-font-normal mly-text-slate-400", children: "Link Title" }),
746
+ /* @__PURE__ */ jsx4(
747
+ Input,
748
+ {
749
+ placeholder: "Add link title here",
750
+ value: linkTitle,
751
+ onChange: (e) => {
752
+ props.updateAttributes({
753
+ linkTitle: e.target.value
754
+ });
755
+ }
756
+ }
757
+ )
758
+ ] }),
759
+ /* @__PURE__ */ jsxs("label", { className: "mly-w-full mly-space-y-1", children: [
760
+ /* @__PURE__ */ jsx4("span", { className: "mly-text-xs mly-font-normal mly-text-slate-400", children: "Link" }),
761
+ /* @__PURE__ */ jsx4(
762
+ Input,
763
+ {
764
+ placeholder: "Add link here",
765
+ value: link,
766
+ onChange: (e) => {
767
+ props.updateAttributes({
768
+ link: e.target.value
769
+ });
770
+ }
771
+ }
772
+ )
773
+ ] })
774
+ ] }),
775
+ /* @__PURE__ */ jsxs("div", { className: "mly-grid mly-grid-cols-2 mly-gap-2", children: [
776
+ /* @__PURE__ */ jsxs("label", { className: "mly-w-full mly-space-y-1", children: [
777
+ /* @__PURE__ */ jsx4("span", { className: "mly-text-xs mly-font-normal mly-text-slate-400", children: "Badge Text" }),
778
+ /* @__PURE__ */ jsx4(
779
+ Input,
780
+ {
781
+ placeholder: "Add badge text here",
782
+ value: badgeText,
783
+ onChange: (e) => {
784
+ props.updateAttributes({
785
+ badgeText: e.target.value
786
+ });
787
+ }
788
+ }
789
+ )
790
+ ] }),
791
+ /* @__PURE__ */ jsxs("label", { className: "mly-w-full mly-space-y-1", children: [
792
+ /* @__PURE__ */ jsx4("span", { className: "mly-text-xs mly-font-normal mly-text-slate-400", children: "Sub Title" }),
793
+ /* @__PURE__ */ jsx4(
794
+ Input,
795
+ {
796
+ placeholder: "Add sub title here",
797
+ value: subTitle,
798
+ onChange: (e) => {
799
+ props.updateAttributes({
800
+ subTitle: e.target.value
801
+ });
802
+ }
803
+ }
804
+ )
805
+ ] })
806
+ ] })
807
+ ]
808
+ }
809
+ )
810
+ ] })
811
+ }
812
+ );
813
+ }
814
+
815
+ // src/editor/extensions/link-card.ts
816
+ var LinkCardExtension = Node4.create({
817
+ name: "linkCard",
818
+ group: "block",
819
+ atom: true,
820
+ draggable: true,
821
+ addAttributes() {
822
+ return {
823
+ mailyComponent: {
824
+ default: "linkCard"
825
+ },
826
+ title: {
827
+ default: ""
828
+ },
829
+ description: {
830
+ default: ""
831
+ },
832
+ link: {
833
+ default: ""
834
+ },
835
+ linkTitle: {
836
+ default: ""
837
+ },
838
+ image: {
839
+ default: ""
840
+ },
841
+ subTitle: {
842
+ default: ""
843
+ },
844
+ badgeText: {
845
+ default: ""
846
+ }
847
+ };
848
+ },
849
+ parseHTML() {
850
+ return [
851
+ {
852
+ tag: `a[data-maily-component="${this.name}"]`
853
+ }
854
+ ];
855
+ },
856
+ renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
857
+ return [
858
+ "div",
859
+ mergeAttributes4(
860
+ {
861
+ "data-maily-component": this.name
862
+ },
863
+ HTMLAttributes2
864
+ )
865
+ ];
866
+ },
867
+ addCommands() {
868
+ return {
869
+ setLinkCard: () => ({ commands }) => {
870
+ return commands.insertContent({
871
+ type: this.name,
872
+ attrs: {
873
+ mailyComponent: this.name
874
+ }
875
+ });
876
+ }
877
+ };
878
+ },
879
+ addNodeView() {
880
+ return ReactNodeViewRenderer(LinkCardComponent, {
881
+ className: "mly-relative"
882
+ });
883
+ }
884
+ });
885
+
886
+ // src/editor/utils/columns.ts
887
+ import { Fragment } from "@tiptap/pm/model";
888
+ import { TextSelection } from "@tiptap/pm/state";
889
+ import { v4 as uuid2 } from "uuid";
890
+ import { findParentNode } from "@tiptap/core";
891
+
892
+ // src/editor/nodes/columns/column.ts
893
+ import { Node as Node5, mergeAttributes as mergeAttributes5 } from "@tiptap/core";
894
+ import { v4 as uuid } from "uuid";
895
+ var DEFAULT_COLUMN_WIDTH = "auto";
896
+ var DEFAULT_COLUMN_VERTICAL_ALIGN = "top";
897
+ var ColumnExtension = Node5.create({
898
+ name: "column",
899
+ content: "block+",
900
+ isolating: true,
901
+ addAttributes() {
902
+ return {
903
+ columnId: {
904
+ default: null,
905
+ parseHTML: (element) => element.getAttribute("data-column-id") || uuid(),
906
+ renderHTML: (attributes) => {
907
+ if (!attributes.columnId) {
908
+ return {
909
+ "data-column-id": uuid()
910
+ };
911
+ }
912
+ return {
913
+ "data-column-id": attributes.columnId
914
+ };
915
+ }
916
+ },
917
+ width: {
918
+ default: DEFAULT_COLUMN_WIDTH,
919
+ parseHTML: (element) => element.style.width.replace(/['"]+/g, "") || DEFAULT_COLUMN_WIDTH,
920
+ renderHTML: (attributes) => {
921
+ if (!attributes.width || attributes.width === DEFAULT_COLUMN_WIDTH) {
922
+ return {};
923
+ }
924
+ return {
925
+ style: `width: ${attributes.width}%;max-width:${attributes.width}%`
926
+ };
927
+ }
928
+ },
929
+ verticalAlign: {
930
+ default: DEFAULT_COLUMN_VERTICAL_ALIGN,
931
+ parseHTML: (element) => {
932
+ var _a;
933
+ return ((_a = element == null ? void 0 : element.style) == null ? void 0 : _a.verticalAlign) || "top";
934
+ },
935
+ renderHTML: (attributes) => {
936
+ const { verticalAlign } = attributes;
937
+ if (!verticalAlign || verticalAlign === DEFAULT_COLUMN_VERTICAL_ALIGN) {
938
+ return {};
939
+ }
940
+ if (verticalAlign === "middle") {
941
+ return {
942
+ style: `display: flex;flex-direction: column;justify-content: center;`
943
+ };
944
+ } else if (verticalAlign === "bottom") {
945
+ return {
946
+ style: `display: flex;flex-direction: column;justify-content: flex-end;`
947
+ };
948
+ }
949
+ }
950
+ }
951
+ };
952
+ },
953
+ addCommands() {
954
+ return {
955
+ updateColumn: (attrs) => updateAttributes(this.name, attrs)
956
+ };
957
+ },
958
+ renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
959
+ return [
960
+ "div",
961
+ mergeAttributes5(HTMLAttributes2, {
962
+ "data-type": "column",
963
+ class: "hide-scrollbars"
964
+ }),
965
+ 0
966
+ ];
967
+ },
968
+ parseHTML() {
969
+ return [
970
+ {
971
+ tag: 'div[data-type="column"]'
972
+ }
973
+ ];
974
+ }
975
+ });
976
+
977
+ // src/editor/utils/columns.ts
978
+ function getClosestNodeByName(editor, name) {
979
+ const { state } = editor.view;
980
+ return findParentNode((node) => node.type.name === name)(state.selection);
981
+ }
982
+ function goToColumn(editor, type) {
983
+ const columnsNode = getClosestNodeByName(editor, "columns");
984
+ const columnNode = getClosestNodeByName(editor, "column");
985
+ if (!columnsNode || !columnNode) {
986
+ return false;
987
+ }
988
+ const { state, dispatch } = editor.view;
989
+ const cols = columnsNode.node;
990
+ let currColumnIndex = 0;
991
+ cols.content.forEach((child, _, index) => {
992
+ var _a, _b, _c;
993
+ if (child.eq(columnNode.node) && ((_a = child == null ? void 0 : child.attrs) == null ? void 0 : _a.columnId) === ((_c = (_b = columnNode.node) == null ? void 0 : _b.attrs) == null ? void 0 : _c.columnId)) {
994
+ currColumnIndex = index;
995
+ }
996
+ });
997
+ const nextColumnIndex = type === "next" ? currColumnIndex + 1 : currColumnIndex - 1;
998
+ if (nextColumnIndex < 0 || nextColumnIndex >= cols.childCount) {
999
+ return false;
1000
+ }
1001
+ let nextColumnPos = columnsNode.pos;
1002
+ cols.content.forEach((child, _, index) => {
1003
+ if (index < nextColumnIndex) {
1004
+ nextColumnPos += child.nodeSize;
1005
+ }
1006
+ });
1007
+ const tr = state.tr.setTime(Date.now());
1008
+ const textSelection = TextSelection.near(tr.doc.resolve(nextColumnPos));
1009
+ tr.setSelection(textSelection);
1010
+ dispatch(tr);
1011
+ return true;
1012
+ }
1013
+
1014
+ // src/editor/nodes/columns/columns.ts
1015
+ import { mergeAttributes as mergeAttributes6 } from "@tiptap/core";
1016
+ import { Node as Node7 } from "@tiptap/core";
1017
+ import { v4 as uuid3 } from "uuid";
1018
+ var DEFAULT_COLUMNS_GAP = 8;
1019
+ var ColumnsExtension = Node7.create({
1020
+ name: "columns",
1021
+ group: "columns",
1022
+ content: "column+",
1023
+ defining: true,
1024
+ isolating: true,
1025
+ addAttributes() {
1026
+ return {
1027
+ showIfKey: {
1028
+ default: DEFAULT_SECTION_SHOW_IF_KEY,
1029
+ parseHTML: (element) => {
1030
+ return element.getAttribute("data-show-if-key") || DEFAULT_SECTION_SHOW_IF_KEY;
1031
+ },
1032
+ renderHTML(attributes) {
1033
+ if (!attributes.showIfKey) {
1034
+ return {};
1035
+ }
1036
+ return {
1037
+ "data-show-if-key": attributes.showIfKey
1038
+ };
1039
+ }
1040
+ },
1041
+ gap: {
1042
+ default: DEFAULT_COLUMNS_GAP,
1043
+ parseHTML: (element) => {
1044
+ return Number(element.style.gap) || DEFAULT_COLUMNS_GAP;
1045
+ },
1046
+ renderHTML(attributes) {
1047
+ if (!attributes.gap) {
1048
+ return {};
1049
+ }
1050
+ return {
1051
+ style: `gap: ${attributes.gap}px`
1052
+ };
1053
+ }
1054
+ }
1055
+ };
1056
+ },
1057
+ addCommands() {
1058
+ return {
1059
+ setColumns: () => ({ commands }) => {
1060
+ return commands.insertContent({
1061
+ type: this.name,
1062
+ attrs: {},
1063
+ content: [
1064
+ {
1065
+ type: "column",
1066
+ attrs: {
1067
+ columnId: uuid3()
1068
+ },
1069
+ content: [
1070
+ {
1071
+ type: "paragraph"
1072
+ }
1073
+ ]
1074
+ },
1075
+ {
1076
+ type: "column",
1077
+ attrs: {
1078
+ columnId: uuid3()
1079
+ },
1080
+ content: [
1081
+ {
1082
+ type: "paragraph"
1083
+ }
1084
+ ]
1085
+ }
1086
+ ]
1087
+ });
1088
+ },
1089
+ updateColumns: (attrs) => updateAttributes(this.name, attrs)
1090
+ };
1091
+ },
1092
+ renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
1093
+ return [
1094
+ "div",
1095
+ mergeAttributes6(HTMLAttributes2, {
1096
+ "data-type": "columns",
1097
+ class: "mly-relative"
1098
+ }),
1099
+ 0
1100
+ ];
1101
+ },
1102
+ parseHTML() {
1103
+ return [
1104
+ {
1105
+ tag: 'div[data-type="columns"]'
1106
+ }
1107
+ ];
1108
+ },
1109
+ addKeyboardShortcuts() {
1110
+ return {
1111
+ Tab: () => {
1112
+ return goToColumn(this.editor, "next");
1113
+ },
1114
+ "Shift-Tab": () => {
1115
+ return goToColumn(this.editor, "previous");
1116
+ }
1117
+ };
1118
+ }
1119
+ });
1120
+
1121
+ // src/editor/nodes/for/for.ts
1122
+ import { mergeAttributes as mergeAttributes7, Node as Node8 } from "@tiptap/core";
1123
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer2 } from "@tiptap/react";
1124
+
1125
+ // src/editor/nodes/for/for-view.tsx
1126
+ import { NodeViewWrapper as NodeViewWrapper2, NodeViewContent } from "@tiptap/react";
1127
+ import { Repeat2 } from "lucide-react";
1128
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1129
+ function ForView(props) {
1130
+ const { editor, getPos } = props;
1131
+ return /* @__PURE__ */ jsxs2(
1132
+ NodeViewWrapper2,
1133
+ {
1134
+ draggable: "true",
1135
+ "data-drag-handle": "",
1136
+ "data-type": "for",
1137
+ className: "mly-relative",
1138
+ children: [
1139
+ /* @__PURE__ */ jsx5(NodeViewContent, { className: "is-editable" }),
1140
+ /* @__PURE__ */ jsxs2(
1141
+ "div",
1142
+ {
1143
+ role: "button",
1144
+ "data-repeat-indicator": "",
1145
+ className: "mly-absolute mly-inset-y-0 mly-right-0 mly-flex mly-translate-x-full mly-cursor-pointer mly-flex-col mly-items-center mly-gap-1 mly-opacity-60",
1146
+ contentEditable: false,
1147
+ onClick: () => {
1148
+ editor.commands.setNodeSelection(getPos());
1149
+ },
1150
+ children: [
1151
+ /* @__PURE__ */ jsx5(Repeat2, { className: "mly-size-3 mly-stroke-[2.5] mly-text-midnight-gray" }),
1152
+ /* @__PURE__ */ jsx5("div", { className: "mly-w-[1.5px] mly-grow mly-rounded-full mly-bg-rose-300" })
1153
+ ]
1154
+ }
1155
+ )
1156
+ ]
1157
+ }
1158
+ );
1159
+ }
1160
+
1161
+ // src/editor/nodes/for/for.ts
1162
+ var ForExtension = Node8.create({
1163
+ name: "for",
1164
+ group: "block",
1165
+ content: "(block|columns)+",
1166
+ draggable: true,
1167
+ isolating: true,
1168
+ addAttributes() {
1169
+ return {
1170
+ each: {
1171
+ default: "items",
1172
+ parseHTML: (element) => {
1173
+ return element.getAttribute("each") || "";
1174
+ },
1175
+ renderHTML: (attributes) => {
1176
+ if (!attributes.each) {
1177
+ return {};
1178
+ }
1179
+ return {
1180
+ each: attributes.each
1181
+ };
1182
+ }
1183
+ },
1184
+ isUpdatingKey: {
1185
+ default: false
1186
+ },
1187
+ showIfKey: {
1188
+ default: DEFAULT_SECTION_SHOW_IF_KEY,
1189
+ parseHTML: (element) => {
1190
+ return element.getAttribute("data-show-if-key") || DEFAULT_SECTION_SHOW_IF_KEY;
1191
+ },
1192
+ renderHTML(attributes) {
1193
+ if (!attributes.showIfKey) {
1194
+ return {};
1195
+ }
1196
+ return {
1197
+ "data-show-if-key": attributes.showIfKey
1198
+ };
1199
+ }
1200
+ }
1201
+ };
1202
+ },
1203
+ parseHTML() {
1204
+ return [
1205
+ {
1206
+ tag: `div[data-type="${this.name}"]`
1207
+ }
1208
+ ];
1209
+ },
1210
+ renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
1211
+ return [
1212
+ "div",
1213
+ mergeAttributes7(HTMLAttributes2, {
1214
+ "data-type": this.name
1215
+ }),
1216
+ 0
1217
+ ];
1218
+ },
1219
+ addCommands() {
1220
+ return {
1221
+ setFor: () => ({ commands }) => {
1222
+ return commands.insertContent({
1223
+ type: this.name,
1224
+ attrs: {},
1225
+ content: [
1226
+ {
1227
+ type: "paragraph"
1228
+ }
1229
+ ]
1230
+ });
1231
+ },
1232
+ updateFor: (attrs) => updateAttributes(this.name, attrs)
1233
+ };
1234
+ },
1235
+ addNodeView() {
1236
+ return ReactNodeViewRenderer2(ForView, {
1237
+ contentDOMElementTag: "div",
1238
+ className: "mly-relative"
1239
+ });
1240
+ }
1241
+ });
1242
+
1243
+ // src/editor/nodes/button/button.tsx
1244
+ import { mergeAttributes as mergeAttributes8, Node as Node9 } from "@tiptap/core";
1245
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer3 } from "@tiptap/react";
1246
+
1247
+ // src/editor/components/alignment-switch.tsx
1248
+ import { AlignCenter, AlignLeft, AlignRight } from "lucide-react";
1249
+
1250
+ // src/editor/components/base-button.tsx
1251
+ import * as React4 from "react";
1252
+ import { Slot } from "@radix-ui/react-slot";
1253
+ import { jsx as jsx6 } from "react/jsx-runtime";
1254
+ var BaseButton = React4.forwardRef(
1255
+ (_a, ref) => {
1256
+ var _b = _a, {
1257
+ className,
1258
+ variant = "default",
1259
+ size = "default",
1260
+ asChild = false
1261
+ } = _b, props = __objRest(_b, [
1262
+ "className",
1263
+ "variant",
1264
+ "size",
1265
+ "asChild"
1266
+ ]);
1267
+ const Comp = asChild ? Slot : "button";
1268
+ const baseClass = "mly-inline-flex mly-items-center mly-justify-center mly-rounded-md mly-text-sm mly-font-medium mly-ring-offset-white mly-transition-colors focus-visible:mly-outline-none focus-visible:mly-ring-2 focus-visible:mly-ring-gray-400 focus-visible:mly-ring-offset-2 focus-visible:mly-relative focus-visible:mly-z-10 disabled:mly-opacity-50 ";
1269
+ const variantClasses = {
1270
+ default: "mly-bg-gray-900 mly-text-gray-50 hover:mly-bg-soft-gray",
1271
+ destructive: "mly-bg-red-500 mly-text-gray-50 hover:mly-bg-red-500/90",
1272
+ outline: "mly-border mly-border-gray-200 mly-bg-white hover:mly-bg-gray-100 hover:mly-text-gray-900",
1273
+ secondary: "mly-bg-gray-100 mly-text-gray-900 hover:mly-bg-gray-100/80",
1274
+ ghost: "hover:mly-bg-soft-gray bg-transparent hover:mly-text-gray-900 data-[state=true]:mly-bg-soft-gray data-[state=true]:mly-text-gray-900",
1275
+ link: "mly-text-gray-900 mly-underline-offset-4 hover:mly-underline"
1276
+ };
1277
+ const sizeClasses = {
1278
+ default: "mly-h-10 mly-px-4 mly-py-2",
1279
+ sm: "mly-h-9 mly-rounded-md mly-px-3",
1280
+ lg: "mly-h-11 mly-rounded-md mly-px-8",
1281
+ icon: "mly-h-10 mly-w-10"
1282
+ };
1283
+ const classes = cn(
1284
+ "mly-editor",
1285
+ baseClass,
1286
+ variantClasses[variant],
1287
+ sizeClasses[size],
1288
+ className
1289
+ );
1290
+ return /* @__PURE__ */ jsx6(Comp, __spreadValues({ className: classes, ref }, props));
1291
+ }
1292
+ );
1293
+ BaseButton.displayName = "BaseButton";
1294
+
1295
+ // src/editor/components/ui/tooltip.tsx
1296
+ import * as React5 from "react";
1297
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
1298
+ import { jsx as jsx7 } from "react/jsx-runtime";
1299
+ var TooltipProvider = TooltipPrimitive.Provider;
1300
+ var Tooltip = TooltipPrimitive.Root;
1301
+ var TooltipTrigger = TooltipPrimitive.Trigger;
1302
+ var TooltipContent = React5.forwardRef((_a, ref) => {
1303
+ var _b = _a, { className, sideOffset = 4 } = _b, props = __objRest(_b, ["className", "sideOffset"]);
1304
+ return /* @__PURE__ */ jsx7(
1305
+ TooltipPrimitive.Content,
1306
+ __spreadValues({
1307
+ ref,
1308
+ sideOffset,
1309
+ className: cn(
1310
+ "mly-z-50 mly-overflow-hidden mly-rounded-md mly-border mly-bg-white mly-px-2 mly-py-1 mly-text-xs mly-animate-in mly-fade-in-0 mly-zoom-in-95",
1311
+ className
1312
+ )
1313
+ }, props)
1314
+ );
1315
+ });
1316
+ TooltipContent.displayName = TooltipPrimitive.Content.displayName;
1317
+
1318
+ // src/editor/components/bubble-menu-button.tsx
1319
+ import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
1320
+ function BubbleMenuButton(item) {
1321
+ var _a;
1322
+ const { tooltip } = item;
1323
+ const content = /* @__PURE__ */ jsx8(
1324
+ BaseButton,
1325
+ __spreadProps(__spreadValues({
1326
+ variant: "ghost",
1327
+ size: "sm"
1328
+ }, item.command ? { onClick: item.command } : {}), {
1329
+ "data-state": (_a = item == null ? void 0 : item.isActive) == null ? void 0 : _a.call(item),
1330
+ className: cn(
1331
+ "!mly-size-7 mly-px-2.5 disabled:mly-cursor-not-allowed",
1332
+ item == null ? void 0 : item.className
1333
+ ),
1334
+ type: "button",
1335
+ disabled: item.disbabled,
1336
+ children: item.icon ? /* @__PURE__ */ jsx8(
1337
+ item.icon,
1338
+ {
1339
+ className: cn(
1340
+ "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5]",
1341
+ item == null ? void 0 : item.iconClassName
1342
+ )
1343
+ }
1344
+ ) : /* @__PURE__ */ jsx8(
1345
+ "span",
1346
+ {
1347
+ className: cn(
1348
+ "mly-text-sm mly-font-medium mly-text-slate-600",
1349
+ item == null ? void 0 : item.nameClassName
1350
+ ),
1351
+ children: item.name
1352
+ }
1353
+ )
1354
+ })
1355
+ );
1356
+ if (tooltip) {
1357
+ return /* @__PURE__ */ jsxs3(Tooltip, { children: [
1358
+ /* @__PURE__ */ jsx8(TooltipTrigger, { asChild: true, children: content }),
1359
+ /* @__PURE__ */ jsx8(TooltipContent, { sideOffset: 8, children: tooltip })
1360
+ ] });
1361
+ }
1362
+ return content;
1363
+ }
1364
+
1365
+ // src/editor/components/alignment-switch.tsx
1366
+ import { jsx as jsx9 } from "react/jsx-runtime";
1367
+ function AlignmentSwitch(props) {
1368
+ const { alignment = "left", onAlignmentChange } = props;
1369
+ const activeAlignment = {
1370
+ left: {
1371
+ icon: AlignLeft,
1372
+ tooltip: "Align Left",
1373
+ onClick: () => {
1374
+ onAlignmentChange("center");
1375
+ }
1376
+ },
1377
+ center: {
1378
+ icon: AlignCenter,
1379
+ tooltip: "Align Center",
1380
+ onClick: () => {
1381
+ onAlignmentChange("right");
1382
+ }
1383
+ },
1384
+ right: {
1385
+ icon: AlignRight,
1386
+ tooltip: "Align Right",
1387
+ onClick: () => {
1388
+ onAlignmentChange("left");
1389
+ }
1390
+ }
1391
+ }[alignment];
1392
+ return /* @__PURE__ */ jsx9(
1393
+ BubbleMenuButton,
1394
+ {
1395
+ icon: activeAlignment.icon,
1396
+ tooltip: activeAlignment.tooltip,
1397
+ command: activeAlignment.onClick
1398
+ }
1399
+ );
1400
+ }
1401
+
1402
+ // src/editor/components/ui/color-picker.tsx
1403
+ import { HexColorPicker, HexColorInput } from "react-colorful";
1404
+ import { jsx as jsx10, jsxs as jsxs4 } from "react/jsx-runtime";
1405
+ function ColorPicker(props) {
1406
+ const {
1407
+ color,
1408
+ onColorChange,
1409
+ borderColor,
1410
+ backgroundColor,
1411
+ tooltip,
1412
+ className,
1413
+ children,
1414
+ onClose,
1415
+ suggestedColors = []
1416
+ } = props;
1417
+ const handleColorChange = (color2) => {
1418
+ queueMicrotask(() => {
1419
+ onColorChange(color2);
1420
+ });
1421
+ };
1422
+ const popoverButton = /* @__PURE__ */ jsx10(PopoverTrigger, { asChild: true, children: children || /* @__PURE__ */ jsx10(
1423
+ BaseButton,
1424
+ {
1425
+ variant: "ghost",
1426
+ className: "!mly-size-7 mly-shrink-0",
1427
+ size: "sm",
1428
+ type: "button",
1429
+ children: /* @__PURE__ */ jsx10(
1430
+ "div",
1431
+ {
1432
+ className: cn(
1433
+ "mly-h-4 mly-w-4 mly-shrink-0 mly-rounded mly-border-2 mly-border-gray-700",
1434
+ className
1435
+ ),
1436
+ style: __spreadProps(__spreadValues({}, borderColor ? { borderColor } : {}), {
1437
+ backgroundColor: backgroundColor || "transparent"
1438
+ })
1439
+ }
1440
+ )
1441
+ }
1442
+ ) });
1443
+ return /* @__PURE__ */ jsxs4(
1444
+ Popover,
1445
+ {
1446
+ onOpenChange: (open) => {
1447
+ if (!open) {
1448
+ onClose == null ? void 0 : onClose(color);
1449
+ }
1450
+ },
1451
+ children: [
1452
+ tooltip ? /* @__PURE__ */ jsxs4(Tooltip, { children: [
1453
+ /* @__PURE__ */ jsx10(TooltipTrigger, { asChild: true, children: popoverButton }),
1454
+ /* @__PURE__ */ jsx10(TooltipContent, { sideOffset: 8, children: tooltip })
1455
+ ] }) : popoverButton,
1456
+ /* @__PURE__ */ jsx10(
1457
+ PopoverContent,
1458
+ {
1459
+ className: "mly-w-full mly-rounded-none mly-border-0 !mly-bg-transparent !mly-p-0 mly-shadow-none mly-drop-shadow-md",
1460
+ sideOffset: 8,
1461
+ children: /* @__PURE__ */ jsxs4("div", { className: "mly-min-w-[260px] mly-rounded-xl mly-border mly-bg-white mly-p-4", children: [
1462
+ /* @__PURE__ */ jsx10(
1463
+ HexColorPicker,
1464
+ {
1465
+ color,
1466
+ onChange: handleColorChange,
1467
+ className: "mly-flex !mly-w-full mly-flex-col mly-gap-4"
1468
+ }
1469
+ ),
1470
+ /* @__PURE__ */ jsx10(
1471
+ HexColorInput,
1472
+ {
1473
+ alpha: true,
1474
+ color,
1475
+ onChange: handleColorChange,
1476
+ className: "mly-mt-4 mly-w-full mly-min-w-0 mly-rounded-lg mly-border mly-px-2 mly-py-1.5 mly-text-sm mly-uppercase focus-visible:mly-border-gray-400 focus-visible:mly-outline-none",
1477
+ prefixed: true
1478
+ }
1479
+ ),
1480
+ suggestedColors.length > 0 && /* @__PURE__ */ jsxs4("div", { children: [
1481
+ /* @__PURE__ */ jsx10("div", { className: "-mly-mx-4 mly-my-4 mly-h-px mly-bg-gray-200" }),
1482
+ /* @__PURE__ */ jsx10("h2", { className: "mly-text-xs mly-text-gray-500", children: "Recently used" }),
1483
+ /* @__PURE__ */ jsx10("div", { className: "mly-mt-2 mly-flex mly-flex-wrap mly-gap-0.5", children: suggestedColors.map((suggestedColor) => /* @__PURE__ */ jsx10(
1484
+ BaseButton,
1485
+ {
1486
+ variant: "ghost",
1487
+ size: "sm",
1488
+ className: "!mly-size-7 mly-shrink-0",
1489
+ type: "button",
1490
+ onClick: () => handleColorChange(suggestedColor),
1491
+ children: /* @__PURE__ */ jsx10(
1492
+ "div",
1493
+ {
1494
+ className: "mly-h-4 mly-w-4 mly-shrink-0 mly-rounded",
1495
+ style: {
1496
+ backgroundColor: suggestedColor
1497
+ }
1498
+ }
1499
+ )
1500
+ },
1501
+ suggestedColor
1502
+ )) })
1503
+ ] })
1504
+ ] })
1505
+ }
1506
+ )
1507
+ ]
1508
+ }
1509
+ );
1510
+ }
1511
+
1512
+ // src/editor/components/ui/divider.tsx
1513
+ import { jsx as jsx11 } from "react/jsx-runtime";
1514
+ function Divider(props) {
1515
+ const { type = "vertical", className } = props;
1516
+ return /* @__PURE__ */ jsx11(
1517
+ "div",
1518
+ {
1519
+ className: cn(
1520
+ "mly-shrink-0 mly-bg-gray-200",
1521
+ type === "vertical" ? "mly-mx-0.5 mly-w-px" : "mly-my-0.5 mly-h-px",
1522
+ className
1523
+ )
1524
+ }
1525
+ );
1526
+ }
1527
+
1528
+ // src/editor/components/ui/link-input-popover.tsx
1529
+ import {
1530
+ ChevronDownIcon,
1531
+ Link
1532
+ } from "lucide-react";
1533
+ import { useRef as useRef3, useState as useState3 } from "react";
1534
+
1535
+ // src/editor/provider.tsx
1536
+ import { createContext, useContext } from "react";
1537
+
1538
+ // src/blocks/button.tsx
1539
+ import { MousePointer, ArrowUpRightSquare } from "lucide-react";
1540
+ import { jsx as jsx12 } from "react/jsx-runtime";
1541
+ var button = {
1542
+ title: "Button",
1543
+ description: "Add a call to action button to email.",
1544
+ searchTerms: ["link", "button", "cta"],
1545
+ icon: /* @__PURE__ */ jsx12(MousePointer, { className: "mly-h-4 mly-w-4" }),
1546
+ command: ({ editor, range }) => {
1547
+ editor.chain().focus().deleteRange(range).setButton().run();
1548
+ }
1549
+ };
1550
+ var linkCard = {
1551
+ title: "Link Card",
1552
+ description: "Add a link card to email.",
1553
+ searchTerms: ["link", "button", "image"],
1554
+ icon: /* @__PURE__ */ jsx12(ArrowUpRightSquare, { className: "mly-h-4 mly-w-4" }),
1555
+ command: ({ editor, range }) => {
1556
+ editor.chain().focus().deleteRange(range).setLinkCard().run();
1557
+ },
1558
+ shouldBeHidden: (editor) => {
1559
+ return editor.extensionManager.extensions.findIndex(
1560
+ (ext) => ext.name === "linkCard"
1561
+ ) === -1;
1562
+ }
1563
+ };
1564
+
1565
+ // src/blocks/image.tsx
1566
+ import { ImageIcon } from "lucide-react";
1567
+ import { jsx as jsx13 } from "react/jsx-runtime";
1568
+ var image = {
1569
+ title: "Image",
1570
+ description: "Full width image",
1571
+ searchTerms: ["image"],
1572
+ icon: /* @__PURE__ */ jsx13(ImageIcon, { className: "mly-h-4 mly-w-4" }),
1573
+ command: ({ editor, range }) => {
1574
+ editor.chain().focus().deleteRange(range).setImage({ src: "" }).run();
1575
+ }
1576
+ };
1577
+ var logo = {
1578
+ title: "Logo",
1579
+ description: "Add your brand logo",
1580
+ searchTerms: ["image", "logo"],
1581
+ icon: /* @__PURE__ */ jsx13(ImageIcon, { className: "mly-h-4 mly-w-4" }),
1582
+ command: ({ editor, range }) => {
1583
+ editor.chain().focus().deleteRange(range).setLogoImage({ src: "" }).run();
1584
+ }
1585
+ };
1586
+
1587
+ // src/blocks/layout.tsx
1588
+ import {
1589
+ ColumnsIcon,
1590
+ Repeat2 as Repeat22,
1591
+ MoveVertical,
1592
+ RectangleHorizontal,
1593
+ Minus
1594
+ } from "lucide-react";
1595
+ import { jsx as jsx14 } from "react/jsx-runtime";
1596
+ var columns = {
1597
+ title: "Columns",
1598
+ description: "Add columns to email.",
1599
+ searchTerms: ["layout", "columns"],
1600
+ icon: /* @__PURE__ */ jsx14(ColumnsIcon, { className: "mly-h-4 mly-w-4" }),
1601
+ shouldBeHidden: (editor) => {
1602
+ return editor.isActive("columns");
1603
+ },
1604
+ command: ({ editor, range }) => {
1605
+ editor.chain().focus().deleteRange(range).setColumns().focus(editor.state.selection.head - 2).run();
1606
+ }
1607
+ };
1608
+ var section = {
1609
+ title: "Section",
1610
+ description: "Add a section to email.",
1611
+ searchTerms: ["layout", "section"],
1612
+ icon: /* @__PURE__ */ jsx14(RectangleHorizontal, { className: "mly-h-4 mly-w-4" }),
1613
+ command: ({ editor, range }) => {
1614
+ editor.chain().focus().deleteRange(range).setSection().run();
1615
+ }
1616
+ };
1617
+ var forLoop = {
1618
+ title: "For",
1619
+ description: "Loop over an array of items.",
1620
+ searchTerms: ["for", "loop"],
1621
+ icon: /* @__PURE__ */ jsx14(Repeat22, { className: "mly-h-4 mly-w-4" }),
1622
+ shouldBeHidden: (editor) => {
1623
+ return editor.isActive("for");
1624
+ },
1625
+ command: ({ editor, range }) => {
1626
+ editor.chain().focus().deleteRange(range).setFor().run();
1627
+ }
1628
+ };
1629
+ var spacer = {
1630
+ title: "Spacer",
1631
+ description: "Add space between blocks.",
1632
+ searchTerms: ["space", "gap", "divider"],
1633
+ icon: /* @__PURE__ */ jsx14(MoveVertical, { className: "mly-h-4 mly-w-4" }),
1634
+ command: ({ editor, range }) => {
1635
+ editor.chain().focus().deleteRange(range).setSpacer({ height: "sm" }).run();
1636
+ }
1637
+ };
1638
+ var divider = {
1639
+ title: "Divider",
1640
+ description: "Add a horizontal divider.",
1641
+ searchTerms: ["divider", "line"],
1642
+ icon: /* @__PURE__ */ jsx14(Minus, { className: "mly-h-4 mly-w-4" }),
1643
+ command: ({ editor, range }) => {
1644
+ editor.chain().focus().deleteRange(range).setHorizontalRule().run();
1645
+ }
1646
+ };
1647
+
1648
+ // src/blocks/list.tsx
1649
+ import { List, ListOrdered } from "lucide-react";
1650
+ import { jsx as jsx15 } from "react/jsx-runtime";
1651
+ var bulletList = {
1652
+ title: "Bullet List",
1653
+ description: "Create a simple bullet list.",
1654
+ searchTerms: ["unordered", "point"],
1655
+ icon: /* @__PURE__ */ jsx15(List, { className: "mly-h-4 mly-w-4" }),
1656
+ command: ({ editor, range }) => {
1657
+ editor.chain().focus().deleteRange(range).toggleBulletList().run();
1658
+ }
1659
+ };
1660
+ var orderedList = {
1661
+ title: "Numbered List",
1662
+ description: "Create a list with numbering.",
1663
+ searchTerms: ["ordered"],
1664
+ icon: /* @__PURE__ */ jsx15(ListOrdered, { className: "mly-h-4 mly-w-4" }),
1665
+ command: ({ editor, range }) => {
1666
+ editor.chain().focus().deleteRange(range).toggleOrderedList().run();
1667
+ }
1668
+ };
1669
+
1670
+ // src/blocks/typography.tsx
1671
+ import {
1672
+ Text,
1673
+ Heading1,
1674
+ Heading2,
1675
+ Heading3,
1676
+ DivideIcon,
1677
+ TextQuote,
1678
+ FootprintsIcon,
1679
+ EraserIcon
1680
+ } from "lucide-react";
1681
+ import { jsx as jsx16 } from "react/jsx-runtime";
1682
+ var text = {
1683
+ title: "Text",
1684
+ description: "Just start typing with plain text.",
1685
+ searchTerms: ["p", "paragraph"],
1686
+ icon: /* @__PURE__ */ jsx16(Text, { className: "mly-h-4 mly-w-4" }),
1687
+ command: ({ editor, range }) => {
1688
+ editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").run();
1689
+ }
1690
+ };
1691
+ var heading1 = {
1692
+ title: "Heading 1",
1693
+ description: "Big heading.",
1694
+ searchTerms: ["title", "big", "large"],
1695
+ icon: /* @__PURE__ */ jsx16(Heading1, { className: "mly-h-4 mly-w-4" }),
1696
+ command: ({ editor, range }) => {
1697
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 1 }).run();
1698
+ }
1699
+ };
1700
+ var heading2 = {
1701
+ title: "Heading 2",
1702
+ description: "Medium heading.",
1703
+ searchTerms: ["subtitle", "medium"],
1704
+ icon: /* @__PURE__ */ jsx16(Heading2, { className: "mly-h-4 mly-w-4" }),
1705
+ command: ({ editor, range }) => {
1706
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 2 }).run();
1707
+ }
1708
+ };
1709
+ var heading3 = {
1710
+ title: "Heading 3",
1711
+ description: "Small heading.",
1712
+ searchTerms: ["subtitle", "small"],
1713
+ icon: /* @__PURE__ */ jsx16(Heading3, { className: "mly-h-4 mly-w-4" }),
1714
+ command: ({ editor, range }) => {
1715
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 3 }).run();
1716
+ }
1717
+ };
1718
+ var hardBreak = {
1719
+ title: "Hard Break",
1720
+ description: "Add a break between lines.",
1721
+ searchTerms: ["break", "line"],
1722
+ icon: /* @__PURE__ */ jsx16(DivideIcon, { className: "mly-h-4 mly-w-4" }),
1723
+ command: ({ editor, range }) => {
1724
+ editor.chain().focus().deleteRange(range).setHardBreak().run();
1725
+ }
1726
+ };
1727
+ var blockquote = {
1728
+ title: "Blockquote",
1729
+ description: "Add blockquote.",
1730
+ searchTerms: ["quote", "blockquote"],
1731
+ icon: /* @__PURE__ */ jsx16(TextQuote, { className: "mly-h-4 mly-w-4" }),
1732
+ command: ({ editor, range }) => {
1733
+ editor.chain().focus().deleteRange(range).toggleBlockquote().run();
1734
+ }
1735
+ };
1736
+ var footer = {
1737
+ title: "Footer",
1738
+ description: "Add a footer text to email.",
1739
+ searchTerms: ["footer", "text"],
1740
+ icon: /* @__PURE__ */ jsx16(FootprintsIcon, { className: "mly-h-4 mly-w-4" }),
1741
+ command: ({ editor, range }) => {
1742
+ editor.chain().focus().deleteRange(range).setFooter().run();
1743
+ }
1744
+ };
1745
+ var clearLine = {
1746
+ title: "Clear Line",
1747
+ description: "Clear the current line.",
1748
+ searchTerms: ["clear", "line"],
1749
+ icon: /* @__PURE__ */ jsx16(EraserIcon, { className: "mly-h-4 mly-w-4" }),
1750
+ command: ({ editor, range }) => {
1751
+ editor.chain().focus().selectParentNode().deleteSelection().run();
1752
+ }
1753
+ };
1754
+
1755
+ // src/editor/extensions/slash-command/default-slash-commands.ts
1756
+ var DEFAULT_SLASH_COMMANDS = [
1757
+ text,
1758
+ heading1,
1759
+ heading2,
1760
+ heading3,
1761
+ bulletList,
1762
+ orderedList,
1763
+ image,
1764
+ logo,
1765
+ columns,
1766
+ section,
1767
+ forLoop,
1768
+ divider,
1769
+ spacer,
1770
+ button,
1771
+ linkCard,
1772
+ hardBreak,
1773
+ blockquote,
1774
+ footer,
1775
+ clearLine
1776
+ ];
1777
+
1778
+ // src/editor/nodes/variable/variable-view.tsx
1779
+ import { NodeViewWrapper as NodeViewWrapper3 } from "@tiptap/react";
1780
+ import { AlertTriangle, Braces, Pencil } from "lucide-react";
1781
+ import { jsx as jsx17, jsxs as jsxs5 } from "react/jsx-runtime";
1782
+ function VariableView(props) {
1783
+ const { node, updateAttributes: updateAttributes2, editor } = props;
1784
+ const { id, fallback, required } = node.attrs;
1785
+ const { renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION } = useMailyContext();
1786
+ return /* @__PURE__ */ jsx17(
1787
+ NodeViewWrapper3,
1788
+ {
1789
+ className: "react-component mly-inline-block mly-leading-none",
1790
+ draggable: "false",
1791
+ children: /* @__PURE__ */ jsxs5(Popover, { children: [
1792
+ /* @__PURE__ */ jsx17(PopoverTrigger, { children: renderVariable({
1793
+ variable: { name: id, required, valid: true },
1794
+ fallback,
1795
+ editor,
1796
+ from: "content-variable"
1797
+ }) }),
1798
+ /* @__PURE__ */ jsx17(
1799
+ PopoverContent,
1800
+ {
1801
+ align: "start",
1802
+ side: "bottom",
1803
+ className: "mly-w-max mly-rounded-lg !mly-p-0.5",
1804
+ sideOffset: 8,
1805
+ onOpenAutoFocus: (e) => e.preventDefault(),
1806
+ onCloseAutoFocus: (e) => e.preventDefault(),
1807
+ children: /* @__PURE__ */ jsx17(TooltipProvider, { children: /* @__PURE__ */ jsxs5("div", { className: "mly-flex mly-items-stretch mly-text-midnight-gray", children: [
1808
+ /* @__PURE__ */ jsxs5("label", { className: "mly-relative", children: [
1809
+ /* @__PURE__ */ jsx17("span", { className: "mly-inline-block mly-px-2 mly-text-xs mly-text-midnight-gray", children: "Variable" }),
1810
+ /* @__PURE__ */ jsx17(
1811
+ "input",
1812
+ __spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
1813
+ value: id != null ? id : "",
1814
+ onChange: (e) => {
1815
+ updateAttributes2({
1816
+ id: e.target.value
1817
+ });
1818
+ },
1819
+ placeholder: "ie. name...",
1820
+ className: "mly-h-7 mly-w-36 mly-rounded-md mly-bg-soft-gray mly-px-2 mly-text-sm mly-text-midnight-gray focus:mly-bg-soft-gray focus:mly-outline-none"
1821
+ })
1822
+ )
1823
+ ] }),
1824
+ /* @__PURE__ */ jsx17(Divider, { className: "mly-mx-1.5" }),
1825
+ /* @__PURE__ */ jsxs5("label", { className: "mly-relative", children: [
1826
+ /* @__PURE__ */ jsx17("span", { className: "mly-inline-block mly-px-2 mly-pl-1 mly-text-xs mly-text-midnight-gray", children: "Default" }),
1827
+ /* @__PURE__ */ jsx17(
1828
+ "input",
1829
+ __spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
1830
+ value: fallback != null ? fallback : "",
1831
+ onChange: (e) => {
1832
+ updateAttributes2({
1833
+ fallback: e.target.value
1834
+ });
1835
+ },
1836
+ placeholder: "ie. John Doe...",
1837
+ className: "mly-h-7 mly-w-32 mly-rounded-md mly-bg-soft-gray mly-px-2 mly-pr-6 mly-text-sm mly-text-midnight-gray focus:mly-bg-soft-gray focus:mly-outline-none"
1838
+ })
1839
+ ),
1840
+ /* @__PURE__ */ jsx17("div", { className: "mly-absolute mly-inset-y-0 mly-right-1 mly-flex mly-items-center", children: /* @__PURE__ */ jsx17(Pencil, { className: "mly-h-3 mly-w-3 mly-stroke-[2.5] mly-text-midnight-gray" }) })
1841
+ ] })
1842
+ ] }) })
1843
+ }
1844
+ )
1845
+ ] })
1846
+ }
1847
+ );
1848
+ }
1849
+ var DefaultRenderVariable = (props) => {
1850
+ const { variable, fallback, from } = props;
1851
+ const { name, required, valid } = variable;
1852
+ if (from === "button-variable") {
1853
+ return /* @__PURE__ */ jsxs5("div", { className: "mly-inline-grid mly-h-7 mly-max-w-xs mly-grid-cols-[12px_1fr] mly-items-center mly-gap-1.5 mly-rounded-md mly-border mly-border-[var(--button-var-border-color)] mly-px-2 mly-font-mono mly-text-sm", children: [
1854
+ /* @__PURE__ */ jsx17(Braces, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5]" }),
1855
+ /* @__PURE__ */ jsx17("span", { className: "mly-min-w-0 mly-truncate mly-text-left", children: name })
1856
+ ] });
1857
+ }
1858
+ if (from === "bubble-variable") {
1859
+ return /* @__PURE__ */ jsxs5(
1860
+ "div",
1861
+ {
1862
+ className: cn(
1863
+ "mly-inline-grid mly-h-7 mly-min-w-28 mly-max-w-xs mly-grid-cols-[12px_1fr] mly-items-center mly-gap-1.5 mly-rounded-md mly-border mly-px-2 mly-font-mono mly-text-sm hover:mly-bg-soft-gray",
1864
+ !valid && "mly-border-rose-400 mly-bg-rose-50 mly-text-rose-600 hover:mly-bg-rose-100"
1865
+ ),
1866
+ children: [
1867
+ /* @__PURE__ */ jsx17(Braces, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5] mly-text-rose-600" }),
1868
+ /* @__PURE__ */ jsx17("span", { className: "mly-min-w-0 mly-truncate mly-text-left", children: name })
1869
+ ]
1870
+ }
1871
+ );
1872
+ }
1873
+ return /* @__PURE__ */ jsxs5(
1874
+ "span",
1875
+ {
1876
+ tabIndex: -1,
1877
+ className: "mly-inline-flex mly-items-center mly-gap-[var(--variable-icon-gap)] mly-rounded-full mly-border mly-px-1.5 mly-py-0.5 mly-leading-none",
1878
+ children: [
1879
+ /* @__PURE__ */ jsx17(Braces, { className: "mly-size-[var(--variable-icon-size)] mly-shrink-0 mly-stroke-[2.5] mly-text-rose-600" }),
1880
+ name,
1881
+ required && !fallback && /* @__PURE__ */ jsx17(AlertTriangle, { className: "mly-size-[var(--variable-icon-size)] mly-shrink-0 mly-stroke-[2.5]" })
1882
+ ]
1883
+ }
1884
+ );
1885
+ };
1886
+
1887
+ // src/editor/provider.tsx
1888
+ import { jsx as jsx18 } from "react/jsx-runtime";
1889
+ var DEFAULT_VARIABLE_TRIGGER_CHAR = "@";
1890
+ var DEFAULT_VARIABLES = [];
1891
+ var DEFAULT_RENDER_VARIABLE_FUNCTION = DefaultRenderVariable;
1892
+ var MailyContext = createContext({
1893
+ variableTriggerCharacter: DEFAULT_VARIABLE_TRIGGER_CHAR,
1894
+ variables: DEFAULT_VARIABLES,
1895
+ blocks: DEFAULT_SLASH_COMMANDS,
1896
+ renderVariable: DEFAULT_RENDER_VARIABLE_FUNCTION
1897
+ });
1898
+ function useMailyContext() {
1899
+ const values = useContext(MailyContext);
1900
+ if (!values) {
1901
+ throw new Error("Missing MailyContext.Provider in the component tree");
1902
+ }
1903
+ return values;
1904
+ }
1905
+
1906
+ // src/editor/nodes/variable/variable-popover.tsx
1907
+ import {
1908
+ ArrowDownIcon,
1909
+ ArrowUpIcon,
1910
+ Braces as Braces2,
1911
+ CornerDownLeftIcon
1912
+ } from "lucide-react";
1913
+ import {
1914
+ useImperativeHandle,
1915
+ forwardRef as forwardRef6,
1916
+ useState,
1917
+ useEffect,
1918
+ useRef
1919
+ } from "react";
1920
+ import { jsx as jsx19, jsxs as jsxs6 } from "react/jsx-runtime";
1921
+ var VariablePopover = forwardRef6((props, ref) => {
1922
+ const { items, onSelectItem } = props;
1923
+ const [selectedIndex, setSelectedIndex] = useState(0);
1924
+ const scrollContainerRef = useRef(null);
1925
+ const itemRefs = useRef([]);
1926
+ const scrollSelectedIntoView = (index) => {
1927
+ const container = scrollContainerRef.current;
1928
+ const selectedItem = itemRefs.current[index];
1929
+ if (!container || !selectedItem) {
1930
+ return;
1931
+ }
1932
+ const containerRect = container.getBoundingClientRect();
1933
+ const itemRect = selectedItem.getBoundingClientRect();
1934
+ const padding = 4;
1935
+ if (itemRect.bottom > containerRect.bottom) {
1936
+ container.scrollTop += itemRect.bottom - containerRect.bottom + padding;
1937
+ } else if (itemRect.top < containerRect.top) {
1938
+ container.scrollTop += itemRect.top - containerRect.top - padding;
1939
+ }
1940
+ };
1941
+ useEffect(() => {
1942
+ setSelectedIndex(0);
1943
+ if (scrollContainerRef.current) {
1944
+ scrollContainerRef.current.scrollTop = 0;
1945
+ }
1946
+ itemRefs.current = items.map(() => null);
1947
+ }, [items]);
1948
+ useEffect(() => {
1949
+ scrollSelectedIntoView(selectedIndex);
1950
+ }, [selectedIndex]);
1951
+ useImperativeHandle(ref, () => ({
1952
+ moveUp: () => {
1953
+ setSelectedIndex((selectedIndex + items.length - 1) % items.length);
1954
+ },
1955
+ moveDown: () => {
1956
+ setSelectedIndex((selectedIndex + 1) % items.length);
1957
+ },
1958
+ select: () => {
1959
+ const item = items[selectedIndex];
1960
+ if (!item) {
1961
+ return;
1962
+ }
1963
+ onSelectItem(item);
1964
+ }
1965
+ }));
1966
+ return /* @__PURE__ */ jsxs6("div", { className: "mly-z-50 mly-w-64 mly-rounded-lg mly-border mly-border-gray-200 mly-bg-white mly-shadow-md mly-transition-all", children: [
1967
+ /* @__PURE__ */ jsxs6("div", { className: "mly-flex mly-items-center mly-justify-between mly-gap-2 mly-border-b mly-border-gray-200 mly-bg-soft-gray/40 mly-px-1 mly-py-1.5 mly-text-gray-500", children: [
1968
+ /* @__PURE__ */ jsx19("span", { className: "mly-text-xs mly-uppercase", children: "Variables" }),
1969
+ /* @__PURE__ */ jsx19(VariableIcon, { children: /* @__PURE__ */ jsx19(Braces2, { className: "mly-size-3 mly-stroke-[2.5]" }) })
1970
+ ] }),
1971
+ /* @__PURE__ */ jsx19(
1972
+ "div",
1973
+ {
1974
+ ref: scrollContainerRef,
1975
+ className: "mly-max-h-52 mly-overflow-y-auto mly-scrollbar-thin mly-scrollbar-track-transparent mly-scrollbar-thumb-gray-200",
1976
+ children: /* @__PURE__ */ jsx19("div", { className: "mly-flex mly-w-fit mly-min-w-full mly-flex-col mly-gap-0.5 mly-p-1", children: (items == null ? void 0 : items.length) ? items == null ? void 0 : items.map((item, index) => /* @__PURE__ */ jsxs6(
1977
+ "button",
1978
+ {
1979
+ ref: (el) => itemRefs.current[index] = el,
1980
+ onClick: () => onSelectItem(item),
1981
+ className: cn(
1982
+ "mly-flex mly-w-fit mly-min-w-full mly-items-center mly-gap-2 mly-rounded-md mly-px-2 mly-py-1 mly-text-left mly-font-mono mly-text-sm mly-text-gray-900 hover:mly-bg-soft-gray",
1983
+ index === selectedIndex ? "mly-bg-soft-gray" : "mly-bg-white"
1984
+ ),
1985
+ children: [
1986
+ /* @__PURE__ */ jsx19(Braces2, { className: "mly-size-3 mly-stroke-[2.5] mly-text-rose-600" }),
1987
+ item.name
1988
+ ]
1989
+ },
1990
+ index
1991
+ )) : /* @__PURE__ */ jsx19("div", { className: "mly-flex mly-h-7 mly-w-full mly-items-center mly-gap-2 mly-rounded-md mly-px-2 mly-py-1 mly-text-left mly-font-mono mly-text-[13px] mly-text-gray-900 hover:mly-bg-soft-gray", children: "No result" }) })
1992
+ }
1993
+ ),
1994
+ /* @__PURE__ */ jsxs6("div", { className: "mly-flex mly-items-center mly-justify-between mly-gap-2 mly-border-t mly-border-gray-200 mly-px-1 mly-py-1.5 mly-text-gray-500", children: [
1995
+ /* @__PURE__ */ jsxs6("div", { className: "mly-flex mly-items-center mly-gap-1", children: [
1996
+ /* @__PURE__ */ jsx19(VariableIcon, { children: /* @__PURE__ */ jsx19(ArrowDownIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) }),
1997
+ /* @__PURE__ */ jsx19(VariableIcon, { children: /* @__PURE__ */ jsx19(ArrowUpIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) }),
1998
+ /* @__PURE__ */ jsx19("span", { className: "mly-text-xs mly-text-gray-500", children: "Navigate" })
1999
+ ] }),
2000
+ /* @__PURE__ */ jsx19(VariableIcon, { children: /* @__PURE__ */ jsx19(CornerDownLeftIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) })
2001
+ ] })
2002
+ ] });
2003
+ });
2004
+ function VariableIcon(props) {
2005
+ const { className, children } = props;
2006
+ return /* @__PURE__ */ jsx19(
2007
+ "div",
2008
+ {
2009
+ className: cn(
2010
+ "mly-flex mly-size-5 mly-items-center mly-justify-center mly-rounded-md mly-border",
2011
+ className
2012
+ ),
2013
+ children
2014
+ }
2015
+ );
2016
+ }
2017
+
2018
+ // src/editor/utils/use-outside-click.ts
2019
+ import { useCallback } from "react";
2020
+ import { useEffect as useEffect2 } from "react";
2021
+ function useOutsideClick(ref, callback) {
2022
+ const handleClick = useCallback(
2023
+ (e) => {
2024
+ if (ref.current && !ref.current.contains(e.target)) {
2025
+ callback();
2026
+ }
2027
+ },
2028
+ [ref, callback]
2029
+ );
2030
+ useEffect2(() => {
2031
+ document.addEventListener("mousedown", handleClick);
2032
+ document.addEventListener("touchstart", handleClick);
2033
+ return () => {
2034
+ document.removeEventListener("mousedown", handleClick);
2035
+ document.removeEventListener("touchstart", handleClick);
2036
+ };
2037
+ }, [handleClick]);
2038
+ }
2039
+
2040
+ // src/editor/components/ui/input-autocomplete.tsx
2041
+ import { CornerDownLeft } from "lucide-react";
2042
+ import { forwardRef as forwardRef7, useRef as useRef2 } from "react";
2043
+ import { jsx as jsx20, jsxs as jsxs7 } from "react/jsx-runtime";
2044
+ var InputAutocomplete = forwardRef7((props, ref) => {
2045
+ const _a = props, {
2046
+ value = "",
2047
+ onValueChange,
2048
+ className,
2049
+ onOutsideClick,
2050
+ onSelectOption,
2051
+ autoCompleteOptions = [],
2052
+ triggerChar = ""
2053
+ } = _a, inputProps = __objRest(_a, [
2054
+ "value",
2055
+ "onValueChange",
2056
+ "className",
2057
+ "onOutsideClick",
2058
+ "onSelectOption",
2059
+ "autoCompleteOptions",
2060
+ "triggerChar"
2061
+ ]);
2062
+ const containerRef = useRef2(null);
2063
+ const popoverRef = useRef2(null);
2064
+ useOutsideClick(containerRef, () => {
2065
+ onOutsideClick == null ? void 0 : onOutsideClick();
2066
+ });
2067
+ const isTriggeringVariable = value.startsWith(triggerChar);
2068
+ return /* @__PURE__ */ jsxs7("div", { className: cn("mly-relative"), ref: containerRef, children: [
2069
+ /* @__PURE__ */ jsxs7("label", { className: "mly-relative", children: [
2070
+ /* @__PURE__ */ jsx20(
2071
+ "input",
2072
+ __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
2073
+ placeholder: "e.g. items",
2074
+ type: "text"
2075
+ }), inputProps), {
2076
+ ref,
2077
+ value,
2078
+ onChange: (e) => {
2079
+ onValueChange(e.target.value);
2080
+ },
2081
+ className: cn(
2082
+ "mly-h-7 mly-w-40 mly-rounded-md mly-px-2 mly-pr-6 mly-text-sm mly-text-midnight-gray hover:mly-bg-soft-gray focus:mly-bg-soft-gray focus:mly-outline-none",
2083
+ className
2084
+ ),
2085
+ onKeyDown: (e) => {
2086
+ if (!popoverRef.current || !isTriggeringVariable) {
2087
+ return;
2088
+ }
2089
+ const { moveUp, moveDown, select } = popoverRef.current;
2090
+ if (e.key === "ArrowDown") {
2091
+ e.preventDefault();
2092
+ moveDown();
2093
+ } else if (e.key === "ArrowUp") {
2094
+ e.preventDefault();
2095
+ moveUp();
2096
+ } else if (e.key === "Enter") {
2097
+ e.preventDefault();
2098
+ select();
2099
+ }
2100
+ },
2101
+ spellCheck: false
2102
+ })
2103
+ ),
2104
+ /* @__PURE__ */ jsx20("div", { className: "mly-absolute mly-inset-y-0 mly-right-1 mly-flex mly-items-center", children: /* @__PURE__ */ jsx20(CornerDownLeft, { className: "mly-h-3 mly-w-3 mly-stroke-[2.5] mly-text-midnight-gray" }) })
2105
+ ] }),
2106
+ isTriggeringVariable && /* @__PURE__ */ jsx20("div", { className: "mly-absolute mly-left-0 mly-top-8", children: /* @__PURE__ */ jsx20(
2107
+ VariablePopover,
2108
+ {
2109
+ items: autoCompleteOptions.map((option) => {
2110
+ return {
2111
+ name: option
2112
+ };
2113
+ }),
2114
+ onSelectItem: (item) => {
2115
+ onSelectOption == null ? void 0 : onSelectOption(item.name);
2116
+ },
2117
+ ref: popoverRef
2118
+ }
2119
+ ) })
2120
+ ] });
2121
+ });
2122
+ InputAutocomplete.displayName = "InputAutocomplete";
2123
+
2124
+ // src/editor/utils/variable.ts
2125
+ function processVariables(variables, options) {
2126
+ const { query } = options;
2127
+ const queryLower = query.toLowerCase();
2128
+ let filteredVariables = [];
2129
+ if (Array.isArray(variables)) {
2130
+ filteredVariables = variables.filter(
2131
+ (variable) => variable.name.toLowerCase().startsWith(queryLower)
2132
+ );
2133
+ if (query.length > 0 && !filteredVariables.some((variable) => variable.name === query)) {
2134
+ filteredVariables.push({ name: query, required: true });
2135
+ }
2136
+ return filteredVariables;
2137
+ } else if (typeof variables === "function") {
2138
+ return variables(options);
2139
+ } else {
2140
+ throw new Error(`Invalid variables type. Expected 'Array' or 'Function', but received '${typeof variables}'.
2141
+
2142
+ You can check out the documentation for more information: https://github.com/arikchakma/maily.to/blob/main/packages/core/readme.md`);
2143
+ }
2144
+ }
2145
+
2146
+ // src/editor/components/ui/link-input-popover.tsx
2147
+ import { useMemo as useMemo2 } from "react";
2148
+ import { Fragment as Fragment2, jsx as jsx21, jsxs as jsxs8 } from "react/jsx-runtime";
2149
+ var LINK_PROTOCOL_REGEX = /https?:\/\//;
2150
+ function LinkInputPopover(props) {
2151
+ var _a;
2152
+ const {
2153
+ defaultValue = "",
2154
+ onValueChange,
2155
+ tooltip,
2156
+ icon: Icon = Link,
2157
+ editor,
2158
+ isVariable
2159
+ } = props;
2160
+ const defaultProtocol = (_a = defaultValue.match(LINK_PROTOCOL_REGEX)) == null ? void 0 : _a[0];
2161
+ const defaultUrlWithoutProtocol = defaultValue.replace(
2162
+ LINK_PROTOCOL_REGEX,
2163
+ ""
2164
+ );
2165
+ const [isOpen, setIsOpen] = useState3(false);
2166
+ const [protocol, setProtocol] = useState3(defaultProtocol || "https://");
2167
+ const [isEditing, setIsEditing] = useState3(!isVariable);
2168
+ const linkInputRef = useRef3(null);
2169
+ const {
2170
+ variables = [],
2171
+ variableTriggerCharacter = DEFAULT_VARIABLE_TRIGGER_CHAR,
2172
+ renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION
2173
+ } = useMailyContext();
2174
+ const autoCompleteOptions = useMemo2(() => {
2175
+ const withoutTrigger = defaultUrlWithoutProtocol.replace(
2176
+ new RegExp(variableTriggerCharacter, "g"),
2177
+ ""
2178
+ );
2179
+ return processVariables(variables, {
2180
+ query: withoutTrigger || "",
2181
+ from: "bubble-variable",
2182
+ editor
2183
+ }).map((variable) => variable.name);
2184
+ }, [variables, defaultUrlWithoutProtocol, editor]);
2185
+ const popoverButton = /* @__PURE__ */ jsx21(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx21(
2186
+ BaseButton,
2187
+ {
2188
+ variant: "ghost",
2189
+ size: "sm",
2190
+ type: "button",
2191
+ className: "mly-size-7",
2192
+ "data-state": !!defaultUrlWithoutProtocol,
2193
+ children: /* @__PURE__ */ jsx21(Icon, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5] mly-text-midnight-gray" })
2194
+ }
2195
+ ) });
2196
+ const normalizeProtocol = (value, p = protocol) => {
2197
+ value = value == null ? void 0 : value.replace(LINK_PROTOCOL_REGEX, "");
2198
+ return p + value;
2199
+ };
2200
+ return /* @__PURE__ */ jsxs8(Popover, { open: isOpen, onOpenChange: setIsOpen, children: [
2201
+ tooltip ? /* @__PURE__ */ jsxs8(Tooltip, { children: [
2202
+ /* @__PURE__ */ jsx21(TooltipTrigger, { asChild: true, children: popoverButton }),
2203
+ /* @__PURE__ */ jsx21(TooltipContent, { sideOffset: 8, children: tooltip })
2204
+ ] }) : popoverButton,
2205
+ /* @__PURE__ */ jsx21(
2206
+ PopoverContent,
2207
+ {
2208
+ align: "end",
2209
+ side: "top",
2210
+ className: "mly-w-max mly-rounded-none mly-border-none mly-bg-transparent !mly-p-0 mly-shadow-none",
2211
+ sideOffset: 8,
2212
+ onCloseAutoFocus: (e) => e.preventDefault(),
2213
+ children: /* @__PURE__ */ jsx21(
2214
+ "form",
2215
+ {
2216
+ onSubmit: (e) => {
2217
+ e.preventDefault();
2218
+ const input = linkInputRef.current;
2219
+ if (!input) {
2220
+ return;
2221
+ }
2222
+ let value = normalizeProtocol(input.value);
2223
+ onValueChange == null ? void 0 : onValueChange(value);
2224
+ setIsOpen(false);
2225
+ },
2226
+ children: /* @__PURE__ */ jsxs8("div", { className: "mly-isolate mly-flex mly-rounded-lg", children: [
2227
+ !isEditing && /* @__PURE__ */ jsx21("div", { className: "mly-flex mly-h-8 mly-items-center mly-rounded-lg mly-border mly-border-gray-300 mly-bg-white mly-px-0.5", children: /* @__PURE__ */ jsx21(
2228
+ "button",
2229
+ {
2230
+ onClick: () => {
2231
+ setIsEditing(true);
2232
+ setTimeout(() => {
2233
+ var _a2;
2234
+ (_a2 = linkInputRef.current) == null ? void 0 : _a2.focus();
2235
+ }, 0);
2236
+ },
2237
+ children: renderVariable({
2238
+ variable: {
2239
+ name: defaultUrlWithoutProtocol,
2240
+ valid: true
2241
+ },
2242
+ fallback: "",
2243
+ from: "bubble-variable",
2244
+ editor
2245
+ })
2246
+ }
2247
+ ) }),
2248
+ isEditing && /* @__PURE__ */ jsxs8(Fragment2, { children: [
2249
+ /* @__PURE__ */ jsxs8("div", { className: "mly-relative", children: [
2250
+ /* @__PURE__ */ jsxs8(
2251
+ "select",
2252
+ {
2253
+ className: "hover:text-accent-foreground mly-peer mly-inline-flex mly-h-full mly-appearance-none mly-items-center mly-rounded-none mly-rounded-s-lg mly-border mly-border-gray-300 mly-bg-gray-50 mly-pe-8 mly-ps-3 mly-text-sm mly-text-gray-700 mly-transition-shadow hover:mly-bg-gray-100 focus:mly-z-10 focus-visible:mly-outline-none disabled:mly-pointer-events-none disabled:mly-cursor-not-allowed disabled:mly-opacity-50",
2254
+ "aria-label": "Protocol",
2255
+ value: protocol,
2256
+ onChange: (e) => {
2257
+ var _a2;
2258
+ const protocol2 = e.target.value;
2259
+ setProtocol(protocol2);
2260
+ const newValue = normalizeProtocol(
2261
+ ((_a2 = linkInputRef.current) == null ? void 0 : _a2.value) || "",
2262
+ protocol2
2263
+ );
2264
+ onValueChange == null ? void 0 : onValueChange(newValue);
2265
+ },
2266
+ children: [
2267
+ /* @__PURE__ */ jsx21("option", { value: "https://", children: "https://" }),
2268
+ /* @__PURE__ */ jsx21("option", { value: "http://", children: "http://" })
2269
+ ]
2270
+ }
2271
+ ),
2272
+ /* @__PURE__ */ jsx21("span", { className: "mly-pointer-events-none mly-absolute mly-inset-y-0 mly-right-0 mly-z-10 mly-flex mly-h-full mly-w-9 mly-items-center mly-justify-center mly-text-gray-600 peer-disabled:mly-opacity-50", children: /* @__PURE__ */ jsx21(
2273
+ ChevronDownIcon,
2274
+ {
2275
+ size: 16,
2276
+ strokeWidth: 2,
2277
+ "aria-hidden": "true",
2278
+ role: "img"
2279
+ }
2280
+ ) })
2281
+ ] }),
2282
+ /* @__PURE__ */ jsx21(
2283
+ InputAutocomplete,
2284
+ {
2285
+ value: defaultUrlWithoutProtocol,
2286
+ onValueChange: (value) => {
2287
+ let newValue = normalizeProtocol(value);
2288
+ onValueChange == null ? void 0 : onValueChange(newValue);
2289
+ },
2290
+ autoCompleteOptions,
2291
+ ref: linkInputRef,
2292
+ placeholder: "maily.to/",
2293
+ className: "-mly-ms-px mly-block mly-h-8 mly-w-52 mly-rounded-lg mly-rounded-s-none mly-border mly-border-gray-300 mly-px-2 mly-py-1.5 mly-pr-6 mly-text-sm mly-shadow-sm mly-outline-none placeholder:mly-text-gray-400",
2294
+ triggerChar: variableTriggerCharacter,
2295
+ onSelectOption: (value) => {
2296
+ var _a2;
2297
+ const isVariable2 = (_a2 = autoCompleteOptions.includes(value)) != null ? _a2 : false;
2298
+ if (isVariable2) {
2299
+ setIsEditing(false);
2300
+ } else {
2301
+ value = normalizeProtocol(value);
2302
+ }
2303
+ onValueChange == null ? void 0 : onValueChange(value, isVariable2);
2304
+ setIsOpen(false);
2305
+ }
2306
+ }
2307
+ )
2308
+ ] })
2309
+ ] })
2310
+ }
2311
+ )
2312
+ }
2313
+ )
2314
+ ] });
2315
+ }
2316
+
2317
+ // src/editor/components/ui/select.tsx
2318
+ import { useId } from "react";
2319
+ import { ChevronDownIcon as ChevronDownIcon2 } from "lucide-react";
2320
+ import { jsx as jsx22, jsxs as jsxs9 } from "react/jsx-runtime";
2321
+ function Select(props) {
2322
+ const {
2323
+ label,
2324
+ options,
2325
+ value,
2326
+ onValueChange,
2327
+ tooltip,
2328
+ className,
2329
+ icon: Icon,
2330
+ iconClassName
2331
+ } = props;
2332
+ const selectId = `mly${useId()}`;
2333
+ const content = /* @__PURE__ */ jsxs9("div", { className: "relative", children: [
2334
+ /* @__PURE__ */ jsx22("label", { htmlFor: selectId, className: "sr-only", children: label }),
2335
+ Icon && /* @__PURE__ */ jsx22("div", { className: "mly-pointer-events-none mly-absolute mly-inset-y-0 mly-left-2 mly-z-20 mly-flex mly-items-center", children: /* @__PURE__ */ jsx22(Icon, { className: cn("mly-size-3", iconClassName) }) }),
2336
+ /* @__PURE__ */ jsx22(
2337
+ "select",
2338
+ {
2339
+ id: selectId,
2340
+ className: cn(
2341
+ "mly-flex mly-min-h-7 mly-max-w-max mly-appearance-none mly-items-center mly-rounded-md mly-px-1.5 mly-py-0.5 mly-pr-7 mly-text-sm mly-text-midnight-gray mly-ring-offset-white mly-transition-colors hover:mly-bg-soft-gray focus-visible:mly-relative focus-visible:mly-z-10 focus-visible:mly-outline-none focus-visible:mly-ring-2 focus-visible:mly-ring-gray-400 focus-visible:mly-ring-offset-2 active:mly-bg-soft-gray",
2342
+ !!Icon && "mly-pl-7",
2343
+ className
2344
+ ),
2345
+ value,
2346
+ onChange: (event) => onValueChange(event.target.value),
2347
+ children: options.map((option) => /* @__PURE__ */ jsx22("option", { value: option.value, children: option.label }, option.value))
2348
+ }
2349
+ ),
2350
+ /* @__PURE__ */ jsx22("span", { className: "mly-pointer-events-none mly-absolute mly-inset-y-0 mly-right-0 mly-z-10 mly-flex mly-h-full mly-w-7 mly-items-center mly-justify-center mly-text-gray-600 peer-disabled:mly-opacity-50", children: /* @__PURE__ */ jsx22(
2351
+ ChevronDownIcon2,
2352
+ {
2353
+ size: 16,
2354
+ strokeWidth: 2,
2355
+ "aria-hidden": "true",
2356
+ role: "img"
2357
+ }
2358
+ ) })
2359
+ ] });
2360
+ if (!tooltip) {
2361
+ return content;
2362
+ }
2363
+ return /* @__PURE__ */ jsxs9(Tooltip, { children: [
2364
+ /* @__PURE__ */ jsx22(TooltipTrigger, { asChild: true, children: content }),
2365
+ /* @__PURE__ */ jsx22(TooltipContent, { sideOffset: 8, children: tooltip })
2366
+ ] });
2367
+ }
2368
+
2369
+ // src/editor/nodes/button/button-view.tsx
2370
+ import { NodeViewWrapper as NodeViewWrapper4 } from "@tiptap/react";
2371
+
2372
+ // src/editor/components/show-popover.tsx
2373
+ import { Eye } from "lucide-react";
2374
+ import { useRef as useRef4, useState as useState4 } from "react";
2375
+ import { useMemo as useMemo3 } from "react";
2376
+ import { memo } from "react";
2377
+ import { jsx as jsx23, jsxs as jsxs10 } from "react/jsx-runtime";
2378
+ function _ShowPopover(props) {
2379
+ const { showIfKey = "", onShowIfKeyValueChange, editor } = props;
2380
+ const { variables = [], renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION } = useMailyContext();
2381
+ const [isUpdatingKey, setIsUpdatingKey] = useState4(false);
2382
+ const inputRef = useRef4(null);
2383
+ const autoCompleteOptions = useMemo3(() => {
2384
+ return processVariables(variables, {
2385
+ query: showIfKey || "",
2386
+ from: "bubble-variable",
2387
+ editor
2388
+ }).map((variable) => variable.name);
2389
+ }, [variables, showIfKey, editor]);
2390
+ const isValidWhenKey = showIfKey || autoCompleteOptions.includes(showIfKey);
2391
+ return /* @__PURE__ */ jsxs10(
2392
+ Popover,
2393
+ {
2394
+ onOpenChange: (open) => {
2395
+ if (open) {
2396
+ return;
2397
+ }
2398
+ setIsUpdatingKey(false);
2399
+ },
2400
+ children: [
2401
+ /* @__PURE__ */ jsxs10(Tooltip, { children: [
2402
+ /* @__PURE__ */ jsx23(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx23(
2403
+ PopoverTrigger,
2404
+ {
2405
+ className: cn(
2406
+ "mly-flex mly-items-center mly-gap-1 mly-rounded-md mly-px-1.5 mly-text-sm data-[state=open]:mly-bg-soft-gray hover:mly-bg-soft-gray focus-visible:mly-relative focus-visible:mly-z-10 focus-visible:mly-outline-none focus-visible:mly-ring-2 focus-visible:mly-ring-gray-400 focus-visible:mly-ring-offset-2",
2407
+ showIfKey && "mly-bg-rose-100 mly-text-rose-800 data-[state=open]:mly-bg-rose-100 hover:mly-bg-rose-100"
2408
+ ),
2409
+ children: /* @__PURE__ */ jsx23(Eye, { className: "mly-h-4 mly-w-4 mly-stroke-[2.5]" })
2410
+ }
2411
+ ) }),
2412
+ /* @__PURE__ */ jsx23(TooltipContent, { sideOffset: 8, children: "Show block conditionally" })
2413
+ ] }),
2414
+ /* @__PURE__ */ jsxs10(
2415
+ PopoverContent,
2416
+ {
2417
+ className: "mly-flex mly-w-max mly-rounded-lg !mly-p-0.5",
2418
+ side: "top",
2419
+ sideOffset: 8,
2420
+ align: "end",
2421
+ onOpenAutoFocus: (e) => {
2422
+ e.preventDefault();
2423
+ },
2424
+ onCloseAutoFocus: (e) => {
2425
+ e.preventDefault();
2426
+ },
2427
+ children: [
2428
+ /* @__PURE__ */ jsx23("span", { className: "mly-flex mly-items-center mly-px-1.5 mly-text-sm mly-leading-none", children: "Show if" }),
2429
+ !isUpdatingKey && /* @__PURE__ */ jsx23(
2430
+ "button",
2431
+ {
2432
+ onClick: () => {
2433
+ setIsUpdatingKey(true);
2434
+ setTimeout(() => {
2435
+ var _a;
2436
+ (_a = inputRef.current) == null ? void 0 : _a.focus();
2437
+ }, 0);
2438
+ },
2439
+ children: renderVariable({
2440
+ variable: {
2441
+ name: showIfKey,
2442
+ valid: !!isValidWhenKey
2443
+ },
2444
+ fallback: "",
2445
+ from: "bubble-variable",
2446
+ editor
2447
+ })
2448
+ }
2449
+ ),
2450
+ isUpdatingKey && /* @__PURE__ */ jsx23(
2451
+ "form",
2452
+ {
2453
+ onSubmit: (e) => {
2454
+ e.preventDefault();
2455
+ setIsUpdatingKey(false);
2456
+ },
2457
+ onKeyDown: (e) => {
2458
+ if (e.key === "Escape") {
2459
+ setIsUpdatingKey(false);
2460
+ }
2461
+ },
2462
+ children: /* @__PURE__ */ jsx23(
2463
+ InputAutocomplete,
2464
+ {
2465
+ value: showIfKey || "",
2466
+ onValueChange: (value) => {
2467
+ onShowIfKeyValueChange == null ? void 0 : onShowIfKeyValueChange(value);
2468
+ },
2469
+ onOutsideClick: () => {
2470
+ setIsUpdatingKey(false);
2471
+ },
2472
+ onSelectOption: (value) => {
2473
+ onShowIfKeyValueChange == null ? void 0 : onShowIfKeyValueChange(value);
2474
+ setIsUpdatingKey(false);
2475
+ },
2476
+ autoCompleteOptions,
2477
+ ref: inputRef
2478
+ }
2479
+ )
2480
+ }
2481
+ )
2482
+ ]
2483
+ }
2484
+ )
2485
+ ]
2486
+ }
2487
+ );
2488
+ }
2489
+ var ShowPopover = memo(_ShowPopover);
2490
+
2491
+ // src/editor/nodes/button/button-label-input.tsx
2492
+ import { useMemo as useMemo4 } from "react";
2493
+ import { useState as useState5 } from "react";
2494
+ import { useRef as useRef5 } from "react";
2495
+ import { jsx as jsx24, jsxs as jsxs11 } from "react/jsx-runtime";
2496
+ function ButtonLabelInput(props) {
2497
+ const { value, onValueChange, isVariable, editor } = props;
2498
+ const linkInputRef = useRef5(null);
2499
+ const [isEditing, setIsEditing] = useState5(!isVariable);
2500
+ const {
2501
+ variables = [],
2502
+ variableTriggerCharacter = DEFAULT_VARIABLE_TRIGGER_CHAR,
2503
+ renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION
2504
+ } = useMailyContext();
2505
+ const autoCompleteOptions = useMemo4(() => {
2506
+ const withoutTrigger = value.replace(
2507
+ new RegExp(variableTriggerCharacter, "g"),
2508
+ ""
2509
+ );
2510
+ return processVariables(variables, {
2511
+ query: withoutTrigger || "",
2512
+ from: "bubble-variable",
2513
+ editor
2514
+ }).map((variable) => variable.name);
2515
+ }, [variables, value, editor]);
2516
+ return /* @__PURE__ */ jsxs11("div", { className: "mly-isolate mly-flex mly-rounded-lg", children: [
2517
+ !isEditing && /* @__PURE__ */ jsx24(
2518
+ "button",
2519
+ {
2520
+ onClick: () => {
2521
+ setIsEditing(true);
2522
+ setTimeout(() => {
2523
+ var _a;
2524
+ (_a = linkInputRef.current) == null ? void 0 : _a.focus();
2525
+ }, 0);
2526
+ },
2527
+ children: renderVariable({
2528
+ variable: {
2529
+ name: value,
2530
+ valid: true
2531
+ },
2532
+ fallback: "",
2533
+ from: "bubble-variable",
2534
+ editor
2535
+ })
2536
+ }
2537
+ ),
2538
+ isEditing && /* @__PURE__ */ jsx24(
2539
+ InputAutocomplete,
2540
+ {
2541
+ value,
2542
+ onValueChange: (value2) => {
2543
+ onValueChange == null ? void 0 : onValueChange(value2);
2544
+ },
2545
+ autoCompleteOptions,
2546
+ ref: linkInputRef,
2547
+ placeholder: "maily.to/",
2548
+ className: "mly-h-7 mly-w-40 mly-rounded-md mly-px-2 mly-pr-6 mly-text-sm mly-text-midnight-gray hover:mly-bg-soft-gray focus:mly-bg-soft-gray focus:mly-outline-none",
2549
+ triggerChar: variableTriggerCharacter,
2550
+ onSelectOption: (value2) => {
2551
+ var _a;
2552
+ const isVariable2 = (_a = autoCompleteOptions.includes(value2)) != null ? _a : false;
2553
+ if (isVariable2) {
2554
+ setIsEditing(false);
2555
+ }
2556
+ onValueChange == null ? void 0 : onValueChange(value2, isVariable2);
2557
+ }
2558
+ }
2559
+ )
2560
+ ] });
2561
+ }
2562
+
2563
+ // src/editor/nodes/button/button-view.tsx
2564
+ import { jsx as jsx25, jsxs as jsxs12 } from "react/jsx-runtime";
2565
+ function ButtonView(props) {
2566
+ const { node, editor, getPos, updateAttributes: updateAttributes2 } = props;
2567
+ const {
2568
+ text: text2,
2569
+ isTextVariable,
2570
+ alignment,
2571
+ variant,
2572
+ borderRadius: _radius,
2573
+ buttonColor,
2574
+ textColor,
2575
+ url: externalLink,
2576
+ showIfKey = "",
2577
+ isUrlVariable
2578
+ } = node.attrs;
2579
+ const { renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION } = useMailyContext();
2580
+ return /* @__PURE__ */ jsx25(
2581
+ NodeViewWrapper4,
2582
+ {
2583
+ draggable: "true",
2584
+ "data-drag-handle": "",
2585
+ "data-type": "button",
2586
+ style: {
2587
+ textAlign: alignment
2588
+ },
2589
+ children: /* @__PURE__ */ jsxs12(Popover, { open: props.selected, children: [
2590
+ /* @__PURE__ */ jsx25(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx25("div", { children: /* @__PURE__ */ jsx25(
2591
+ "button",
2592
+ {
2593
+ className: cn(
2594
+ "mly-inline-flex mly-items-center mly-justify-center mly-rounded-md mly-text-sm mly-font-medium mly-ring-offset-white mly-transition-colors disabled:mly-pointer-events-none disabled:mly-opacity-50",
2595
+ "mly-h-10 mly-px-4 mly-py-2",
2596
+ "mly-px-[32px] mly-py-[20px] mly-font-semibold mly-no-underline",
2597
+ {
2598
+ "!mly-rounded-full": _radius === "round",
2599
+ "!mly-rounded-md": _radius === "smooth",
2600
+ "!mly-rounded-none": _radius === "sharp"
2601
+ }
2602
+ ),
2603
+ tabIndex: -1,
2604
+ style: {
2605
+ backgroundColor: variant === "filled" ? buttonColor : "transparent",
2606
+ color: textColor,
2607
+ borderWidth: 2,
2608
+ borderStyle: "solid",
2609
+ borderColor: buttonColor,
2610
+ // decrease the border color opacity to 80%
2611
+ // so that it's not too prominent
2612
+ "--button-var-border-color": `${textColor}80`
2613
+ },
2614
+ onClick: (e) => {
2615
+ e.preventDefault();
2616
+ const pos = getPos();
2617
+ editor.commands.setNodeSelection(pos);
2618
+ },
2619
+ children: isTextVariable ? renderVariable({
2620
+ variable: { name: text2, valid: true },
2621
+ fallback: text2,
2622
+ from: "button-variable",
2623
+ editor
2624
+ }) : text2
2625
+ }
2626
+ ) }) }),
2627
+ /* @__PURE__ */ jsx25(
2628
+ PopoverContent,
2629
+ {
2630
+ align: "end",
2631
+ side: "top",
2632
+ className: "mly-w-max mly-rounded-lg !mly-p-0.5",
2633
+ sideOffset: 8,
2634
+ onOpenAutoFocus: (e) => e.preventDefault(),
2635
+ onCloseAutoFocus: (e) => e.preventDefault(),
2636
+ children: /* @__PURE__ */ jsx25(TooltipProvider, { children: /* @__PURE__ */ jsxs12("div", { className: "mly-flex mly-items-stretch mly-text-midnight-gray", children: [
2637
+ /* @__PURE__ */ jsx25(
2638
+ ButtonLabelInput,
2639
+ {
2640
+ value: text2,
2641
+ onValueChange: (value, isVariable) => {
2642
+ updateAttributes2({
2643
+ text: value,
2644
+ isTextVariable: isVariable != null ? isVariable : false
2645
+ });
2646
+ },
2647
+ isVariable: isTextVariable,
2648
+ editor
2649
+ }
2650
+ ),
2651
+ /* @__PURE__ */ jsx25(Divider, {}),
2652
+ /* @__PURE__ */ jsxs12("div", { className: "mly-flex mly-space-x-0.5", children: [
2653
+ /* @__PURE__ */ jsx25(
2654
+ Select,
2655
+ {
2656
+ label: "Border Radius",
2657
+ value: _radius,
2658
+ options: allowedButtonBorderRadius.map((value) => ({
2659
+ value,
2660
+ label: value
2661
+ })),
2662
+ onValueChange: (value) => {
2663
+ updateAttributes2({
2664
+ borderRadius: value
2665
+ });
2666
+ },
2667
+ tooltip: "Border Radius",
2668
+ className: "mly-capitalize"
2669
+ }
2670
+ ),
2671
+ /* @__PURE__ */ jsx25(
2672
+ Select,
2673
+ {
2674
+ label: "Style",
2675
+ value: variant,
2676
+ options: allowedButtonVariant.map((value) => ({
2677
+ value,
2678
+ label: value
2679
+ })),
2680
+ onValueChange: (value) => {
2681
+ updateAttributes2({
2682
+ variant: value
2683
+ });
2684
+ },
2685
+ tooltip: "Style",
2686
+ className: "mly-capitalize"
2687
+ }
2688
+ )
2689
+ ] }),
2690
+ /* @__PURE__ */ jsx25(Divider, {}),
2691
+ /* @__PURE__ */ jsxs12("div", { className: "mly-flex mly-space-x-0.5", children: [
2692
+ /* @__PURE__ */ jsx25(
2693
+ AlignmentSwitch,
2694
+ {
2695
+ alignment,
2696
+ onAlignmentChange: (alignment2) => {
2697
+ updateAttributes2({
2698
+ alignment: alignment2
2699
+ });
2700
+ }
2701
+ }
2702
+ ),
2703
+ /* @__PURE__ */ jsx25(
2704
+ LinkInputPopover,
2705
+ {
2706
+ defaultValue: externalLink || "",
2707
+ onValueChange: (value, isVariable) => {
2708
+ updateAttributes2({
2709
+ url: value,
2710
+ isUrlVariable: isVariable != null ? isVariable : false
2711
+ });
2712
+ },
2713
+ tooltip: "Update External Link",
2714
+ editor,
2715
+ isVariable: isUrlVariable
2716
+ }
2717
+ )
2718
+ ] }),
2719
+ /* @__PURE__ */ jsx25(Divider, {}),
2720
+ /* @__PURE__ */ jsxs12("div", { className: "mly-flex mly-space-x-0.5", children: [
2721
+ /* @__PURE__ */ jsx25(
2722
+ BackgroundColorPickerPopup,
2723
+ {
2724
+ variant,
2725
+ color: buttonColor,
2726
+ onChange: (color) => {
2727
+ updateAttributes2({
2728
+ buttonColor: color
2729
+ });
2730
+ }
2731
+ }
2732
+ ),
2733
+ /* @__PURE__ */ jsx25(
2734
+ TextColorPickerPopup,
2735
+ {
2736
+ color: textColor,
2737
+ onChange: (color) => {
2738
+ updateAttributes2({
2739
+ textColor: color
2740
+ });
2741
+ }
2742
+ }
2743
+ )
2744
+ ] }),
2745
+ /* @__PURE__ */ jsx25(Divider, {}),
2746
+ /* @__PURE__ */ jsx25(
2747
+ ShowPopover,
2748
+ {
2749
+ showIfKey,
2750
+ onShowIfKeyValueChange: (value) => {
2751
+ updateAttributes2({
2752
+ showIfKey: value
2753
+ });
2754
+ },
2755
+ editor
2756
+ }
2757
+ )
2758
+ ] }) })
2759
+ }
2760
+ )
2761
+ ] })
2762
+ }
2763
+ );
2764
+ }
2765
+ function BackgroundColorPickerPopup(props) {
2766
+ const { color, onChange, variant } = props;
2767
+ return /* @__PURE__ */ jsx25(
2768
+ ColorPicker,
2769
+ {
2770
+ color,
2771
+ onColorChange: onChange,
2772
+ tooltip: "Background Color",
2773
+ children: /* @__PURE__ */ jsx25(
2774
+ BaseButton,
2775
+ {
2776
+ variant: "ghost",
2777
+ size: "sm",
2778
+ type: "button",
2779
+ className: "mly-size-7",
2780
+ children: /* @__PURE__ */ jsx25(
2781
+ "div",
2782
+ {
2783
+ className: "mly-h-4 mly-w-4 mly-shrink-0 mly-rounded-full mly-shadow",
2784
+ style: {
2785
+ backgroundColor: variant === "filled" ? color : "transparent",
2786
+ borderStyle: "solid",
2787
+ borderWidth: 2,
2788
+ borderColor: variant === "filled" ? "white" : color
2789
+ }
2790
+ }
2791
+ )
2792
+ }
2793
+ )
2794
+ }
2795
+ );
2796
+ }
2797
+ function TextColorPickerPopup(props) {
2798
+ const { color, onChange } = props;
2799
+ return /* @__PURE__ */ jsx25(ColorPicker, { color, onColorChange: onChange, tooltip: "Text Color", children: /* @__PURE__ */ jsx25(
2800
+ BaseButton,
2801
+ {
2802
+ variant: "ghost",
2803
+ size: "sm",
2804
+ type: "button",
2805
+ className: "mly-size-7",
2806
+ children: /* @__PURE__ */ jsxs12("div", { className: "mly-flex mly-flex-col mly-items-center mly-justify-center mly-gap-[1px]", children: [
2807
+ /* @__PURE__ */ jsx25("span", { className: "mly-font-bolder mly-font-mono mly-text-xs mly-text-midnight-gray", children: "A" }),
2808
+ /* @__PURE__ */ jsx25(
2809
+ "div",
2810
+ {
2811
+ className: "mly-h-[2px] mly-w-3 mly-shrink-0 mly-rounded-md mly-shadow",
2812
+ style: { backgroundColor: color }
2813
+ }
2814
+ )
2815
+ ] })
2816
+ }
2817
+ ) });
2818
+ }
2819
+
2820
+ // src/editor/nodes/button/button.tsx
2821
+ var DEFAULT_BUTTON_ALIGNMENT = "left";
2822
+ var DEFAULT_BUTTON_VARIANT = "filled";
2823
+ var DEFAULT_BUTTON_BORDER_RADIUS = "smooth";
2824
+ var DEFAULT_BUTTON_BACKGROUND_COLOR = "#000000";
2825
+ var DEFAULT_BUTTON_TEXT_COLOR = "#ffffff";
2826
+ var allowedButtonVariant = ["filled", "outline"];
2827
+ var allowedButtonBorderRadius = ["sharp", "smooth", "round"];
2828
+ var ButtonExtension = Node9.create({
2829
+ name: "button",
2830
+ group: "block",
2831
+ atom: true,
2832
+ draggable: true,
2833
+ addAttributes() {
2834
+ return {
2835
+ text: {
2836
+ default: "Button",
2837
+ parseHTML: (element) => {
2838
+ return element.getAttribute("data-text") || "";
2839
+ },
2840
+ renderHTML: (attributes) => {
2841
+ return {
2842
+ "data-text": attributes.text
2843
+ };
2844
+ }
2845
+ },
2846
+ isTextVariable: {
2847
+ default: false,
2848
+ parseHTML: (element) => {
2849
+ return element.getAttribute("data-is-text-variable") === "true";
2850
+ },
2851
+ renderHTML: (attributes) => {
2852
+ if (!attributes.isTextVariable) {
2853
+ return {};
2854
+ }
2855
+ return {
2856
+ "data-is-text-variable": "true"
2857
+ };
2858
+ }
2859
+ },
2860
+ url: {
2861
+ default: "",
2862
+ parseHTML: (element) => {
2863
+ return element.getAttribute("data-url") || "";
2864
+ },
2865
+ renderHTML: (attributes) => {
2866
+ return {
2867
+ "data-url": attributes.url
2868
+ };
2869
+ }
2870
+ },
2871
+ // Later we will remove this attribute
2872
+ // and use the `url` attribute instead when implement
2873
+ // the URL variable feature
2874
+ isUrlVariable: {
2875
+ default: false,
2876
+ parseHTML: (element) => {
2877
+ return element.getAttribute("data-is-url-variable") === "true";
2878
+ },
2879
+ renderHTML: (attributes) => {
2880
+ if (!attributes.isUrlVariable) {
2881
+ return {};
2882
+ }
2883
+ return {
2884
+ "data-is-url-variable": "true"
2885
+ };
2886
+ }
2887
+ },
2888
+ alignment: {
2889
+ default: DEFAULT_BUTTON_ALIGNMENT,
2890
+ parseHTML: (element) => {
2891
+ return element.getAttribute("data-alignment") || DEFAULT_BUTTON_ALIGNMENT;
2892
+ },
2893
+ renderHTML: (attributes) => {
2894
+ return {
2895
+ "data-alignment": attributes.alignment
2896
+ };
2897
+ }
2898
+ },
2899
+ variant: {
2900
+ default: DEFAULT_BUTTON_VARIANT,
2901
+ parseHTML: (element) => {
2902
+ return element.getAttribute("data-variant") || DEFAULT_BUTTON_VARIANT;
2903
+ },
2904
+ renderHTML: (attributes) => {
2905
+ return {
2906
+ "data-variant": attributes.variant
2907
+ };
2908
+ }
2909
+ },
2910
+ borderRadius: {
2911
+ default: DEFAULT_BUTTON_BORDER_RADIUS,
2912
+ parseHTML: (element) => {
2913
+ return element.getAttribute("data-border-radius") || DEFAULT_BUTTON_BORDER_RADIUS;
2914
+ },
2915
+ renderHTML: (attributes) => {
2916
+ return {
2917
+ "data-border-radius": attributes.borderRadius
2918
+ };
2919
+ }
2920
+ },
2921
+ buttonColor: {
2922
+ default: DEFAULT_BUTTON_BACKGROUND_COLOR,
2923
+ parseHTML: (element) => {
2924
+ return element.getAttribute("data-button-color") || DEFAULT_BUTTON_BACKGROUND_COLOR;
2925
+ },
2926
+ renderHTML: (attributes) => {
2927
+ return {
2928
+ "data-button-color": attributes.buttonColor
2929
+ };
2930
+ }
2931
+ },
2932
+ textColor: {
2933
+ default: DEFAULT_BUTTON_TEXT_COLOR,
2934
+ parseHTML: (element) => {
2935
+ return element.getAttribute("data-text-color") || DEFAULT_BUTTON_TEXT_COLOR;
2936
+ },
2937
+ renderHTML: (attributes) => {
2938
+ return {
2939
+ "data-text-color": attributes.textColor
2940
+ };
2941
+ }
2942
+ },
2943
+ showIfKey: {
2944
+ default: DEFAULT_SECTION_SHOW_IF_KEY,
2945
+ parseHTML: (element) => {
2946
+ return element.getAttribute("data-show-if-key") || DEFAULT_SECTION_SHOW_IF_KEY;
2947
+ },
2948
+ renderHTML(attributes) {
2949
+ if (!attributes.showIfKey) {
2950
+ return {};
2951
+ }
2952
+ return {
2953
+ "data-show-if-key": attributes.showIfKey
2954
+ };
2955
+ }
2956
+ }
2957
+ };
2958
+ },
2959
+ parseHTML() {
2960
+ return [
2961
+ {
2962
+ tag: `div[data-type="${this.name}"]`
2963
+ }
2964
+ ];
2965
+ },
2966
+ renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
2967
+ return [
2968
+ "div",
2969
+ mergeAttributes8(HTMLAttributes2, {
2970
+ "data-type": this.name
2971
+ })
2972
+ ];
2973
+ },
2974
+ addCommands() {
2975
+ return {
2976
+ setButton: () => ({ commands }) => {
2977
+ return commands.insertContent({
2978
+ type: this.name,
2979
+ attrs: {},
2980
+ content: []
2981
+ });
2982
+ },
2983
+ updateButton: (attrs) => updateAttributes(this.name, attrs)
2984
+ };
2985
+ },
2986
+ addNodeView() {
2987
+ return ReactNodeViewRenderer3(ButtonView, {
2988
+ contentDOMElementTag: "div",
2989
+ className: "mly-relative"
2990
+ });
2991
+ }
2992
+ });
2993
+
2994
+ // src/editor/nodes/logo/logo.ts
2995
+ import TiptapImage from "@tiptap/extension-image";
2996
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer4 } from "@tiptap/react";
2997
+
2998
+ // src/editor/nodes/logo/logo-view.tsx
2999
+ import { NodeViewWrapper as NodeViewWrapper6 } from "@tiptap/react";
3000
+ import { useEffect as useEffect4 } from "react";
3001
+ import { useState as useState7 } from "react";
3002
+
3003
+ // src/editor/utils/use-event.ts
3004
+ import { useCallback as useCallback2, useLayoutEffect, useRef as useRef6 } from "react";
3005
+ var useEvent = (handler) => {
3006
+ const handlerRef = useRef6(null);
3007
+ useLayoutEffect(() => {
3008
+ handlerRef.current = handler;
3009
+ }, [handler]);
3010
+ return useCallback2((...args) => {
3011
+ if (handlerRef.current === null) {
3012
+ throw new Error("Handler is not assigned");
3013
+ }
3014
+ return handlerRef.current(...args);
3015
+ }, []);
3016
+ };
3017
+
3018
+ // src/editor/nodes/image/image-view.tsx
3019
+ import { NodeViewWrapper as NodeViewWrapper5 } from "@tiptap/react";
3020
+ import { Ban, BracesIcon as BracesIcon2, ImageOffIcon, Loader2 } from "lucide-react";
3021
+ import { useEffect as useEffect3, useRef as useRef7, useState as useState6 } from "react";
3022
+ import { Fragment as Fragment3, jsx as jsx26, jsxs as jsxs13 } from "react/jsx-runtime";
3023
+ var MIN_WIDTH = 20;
3024
+ var MAX_WIDTH = 600;
3025
+ function ImageView(props) {
3026
+ const { node, updateAttributes: updateAttributes2, selected } = props;
3027
+ const [status, setStatus] = useState6("idle");
3028
+ const wrapperRef = useRef7(null);
3029
+ const imgRef = useRef7(null);
3030
+ const [resizingStyle, setResizingStyle] = useState6();
3031
+ const handleMouseDown = useEvent(
3032
+ (event) => {
3033
+ const imageParent = document.querySelector(
3034
+ ".ProseMirror-selectednode"
3035
+ );
3036
+ if (!imgRef.current || !imageParent || !selected) {
3037
+ return;
3038
+ }
3039
+ const imageParentWidth = Math.max(imageParent.offsetWidth, MAX_WIDTH);
3040
+ event.preventDefault();
3041
+ const direction = event.currentTarget.dataset.direction || "--";
3042
+ const initialXPosition = event.clientX;
3043
+ const currentWidth = imgRef.current.width;
3044
+ const currentHeight = imgRef.current.height;
3045
+ let newWidth = currentWidth;
3046
+ let newHeight = currentHeight;
3047
+ const transform = direction[1] === "w" ? -1 : 1;
3048
+ const removeListeners = () => {
3049
+ window.removeEventListener("mousemove", mouseMoveHandler);
3050
+ window.removeEventListener("mouseup", removeListeners);
3051
+ updateAttributes2({ width: newWidth, height: newHeight });
3052
+ setResizingStyle(void 0);
3053
+ };
3054
+ const mouseMoveHandler = (event2) => {
3055
+ newWidth = Math.max(
3056
+ currentWidth + transform * (event2.clientX - initialXPosition),
3057
+ MIN_WIDTH
3058
+ );
3059
+ if (newWidth > imageParentWidth) {
3060
+ newWidth = imageParentWidth;
3061
+ }
3062
+ newHeight = newWidth / currentWidth * currentHeight;
3063
+ setResizingStyle({ width: newWidth, height: newHeight });
3064
+ if (!event2.buttons) {
3065
+ return removeListeners();
3066
+ }
3067
+ };
3068
+ window.addEventListener("mousemove", mouseMoveHandler);
3069
+ window.addEventListener("mouseup", removeListeners);
3070
+ }
3071
+ );
3072
+ function dragCornerButton(direction) {
3073
+ return /* @__PURE__ */ jsx26(
3074
+ "div",
3075
+ {
3076
+ role: "button",
3077
+ tabIndex: 0,
3078
+ onMouseDown: handleMouseDown,
3079
+ "data-direction": direction,
3080
+ className: "mly-bg-rose-500",
3081
+ style: __spreadProps(__spreadValues(__spreadValues({
3082
+ position: "absolute",
3083
+ height: "10px",
3084
+ width: "10px"
3085
+ }, { n: { top: 0 }, s: { bottom: 0 } }[direction[0]]), { w: { left: 0 }, e: { right: 0 } }[direction[1]]), {
3086
+ cursor: `${direction}-resize`
3087
+ })
3088
+ }
3089
+ );
3090
+ }
3091
+ let { alignment = "center", width, height, src } = node.attrs || {};
3092
+ const _a = node.attrs || {}, {
3093
+ externalLink,
3094
+ isExternalLinkVariable,
3095
+ isSrcVariable,
3096
+ showIfKey
3097
+ } = _a, attrs = __objRest(_a, [
3098
+ "externalLink",
3099
+ "isExternalLinkVariable",
3100
+ "isSrcVariable",
3101
+ "showIfKey"
3102
+ ]);
3103
+ const hasImageSrc = !!attrs.src;
3104
+ useEffect3(() => {
3105
+ if (!src) {
3106
+ return;
3107
+ }
3108
+ setStatus("loading");
3109
+ const img = new Image();
3110
+ img.src = src;
3111
+ img.onload = () => {
3112
+ setStatus("loaded");
3113
+ const { naturalWidth, naturalHeight } = img;
3114
+ const wrapper = wrapperRef == null ? void 0 : wrapperRef.current;
3115
+ if (!wrapper || width !== "auto" || !naturalWidth) {
3116
+ return;
3117
+ }
3118
+ const wrapperWidth = wrapper.offsetWidth;
3119
+ const aspectRatio = naturalWidth / naturalHeight;
3120
+ const calculatedHeight = Math.min(
3121
+ wrapperWidth / aspectRatio,
3122
+ naturalHeight
3123
+ );
3124
+ updateAttributes2({
3125
+ width: Math.min(wrapperWidth, naturalWidth),
3126
+ height: Math.min(calculatedHeight, naturalHeight)
3127
+ });
3128
+ };
3129
+ img.onerror = () => {
3130
+ setStatus("error");
3131
+ };
3132
+ return () => {
3133
+ img.src = "";
3134
+ img.onload = null;
3135
+ img.onerror = null;
3136
+ };
3137
+ }, [src]);
3138
+ return /* @__PURE__ */ jsxs13(
3139
+ NodeViewWrapper5,
3140
+ {
3141
+ as: "div",
3142
+ draggable: true,
3143
+ "data-drag-handle": true,
3144
+ style: __spreadValues(__spreadProps(__spreadValues({}, hasImageSrc && status === "loaded" ? __spreadValues({
3145
+ width: `${width}px`,
3146
+ height: `${height}px`
3147
+ }, resizingStyle) : {}), {
3148
+ overflow: "hidden",
3149
+ position: "relative",
3150
+ // Weird! Basically tiptap/prose wraps this in a span and the line height causes an annoying buffer.
3151
+ lineHeight: "0px",
3152
+ display: "block"
3153
+ }), {
3154
+ center: { marginLeft: "auto", marginRight: "auto" },
3155
+ left: { marginRight: "auto" },
3156
+ right: { marginLeft: "auto" }
3157
+ }[alignment] || {}),
3158
+ ref: wrapperRef,
3159
+ children: [
3160
+ !hasImageSrc && /* @__PURE__ */ jsx26(ImageStatusLabel, { status: "idle" }),
3161
+ hasImageSrc && isSrcVariable && /* @__PURE__ */ jsx26(ImageStatusLabel, { status: "variable" }),
3162
+ hasImageSrc && status === "loading" && !isSrcVariable && /* @__PURE__ */ jsx26(ImageStatusLabel, { status: "loading" }),
3163
+ hasImageSrc && status === "error" && !isSrcVariable && /* @__PURE__ */ jsx26(ImageStatusLabel, { status: "error" }),
3164
+ hasImageSrc && status === "loaded" && !isSrcVariable && /* @__PURE__ */ jsxs13(Fragment3, { children: [
3165
+ /* @__PURE__ */ jsx26(
3166
+ "img",
3167
+ __spreadProps(__spreadValues({}, attrs), {
3168
+ ref: imgRef,
3169
+ style: __spreadProps(__spreadValues({}, resizingStyle), {
3170
+ cursor: "default",
3171
+ marginBottom: 0
3172
+ })
3173
+ })
3174
+ ),
3175
+ selected && /* @__PURE__ */ jsxs13(Fragment3, { children: [
3176
+ [
3177
+ { left: 0, top: 0, height: "100%", width: "1px" },
3178
+ { right: 0, top: 0, height: "100%", width: "1px" },
3179
+ { top: 0, left: 0, width: "100%", height: "1px" },
3180
+ { bottom: 0, left: 0, width: "100%", height: "1px" }
3181
+ ].map((style, i) => /* @__PURE__ */ jsx26(
3182
+ "div",
3183
+ {
3184
+ className: "mly-bg-rose-500",
3185
+ style: __spreadValues({
3186
+ position: "absolute"
3187
+ }, style)
3188
+ },
3189
+ i
3190
+ )),
3191
+ dragCornerButton("nw"),
3192
+ dragCornerButton("ne"),
3193
+ dragCornerButton("sw"),
3194
+ dragCornerButton("se")
3195
+ ] })
3196
+ ] })
3197
+ ]
3198
+ }
3199
+ );
3200
+ }
3201
+ function ImageStatusLabel(props) {
3202
+ const { status } = props;
3203
+ return /* @__PURE__ */ jsxs13(
3204
+ "div",
3205
+ {
3206
+ className: cn(
3207
+ "mly-flex mly-items-center mly-gap-2 mly-rounded-lg mly-bg-soft-gray mly-p-4 mly-text-sm mly-font-medium",
3208
+ {
3209
+ "mly-text-gray-500 hover:mly-bg-soft-gray/60": status === "loading",
3210
+ "mly-text-red-500 hover:mly-bg-soft-gray/60": status === "error"
3211
+ }
3212
+ ),
3213
+ children: [
3214
+ status === "idle" && /* @__PURE__ */ jsxs13(Fragment3, { children: [
3215
+ /* @__PURE__ */ jsx26(ImageOffIcon, { className: "mly-size-4 mly-stroke-[2.5]" }),
3216
+ /* @__PURE__ */ jsx26("span", { children: "No image selected" })
3217
+ ] }),
3218
+ status === "loading" && /* @__PURE__ */ jsxs13(Fragment3, { children: [
3219
+ /* @__PURE__ */ jsx26(Loader2, { className: "mly-size-4 mly-animate-spin mly-stroke-[2.5]" }),
3220
+ /* @__PURE__ */ jsx26("span", { children: "Loading image..." })
3221
+ ] }),
3222
+ status === "error" && /* @__PURE__ */ jsxs13(Fragment3, { children: [
3223
+ /* @__PURE__ */ jsx26(Ban, { className: "mly-size-4 mly-stroke-[2.5]" }),
3224
+ /* @__PURE__ */ jsx26("span", { children: "Error loading image" })
3225
+ ] }),
3226
+ status === "variable" && /* @__PURE__ */ jsxs13(Fragment3, { children: [
3227
+ /* @__PURE__ */ jsx26(BracesIcon2, { className: "mly-size-4 mly-stroke-[2.5]" }),
3228
+ /* @__PURE__ */ jsx26("span", { children: "Variable Image URL" })
3229
+ ] })
3230
+ ]
3231
+ }
3232
+ );
3233
+ }
3234
+
3235
+ // src/editor/nodes/logo/logo-view.tsx
3236
+ import { jsx as jsx27, jsxs as jsxs14 } from "react/jsx-runtime";
3237
+ function LogoView(props) {
3238
+ const { node } = props;
3239
+ const [status, setStatus] = useState7("idle");
3240
+ let {
3241
+ alignment = "center",
3242
+ src: logoSrc,
3243
+ isSrcVariable,
3244
+ size = "sm"
3245
+ } = node.attrs || {};
3246
+ const hasImageSrc = !!logoSrc;
3247
+ useEffect4(() => {
3248
+ if (!logoSrc) {
3249
+ return;
3250
+ }
3251
+ setStatus("loading");
3252
+ const img = new Image();
3253
+ img.src = logoSrc;
3254
+ img.onload = () => {
3255
+ setStatus("loaded");
3256
+ };
3257
+ img.onerror = () => {
3258
+ setStatus("error");
3259
+ };
3260
+ return () => {
3261
+ img.src = "";
3262
+ img.onload = null;
3263
+ img.onerror = null;
3264
+ };
3265
+ }, [logoSrc]);
3266
+ const logoSize = logoSizes[size];
3267
+ return /* @__PURE__ */ jsxs14(
3268
+ NodeViewWrapper6,
3269
+ {
3270
+ as: "div",
3271
+ draggable: true,
3272
+ "data-drag-handle": true,
3273
+ style: {
3274
+ overflow: "hidden",
3275
+ position: "relative",
3276
+ // Weird! Basically tiptap/prose wraps this in a span and the line height causes an annoying buffer.
3277
+ lineHeight: "0px",
3278
+ display: "block"
3279
+ },
3280
+ children: [
3281
+ !hasImageSrc && /* @__PURE__ */ jsx27(ImageStatusLabel, { status: "idle" }),
3282
+ hasImageSrc && isSrcVariable && /* @__PURE__ */ jsx27(ImageStatusLabel, { status: "variable" }),
3283
+ hasImageSrc && status === "loading" && !isSrcVariable && /* @__PURE__ */ jsx27(ImageStatusLabel, { status: "loading" }),
3284
+ hasImageSrc && status === "error" && !isSrcVariable && /* @__PURE__ */ jsx27(ImageStatusLabel, { status: "error" }),
3285
+ hasImageSrc && status === "loaded" && !isSrcVariable && /* @__PURE__ */ jsx27(
3286
+ "img",
3287
+ {
3288
+ src: logoSrc,
3289
+ alt: "Logo",
3290
+ style: __spreadValues({
3291
+ height: logoSize,
3292
+ width: logoSize,
3293
+ cursor: "default",
3294
+ marginBottom: 0
3295
+ }, {
3296
+ center: { marginLeft: "auto", marginRight: "auto" },
3297
+ left: { marginRight: "auto" },
3298
+ right: { marginLeft: "auto" }
3299
+ }[alignment] || {})
3300
+ }
3301
+ )
3302
+ ]
3303
+ }
3304
+ );
3305
+ }
3306
+
3307
+ // src/editor/nodes/logo/logo.ts
3308
+ var allowedLogoSize = ["sm", "md", "lg"];
3309
+ var allowedLogoAlignment = ["left", "center", "right"];
3310
+ var DEFAULT_ALIGNMENT = "left";
3311
+ var DEFAULT_LOGO_SIZE = "sm";
3312
+ var logoSizes = {
3313
+ sm: "40px",
3314
+ md: "48px",
3315
+ lg: "64px"
3316
+ };
3317
+ var LogoExtension = TiptapImage.extend({
3318
+ name: "logo",
3319
+ priority: 1e3,
3320
+ addAttributes() {
3321
+ var _a;
3322
+ return __spreadProps(__spreadValues({}, (_a = this.parent) == null ? void 0 : _a.call(this)), {
3323
+ "maily-component": {
3324
+ default: "logo",
3325
+ renderHTML: (attributes) => {
3326
+ return {
3327
+ "data-maily-component": attributes["maily-component"]
3328
+ };
3329
+ },
3330
+ parseHTML: (element) => element.getAttribute("data-maily-component")
3331
+ },
3332
+ size: {
3333
+ default: DEFAULT_LOGO_SIZE,
3334
+ parseHTML: (element) => element.getAttribute("data-size"),
3335
+ renderHTML: (attributes) => {
3336
+ return {
3337
+ "data-size": attributes.size
3338
+ };
3339
+ }
3340
+ },
3341
+ alignment: {
3342
+ default: DEFAULT_ALIGNMENT,
3343
+ parseHTML: (element) => element.getAttribute("data-alignment"),
3344
+ renderHTML: (attributes) => {
3345
+ return {
3346
+ "data-alignment": attributes.alignment
3347
+ };
3348
+ }
3349
+ },
3350
+ showIfKey: {
3351
+ default: DEFAULT_SECTION_SHOW_IF_KEY,
3352
+ parseHTML: (element) => {
3353
+ return element.getAttribute("data-show-if-key") || DEFAULT_SECTION_SHOW_IF_KEY;
3354
+ },
3355
+ renderHTML(attributes) {
3356
+ if (!attributes.showIfKey) {
3357
+ return {};
3358
+ }
3359
+ return {
3360
+ "data-show-if-key": attributes.showIfKey
3361
+ };
3362
+ }
3363
+ },
3364
+ // Later we will remove this attribute
3365
+ // and use the `src` attribute instead when implement
3366
+ // the URL variable feature
3367
+ isSrcVariable: {
3368
+ default: false,
3369
+ parseHTML: (element) => {
3370
+ return element.getAttribute("data-is-src-variable") === "true";
3371
+ },
3372
+ renderHTML: (attributes) => {
3373
+ if (!attributes.isSrcVariable) {
3374
+ return {};
3375
+ }
3376
+ return {
3377
+ "data-is-src-variable": "true"
3378
+ };
3379
+ }
3380
+ }
3381
+ });
3382
+ },
3383
+ addCommands() {
3384
+ return {
3385
+ setLogoImage: (options) => ({ commands }) => {
3386
+ return commands.insertContent({
3387
+ type: this.name,
3388
+ attrs: options
3389
+ });
3390
+ },
3391
+ setLogoAttributes: (attributes) => ({ commands }) => {
3392
+ return commands.updateAttributes("logo", attributes);
3393
+ }
3394
+ };
3395
+ },
3396
+ parseHTML() {
3397
+ return [
3398
+ {
3399
+ tag: `img[data-maily-component="${this.name}"]`
3400
+ }
3401
+ ];
3402
+ },
3403
+ addNodeView() {
3404
+ return ReactNodeViewRenderer4(LogoView, {
3405
+ className: "mly-relative"
3406
+ });
3407
+ }
3408
+ });
3409
+
3410
+ // src/editor/nodes/image/image.ts
3411
+ import TiptapImage2 from "@tiptap/extension-image";
3412
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer5 } from "@tiptap/react";
3413
+ var ImageExtension = TiptapImage2.extend({
3414
+ addAttributes() {
3415
+ var _a;
3416
+ return __spreadProps(__spreadValues({}, (_a = this.parent) == null ? void 0 : _a.call(this)), {
3417
+ width: {
3418
+ default: "auto",
3419
+ parseHTML: (element) => {
3420
+ const width = element.style.width;
3421
+ return width ? { width } : null;
3422
+ },
3423
+ renderHTML: ({ width }) => ({ style: `width: ${width}` })
3424
+ },
3425
+ height: {
3426
+ default: "auto",
3427
+ parseHTML: (element) => {
3428
+ const height = element.style.height;
3429
+ return height ? { height } : null;
3430
+ },
3431
+ renderHTML: ({ height }) => ({ style: `height: ${height}` })
3432
+ },
3433
+ alignment: {
3434
+ default: "center",
3435
+ renderHTML: ({ alignment }) => ({ "data-alignment": alignment }),
3436
+ parseHTML: (element) => element.getAttribute("data-alignment") || "center"
3437
+ },
3438
+ externalLink: {
3439
+ default: null,
3440
+ renderHTML: ({ externalLink }) => {
3441
+ if (!externalLink) {
3442
+ return {};
3443
+ }
3444
+ return {
3445
+ "data-external-link": externalLink
3446
+ };
3447
+ },
3448
+ parseHTML: (element) => {
3449
+ const externalLink = element.getAttribute("data-external-link");
3450
+ return externalLink ? { externalLink } : null;
3451
+ }
3452
+ },
3453
+ // Later we will remove this attribute
3454
+ // and use the `externalLink` attribute instead
3455
+ // when implement the URL variable feature
3456
+ isExternalLinkVariable: {
3457
+ default: false,
3458
+ parseHTML: (element) => {
3459
+ return element.getAttribute("data-is-external-link-variable") === "true";
3460
+ },
3461
+ renderHTML: (attributes) => {
3462
+ if (!attributes.isExternalLinkVariable) {
3463
+ return {};
3464
+ }
3465
+ return {
3466
+ "data-is-external-link-variable": "true"
3467
+ };
3468
+ }
3469
+ },
3470
+ // Later we will remove this attribute
3471
+ // and use the `src` attribute instead when implement
3472
+ // the URL variable feature
3473
+ isSrcVariable: {
3474
+ default: false,
3475
+ parseHTML: (element) => {
3476
+ return element.getAttribute("data-is-src-variable") === "true";
3477
+ },
3478
+ renderHTML: (attributes) => {
3479
+ if (!attributes.isSrcVariable) {
3480
+ return {};
3481
+ }
3482
+ return {
3483
+ "data-is-src-variable": "true"
3484
+ };
3485
+ }
3486
+ },
3487
+ showIfKey: {
3488
+ default: DEFAULT_SECTION_SHOW_IF_KEY,
3489
+ parseHTML: (element) => {
3490
+ return element.getAttribute("data-show-if-key") || DEFAULT_SECTION_SHOW_IF_KEY;
3491
+ },
3492
+ renderHTML(attributes) {
3493
+ if (!attributes.showIfKey) {
3494
+ return {};
3495
+ }
3496
+ return {
3497
+ "data-show-if-key": attributes.showIfKey
3498
+ };
3499
+ }
3500
+ }
3501
+ });
3502
+ },
3503
+ addNodeView() {
3504
+ return ReactNodeViewRenderer5(ImageView, {
3505
+ className: "mly-relative"
3506
+ });
3507
+ }
3508
+ });
3509
+
3510
+ // src/editor/nodes/link.ts
3511
+ import TiptapLink from "@tiptap/extension-link";
3512
+ var LinkExtension = TiptapLink.extend({
3513
+ addAttributes() {
3514
+ var _a;
3515
+ return __spreadProps(__spreadValues({}, (_a = this.parent) == null ? void 0 : _a.call(this)), {
3516
+ isUrlVariable: {
3517
+ default: false
3518
+ }
3519
+ });
3520
+ },
3521
+ addCommands() {
3522
+ var _a;
3523
+ return __spreadProps(__spreadValues({}, (_a = this.parent) == null ? void 0 : _a.call(this)), {
3524
+ setIsUrlVariable: (isUrlVariable) => ({ chain }) => {
3525
+ return chain().setMark("link", { isUrlVariable }).run();
3526
+ }
3527
+ });
3528
+ }
3529
+ });
3530
+
3531
+ // src/editor/extensions/maily-kit.tsx
3532
+ var MailyKit = Extension.create({
3533
+ name: "maily-kit",
3534
+ addOptions() {
3535
+ return {
3536
+ link: {
3537
+ HTMLAttributes: {
3538
+ target: "_blank",
3539
+ rel: "noopener noreferrer nofollow",
3540
+ class: "mly-no-underline"
3541
+ },
3542
+ openOnClick: false
3543
+ }
3544
+ };
3545
+ },
3546
+ addExtensions() {
3547
+ const extensions = [
3548
+ Document.extend({
3549
+ content: "(block|columns)+"
3550
+ }),
3551
+ StarterKit.configure({
3552
+ heading: {
3553
+ levels: [1, 2, 3],
3554
+ HTMLAttributes: {
3555
+ class: "mly-relative"
3556
+ }
3557
+ },
3558
+ code: {
3559
+ HTMLAttributes: {
3560
+ class: "mly-px-1 mly-relative mly-py-0.5 mly-bg-[#efefef] mly-text-sm mly-rounded-md mly-tracking-normal mly-font-normal"
3561
+ }
3562
+ },
3563
+ blockquote: {
3564
+ HTMLAttributes: {
3565
+ class: "mly-not-prose mly-border-l-4 mly-border-gray-300 mly-pl-4 mly-mt-4 mly-mb-4 mly-relative"
3566
+ }
3567
+ },
3568
+ paragraph: {
3569
+ HTMLAttributes: {
3570
+ class: "mly-relative"
3571
+ }
3572
+ },
3573
+ bulletList: {
3574
+ HTMLAttributes: {
3575
+ class: "mly-relative"
3576
+ }
3577
+ },
3578
+ orderedList: {
3579
+ HTMLAttributes: {
3580
+ class: "mly-relative"
3581
+ }
3582
+ },
3583
+ horizontalRule: false,
3584
+ dropcursor: false,
3585
+ document: false
3586
+ }),
3587
+ Underline,
3588
+ Color.configure({ types: [TextStyle.name, ListItem.name] }),
3589
+ TextStyle.configure(),
3590
+ TextAlign.configure({
3591
+ types: [Paragraph.name, Heading.name, Footer.name]
3592
+ }),
3593
+ HorizontalRule,
3594
+ Placeholder.configure({
3595
+ placeholder: ({ node }) => {
3596
+ if (node.type.name === "heading") {
3597
+ return `Heading ${node.attrs.level}`;
3598
+ } else if ([
3599
+ "columns",
3600
+ "column",
3601
+ "section",
3602
+ "for",
3603
+ "show",
3604
+ "blockquote"
3605
+ ].includes(node.type.name)) {
3606
+ return "";
3607
+ }
3608
+ return "Write something or / to see commands";
3609
+ },
3610
+ includeChildren: true
3611
+ }),
3612
+ Footer,
3613
+ Focus,
3614
+ Dropcursor.configure({
3615
+ color: "#555",
3616
+ width: 3,
3617
+ class: "ProseMirror-dropcursor"
3618
+ })
3619
+ ];
3620
+ if (this.options.linkCard !== false) {
3621
+ extensions.push(LinkCardExtension.configure(this.options.linkCard));
3622
+ }
3623
+ if (this.options.for !== false) {
3624
+ extensions.push(ForExtension);
3625
+ }
3626
+ if (this.options.section !== false) {
3627
+ extensions.push(SectionExtension);
3628
+ }
3629
+ if (this.options.columns !== false) {
3630
+ extensions.push(ColumnsExtension);
3631
+ }
3632
+ if (this.options.column !== false) {
3633
+ extensions.push(ColumnExtension);
3634
+ }
3635
+ if (this.options.button !== false) {
3636
+ extensions.push(ButtonExtension);
3637
+ }
3638
+ if (this.options.spacer !== false) {
3639
+ extensions.push(Spacer);
3640
+ }
3641
+ if (this.options.logo !== false) {
3642
+ extensions.push(LogoExtension);
3643
+ }
3644
+ if (this.options.image !== false) {
3645
+ extensions.push(ImageExtension);
3646
+ }
3647
+ if (this.options.link !== false) {
3648
+ extensions.push(LinkExtension.configure(this.options.link));
3649
+ }
3650
+ return extensions;
3651
+ }
3652
+ });
3653
+
3654
+ // src/editor/extensions/slash-command/slash-command.ts
3655
+ import { Extension as Extension2 } from "@tiptap/core";
3656
+ import Suggestion from "@tiptap/suggestion";
3657
+ var SlashCommandExtension = Extension2.create({
3658
+ name: "slash-command",
3659
+ addOptions() {
3660
+ return {
3661
+ suggestion: {
3662
+ char: "/",
3663
+ command: ({ editor, range, props }) => {
3664
+ props.command({ editor, range });
3665
+ }
3666
+ }
3667
+ };
3668
+ },
3669
+ addProseMirrorPlugins() {
3670
+ return [
3671
+ Suggestion(__spreadValues({
3672
+ editor: this.editor
3673
+ }, this.options.suggestion))
3674
+ ];
3675
+ }
3676
+ });
3677
+
3678
+ // src/editor/utils/update-scroll-view.ts
3679
+ var updateScrollView = (container, item) => {
3680
+ const containerHeight = container.offsetHeight;
3681
+ const itemHeight = item ? item.offsetHeight : 0;
3682
+ const top = item.offsetTop;
3683
+ const bottom = top + itemHeight;
3684
+ if (top < container.scrollTop) {
3685
+ container.scrollTop -= container.scrollTop - top + 5;
3686
+ } else if (bottom > containerHeight + container.scrollTop) {
3687
+ container.scrollTop += bottom - containerHeight - container.scrollTop + 5;
3688
+ }
3689
+ };
3690
+
3691
+ // src/editor/extensions/slash-command/slash-command-view.tsx
3692
+ import { ReactRenderer } from "@tiptap/react";
3693
+ import {
3694
+ useCallback as useCallback3,
3695
+ useEffect as useEffect5,
3696
+ useLayoutEffect as useLayoutEffect2,
3697
+ useRef as useRef8,
3698
+ useState as useState8
3699
+ } from "react";
3700
+ import tippy from "tippy.js";
3701
+ import { jsx as jsx28, jsxs as jsxs15 } from "react/jsx-runtime";
3702
+ function CommandList(props) {
3703
+ const { items, command, editor } = props;
3704
+ const [selectedIndex, setSelectedIndex] = useState8(0);
3705
+ const selectItem = useCallback3(
3706
+ (index) => {
3707
+ const item = items[index];
3708
+ if (item) {
3709
+ command(item);
3710
+ }
3711
+ },
3712
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3713
+ [command, editor, items]
3714
+ );
3715
+ useEffect5(() => {
3716
+ const navigationKeys = ["ArrowUp", "ArrowDown", "Enter"];
3717
+ const onKeyDown = (e) => {
3718
+ if (navigationKeys.includes(e.key)) {
3719
+ e.preventDefault();
3720
+ if (e.key === "ArrowUp") {
3721
+ setSelectedIndex((selectedIndex + items.length - 1) % items.length);
3722
+ return true;
3723
+ }
3724
+ if (e.key === "ArrowDown") {
3725
+ setSelectedIndex((selectedIndex + 1) % items.length);
3726
+ return true;
3727
+ }
3728
+ if (e.key === "Enter") {
3729
+ selectItem(selectedIndex);
3730
+ return true;
3731
+ }
3732
+ return false;
3733
+ }
3734
+ };
3735
+ document.addEventListener("keydown", onKeyDown);
3736
+ return () => {
3737
+ document.removeEventListener("keydown", onKeyDown);
3738
+ };
3739
+ }, [items, selectedIndex, setSelectedIndex, selectItem]);
3740
+ useEffect5(() => {
3741
+ setSelectedIndex(0);
3742
+ }, [items]);
3743
+ const commandListContainer = useRef8(null);
3744
+ useLayoutEffect2(() => {
3745
+ const container = commandListContainer == null ? void 0 : commandListContainer.current;
3746
+ const item = container == null ? void 0 : container.children[selectedIndex];
3747
+ if (item && container) {
3748
+ updateScrollView(container, item);
3749
+ }
3750
+ }, [selectedIndex]);
3751
+ return items.length > 0 ? /* @__PURE__ */ jsxs15("div", { className: "mly-z-50 mly-w-72 mly-rounded-md mly-border mly-border-gray-200 mly-bg-white mly-shadow-md mly-transition-all", children: [
3752
+ /* @__PURE__ */ jsx28(
3753
+ "div",
3754
+ {
3755
+ id: "slash-command",
3756
+ ref: commandListContainer,
3757
+ className: "mly-no-scrollbar mly-h-auto mly-max-h-[330px] mly-overflow-y-auto mly-scroll-smooth mly-p-1",
3758
+ children: items.map((item, index) => {
3759
+ return /* @__PURE__ */ jsxs15(
3760
+ "button",
3761
+ {
3762
+ className: cn(
3763
+ "mly-flex mly-w-full mly-items-center mly-space-x-2 mly-rounded-md mly-px-2 mly-py-1 mly-text-left mly-text-sm mly-text-gray-900 hover:mly-bg-gray-100 hover:mly-text-gray-900",
3764
+ index === selectedIndex ? "mly-bg-gray-100 mly-text-gray-900" : "mly-bg-transparent"
3765
+ ),
3766
+ onClick: () => selectItem(index),
3767
+ type: "button",
3768
+ children: [
3769
+ /* @__PURE__ */ jsx28("div", { className: "mly-flex mly-h-6 mly-w-6 mly-shrink-0 mly-items-center mly-justify-center", children: item.icon }),
3770
+ /* @__PURE__ */ jsxs15("div", { children: [
3771
+ /* @__PURE__ */ jsx28("p", { className: "mly-font-medium", children: item.title }),
3772
+ /* @__PURE__ */ jsx28("p", { className: "mly-text-xs mly-text-gray-400", children: item.description })
3773
+ ] })
3774
+ ]
3775
+ },
3776
+ index
3777
+ );
3778
+ })
3779
+ }
3780
+ ),
3781
+ /* @__PURE__ */ jsx28("div", { className: "mly-border-t mly-border-gray-200 mly-px-1 mly-py-3 mly-pl-4", children: /* @__PURE__ */ jsxs15("div", { className: "mly-flex mly-items-center", children: [
3782
+ /* @__PURE__ */ jsxs15("p", { className: "mly-text-center mly-text-xs mly-text-gray-400", children: [
3783
+ /* @__PURE__ */ jsx28("kbd", { className: "mly-rounded mly-border mly-p-1 mly-px-2 mly-font-medium", children: "\u2191" }),
3784
+ /* @__PURE__ */ jsx28("kbd", { className: "mly-ml-1 mly-rounded mly-border mly-p-1 mly-px-2 mly-font-medium", children: "\u2193" }),
3785
+ " ",
3786
+ "to navigate"
3787
+ ] }),
3788
+ /* @__PURE__ */ jsx28("span", { "aria-hidden": "true", className: "mly-select-none mly-px-1", children: "\xB7" }),
3789
+ /* @__PURE__ */ jsxs15("p", { className: "mly-text-center mly-text-xs mly-text-gray-400", children: [
3790
+ /* @__PURE__ */ jsx28("kbd", { className: "mly-rounded mly-border mly-p-1 mly-px-1.5 mly-font-medium", children: "Enter" }),
3791
+ " ",
3792
+ "to select"
3793
+ ] })
3794
+ ] }) })
3795
+ ] }) : null;
3796
+ }
3797
+ function getSlashCommandSuggestions(commands = DEFAULT_SLASH_COMMANDS) {
3798
+ return {
3799
+ items: ({ query, editor }) => {
3800
+ return commands.filter((item) => {
3801
+ var _a;
3802
+ if (typeof query === "string" && query.length > 0) {
3803
+ const search = query.toLowerCase();
3804
+ if ((_a = item == null ? void 0 : item.shouldBeHidden) == null ? void 0 : _a.call(item, editor)) {
3805
+ return false;
3806
+ }
3807
+ return item.title.toLowerCase().includes(search) || item.description.toLowerCase().includes(search) || item.searchTerms && item.searchTerms.some((term) => term.includes(search));
3808
+ }
3809
+ return true;
3810
+ });
3811
+ },
3812
+ render: () => {
3813
+ let component;
3814
+ let popup = null;
3815
+ return {
3816
+ onStart: (props) => {
3817
+ component = new ReactRenderer(CommandList, {
3818
+ props,
3819
+ editor: props.editor
3820
+ });
3821
+ popup = tippy("body", {
3822
+ getReferenceClientRect: props.clientRect,
3823
+ appendTo: () => document.body,
3824
+ content: component.element,
3825
+ showOnCreate: true,
3826
+ interactive: true,
3827
+ trigger: "manual"
3828
+ });
3829
+ },
3830
+ onUpdate: (props) => {
3831
+ component == null ? void 0 : component.updateProps(props);
3832
+ popup && popup[0].setProps({
3833
+ getReferenceClientRect: props.clientRect
3834
+ });
3835
+ },
3836
+ onKeyDown: (props) => {
3837
+ var _a;
3838
+ if (props.event.key === "Escape") {
3839
+ popup == null ? void 0 : popup[0].hide();
3840
+ return true;
3841
+ }
3842
+ return (_a = component == null ? void 0 : component.ref) == null ? void 0 : _a.onKeyDown(props);
3843
+ },
3844
+ onExit: () => {
3845
+ if (!popup || !(popup == null ? void 0 : popup[0]) || !component) {
3846
+ return;
3847
+ }
3848
+ popup == null ? void 0 : popup[0].destroy();
3849
+ component == null ? void 0 : component.destroy();
3850
+ }
3851
+ };
3852
+ }
3853
+ };
3854
+ }
3855
+
3856
+ // src/editor/nodes/variable/variable.ts
3857
+ import { mergeAttributes as mergeAttributes9, Node as Node10 } from "@tiptap/core";
3858
+ import { PluginKey } from "@tiptap/pm/state";
3859
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer6 } from "@tiptap/react";
3860
+ import Suggestion2 from "@tiptap/suggestion";
3861
+ var VariablePluginKey = new PluginKey("variable");
3862
+ var VariableExtension = Node10.create({
3863
+ name: "variable",
3864
+ group: "inline",
3865
+ inline: true,
3866
+ selectable: true,
3867
+ atom: true,
3868
+ addOptions() {
3869
+ return {
3870
+ variables: [],
3871
+ triggerChar: "@",
3872
+ renderLabel({ options, node }) {
3873
+ var _a;
3874
+ return `${(_a = node.attrs.label) != null ? _a : node.attrs.id}`;
3875
+ },
3876
+ suggestion: {
3877
+ char: "@",
3878
+ pluginKey: VariablePluginKey,
3879
+ command: ({ editor, range, props }) => {
3880
+ var _a, _b;
3881
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
3882
+ const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" ");
3883
+ if (overrideSpace) {
3884
+ range.to += 1;
3885
+ }
3886
+ editor.chain().focus().insertContentAt(range, [
3887
+ {
3888
+ type: this.name,
3889
+ attrs: props
3890
+ },
3891
+ {
3892
+ type: "text",
3893
+ text: " "
3894
+ }
3895
+ ]).run();
3896
+ (_b = window.getSelection()) == null ? void 0 : _b.collapseToEnd();
3897
+ },
3898
+ allow: ({ state, range }) => {
3899
+ const $from = state.doc.resolve(range.from);
3900
+ const type = state.schema.nodes[this.name];
3901
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
3902
+ return allow;
3903
+ }
3904
+ }
3905
+ };
3906
+ },
3907
+ addAttributes() {
3908
+ return {
3909
+ id: {
3910
+ default: null,
3911
+ parseHTML: (element) => element.getAttribute("data-id"),
3912
+ renderHTML: (attributes) => {
3913
+ if (!attributes.id) {
3914
+ return {};
3915
+ }
3916
+ return {
3917
+ "data-id": attributes.id
3918
+ };
3919
+ }
3920
+ },
3921
+ label: {
3922
+ default: null,
3923
+ parseHTML: (element) => element.getAttribute("data-label"),
3924
+ renderHTML: (attributes) => {
3925
+ if (!attributes.label) {
3926
+ return {};
3927
+ }
3928
+ return {
3929
+ "data-label": attributes.label
3930
+ };
3931
+ }
3932
+ },
3933
+ fallback: {
3934
+ default: null,
3935
+ parseHTML: (element) => element.getAttribute("data-fallback"),
3936
+ renderHTML: (attributes) => {
3937
+ if (!attributes.fallback) {
3938
+ return {};
3939
+ }
3940
+ return {
3941
+ "data-fallback": attributes.fallback
3942
+ };
3943
+ }
3944
+ },
3945
+ required: {
3946
+ default: true,
3947
+ parseHTML: (element) => element.hasAttribute("data-required"),
3948
+ renderHTML: (attributes) => {
3949
+ var _a;
3950
+ return {
3951
+ "data-required": (_a = attributes == null ? void 0 : attributes.required) != null ? _a : true
3952
+ };
3953
+ }
3954
+ }
3955
+ };
3956
+ },
3957
+ parseHTML() {
3958
+ return [
3959
+ {
3960
+ tag: `div[data-type="${this.name}"]`
3961
+ }
3962
+ ];
3963
+ },
3964
+ renderHTML({ node, HTMLAttributes: HTMLAttributes2 }) {
3965
+ return [
3966
+ "div",
3967
+ mergeAttributes9({ "data-type": this.name }, HTMLAttributes2),
3968
+ this.options.renderLabel({
3969
+ options: this.options,
3970
+ node
3971
+ })
3972
+ ];
3973
+ },
3974
+ renderText({ node }) {
3975
+ return this.options.renderLabel({
3976
+ options: this.options,
3977
+ node
3978
+ });
3979
+ },
3980
+ addKeyboardShortcuts() {
3981
+ return {
3982
+ Backspace: () => this.editor.commands.command(({ tr, state }) => {
3983
+ let isMention = false;
3984
+ const { selection } = state;
3985
+ const { empty, anchor } = selection;
3986
+ if (!empty) {
3987
+ return false;
3988
+ }
3989
+ state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
3990
+ if (node.type.name === this.name) {
3991
+ isMention = true;
3992
+ tr.insertText(
3993
+ this.options.suggestion.char || "",
3994
+ pos,
3995
+ pos + node.nodeSize
3996
+ );
3997
+ return false;
3998
+ }
3999
+ });
4000
+ return isMention;
4001
+ })
4002
+ };
4003
+ },
4004
+ addProseMirrorPlugins() {
4005
+ return [
4006
+ Suggestion2(__spreadValues({
4007
+ editor: this.editor
4008
+ }, this.options.suggestion))
4009
+ ];
4010
+ },
4011
+ addNodeView() {
4012
+ return ReactNodeViewRenderer6(VariableView, {
4013
+ className: "mly-relative mly-inline-block",
4014
+ as: "div"
4015
+ });
4016
+ }
4017
+ });
4018
+
4019
+ // src/editor/nodes/variable/variable-suggestions.tsx
4020
+ import { ReactRenderer as ReactRenderer2 } from "@tiptap/react";
4021
+ import { forwardRef as forwardRef8, useImperativeHandle as useImperativeHandle2 } from "react";
4022
+ import tippy2 from "tippy.js";
4023
+ import { useRef as useRef9 } from "react";
4024
+ import { jsx as jsx29 } from "react/jsx-runtime";
4025
+ var VariableList = forwardRef8((props, ref) => {
4026
+ const { items = [] } = props;
4027
+ const popoverRef = useRef9(null);
4028
+ useImperativeHandle2(ref, () => ({
4029
+ onKeyDown: ({ event }) => {
4030
+ if (!popoverRef.current) {
4031
+ return false;
4032
+ }
4033
+ const { moveUp, moveDown, select } = popoverRef.current || {};
4034
+ if (event.key === "ArrowUp") {
4035
+ event.preventDefault();
4036
+ moveUp();
4037
+ return true;
4038
+ }
4039
+ if (event.key === "ArrowDown") {
4040
+ event.preventDefault();
4041
+ moveDown();
4042
+ return true;
4043
+ }
4044
+ if (event.key === "Enter") {
4045
+ select();
4046
+ return true;
4047
+ }
4048
+ return false;
4049
+ }
4050
+ }));
4051
+ return /* @__PURE__ */ jsx29(
4052
+ VariablePopover,
4053
+ {
4054
+ items,
4055
+ onSelectItem: (value) => {
4056
+ var _a;
4057
+ props.command({
4058
+ id: value.name,
4059
+ required: (_a = value.required) != null ? _a : true
4060
+ });
4061
+ },
4062
+ ref: popoverRef
4063
+ }
4064
+ );
4065
+ });
4066
+ VariableList.displayName = "VariableList";
4067
+ function getVariableSuggestions(variables = DEFAULT_VARIABLES, char = DEFAULT_VARIABLE_TRIGGER_CHAR) {
4068
+ return {
4069
+ char,
4070
+ items: ({ query, editor }) => {
4071
+ return processVariables(variables, {
4072
+ query,
4073
+ editor,
4074
+ from: "content-variable"
4075
+ });
4076
+ },
4077
+ render: () => {
4078
+ let component;
4079
+ let popup = null;
4080
+ return {
4081
+ onStart: (props) => {
4082
+ component = new ReactRenderer2(VariableList, {
4083
+ props,
4084
+ editor: props.editor
4085
+ });
4086
+ if (!props.clientRect) {
4087
+ return;
4088
+ }
4089
+ popup = tippy2("body", {
4090
+ getReferenceClientRect: props.clientRect,
4091
+ appendTo: () => document.body,
4092
+ content: component.element,
4093
+ showOnCreate: true,
4094
+ interactive: true,
4095
+ trigger: "manual",
4096
+ placement: "bottom-start"
4097
+ });
4098
+ },
4099
+ onUpdate(props) {
4100
+ var _a;
4101
+ component.updateProps(props);
4102
+ if (!props.clientRect) {
4103
+ return;
4104
+ }
4105
+ (_a = popup == null ? void 0 : popup[0]) == null ? void 0 : _a.setProps({
4106
+ getReferenceClientRect: props.clientRect
4107
+ });
4108
+ },
4109
+ onKeyDown(props) {
4110
+ var _a;
4111
+ if (props.event.key === "Escape") {
4112
+ popup == null ? void 0 : popup[0].hide();
4113
+ return true;
4114
+ }
4115
+ return (_a = component.ref) == null ? void 0 : _a.onKeyDown(props);
4116
+ },
4117
+ onExit() {
4118
+ if (!popup || !(popup == null ? void 0 : popup[0]) || !component) {
4119
+ return;
4120
+ }
4121
+ popup == null ? void 0 : popup[0].destroy();
4122
+ component.destroy();
4123
+ }
4124
+ };
4125
+ }
4126
+ };
4127
+ }
4128
+ export {
4129
+ ButtonExtension,
4130
+ Color,
4131
+ ColumnExtension,
4132
+ ColumnsExtension,
4133
+ DEFAULT_BUTTON_ALIGNMENT,
4134
+ DEFAULT_BUTTON_BACKGROUND_COLOR,
4135
+ DEFAULT_BUTTON_BORDER_RADIUS,
4136
+ DEFAULT_BUTTON_TEXT_COLOR,
4137
+ DEFAULT_BUTTON_VARIANT,
4138
+ DEFAULT_COLUMNS_GAP,
4139
+ DEFAULT_COLUMN_VERTICAL_ALIGN,
4140
+ DEFAULT_COLUMN_WIDTH,
4141
+ DEFAULT_LOGO_SIZE,
4142
+ DEFAULT_SECTION_ALIGN,
4143
+ DEFAULT_SECTION_BACKGROUND_COLOR,
4144
+ DEFAULT_SECTION_BORDER_COLOR,
4145
+ DEFAULT_SECTION_BORDER_RADIUS,
4146
+ DEFAULT_SECTION_BORDER_WIDTH,
4147
+ DEFAULT_SECTION_MARGIN_BOTTOM,
4148
+ DEFAULT_SECTION_MARGIN_LEFT,
4149
+ DEFAULT_SECTION_MARGIN_RIGHT,
4150
+ DEFAULT_SECTION_MARGIN_TOP,
4151
+ DEFAULT_SECTION_PADDING_BOTTOM,
4152
+ DEFAULT_SECTION_PADDING_LEFT,
4153
+ DEFAULT_SECTION_PADDING_RIGHT,
4154
+ DEFAULT_SECTION_PADDING_TOP,
4155
+ DEFAULT_SECTION_SHOW_IF_KEY,
4156
+ Footer,
4157
+ ForExtension,
4158
+ HorizontalRule,
4159
+ ImageExtension,
4160
+ LinkExtension,
4161
+ LogoExtension,
4162
+ MailyKit,
4163
+ SectionExtension,
4164
+ SlashCommandExtension,
4165
+ Spacer,
4166
+ VariableExtension,
4167
+ VariableList,
4168
+ VariablePluginKey,
4169
+ allowedButtonBorderRadius,
4170
+ allowedButtonVariant,
4171
+ allowedLogoAlignment,
4172
+ allowedLogoSize,
4173
+ allowedSpacerSize,
4174
+ getSlashCommandSuggestions,
4175
+ getVariableSuggestions,
4176
+ logoSizes
4177
+ };
4178
+ //# sourceMappingURL=index.mjs.map