@maily-to/core 0.1.2 → 0.2.0

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.
@@ -29,19 +29,26 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
-
33
- // src/editor/extensions/maily-kit.tsx
34
- import { Extension } from "@tiptap/core";
35
- import StarterKit from "@tiptap/starter-kit";
36
- import ListItem from "@tiptap/extension-list-item";
37
- import Paragraph from "@tiptap/extension-paragraph";
38
- import TextAlign from "@tiptap/extension-text-align";
39
- import TextStyle from "@tiptap/extension-text-style";
40
- import Heading from "@tiptap/extension-heading";
41
- import Underline from "@tiptap/extension-underline";
42
- import Document from "@tiptap/extension-document";
43
- import Focus from "@tiptap/extension-focus";
44
- import Dropcursor from "@tiptap/extension-dropcursor";
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
45
52
 
46
53
  // src/editor/extensions/color.ts
47
54
  import TiptapColor from "@tiptap/extension-color";
@@ -83,6 +90,154 @@ var HorizontalRule = TipTapHorizontalRule.extend({
83
90
  }
84
91
  });
85
92
 
93
+ // src/editor/plugins/image-upload/image-upload-plugin.ts
94
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
95
+ function ImageUploadPlugin(options) {
96
+ const { editor, onImageUpload, allowedMimeTypes } = options;
97
+ function handleImageUpload(view, file, pos) {
98
+ var _a, _b, _c;
99
+ const placeholderSrc = URL.createObjectURL(file);
100
+ const { tr, schema } = view.state;
101
+ const imageNode = schema.nodes.image.create({
102
+ src: placeholderSrc,
103
+ isSrcVariable: false,
104
+ alt: file.name,
105
+ externalLink: "",
106
+ isExternalLinkVariable: false
107
+ });
108
+ (_c = (_b = (_a = editor == null ? void 0 : editor.extensionStorage) == null ? void 0 : _a.imageUpload) == null ? void 0 : _b.placeholderImages) == null ? void 0 : _c.add(
109
+ placeholderSrc
110
+ );
111
+ const resolvedPos = pos !== void 0 ? view.state.doc.resolve(pos) : view.state.selection.$head;
112
+ const transaction = tr.insert(resolvedPos.pos, imageNode);
113
+ view.dispatch(transaction);
114
+ onImageUpload == null ? void 0 : onImageUpload(file).then((uploadedSrc) => {
115
+ const updateTr = view.state.tr;
116
+ const predicate = (node) => node.type.name === "image" && node.attrs.src === placeholderSrc;
117
+ view.state.doc.descendants((node, pos2) => {
118
+ if (predicate(node)) {
119
+ updateTr.setNodeMarkup(pos2, void 0, __spreadProps(__spreadValues({}, node.attrs), {
120
+ src: uploadedSrc
121
+ }));
122
+ return false;
123
+ }
124
+ });
125
+ view.dispatch(updateTr);
126
+ }).catch((error) => {
127
+ console.error("Image upload failed", error);
128
+ }).finally(() => {
129
+ editor.extensionStorage.imageUpload.placeholderImages.delete(
130
+ placeholderSrc
131
+ );
132
+ URL.revokeObjectURL(placeholderSrc);
133
+ });
134
+ }
135
+ return new Plugin({
136
+ key: new PluginKey("imageUpload"),
137
+ props: {
138
+ handleDrop: (view, event) => {
139
+ var _a, _b;
140
+ if (!onImageUpload || // we'll handle drops in the ImageView component
141
+ // this is just for dropping images in empty areas
142
+ !((_b = (_a = event.dataTransfer) == null ? void 0 : _a.files) == null ? void 0 : _b.length)) {
143
+ return false;
144
+ }
145
+ const images = Array.from(event.dataTransfer.files).filter(
146
+ (file) => allowedMimeTypes == null ? void 0 : allowedMimeTypes.includes(file.type)
147
+ );
148
+ if (images.length === 0) {
149
+ return false;
150
+ }
151
+ const pos = view.posAtCoords({
152
+ left: event.clientX,
153
+ top: event.clientY
154
+ });
155
+ if (!pos) {
156
+ return false;
157
+ }
158
+ event.preventDefault();
159
+ event.stopPropagation();
160
+ images.forEach((file) => handleImageUpload(view, file, pos.pos));
161
+ return true;
162
+ },
163
+ handlePaste: (view, event) => {
164
+ var _a, _b;
165
+ if (!onImageUpload || !((_b = (_a = event.clipboardData) == null ? void 0 : _a.files) == null ? void 0 : _b.length)) {
166
+ return false;
167
+ }
168
+ const images = Array.from(event.clipboardData.files).filter(
169
+ (file) => allowedMimeTypes == null ? void 0 : allowedMimeTypes.includes(file.type)
170
+ );
171
+ if (images.length === 0) {
172
+ return false;
173
+ }
174
+ event.preventDefault();
175
+ event.stopPropagation();
176
+ images.forEach((file) => handleImageUpload(view, file));
177
+ return true;
178
+ }
179
+ }
180
+ });
181
+ }
182
+
183
+ // src/editor/extensions/image-upload/image-upload.ts
184
+ import { Extension } from "@tiptap/core";
185
+ import { useMemo } from "react";
186
+ var ImageUploadExtension = Extension.create({
187
+ name: "imageUpload",
188
+ addOptions() {
189
+ return {
190
+ allowedMimeTypes: [
191
+ "image/jpeg",
192
+ "image/png",
193
+ "image/gif",
194
+ "image/webp",
195
+ "image/svg+xml"
196
+ ],
197
+ onImageUpload: void 0
198
+ };
199
+ },
200
+ addStorage() {
201
+ return {
202
+ placeholderImages: /* @__PURE__ */ new Set()
203
+ };
204
+ },
205
+ addProseMirrorPlugins() {
206
+ const { onImageUpload } = this.options;
207
+ if (!onImageUpload) {
208
+ return [];
209
+ }
210
+ return [
211
+ ImageUploadPlugin({
212
+ editor: this.editor,
213
+ allowedMimeTypes: this.options.allowedMimeTypes,
214
+ onImageUpload: this.options.onImageUpload
215
+ })
216
+ ];
217
+ }
218
+ });
219
+ function useImageUploadOptions(editor) {
220
+ return useMemo(() => {
221
+ const node = editor.extensionManager.extensions.find(
222
+ (extension) => extension.name === "imageUpload"
223
+ );
224
+ return (node == null ? void 0 : node.options) || {};
225
+ }, [editor]);
226
+ }
227
+
228
+ // src/editor/extensions/maily-kit.tsx
229
+ import { Extension as Extension2 } from "@tiptap/core";
230
+ import StarterKit from "@tiptap/starter-kit";
231
+ import ListItem from "@tiptap/extension-list-item";
232
+ import Paragraph from "@tiptap/extension-paragraph";
233
+ import TextAlign from "@tiptap/extension-text-align";
234
+ import TextStyle from "@tiptap/extension-text-style";
235
+ import Heading from "@tiptap/extension-heading";
236
+ import Underline from "@tiptap/extension-underline";
237
+ import Document from "@tiptap/extension-document";
238
+ import Focus from "@tiptap/extension-focus";
239
+ import Dropcursor from "@tiptap/extension-dropcursor";
240
+
86
241
  // src/editor/nodes/footer.ts
87
242
  import { mergeAttributes, Node } from "@tiptap/core";
88
243
  var Footer = Node.create({
@@ -1111,8 +1266,8 @@ var ColumnsExtension = Node7.create({
1111
1266
  });
1112
1267
 
1113
1268
  // src/editor/nodes/button/button.tsx
1114
- import { mergeAttributes as mergeAttributes7, Node as Node8 } from "@tiptap/core";
1115
- import { ReactNodeViewRenderer as ReactNodeViewRenderer2 } from "@tiptap/react";
1269
+ import { mergeAttributes as mergeAttributes8, Node as Node9 } from "@tiptap/core";
1270
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer3 } from "@tiptap/react";
1116
1271
 
1117
1272
  // src/editor/components/alignment-switch.tsx
1118
1273
  import { AlignCenter, AlignLeft, AlignRight } from "lucide-react";
@@ -1303,67 +1458,360 @@ function AlignmentSwitch(props) {
1303
1458
  ] });
1304
1459
  }
1305
1460
 
1306
- // src/editor/components/ui/color-picker.tsx
1307
- import { HexColorPicker, HexColorInput } from "react-colorful";
1461
+ // src/editor/components/show-popover.tsx
1462
+ import { Eye, InfoIcon } from "lucide-react";
1463
+ import { memo, useMemo as useMemo3, useRef as useRef2, useState } from "react";
1464
+
1465
+ // src/editor/utils/node-options.ts
1466
+ import { useMemo as useMemo2 } from "react";
1467
+ function getNodeOptions(editor, name) {
1468
+ const node = editor.extensionManager.extensions.find(
1469
+ (extension) => extension.name === name
1470
+ );
1471
+ if (!node) {
1472
+ throw new Error(`Node ${name} not found`);
1473
+ }
1474
+ return node.options;
1475
+ }
1476
+ function getVariableOptions(editor) {
1477
+ return getNodeOptions(editor, "variable");
1478
+ }
1479
+ function useVariableOptions(editor) {
1480
+ return useMemo2(() => {
1481
+ return getVariableOptions(editor);
1482
+ }, [editor]);
1483
+ }
1484
+
1485
+ // src/editor/utils/variable.ts
1486
+ function processVariables(variables, options) {
1487
+ const { query } = options;
1488
+ const queryLower = query.toLowerCase();
1489
+ let filteredVariables = [];
1490
+ if (Array.isArray(variables)) {
1491
+ filteredVariables = variables.filter(
1492
+ (variable) => variable.name.toLowerCase().startsWith(queryLower)
1493
+ );
1494
+ if (query.length > 0 && !filteredVariables.some((variable) => variable.name === query)) {
1495
+ filteredVariables.push({ name: query, required: true });
1496
+ }
1497
+ return filteredVariables;
1498
+ } else if (typeof variables === "function") {
1499
+ return variables(options);
1500
+ } else {
1501
+ throw new Error(`Invalid variables type. Expected 'Array' or 'Function', but received '${typeof variables}'.
1502
+
1503
+ You can check out the documentation for more information: https://github.com/arikchakma/maily.to/blob/main/packages/core/readme.md`);
1504
+ }
1505
+ }
1506
+
1507
+ // src/editor/utils/use-outside-click.ts
1508
+ import { useCallback } from "react";
1509
+ import { useEffect } from "react";
1510
+ function useOutsideClick(ref, callback) {
1511
+ const handleClick = useCallback(
1512
+ (e) => {
1513
+ if (ref.current && !ref.current.contains(e.target)) {
1514
+ callback();
1515
+ }
1516
+ },
1517
+ [ref, callback]
1518
+ );
1519
+ useEffect(() => {
1520
+ document.addEventListener("mousedown", handleClick);
1521
+ document.addEventListener("touchstart", handleClick);
1522
+ return () => {
1523
+ document.removeEventListener("mousedown", handleClick);
1524
+ document.removeEventListener("touchstart", handleClick);
1525
+ };
1526
+ }, [handleClick]);
1527
+ }
1528
+
1529
+ // src/editor/components/ui/input-autocomplete.tsx
1530
+ import { CornerDownLeft } from "lucide-react";
1531
+ import { forwardRef as forwardRef6, useRef } from "react";
1308
1532
  import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
1309
- function ColorPicker(props) {
1310
- const {
1311
- color,
1312
- onColorChange,
1313
- borderColor,
1314
- backgroundColor,
1315
- tooltip,
1533
+ var InputAutocomplete = forwardRef6((props, ref) => {
1534
+ var _b;
1535
+ const _a = props, {
1536
+ value = "",
1537
+ onValueChange,
1316
1538
  className,
1317
- children,
1318
- onClose,
1319
- suggestedColors = []
1320
- } = props;
1321
- const handleColorChange = (color2) => {
1322
- queueMicrotask(() => {
1323
- onColorChange(color2);
1324
- });
1325
- };
1326
- const popoverButton = /* @__PURE__ */ jsx9(PopoverTrigger, { asChild: true, children: children || /* @__PURE__ */ jsx9(
1327
- BaseButton,
1328
- {
1329
- variant: "ghost",
1330
- className: "!mly-size-7 mly-shrink-0",
1331
- size: "sm",
1332
- type: "button",
1333
- children: /* @__PURE__ */ jsx9(
1334
- "div",
1335
- {
1539
+ onOutsideClick,
1540
+ onSelectOption,
1541
+ autoCompleteOptions = [],
1542
+ triggerChar = "",
1543
+ editor
1544
+ } = _a, inputProps = __objRest(_a, [
1545
+ "value",
1546
+ "onValueChange",
1547
+ "className",
1548
+ "onOutsideClick",
1549
+ "onSelectOption",
1550
+ "autoCompleteOptions",
1551
+ "triggerChar",
1552
+ "editor"
1553
+ ]);
1554
+ const containerRef = useRef(null);
1555
+ const popoverRef = useRef(null);
1556
+ const VariableSuggestionPopoverComponent = (_b = useVariableOptions(editor)) == null ? void 0 : _b.variableSuggestionsPopover;
1557
+ useOutsideClick(containerRef, () => {
1558
+ onOutsideClick == null ? void 0 : onOutsideClick();
1559
+ });
1560
+ const isTriggeringVariable = value.startsWith(triggerChar);
1561
+ return /* @__PURE__ */ jsxs4("div", { className: cn("mly-relative"), ref: containerRef, children: [
1562
+ /* @__PURE__ */ jsxs4("label", { className: "mly-relative", children: [
1563
+ /* @__PURE__ */ jsx9(
1564
+ "input",
1565
+ __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
1566
+ placeholder: "e.g. items",
1567
+ type: "text"
1568
+ }), inputProps), {
1569
+ ref,
1570
+ value,
1571
+ onChange: (e) => {
1572
+ onValueChange(e.target.value);
1573
+ },
1336
1574
  className: cn(
1337
- "mly-h-4 mly-w-4 mly-shrink-0 mly-rounded mly-border-2 mly-border-gray-700",
1575
+ "mly-h-7 mly-w-40 mly-rounded-md mly-bg-white 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",
1338
1576
  className
1339
1577
  ),
1340
- style: __spreadProps(__spreadValues({}, borderColor ? { borderColor } : {}), {
1341
- backgroundColor: backgroundColor || "transparent"
1342
- })
1343
- }
1344
- )
1345
- }
1346
- ) });
1347
- return /* @__PURE__ */ jsxs4(
1578
+ onKeyDown: (e) => {
1579
+ if (!popoverRef.current || !isTriggeringVariable) {
1580
+ return;
1581
+ }
1582
+ const { moveUp, moveDown, select } = popoverRef.current;
1583
+ if (e.key === "ArrowDown") {
1584
+ e.preventDefault();
1585
+ moveDown();
1586
+ } else if (e.key === "ArrowUp") {
1587
+ e.preventDefault();
1588
+ moveUp();
1589
+ } else if (e.key === "Enter") {
1590
+ e.preventDefault();
1591
+ select();
1592
+ }
1593
+ },
1594
+ spellCheck: false
1595
+ })
1596
+ ),
1597
+ /* @__PURE__ */ jsx9("div", { className: "mly-absolute mly-inset-y-0 mly-right-1 mly-flex mly-items-center", children: /* @__PURE__ */ jsx9(CornerDownLeft, { className: "mly-h-3 mly-w-3 mly-stroke-[2.5] mly-text-midnight-gray" }) })
1598
+ ] }),
1599
+ isTriggeringVariable && /* @__PURE__ */ jsx9("div", { className: "mly-absolute mly-left-0 mly-top-8", children: /* @__PURE__ */ jsx9(
1600
+ VariableSuggestionPopoverComponent,
1601
+ {
1602
+ items: autoCompleteOptions.map((option) => {
1603
+ return {
1604
+ name: option
1605
+ };
1606
+ }),
1607
+ onSelectItem: (item) => {
1608
+ onSelectOption == null ? void 0 : onSelectOption(item.name);
1609
+ },
1610
+ ref: popoverRef
1611
+ }
1612
+ ) })
1613
+ ] });
1614
+ });
1615
+ InputAutocomplete.displayName = "InputAutocomplete";
1616
+
1617
+ // src/editor/components/show-popover.tsx
1618
+ import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
1619
+ function _ShowPopover(props) {
1620
+ const { showIfKey = "", onShowIfKeyValueChange, editor } = props;
1621
+ const opts = useVariableOptions(editor);
1622
+ const variables = opts == null ? void 0 : opts.variables;
1623
+ const renderVariable = opts == null ? void 0 : opts.renderVariable;
1624
+ const [isUpdatingKey, setIsUpdatingKey] = useState(false);
1625
+ const inputRef = useRef2(null);
1626
+ const autoCompleteOptions = useMemo3(() => {
1627
+ return processVariables(variables, {
1628
+ query: showIfKey || "",
1629
+ from: "bubble-variable",
1630
+ editor
1631
+ }).map((variable) => variable.name);
1632
+ }, [variables, showIfKey, editor]);
1633
+ const isValidWhenKey = showIfKey || autoCompleteOptions.includes(showIfKey);
1634
+ return /* @__PURE__ */ jsxs5(
1348
1635
  Popover,
1349
1636
  {
1350
1637
  onOpenChange: (open) => {
1351
- if (!open) {
1352
- onClose == null ? void 0 : onClose(color);
1353
- }
1638
+ if (open) {
1639
+ return;
1640
+ }
1641
+ setIsUpdatingKey(false);
1642
+ },
1643
+ children: [
1644
+ /* @__PURE__ */ jsxs5(Tooltip, { children: [
1645
+ /* @__PURE__ */ jsx10(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx10(
1646
+ PopoverTrigger,
1647
+ {
1648
+ className: cn(
1649
+ "mly-flex mly-size-7 mly-items-center mly-justify-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",
1650
+ showIfKey && "mly-bg-rose-100 mly-text-rose-800 data-[state=open]:mly-bg-rose-100 hover:mly-bg-rose-100"
1651
+ ),
1652
+ children: /* @__PURE__ */ jsx10(Eye, { className: "mly-h-3 mly-w-3 mly-stroke-[2.5]" })
1653
+ }
1654
+ ) }),
1655
+ /* @__PURE__ */ jsx10(TooltipContent, { sideOffset: 8, children: "Show block conditionally" })
1656
+ ] }),
1657
+ /* @__PURE__ */ jsxs5(
1658
+ PopoverContent,
1659
+ {
1660
+ className: "mly-flex mly-w-max mly-rounded-lg !mly-p-0.5",
1661
+ side: "top",
1662
+ sideOffset: 8,
1663
+ align: "end",
1664
+ onOpenAutoFocus: (e) => {
1665
+ e.preventDefault();
1666
+ },
1667
+ onCloseAutoFocus: (e) => {
1668
+ e.preventDefault();
1669
+ },
1670
+ children: [
1671
+ /* @__PURE__ */ jsxs5("div", { className: "mly-flex mly-items-center mly-gap-1.5 mly-px-1.5 mly-text-sm mly-leading-none", children: [
1672
+ "Show if",
1673
+ /* @__PURE__ */ jsxs5(Tooltip, { children: [
1674
+ /* @__PURE__ */ jsx10(TooltipTrigger, { children: /* @__PURE__ */ jsx10(
1675
+ InfoIcon,
1676
+ {
1677
+ className: cn("mly-size-3 mly-stroke-[2.5] mly-text-gray-500")
1678
+ }
1679
+ ) }),
1680
+ /* @__PURE__ */ jsx10(
1681
+ TooltipContent,
1682
+ {
1683
+ sideOffset: 14,
1684
+ className: "mly-max-w-[285px]",
1685
+ align: "start",
1686
+ children: "Show the block if the selected variable is true."
1687
+ }
1688
+ )
1689
+ ] })
1690
+ ] }),
1691
+ !isUpdatingKey && /* @__PURE__ */ jsx10(
1692
+ "button",
1693
+ {
1694
+ onClick: () => {
1695
+ setIsUpdatingKey(true);
1696
+ setTimeout(() => {
1697
+ var _a;
1698
+ (_a = inputRef.current) == null ? void 0 : _a.focus();
1699
+ }, 0);
1700
+ },
1701
+ children: renderVariable({
1702
+ variable: {
1703
+ name: showIfKey,
1704
+ valid: !!isValidWhenKey
1705
+ },
1706
+ fallback: "",
1707
+ from: "bubble-variable",
1708
+ editor
1709
+ })
1710
+ }
1711
+ ),
1712
+ isUpdatingKey && /* @__PURE__ */ jsx10(
1713
+ "form",
1714
+ {
1715
+ onSubmit: (e) => {
1716
+ e.preventDefault();
1717
+ setIsUpdatingKey(false);
1718
+ },
1719
+ onKeyDown: (e) => {
1720
+ if (e.key === "Escape") {
1721
+ setIsUpdatingKey(false);
1722
+ }
1723
+ },
1724
+ children: /* @__PURE__ */ jsx10(
1725
+ InputAutocomplete,
1726
+ {
1727
+ editor,
1728
+ value: showIfKey || "",
1729
+ onValueChange: (value) => {
1730
+ onShowIfKeyValueChange == null ? void 0 : onShowIfKeyValueChange(value);
1731
+ },
1732
+ onOutsideClick: () => {
1733
+ setIsUpdatingKey(false);
1734
+ },
1735
+ onSelectOption: (value) => {
1736
+ onShowIfKeyValueChange == null ? void 0 : onShowIfKeyValueChange(value);
1737
+ setIsUpdatingKey(false);
1738
+ },
1739
+ autoCompleteOptions,
1740
+ ref: inputRef
1741
+ }
1742
+ )
1743
+ }
1744
+ )
1745
+ ]
1746
+ }
1747
+ )
1748
+ ]
1749
+ }
1750
+ );
1751
+ }
1752
+ var ShowPopover = memo(_ShowPopover);
1753
+
1754
+ // src/editor/components/ui/color-picker.tsx
1755
+ import { HexColorPicker, HexColorInput } from "react-colorful";
1756
+ import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
1757
+ function ColorPicker(props) {
1758
+ const {
1759
+ color,
1760
+ onColorChange,
1761
+ borderColor,
1762
+ backgroundColor,
1763
+ tooltip,
1764
+ className,
1765
+ children,
1766
+ onClose,
1767
+ suggestedColors = []
1768
+ } = props;
1769
+ const handleColorChange = (color2) => {
1770
+ queueMicrotask(() => {
1771
+ onColorChange(color2);
1772
+ });
1773
+ };
1774
+ const popoverButton = /* @__PURE__ */ jsx11(PopoverTrigger, { asChild: true, children: children || /* @__PURE__ */ jsx11(
1775
+ BaseButton,
1776
+ {
1777
+ variant: "ghost",
1778
+ className: "!mly-size-7 mly-shrink-0",
1779
+ size: "sm",
1780
+ type: "button",
1781
+ children: /* @__PURE__ */ jsx11(
1782
+ "div",
1783
+ {
1784
+ className: cn(
1785
+ "mly-h-4 mly-w-4 mly-shrink-0 mly-rounded mly-border-2 mly-border-gray-700",
1786
+ className
1787
+ ),
1788
+ style: __spreadProps(__spreadValues({}, borderColor ? { borderColor } : {}), {
1789
+ backgroundColor: backgroundColor || "transparent"
1790
+ })
1791
+ }
1792
+ )
1793
+ }
1794
+ ) });
1795
+ return /* @__PURE__ */ jsxs6(
1796
+ Popover,
1797
+ {
1798
+ onOpenChange: (open) => {
1799
+ if (!open) {
1800
+ onClose == null ? void 0 : onClose(color);
1801
+ }
1354
1802
  },
1355
1803
  children: [
1356
- tooltip ? /* @__PURE__ */ jsxs4(Tooltip, { children: [
1357
- /* @__PURE__ */ jsx9(TooltipTrigger, { asChild: true, children: popoverButton }),
1358
- /* @__PURE__ */ jsx9(TooltipContent, { sideOffset: 8, children: tooltip })
1804
+ tooltip ? /* @__PURE__ */ jsxs6(Tooltip, { children: [
1805
+ /* @__PURE__ */ jsx11(TooltipTrigger, { asChild: true, children: popoverButton }),
1806
+ /* @__PURE__ */ jsx11(TooltipContent, { sideOffset: 8, children: tooltip })
1359
1807
  ] }) : popoverButton,
1360
- /* @__PURE__ */ jsx9(
1808
+ /* @__PURE__ */ jsx11(
1361
1809
  PopoverContent,
1362
1810
  {
1363
1811
  className: "mly-w-full mly-rounded-none mly-border-0 !mly-bg-transparent !mly-p-0 mly-shadow-none mly-drop-shadow-md",
1364
1812
  sideOffset: 8,
1365
- children: /* @__PURE__ */ jsxs4("div", { className: "mly-min-w-[260px] mly-rounded-xl mly-border mly-bg-white mly-p-4", children: [
1366
- /* @__PURE__ */ jsx9(
1813
+ children: /* @__PURE__ */ jsxs6("div", { className: "mly-min-w-[260px] mly-rounded-xl mly-border mly-border-gray-200 mly-bg-white mly-p-4", children: [
1814
+ /* @__PURE__ */ jsx11(
1367
1815
  HexColorPicker,
1368
1816
  {
1369
1817
  color,
@@ -1371,20 +1819,20 @@ function ColorPicker(props) {
1371
1819
  className: "mly-flex !mly-w-full mly-flex-col mly-gap-4"
1372
1820
  }
1373
1821
  ),
1374
- /* @__PURE__ */ jsx9(
1822
+ /* @__PURE__ */ jsx11(
1375
1823
  HexColorInput,
1376
1824
  {
1377
1825
  alpha: true,
1378
1826
  color,
1379
1827
  onChange: handleColorChange,
1380
- 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",
1828
+ className: "mly-mt-4 mly-w-full mly-min-w-0 mly-rounded-lg mly-border mly-border-gray-200 mly-px-2 mly-py-1.5 mly-text-sm mly-uppercase focus-visible:mly-border-gray-400 focus-visible:mly-outline-none",
1381
1829
  prefixed: true
1382
1830
  }
1383
1831
  ),
1384
- suggestedColors.length > 0 && /* @__PURE__ */ jsxs4("div", { children: [
1385
- /* @__PURE__ */ jsx9("div", { className: "-mly-mx-4 mly-my-4 mly-h-px mly-bg-gray-200" }),
1386
- /* @__PURE__ */ jsx9("h2", { className: "mly-text-xs mly-text-gray-500", children: "Recently used" }),
1387
- /* @__PURE__ */ jsx9("div", { className: "mly-mt-2 mly-flex mly-flex-wrap mly-gap-0.5", children: suggestedColors.map((suggestedColor) => /* @__PURE__ */ jsx9(
1832
+ suggestedColors.length > 0 && /* @__PURE__ */ jsxs6("div", { children: [
1833
+ /* @__PURE__ */ jsx11("div", { className: "-mly-mx-4 mly-my-4 mly-h-px mly-bg-gray-200" }),
1834
+ /* @__PURE__ */ jsx11("h2", { className: "mly-text-xs mly-text-gray-500", children: "Recently used" }),
1835
+ /* @__PURE__ */ jsx11("div", { className: "mly-mt-2 mly-flex mly-flex-wrap mly-gap-0.5", children: suggestedColors.map((suggestedColor) => /* @__PURE__ */ jsx11(
1388
1836
  BaseButton,
1389
1837
  {
1390
1838
  variant: "ghost",
@@ -1392,7 +1840,7 @@ function ColorPicker(props) {
1392
1840
  className: "!mly-size-7 mly-shrink-0",
1393
1841
  type: "button",
1394
1842
  onClick: () => handleColorChange(suggestedColor),
1395
- children: /* @__PURE__ */ jsx9(
1843
+ children: /* @__PURE__ */ jsx11(
1396
1844
  "div",
1397
1845
  {
1398
1846
  className: "mly-h-4 mly-w-4 mly-shrink-0 mly-rounded",
@@ -1414,10 +1862,10 @@ function ColorPicker(props) {
1414
1862
  }
1415
1863
 
1416
1864
  // src/editor/components/ui/divider.tsx
1417
- import { jsx as jsx10 } from "react/jsx-runtime";
1865
+ import { jsx as jsx12 } from "react/jsx-runtime";
1418
1866
  function Divider(props) {
1419
1867
  const { type = "vertical", className } = props;
1420
- return /* @__PURE__ */ jsx10(
1868
+ return /* @__PURE__ */ jsx12(
1421
1869
  "div",
1422
1870
  {
1423
1871
  className: cn(
@@ -1430,11 +1878,8 @@ function Divider(props) {
1430
1878
  }
1431
1879
 
1432
1880
  // src/editor/components/ui/link-input-popover.tsx
1433
- import {
1434
- ChevronDownIcon,
1435
- Link
1436
- } from "lucide-react";
1437
- import { useRef as useRef3, useState as useState3 } from "react";
1881
+ import { ChevronDownIcon, Link } from "lucide-react";
1882
+ import { useRef as useRef4, useState as useState3 } from "react";
1438
1883
 
1439
1884
  // src/editor/provider.tsx
1440
1885
  import { createContext, useContext } from "react";
@@ -1444,12 +1889,12 @@ import { FootprintsIcon as FootprintsIcon2, Heading1 as Heading12 } from "lucide
1444
1889
 
1445
1890
  // src/blocks/button.tsx
1446
1891
  import { MousePointer, ArrowUpRightSquare } from "lucide-react";
1447
- import { jsx as jsx11 } from "react/jsx-runtime";
1892
+ import { jsx as jsx13 } from "react/jsx-runtime";
1448
1893
  var button = {
1449
1894
  title: "Button",
1450
1895
  description: "Add a call to action button to email.",
1451
1896
  searchTerms: ["link", "button", "cta"],
1452
- icon: /* @__PURE__ */ jsx11(MousePointer, { className: "mly-h-4 mly-w-4" }),
1897
+ icon: /* @__PURE__ */ jsx13(MousePointer, { className: "mly-h-4 mly-w-4" }),
1453
1898
  command: ({ editor, range }) => {
1454
1899
  editor.chain().focus().deleteRange(range).setButton().run();
1455
1900
  }
@@ -1458,7 +1903,7 @@ var linkCard = {
1458
1903
  title: "Link Card",
1459
1904
  description: "Add a link card to email.",
1460
1905
  searchTerms: ["link", "button", "image"],
1461
- icon: /* @__PURE__ */ jsx11(ArrowUpRightSquare, { className: "mly-h-4 mly-w-4" }),
1906
+ icon: /* @__PURE__ */ jsx13(ArrowUpRightSquare, { className: "mly-h-4 mly-w-4" }),
1462
1907
  command: ({ editor, range }) => {
1463
1908
  editor.chain().focus().deleteRange(range).setLinkCard().run();
1464
1909
  },
@@ -1471,12 +1916,12 @@ var linkCard = {
1471
1916
 
1472
1917
  // src/blocks/code.tsx
1473
1918
  import { CodeXmlIcon } from "lucide-react";
1474
- import { jsx as jsx12 } from "react/jsx-runtime";
1919
+ import { jsx as jsx14 } from "react/jsx-runtime";
1475
1920
  var htmlCodeBlock = {
1476
1921
  title: "Custom HTML",
1477
1922
  description: "Insert a custom HTML block",
1478
1923
  searchTerms: ["html", "code", "custom"],
1479
- icon: /* @__PURE__ */ jsx12(CodeXmlIcon, { className: "mly-h-4 mly-w-4" }),
1924
+ icon: /* @__PURE__ */ jsx14(CodeXmlIcon, { className: "mly-h-4 mly-w-4" }),
1480
1925
  command: ({ editor, range }) => {
1481
1926
  editor.chain().focus().deleteRange(range).setHtmlCodeBlock({ language: "html" }).run();
1482
1927
  }
@@ -1485,12 +1930,12 @@ var htmlCodeBlock = {
1485
1930
  // src/blocks/image.tsx
1486
1931
  import { TextSelection as TextSelection2 } from "@tiptap/pm/state";
1487
1932
  import { ImageIcon } from "lucide-react";
1488
- import { jsx as jsx13 } from "react/jsx-runtime";
1933
+ import { jsx as jsx15 } from "react/jsx-runtime";
1489
1934
  var image = {
1490
1935
  title: "Image",
1491
1936
  description: "Full width image",
1492
1937
  searchTerms: ["image"],
1493
- icon: /* @__PURE__ */ jsx13(ImageIcon, { className: "mly-h-4 mly-w-4" }),
1938
+ icon: /* @__PURE__ */ jsx15(ImageIcon, { className: "mly-h-4 mly-w-4" }),
1494
1939
  command: ({ editor, range }) => {
1495
1940
  editor.chain().focus().deleteRange(range).setImage({ src: "" }).run();
1496
1941
  }
@@ -1499,7 +1944,7 @@ var logo = {
1499
1944
  title: "Logo",
1500
1945
  description: "Add your brand logo",
1501
1946
  searchTerms: ["image", "logo"],
1502
- icon: /* @__PURE__ */ jsx13(ImageIcon, { className: "mly-h-4 mly-w-4" }),
1947
+ icon: /* @__PURE__ */ jsx15(ImageIcon, { className: "mly-h-4 mly-w-4" }),
1503
1948
  command: ({ editor, range }) => {
1504
1949
  editor.chain().focus().deleteRange(range).setLogoImage({ src: "" }).run();
1505
1950
  }
@@ -1508,7 +1953,7 @@ var inlineImage = {
1508
1953
  title: "Inline Image",
1509
1954
  description: "Inline image",
1510
1955
  searchTerms: ["image", "inline"],
1511
- icon: /* @__PURE__ */ jsx13(ImageIcon, { className: "mly-h-4 mly-w-4" }),
1956
+ icon: /* @__PURE__ */ jsx15(ImageIcon, { className: "mly-h-4 mly-w-4" }),
1512
1957
  command: ({ editor, range }) => {
1513
1958
  editor.chain().focus().deleteRange(range).setInlineImage({
1514
1959
  src: ""
@@ -1538,12 +1983,12 @@ import {
1538
1983
  RectangleHorizontal,
1539
1984
  Minus
1540
1985
  } from "lucide-react";
1541
- import { jsx as jsx14 } from "react/jsx-runtime";
1986
+ import { jsx as jsx16 } from "react/jsx-runtime";
1542
1987
  var columns = {
1543
1988
  title: "Columns",
1544
1989
  description: "Add columns to email.",
1545
1990
  searchTerms: ["layout", "columns"],
1546
- icon: /* @__PURE__ */ jsx14(ColumnsIcon, { className: "mly-h-4 mly-w-4" }),
1991
+ icon: /* @__PURE__ */ jsx16(ColumnsIcon, { className: "mly-h-4 mly-w-4" }),
1547
1992
  command: ({ editor, range }) => {
1548
1993
  editor.chain().focus().deleteRange(range).setColumns().focus(editor.state.selection.head - 2).run();
1549
1994
  }
@@ -1552,7 +1997,7 @@ var section = {
1552
1997
  title: "Section",
1553
1998
  description: "Add a section to email.",
1554
1999
  searchTerms: ["layout", "section"],
1555
- icon: /* @__PURE__ */ jsx14(RectangleHorizontal, { className: "mly-h-4 mly-w-4" }),
2000
+ icon: /* @__PURE__ */ jsx16(RectangleHorizontal, { className: "mly-h-4 mly-w-4" }),
1556
2001
  command: ({ editor, range }) => {
1557
2002
  editor.chain().focus().deleteRange(range).setSection().run();
1558
2003
  }
@@ -1561,7 +2006,7 @@ var repeat = {
1561
2006
  title: "Repeat",
1562
2007
  description: "Loop over an array of items.",
1563
2008
  searchTerms: ["repeat", "for", "loop"],
1564
- icon: /* @__PURE__ */ jsx14(Repeat2, { className: "mly-h-4 mly-w-4" }),
2009
+ icon: /* @__PURE__ */ jsx16(Repeat2, { className: "mly-h-4 mly-w-4" }),
1565
2010
  command: ({ editor, range }) => {
1566
2011
  editor.chain().focus().deleteRange(range).setRepeat().run();
1567
2012
  }
@@ -1570,7 +2015,7 @@ var spacer = {
1570
2015
  title: "Spacer",
1571
2016
  description: "Add space between blocks.",
1572
2017
  searchTerms: ["space", "gap", "divider"],
1573
- icon: /* @__PURE__ */ jsx14(MoveVertical, { className: "mly-h-4 mly-w-4" }),
2018
+ icon: /* @__PURE__ */ jsx16(MoveVertical, { className: "mly-h-4 mly-w-4" }),
1574
2019
  command: ({ editor, range }) => {
1575
2020
  editor.chain().focus().deleteRange(range).setSpacer({ height: "sm" }).run();
1576
2021
  }
@@ -1579,7 +2024,7 @@ var divider = {
1579
2024
  title: "Divider",
1580
2025
  description: "Add a horizontal divider.",
1581
2026
  searchTerms: ["divider", "line"],
1582
- icon: /* @__PURE__ */ jsx14(Minus, { className: "mly-h-4 mly-w-4" }),
2027
+ icon: /* @__PURE__ */ jsx16(Minus, { className: "mly-h-4 mly-w-4" }),
1583
2028
  command: ({ editor, range }) => {
1584
2029
  editor.chain().focus().deleteRange(range).setHorizontalRule().run();
1585
2030
  }
@@ -1587,12 +2032,12 @@ var divider = {
1587
2032
 
1588
2033
  // src/blocks/list.tsx
1589
2034
  import { List, ListOrdered } from "lucide-react";
1590
- import { jsx as jsx15 } from "react/jsx-runtime";
2035
+ import { jsx as jsx17 } from "react/jsx-runtime";
1591
2036
  var bulletList = {
1592
2037
  title: "Bullet List",
1593
2038
  description: "Create a simple bullet list.",
1594
2039
  searchTerms: ["unordered", "point"],
1595
- icon: /* @__PURE__ */ jsx15(List, { className: "mly-h-4 mly-w-4" }),
2040
+ icon: /* @__PURE__ */ jsx17(List, { className: "mly-h-4 mly-w-4" }),
1596
2041
  command: ({ editor, range }) => {
1597
2042
  editor.chain().focus().deleteRange(range).toggleBulletList().run();
1598
2043
  }
@@ -1601,7 +2046,7 @@ var orderedList = {
1601
2046
  title: "Numbered List",
1602
2047
  description: "Create a list with numbering.",
1603
2048
  searchTerms: ["ordered"],
1604
- icon: /* @__PURE__ */ jsx15(ListOrdered, { className: "mly-h-4 mly-w-4" }),
2049
+ icon: /* @__PURE__ */ jsx17(ListOrdered, { className: "mly-h-4 mly-w-4" }),
1605
2050
  command: ({ editor, range }) => {
1606
2051
  editor.chain().focus().deleteRange(range).toggleOrderedList().run();
1607
2052
  }
@@ -1618,12 +2063,12 @@ import {
1618
2063
  FootprintsIcon,
1619
2064
  EraserIcon
1620
2065
  } from "lucide-react";
1621
- import { jsx as jsx16 } from "react/jsx-runtime";
2066
+ import { jsx as jsx18 } from "react/jsx-runtime";
1622
2067
  var text = {
1623
2068
  title: "Text",
1624
2069
  description: "Just start typing with plain text.",
1625
2070
  searchTerms: ["p", "paragraph"],
1626
- icon: /* @__PURE__ */ jsx16(Text, { className: "mly-h-4 mly-w-4" }),
2071
+ icon: /* @__PURE__ */ jsx18(Text, { className: "mly-h-4 mly-w-4" }),
1627
2072
  command: ({ editor, range }) => {
1628
2073
  editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").run();
1629
2074
  }
@@ -1631,8 +2076,8 @@ var text = {
1631
2076
  var heading1 = {
1632
2077
  title: "Heading 1",
1633
2078
  description: "Big heading.",
1634
- searchTerms: ["title", "big", "large"],
1635
- icon: /* @__PURE__ */ jsx16(Heading1, { className: "mly-h-4 mly-w-4" }),
2079
+ searchTerms: ["h1", "title", "big", "large"],
2080
+ icon: /* @__PURE__ */ jsx18(Heading1, { className: "mly-h-4 mly-w-4" }),
1636
2081
  command: ({ editor, range }) => {
1637
2082
  editor.chain().focus().deleteRange(range).setNode("heading", { level: 1 }).run();
1638
2083
  }
@@ -1640,8 +2085,8 @@ var heading1 = {
1640
2085
  var heading2 = {
1641
2086
  title: "Heading 2",
1642
2087
  description: "Medium heading.",
1643
- searchTerms: ["subtitle", "medium"],
1644
- icon: /* @__PURE__ */ jsx16(Heading2, { className: "mly-h-4 mly-w-4" }),
2088
+ searchTerms: ["h2", "subtitle", "medium"],
2089
+ icon: /* @__PURE__ */ jsx18(Heading2, { className: "mly-h-4 mly-w-4" }),
1645
2090
  command: ({ editor, range }) => {
1646
2091
  editor.chain().focus().deleteRange(range).setNode("heading", { level: 2 }).run();
1647
2092
  }
@@ -1649,8 +2094,8 @@ var heading2 = {
1649
2094
  var heading3 = {
1650
2095
  title: "Heading 3",
1651
2096
  description: "Small heading.",
1652
- searchTerms: ["subtitle", "small"],
1653
- icon: /* @__PURE__ */ jsx16(Heading3, { className: "mly-h-4 mly-w-4" }),
2097
+ searchTerms: ["h3", "subtitle", "small"],
2098
+ icon: /* @__PURE__ */ jsx18(Heading3, { className: "mly-h-4 mly-w-4" }),
1654
2099
  command: ({ editor, range }) => {
1655
2100
  editor.chain().focus().deleteRange(range).setNode("heading", { level: 3 }).run();
1656
2101
  }
@@ -1659,7 +2104,7 @@ var hardBreak = {
1659
2104
  title: "Hard Break",
1660
2105
  description: "Add a break between lines.",
1661
2106
  searchTerms: ["break", "line"],
1662
- icon: /* @__PURE__ */ jsx16(DivideIcon, { className: "mly-h-4 mly-w-4" }),
2107
+ icon: /* @__PURE__ */ jsx18(DivideIcon, { className: "mly-h-4 mly-w-4" }),
1663
2108
  command: ({ editor, range }) => {
1664
2109
  editor.chain().focus().deleteRange(range).setHardBreak().run();
1665
2110
  }
@@ -1668,7 +2113,7 @@ var blockquote = {
1668
2113
  title: "Blockquote",
1669
2114
  description: "Add blockquote.",
1670
2115
  searchTerms: ["quote", "blockquote"],
1671
- icon: /* @__PURE__ */ jsx16(TextQuote, { className: "mly-h-4 mly-w-4" }),
2116
+ icon: /* @__PURE__ */ jsx18(TextQuote, { className: "mly-h-4 mly-w-4" }),
1672
2117
  command: ({ editor, range }) => {
1673
2118
  editor.chain().focus().deleteRange(range).toggleBlockquote().run();
1674
2119
  }
@@ -1677,7 +2122,7 @@ var footer = {
1677
2122
  title: "Footer",
1678
2123
  description: "Add a footer text to email.",
1679
2124
  searchTerms: ["footer", "text"],
1680
- icon: /* @__PURE__ */ jsx16(FootprintsIcon, { className: "mly-h-4 mly-w-4" }),
2125
+ icon: /* @__PURE__ */ jsx18(FootprintsIcon, { className: "mly-h-4 mly-w-4" }),
1681
2126
  command: ({ editor, range }) => {
1682
2127
  editor.chain().focus().deleteRange(range).setFooter().run();
1683
2128
  }
@@ -1686,16 +2131,16 @@ var clearLine = {
1686
2131
  title: "Clear Line",
1687
2132
  description: "Clear the current line.",
1688
2133
  searchTerms: ["clear", "line"],
1689
- icon: /* @__PURE__ */ jsx16(EraserIcon, { className: "mly-h-4 mly-w-4" }),
2134
+ icon: /* @__PURE__ */ jsx18(EraserIcon, { className: "mly-h-4 mly-w-4" }),
1690
2135
  command: ({ editor, range }) => {
1691
2136
  editor.chain().focus().selectParentNode().deleteSelection().run();
1692
2137
  }
1693
2138
  };
1694
2139
 
1695
2140
  // src/editor/components/icons/logo-with-cover-image.tsx
1696
- import { jsx as jsx17, jsxs as jsxs5 } from "react/jsx-runtime";
2141
+ import { jsx as jsx19, jsxs as jsxs7 } from "react/jsx-runtime";
1697
2142
  function LogoWithCoverImageIcon(props) {
1698
- return /* @__PURE__ */ jsxs5(
2143
+ return /* @__PURE__ */ jsxs7(
1699
2144
  "svg",
1700
2145
  __spreadProps(__spreadValues({
1701
2146
  width: "14",
@@ -1705,7 +2150,7 @@ function LogoWithCoverImageIcon(props) {
1705
2150
  xmlns: "http://www.w3.org/2000/svg"
1706
2151
  }, props), {
1707
2152
  children: [
1708
- /* @__PURE__ */ jsx17(
2153
+ /* @__PURE__ */ jsx19(
1709
2154
  "path",
1710
2155
  {
1711
2156
  fillRule: "evenodd",
@@ -1714,7 +2159,7 @@ function LogoWithCoverImageIcon(props) {
1714
2159
  fill: "currentColor"
1715
2160
  }
1716
2161
  ),
1717
- /* @__PURE__ */ jsx17(
2162
+ /* @__PURE__ */ jsx19(
1718
2163
  "path",
1719
2164
  {
1720
2165
  fillRule: "evenodd",
@@ -1723,7 +2168,7 @@ function LogoWithCoverImageIcon(props) {
1723
2168
  fill: "currentColor"
1724
2169
  }
1725
2170
  ),
1726
- /* @__PURE__ */ jsx17(
2171
+ /* @__PURE__ */ jsx19(
1727
2172
  "path",
1728
2173
  {
1729
2174
  fillRule: "evenodd",
@@ -1732,8 +2177,8 @@ function LogoWithCoverImageIcon(props) {
1732
2177
  fill: "currentColor"
1733
2178
  }
1734
2179
  ),
1735
- /* @__PURE__ */ jsx17("mask", { id: "path-4-inside-1_1046_19527", fill: "white", children: /* @__PURE__ */ jsx17("rect", { x: "3", y: "4", width: "8", height: "3", rx: "0.5" }) }),
1736
- /* @__PURE__ */ jsx17(
2180
+ /* @__PURE__ */ jsx19("mask", { id: "path-4-inside-1_1046_19527", fill: "white", children: /* @__PURE__ */ jsx19("rect", { x: "3", y: "4", width: "8", height: "3", rx: "0.5" }) }),
2181
+ /* @__PURE__ */ jsx19(
1737
2182
  "rect",
1738
2183
  {
1739
2184
  x: "3",
@@ -1746,7 +2191,7 @@ function LogoWithCoverImageIcon(props) {
1746
2191
  mask: "url(#path-4-inside-1_1046_19527)"
1747
2192
  }
1748
2193
  ),
1749
- /* @__PURE__ */ jsx17(
2194
+ /* @__PURE__ */ jsx19(
1750
2195
  "rect",
1751
2196
  {
1752
2197
  x: "6.25",
@@ -1758,16 +2203,16 @@ function LogoWithCoverImageIcon(props) {
1758
2203
  strokeWidth: "0.5"
1759
2204
  }
1760
2205
  ),
1761
- /* @__PURE__ */ jsx17("rect", { x: "3", y: "8", width: "2", height: "1", rx: "0.5", fill: "currentColor" })
2206
+ /* @__PURE__ */ jsx19("rect", { x: "3", y: "8", width: "2", height: "1", rx: "0.5", fill: "currentColor" })
1762
2207
  ]
1763
2208
  })
1764
2209
  );
1765
2210
  }
1766
2211
 
1767
2212
  // src/editor/components/icons/logo-with-text-horizon.tsx
1768
- import { jsx as jsx18, jsxs as jsxs6 } from "react/jsx-runtime";
2213
+ import { jsx as jsx20, jsxs as jsxs8 } from "react/jsx-runtime";
1769
2214
  function LogoWithTextHorizonIcon(props) {
1770
- return /* @__PURE__ */ jsxs6(
2215
+ return /* @__PURE__ */ jsxs8(
1771
2216
  "svg",
1772
2217
  __spreadProps(__spreadValues({
1773
2218
  width: "14",
@@ -1777,7 +2222,7 @@ function LogoWithTextHorizonIcon(props) {
1777
2222
  xmlns: "http://www.w3.org/2000/svg"
1778
2223
  }, props), {
1779
2224
  children: [
1780
- /* @__PURE__ */ jsx18(
2225
+ /* @__PURE__ */ jsx20(
1781
2226
  "path",
1782
2227
  {
1783
2228
  fillRule: "evenodd",
@@ -1786,7 +2231,7 @@ function LogoWithTextHorizonIcon(props) {
1786
2231
  fill: "currentColor"
1787
2232
  }
1788
2233
  ),
1789
- /* @__PURE__ */ jsx18(
2234
+ /* @__PURE__ */ jsx20(
1790
2235
  "rect",
1791
2236
  {
1792
2237
  x: "6.25",
@@ -1798,8 +2243,8 @@ function LogoWithTextHorizonIcon(props) {
1798
2243
  strokeWidth: "0.5"
1799
2244
  }
1800
2245
  ),
1801
- /* @__PURE__ */ jsx18("rect", { x: "3", y: "6.5", width: "2", height: "1", rx: "0.5", fill: "currentColor" }),
1802
- /* @__PURE__ */ jsx18(
2246
+ /* @__PURE__ */ jsx20("rect", { x: "3", y: "6.5", width: "2", height: "1", rx: "0.5", fill: "currentColor" }),
2247
+ /* @__PURE__ */ jsx20(
1803
2248
  "path",
1804
2249
  {
1805
2250
  fillRule: "evenodd",
@@ -1808,7 +2253,7 @@ function LogoWithTextHorizonIcon(props) {
1808
2253
  fill: "currentColor"
1809
2254
  }
1810
2255
  ),
1811
- /* @__PURE__ */ jsx18(
2256
+ /* @__PURE__ */ jsx20(
1812
2257
  "path",
1813
2258
  {
1814
2259
  fillRule: "evenodd",
@@ -1823,9 +2268,9 @@ function LogoWithTextHorizonIcon(props) {
1823
2268
  }
1824
2269
 
1825
2270
  // src/editor/components/icons/logo-with-text-vertical.tsx
1826
- import { jsx as jsx19, jsxs as jsxs7 } from "react/jsx-runtime";
2271
+ import { jsx as jsx21, jsxs as jsxs9 } from "react/jsx-runtime";
1827
2272
  function LogoWithTextVerticalIcon(props) {
1828
- return /* @__PURE__ */ jsxs7(
2273
+ return /* @__PURE__ */ jsxs9(
1829
2274
  "svg",
1830
2275
  __spreadProps(__spreadValues({
1831
2276
  width: "14",
@@ -1835,7 +2280,7 @@ function LogoWithTextVerticalIcon(props) {
1835
2280
  xmlns: "http://www.w3.org/2000/svg"
1836
2281
  }, props), {
1837
2282
  children: [
1838
- /* @__PURE__ */ jsx19(
2283
+ /* @__PURE__ */ jsx21(
1839
2284
  "path",
1840
2285
  {
1841
2286
  fillRule: "evenodd",
@@ -1844,7 +2289,7 @@ function LogoWithTextVerticalIcon(props) {
1844
2289
  fill: "currentColor"
1845
2290
  }
1846
2291
  ),
1847
- /* @__PURE__ */ jsx19(
2292
+ /* @__PURE__ */ jsx21(
1848
2293
  "rect",
1849
2294
  {
1850
2295
  x: "4.25",
@@ -1856,8 +2301,8 @@ function LogoWithTextVerticalIcon(props) {
1856
2301
  strokeWidth: "0.5"
1857
2302
  }
1858
2303
  ),
1859
- /* @__PURE__ */ jsx19("rect", { x: "6", y: "6", width: "2", height: "1", rx: "0.5", fill: "currentColor" }),
1860
- /* @__PURE__ */ jsx19(
2304
+ /* @__PURE__ */ jsx21("rect", { x: "6", y: "6", width: "2", height: "1", rx: "0.5", fill: "currentColor" }),
2305
+ /* @__PURE__ */ jsx21(
1861
2306
  "path",
1862
2307
  {
1863
2308
  fillRule: "evenodd",
@@ -1866,7 +2311,7 @@ function LogoWithTextVerticalIcon(props) {
1866
2311
  fill: "currentColor"
1867
2312
  }
1868
2313
  ),
1869
- /* @__PURE__ */ jsx19(
2314
+ /* @__PURE__ */ jsx21(
1870
2315
  "path",
1871
2316
  {
1872
2317
  fillRule: "evenodd",
@@ -1881,12 +2326,12 @@ function LogoWithTextVerticalIcon(props) {
1881
2326
  }
1882
2327
 
1883
2328
  // src/blocks/headers.tsx
1884
- import { jsx as jsx20 } from "react/jsx-runtime";
2329
+ import { jsx as jsx22 } from "react/jsx-runtime";
1885
2330
  var headerLogoWithTextHorizontal = {
1886
2331
  title: "Logo with Text (Horizontal)",
1887
2332
  description: "Logo and a text horizontally",
1888
2333
  searchTerms: ["logo", "text"],
1889
- icon: /* @__PURE__ */ jsx20(LogoWithTextHorizonIcon, { className: "mly-h-4 mly-w-4" }),
2334
+ icon: /* @__PURE__ */ jsx22(LogoWithTextHorizonIcon, { className: "mly-h-4 mly-w-4" }),
1890
2335
  command: ({ editor, range }) => {
1891
2336
  editor.chain().deleteRange(range).insertContent({
1892
2337
  type: "columns",
@@ -1950,7 +2395,7 @@ var headerLogoWithTextVertical = {
1950
2395
  title: "Logo with Text (Vertical)",
1951
2396
  description: "Logo and a text vertically",
1952
2397
  searchTerms: ["logo", "text"],
1953
- icon: /* @__PURE__ */ jsx20(LogoWithTextVerticalIcon, { className: "mly-h-4 mly-w-4" }),
2398
+ icon: /* @__PURE__ */ jsx22(LogoWithTextVerticalIcon, { className: "mly-h-4 mly-w-4" }),
1954
2399
  command: ({ editor, range }) => {
1955
2400
  editor.chain().deleteRange(range).insertContent([
1956
2401
  {
@@ -1981,7 +2426,7 @@ var headerLogoWithCoverImage = {
1981
2426
  title: "Logo with Cover Image",
1982
2427
  description: "Logo and a cover image",
1983
2428
  searchTerms: ["logo", "cover", "image"],
1984
- icon: /* @__PURE__ */ jsx20(LogoWithCoverImageIcon, { className: "mly-h-4 mly-w-4" }),
2429
+ icon: /* @__PURE__ */ jsx22(LogoWithCoverImageIcon, { className: "mly-h-4 mly-w-4" }),
1985
2430
  command: ({ editor, range }) => {
1986
2431
  const todayFormatted = (/* @__PURE__ */ new Date()).toLocaleDateString("en-US", {
1987
2432
  year: "numeric",
@@ -2074,12 +2519,12 @@ import {
2074
2519
  LayoutTemplateIcon,
2075
2520
  RectangleHorizontalIcon
2076
2521
  } from "lucide-react";
2077
- import { jsx as jsx21 } from "react/jsx-runtime";
2522
+ import { jsx as jsx23 } from "react/jsx-runtime";
2078
2523
  var footerCopyrightText = {
2079
2524
  title: "Footer Copyright",
2080
2525
  description: "Copyright text for the footer.",
2081
2526
  searchTerms: ["footer", "copyright"],
2082
- icon: /* @__PURE__ */ jsx21(CopyrightIcon, { className: "mly-h-4 mly-w-4" }),
2527
+ icon: /* @__PURE__ */ jsx23(CopyrightIcon, { className: "mly-h-4 mly-w-4" }),
2083
2528
  command: ({ editor, range }) => {
2084
2529
  const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
2085
2530
  editor.chain().focus().deleteRange(range).insertContent({
@@ -2099,7 +2544,7 @@ var footerCommunityFeedbackCta = {
2099
2544
  title: "Footer Community Feedback CTA",
2100
2545
  description: "Community feedback CTA for the footer.",
2101
2546
  searchTerms: ["footer", "community", "feedback", "cta"],
2102
- icon: /* @__PURE__ */ jsx21(RectangleHorizontalIcon, { className: "mly-h-4 mly-w-4" }),
2547
+ icon: /* @__PURE__ */ jsx23(RectangleHorizontalIcon, { className: "mly-h-4 mly-w-4" }),
2103
2548
  command: ({ editor, range }) => {
2104
2549
  editor.chain().focus().deleteRange(range).insertContent([
2105
2550
  {
@@ -2142,7 +2587,7 @@ var footerCompanySignature = {
2142
2587
  title: "Footer Company Signature",
2143
2588
  description: "Company signature for the footer.",
2144
2589
  searchTerms: ["footer", "company", "signature"],
2145
- icon: /* @__PURE__ */ jsx21(LayoutTemplateIcon, { className: "mly-h-4 mly-w-4" }),
2590
+ icon: /* @__PURE__ */ jsx23(LayoutTemplateIcon, { className: "mly-h-4 mly-w-4" }),
2146
2591
  command: ({ editor, range }) => {
2147
2592
  editor.chain().focus().deleteRange(range).insertContent([
2148
2593
  { type: "horizontalRule" },
@@ -2296,7 +2741,7 @@ var footerCompanySignature = {
2296
2741
  };
2297
2742
 
2298
2743
  // src/editor/extensions/slash-command/default-slash-commands.tsx
2299
- import { jsx as jsx22 } from "react/jsx-runtime";
2744
+ import { jsx as jsx24 } from "react/jsx-runtime";
2300
2745
  var DEFAULT_SLASH_COMMANDS = [
2301
2746
  {
2302
2747
  title: "Blocks",
@@ -2331,7 +2776,7 @@ var DEFAULT_SLASH_COMMANDS = [
2331
2776
  title: "Headers",
2332
2777
  description: "Add pre-designed headers block",
2333
2778
  searchTerms: ["header", "headers"],
2334
- icon: /* @__PURE__ */ jsx22(Heading12, { className: "mly-h-4 mly-w-4" }),
2779
+ icon: /* @__PURE__ */ jsx24(Heading12, { className: "mly-h-4 mly-w-4" }),
2335
2780
  preview: "https://cdn.usemaily.com/previews/header-preview-xyz.png",
2336
2781
  commands: [
2337
2782
  headerLogoWithTextVertical,
@@ -2344,7 +2789,7 @@ var DEFAULT_SLASH_COMMANDS = [
2344
2789
  title: "Footers",
2345
2790
  description: "Add pre-designed footers block",
2346
2791
  searchTerms: ["footers"],
2347
- icon: /* @__PURE__ */ jsx22(FootprintsIcon2, { className: "mly-h-4 mly-w-4" }),
2792
+ icon: /* @__PURE__ */ jsx24(FootprintsIcon2, { className: "mly-h-4 mly-w-4" }),
2348
2793
  commands: [
2349
2794
  footerCopyrightText,
2350
2795
  footerCommunityFeedbackCta,
@@ -2356,164 +2801,50 @@ var DEFAULT_SLASH_COMMANDS = [
2356
2801
  }
2357
2802
  ];
2358
2803
 
2359
- // src/editor/nodes/variable/variable-view.tsx
2360
- import { NodeViewWrapper as NodeViewWrapper2 } from "@tiptap/react";
2361
- import { AlertTriangle, Braces, Pencil } from "lucide-react";
2362
- import { jsx as jsx23, jsxs as jsxs8 } from "react/jsx-runtime";
2363
- function VariableView(props) {
2364
- const { node, updateAttributes: updateAttributes2, editor } = props;
2365
- const { id, fallback, required } = node.attrs;
2366
- const { renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION } = useMailyContext();
2367
- return /* @__PURE__ */ jsx23(
2368
- NodeViewWrapper2,
2369
- {
2370
- className: "react-component mly-inline-block mly-leading-none",
2371
- draggable: "false",
2372
- children: /* @__PURE__ */ jsxs8(
2373
- Popover,
2374
- {
2375
- onOpenChange: (open) => {
2376
- editor.storage.variable.popover = open;
2377
- },
2378
- children: [
2379
- /* @__PURE__ */ jsx23(PopoverTrigger, { children: renderVariable({
2380
- variable: { name: id, required, valid: true },
2381
- fallback,
2382
- editor,
2383
- from: "content-variable"
2384
- }) }),
2385
- /* @__PURE__ */ jsx23(
2386
- PopoverContent,
2387
- {
2388
- align: "start",
2389
- side: "bottom",
2390
- className: "mly-w-max mly-rounded-lg !mly-p-0.5",
2391
- sideOffset: 8,
2392
- onOpenAutoFocus: (e) => e.preventDefault(),
2393
- onCloseAutoFocus: (e) => e.preventDefault(),
2394
- children: /* @__PURE__ */ jsx23(TooltipProvider, { children: /* @__PURE__ */ jsxs8("div", { className: "mly-flex mly-items-stretch mly-text-midnight-gray", children: [
2395
- /* @__PURE__ */ jsxs8("label", { className: "mly-relative", children: [
2396
- /* @__PURE__ */ jsx23("span", { className: "mly-inline-block mly-px-2 mly-text-xs mly-text-midnight-gray", children: "Variable" }),
2397
- /* @__PURE__ */ jsx23(
2398
- "input",
2399
- __spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
2400
- value: id != null ? id : "",
2401
- onChange: (e) => {
2402
- updateAttributes2({
2403
- id: e.target.value
2404
- });
2405
- },
2406
- placeholder: "ie. name...",
2407
- 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"
2408
- })
2409
- )
2410
- ] }),
2411
- /* @__PURE__ */ jsx23(Divider, { className: "mly-mx-1.5" }),
2412
- /* @__PURE__ */ jsxs8("label", { className: "mly-relative", children: [
2413
- /* @__PURE__ */ jsx23("span", { className: "mly-inline-block mly-px-2 mly-pl-1 mly-text-xs mly-text-midnight-gray", children: "Default" }),
2414
- /* @__PURE__ */ jsx23(
2415
- "input",
2416
- __spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
2417
- value: fallback != null ? fallback : "",
2418
- onChange: (e) => {
2419
- updateAttributes2({
2420
- fallback: e.target.value
2421
- });
2422
- },
2423
- placeholder: "ie. John Doe...",
2424
- 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"
2425
- })
2426
- ),
2427
- /* @__PURE__ */ jsx23("div", { className: "mly-absolute mly-inset-y-0 mly-right-1 mly-flex mly-items-center", children: /* @__PURE__ */ jsx23(Pencil, { className: "mly-h-3 mly-w-3 mly-stroke-[2.5] mly-text-midnight-gray" }) })
2428
- ] })
2429
- ] }) })
2430
- }
2431
- )
2432
- ]
2433
- }
2434
- )
2435
- }
2436
- );
2437
- }
2438
- var DefaultRenderVariable = (props) => {
2439
- const { variable, fallback, from } = props;
2440
- const { name, required, valid } = variable;
2441
- if (from === "button-variable") {
2442
- return /* @__PURE__ */ jsxs8("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: [
2443
- /* @__PURE__ */ jsx23(Braces, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5]" }),
2444
- /* @__PURE__ */ jsx23("span", { className: "mly-min-w-0 mly-truncate mly-text-left", children: name })
2445
- ] });
2446
- }
2447
- if (from === "bubble-variable") {
2448
- return /* @__PURE__ */ jsxs8(
2449
- "div",
2450
- {
2451
- className: cn(
2452
- "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",
2453
- !valid && "mly-border-rose-400 mly-bg-rose-50 mly-text-rose-600 hover:mly-bg-rose-100"
2454
- ),
2455
- children: [
2456
- /* @__PURE__ */ jsx23(Braces, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5] mly-text-rose-600" }),
2457
- /* @__PURE__ */ jsx23("span", { className: "mly-min-w-0 mly-truncate mly-text-left", children: name })
2458
- ]
2459
- }
2460
- );
2461
- }
2462
- return /* @__PURE__ */ jsxs8(
2463
- "span",
2464
- {
2465
- tabIndex: -1,
2466
- 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",
2467
- children: [
2468
- /* @__PURE__ */ jsx23(Braces, { className: "mly-size-[var(--variable-icon-size)] mly-shrink-0 mly-stroke-[2.5] mly-text-rose-600" }),
2469
- name,
2470
- required && !fallback && /* @__PURE__ */ jsx23(AlertTriangle, { className: "mly-size-[var(--variable-icon-size)] mly-shrink-0 mly-stroke-[2.5]" })
2471
- ]
2472
- }
2473
- );
2474
- };
2475
-
2476
- // src/editor/provider.tsx
2477
- import { jsx as jsx24 } from "react/jsx-runtime";
2478
- var DEFAULT_PLACEHOLDER_URL = "maily.to/";
2479
- var DEFAULT_VARIABLE_TRIGGER_CHAR = "@";
2480
- var DEFAULT_VARIABLES = [];
2481
- var DEFAULT_RENDER_VARIABLE_FUNCTION = DefaultRenderVariable;
2482
- var MailyContext = createContext({
2483
- placeholderUrl: DEFAULT_PLACEHOLDER_URL,
2484
- variableTriggerCharacter: DEFAULT_VARIABLE_TRIGGER_CHAR,
2485
- variables: DEFAULT_VARIABLES,
2486
- blocks: DEFAULT_SLASH_COMMANDS,
2487
- renderVariable: DEFAULT_RENDER_VARIABLE_FUNCTION
2488
- });
2489
- function useMailyContext() {
2490
- const values = useContext(MailyContext);
2491
- if (!values) {
2492
- throw new Error("Missing MailyContext.Provider in the component tree");
2804
+ // src/editor/provider.tsx
2805
+ import { jsx as jsx25 } from "react/jsx-runtime";
2806
+ var DEFAULT_PLACEHOLDER_URL = "maily.to/";
2807
+ var MailyContext = createContext({
2808
+ placeholderUrl: DEFAULT_PLACEHOLDER_URL,
2809
+ blocks: DEFAULT_SLASH_COMMANDS
2810
+ });
2811
+ function useMailyContext() {
2812
+ const values = useContext(MailyContext);
2813
+ if (!values) {
2814
+ throw new Error("Missing MailyContext.Provider in the component tree");
2493
2815
  }
2494
2816
  return values;
2495
2817
  }
2496
2818
 
2497
- // src/editor/nodes/variable/variable-popover.tsx
2819
+ // src/editor/components/ui/link-input-popover.tsx
2820
+ import { useMemo as useMemo5 } from "react";
2821
+
2822
+ // src/editor/nodes/variable/variable.ts
2823
+ import { mergeAttributes as mergeAttributes7, Node as Node8 } from "@tiptap/core";
2824
+ import { PluginKey as PluginKey2 } from "@tiptap/pm/state";
2825
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer2 } from "@tiptap/react";
2826
+ import Suggestion from "@tiptap/suggestion";
2827
+
2828
+ // src/editor/nodes/variable/variable-suggestions-popover.tsx
2498
2829
  import {
2499
2830
  ArrowDownIcon,
2500
2831
  ArrowUpIcon,
2501
- Braces as Braces2,
2832
+ Braces,
2502
2833
  CornerDownLeftIcon
2503
2834
  } from "lucide-react";
2504
2835
  import {
2836
+ forwardRef as forwardRef7,
2837
+ useEffect as useEffect2,
2505
2838
  useImperativeHandle,
2506
- forwardRef as forwardRef6,
2507
- useState,
2508
- useEffect,
2509
- useRef
2839
+ useRef as useRef3,
2840
+ useState as useState2
2510
2841
  } from "react";
2511
- import { jsx as jsx25, jsxs as jsxs9 } from "react/jsx-runtime";
2512
- var VariablePopover = forwardRef6((props, ref) => {
2842
+ import { jsx as jsx26, jsxs as jsxs10 } from "react/jsx-runtime";
2843
+ var VariableSuggestionsPopover = forwardRef7((props, ref) => {
2513
2844
  const { items, onSelectItem } = props;
2514
- const [selectedIndex, setSelectedIndex] = useState(0);
2515
- const scrollContainerRef = useRef(null);
2516
- const itemRefs = useRef([]);
2845
+ const [selectedIndex, setSelectedIndex] = useState2(0);
2846
+ const scrollContainerRef = useRef3(null);
2847
+ const itemRefs = useRef3([]);
2517
2848
  const scrollSelectedIntoView = (index) => {
2518
2849
  const container = scrollContainerRef.current;
2519
2850
  const selectedItem = itemRefs.current[index];
@@ -2529,14 +2860,14 @@ var VariablePopover = forwardRef6((props, ref) => {
2529
2860
  container.scrollTop += itemRect.top - containerRect.top - padding;
2530
2861
  }
2531
2862
  };
2532
- useEffect(() => {
2863
+ useEffect2(() => {
2533
2864
  setSelectedIndex(0);
2534
2865
  if (scrollContainerRef.current) {
2535
2866
  scrollContainerRef.current.scrollTop = 0;
2536
2867
  }
2537
2868
  itemRefs.current = items.map(() => null);
2538
2869
  }, [items]);
2539
- useEffect(() => {
2870
+ useEffect2(() => {
2540
2871
  scrollSelectedIntoView(selectedIndex);
2541
2872
  }, [selectedIndex]);
2542
2873
  useImperativeHandle(ref, () => ({
@@ -2554,17 +2885,17 @@ var VariablePopover = forwardRef6((props, ref) => {
2554
2885
  onSelectItem(item);
2555
2886
  }
2556
2887
  }));
2557
- return /* @__PURE__ */ jsxs9("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: [
2558
- /* @__PURE__ */ jsxs9("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: [
2559
- /* @__PURE__ */ jsx25("span", { className: "mly-text-xs mly-uppercase", children: "Variables" }),
2560
- /* @__PURE__ */ jsx25(VariableIcon, { children: /* @__PURE__ */ jsx25(Braces2, { className: "mly-size-3 mly-stroke-[2.5]" }) })
2888
+ return /* @__PURE__ */ jsxs10("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: [
2889
+ /* @__PURE__ */ jsxs10("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: [
2890
+ /* @__PURE__ */ jsx26("span", { className: "mly-text-xs mly-uppercase", children: "Variables" }),
2891
+ /* @__PURE__ */ jsx26(VariableIcon, { children: /* @__PURE__ */ jsx26(Braces, { className: "mly-size-3 mly-stroke-[2.5]" }) })
2561
2892
  ] }),
2562
- /* @__PURE__ */ jsx25(
2893
+ /* @__PURE__ */ jsx26(
2563
2894
  "div",
2564
2895
  {
2565
2896
  ref: scrollContainerRef,
2566
2897
  className: "mly-max-h-52 mly-overflow-y-auto mly-scrollbar-thin mly-scrollbar-track-transparent mly-scrollbar-thumb-gray-200",
2567
- children: /* @__PURE__ */ jsx25("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__ */ jsxs9(
2898
+ children: /* @__PURE__ */ jsx26("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__ */ jsxs10(
2568
2899
  "button",
2569
2900
  {
2570
2901
  ref: (el) => itemRefs.current[index] = el,
@@ -2574,27 +2905,27 @@ var VariablePopover = forwardRef6((props, ref) => {
2574
2905
  index === selectedIndex ? "mly-bg-soft-gray" : "mly-bg-white"
2575
2906
  ),
2576
2907
  children: [
2577
- /* @__PURE__ */ jsx25(Braces2, { className: "mly-size-3 mly-stroke-[2.5] mly-text-rose-600" }),
2908
+ /* @__PURE__ */ jsx26(Braces, { className: "mly-size-3 mly-stroke-[2.5] mly-text-rose-600" }),
2578
2909
  item.name
2579
2910
  ]
2580
2911
  },
2581
2912
  index
2582
- )) : /* @__PURE__ */ jsx25("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" }) })
2913
+ )) : /* @__PURE__ */ jsx26("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" }) })
2583
2914
  }
2584
2915
  ),
2585
- /* @__PURE__ */ jsxs9("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: [
2586
- /* @__PURE__ */ jsxs9("div", { className: "mly-flex mly-items-center mly-gap-1", children: [
2587
- /* @__PURE__ */ jsx25(VariableIcon, { children: /* @__PURE__ */ jsx25(ArrowDownIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) }),
2588
- /* @__PURE__ */ jsx25(VariableIcon, { children: /* @__PURE__ */ jsx25(ArrowUpIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) }),
2589
- /* @__PURE__ */ jsx25("span", { className: "mly-text-xs mly-text-gray-500", children: "Navigate" })
2916
+ /* @__PURE__ */ jsxs10("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: [
2917
+ /* @__PURE__ */ jsxs10("div", { className: "mly-flex mly-items-center mly-gap-1", children: [
2918
+ /* @__PURE__ */ jsx26(VariableIcon, { children: /* @__PURE__ */ jsx26(ArrowDownIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) }),
2919
+ /* @__PURE__ */ jsx26(VariableIcon, { children: /* @__PURE__ */ jsx26(ArrowUpIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) }),
2920
+ /* @__PURE__ */ jsx26("span", { className: "mly-text-xs mly-text-gray-500", children: "Navigate" })
2590
2921
  ] }),
2591
- /* @__PURE__ */ jsx25(VariableIcon, { children: /* @__PURE__ */ jsx25(CornerDownLeftIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) })
2922
+ /* @__PURE__ */ jsx26(VariableIcon, { children: /* @__PURE__ */ jsx26(CornerDownLeftIcon, { className: "mly-size-3 mly-stroke-[2.5]" }) })
2592
2923
  ] })
2593
2924
  ] });
2594
2925
  });
2595
2926
  function VariableIcon(props) {
2596
2927
  const { className, children } = props;
2597
- return /* @__PURE__ */ jsx25(
2928
+ return /* @__PURE__ */ jsx26(
2598
2929
  "div",
2599
2930
  {
2600
2931
  className: cn(
@@ -2606,140 +2937,303 @@ function VariableIcon(props) {
2606
2937
  );
2607
2938
  }
2608
2939
 
2609
- // src/editor/utils/use-outside-click.ts
2610
- import { useCallback } from "react";
2611
- import { useEffect as useEffect2 } from "react";
2612
- function useOutsideClick(ref, callback) {
2613
- const handleClick = useCallback(
2614
- (e) => {
2615
- if (ref.current && !ref.current.contains(e.target)) {
2616
- callback();
2617
- }
2618
- },
2619
- [ref, callback]
2940
+ // src/editor/nodes/variable/variable-view.tsx
2941
+ import { NodeViewWrapper as NodeViewWrapper2 } from "@tiptap/react";
2942
+ import { AlertTriangle, Braces as Braces2, Pencil } from "lucide-react";
2943
+ import { useMemo as useMemo4 } from "react";
2944
+ import { jsx as jsx27, jsxs as jsxs11 } from "react/jsx-runtime";
2945
+ function VariableView(props) {
2946
+ const { node, updateAttributes: updateAttributes2, editor } = props;
2947
+ const { id, fallback, required } = node.attrs;
2948
+ const renderVariable = useMemo4(() => {
2949
+ var _a, _b;
2950
+ const variableRender = (_b = (_a = getNodeOptions(editor, "variable")) == null ? void 0 : _a.renderVariable) != null ? _b : DEFAULT_RENDER_VARIABLE_FUNCTION;
2951
+ return variableRender;
2952
+ }, [editor]);
2953
+ return /* @__PURE__ */ jsx27(
2954
+ NodeViewWrapper2,
2955
+ {
2956
+ className: "react-component mly-inline-block mly-leading-none",
2957
+ draggable: "false",
2958
+ children: /* @__PURE__ */ jsxs11(
2959
+ Popover,
2960
+ {
2961
+ onOpenChange: (open) => {
2962
+ editor.storage.variable.popover = open;
2963
+ },
2964
+ children: [
2965
+ /* @__PURE__ */ jsx27(PopoverTrigger, { children: renderVariable({
2966
+ variable: { name: id, required, valid: true },
2967
+ fallback,
2968
+ editor,
2969
+ from: "content-variable"
2970
+ }) }),
2971
+ /* @__PURE__ */ jsx27(
2972
+ PopoverContent,
2973
+ {
2974
+ align: "start",
2975
+ side: "bottom",
2976
+ className: "mly-w-max mly-rounded-lg !mly-p-0.5",
2977
+ sideOffset: 8,
2978
+ onOpenAutoFocus: (e) => e.preventDefault(),
2979
+ onCloseAutoFocus: (e) => e.preventDefault(),
2980
+ children: /* @__PURE__ */ jsx27(TooltipProvider, { children: /* @__PURE__ */ jsxs11("div", { className: "mly-flex mly-items-stretch mly-text-midnight-gray", children: [
2981
+ /* @__PURE__ */ jsxs11("label", { className: "mly-relative", children: [
2982
+ /* @__PURE__ */ jsx27("span", { className: "mly-inline-block mly-px-2 mly-text-xs mly-text-midnight-gray", children: "Variable" }),
2983
+ /* @__PURE__ */ jsx27(
2984
+ "input",
2985
+ __spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
2986
+ value: id != null ? id : "",
2987
+ onChange: (e) => {
2988
+ updateAttributes2({
2989
+ id: e.target.value
2990
+ });
2991
+ },
2992
+ placeholder: "ie. name...",
2993
+ 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"
2994
+ })
2995
+ )
2996
+ ] }),
2997
+ /* @__PURE__ */ jsx27(Divider, { className: "mly-mx-1.5" }),
2998
+ /* @__PURE__ */ jsxs11("label", { className: "mly-relative", children: [
2999
+ /* @__PURE__ */ jsx27("span", { className: "mly-inline-block mly-px-2 mly-pl-1 mly-text-xs mly-text-midnight-gray", children: "Default" }),
3000
+ /* @__PURE__ */ jsx27(
3001
+ "input",
3002
+ __spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
3003
+ value: fallback != null ? fallback : "",
3004
+ onChange: (e) => {
3005
+ updateAttributes2({
3006
+ fallback: e.target.value
3007
+ });
3008
+ },
3009
+ placeholder: "ie. John Doe...",
3010
+ 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"
3011
+ })
3012
+ ),
3013
+ /* @__PURE__ */ jsx27("div", { className: "mly-absolute mly-inset-y-0 mly-right-1 mly-flex mly-items-center", children: /* @__PURE__ */ jsx27(Pencil, { className: "mly-h-3 mly-w-3 mly-stroke-[2.5] mly-text-midnight-gray" }) })
3014
+ ] })
3015
+ ] }) })
3016
+ }
3017
+ )
3018
+ ]
3019
+ }
3020
+ )
3021
+ }
2620
3022
  );
2621
- useEffect2(() => {
2622
- document.addEventListener("mousedown", handleClick);
2623
- document.addEventListener("touchstart", handleClick);
2624
- return () => {
2625
- document.removeEventListener("mousedown", handleClick);
2626
- document.removeEventListener("touchstart", handleClick);
2627
- };
2628
- }, [handleClick]);
2629
3023
  }
2630
-
2631
- // src/editor/components/ui/input-autocomplete.tsx
2632
- import { CornerDownLeft } from "lucide-react";
2633
- import { forwardRef as forwardRef7, useRef as useRef2 } from "react";
2634
- import { jsx as jsx26, jsxs as jsxs10 } from "react/jsx-runtime";
2635
- var InputAutocomplete = forwardRef7((props, ref) => {
2636
- const _a = props, {
2637
- value = "",
2638
- onValueChange,
2639
- className,
2640
- onOutsideClick,
2641
- onSelectOption,
2642
- autoCompleteOptions = [],
2643
- triggerChar = ""
2644
- } = _a, inputProps = __objRest(_a, [
2645
- "value",
2646
- "onValueChange",
2647
- "className",
2648
- "onOutsideClick",
2649
- "onSelectOption",
2650
- "autoCompleteOptions",
2651
- "triggerChar"
2652
- ]);
2653
- const containerRef = useRef2(null);
2654
- const popoverRef = useRef2(null);
2655
- useOutsideClick(containerRef, () => {
2656
- onOutsideClick == null ? void 0 : onOutsideClick();
2657
- });
2658
- const isTriggeringVariable = value.startsWith(triggerChar);
2659
- return /* @__PURE__ */ jsxs10("div", { className: cn("mly-relative"), ref: containerRef, children: [
2660
- /* @__PURE__ */ jsxs10("label", { className: "mly-relative", children: [
2661
- /* @__PURE__ */ jsx26(
2662
- "input",
2663
- __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, AUTOCOMPLETE_PASSWORD_MANAGERS_OFF), {
2664
- placeholder: "e.g. items",
2665
- type: "text"
2666
- }), inputProps), {
2667
- ref,
2668
- value,
2669
- onChange: (e) => {
2670
- onValueChange(e.target.value);
2671
- },
2672
- className: cn(
2673
- "mly-h-7 mly-w-40 mly-rounded-md mly-bg-white 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",
2674
- className
2675
- ),
2676
- onKeyDown: (e) => {
2677
- if (!popoverRef.current || !isTriggeringVariable) {
2678
- return;
2679
- }
2680
- const { moveUp, moveDown, select } = popoverRef.current;
2681
- if (e.key === "ArrowDown") {
2682
- e.preventDefault();
2683
- moveDown();
2684
- } else if (e.key === "ArrowUp") {
2685
- e.preventDefault();
2686
- moveUp();
2687
- } else if (e.key === "Enter") {
2688
- e.preventDefault();
2689
- select();
2690
- }
2691
- },
2692
- spellCheck: false
2693
- })
2694
- ),
2695
- /* @__PURE__ */ jsx26("div", { className: "mly-absolute mly-inset-y-0 mly-right-1 mly-flex mly-items-center", children: /* @__PURE__ */ jsx26(CornerDownLeft, { className: "mly-h-3 mly-w-3 mly-stroke-[2.5] mly-text-midnight-gray" }) })
2696
- ] }),
2697
- isTriggeringVariable && /* @__PURE__ */ jsx26("div", { className: "mly-absolute mly-left-0 mly-top-8", children: /* @__PURE__ */ jsx26(
2698
- VariablePopover,
3024
+ var DefaultRenderVariable = (props) => {
3025
+ const { variable, fallback, from } = props;
3026
+ const { name, required, valid } = variable;
3027
+ if (from === "button-variable") {
3028
+ return /* @__PURE__ */ jsxs11("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: [
3029
+ /* @__PURE__ */ jsx27(Braces2, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5]" }),
3030
+ /* @__PURE__ */ jsx27("span", { className: "mly-min-w-0 mly-truncate mly-text-left", children: name })
3031
+ ] });
3032
+ }
3033
+ if (from === "bubble-variable") {
3034
+ return /* @__PURE__ */ jsxs11(
3035
+ "div",
2699
3036
  {
2700
- items: autoCompleteOptions.map((option) => {
2701
- return {
2702
- name: option
2703
- };
2704
- }),
2705
- onSelectItem: (item) => {
2706
- onSelectOption == null ? void 0 : onSelectOption(item.name);
2707
- },
2708
- ref: popoverRef
3037
+ className: cn(
3038
+ "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",
3039
+ !valid && "mly-border-rose-400 mly-bg-rose-50 mly-text-rose-600 hover:mly-bg-rose-100"
3040
+ ),
3041
+ children: [
3042
+ /* @__PURE__ */ jsx27(Braces2, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5] mly-text-rose-600" }),
3043
+ /* @__PURE__ */ jsx27("span", { className: "mly-min-w-0 mly-truncate mly-text-left", children: name })
3044
+ ]
2709
3045
  }
2710
- ) })
2711
- ] });
2712
- });
2713
- InputAutocomplete.displayName = "InputAutocomplete";
2714
-
2715
- // src/editor/utils/variable.ts
2716
- function processVariables(variables, options) {
2717
- const { query } = options;
2718
- const queryLower = query.toLowerCase();
2719
- let filteredVariables = [];
2720
- if (Array.isArray(variables)) {
2721
- filteredVariables = variables.filter(
2722
- (variable) => variable.name.toLowerCase().startsWith(queryLower)
2723
3046
  );
2724
- if (query.length > 0 && !filteredVariables.some((variable) => variable.name === query)) {
2725
- filteredVariables.push({ name: query, required: true });
3047
+ }
3048
+ return /* @__PURE__ */ jsxs11(
3049
+ "span",
3050
+ {
3051
+ tabIndex: -1,
3052
+ className: "mly-inline-flex mly-items-center mly-gap-[var(--variable-icon-gap)] mly-rounded-full mly-border mly-border-gray-200 mly-px-1.5 mly-py-0.5 mly-leading-none",
3053
+ children: [
3054
+ /* @__PURE__ */ jsx27(Braces2, { className: "mly-size-[var(--variable-icon-size)] mly-shrink-0 mly-stroke-[2.5] mly-text-rose-600" }),
3055
+ name,
3056
+ required && !fallback && /* @__PURE__ */ jsx27(AlertTriangle, { className: "mly-size-[var(--variable-icon-size)] mly-shrink-0 mly-stroke-[2.5]" })
3057
+ ]
2726
3058
  }
2727
- return filteredVariables;
2728
- } else if (typeof variables === "function") {
2729
- return variables(options);
2730
- } else {
2731
- throw new Error(`Invalid variables type. Expected 'Array' or 'Function', but received '${typeof variables}'.
3059
+ );
3060
+ };
2732
3061
 
2733
- You can check out the documentation for more information: https://github.com/arikchakma/maily.to/blob/main/packages/core/readme.md`);
3062
+ // src/editor/nodes/variable/variable.ts
3063
+ var DEFAULT_VARIABLE_TRIGGER_CHAR = "@";
3064
+ var DEFAULT_VARIABLES = [];
3065
+ var DEFAULT_RENDER_VARIABLE_FUNCTION = DefaultRenderVariable;
3066
+ var DEFAULT_VARIABLE_SUGGESTION_POPOVER = VariableSuggestionsPopover;
3067
+ var VariablePluginKey = new PluginKey2("variable");
3068
+ var VariableExtension = Node8.create({
3069
+ name: "variable",
3070
+ group: "inline",
3071
+ inline: true,
3072
+ selectable: true,
3073
+ atom: true,
3074
+ addStorage() {
3075
+ return {
3076
+ popover: false
3077
+ };
3078
+ },
3079
+ addOptions() {
3080
+ return {
3081
+ variables: DEFAULT_VARIABLES,
3082
+ variableSuggestionsPopover: DEFAULT_VARIABLE_SUGGESTION_POPOVER,
3083
+ renderVariable: DEFAULT_RENDER_VARIABLE_FUNCTION,
3084
+ renderLabel(props) {
3085
+ var _a;
3086
+ const { node } = props;
3087
+ return `${(_a = node.attrs.label) != null ? _a : node.attrs.id}`;
3088
+ },
3089
+ suggestion: {
3090
+ char: "@",
3091
+ pluginKey: VariablePluginKey,
3092
+ command: ({ editor, range, props }) => {
3093
+ var _a, _b;
3094
+ const nodeAfter = editor.view.state.selection.$to.nodeAfter;
3095
+ const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" ");
3096
+ if (overrideSpace) {
3097
+ range.to += 1;
3098
+ }
3099
+ editor.chain().focus().insertContentAt(range, [
3100
+ {
3101
+ type: this.name,
3102
+ attrs: props
3103
+ },
3104
+ {
3105
+ type: "text",
3106
+ text: " "
3107
+ }
3108
+ ]).run();
3109
+ (_b = window.getSelection()) == null ? void 0 : _b.collapseToEnd();
3110
+ },
3111
+ allow: ({ state, range }) => {
3112
+ const $from = state.doc.resolve(range.from);
3113
+ const type = state.schema.nodes[this.name];
3114
+ const allow = !!$from.parent.type.contentMatch.matchType(type);
3115
+ return allow;
3116
+ }
3117
+ }
3118
+ };
3119
+ },
3120
+ addAttributes() {
3121
+ return {
3122
+ id: {
3123
+ default: null,
3124
+ parseHTML: (element) => element.getAttribute("data-id"),
3125
+ renderHTML: (attributes) => {
3126
+ if (!attributes.id) {
3127
+ return {};
3128
+ }
3129
+ return {
3130
+ "data-id": attributes.id
3131
+ };
3132
+ }
3133
+ },
3134
+ label: {
3135
+ default: null,
3136
+ parseHTML: (element) => element.getAttribute("data-label"),
3137
+ renderHTML: (attributes) => {
3138
+ if (!attributes.label) {
3139
+ return {};
3140
+ }
3141
+ return {
3142
+ "data-label": attributes.label
3143
+ };
3144
+ }
3145
+ },
3146
+ fallback: {
3147
+ default: null,
3148
+ parseHTML: (element) => element.getAttribute("data-fallback"),
3149
+ renderHTML: (attributes) => {
3150
+ if (!attributes.fallback) {
3151
+ return {};
3152
+ }
3153
+ return {
3154
+ "data-fallback": attributes.fallback
3155
+ };
3156
+ }
3157
+ },
3158
+ required: {
3159
+ default: true,
3160
+ parseHTML: (element) => element.hasAttribute("data-required"),
3161
+ renderHTML: (attributes) => {
3162
+ var _a;
3163
+ return {
3164
+ "data-required": (_a = attributes == null ? void 0 : attributes.required) != null ? _a : true
3165
+ };
3166
+ }
3167
+ }
3168
+ };
3169
+ },
3170
+ parseHTML() {
3171
+ return [
3172
+ {
3173
+ tag: `div[data-type="${this.name}"]`
3174
+ }
3175
+ ];
3176
+ },
3177
+ renderHTML({ node, HTMLAttributes: HTMLAttributes2 }) {
3178
+ return [
3179
+ "div",
3180
+ mergeAttributes7({ "data-type": this.name }, HTMLAttributes2),
3181
+ this.options.renderLabel({
3182
+ options: this.options,
3183
+ node
3184
+ })
3185
+ ];
3186
+ },
3187
+ renderText({ node }) {
3188
+ return this.options.renderLabel({
3189
+ options: this.options,
3190
+ node
3191
+ });
3192
+ },
3193
+ addKeyboardShortcuts() {
3194
+ return {
3195
+ Backspace: () => this.editor.commands.command(({ tr, state }) => {
3196
+ let isMention = false;
3197
+ const { selection } = state;
3198
+ const { empty, anchor } = selection;
3199
+ if (!empty) {
3200
+ return false;
3201
+ }
3202
+ state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
3203
+ if (node.type.name === this.name) {
3204
+ isMention = true;
3205
+ tr.insertText(
3206
+ this.options.suggestion.char || "",
3207
+ pos,
3208
+ pos + node.nodeSize
3209
+ );
3210
+ return false;
3211
+ }
3212
+ });
3213
+ return isMention;
3214
+ })
3215
+ };
3216
+ },
3217
+ addProseMirrorPlugins() {
3218
+ return [
3219
+ Suggestion(__spreadValues({
3220
+ editor: this.editor
3221
+ }, this.options.suggestion))
3222
+ ];
3223
+ },
3224
+ addNodeView() {
3225
+ return ReactNodeViewRenderer2(VariableView, {
3226
+ className: "mly-relative mly-inline-block",
3227
+ as: "div"
3228
+ });
2734
3229
  }
2735
- }
3230
+ });
2736
3231
 
2737
3232
  // src/editor/components/ui/link-input-popover.tsx
2738
- import { useMemo as useMemo2 } from "react";
2739
- import { Fragment as Fragment2, jsx as jsx27, jsxs as jsxs11 } from "react/jsx-runtime";
3233
+ import { Fragment as Fragment2, jsx as jsx28, jsxs as jsxs12 } from "react/jsx-runtime";
2740
3234
  var LINK_PROTOCOL_REGEX = /https?:\/\//;
2741
3235
  function LinkInputPopover(props) {
2742
- var _a;
3236
+ var _a, _b, _c;
2743
3237
  const {
2744
3238
  defaultValue = "",
2745
3239
  onValueChange,
@@ -2756,14 +3250,13 @@ function LinkInputPopover(props) {
2756
3250
  const [isOpen, setIsOpen] = useState3(false);
2757
3251
  const [protocol, setProtocol] = useState3(defaultProtocol || "https://");
2758
3252
  const [isEditing, setIsEditing] = useState3(!isVariable);
2759
- const linkInputRef = useRef3(null);
2760
- const {
2761
- variables = [],
2762
- variableTriggerCharacter = DEFAULT_VARIABLE_TRIGGER_CHAR,
2763
- renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION,
2764
- placeholderUrl = DEFAULT_PLACEHOLDER_URL
2765
- } = useMailyContext();
2766
- const autoCompleteOptions = useMemo2(() => {
3253
+ const linkInputRef = useRef4(null);
3254
+ const { placeholderUrl = DEFAULT_PLACEHOLDER_URL } = useMailyContext();
3255
+ const options = useVariableOptions(editor);
3256
+ const renderVariable = options == null ? void 0 : options.renderVariable;
3257
+ const variables = options == null ? void 0 : options.variables;
3258
+ const variableTriggerCharacter = (_c = (_b = options == null ? void 0 : options.suggestion) == null ? void 0 : _b.char) != null ? _c : DEFAULT_VARIABLE_TRIGGER_CHAR;
3259
+ const autoCompleteOptions = useMemo5(() => {
2767
3260
  const withoutTrigger = defaultUrlWithoutProtocol.replace(
2768
3261
  new RegExp(variableTriggerCharacter, "g"),
2769
3262
  ""
@@ -2773,8 +3266,8 @@ function LinkInputPopover(props) {
2773
3266
  from: "bubble-variable",
2774
3267
  editor
2775
3268
  }).map((variable) => variable.name);
2776
- }, [variables, defaultUrlWithoutProtocol, editor]);
2777
- const popoverButton = /* @__PURE__ */ jsx27(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx27(
3269
+ }, [variables, variableTriggerCharacter, defaultUrlWithoutProtocol, editor]);
3270
+ const popoverButton = /* @__PURE__ */ jsx28(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx28(
2778
3271
  BaseButton,
2779
3272
  {
2780
3273
  variant: "ghost",
@@ -2782,19 +3275,19 @@ function LinkInputPopover(props) {
2782
3275
  type: "button",
2783
3276
  className: "mly-size-7",
2784
3277
  "data-state": !!defaultUrlWithoutProtocol,
2785
- children: /* @__PURE__ */ jsx27(Icon, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5] mly-text-midnight-gray" })
3278
+ children: /* @__PURE__ */ jsx28(Icon, { className: "mly-h-3 mly-w-3 mly-shrink-0 mly-stroke-[2.5] mly-text-midnight-gray" })
2786
3279
  }
2787
3280
  ) });
2788
3281
  const normalizeProtocol = (value, p = protocol) => {
2789
3282
  value = value == null ? void 0 : value.replace(LINK_PROTOCOL_REGEX, "");
2790
3283
  return p + value;
2791
3284
  };
2792
- return /* @__PURE__ */ jsxs11(Popover, { open: isOpen, onOpenChange: setIsOpen, children: [
2793
- tooltip ? /* @__PURE__ */ jsxs11(Tooltip, { children: [
2794
- /* @__PURE__ */ jsx27(TooltipTrigger, { asChild: true, children: popoverButton }),
2795
- /* @__PURE__ */ jsx27(TooltipContent, { sideOffset: 8, children: tooltip })
3285
+ return /* @__PURE__ */ jsxs12(Popover, { open: isOpen, onOpenChange: setIsOpen, children: [
3286
+ tooltip ? /* @__PURE__ */ jsxs12(Tooltip, { children: [
3287
+ /* @__PURE__ */ jsx28(TooltipTrigger, { asChild: true, children: popoverButton }),
3288
+ /* @__PURE__ */ jsx28(TooltipContent, { sideOffset: 8, children: tooltip })
2796
3289
  ] }) : popoverButton,
2797
- /* @__PURE__ */ jsx27(
3290
+ /* @__PURE__ */ jsx28(
2798
3291
  PopoverContent,
2799
3292
  {
2800
3293
  align: "end",
@@ -2802,7 +3295,7 @@ function LinkInputPopover(props) {
2802
3295
  className: "mly-w-max mly-rounded-none mly-border-none mly-bg-transparent !mly-p-0 mly-shadow-none",
2803
3296
  sideOffset: 8,
2804
3297
  onCloseAutoFocus: (e) => e.preventDefault(),
2805
- children: /* @__PURE__ */ jsx27(
3298
+ children: /* @__PURE__ */ jsx28(
2806
3299
  "form",
2807
3300
  {
2808
3301
  onSubmit: (e) => {
@@ -2815,8 +3308,8 @@ function LinkInputPopover(props) {
2815
3308
  onValueChange == null ? void 0 : onValueChange(value);
2816
3309
  setIsOpen(false);
2817
3310
  },
2818
- children: /* @__PURE__ */ jsxs11("div", { className: "mly-isolate mly-flex mly-rounded-lg", children: [
2819
- !isEditing && /* @__PURE__ */ jsx27("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__ */ jsx27(
3311
+ children: /* @__PURE__ */ jsxs12("div", { className: "mly-isolate mly-flex mly-rounded-lg", children: [
3312
+ !isEditing && /* @__PURE__ */ jsx28("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__ */ jsx28(
2820
3313
  "button",
2821
3314
  {
2822
3315
  onClick: () => {
@@ -2837,9 +3330,9 @@ function LinkInputPopover(props) {
2837
3330
  })
2838
3331
  }
2839
3332
  ) }),
2840
- isEditing && /* @__PURE__ */ jsxs11(Fragment2, { children: [
2841
- /* @__PURE__ */ jsxs11("div", { className: "mly-relative", children: [
2842
- /* @__PURE__ */ jsxs11(
3333
+ isEditing && /* @__PURE__ */ jsxs12(Fragment2, { children: [
3334
+ /* @__PURE__ */ jsxs12("div", { className: "mly-relative", children: [
3335
+ /* @__PURE__ */ jsxs12(
2843
3336
  "select",
2844
3337
  {
2845
3338
  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",
@@ -2856,12 +3349,12 @@ function LinkInputPopover(props) {
2856
3349
  onValueChange == null ? void 0 : onValueChange(newValue);
2857
3350
  },
2858
3351
  children: [
2859
- /* @__PURE__ */ jsx27("option", { value: "https://", children: "https://" }),
2860
- /* @__PURE__ */ jsx27("option", { value: "http://", children: "http://" })
3352
+ /* @__PURE__ */ jsx28("option", { value: "https://", children: "https://" }),
3353
+ /* @__PURE__ */ jsx28("option", { value: "http://", children: "http://" })
2861
3354
  ]
2862
3355
  }
2863
3356
  ),
2864
- /* @__PURE__ */ jsx27("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__ */ jsx27(
3357
+ /* @__PURE__ */ jsx28("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__ */ jsx28(
2865
3358
  ChevronDownIcon,
2866
3359
  {
2867
3360
  size: 16,
@@ -2871,9 +3364,10 @@ function LinkInputPopover(props) {
2871
3364
  }
2872
3365
  ) })
2873
3366
  ] }),
2874
- /* @__PURE__ */ jsx27(
3367
+ /* @__PURE__ */ jsx28(
2875
3368
  InputAutocomplete,
2876
3369
  {
3370
+ editor,
2877
3371
  value: defaultUrlWithoutProtocol,
2878
3372
  onValueChange: (value) => {
2879
3373
  let newValue = normalizeProtocol(value);
@@ -2909,7 +3403,7 @@ function LinkInputPopover(props) {
2909
3403
  // src/editor/components/ui/select.tsx
2910
3404
  import { useId } from "react";
2911
3405
  import { ChevronDownIcon as ChevronDownIcon2 } from "lucide-react";
2912
- import { jsx as jsx28, jsxs as jsxs12 } from "react/jsx-runtime";
3406
+ import { jsx as jsx29, jsxs as jsxs13 } from "react/jsx-runtime";
2913
3407
  function Select(props) {
2914
3408
  const {
2915
3409
  label,
@@ -2922,24 +3416,24 @@ function Select(props) {
2922
3416
  iconClassName
2923
3417
  } = props;
2924
3418
  const selectId = `mly${useId()}`;
2925
- const content = /* @__PURE__ */ jsxs12("div", { className: "mly-relative", children: [
2926
- /* @__PURE__ */ jsx28("label", { htmlFor: selectId, className: "mly-sr-only", children: label }),
2927
- Icon && /* @__PURE__ */ jsx28("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__ */ jsx28(Icon, { className: cn("mly-size-3", iconClassName) }) }),
2928
- /* @__PURE__ */ jsx28(
3419
+ const content = /* @__PURE__ */ jsxs13("div", { className: "mly-relative", children: [
3420
+ /* @__PURE__ */ jsx29("label", { htmlFor: selectId, className: "mly-sr-only", children: label }),
3421
+ Icon && /* @__PURE__ */ jsx29("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__ */ jsx29(Icon, { className: cn("mly-size-3", iconClassName) }) }),
3422
+ /* @__PURE__ */ jsx29(
2929
3423
  "select",
2930
3424
  {
2931
3425
  id: selectId,
2932
3426
  className: cn(
2933
- "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",
3427
+ "mly-flex mly-min-h-7 mly-max-w-max mly-appearance-none mly-items-center mly-rounded-md mly-bg-white 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",
2934
3428
  !!Icon && "mly-pl-7",
2935
3429
  className
2936
3430
  ),
2937
3431
  value,
2938
3432
  onChange: (event) => onValueChange(event.target.value),
2939
- children: options.map((option) => /* @__PURE__ */ jsx28("option", { value: option.value, children: option.label }, option.value))
3433
+ children: options.map((option) => /* @__PURE__ */ jsx29("option", { value: option.value, children: option.label }, option.value))
2940
3434
  }
2941
3435
  ),
2942
- /* @__PURE__ */ jsx28("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__ */ jsx28(
3436
+ /* @__PURE__ */ jsx29("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__ */ jsx29(
2943
3437
  ChevronDownIcon2,
2944
3438
  {
2945
3439
  size: 16,
@@ -2952,167 +3446,30 @@ function Select(props) {
2952
3446
  if (!tooltip) {
2953
3447
  return content;
2954
3448
  }
2955
- return /* @__PURE__ */ jsxs12(Tooltip, { children: [
2956
- /* @__PURE__ */ jsx28(TooltipTrigger, { asChild: true, children: content }),
2957
- /* @__PURE__ */ jsx28(TooltipContent, { sideOffset: 8, children: tooltip })
3449
+ return /* @__PURE__ */ jsxs13(Tooltip, { children: [
3450
+ /* @__PURE__ */ jsx29(TooltipTrigger, { asChild: true, children: content }),
3451
+ /* @__PURE__ */ jsx29(TooltipContent, { sideOffset: 8, children: tooltip })
2958
3452
  ] });
2959
3453
  }
2960
3454
 
2961
3455
  // src/editor/nodes/button/button-view.tsx
2962
3456
  import { NodeViewWrapper as NodeViewWrapper3 } from "@tiptap/react";
2963
-
2964
- // src/editor/components/show-popover.tsx
2965
- import { Eye, InfoIcon } from "lucide-react";
2966
- import { memo, useMemo as useMemo3, useRef as useRef4, useState as useState4 } from "react";
2967
- import { jsx as jsx29, jsxs as jsxs13 } from "react/jsx-runtime";
2968
- function _ShowPopover(props) {
2969
- const { showIfKey = "", onShowIfKeyValueChange, editor } = props;
2970
- const { variables = [], renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION } = useMailyContext();
2971
- const [isUpdatingKey, setIsUpdatingKey] = useState4(false);
2972
- const inputRef = useRef4(null);
2973
- const autoCompleteOptions = useMemo3(() => {
2974
- return processVariables(variables, {
2975
- query: showIfKey || "",
2976
- from: "bubble-variable",
2977
- editor
2978
- }).map((variable) => variable.name);
2979
- }, [variables, showIfKey, editor]);
2980
- const isValidWhenKey = showIfKey || autoCompleteOptions.includes(showIfKey);
2981
- return /* @__PURE__ */ jsxs13(
2982
- Popover,
2983
- {
2984
- onOpenChange: (open) => {
2985
- if (open) {
2986
- return;
2987
- }
2988
- setIsUpdatingKey(false);
2989
- },
2990
- children: [
2991
- /* @__PURE__ */ jsxs13(Tooltip, { children: [
2992
- /* @__PURE__ */ jsx29(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx29(
2993
- PopoverTrigger,
2994
- {
2995
- className: cn(
2996
- "mly-flex mly-size-7 mly-items-center mly-justify-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",
2997
- showIfKey && "mly-bg-rose-100 mly-text-rose-800 data-[state=open]:mly-bg-rose-100 hover:mly-bg-rose-100"
2998
- ),
2999
- children: /* @__PURE__ */ jsx29(Eye, { className: "mly-h-3 mly-w-3 mly-stroke-[2.5]" })
3000
- }
3001
- ) }),
3002
- /* @__PURE__ */ jsx29(TooltipContent, { sideOffset: 8, children: "Show block conditionally" })
3003
- ] }),
3004
- /* @__PURE__ */ jsxs13(
3005
- PopoverContent,
3006
- {
3007
- className: "mly-flex mly-w-max mly-rounded-lg !mly-p-0.5",
3008
- side: "top",
3009
- sideOffset: 8,
3010
- align: "end",
3011
- onOpenAutoFocus: (e) => {
3012
- e.preventDefault();
3013
- },
3014
- onCloseAutoFocus: (e) => {
3015
- e.preventDefault();
3016
- },
3017
- children: [
3018
- /* @__PURE__ */ jsxs13("div", { className: "mly-flex mly-items-center mly-gap-1.5 mly-px-1.5 mly-text-sm mly-leading-none", children: [
3019
- "Show if",
3020
- /* @__PURE__ */ jsxs13(Tooltip, { children: [
3021
- /* @__PURE__ */ jsx29(TooltipTrigger, { children: /* @__PURE__ */ jsx29(
3022
- InfoIcon,
3023
- {
3024
- className: cn("mly-size-3 mly-stroke-[2.5] mly-text-gray-500")
3025
- }
3026
- ) }),
3027
- /* @__PURE__ */ jsx29(
3028
- TooltipContent,
3029
- {
3030
- sideOffset: 14,
3031
- className: "mly-max-w-[285px]",
3032
- align: "start",
3033
- children: "Show the block if the selected variable is true."
3034
- }
3035
- )
3036
- ] })
3037
- ] }),
3038
- !isUpdatingKey && /* @__PURE__ */ jsx29(
3039
- "button",
3040
- {
3041
- onClick: () => {
3042
- setIsUpdatingKey(true);
3043
- setTimeout(() => {
3044
- var _a;
3045
- (_a = inputRef.current) == null ? void 0 : _a.focus();
3046
- }, 0);
3047
- },
3048
- children: renderVariable({
3049
- variable: {
3050
- name: showIfKey,
3051
- valid: !!isValidWhenKey
3052
- },
3053
- fallback: "",
3054
- from: "bubble-variable",
3055
- editor
3056
- })
3057
- }
3058
- ),
3059
- isUpdatingKey && /* @__PURE__ */ jsx29(
3060
- "form",
3061
- {
3062
- onSubmit: (e) => {
3063
- e.preventDefault();
3064
- setIsUpdatingKey(false);
3065
- },
3066
- onKeyDown: (e) => {
3067
- if (e.key === "Escape") {
3068
- setIsUpdatingKey(false);
3069
- }
3070
- },
3071
- children: /* @__PURE__ */ jsx29(
3072
- InputAutocomplete,
3073
- {
3074
- value: showIfKey || "",
3075
- onValueChange: (value) => {
3076
- onShowIfKeyValueChange == null ? void 0 : onShowIfKeyValueChange(value);
3077
- },
3078
- onOutsideClick: () => {
3079
- setIsUpdatingKey(false);
3080
- },
3081
- onSelectOption: (value) => {
3082
- onShowIfKeyValueChange == null ? void 0 : onShowIfKeyValueChange(value);
3083
- setIsUpdatingKey(false);
3084
- },
3085
- autoCompleteOptions,
3086
- ref: inputRef
3087
- }
3088
- )
3089
- }
3090
- )
3091
- ]
3092
- }
3093
- )
3094
- ]
3095
- }
3096
- );
3097
- }
3098
- var ShowPopover = memo(_ShowPopover);
3457
+ import { useMemo as useMemo7 } from "react";
3099
3458
 
3100
3459
  // src/editor/nodes/button/button-label-input.tsx
3101
- import { useMemo as useMemo4 } from "react";
3102
- import { useState as useState5 } from "react";
3103
- import { useRef as useRef5 } from "react";
3460
+ import { useMemo as useMemo6, useRef as useRef5, useState as useState4 } from "react";
3104
3461
  import { jsx as jsx30, jsxs as jsxs14 } from "react/jsx-runtime";
3105
3462
  function ButtonLabelInput(props) {
3463
+ var _a, _b;
3106
3464
  const { value, onValueChange, isVariable, editor } = props;
3107
3465
  const linkInputRef = useRef5(null);
3108
- const [isEditing, setIsEditing] = useState5(!isVariable);
3109
- const {
3110
- variables = [],
3111
- variableTriggerCharacter = DEFAULT_VARIABLE_TRIGGER_CHAR,
3112
- renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION,
3113
- placeholderUrl = DEFAULT_PLACEHOLDER_URL
3114
- } = useMailyContext();
3115
- const autoCompleteOptions = useMemo4(() => {
3466
+ const [isEditing, setIsEditing] = useState4(!isVariable);
3467
+ const { placeholderUrl = DEFAULT_PLACEHOLDER_URL } = useMailyContext();
3468
+ const otps = useVariableOptions(editor);
3469
+ const variables = otps == null ? void 0 : otps.variables;
3470
+ const variableTriggerCharacter = (_b = (_a = otps == null ? void 0 : otps.suggestion) == null ? void 0 : _a.char) != null ? _b : DEFAULT_VARIABLE_TRIGGER_CHAR;
3471
+ const renderVariable = otps == null ? void 0 : otps.renderVariable;
3472
+ const autoCompleteOptions = useMemo6(() => {
3116
3473
  const withoutTrigger = value.replace(
3117
3474
  new RegExp(variableTriggerCharacter, "g"),
3118
3475
  ""
@@ -3130,8 +3487,8 @@ function ButtonLabelInput(props) {
3130
3487
  onClick: () => {
3131
3488
  setIsEditing(true);
3132
3489
  setTimeout(() => {
3133
- var _a;
3134
- (_a = linkInputRef.current) == null ? void 0 : _a.focus();
3490
+ var _a2;
3491
+ (_a2 = linkInputRef.current) == null ? void 0 : _a2.focus();
3135
3492
  }, 0);
3136
3493
  },
3137
3494
  children: renderVariable({
@@ -3148,6 +3505,7 @@ function ButtonLabelInput(props) {
3148
3505
  isEditing && /* @__PURE__ */ jsx30(
3149
3506
  InputAutocomplete,
3150
3507
  {
3508
+ editor,
3151
3509
  value,
3152
3510
  onValueChange: (value2) => {
3153
3511
  onValueChange == null ? void 0 : onValueChange(value2);
@@ -3158,8 +3516,8 @@ function ButtonLabelInput(props) {
3158
3516
  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",
3159
3517
  triggerChar: variableTriggerCharacter,
3160
3518
  onSelectOption: (value2) => {
3161
- var _a;
3162
- const isVariable2 = (_a = autoCompleteOptions.includes(value2)) != null ? _a : false;
3519
+ var _a2;
3520
+ const isVariable2 = (_a2 = autoCompleteOptions.includes(value2)) != null ? _a2 : false;
3163
3521
  if (isVariable2) {
3164
3522
  setIsEditing(false);
3165
3523
  }
@@ -3171,7 +3529,6 @@ function ButtonLabelInput(props) {
3171
3529
  }
3172
3530
 
3173
3531
  // src/editor/nodes/button/button-view.tsx
3174
- import { useMemo as useMemo5 } from "react";
3175
3532
  import { jsx as jsx31, jsxs as jsxs15 } from "react/jsx-runtime";
3176
3533
  function ButtonView(props) {
3177
3534
  const { node, editor, getPos, updateAttributes: updateAttributes2 } = props;
@@ -3191,8 +3548,9 @@ function ButtonView(props) {
3191
3548
  paddingBottom,
3192
3549
  paddingLeft
3193
3550
  } = node.attrs;
3194
- const { renderVariable = DEFAULT_RENDER_VARIABLE_FUNCTION } = useMailyContext();
3195
- const sizes = useMemo5(
3551
+ const opts = useVariableOptions(editor);
3552
+ const renderVariable = opts == null ? void 0 : opts.renderVariable;
3553
+ const sizes = useMemo7(
3196
3554
  () => ({
3197
3555
  small: {
3198
3556
  paddingX: 24,
@@ -3209,7 +3567,7 @@ function ButtonView(props) {
3209
3567
  }),
3210
3568
  []
3211
3569
  );
3212
- const size = useMemo5(() => {
3570
+ const size = useMemo7(() => {
3213
3571
  var _a;
3214
3572
  return (_a = Object.entries(sizes).find(
3215
3573
  ([, { paddingX, paddingY }]) => paddingRight === paddingX && paddingTop === paddingY
@@ -3495,7 +3853,7 @@ var DEFAULT_BUTTON_PADDING_BOTTOM = 10;
3495
3853
  var DEFAULT_BUTTON_PADDING_LEFT = 32;
3496
3854
  var allowedButtonVariant = ["filled", "outline"];
3497
3855
  var allowedButtonBorderRadius = ["sharp", "smooth", "round"];
3498
- var ButtonExtension = Node8.create({
3856
+ var ButtonExtension = Node9.create({
3499
3857
  name: "button",
3500
3858
  group: "block",
3501
3859
  atom: true,
@@ -3692,7 +4050,7 @@ var ButtonExtension = Node8.create({
3692
4050
  renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
3693
4051
  return [
3694
4052
  "div",
3695
- mergeAttributes7(HTMLAttributes2, {
4053
+ mergeAttributes8(HTMLAttributes2, {
3696
4054
  "data-type": this.name
3697
4055
  })
3698
4056
  ];
@@ -3710,7 +4068,7 @@ var ButtonExtension = Node8.create({
3710
4068
  };
3711
4069
  },
3712
4070
  addNodeView() {
3713
- return ReactNodeViewRenderer2(ButtonView, {
4071
+ return ReactNodeViewRenderer3(ButtonView, {
3714
4072
  contentDOMElementTag: "div",
3715
4073
  className: "mly-relative"
3716
4074
  });
@@ -3719,12 +4077,22 @@ var ButtonExtension = Node8.create({
3719
4077
 
3720
4078
  // src/editor/nodes/logo/logo.ts
3721
4079
  import TiptapImage from "@tiptap/extension-image";
3722
- import { ReactNodeViewRenderer as ReactNodeViewRenderer3 } from "@tiptap/react";
4080
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer4 } from "@tiptap/react";
3723
4081
 
3724
4082
  // src/editor/nodes/logo/logo-view.tsx
3725
4083
  import { NodeViewWrapper as NodeViewWrapper5 } from "@tiptap/react";
3726
- import { useEffect as useEffect4 } from "react";
3727
- import { useState as useState7 } from "react";
4084
+ import { useCallback as useCallback4, useEffect as useEffect4 } from "react";
4085
+ import { useState as useState6 } from "react";
4086
+
4087
+ // src/editor/nodes/image/image-view.tsx
4088
+ import {
4089
+ useCallback as useCallback3,
4090
+ useEffect as useEffect3,
4091
+ useRef as useRef7,
4092
+ useState as useState5
4093
+ } from "react";
4094
+ import { NodeViewWrapper as NodeViewWrapper4 } from "@tiptap/react";
4095
+ import { Ban, BracesIcon, GrabIcon, ImageOffIcon, Loader2 } from "lucide-react";
3728
4096
 
3729
4097
  // src/editor/utils/use-event.ts
3730
4098
  import { useCallback as useCallback2, useLayoutEffect, useRef as useRef6 } from "react";
@@ -3742,18 +4110,18 @@ var useEvent = (handler) => {
3742
4110
  };
3743
4111
 
3744
4112
  // src/editor/nodes/image/image-view.tsx
3745
- import { NodeViewWrapper as NodeViewWrapper4 } from "@tiptap/react";
3746
- import { Ban, BracesIcon as BracesIcon2, ImageOffIcon, Loader2 } from "lucide-react";
3747
- import { useEffect as useEffect3, useRef as useRef7, useState as useState6 } from "react";
3748
4113
  import { Fragment as Fragment3, jsx as jsx32, jsxs as jsxs16 } from "react/jsx-runtime";
3749
4114
  var MIN_WIDTH = 20;
3750
4115
  var MAX_WIDTH = 600;
3751
4116
  function ImageView(props) {
3752
4117
  const { node, updateAttributes: updateAttributes2, selected, editor } = props;
3753
- const [status, setStatus] = useState6("idle");
4118
+ const [status, setStatus] = useState5("idle");
4119
+ const [isPlaceholderImage, setIsPlaceholderImage] = useState5(false);
4120
+ const { onImageUpload, allowedMimeTypes = [] } = useImageUploadOptions(editor);
3754
4121
  const wrapperRef = useRef7(null);
3755
4122
  const imgRef = useRef7(null);
3756
- const [resizingStyle, setResizingStyle] = useState6();
4123
+ const [resizingStyle, setResizingStyle] = useState5();
4124
+ const [isDraggingOver, setIsDraggingOver] = useState5(false);
3757
4125
  const handleMouseDown = useEvent(
3758
4126
  (event) => {
3759
4127
  const imageParent = document.querySelector(
@@ -3795,25 +4163,31 @@ function ImageView(props) {
3795
4163
  window.addEventListener("mouseup", removeListeners);
3796
4164
  }
3797
4165
  );
3798
- function dragCornerButton(direction) {
3799
- return /* @__PURE__ */ jsx32(
3800
- "div",
3801
- {
3802
- role: "button",
3803
- tabIndex: 0,
3804
- onMouseDown: handleMouseDown,
3805
- "data-direction": direction,
3806
- className: "mly-bg-rose-500",
3807
- style: __spreadProps(__spreadValues(__spreadValues({
3808
- position: "absolute",
3809
- height: "10px",
3810
- width: "10px"
3811
- }, { n: { top: 0 }, s: { bottom: 0 } }[direction[0]]), { w: { left: 0 }, e: { right: 0 } }[direction[1]]), {
3812
- cursor: `${direction}-resize`
3813
- })
4166
+ const dragCornerButton = useCallback3(
4167
+ (direction) => {
4168
+ if (isPlaceholderImage) {
4169
+ return null;
3814
4170
  }
3815
- );
3816
- }
4171
+ return /* @__PURE__ */ jsx32(
4172
+ "div",
4173
+ {
4174
+ role: "button",
4175
+ tabIndex: 0,
4176
+ onMouseDown: handleMouseDown,
4177
+ "data-direction": direction,
4178
+ className: "mly-bg-rose-500",
4179
+ style: __spreadProps(__spreadValues(__spreadValues({
4180
+ position: "absolute",
4181
+ height: "10px",
4182
+ width: "10px"
4183
+ }, { n: { top: 0 }, s: { bottom: 0 } }[direction[0]]), { w: { left: 0 }, e: { right: 0 } }[direction[1]]), {
4184
+ cursor: `${direction}-resize`
4185
+ })
4186
+ }
4187
+ );
4188
+ },
4189
+ [handleMouseDown, isPlaceholderImage]
4190
+ );
3817
4191
  let { alignment = "center", width, height, src } = node.attrs || {};
3818
4192
  const _a = node.attrs || {}, {
3819
4193
  externalLink,
@@ -3827,11 +4201,40 @@ function ImageView(props) {
3827
4201
  "showIfKey"
3828
4202
  ]);
3829
4203
  const hasImageSrc = !!attrs.src;
4204
+ const isDroppable = !!onImageUpload && editor.isEditable && !hasImageSrc && !isSrcVariable && status === "idle";
4205
+ const handleFileChange = (e) => __async(this, null, function* () {
4206
+ if (!isDroppable || !e.target.files || e.target.files.length === 0) {
4207
+ return;
4208
+ }
4209
+ const file = e.target.files[0];
4210
+ yield handleImageUpload(file);
4211
+ });
4212
+ const handleImageUpload = useCallback3(
4213
+ (file) => __async(this, null, function* () {
4214
+ if (!isDroppable) {
4215
+ return;
4216
+ }
4217
+ try {
4218
+ setStatus("loading");
4219
+ const imageUrl = yield onImageUpload(file);
4220
+ updateAttributes2({ src: imageUrl });
4221
+ setIsPlaceholderImage(false);
4222
+ setStatus("loaded");
4223
+ } catch (error) {
4224
+ console.error("Error uploading image:", error);
4225
+ setStatus("error");
4226
+ }
4227
+ }),
4228
+ [onImageUpload, updateAttributes2]
4229
+ );
3830
4230
  useEffect3(() => {
3831
- if (!src) {
4231
+ var _a2, _b, _c, _d;
4232
+ if (!src || isSrcVariable) {
3832
4233
  return;
3833
4234
  }
3834
4235
  setStatus("loading");
4236
+ const isPlaceHolder = (_d = (_c = (_b = (_a2 = editor == null ? void 0 : editor.extensionStorage) == null ? void 0 : _a2.imageUpload) == null ? void 0 : _b.placeholderImages) == null ? void 0 : _c.has(src)) != null ? _d : false;
4237
+ setIsPlaceholderImage(isPlaceHolder);
3835
4238
  const img = new Image();
3836
4239
  img.src = src;
3837
4240
  img.onload = () => {
@@ -3861,15 +4264,59 @@ function ImageView(props) {
3861
4264
  img.onerror = null;
3862
4265
  };
3863
4266
  }, [src]);
4267
+ const handleDragOver = useCallback3(
4268
+ (e) => {
4269
+ if (!isDroppable) {
4270
+ return;
4271
+ }
4272
+ e.preventDefault();
4273
+ e.stopPropagation();
4274
+ setIsDraggingOver(true);
4275
+ },
4276
+ [onImageUpload]
4277
+ );
4278
+ const handleDragLeave = useCallback3(
4279
+ (e) => {
4280
+ if (!isDroppable) {
4281
+ return;
4282
+ }
4283
+ e.preventDefault();
4284
+ e.stopPropagation();
4285
+ setIsDraggingOver(false);
4286
+ },
4287
+ [onImageUpload]
4288
+ );
4289
+ const handleDrop = useCallback3(
4290
+ (e) => __async(this, null, function* () {
4291
+ var _a2;
4292
+ if (!isDroppable) {
4293
+ return;
4294
+ }
4295
+ e.preventDefault();
4296
+ e.stopPropagation();
4297
+ setIsDraggingOver(false);
4298
+ const files = (_a2 = e.dataTransfer) == null ? void 0 : _a2.files;
4299
+ if (!files || (files == null ? void 0 : files.length) === 0) {
4300
+ return;
4301
+ }
4302
+ const firstFile = files[0];
4303
+ if (!allowedMimeTypes.includes(firstFile.type)) {
4304
+ return;
4305
+ }
4306
+ yield handleImageUpload(firstFile);
4307
+ }),
4308
+ [handleImageUpload]
4309
+ );
3864
4310
  return /* @__PURE__ */ jsxs16(
3865
4311
  NodeViewWrapper4,
3866
- {
4312
+ __spreadProps(__spreadValues({
3867
4313
  as: "div",
3868
4314
  draggable: editor.isEditable,
3869
4315
  "data-drag-handle": editor.isEditable,
4316
+ className: cn("mly-image-drop-zone", isDraggingOver && "mly-drag-over"),
3870
4317
  style: __spreadValues(__spreadProps(__spreadValues({}, hasImageSrc && status === "loaded" ? __spreadValues({
3871
- width: `${width}px`,
3872
- height: `${height}px`
4318
+ width: width ? `${width}px` : void 0,
4319
+ height: height ? `${height}px` : void 0
3873
4320
  }, resizingStyle) : {}), {
3874
4321
  overflow: "hidden",
3875
4322
  position: "relative",
@@ -3881,12 +4328,35 @@ function ImageView(props) {
3881
4328
  left: { marginRight: "auto" },
3882
4329
  right: { marginLeft: "auto" }
3883
4330
  }[alignment] || {}),
3884
- ref: wrapperRef,
4331
+ ref: wrapperRef
4332
+ }, isDroppable ? {
4333
+ onDragOver: handleDragOver,
4334
+ onDragLeave: handleDragLeave,
4335
+ onDrop: handleDrop
4336
+ } : {}), {
3885
4337
  children: [
3886
- !hasImageSrc && /* @__PURE__ */ jsx32(ImageStatusLabel, { status: "idle", minHeight: height }),
4338
+ !hasImageSrc && status === "idle" && /* @__PURE__ */ jsx32(
4339
+ ImageStatusLabel,
4340
+ {
4341
+ status: "idle",
4342
+ minHeight: height,
4343
+ isDropZone: isDroppable
4344
+ }
4345
+ ),
4346
+ !hasImageSrc && status === "loading" && !isSrcVariable && /* @__PURE__ */ jsx32(ImageStatusLabel, { status: "loading", minHeight: height }),
3887
4347
  hasImageSrc && isSrcVariable && /* @__PURE__ */ jsx32(ImageStatusLabel, { status: "variable", minHeight: height }),
3888
4348
  hasImageSrc && status === "loading" && !isSrcVariable && /* @__PURE__ */ jsx32(ImageStatusLabel, { status: "loading", minHeight: height }),
3889
4349
  hasImageSrc && status === "error" && !isSrcVariable && /* @__PURE__ */ jsx32(ImageStatusLabel, { status: "error", minHeight: height }),
4350
+ isDroppable && /* @__PURE__ */ jsx32(
4351
+ "input",
4352
+ {
4353
+ type: "file",
4354
+ accept: "image/*",
4355
+ onChange: handleFileChange,
4356
+ className: "mly-absolute mly-inset-0 mly-opacity-0",
4357
+ multiple: false
4358
+ }
4359
+ ),
3890
4360
  hasImageSrc && status === "loaded" && !isSrcVariable && /* @__PURE__ */ jsxs16(Fragment3, { children: [
3891
4361
  /* @__PURE__ */ jsx32(
3892
4362
  "img",
@@ -3896,10 +4366,13 @@ function ImageView(props) {
3896
4366
  cursor: "default",
3897
4367
  marginBottom: 0
3898
4368
  }),
3899
- draggable: editor.isEditable
4369
+ draggable: editor.isEditable,
4370
+ className: cn(
4371
+ isPlaceholderImage && "mly-animate-pulse mly-opacity-40"
4372
+ )
3900
4373
  })
3901
4374
  ),
3902
- selected && editor.isEditable && /* @__PURE__ */ jsxs16(Fragment3, { children: [
4375
+ selected && editor.isEditable && !isPlaceholderImage && /* @__PURE__ */ jsxs16(Fragment3, { children: [
3903
4376
  [
3904
4377
  { left: 0, top: 0, height: "100%", width: "1px" },
3905
4378
  { right: 0, top: 0, height: "100%", width: "1px" },
@@ -3922,29 +4395,34 @@ function ImageView(props) {
3922
4395
  ] })
3923
4396
  ] })
3924
4397
  ]
3925
- }
4398
+ })
3926
4399
  );
3927
4400
  }
3928
4401
  function ImageStatusLabel(props) {
3929
- const { status, minHeight } = props;
4402
+ const _a = props, { status, minHeight, className, style, isDropZone } = _a, rest = __objRest(_a, ["status", "minHeight", "className", "style", "isDropZone"]);
3930
4403
  return /* @__PURE__ */ jsxs16(
3931
4404
  "div",
3932
- {
4405
+ __spreadProps(__spreadValues({}, rest), {
3933
4406
  className: cn(
3934
4407
  "mly-flex mly-items-center mly-justify-center mly-gap-2 mly-rounded-lg mly-bg-soft-gray mly-px-4 mly-py-2 mly-text-sm mly-font-medium",
3935
4408
  {
3936
4409
  "mly-text-gray-500 hover:mly-bg-soft-gray/60": status === "loading",
3937
4410
  "mly-text-red-500 hover:mly-bg-soft-gray/60": status === "error"
3938
- }
4411
+ },
4412
+ className
3939
4413
  ),
3940
- style: __spreadValues({}, minHeight ? {
4414
+ style: __spreadValues(__spreadValues({}, minHeight ? {
3941
4415
  minHeight
3942
- } : {}),
4416
+ } : {}), style),
3943
4417
  children: [
3944
- status === "idle" && /* @__PURE__ */ jsxs16(Fragment3, { children: [
4418
+ status === "idle" && !isDropZone && /* @__PURE__ */ jsxs16(Fragment3, { children: [
3945
4419
  /* @__PURE__ */ jsx32(ImageOffIcon, { className: "mly-size-4 mly-stroke-[2.5]" }),
3946
4420
  /* @__PURE__ */ jsx32("span", { children: "No image selected" })
3947
4421
  ] }),
4422
+ status === "idle" && isDropZone && /* @__PURE__ */ jsxs16(Fragment3, { children: [
4423
+ /* @__PURE__ */ jsx32(GrabIcon, { className: "mly-size-4 mly-stroke-[2.5]" }),
4424
+ /* @__PURE__ */ jsx32("span", { children: "Click or Drop image here" })
4425
+ ] }),
3948
4426
  status === "loading" && /* @__PURE__ */ jsxs16(Fragment3, { children: [
3949
4427
  /* @__PURE__ */ jsx32(Loader2, { className: "mly-size-4 mly-animate-spin mly-stroke-[2.5]" }),
3950
4428
  /* @__PURE__ */ jsx32("span", { children: "Loading image..." })
@@ -3954,19 +4432,22 @@ function ImageStatusLabel(props) {
3954
4432
  /* @__PURE__ */ jsx32("span", { children: "Error loading image" })
3955
4433
  ] }),
3956
4434
  status === "variable" && /* @__PURE__ */ jsxs16(Fragment3, { children: [
3957
- /* @__PURE__ */ jsx32(BracesIcon2, { className: "mly-size-4 mly-stroke-[2.5]" }),
4435
+ /* @__PURE__ */ jsx32(BracesIcon, { className: "mly-size-4 mly-stroke-[2.5]" }),
3958
4436
  /* @__PURE__ */ jsx32("span", { children: "Variable Image URL" })
3959
4437
  ] })
3960
4438
  ]
3961
- }
4439
+ })
3962
4440
  );
3963
4441
  }
3964
4442
 
3965
4443
  // src/editor/nodes/logo/logo-view.tsx
3966
4444
  import { jsx as jsx33, jsxs as jsxs17 } from "react/jsx-runtime";
3967
4445
  function LogoView(props) {
3968
- const { node, editor } = props;
3969
- const [status, setStatus] = useState7("idle");
4446
+ const { node, editor, updateAttributes: updateAttributes2 } = props;
4447
+ const [status, setStatus] = useState6("idle");
4448
+ const [isPlaceholderImage, setIsPlaceholderImage] = useState6(false);
4449
+ const [isDraggingOver, setIsDraggingOver] = useState6(false);
4450
+ const { onImageUpload, allowedMimeTypes = [] } = useImageUploadOptions(editor);
3970
4451
  let {
3971
4452
  alignment = "center",
3972
4453
  src: logoSrc,
@@ -3974,11 +4455,83 @@ function LogoView(props) {
3974
4455
  size = "sm"
3975
4456
  } = node.attrs || {};
3976
4457
  const hasImageSrc = !!logoSrc;
4458
+ const isDroppable = !!onImageUpload && editor.isEditable && !isSrcVariable && status === "idle";
4459
+ const handleFileChange = (e) => __async(this, null, function* () {
4460
+ if (!isDroppable || !e.target.files || e.target.files.length === 0) {
4461
+ return;
4462
+ }
4463
+ const file = e.target.files[0];
4464
+ yield handleImageUpload(file);
4465
+ });
4466
+ const handleImageUpload = useCallback4(
4467
+ (file) => __async(this, null, function* () {
4468
+ if (!isDroppable) {
4469
+ return;
4470
+ }
4471
+ try {
4472
+ setStatus("loading");
4473
+ const imageUrl = yield onImageUpload(file);
4474
+ updateAttributes2({ src: imageUrl });
4475
+ setIsPlaceholderImage(false);
4476
+ setStatus("loaded");
4477
+ } catch (error) {
4478
+ console.error("Error uploading image:", error);
4479
+ setStatus("error");
4480
+ }
4481
+ }),
4482
+ [onImageUpload, updateAttributes2]
4483
+ );
4484
+ const handleDragOver = useCallback4(
4485
+ (e) => {
4486
+ if (!isDroppable) {
4487
+ return;
4488
+ }
4489
+ e.preventDefault();
4490
+ e.stopPropagation();
4491
+ setIsDraggingOver(true);
4492
+ },
4493
+ [onImageUpload]
4494
+ );
4495
+ const handleDragLeave = useCallback4(
4496
+ (e) => {
4497
+ if (!isDroppable) {
4498
+ return;
4499
+ }
4500
+ e.preventDefault();
4501
+ e.stopPropagation();
4502
+ setIsDraggingOver(false);
4503
+ },
4504
+ [onImageUpload]
4505
+ );
4506
+ const handleDrop = useCallback4(
4507
+ (e) => __async(this, null, function* () {
4508
+ var _a;
4509
+ if (!isDroppable) {
4510
+ return;
4511
+ }
4512
+ e.preventDefault();
4513
+ e.stopPropagation();
4514
+ setIsDraggingOver(false);
4515
+ const files = (_a = e.dataTransfer) == null ? void 0 : _a.files;
4516
+ if (!files || (files == null ? void 0 : files.length) === 0) {
4517
+ return;
4518
+ }
4519
+ const firstFile = files[0];
4520
+ if (!allowedMimeTypes.includes(firstFile.type)) {
4521
+ return;
4522
+ }
4523
+ yield handleImageUpload(firstFile);
4524
+ }),
4525
+ [handleImageUpload]
4526
+ );
3977
4527
  useEffect4(() => {
4528
+ var _a, _b, _c, _d;
3978
4529
  if (!logoSrc) {
3979
4530
  return;
3980
4531
  }
3981
4532
  setStatus("loading");
4533
+ const isPlaceHolder = (_d = (_c = (_b = (_a = editor == null ? void 0 : editor.extensionStorage) == null ? void 0 : _a.imageUpload) == null ? void 0 : _b.placeholderImages) == null ? void 0 : _c.has(logoSrc)) != null ? _d : false;
4534
+ setIsPlaceholderImage(isPlaceHolder);
3982
4535
  const img = new Image();
3983
4536
  img.src = logoSrc;
3984
4537
  img.onload = () => {
@@ -3996,7 +4549,7 @@ function LogoView(props) {
3996
4549
  const logoSize = logoSizes[size];
3997
4550
  return /* @__PURE__ */ jsxs17(
3998
4551
  NodeViewWrapper5,
3999
- {
4552
+ __spreadProps(__spreadValues({
4000
4553
  as: "div",
4001
4554
  draggable: editor.isEditable,
4002
4555
  "data-drag-handle": editor.isEditable,
@@ -4007,11 +4560,35 @@ function LogoView(props) {
4007
4560
  lineHeight: "0px",
4008
4561
  display: "block"
4009
4562
  },
4563
+ className: cn("mly-image-drop-zone", isDraggingOver && "mly-drag-over")
4564
+ }, isDroppable ? {
4565
+ onDragOver: handleDragOver,
4566
+ onDragLeave: handleDragLeave,
4567
+ onDrop: handleDrop
4568
+ } : {}), {
4010
4569
  children: [
4011
- !hasImageSrc && /* @__PURE__ */ jsx33(ImageStatusLabel, { status: "idle", minHeight: logoSize }),
4570
+ !hasImageSrc && status === "idle" && /* @__PURE__ */ jsx33(
4571
+ ImageStatusLabel,
4572
+ {
4573
+ status: "idle",
4574
+ minHeight: logoSize,
4575
+ isDropZone: isDroppable
4576
+ }
4577
+ ),
4578
+ !hasImageSrc && status === "loading" && !isSrcVariable && /* @__PURE__ */ jsx33(ImageStatusLabel, { status: "loading", minHeight: logoSize }),
4012
4579
  hasImageSrc && isSrcVariable && /* @__PURE__ */ jsx33(ImageStatusLabel, { status: "variable", minHeight: logoSize }),
4013
4580
  hasImageSrc && status === "loading" && !isSrcVariable && /* @__PURE__ */ jsx33(ImageStatusLabel, { status: "loading", minHeight: logoSize }),
4014
4581
  hasImageSrc && status === "error" && !isSrcVariable && /* @__PURE__ */ jsx33(ImageStatusLabel, { status: "error", minHeight: logoSize }),
4582
+ isDroppable && /* @__PURE__ */ jsx33(
4583
+ "input",
4584
+ {
4585
+ type: "file",
4586
+ accept: "image/*",
4587
+ onChange: handleFileChange,
4588
+ className: "mly-absolute mly-inset-0 mly-opacity-0",
4589
+ multiple: false
4590
+ }
4591
+ ),
4015
4592
  hasImageSrc && status === "loaded" && !isSrcVariable && /* @__PURE__ */ jsx33(
4016
4593
  "img",
4017
4594
  {
@@ -4031,7 +4608,7 @@ function LogoView(props) {
4031
4608
  }
4032
4609
  )
4033
4610
  ]
4034
- }
4611
+ })
4035
4612
  );
4036
4613
  }
4037
4614
 
@@ -4132,7 +4709,7 @@ var LogoExtension = TiptapImage.extend({
4132
4709
  ];
4133
4710
  },
4134
4711
  addNodeView() {
4135
- return ReactNodeViewRenderer3(LogoView, {
4712
+ return ReactNodeViewRenderer4(LogoView, {
4136
4713
  className: "mly-relative"
4137
4714
  });
4138
4715
  }
@@ -4140,7 +4717,7 @@ var LogoExtension = TiptapImage.extend({
4140
4717
 
4141
4718
  // src/editor/nodes/image/image.ts
4142
4719
  import TiptapImage2 from "@tiptap/extension-image";
4143
- import { ReactNodeViewRenderer as ReactNodeViewRenderer4 } from "@tiptap/react";
4720
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer5 } from "@tiptap/react";
4144
4721
  var ImageExtension = TiptapImage2.extend({
4145
4722
  addAttributes() {
4146
4723
  var _a;
@@ -4148,18 +4725,24 @@ var ImageExtension = TiptapImage2.extend({
4148
4725
  width: {
4149
4726
  default: "auto",
4150
4727
  parseHTML: (element) => {
4151
- const width = element.style.width;
4152
- return width ? { width } : null;
4728
+ var _a2, _b, _c;
4729
+ return element.getAttribute("width") || ((_c = ((_a2 = element.style) == null ? void 0 : _a2.width) || ((_b = element.style) == null ? void 0 : _b.inlineSize)) == null ? void 0 : _c.replace(
4730
+ "px",
4731
+ ""
4732
+ )) || null;
4153
4733
  },
4154
- renderHTML: ({ width }) => ({ style: `width: ${width}` })
4734
+ renderHTML: ({ width }) => ({ width })
4155
4735
  },
4156
4736
  height: {
4157
4737
  default: "auto",
4158
4738
  parseHTML: (element) => {
4159
- const height = element.style.height;
4160
- return height ? { height } : null;
4739
+ var _a2, _b, _c;
4740
+ return element.getAttribute("height") || ((_c = ((_a2 = element.style) == null ? void 0 : _a2.height) || ((_b = element.style) == null ? void 0 : _b.blockSize)) == null ? void 0 : _c.replace(
4741
+ "px",
4742
+ ""
4743
+ )) || null;
4161
4744
  },
4162
- renderHTML: ({ height }) => ({ style: `height: ${height}` })
4745
+ renderHTML: ({ height }) => ({ height })
4163
4746
  },
4164
4747
  alignment: {
4165
4748
  default: "center",
@@ -4232,7 +4815,7 @@ var ImageExtension = TiptapImage2.extend({
4232
4815
  });
4233
4816
  },
4234
4817
  addNodeView() {
4235
- return ReactNodeViewRenderer4(ImageView, {
4818
+ return ReactNodeViewRenderer5(ImageView, {
4236
4819
  className: "mly-relative"
4237
4820
  });
4238
4821
  }
@@ -4308,8 +4891,8 @@ var ParagraphExtension = TiptapParagraph.extend({
4308
4891
  });
4309
4892
 
4310
4893
  // src/editor/nodes/repeat/repeat.ts
4311
- import { mergeAttributes as mergeAttributes8, Node as Node9 } from "@tiptap/core";
4312
- import { ReactNodeViewRenderer as ReactNodeViewRenderer5 } from "@tiptap/react";
4894
+ import { mergeAttributes as mergeAttributes9, Node as Node10 } from "@tiptap/core";
4895
+ import { ReactNodeViewRenderer as ReactNodeViewRenderer6 } from "@tiptap/react";
4313
4896
 
4314
4897
  // src/editor/nodes/repeat/repeat-view.tsx
4315
4898
  import { NodeViewWrapper as NodeViewWrapper6, NodeViewContent } from "@tiptap/react";
@@ -4348,7 +4931,7 @@ function RepeatView(props) {
4348
4931
  }
4349
4932
 
4350
4933
  // src/editor/nodes/repeat/repeat.ts
4351
- var RepeatExtension = Node9.create({
4934
+ var RepeatExtension = Node10.create({
4352
4935
  name: "repeat",
4353
4936
  group: "block",
4354
4937
  content: "(block|columns)+",
@@ -4399,7 +4982,7 @@ var RepeatExtension = Node9.create({
4399
4982
  renderHTML({ HTMLAttributes: HTMLAttributes2 }) {
4400
4983
  return [
4401
4984
  "div",
4402
- mergeAttributes8(HTMLAttributes2, {
4985
+ mergeAttributes9(HTMLAttributes2, {
4403
4986
  "data-type": this.name
4404
4987
  }),
4405
4988
  0
@@ -4422,7 +5005,7 @@ var RepeatExtension = Node9.create({
4422
5005
  };
4423
5006
  },
4424
5007
  addNodeView() {
4425
- return ReactNodeViewRenderer5(RepeatView, {
5008
+ return ReactNodeViewRenderer6(RepeatView, {
4426
5009
  contentDOMElementTag: "div",
4427
5010
  className: "mly-relative"
4428
5011
  });
@@ -4430,7 +5013,7 @@ var RepeatExtension = Node9.create({
4430
5013
  });
4431
5014
 
4432
5015
  // src/editor/extensions/maily-kit.tsx
4433
- var MailyKit = Extension.create({
5016
+ var MailyKit = Extension2.create({
4434
5017
  name: "maily-kit",
4435
5018
  addOptions() {
4436
5019
  return {
@@ -4536,10 +5119,28 @@ var MailyKit = Extension.create({
4536
5119
  }
4537
5120
  });
4538
5121
 
5122
+ // src/editor/extensions/placeholder.ts
5123
+ import Placeholder from "@tiptap/extension-placeholder";
5124
+ var PlaceholderExtension = Placeholder.configure({
5125
+ placeholder: ({ node }) => {
5126
+ if (node.type.name === "heading") {
5127
+ return `Heading ${node.attrs.level}`;
5128
+ } else if (node.type.name === "htmlCodeBlock") {
5129
+ return "Type your HTML code...";
5130
+ } else if (["columns", "column", "section", "repeat", "show", "blockquote"].includes(
5131
+ node.type.name
5132
+ )) {
5133
+ return "";
5134
+ }
5135
+ return "Write something or / to see commands";
5136
+ },
5137
+ includeChildren: true
5138
+ });
5139
+
4539
5140
  // src/editor/extensions/slash-command/slash-command.ts
4540
- import { Extension as Extension2 } from "@tiptap/core";
4541
- import Suggestion from "@tiptap/suggestion";
4542
- var SlashCommandExtension = Extension2.create({
5141
+ import { Extension as Extension3 } from "@tiptap/core";
5142
+ import Suggestion2 from "@tiptap/suggestion";
5143
+ var SlashCommandExtension = Extension3.create({
4543
5144
  name: "slash-command",
4544
5145
  addOptions() {
4545
5146
  return {
@@ -4553,7 +5154,7 @@ var SlashCommandExtension = Extension2.create({
4553
5154
  },
4554
5155
  addProseMirrorPlugins() {
4555
5156
  return [
4556
- Suggestion(__spreadValues({
5157
+ Suggestion2(__spreadValues({
4557
5158
  editor: this.editor
4558
5159
  }, this.options.suggestion))
4559
5160
  ];
@@ -4565,21 +5166,21 @@ import { ReactRenderer } from "@tiptap/react";
4565
5166
  import {
4566
5167
  forwardRef as forwardRef8,
4567
5168
  Fragment as Fragment4,
4568
- useCallback as useCallback3,
5169
+ useCallback as useCallback5,
4569
5170
  useEffect as useEffect5,
4570
5171
  useImperativeHandle as useImperativeHandle2,
4571
5172
  useLayoutEffect as useLayoutEffect2,
4572
5173
  useRef as useRef8,
4573
- useState as useState8
5174
+ useState as useState7
4574
5175
  } from "react";
4575
5176
  import tippy from "tippy.js";
4576
5177
  import { ChevronRightIcon } from "lucide-react";
4577
5178
  import { Fragment as Fragment5, jsx as jsx35, jsxs as jsxs19 } from "react/jsx-runtime";
4578
5179
  var CommandList = forwardRef8(function CommandList2(props, ref) {
4579
5180
  const { items: groups, command, editor } = props;
4580
- const [selectedGroupIndex, setSelectedGroupIndex] = useState8(0);
4581
- const [selectedCommandIndex, setSelectedCommandIndex] = useState8(0);
4582
- const selectItem = useCallback3(
5181
+ const [selectedGroupIndex, setSelectedGroupIndex] = useState7(0);
5182
+ const [selectedCommandIndex, setSelectedCommandIndex] = useState7(0);
5183
+ const selectItem = useCallback5(
4583
5184
  (groupIndex, commandIndex) => {
4584
5185
  const item = groups[groupIndex].commands[commandIndex];
4585
5186
  if (!item) {
@@ -4872,182 +5473,16 @@ function getSlashCommandSuggestions(groups = DEFAULT_SLASH_COMMANDS) {
4872
5473
  };
4873
5474
  }
4874
5475
 
4875
- // src/editor/nodes/variable/variable.ts
4876
- import { mergeAttributes as mergeAttributes9, Node as Node10 } from "@tiptap/core";
4877
- import { PluginKey } from "@tiptap/pm/state";
4878
- import { ReactNodeViewRenderer as ReactNodeViewRenderer6 } from "@tiptap/react";
4879
- import Suggestion2 from "@tiptap/suggestion";
4880
- var VariablePluginKey = new PluginKey("variable");
4881
- var VariableExtension = Node10.create({
4882
- name: "variable",
4883
- group: "inline",
4884
- inline: true,
4885
- selectable: true,
4886
- atom: true,
4887
- addStorage() {
4888
- return {
4889
- popover: false
4890
- };
4891
- },
4892
- addOptions() {
4893
- return {
4894
- variables: [],
4895
- triggerChar: "@",
4896
- renderLabel({ options, node }) {
4897
- var _a;
4898
- return `${(_a = node.attrs.label) != null ? _a : node.attrs.id}`;
4899
- },
4900
- suggestion: {
4901
- char: "@",
4902
- pluginKey: VariablePluginKey,
4903
- command: ({ editor, range, props }) => {
4904
- var _a, _b;
4905
- const nodeAfter = editor.view.state.selection.$to.nodeAfter;
4906
- const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" ");
4907
- if (overrideSpace) {
4908
- range.to += 1;
4909
- }
4910
- editor.chain().focus().insertContentAt(range, [
4911
- {
4912
- type: this.name,
4913
- attrs: props
4914
- },
4915
- {
4916
- type: "text",
4917
- text: " "
4918
- }
4919
- ]).run();
4920
- (_b = window.getSelection()) == null ? void 0 : _b.collapseToEnd();
4921
- },
4922
- allow: ({ state, range }) => {
4923
- const $from = state.doc.resolve(range.from);
4924
- const type = state.schema.nodes[this.name];
4925
- const allow = !!$from.parent.type.contentMatch.matchType(type);
4926
- return allow;
4927
- }
4928
- }
4929
- };
4930
- },
4931
- addAttributes() {
4932
- return {
4933
- id: {
4934
- default: null,
4935
- parseHTML: (element) => element.getAttribute("data-id"),
4936
- renderHTML: (attributes) => {
4937
- if (!attributes.id) {
4938
- return {};
4939
- }
4940
- return {
4941
- "data-id": attributes.id
4942
- };
4943
- }
4944
- },
4945
- label: {
4946
- default: null,
4947
- parseHTML: (element) => element.getAttribute("data-label"),
4948
- renderHTML: (attributes) => {
4949
- if (!attributes.label) {
4950
- return {};
4951
- }
4952
- return {
4953
- "data-label": attributes.label
4954
- };
4955
- }
4956
- },
4957
- fallback: {
4958
- default: null,
4959
- parseHTML: (element) => element.getAttribute("data-fallback"),
4960
- renderHTML: (attributes) => {
4961
- if (!attributes.fallback) {
4962
- return {};
4963
- }
4964
- return {
4965
- "data-fallback": attributes.fallback
4966
- };
4967
- }
4968
- },
4969
- required: {
4970
- default: true,
4971
- parseHTML: (element) => element.hasAttribute("data-required"),
4972
- renderHTML: (attributes) => {
4973
- var _a;
4974
- return {
4975
- "data-required": (_a = attributes == null ? void 0 : attributes.required) != null ? _a : true
4976
- };
4977
- }
4978
- }
4979
- };
4980
- },
4981
- parseHTML() {
4982
- return [
4983
- {
4984
- tag: `div[data-type="${this.name}"]`
4985
- }
4986
- ];
4987
- },
4988
- renderHTML({ node, HTMLAttributes: HTMLAttributes2 }) {
4989
- return [
4990
- "div",
4991
- mergeAttributes9({ "data-type": this.name }, HTMLAttributes2),
4992
- this.options.renderLabel({
4993
- options: this.options,
4994
- node
4995
- })
4996
- ];
4997
- },
4998
- renderText({ node }) {
4999
- return this.options.renderLabel({
5000
- options: this.options,
5001
- node
5002
- });
5003
- },
5004
- addKeyboardShortcuts() {
5005
- return {
5006
- Backspace: () => this.editor.commands.command(({ tr, state }) => {
5007
- let isMention = false;
5008
- const { selection } = state;
5009
- const { empty, anchor } = selection;
5010
- if (!empty) {
5011
- return false;
5012
- }
5013
- state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
5014
- if (node.type.name === this.name) {
5015
- isMention = true;
5016
- tr.insertText(
5017
- this.options.suggestion.char || "",
5018
- pos,
5019
- pos + node.nodeSize
5020
- );
5021
- return false;
5022
- }
5023
- });
5024
- return isMention;
5025
- })
5026
- };
5027
- },
5028
- addProseMirrorPlugins() {
5029
- return [
5030
- Suggestion2(__spreadValues({
5031
- editor: this.editor
5032
- }, this.options.suggestion))
5033
- ];
5034
- },
5035
- addNodeView() {
5036
- return ReactNodeViewRenderer6(VariableView, {
5037
- className: "mly-relative mly-inline-block",
5038
- as: "div"
5039
- });
5040
- }
5041
- });
5042
-
5043
5476
  // src/editor/nodes/variable/variable-suggestions.tsx
5044
5477
  import { ReactRenderer as ReactRenderer2 } from "@tiptap/react";
5045
- import { useRef as useRef9, forwardRef as forwardRef9, useImperativeHandle as useImperativeHandle3 } from "react";
5478
+ import { forwardRef as forwardRef9, useImperativeHandle as useImperativeHandle3, useRef as useRef9 } from "react";
5046
5479
  import tippy2 from "tippy.js";
5047
5480
  import { jsx as jsx36 } from "react/jsx-runtime";
5048
5481
  var VariableList = forwardRef9((props, ref) => {
5049
- const { items = [] } = props;
5482
+ var _a;
5483
+ const { items = [], editor } = props;
5050
5484
  const popoverRef = useRef9(null);
5485
+ const VariableSuggestionPopoverComponent = (_a = useVariableOptions(editor)) == null ? void 0 : _a.variableSuggestionsPopover;
5051
5486
  useImperativeHandle3(ref, () => ({
5052
5487
  onKeyDown: ({ event }) => {
5053
5488
  if (!popoverRef.current) {
@@ -5072,14 +5507,14 @@ var VariableList = forwardRef9((props, ref) => {
5072
5507
  }
5073
5508
  }));
5074
5509
  return /* @__PURE__ */ jsx36(
5075
- VariablePopover,
5510
+ VariableSuggestionPopoverComponent,
5076
5511
  {
5077
5512
  items,
5078
5513
  onSelectItem: (value) => {
5079
- var _a;
5514
+ var _a2;
5080
5515
  props.command({
5081
5516
  id: value.name,
5082
- required: (_a = value.required) != null ? _a : true
5517
+ required: (_a2 = value.required) != null ? _a2 : true
5083
5518
  });
5084
5519
  },
5085
5520
  ref: popoverRef
@@ -5087,10 +5522,12 @@ var VariableList = forwardRef9((props, ref) => {
5087
5522
  );
5088
5523
  });
5089
5524
  VariableList.displayName = "VariableList";
5090
- function getVariableSuggestions(variables = DEFAULT_VARIABLES, char = DEFAULT_VARIABLE_TRIGGER_CHAR, variableListComponent = VariableList) {
5525
+ function getVariableSuggestions(char = DEFAULT_VARIABLE_TRIGGER_CHAR) {
5091
5526
  return {
5092
5527
  char,
5093
5528
  items: ({ query, editor }) => {
5529
+ var _a;
5530
+ const variables = (_a = getVariableOptions(editor)) == null ? void 0 : _a.variables;
5094
5531
  return processVariables(variables, {
5095
5532
  query,
5096
5533
  editor,
@@ -5102,7 +5539,7 @@ function getVariableSuggestions(variables = DEFAULT_VARIABLES, char = DEFAULT_VA
5102
5539
  let popup = null;
5103
5540
  return {
5104
5541
  onStart: (props) => {
5105
- component = new ReactRenderer2(variableListComponent, {
5542
+ component = new ReactRenderer2(VariableList, {
5106
5543
  props,
5107
5544
  editor: props.editor
5108
5545
  });
@@ -5148,24 +5585,6 @@ function getVariableSuggestions(variables = DEFAULT_VARIABLES, char = DEFAULT_VA
5148
5585
  }
5149
5586
  };
5150
5587
  }
5151
-
5152
- // src/editor/extensions/placeholder.ts
5153
- import Placeholder from "@tiptap/extension-placeholder";
5154
- var PlaceholderExtension = Placeholder.configure({
5155
- placeholder: ({ node }) => {
5156
- if (node.type.name === "heading") {
5157
- return `Heading ${node.attrs.level}`;
5158
- } else if (node.type.name === "htmlCodeBlock") {
5159
- return "Type your HTML code...";
5160
- } else if (["columns", "column", "section", "repeat", "show", "blockquote"].includes(
5161
- node.type.name
5162
- )) {
5163
- return "";
5164
- }
5165
- return "Write something or / to see commands";
5166
- },
5167
- includeChildren: true
5168
- });
5169
5588
  export {
5170
5589
  ButtonExtension,
5171
5590
  Color,
@@ -5184,6 +5603,7 @@ export {
5184
5603
  DEFAULT_COLUMN_VERTICAL_ALIGN,
5185
5604
  DEFAULT_COLUMN_WIDTH,
5186
5605
  DEFAULT_LOGO_SIZE,
5606
+ DEFAULT_RENDER_VARIABLE_FUNCTION,
5187
5607
  DEFAULT_SECTION_ALIGN,
5188
5608
  DEFAULT_SECTION_BACKGROUND_COLOR,
5189
5609
  DEFAULT_SECTION_BORDER_COLOR,
@@ -5199,9 +5619,14 @@ export {
5199
5619
  DEFAULT_SECTION_PADDING_TOP,
5200
5620
  DEFAULT_SECTION_SHOW_IF_KEY,
5201
5621
  DEFAULT_SPACER_HEIGHT,
5622
+ DEFAULT_VARIABLES,
5623
+ DEFAULT_VARIABLE_SUGGESTION_POPOVER,
5624
+ DEFAULT_VARIABLE_TRIGGER_CHAR,
5202
5625
  Footer,
5203
5626
  HorizontalRule,
5204
5627
  ImageExtension,
5628
+ ImageUploadExtension,
5629
+ ImageUploadPlugin,
5205
5630
  LinkExtension,
5206
5631
  LogoExtension,
5207
5632
  MailyKit,
@@ -5219,6 +5644,7 @@ export {
5219
5644
  allowedLogoSize,
5220
5645
  getSlashCommandSuggestions,
5221
5646
  getVariableSuggestions,
5222
- logoSizes
5647
+ logoSizes,
5648
+ useImageUploadOptions
5223
5649
  };
5224
5650
  //# sourceMappingURL=index.mjs.map