@maily-to/core 0.0.22 → 0.0.24

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