@maily-to/core 0.0.21 → 0.0.23

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