@maily-to/core 2.0.0-beta.1 → 2.0.0-beta.10

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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/dist/blocks/index.cjs +8 -1
  3. package/dist/blocks/index.d.cts +1 -38
  4. package/dist/blocks/index.d.mts +14 -6
  5. package/dist/blocks/index.d.mts.map +1 -1
  6. package/dist/blocks/index.mjs +2 -2
  7. package/dist/extensions/index.cjs +266 -286
  8. package/dist/extensions/index.d.cts +1 -379
  9. package/dist/extensions/index.d.mts +127 -224
  10. package/dist/extensions/index.d.mts.map +1 -1
  11. package/dist/extensions/index.mjs +238 -271
  12. package/dist/index.cjs +8717 -11689
  13. package/dist/index.d.cts +1 -107
  14. package/dist/index.d.mts +711 -73
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +8397 -11474
  17. package/dist/{slash-command-BmWRVPbv.d.mts → slash-command-BrwA1bHs.d.mts} +10 -11
  18. package/dist/slash-command-BrwA1bHs.d.mts.map +1 -0
  19. package/dist/theme-D1CI7_8s.d.mts +70 -0
  20. package/dist/theme-D1CI7_8s.d.mts.map +1 -0
  21. package/dist/typography-BdOKvXfQ.mjs +911 -0
  22. package/dist/typography-D-VnwOSw.cjs +970 -0
  23. package/dist/typography-DW7VApAR.cjs +1072 -0
  24. package/dist/use-maily-editor-Atvy2kSO.cjs +3993 -0
  25. package/dist/use-maily-editor-CByaDhmT.cjs +4955 -0
  26. package/dist/use-maily-editor-idL0RNsG.mjs +4504 -0
  27. package/package.json +102 -90
  28. package/readme.md +177 -133
  29. package/src/styles/index.css +2537 -0
  30. package/dist/blocks/index.d.cts.map +0 -1
  31. package/dist/chunk-CfYAbeIz.mjs +0 -13
  32. package/dist/extensions/index.d.cts.map +0 -1
  33. package/dist/extensions/index.mjs.map +0 -1
  34. package/dist/index.css +0 -2312
  35. package/dist/index.d.cts.map +0 -1
  36. package/dist/index.mjs.map +0 -1
  37. package/dist/slash-command-BmWRVPbv.d.mts.map +0 -1
  38. package/dist/slash-command-CK0-1FwR.d.cts +0 -39
  39. package/dist/slash-command-CK0-1FwR.d.cts.map +0 -1
  40. package/dist/spacer-DBtsr3hu.cjs +0 -5768
  41. package/dist/spacer-DzZWX-wB.mjs +0 -5456
  42. package/dist/spacer-DzZWX-wB.mjs.map +0 -1
  43. package/dist/typography-CWL13acR.cjs +0 -400
  44. package/dist/typography-DhrUe809.mjs +0 -282
  45. package/dist/typography-DhrUe809.mjs.map +0 -1
  46. package/dist/variable-C9S9ZoHv.d.cts +0 -108
  47. package/dist/variable-C9S9ZoHv.d.cts.map +0 -1
  48. package/dist/variable-DVwGrg2a.d.mts +0 -108
  49. package/dist/variable-DVwGrg2a.d.mts.map +0 -1
@@ -0,0 +1,4504 @@
1
+ import { C as headerLogoWithTextVertical, D as button, E as footerCopyrightText, S as headerLogoWithTextHorizontal, T as footerCompanySignature, _ as spacer, a as heading1, b as inlineImage, c as text, d as linkCard, f as columns, g as section, h as repeat, i as hardBreak, l as bulletList, m as htmlCodeBlock, n as clearLine, o as heading2, p as divider, r as footer, s as heading3, t as blockquote, u as orderedList, w as footerCommunityFeedbackCta, x as headerLogoWithCoverImage, y as image } from "./typography-BdOKvXfQ.mjs";
2
+ import { c } from "react/compiler-runtime";
3
+ import { Fragment, forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
4
+ import { useIsoLayoutEffect } from "@base-ui/utils/useIsoLayoutEffect";
5
+ import { useRefWithInit } from "@base-ui/utils/useRefWithInit";
6
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
+ import { ArrowDownIcon, ArrowUpIcon, BracesIcon, ChevronRightIcon, CornerDownLeftIcon, FootprintsIcon, Heading1Icon } from "lucide-react";
8
+ import { Tooltip } from "@base-ui/react/tooltip";
9
+ import { autoUpdate, computePosition, flip, offset, shift, useDismiss, useFloating, useInteractions, useMergeRefs } from "@floating-ui/react";
10
+ import { isHTMLElement } from "@floating-ui/utils/dom";
11
+ import { BLOCK_CONTAINER_TYPES, DATA_NODE_TYPE_KEY, DEFAULT_BUTTON_KIND, DEFAULT_FONT_FAMILIES, DEFAULT_HTML_CODE_BLOCK_TAB, DEFAULT_TEXT_ALIGN, DEFAULT_VARIABLE_ATTRIBUTES, DEFAULT_VARIABLE_END_TRIGGER, DEFAULT_VARIABLE_START_TRIGGER, FONT_STYLES, FONT_WEIGHTS, HTML_CODE_BLOCK_TABS, MAILY_BUG_REPORT_URL, MAILY_EXTENSION_TYPES, MAILY_MARK_TYPES, MAILY_NODE_TYPES, MARGIN_BOTTOM_ABSORBER_TYPES, MARGIN_TOP_ABSORBER_TYPES, MAX_IMAGE_WIDTH_PERCENTAGE, MIN_IMAGE_WIDTH_PERCENTAGE, TEXT_ALIGNMENTS, clamp, clampImageWidthPercentage, deepMerge, deserializeVariableFromText, getColumnWidth, getColumnWidthValue, getThemeDeclarations, getVariableSegments, getVisibilityRule, getVisibilityValueSupport, hasVariableInText, invariant, isAllowedButtonKind, isAllowedTextAlignment, mergeInlineStyles, noop, parseInlineStyles, percentage, stringifyInlineStyles } from "@maily-to/shared";
12
+ import { NodeViewContent, NodeViewWrapper, ReactNodeViewRenderer, ReactRenderer, findParentNode, isNodeSelection, isTextSelection, posToDOMRect, useCurrentEditor, useEditor, useEditorState } from "@tiptap/react";
13
+ import { create } from "zustand";
14
+ import { NodeSelection, Plugin, PluginKey, Selection, TextSelection } from "@tiptap/pm/state";
15
+ import { Paragraph } from "@tiptap/extension-paragraph";
16
+ import { Text } from "@tiptap/extension-text";
17
+ import { Dropcursor, Focus, Gapcursor, Placeholder, Selection as Selection$1, UndoRedo } from "@tiptap/extensions";
18
+ import { Document } from "@tiptap/extension-document";
19
+ import { Extension, Mark, Node as Node$1, findParentNode as findParentNode$1, isNodeEmpty, mergeAttributes } from "@tiptap/core";
20
+ import { Suggestion } from "@tiptap/suggestion";
21
+ import { Code } from "@tiptap/extension-code";
22
+ import { HardBreak } from "@tiptap/extension-hard-break";
23
+ import { Heading } from "@tiptap/extension-heading";
24
+ import { Highlight } from "@tiptap/extension-highlight";
25
+ import { Italic } from "@tiptap/extension-italic";
26
+ import { Link } from "@tiptap/extension-link";
27
+ import { BulletList, ListItem, OrderedList } from "@tiptap/extension-list";
28
+ import { Strike } from "@tiptap/extension-strike";
29
+ import { TextStyle, TextStyleKit } from "@tiptap/extension-text-style";
30
+ import { Typography } from "@tiptap/extension-typography";
31
+ import { Underline } from "@tiptap/extension-underline";
32
+ import { UniqueID } from "@tiptap/extension-unique-id";
33
+ import { Blockquote } from "@tiptap/extension-blockquote";
34
+ import { Bold } from "@tiptap/extension-bold";
35
+ import { HorizontalRule } from "@tiptap/extension-horizontal-rule";
36
+ import { CodeBlockLowlight } from "@tiptap/extension-code-block-lowlight";
37
+ import html from "highlight.js/lib/languages/xml";
38
+ import { common, createLowlight } from "lowlight";
39
+ import { FileHandler } from "@tiptap/extension-file-handler";
40
+ import { Image } from "@tiptap/extension-image";
41
+ import { Table, TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
42
+ import { closeHistory } from "@tiptap/pm/history";
43
+ import { DOMParser as DOMParser$1, Slice } from "@tiptap/pm/model";
44
+ //#region src/hooks/use-value-as-ref.ts
45
+ /**
46
+ * Untracks the provided value by turning it into a ref to remove its reactivity.
47
+ *
48
+ * Used to access the passed value inside `React.useEffect` without causing the effect to re-run when the value changes.
49
+ */
50
+ function useValueAsRef(value) {
51
+ const latest = useRefWithInit(createLatestRef, value).current;
52
+ latest.next = value;
53
+ useIsoLayoutEffect(latest.effect);
54
+ return latest;
55
+ }
56
+ function createLatestRef(value) {
57
+ const latest = {
58
+ current: value,
59
+ next: value,
60
+ effect: () => {
61
+ latest.current = latest.next;
62
+ }
63
+ };
64
+ return latest;
65
+ }
66
+ //#endregion
67
+ //#region src/components/icons/arrow-icon.tsx
68
+ function ArrowIcon(props) {
69
+ const $ = c(4);
70
+ let t0;
71
+ let t1;
72
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
73
+ t0 = /* @__PURE__ */ jsx("path", {
74
+ d: "M9.66437 2.60207L4.80758 6.97318C4.07308 7.63423 3.11989 8 2.13172 8H0V10H20V8H18.5349C17.5468 8 16.5936 7.63423 15.8591 6.97318L11.0023 2.60207C10.622 2.2598 10.0447 2.25979 9.66437 2.60207Z",
75
+ "data-mly-arrow-fill": ""
76
+ });
77
+ t1 = /* @__PURE__ */ jsx("path", {
78
+ d: "M8.99542 1.85876C9.75604 1.17425 10.9106 1.17422 11.6713 1.85878L16.5281 6.22989C17.0789 6.72568 17.7938 7.00001 18.5349 7.00001L15.89 7L11.0023 2.60207C10.622 2.2598 10.0447 2.2598 9.66436 2.60207L4.77734 7L2.13171 7.00001C2.87284 7.00001 3.58774 6.72568 4.13861 6.22989L8.99542 1.85876Z",
79
+ "data-mly-arrow-border": ""
80
+ });
81
+ $[0] = t0;
82
+ $[1] = t1;
83
+ } else {
84
+ t0 = $[0];
85
+ t1 = $[1];
86
+ }
87
+ let t2;
88
+ if ($[2] !== props) {
89
+ t2 = /* @__PURE__ */ jsxs("svg", {
90
+ "data-mly-arrow-icon": "",
91
+ fill: "none",
92
+ height: "10",
93
+ viewBox: "0 0 20 10",
94
+ width: "20",
95
+ ...props,
96
+ children: [t0, t1]
97
+ });
98
+ $[2] = props;
99
+ $[3] = t2;
100
+ } else t2 = $[3];
101
+ return t2;
102
+ }
103
+ //#endregion
104
+ //#region src/hooks/use-editor-instance.ts
105
+ const EDITOR_INSTANCE_NOT_FOUND_ERROR = `Editor instance not found. Make sure to use the EditorContext.Provider or useEditor hook.
106
+
107
+ Please create an issue at ${MAILY_BUG_REPORT_URL} if you think this is a bug.
108
+ `;
109
+ /**
110
+ * Returns the active Tiptap editor instance, preferring the explicitly
111
+ * passed editor over the one from EditorContext. Throws if neither exists.
112
+ */
113
+ function useEditorInstance(editor) {
114
+ const { editor: currentEditor } = useCurrentEditor();
115
+ const editorInstance = editor || currentEditor;
116
+ invariant(editorInstance, EDITOR_INSTANCE_NOT_FOUND_ERROR);
117
+ return editorInstance;
118
+ }
119
+ //#endregion
120
+ //#region src/hooks/use-floating-store.ts
121
+ /**
122
+ * Global Zustand store that tracks FloatingUI contexts for all
123
+ * bubble menus. Menus register on mount and unregister on unmount
124
+ * so the editor can coordinate which menu is visible.
125
+ */
126
+ const useFloatingStore = create((set, get, store) => ({
127
+ contexts: [],
128
+ isDragContextOpen: false,
129
+ setDragContextOpen: (open) => {
130
+ set({ isDragContextOpen: open });
131
+ },
132
+ register: (id, context) => {
133
+ set((state) => {
134
+ if (state.contexts.find((item) => item.id === id)) return state;
135
+ return { contexts: [...state.contexts, {
136
+ id,
137
+ value: context
138
+ }] };
139
+ });
140
+ return () => {
141
+ get().unregister(id);
142
+ };
143
+ },
144
+ unregister: (id) => {
145
+ set((state) => ({ contexts: state.contexts.filter((item) => item.id !== id) }));
146
+ },
147
+ update: (id, context) => {
148
+ set((state) => ({ contexts: state.contexts.map((item) => item.id === id ? {
149
+ ...item,
150
+ value: context
151
+ } : item) }));
152
+ },
153
+ getContext: (id) => get().contexts.find((item) => item.id === id)?.value,
154
+ getAll: () => get().contexts,
155
+ reset: () => {
156
+ set(store.getInitialState());
157
+ }
158
+ }));
159
+ /** Registers a floating menu's context on mount and cleans up on unmount. */
160
+ function useRegisterFloatingContext(id, context) {
161
+ const $ = c(5);
162
+ const register = useFloatingStore(_temp$3);
163
+ let t0;
164
+ let t1;
165
+ if ($[0] !== context || $[1] !== id || $[2] !== register) {
166
+ t0 = () => register(id, context);
167
+ t1 = [
168
+ id,
169
+ context,
170
+ register
171
+ ];
172
+ $[0] = context;
173
+ $[1] = id;
174
+ $[2] = register;
175
+ $[3] = t0;
176
+ $[4] = t1;
177
+ } else {
178
+ t0 = $[3];
179
+ t1 = $[4];
180
+ }
181
+ useEffect(t0, t1);
182
+ }
183
+ function _temp$3(state) {
184
+ return state.register;
185
+ }
186
+ //#endregion
187
+ //#region src/hooks/use-on-selection-update.ts
188
+ function useOnSelectionUpdate(editor, onSelectionUpdate) {
189
+ const $ = c(4);
190
+ const callback = useValueAsRef(onSelectionUpdate);
191
+ let t0;
192
+ let t1;
193
+ if ($[0] !== callback || $[1] !== editor) {
194
+ t0 = () => {
195
+ const handler = () => {
196
+ callback.current();
197
+ };
198
+ handler();
199
+ editor.on("selectionUpdate", handler);
200
+ return () => {
201
+ editor.off("selectionUpdate", handler);
202
+ };
203
+ };
204
+ t1 = [callback, editor];
205
+ $[0] = callback;
206
+ $[1] = editor;
207
+ $[2] = t0;
208
+ $[3] = t1;
209
+ } else {
210
+ t0 = $[2];
211
+ t1 = $[3];
212
+ }
213
+ useEffect(t0, t1);
214
+ }
215
+ //#endregion
216
+ //#region src/types/floating-ui.ts
217
+ /**
218
+ * Stable IDs for each floating bubble menu. Used to register, look up,
219
+ * and coordinate visibility of menus through the floating store.
220
+ */
221
+ const FLOATING_ELEMENT_ATTRIBUTE = "data-mly-floating-element";
222
+ const FLOATING_ELEMENT_IDS = {
223
+ TEXT_BUBBLE_MENU: "text-bubble-menu",
224
+ VARIABLE_BUBBLE_MENU: "variable-bubble-menu",
225
+ SPACER_BUBBLE_MENU: "spacer-bubble-menu",
226
+ SECTION_BUBBLE_MENU: "section-bubble-menu",
227
+ COLUMNS_BUBBLE_MENU: "columns-bubble-menu",
228
+ INLINE_IMAGE_BUBBLE_MENU: "inline-image-bubble-menu",
229
+ IMAGE_BUBBLE_MENU: "image-bubble-menu",
230
+ BUTTON_BUBBLE_MENU: "button-bubble-menu",
231
+ HTML_CODE_BLOCK_BUBBLE_MENU: "html-code-block-bubble-menu",
232
+ REPEAT_BUBBLE_MENU: "repeat-bubble-menu",
233
+ LINK_CARD_BUBBLE_MENU: "link-card-bubble-menu"
234
+ };
235
+ /**
236
+ * Priority order for bubble menu visibility. When multiple menus
237
+ * could be active (e.g. text inside a button inside a section),
238
+ * the first matching menu in this list wins.
239
+ */
240
+ const FLOATING_ELEMENT_ORDER = [
241
+ FLOATING_ELEMENT_IDS.BUTTON_BUBBLE_MENU,
242
+ FLOATING_ELEMENT_IDS.HTML_CODE_BLOCK_BUBBLE_MENU,
243
+ FLOATING_ELEMENT_IDS.VARIABLE_BUBBLE_MENU,
244
+ FLOATING_ELEMENT_IDS.SPACER_BUBBLE_MENU,
245
+ FLOATING_ELEMENT_IDS.COLUMNS_BUBBLE_MENU,
246
+ FLOATING_ELEMENT_IDS.REPEAT_BUBBLE_MENU,
247
+ FLOATING_ELEMENT_IDS.SECTION_BUBBLE_MENU,
248
+ FLOATING_ELEMENT_IDS.INLINE_IMAGE_BUBBLE_MENU,
249
+ FLOATING_ELEMENT_IDS.IMAGE_BUBBLE_MENU,
250
+ FLOATING_ELEMENT_IDS.LINK_CARD_BUBBLE_MENU,
251
+ FLOATING_ELEMENT_IDS.TEXT_BUBBLE_MENU
252
+ ];
253
+ //#endregion
254
+ //#region src/utils/selection.ts
255
+ const CONTAINER_NODES = [
256
+ MAILY_NODE_TYPES.COLUMNS,
257
+ MAILY_NODE_TYPES.REPEAT,
258
+ MAILY_NODE_TYPES.SECTION,
259
+ MAILY_NODE_TYPES.BUTTON,
260
+ MAILY_NODE_TYPES.HTML_CODE_BLOCK
261
+ ];
262
+ function clearInitialNodeSelection(editor) {
263
+ const { state } = editor;
264
+ if (!(state.selection instanceof NodeSelection)) return;
265
+ const textSelection = Selection.findFrom(state.doc.resolve(0), 1, true);
266
+ if (textSelection) editor.view.dispatch(state.tr.setSelection(textSelection));
267
+ editor.view.dom.blur();
268
+ }
269
+ function findNodeClientRect(editor, nodeType) {
270
+ const activeNode = findParentNode((node) => node.type.name === nodeType)(editor.state.selection);
271
+ if (!activeNode) return null;
272
+ const dom = editor.view.nodeDOM(activeNode.pos);
273
+ return dom instanceof HTMLElement ? dom.getBoundingClientRect() : null;
274
+ }
275
+ /**
276
+ * Returns a DOMRect for the current selection. For nodes inside a
277
+ * container (columns, repeat, section, button, html code block), returns the
278
+ * container's rect so the bubble menu stays anchored to the block rather than
279
+ * the inline selection.
280
+ */
281
+ function getCurrentSelectionRect(editor) {
282
+ const { selection } = editor.state;
283
+ const { ranges } = selection;
284
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
285
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
286
+ for (const nodeType of CONTAINER_NODES) if (editor.isActive(nodeType)) return findNodeClientRect(editor, nodeType) ?? posToDOMRect(editor.view, from, to);
287
+ if (isNodeSelection(selection)) {
288
+ const node = editor.view.nodeDOM(from);
289
+ if (node instanceof HTMLElement) return node.getBoundingClientRect();
290
+ }
291
+ return posToDOMRect(editor.view, from, to);
292
+ }
293
+ /**
294
+ * Returns true if the current selection is non-empty, non-collapsed,
295
+ * and not on a disallowed node type.
296
+ */
297
+ function isValidSelection(editor, notAllowedNodes = []) {
298
+ const { doc, selection } = editor.state;
299
+ const { empty, from, to } = selection;
300
+ const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(selection);
301
+ const isNotAllowedNode = isNodeSelection(selection) && notAllowedNodes.includes(selection.node.type.name);
302
+ return !isEmptyTextBlock && !empty && !isNotAllowedNode;
303
+ }
304
+ /**
305
+ * Sets cursor position at mouse coordinates to prevent flicker
306
+ * when clicking outside the floating bubble menu. Only moves the
307
+ * cursor if the target position is inside an inline-content parent
308
+ * (skips block nodes like images and lists).
309
+ */
310
+ function moveCursorToCoords(editor, coords) {
311
+ const { state, view } = editor;
312
+ const position = view.posAtCoords(coords);
313
+ if (!position || position.pos <= 0) return;
314
+ const $pos = state.doc.resolve(position.pos);
315
+ if (!$pos.parent.inlineContent) return;
316
+ view.dispatch(state.tr.setSelection(Selection.near($pos)));
317
+ }
318
+ //#endregion
319
+ //#region src/components/interface/floating-element.tsx
320
+ const FLOATING_ELEMENT_PADDING = 8;
321
+ const FLOATING_ELEMENT_HEIGHT = 28;
322
+ const NOT_ALLOWED_NODES = [
323
+ MAILY_NODE_TYPES.IMAGE,
324
+ MAILY_NODE_TYPES.INLINE_IMAGE,
325
+ MAILY_NODE_TYPES.SPACER,
326
+ MAILY_NODE_TYPES.HORIZONTAL_RULE
327
+ ];
328
+ const FloatingElement = forwardRef((props, ref) => {
329
+ const $ = c(60);
330
+ const { children, editor: defaultEditor, floatingId, onOpenChange, open: defaultOpen, placement: t0 } = props;
331
+ const placement = t0 === void 0 ? "top" : t0;
332
+ const editor = useEditorInstance(defaultEditor);
333
+ const isDragContextOpen = useFloatingStore(_temp$2);
334
+ const preventShowRef = useRef(false);
335
+ const [isOpen, setIsOpen] = useState(defaultOpen ?? false);
336
+ const openRef = useValueAsRef(isOpen);
337
+ const elementRef = useRef(null);
338
+ let t1;
339
+ if ($[0] !== editor.commands || $[1] !== onOpenChange || $[2] !== openRef) {
340
+ t1 = (open, _event, reason) => {
341
+ if (!open && reason === "escape-key" && elementRef.current?.contains(document.activeElement)) editor.commands.focus();
342
+ setIsOpen(open);
343
+ onOpenChange?.(open);
344
+ openRef.current = open;
345
+ };
346
+ $[0] = editor.commands;
347
+ $[1] = onOpenChange;
348
+ $[2] = openRef;
349
+ $[3] = t1;
350
+ } else t1 = $[3];
351
+ const handleOpenChange = t1;
352
+ let t2;
353
+ if ($[4] !== editor.view.dom) {
354
+ t2 = (event) => {
355
+ const target = event.target;
356
+ const editorWrapper = editor.view.dom.parentElement;
357
+ if (!isHTMLElement(target) || !editorWrapper) return false;
358
+ if (target.closest(`[data-mly-floating-element]`)) return false;
359
+ return !editorWrapper.contains(target);
360
+ };
361
+ $[4] = editor.view.dom;
362
+ $[5] = t2;
363
+ } else t2 = $[5];
364
+ const handleOutsidePress = t2;
365
+ let t3;
366
+ if ($[6] !== floatingId) {
367
+ t3 = (state_0) => {
368
+ const { contexts } = useFloatingStore.getState();
369
+ const index = [...contexts.filter((context) => context.id !== floatingId && context.value.open && context.value.placement === state_0.placement).map(_temp2$2), floatingId].sort(_temp3$1).indexOf(floatingId);
370
+ if (index === 0) return 8;
371
+ return index * 36 + 8;
372
+ };
373
+ $[6] = floatingId;
374
+ $[7] = t3;
375
+ } else t3 = $[7];
376
+ const bubbleMenuOffset = t3;
377
+ let t4;
378
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
379
+ t4 = shift({ padding: 8 });
380
+ $[8] = t4;
381
+ } else t4 = $[8];
382
+ let t5;
383
+ if ($[9] !== bubbleMenuOffset) {
384
+ t5 = offset(bubbleMenuOffset);
385
+ $[9] = bubbleMenuOffset;
386
+ $[10] = t5;
387
+ } else t5 = $[10];
388
+ let t6;
389
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
390
+ t6 = flip();
391
+ $[11] = t6;
392
+ } else t6 = $[11];
393
+ let t7;
394
+ if ($[12] !== t5) {
395
+ t7 = [
396
+ t4,
397
+ t5,
398
+ t6
399
+ ];
400
+ $[12] = t5;
401
+ $[13] = t7;
402
+ } else t7 = $[13];
403
+ let t8;
404
+ if ($[14] !== floatingId || $[15] !== handleOpenChange || $[16] !== isOpen || $[17] !== placement || $[18] !== t7) {
405
+ t8 = {
406
+ nodeId: floatingId,
407
+ open: isOpen,
408
+ onOpenChange: handleOpenChange,
409
+ whileElementsMounted: autoUpdate,
410
+ placement,
411
+ middleware: t7
412
+ };
413
+ $[14] = floatingId;
414
+ $[15] = handleOpenChange;
415
+ $[16] = isOpen;
416
+ $[17] = placement;
417
+ $[18] = t7;
418
+ $[19] = t8;
419
+ } else t8 = $[19];
420
+ const { context: context_1, floatingStyles, placement: floatingPlacement, refs } = useFloating(t8);
421
+ useRegisterFloatingContext(floatingId, context_1);
422
+ let t9;
423
+ if ($[20] !== handleOutsidePress) {
424
+ t9 = {
425
+ enabled: true,
426
+ escapeKey: true,
427
+ outsidePress: handleOutsidePress
428
+ };
429
+ $[20] = handleOutsidePress;
430
+ $[21] = t9;
431
+ } else t9 = $[21];
432
+ const dismiss = useDismiss(context_1, t9);
433
+ let t10;
434
+ if ($[22] !== dismiss) {
435
+ t10 = [dismiss];
436
+ $[22] = dismiss;
437
+ $[23] = t10;
438
+ } else t10 = $[23];
439
+ const { getReferenceProps } = useInteractions(t10);
440
+ let t11;
441
+ if ($[24] !== defaultOpen || $[25] !== editor || $[26] !== refs) {
442
+ t11 = () => {
443
+ const preventShow = preventShowRef.current;
444
+ const rect = getCurrentSelectionRect(editor);
445
+ if (rect && defaultOpen !== void 0 && !preventShow) {
446
+ setIsOpen(defaultOpen);
447
+ refs.setReference({ getBoundingClientRect: () => rect });
448
+ return;
449
+ }
450
+ if (!isValidSelection(editor, NOT_ALLOWED_NODES) || preventShow || !editor.isEditable) {
451
+ setIsOpen(false);
452
+ return;
453
+ }
454
+ setIsOpen(true);
455
+ refs.setReference({ getBoundingClientRect: () => rect });
456
+ };
457
+ $[24] = defaultOpen;
458
+ $[25] = editor;
459
+ $[26] = refs;
460
+ $[27] = t11;
461
+ } else t11 = $[27];
462
+ const handleSelectionChange = t11;
463
+ useOnSelectionUpdate(editor, handleSelectionChange);
464
+ let t12;
465
+ let t13;
466
+ if ($[28] !== editor || $[29] !== handleSelectionChange) {
467
+ t12 = () => {
468
+ const editorView = editor.view;
469
+ const handleMouseDown = (event_0) => {
470
+ if (event_0.button !== 0) return;
471
+ preventShowRef.current = true;
472
+ if (event_0.detail <= 1) moveCursorToCoords(editor, {
473
+ left: event_0.clientX,
474
+ top: event_0.clientY
475
+ });
476
+ };
477
+ const handleMouseUp = () => {
478
+ if (!preventShowRef.current) return;
479
+ preventShowRef.current = false;
480
+ handleSelectionChange();
481
+ };
482
+ editorView.dom.addEventListener("mousedown", handleMouseDown);
483
+ editorView.root.addEventListener("mouseup", handleMouseUp);
484
+ return () => {
485
+ editorView.dom.removeEventListener("mousedown", handleMouseDown);
486
+ editorView.root.removeEventListener("mouseup", handleMouseUp);
487
+ };
488
+ };
489
+ t13 = [editor, handleSelectionChange];
490
+ $[28] = editor;
491
+ $[29] = handleSelectionChange;
492
+ $[30] = t12;
493
+ $[31] = t13;
494
+ } else {
495
+ t12 = $[30];
496
+ t13 = $[31];
497
+ }
498
+ useEffect(t12, t13);
499
+ let t14;
500
+ let t15;
501
+ if ($[32] !== handleSelectionChange || $[33] !== openRef) {
502
+ t14 = () => {
503
+ const handleResize = () => {
504
+ if (!openRef.current) return;
505
+ handleSelectionChange();
506
+ };
507
+ window.addEventListener("resize", handleResize);
508
+ window.addEventListener("scroll", handleResize);
509
+ return () => {
510
+ window.removeEventListener("resize", handleResize);
511
+ window.removeEventListener("scroll", handleResize);
512
+ };
513
+ };
514
+ t15 = [handleSelectionChange, openRef];
515
+ $[32] = handleSelectionChange;
516
+ $[33] = openRef;
517
+ $[34] = t14;
518
+ $[35] = t15;
519
+ } else {
520
+ t14 = $[34];
521
+ t15 = $[35];
522
+ }
523
+ useEffect(t14, t15);
524
+ let t16;
525
+ if ($[36] !== editor.view.dom || $[37] !== handleOpenChange) {
526
+ t16 = () => {
527
+ const editorViewDom = editor.view.dom;
528
+ const handleDrag = () => {
529
+ handleOpenChange(false);
530
+ };
531
+ editorViewDom.addEventListener("dragstart", handleDrag);
532
+ editorViewDom.addEventListener("dragover", handleDrag);
533
+ return () => {
534
+ editorViewDom.removeEventListener("dragstart", handleDrag);
535
+ editorViewDom.removeEventListener("dragover", handleDrag);
536
+ };
537
+ };
538
+ $[36] = editor.view.dom;
539
+ $[37] = handleOpenChange;
540
+ $[38] = t16;
541
+ } else t16 = $[38];
542
+ let t17;
543
+ if ($[39] !== editor || $[40] !== handleOpenChange) {
544
+ t17 = [editor, handleOpenChange];
545
+ $[39] = editor;
546
+ $[40] = handleOpenChange;
547
+ $[41] = t17;
548
+ } else t17 = $[41];
549
+ useEffect(t16, t17);
550
+ let t18;
551
+ if ($[42] !== ref || $[43] !== refs.setFloating) {
552
+ t18 = [
553
+ refs.setFloating,
554
+ elementRef,
555
+ ref
556
+ ];
557
+ $[42] = ref;
558
+ $[43] = refs.setFloating;
559
+ $[44] = t18;
560
+ } else t18 = $[44];
561
+ const finalRef = useMergeRefs(t18);
562
+ let t19;
563
+ if ($[45] !== floatingId) {
564
+ t19 = FLOATING_ELEMENT_ORDER.toReversed().indexOf(floatingId);
565
+ $[45] = floatingId;
566
+ $[46] = t19;
567
+ } else t19 = $[46];
568
+ const zIndex = 99 - t19 * (floatingPlacement === "top" ? 1 : -1);
569
+ if (!isOpen || isDragContextOpen) return null;
570
+ let t20;
571
+ if ($[47] !== getReferenceProps) {
572
+ t20 = getReferenceProps();
573
+ $[47] = getReferenceProps;
574
+ $[48] = t20;
575
+ } else t20 = $[48];
576
+ let t21;
577
+ if ($[49] !== floatingId) {
578
+ t21 = { [FLOATING_ELEMENT_ATTRIBUTE]: floatingId };
579
+ $[49] = floatingId;
580
+ $[50] = t21;
581
+ } else t21 = $[50];
582
+ let t22;
583
+ if ($[51] !== floatingStyles || $[52] !== zIndex) {
584
+ t22 = {
585
+ ...floatingStyles,
586
+ zIndex
587
+ };
588
+ $[51] = floatingStyles;
589
+ $[52] = zIndex;
590
+ $[53] = t22;
591
+ } else t22 = $[53];
592
+ let t23;
593
+ if ($[54] !== children || $[55] !== finalRef || $[56] !== t20 || $[57] !== t21 || $[58] !== t22) {
594
+ t23 = /* @__PURE__ */ jsx("div", {
595
+ ...t20,
596
+ ...t21,
597
+ ref: finalRef,
598
+ style: t22,
599
+ children
600
+ });
601
+ $[54] = children;
602
+ $[55] = finalRef;
603
+ $[56] = t20;
604
+ $[57] = t21;
605
+ $[58] = t22;
606
+ $[59] = t23;
607
+ } else t23 = $[59];
608
+ return t23;
609
+ });
610
+ FloatingElement.displayName = "FloatingElement";
611
+ function _temp$2(state) {
612
+ return state.isDragContextOpen;
613
+ }
614
+ function _temp2$2(context_0) {
615
+ return context_0.id;
616
+ }
617
+ function _temp3$1(a, b) {
618
+ return FLOATING_ELEMENT_ORDER.indexOf(a) - FLOATING_ELEMENT_ORDER.indexOf(b);
619
+ }
620
+ //#endregion
621
+ //#region src/components/interface/tooltip.tsx
622
+ const Tooltip$1 = Tooltip.Root;
623
+ const TooltipProvider = Tooltip.Provider;
624
+ const TooltipTrigger = Tooltip.Trigger;
625
+ function TooltipPositioner(props) {
626
+ const $ = c(10);
627
+ let container;
628
+ let rest;
629
+ let t0;
630
+ if ($[0] !== props) {
631
+ ({container, sideOffset: t0, ...rest} = props);
632
+ $[0] = props;
633
+ $[1] = container;
634
+ $[2] = rest;
635
+ $[3] = t0;
636
+ } else {
637
+ container = $[1];
638
+ rest = $[2];
639
+ t0 = $[3];
640
+ }
641
+ const sideOffset = t0 === void 0 ? 8 : t0;
642
+ let t1;
643
+ if ($[4] !== rest || $[5] !== sideOffset) {
644
+ t1 = /* @__PURE__ */ jsx(Tooltip.Positioner, {
645
+ sideOffset,
646
+ ...rest
647
+ });
648
+ $[4] = rest;
649
+ $[5] = sideOffset;
650
+ $[6] = t1;
651
+ } else t1 = $[6];
652
+ let t2;
653
+ if ($[7] !== container || $[8] !== t1) {
654
+ t2 = /* @__PURE__ */ jsx(Tooltip.Portal, {
655
+ container,
656
+ children: t1
657
+ });
658
+ $[7] = container;
659
+ $[8] = t1;
660
+ $[9] = t2;
661
+ } else t2 = $[9];
662
+ return t2;
663
+ }
664
+ function TooltipPopup(props) {
665
+ const $ = c(2);
666
+ let t0;
667
+ if ($[0] !== props) {
668
+ t0 = /* @__PURE__ */ jsx(Tooltip.Popup, {
669
+ "data-mly-tooltip": "",
670
+ ...props
671
+ });
672
+ $[0] = props;
673
+ $[1] = t0;
674
+ } else t0 = $[1];
675
+ return t0;
676
+ }
677
+ function TooltipArrow(props) {
678
+ const $ = c(3);
679
+ let t0;
680
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
681
+ t0 = /* @__PURE__ */ jsx(ArrowIcon, {});
682
+ $[0] = t0;
683
+ } else t0 = $[0];
684
+ let t1;
685
+ if ($[1] !== props) {
686
+ t1 = /* @__PURE__ */ jsx(Tooltip.Arrow, {
687
+ "data-mly-tooltip-arrow": "",
688
+ ...props,
689
+ children: t0
690
+ });
691
+ $[1] = props;
692
+ $[2] = t1;
693
+ } else t1 = $[2];
694
+ return t1;
695
+ }
696
+ //#endregion
697
+ //#region src/utils/theme.ts
698
+ const HEADING_LEVEL_PATTERN = /^h[1-6]$/;
699
+ function getThemeSelector(type) {
700
+ const nodeType = HEADING_LEVEL_PATTERN.test(type) ? MAILY_NODE_TYPES.HEADING : type;
701
+ return `${nodeType === type ? "" : type}[${DATA_NODE_TYPE_KEY}="${nodeType}"]`;
702
+ }
703
+ function getNodeTheme(editor) {
704
+ return editor.state.doc.attrs.theme ?? {};
705
+ }
706
+ function getMergedNodeTheme(options) {
707
+ const { theme, update } = options;
708
+ const merged = deepMerge(theme, update);
709
+ const next = {};
710
+ for (const [type, declarations] of Object.entries(merged)) {
711
+ if (!declarations) continue;
712
+ const kept = {};
713
+ for (const [property, value] of Object.entries(declarations)) {
714
+ if (value === null || value === void 0 || value === "") continue;
715
+ kept[property] = value;
716
+ }
717
+ if (Object.keys(kept).length > 0) next[type] = kept;
718
+ }
719
+ return next;
720
+ }
721
+ function getNodeStyleState(options) {
722
+ const { editor, type } = options;
723
+ const attrs = editor.getAttributes(type);
724
+ const authored = parseInlineStyles(attrs.style ?? "");
725
+ const theme = getThemeDeclarations({
726
+ attrs,
727
+ theme: getNodeTheme(editor),
728
+ type
729
+ }) ?? {};
730
+ return {
731
+ authored,
732
+ resolved: mergeInlineStyles(theme, authored)
733
+ };
734
+ }
735
+ function getTypeSelector(type) {
736
+ return `[${DATA_NODE_TYPE_KEY}="${type}"]`;
737
+ }
738
+ function getSuppressionRules(options) {
739
+ const { declarations, scope, selector } = options;
740
+ const outside = BLOCK_CONTAINER_TYPES.map(getTypeSelector).join(",");
741
+ const rules = [];
742
+ if (declarations.marginTop && declarations.marginTop !== "0") {
743
+ const absorbers = MARGIN_TOP_ABSORBER_TYPES.map((type) => {
744
+ return `${scope} ${getTypeSelector(type)}+${selector}`;
745
+ });
746
+ rules.push(`${[`${scope} ${selector}:first-child`, ...absorbers].join(",")}{margin-top:0}`);
747
+ }
748
+ if (declarations.marginBottom && declarations.marginBottom !== "0") {
749
+ const absorbers = MARGIN_BOTTOM_ABSORBER_TYPES.map((type) => {
750
+ return `${scope} ${selector}:has(+${getTypeSelector(type)})`;
751
+ });
752
+ rules.push(`${[`${scope} ${selector}:last-child`, ...absorbers].join(",")}{margin-bottom:0}`);
753
+ }
754
+ if (rules.length > 0) rules.push(`${scope} :not(${outside})>${selector}{margin-top:0;margin-bottom:0}`);
755
+ return rules;
756
+ }
757
+ function getThemeCss(options) {
758
+ const { scope, theme } = options;
759
+ const rules = [];
760
+ for (const [type, declarations] of Object.entries(theme)) {
761
+ const selector = getThemeSelector(type);
762
+ const style = stringifyInlineStyles(declarations);
763
+ if (style) {
764
+ rules.push(`${scope} ${selector}{${style}}`);
765
+ rules.push(...getSuppressionRules({
766
+ declarations,
767
+ scope,
768
+ selector
769
+ }));
770
+ }
771
+ }
772
+ return rules.join("");
773
+ }
774
+ function getChildEntries(options) {
775
+ const { offset, parent, type } = options;
776
+ const entries = [];
777
+ let position = offset;
778
+ parent.forEach((child) => {
779
+ if (child.type.name === type) entries.push({
780
+ node: child,
781
+ position
782
+ });
783
+ position += child.nodeSize;
784
+ });
785
+ return entries;
786
+ }
787
+ function getShellNodes(options) {
788
+ const { doc, type } = options;
789
+ const bodies = getChildEntries({
790
+ offset: 0,
791
+ parent: doc,
792
+ type: MAILY_NODE_TYPES.BODY
793
+ });
794
+ if (type === MAILY_NODE_TYPES.BODY) return bodies;
795
+ return bodies.flatMap((body) => {
796
+ return getChildEntries({
797
+ offset: body.position + 1,
798
+ parent: body.node,
799
+ type
800
+ });
801
+ });
802
+ }
803
+ //#endregion
804
+ //#region src/extensions/document/document.ts
805
+ const DOCUMENT_VERSION = 2;
806
+ const Document$1 = Document.extend({
807
+ content: MAILY_NODE_TYPES.BODY,
808
+ addAttributes() {
809
+ return {
810
+ ...this.parent?.(),
811
+ version: { default: DOCUMENT_VERSION }
812
+ };
813
+ }
814
+ });
815
+ //#endregion
816
+ //#region ../extension-variable/dist/index.mjs
817
+ function getMarksAt(options) {
818
+ const { pos, state } = options;
819
+ return (state.storedMarks ?? state.doc.resolve(pos).marks()).map((mark) => {
820
+ return {
821
+ attrs: mark.attrs,
822
+ type: mark.type.name
823
+ };
824
+ });
825
+ }
826
+ /**
827
+ * Returns the suggestion options for a trigger of the Variable extension. These
828
+ * options are used to create a `Suggestion` ProseMirror plugin. Each plugin lets
829
+ * you define a different trigger that opens the variable menu. For example,
830
+ * you can define a `{{` trigger to insert variables and a `#` trigger to insert
831
+ * tags.
832
+ */
833
+ function getSuggestionOptions(options) {
834
+ const { addSpaceSuffix = true, char = DEFAULT_VARIABLE_START_TRIGGER, editor: tiptapEditor, extensionName, overrideSuggestionOptions, shouldScrollIntoView = false } = options;
835
+ return {
836
+ editor: tiptapEditor,
837
+ char,
838
+ pluginKey: new PluginKey(`variable-${char}`),
839
+ command: ({ editor, props, range }) => {
840
+ if (editor.view.state.selection.$to.nodeAfter?.text?.startsWith(" ")) range.to += 1;
841
+ const marks = getMarksAt({
842
+ pos: range.from,
843
+ state: editor.view.state
844
+ });
845
+ let chain = editor.chain().focus().insertContentAt(range, [{
846
+ type: extensionName,
847
+ attrs: {
848
+ ...props,
849
+ variableSuggestionChar: char
850
+ },
851
+ marks
852
+ }, ...addSpaceSuffix ? [{
853
+ type: "text",
854
+ text: " ",
855
+ marks
856
+ }] : []]);
857
+ if (shouldScrollIntoView) chain = chain.scrollIntoView();
858
+ chain.run();
859
+ editor.view.dom.ownerDocument.defaultView?.getSelection()?.collapseToEnd();
860
+ },
861
+ allow: ({ range, state }) => {
862
+ return !!state.doc.resolve(range.from).parent.type.contentMatch.matchType(state.schema.nodes[extensionName]);
863
+ },
864
+ ...overrideSuggestionOptions
865
+ };
866
+ }
867
+ function getSuggestions(options) {
868
+ return (options.options.suggestions.length ? options.options.suggestions : [options.options.suggestion]).map((suggestion) => getSuggestionOptions({
869
+ addSpaceSuffix: options.options.addSpaceSuffix,
870
+ char: suggestion.char,
871
+ editor: options.editor,
872
+ extensionName: options.name,
873
+ overrideSuggestionOptions: suggestion,
874
+ shouldScrollIntoView: options.options.shouldScrollIntoView
875
+ }));
876
+ }
877
+ function getSuggestionFromChar(options, char) {
878
+ const suggestions = getSuggestions(options);
879
+ return suggestions.find((item) => item.char === char) ?? suggestions[0] ?? null;
880
+ }
881
+ function getVariableLabel$1(node, suggestion) {
882
+ return `${suggestion?.char ?? DEFAULT_VARIABLE_START_TRIGGER}${node.attrs.label ?? node.attrs.id}`;
883
+ }
884
+ const Variable = Node$1.create({
885
+ name: MAILY_NODE_TYPES.VARIABLE,
886
+ priority: 101,
887
+ group: "inline",
888
+ inline: true,
889
+ selectable: true,
890
+ atom: true,
891
+ addOptions() {
892
+ return {
893
+ addSpaceSuffix: true,
894
+ deleteTriggerWithBackspace: false,
895
+ HTMLAttributes: {},
896
+ renderHTML({ node, options, suggestion }) {
897
+ return [
898
+ "span",
899
+ mergeAttributes(options.HTMLAttributes),
900
+ getVariableLabel$1(node, suggestion)
901
+ ];
902
+ },
903
+ renderText({ node, suggestion }) {
904
+ return getVariableLabel$1(node, suggestion);
905
+ },
906
+ shouldScrollIntoView: false,
907
+ suggestion: {},
908
+ suggestions: []
909
+ };
910
+ },
911
+ addAttributes() {
912
+ return {
913
+ id: {
914
+ parseHTML: (element) => element.getAttribute("data-id"),
915
+ renderHTML: (attributes) => attributes.id ? { "data-id": attributes.id } : {}
916
+ },
917
+ label: {
918
+ default: DEFAULT_VARIABLE_ATTRIBUTES.label,
919
+ parseHTML: (element) => element.getAttribute("data-label"),
920
+ renderHTML: (attributes) => attributes.label ? { "data-label": attributes.label } : {}
921
+ },
922
+ variableSuggestionChar: {
923
+ default: DEFAULT_VARIABLE_START_TRIGGER,
924
+ parseHTML: (element) => element.getAttribute("data-variable-suggestion-char") ?? DEFAULT_VARIABLE_START_TRIGGER,
925
+ renderHTML: (attributes) => ({ "data-variable-suggestion-char": attributes.variableSuggestionChar })
926
+ },
927
+ fallback: {
928
+ default: DEFAULT_VARIABLE_ATTRIBUTES.fallback,
929
+ parseHTML: (element) => element.getAttribute("data-fallback"),
930
+ renderHTML: (attributes) => attributes.fallback ? { "data-fallback": attributes.fallback } : {}
931
+ },
932
+ required: {
933
+ default: DEFAULT_VARIABLE_ATTRIBUTES.required,
934
+ parseHTML: (element) => element.getAttribute("data-required") !== "false",
935
+ renderHTML: (attributes) => ({ "data-required": String(attributes.required) })
936
+ },
937
+ isDefaultEditable: {
938
+ default: DEFAULT_VARIABLE_ATTRIBUTES.isDefaultEditable,
939
+ parseHTML: (element) => element.getAttribute("data-is-default-editable") !== "false" && element.getAttribute("data-hide-default-value") !== "true",
940
+ renderHTML: (attributes) => ({ "data-is-default-editable": String(attributes.isDefaultEditable) })
941
+ }
942
+ };
943
+ },
944
+ addCommands() {
945
+ return { insertVariable: (attrs) => ({ commands, state }) => commands.insertContent({
946
+ type: this.name,
947
+ attrs,
948
+ marks: getMarksAt({
949
+ pos: state.selection.from,
950
+ state
951
+ })
952
+ }) };
953
+ },
954
+ parseHTML() {
955
+ return [{ tag: `span[${DATA_NODE_TYPE_KEY}="${this.name}"]` }];
956
+ },
957
+ renderHTML({ HTMLAttributes, node }) {
958
+ const options = {
959
+ ...this.options,
960
+ HTMLAttributes: mergeAttributes({ [DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes)
961
+ };
962
+ return this.options.renderHTML({
963
+ node,
964
+ options,
965
+ suggestion: getSuggestionFromChar(this, node.attrs.variableSuggestionChar)
966
+ });
967
+ },
968
+ renderText({ node }) {
969
+ return this.options.renderText({
970
+ node,
971
+ options: this.options,
972
+ suggestion: getSuggestionFromChar(this, node.attrs.variableSuggestionChar)
973
+ });
974
+ },
975
+ addKeyboardShortcuts() {
976
+ return { Backspace: () => this.editor.commands.command(({ state, tr }) => {
977
+ const { anchor, empty } = state.selection;
978
+ if (!empty) return false;
979
+ let matched = null;
980
+ let matchedPos = 0;
981
+ state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
982
+ if (node.type.name === this.name) {
983
+ matched = node;
984
+ matchedPos = pos;
985
+ return false;
986
+ }
987
+ return true;
988
+ });
989
+ if (!matched) return false;
990
+ const variableNode = matched;
991
+ tr.insertText(this.options.deleteTriggerWithBackspace ? "" : variableNode.attrs.variableSuggestionChar, matchedPos, matchedPos + variableNode.nodeSize);
992
+ return true;
993
+ }) };
994
+ },
995
+ addProseMirrorPlugins() {
996
+ return getSuggestions(this).map(Suggestion);
997
+ }
998
+ });
999
+ //#endregion
1000
+ //#region src/utils/variable.ts
1001
+ const VARIABLE_SUGGESTION_POPOVER_ID = "mly-variable-suggestion-popover";
1002
+ function getVariableLabel(item) {
1003
+ return item.label ?? item.id ?? "";
1004
+ }
1005
+ /**
1006
+ * Filters the variable list by query prefix. If no exact match exists,
1007
+ * appends a dynamic entry so users can create variables on the fly.
1008
+ */
1009
+ function filterVariableSuggestions(variables = [], opts) {
1010
+ if (typeof variables === "function") return variables(opts);
1011
+ const query = opts.query.toLowerCase();
1012
+ const filtered = variables.filter((item) => getVariableLabel(item).toLowerCase().startsWith(query));
1013
+ if (!variables.some((item) => getVariableLabel(item).toLowerCase() === query) && query.length > 0) filtered.push({
1014
+ id: opts.query,
1015
+ label: opts.query,
1016
+ required: true,
1017
+ isDefaultEditable: true
1018
+ });
1019
+ return filtered;
1020
+ }
1021
+ //#endregion
1022
+ //#region src/components/interface/suggestion.tsx
1023
+ function SuggestionWrapper(props) {
1024
+ const $ = c(2);
1025
+ let t0;
1026
+ if ($[0] !== props) {
1027
+ t0 = /* @__PURE__ */ jsx("div", {
1028
+ ...props,
1029
+ "data-mly-suggestion": ""
1030
+ });
1031
+ $[0] = props;
1032
+ $[1] = t0;
1033
+ } else t0 = $[1];
1034
+ return t0;
1035
+ }
1036
+ function SuggestionHeader(props) {
1037
+ const $ = c(2);
1038
+ let t0;
1039
+ if ($[0] !== props) {
1040
+ t0 = /* @__PURE__ */ jsx("div", {
1041
+ ...props,
1042
+ "data-mly-suggestion-header": ""
1043
+ });
1044
+ $[0] = props;
1045
+ $[1] = t0;
1046
+ } else t0 = $[1];
1047
+ return t0;
1048
+ }
1049
+ function SuggestionKeyIcon(props) {
1050
+ const $ = c(2);
1051
+ let t0;
1052
+ if ($[0] !== props.children) {
1053
+ t0 = /* @__PURE__ */ jsx("div", {
1054
+ "data-mly-suggestion-key": "",
1055
+ children: props.children
1056
+ });
1057
+ $[0] = props.children;
1058
+ $[1] = t0;
1059
+ } else t0 = $[1];
1060
+ return t0;
1061
+ }
1062
+ function SuggestionFooter() {
1063
+ const $ = c(3);
1064
+ let t0;
1065
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1066
+ t0 = /* @__PURE__ */ jsx(SuggestionKeyIcon, { children: /* @__PURE__ */ jsx(ArrowDownIcon, { size: 12 }) });
1067
+ $[0] = t0;
1068
+ } else t0 = $[0];
1069
+ let t1;
1070
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
1071
+ t1 = /* @__PURE__ */ jsxs("div", {
1072
+ "data-mly-suggestion-hint": "",
1073
+ children: [
1074
+ t0,
1075
+ /* @__PURE__ */ jsx(SuggestionKeyIcon, { children: /* @__PURE__ */ jsx(ArrowUpIcon, { size: 12 }) }),
1076
+ /* @__PURE__ */ jsx("span", { children: "Navigate" })
1077
+ ]
1078
+ });
1079
+ $[1] = t1;
1080
+ } else t1 = $[1];
1081
+ let t2;
1082
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
1083
+ t2 = /* @__PURE__ */ jsxs("div", {
1084
+ "data-mly-suggestion-footer": "",
1085
+ children: [t1, /* @__PURE__ */ jsx(SuggestionKeyIcon, { children: /* @__PURE__ */ jsx(CornerDownLeftIcon, { size: 12 }) })]
1086
+ });
1087
+ $[2] = t2;
1088
+ } else t2 = $[2];
1089
+ return t2;
1090
+ }
1091
+ //#endregion
1092
+ //#region src/hooks/use-scroll-into-view.ts
1093
+ function useScrollIntoView(deps = []) {
1094
+ const containerRef = useRef(null);
1095
+ const activeRef = useRef(null);
1096
+ useLayoutEffect(() => {
1097
+ const container = containerRef.current;
1098
+ const activeElement = activeRef.current;
1099
+ if (!container || !activeElement) return;
1100
+ const { offsetHeight, offsetTop } = activeElement;
1101
+ container.scrollTop = offsetTop - container.getBoundingClientRect().height / 2 + offsetHeight / 2;
1102
+ }, deps);
1103
+ return {
1104
+ activeRef,
1105
+ containerRef
1106
+ };
1107
+ }
1108
+ //#endregion
1109
+ //#region src/utils/composite.ts
1110
+ const ARROW_UP = "ArrowUp";
1111
+ const ARROW_DOWN = "ArrowDown";
1112
+ const HOME = "Home";
1113
+ const ENTER = "Enter";
1114
+ //#endregion
1115
+ //#region src/extensions/variable/variable-suggestions-popover.tsx
1116
+ const NAVIGATION_KEYS$1 = /* @__PURE__ */ new Set([
1117
+ ARROW_UP,
1118
+ ARROW_DOWN,
1119
+ ENTER,
1120
+ HOME,
1121
+ "End"
1122
+ ]);
1123
+ const VariableSuggestionsPopover = forwardRef((props, ref) => {
1124
+ const { items, onSelectItem } = props;
1125
+ const [selectedIndex, setSelectedIndex] = useState(0);
1126
+ const [prevItems, setPrevItems] = useState(items);
1127
+ const { activeRef: activeItemRef, containerRef: scrollContainerRef } = useScrollIntoView([selectedIndex]);
1128
+ if (prevItems !== items) {
1129
+ setPrevItems(items);
1130
+ setSelectedIndex(0);
1131
+ if (scrollContainerRef.current) scrollContainerRef.current.scrollTop = 0;
1132
+ }
1133
+ useImperativeHandle(ref, () => ({ onKeyDown: (event) => {
1134
+ if (!NAVIGATION_KEYS$1.has(event.key) || !items.length) return false;
1135
+ let newIndex = selectedIndex;
1136
+ let shouldSelect = false;
1137
+ switch (event.key) {
1138
+ case HOME:
1139
+ newIndex = 0;
1140
+ break;
1141
+ case "End":
1142
+ newIndex = items.length - 1;
1143
+ break;
1144
+ case ARROW_UP:
1145
+ newIndex = (selectedIndex + items.length - 1) % items.length;
1146
+ break;
1147
+ case ARROW_DOWN:
1148
+ newIndex = (selectedIndex + 1) % items.length;
1149
+ break;
1150
+ case ENTER:
1151
+ shouldSelect = true;
1152
+ break;
1153
+ default: return false;
1154
+ }
1155
+ event.preventDefault();
1156
+ if (shouldSelect) {
1157
+ const item = items[selectedIndex];
1158
+ if (item) onSelectItem(item);
1159
+ return true;
1160
+ }
1161
+ if (newIndex !== selectedIndex) setSelectedIndex(newIndex);
1162
+ return true;
1163
+ } }));
1164
+ return /* @__PURE__ */ jsxs(SuggestionWrapper, { children: [
1165
+ /* @__PURE__ */ jsxs(SuggestionHeader, { children: [/* @__PURE__ */ jsx("span", { children: "Variables" }), /* @__PURE__ */ jsx(SuggestionKeyIcon, { children: /* @__PURE__ */ jsx(BracesIcon, { size: 12 }) })] }),
1166
+ /* @__PURE__ */ jsx("div", {
1167
+ "data-mly-suggestion-body": "",
1168
+ children: /* @__PURE__ */ jsx("div", {
1169
+ "data-axis": "y",
1170
+ "data-mly-scroll-fade": "",
1171
+ "data-mly-suggestion-scroll": "",
1172
+ ref: scrollContainerRef,
1173
+ children: /* @__PURE__ */ jsxs("div", {
1174
+ "data-mly-suggestion-items": "",
1175
+ children: [items.map((item, index) => /* @__PURE__ */ jsxs("button", {
1176
+ "data-mly-suggestion-item": "",
1177
+ "data-selected": index === selectedIndex ? "" : void 0,
1178
+ onClick: () => onSelectItem(item),
1179
+ ref: index === selectedIndex ? activeItemRef : null,
1180
+ type: "button",
1181
+ children: [/* @__PURE__ */ jsx(BracesIcon, {
1182
+ "data-mly-suggestion-item-icon": "",
1183
+ size: 12
1184
+ }), item.label || item.id]
1185
+ }, item.id ?? index)), items.length === 0 ? /* @__PURE__ */ jsx("div", {
1186
+ "data-mly-suggestion-empty": "",
1187
+ children: "No result"
1188
+ }) : null]
1189
+ })
1190
+ })
1191
+ }),
1192
+ /* @__PURE__ */ jsx(SuggestionFooter, {})
1193
+ ] });
1194
+ });
1195
+ VariableSuggestionsPopover.displayName = "VariableSuggestionsPopover";
1196
+ //#endregion
1197
+ //#region src/extensions/variable/variable-suggestion-list.tsx
1198
+ const VariableSuggestionList = forwardRef((props, ref) => {
1199
+ const $ = c(6);
1200
+ const { command: selectItem, items } = props;
1201
+ const popoverRef = useRef(null);
1202
+ let t0;
1203
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1204
+ t0 = () => ({ onKeyDown: (t1) => {
1205
+ const { event } = t1;
1206
+ return popoverRef.current?.onKeyDown(event) ?? false;
1207
+ } });
1208
+ $[0] = t0;
1209
+ } else t0 = $[0];
1210
+ useImperativeHandle(ref, t0);
1211
+ let t1;
1212
+ if ($[1] !== selectItem) {
1213
+ t1 = (value) => {
1214
+ selectItem({
1215
+ id: value.id,
1216
+ isDefaultEditable: value.isDefaultEditable ?? value.hideDefaultValue !== true,
1217
+ label: value.label,
1218
+ required: value.required ?? true
1219
+ });
1220
+ };
1221
+ $[1] = selectItem;
1222
+ $[2] = t1;
1223
+ } else t1 = $[2];
1224
+ let t2;
1225
+ if ($[3] !== items || $[4] !== t1) {
1226
+ t2 = /* @__PURE__ */ jsx(VariableSuggestionsPopover, {
1227
+ items,
1228
+ onSelectItem: t1,
1229
+ ref: popoverRef
1230
+ });
1231
+ $[3] = items;
1232
+ $[4] = t1;
1233
+ $[5] = t2;
1234
+ } else t2 = $[5];
1235
+ return t2;
1236
+ });
1237
+ VariableSuggestionList.displayName = "VariableSuggestionList";
1238
+ //#endregion
1239
+ //#region src/extensions/variable/variable-suggestion.ts
1240
+ async function updatePosition$1(editor, element, range) {
1241
+ const position = await computePosition({ getBoundingClientRect: () => posToDOMRect(editor.view, range.from, range.to) }, element, {
1242
+ placement: "bottom-start",
1243
+ strategy: "absolute",
1244
+ middleware: [
1245
+ shift(),
1246
+ flip(),
1247
+ offset(8)
1248
+ ]
1249
+ });
1250
+ element.style.width = "max-content";
1251
+ element.style.position = position.strategy;
1252
+ element.style.left = `${position.x}px`;
1253
+ element.style.top = `${position.y}px`;
1254
+ element.style.zIndex = "9999";
1255
+ }
1256
+ function getVariableSuggestions(char = DEFAULT_VARIABLE_START_TRIGGER) {
1257
+ return {
1258
+ char,
1259
+ items: ({ editor, query }) => filterVariableSuggestions(editor.storage.variable?.variables, {
1260
+ editor,
1261
+ query
1262
+ }),
1263
+ render: () => {
1264
+ let component = null;
1265
+ return {
1266
+ onStart: async (props) => {
1267
+ const { editor, range } = props;
1268
+ const parentElement = editor.view.dom.parentElement;
1269
+ if (!parentElement) return;
1270
+ component = new ReactRenderer(VariableSuggestionList, {
1271
+ editor,
1272
+ props
1273
+ });
1274
+ if (!props.clientRect) return;
1275
+ component.element.style.position = "absolute";
1276
+ component.element.id = VARIABLE_SUGGESTION_POPOVER_ID;
1277
+ parentElement.append(component.element);
1278
+ await updatePosition$1(editor, component.element, range);
1279
+ },
1280
+ onUpdate: async (props) => {
1281
+ const { editor, range } = props;
1282
+ if (!component) return;
1283
+ component.updateProps(props);
1284
+ if (!props.clientRect) return;
1285
+ await updatePosition$1(editor, component.element, range);
1286
+ },
1287
+ onKeyDown(props) {
1288
+ if (!component) return false;
1289
+ if (props.event.key === "Escape") {
1290
+ component.destroy();
1291
+ return true;
1292
+ }
1293
+ return component.ref?.onKeyDown(props) ?? false;
1294
+ },
1295
+ onExit() {
1296
+ if (!component) return;
1297
+ component.element.remove();
1298
+ component.destroy();
1299
+ }
1300
+ };
1301
+ }
1302
+ };
1303
+ }
1304
+ //#endregion
1305
+ //#region src/extensions/variable/variable-view.tsx
1306
+ function VariableView(props) {
1307
+ const $ = c(6);
1308
+ const { node } = props;
1309
+ const { id, label } = node.attrs;
1310
+ let t0;
1311
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1312
+ t0 = /* @__PURE__ */ jsxs("span", {
1313
+ "data-mly-variable-trigger": "",
1314
+ children: [DEFAULT_VARIABLE_START_TRIGGER, "\xA0"]
1315
+ });
1316
+ $[0] = t0;
1317
+ } else t0 = $[0];
1318
+ const t1 = label ?? id;
1319
+ let t2;
1320
+ if ($[1] !== t1) {
1321
+ t2 = /* @__PURE__ */ jsx("span", {
1322
+ "data-mly-variable-label": "",
1323
+ children: t1
1324
+ });
1325
+ $[1] = t1;
1326
+ $[2] = t2;
1327
+ } else t2 = $[2];
1328
+ let t3;
1329
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
1330
+ t3 = /* @__PURE__ */ jsxs("span", {
1331
+ "data-mly-variable-trigger": "",
1332
+ children: ["\xA0", DEFAULT_VARIABLE_END_TRIGGER]
1333
+ });
1334
+ $[3] = t3;
1335
+ } else t3 = $[3];
1336
+ let t4;
1337
+ if ($[4] !== t2) {
1338
+ t4 = /* @__PURE__ */ jsxs(NodeViewWrapper, {
1339
+ as: "span",
1340
+ "data-mly-variable": "",
1341
+ children: [
1342
+ t0,
1343
+ t2,
1344
+ t3
1345
+ ]
1346
+ });
1347
+ $[4] = t2;
1348
+ $[5] = t4;
1349
+ } else t4 = $[5];
1350
+ return t4;
1351
+ }
1352
+ //#endregion
1353
+ //#region src/extensions/variable/variable.ts
1354
+ const VariableExtension = Variable.extend({
1355
+ addOptions() {
1356
+ return {
1357
+ ...this.parent?.(),
1358
+ isIdEditable: true,
1359
+ variables: void 0
1360
+ };
1361
+ },
1362
+ addStorage() {
1363
+ return {
1364
+ isIdEditable: this.options.isIdEditable,
1365
+ variables: this.options.variables
1366
+ };
1367
+ },
1368
+ addNodeView() {
1369
+ return ReactNodeViewRenderer(VariableView, { attrs: { [DATA_NODE_TYPE_KEY]: this.name } });
1370
+ }
1371
+ }).configure({ suggestion: getVariableSuggestions() });
1372
+ //#endregion
1373
+ //#region src/utils/spacing.ts
1374
+ const MIN_SPACER_HEIGHT = 1;
1375
+ const MAX_SPACER_HEIGHT = 1e3;
1376
+ const SPACER_SPACING = [
1377
+ {
1378
+ displayValue: "XS",
1379
+ label: "Extra Small",
1380
+ value: 4
1381
+ },
1382
+ {
1383
+ displayValue: "SM",
1384
+ label: "Small",
1385
+ value: 8
1386
+ },
1387
+ {
1388
+ displayValue: "MD",
1389
+ label: "Medium",
1390
+ value: 16
1391
+ },
1392
+ {
1393
+ displayValue: "LG",
1394
+ label: "Large",
1395
+ value: 32
1396
+ },
1397
+ {
1398
+ displayValue: "XL",
1399
+ label: "Extra Large",
1400
+ value: 64
1401
+ }
1402
+ ];
1403
+ const SPACING_PRESETS = [
1404
+ {
1405
+ label: "None",
1406
+ value: 0
1407
+ },
1408
+ {
1409
+ label: "Small",
1410
+ value: 8
1411
+ },
1412
+ {
1413
+ label: "Medium",
1414
+ value: 16
1415
+ },
1416
+ {
1417
+ label: "Large",
1418
+ value: 32
1419
+ }
1420
+ ];
1421
+ //#endregion
1422
+ //#region src/utils/columns.ts
1423
+ function getClosestColumns(editor) {
1424
+ return findParentNode$1((node) => node.type.name === MAILY_NODE_TYPES.COLUMNS)(editor.state.selection);
1425
+ }
1426
+ function getColumnWidths(editor) {
1427
+ const columns = getClosestColumns(editor);
1428
+ if (!columns) return [];
1429
+ const widths = [];
1430
+ columns.node.forEach((child) => {
1431
+ if (child.type.name === MAILY_NODE_TYPES.COLUMN) {
1432
+ const width = child.attrs.width;
1433
+ widths.push(typeof width === "number" ? width : null);
1434
+ }
1435
+ });
1436
+ return widths;
1437
+ }
1438
+ function updateColumnWidth(editor, columnIndex, width) {
1439
+ const columns = getClosestColumns(editor);
1440
+ if (!columns) return false;
1441
+ const { node: columnsNode, pos: columnsPos } = columns;
1442
+ const { dispatch, state } = editor.view;
1443
+ const { selection, tr } = state;
1444
+ const selectionRelative = {
1445
+ from: selection.from - columnsPos,
1446
+ to: selection.to - columnsPos
1447
+ };
1448
+ const updatedContent = [];
1449
+ columnsNode.content.forEach((child, _, index) => {
1450
+ updatedContent.push(child.type.create({
1451
+ ...child.attrs,
1452
+ width: index === columnIndex ? width : child.attrs.width
1453
+ }, child.content));
1454
+ });
1455
+ const transaction = tr.replaceWith(columnsPos, columnsPos + columnsNode.nodeSize, columnsNode.type.create(columnsNode.attrs, updatedContent, columnsNode.marks));
1456
+ dispatch(transaction.setSelection(TextSelection.create(transaction.doc, columnsPos + selectionRelative.from, columnsPos + selectionRelative.to)));
1457
+ return true;
1458
+ }
1459
+ function addColumn(editor) {
1460
+ const columns = getClosestColumns(editor);
1461
+ if (!columns) return false;
1462
+ const { node: columnsNode, pos: columnsPos } = columns;
1463
+ const { dispatch, state } = editor.view;
1464
+ const { tr } = state;
1465
+ const newColumn = state.schema.nodes[MAILY_NODE_TYPES.COLUMN].create({ width: null }, state.schema.nodes[MAILY_NODE_TYPES.PARAGRAPH].create());
1466
+ const updatedContent = [];
1467
+ columnsNode.content.forEach((child) => {
1468
+ updatedContent.push(child);
1469
+ });
1470
+ updatedContent.push(newColumn);
1471
+ const updatedColumnsNode = columnsNode.type.create({
1472
+ ...columnsNode.attrs,
1473
+ columnCount: columnsNode.childCount + 1
1474
+ }, updatedContent);
1475
+ const transaction = tr.replaceWith(columnsPos, columnsPos + columnsNode.nodeSize, updatedColumnsNode);
1476
+ dispatch(transaction.setSelection(TextSelection.create(transaction.doc, columnsPos + 3)));
1477
+ return true;
1478
+ }
1479
+ function removeColumn(editor) {
1480
+ const columns = getClosestColumns(editor);
1481
+ if (!columns) return false;
1482
+ const { node: columnsNode, pos: columnsPos } = columns;
1483
+ if (columnsNode.childCount <= 1) return false;
1484
+ const { dispatch, state } = editor.view;
1485
+ const { selection, tr } = state;
1486
+ const removeIndex = columnsNode.childCount - 1;
1487
+ const updatedContent = [];
1488
+ columnsNode.content.forEach((child, _, childIndex) => {
1489
+ if (childIndex !== removeIndex) updatedContent.push(child);
1490
+ });
1491
+ const updatedColumnsNode = columnsNode.type.create({
1492
+ ...columnsNode.attrs,
1493
+ columnCount: columnsNode.childCount - 1
1494
+ }, updatedContent);
1495
+ const selectionFrom = selection.from - columnsPos;
1496
+ const transaction = tr.replaceWith(columnsPos, columnsPos + columnsNode.nodeSize, updatedColumnsNode);
1497
+ const maxPos = columnsPos + updatedColumnsNode.nodeSize - 1;
1498
+ dispatch(transaction.setSelection(TextSelection.near(transaction.doc.resolve(Math.min(columnsPos + selectionFrom, maxPos)))));
1499
+ return true;
1500
+ }
1501
+ function goToSiblingColumn(editor, direction) {
1502
+ const { $from } = editor.state.selection;
1503
+ let columnDepth = -1;
1504
+ for (let depth = $from.depth; depth > 0; depth--) if ($from.node(depth).type.name === MAILY_NODE_TYPES.COLUMN) {
1505
+ columnDepth = depth;
1506
+ break;
1507
+ }
1508
+ if (columnDepth === -1) return false;
1509
+ const columnsDepth = columnDepth - 1;
1510
+ const columnIndex = $from.index(columnsDepth);
1511
+ const targetIndex = direction === "next" ? columnIndex + 1 : columnIndex - 1;
1512
+ if (targetIndex < 0 || targetIndex >= $from.node(columnsDepth).childCount) return false;
1513
+ const targetPos = direction === "next" ? $from.after(columnDepth) + 1 : $from.before(columnDepth) - 1;
1514
+ const { tr } = editor.state;
1515
+ tr.setSelection(TextSelection.near(tr.doc.resolve(targetPos), direction === "next" ? 1 : -1));
1516
+ editor.view.dispatch(tr);
1517
+ return true;
1518
+ }
1519
+ //#endregion
1520
+ //#region src/utils/exit-on-triple-enter.ts
1521
+ /**
1522
+ * Exits a container node when the user presses Enter three times
1523
+ * (i.e. the last three children are empty). Deletes the trailing
1524
+ * empty blocks and inserts a paragraph after the container.
1525
+ */
1526
+ function exitOnTripleEnter(options) {
1527
+ const { editor, exitDepthOffset = 0, nodeName } = options;
1528
+ const { state } = editor;
1529
+ const { $from, empty } = state.selection;
1530
+ if (!empty) return false;
1531
+ let nodeDepth = -1;
1532
+ for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === nodeName) {
1533
+ nodeDepth = d;
1534
+ break;
1535
+ }
1536
+ if (nodeDepth === -1) return false;
1537
+ const node = $from.node(nodeDepth);
1538
+ const lastChildIndex = node.childCount - 1;
1539
+ if (node.childCount < 3 || $from.index(nodeDepth) !== lastChildIndex || $from.parent.content.size !== 0 || node.child(lastChildIndex - 1).content.size !== 0 || node.child(lastChildIndex - 2).content.size !== 0) return false;
1540
+ const exitDepth = nodeDepth + exitDepthOffset;
1541
+ const deleteCount = Math.min(3, node.childCount - 1);
1542
+ let deleteFrom = $from.start(nodeDepth);
1543
+ for (let i = 0; i < node.childCount - deleteCount; i++) deleteFrom += node.child(i).nodeSize;
1544
+ return editor.chain().command(({ tr }) => {
1545
+ const afterNode = $from.after(exitDepth);
1546
+ tr.delete(deleteFrom, $from.end(nodeDepth));
1547
+ const mappedPos = tr.mapping.map(afterNode);
1548
+ tr.insert(mappedPos, editor.schema.nodes.paragraph.create());
1549
+ tr.setSelection(TextSelection.near(tr.doc.resolve(mappedPos + 1)));
1550
+ return true;
1551
+ }).run();
1552
+ }
1553
+ //#endregion
1554
+ //#region src/extensions/columns/column.ts
1555
+ const DEFAULT_COLUMN_WIDTH = null;
1556
+ const ColumnExtension = Node$1.create({
1557
+ name: MAILY_NODE_TYPES.COLUMN,
1558
+ group: "column",
1559
+ content: "block+",
1560
+ defining: true,
1561
+ isolating: true,
1562
+ addAttributes() {
1563
+ return {
1564
+ width: {
1565
+ default: DEFAULT_COLUMN_WIDTH,
1566
+ parseHTML: (element) => {
1567
+ return getColumnWidth(element.style.width) ?? DEFAULT_COLUMN_WIDTH;
1568
+ },
1569
+ renderHTML: (attributes) => {
1570
+ const width = attributes.width;
1571
+ if (width === null) return {};
1572
+ const value = getColumnWidthValue(width);
1573
+ return { style: `width:${value};max-width:${value}` };
1574
+ }
1575
+ },
1576
+ verticalAlign: {
1577
+ default: "top",
1578
+ parseHTML: (element) => {
1579
+ if (element.style.verticalAlign) return element.style.verticalAlign;
1580
+ if (element.style.justifyContent === "center") return "middle";
1581
+ if (element.style.justifyContent === "flex-end") return "bottom";
1582
+ return "top";
1583
+ },
1584
+ renderHTML: (attributes) => {
1585
+ const verticalAlign = attributes.verticalAlign;
1586
+ if (!verticalAlign || verticalAlign === "top") return {};
1587
+ if (verticalAlign === "middle") return { style: "display:flex;flex-direction:column;justify-content:center" };
1588
+ if (verticalAlign === "bottom") return { style: "display:flex;flex-direction:column;justify-content:flex-end" };
1589
+ return {};
1590
+ }
1591
+ }
1592
+ };
1593
+ },
1594
+ addCommands() {
1595
+ return { updateColumn: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs) };
1596
+ },
1597
+ addKeyboardShortcuts() {
1598
+ return {
1599
+ Tab: ({ editor }) => goToSiblingColumn(editor, "next"),
1600
+ "Shift-Tab": ({ editor }) => goToSiblingColumn(editor, "previous"),
1601
+ Enter: ({ editor }) => {
1602
+ return exitOnTripleEnter({
1603
+ editor,
1604
+ exitDepthOffset: -1,
1605
+ nodeName: this.name
1606
+ });
1607
+ }
1608
+ };
1609
+ },
1610
+ parseHTML() {
1611
+ return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${MAILY_NODE_TYPES.COLUMN}"]` }];
1612
+ },
1613
+ renderHTML({ HTMLAttributes }) {
1614
+ return [
1615
+ "div",
1616
+ mergeAttributes(HTMLAttributes, { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.COLUMN }),
1617
+ 0
1618
+ ];
1619
+ }
1620
+ });
1621
+ const ColumnsExtension = Node$1.create({
1622
+ name: MAILY_NODE_TYPES.COLUMNS,
1623
+ group: "block",
1624
+ content: "column+",
1625
+ defining: true,
1626
+ isolating: true,
1627
+ draggable: true,
1628
+ addAttributes() {
1629
+ return {
1630
+ columnCount: {
1631
+ default: 2,
1632
+ parseHTML: (element) => Number(element.getAttribute("data-column-count")) || 2,
1633
+ renderHTML: (attributes) => ({ "data-column-count": attributes.columnCount })
1634
+ },
1635
+ gap: {
1636
+ default: 8,
1637
+ parseHTML: (element) => Number(element.getAttribute("data-gap")) || 8,
1638
+ renderHTML: (attributes) => ({
1639
+ "data-gap": attributes.gap,
1640
+ style: `gap:${attributes.gap}px`
1641
+ })
1642
+ }
1643
+ };
1644
+ },
1645
+ addCommands() {
1646
+ return {
1647
+ setColumns: (columnCount = 2) => ({ tr, dispatch, editor }) => {
1648
+ const columnNodes = Array.from({ length: columnCount }, () => editor.schema.nodes[MAILY_NODE_TYPES.COLUMN].createAndFill({}, editor.schema.nodes.paragraph.create())).filter((node) => node !== null);
1649
+ const columnsNode = editor.schema.nodes[this.name].createAndFill({ columnCount }, columnNodes);
1650
+ if (!columnsNode) return false;
1651
+ const { $from } = tr.selection;
1652
+ const isEmptyBlock = $from.parent.isTextblock && $from.parent.content.size === 0;
1653
+ const insertFrom = isEmptyBlock ? $from.before($from.depth) : $from.after($from.depth);
1654
+ const insertTo = isEmptyBlock ? $from.after($from.depth) : insertFrom;
1655
+ tr.replaceWith(insertFrom, insertTo, columnsNode);
1656
+ tr.setSelection(TextSelection.near(tr.doc.resolve(insertFrom + 3)));
1657
+ if (dispatch) dispatch(tr);
1658
+ return true;
1659
+ },
1660
+ updateColumns: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
1661
+ };
1662
+ },
1663
+ parseHTML() {
1664
+ return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${MAILY_NODE_TYPES.COLUMNS}"]` }];
1665
+ },
1666
+ renderHTML({ HTMLAttributes }) {
1667
+ return [
1668
+ "div",
1669
+ mergeAttributes(HTMLAttributes, { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.COLUMNS }),
1670
+ 0
1671
+ ];
1672
+ }
1673
+ });
1674
+ //#endregion
1675
+ //#region src/extensions/visibility/visibility.ts
1676
+ const VISIBILITY_SUPPORTED_TYPES = [
1677
+ MAILY_NODE_TYPES.PARAGRAPH,
1678
+ MAILY_NODE_TYPES.HEADING,
1679
+ MAILY_NODE_TYPES.IMAGE,
1680
+ MAILY_NODE_TYPES.SPACER,
1681
+ MAILY_NODE_TYPES.SECTION,
1682
+ MAILY_NODE_TYPES.COLUMNS,
1683
+ MAILY_NODE_TYPES.BULLET_LIST,
1684
+ MAILY_NODE_TYPES.ORDERED_LIST,
1685
+ MAILY_NODE_TYPES.HORIZONTAL_RULE,
1686
+ MAILY_NODE_TYPES.BUTTON,
1687
+ MAILY_NODE_TYPES.REPEAT,
1688
+ MAILY_NODE_TYPES.HTML_CODE_BLOCK,
1689
+ MAILY_NODE_TYPES.LINK_CARD
1690
+ ];
1691
+ function getRuleAttributes(rule) {
1692
+ const attributes = {
1693
+ "data-visibility-action": rule.action,
1694
+ "data-visibility-operator": rule.operator,
1695
+ "data-visibility-variable": rule.variable
1696
+ };
1697
+ if (getVisibilityValueSupport(rule.operator)) attributes["data-visibility-value"] = rule.value;
1698
+ return attributes;
1699
+ }
1700
+ const VisibilityExtension = Extension.create({
1701
+ name: MAILY_EXTENSION_TYPES.VISIBILITY,
1702
+ addOptions() {
1703
+ return { types: VISIBILITY_SUPPORTED_TYPES };
1704
+ },
1705
+ addGlobalAttributes() {
1706
+ return [{
1707
+ types: this.options.types,
1708
+ attributes: { visibilityRule: {
1709
+ default: null,
1710
+ keepOnSplit: false,
1711
+ parseHTML: (element) => getVisibilityRule({
1712
+ action: element.getAttribute("data-visibility-action"),
1713
+ operator: element.getAttribute("data-visibility-operator"),
1714
+ value: element.getAttribute("data-visibility-value"),
1715
+ variable: element.getAttribute("data-visibility-variable")
1716
+ }),
1717
+ renderHTML: (attributes) => {
1718
+ const rule = attributes.visibilityRule;
1719
+ return rule ? getRuleAttributes(rule) : {};
1720
+ }
1721
+ } }
1722
+ }];
1723
+ },
1724
+ addCommands() {
1725
+ return {
1726
+ setVisibilityRule: (typeOrName, rule) => ({ commands }) => commands.updateAttributes(typeOrName, { visibilityRule: rule }),
1727
+ unsetVisibilityRule: (typeOrName) => ({ commands }) => commands.updateAttributes(typeOrName, { visibilityRule: null })
1728
+ };
1729
+ }
1730
+ });
1731
+ //#endregion
1732
+ //#region src/utils/collaboration.ts
1733
+ const Y_SYNC_META_KEY = "y-sync$";
1734
+ function isRemoteChange(tr) {
1735
+ return Boolean(tr.getMeta(Y_SYNC_META_KEY));
1736
+ }
1737
+ //#endregion
1738
+ //#region src/extensions/variable/protect-variable-trigger.ts
1739
+ const ProtectVariableTrigger = Extension.create({
1740
+ name: "protectVariableTrigger",
1741
+ addProseMirrorPlugins() {
1742
+ return [new Plugin({ appendTransaction(transactions, _oldState, newState) {
1743
+ if (!transactions.some((tr) => tr.docChanged) || transactions.some(isRemoteChange)) return null;
1744
+ let hasVariable = false;
1745
+ newState.doc.descendants((node) => {
1746
+ if (node.type.name === MAILY_NODE_TYPES.VARIABLE) {
1747
+ hasVariable = true;
1748
+ return false;
1749
+ }
1750
+ return true;
1751
+ });
1752
+ if (hasVariable) return null;
1753
+ const paragraph = newState.doc.firstChild;
1754
+ if (!paragraph) return null;
1755
+ if (paragraph.textContent.startsWith(DEFAULT_VARIABLE_START_TRIGGER)) return null;
1756
+ const tr = newState.tr;
1757
+ const start = 1;
1758
+ return tr.replaceWith(start, start + paragraph.content.size, newState.schema.text(DEFAULT_VARIABLE_START_TRIGGER));
1759
+ } })];
1760
+ }
1761
+ });
1762
+ //#endregion
1763
+ //#region src/extensions/repeat/repeat.ts
1764
+ const DEFAULT_REPEAT_EACH = "{{items}}";
1765
+ const RepeatExtension = Node$1.create({
1766
+ name: MAILY_NODE_TYPES.REPEAT,
1767
+ group: "block",
1768
+ content: "block+",
1769
+ defining: true,
1770
+ isolating: true,
1771
+ draggable: true,
1772
+ addOptions() {
1773
+ return { HTMLAttributes: {} };
1774
+ },
1775
+ addAttributes() {
1776
+ return { each: {
1777
+ default: DEFAULT_REPEAT_EACH,
1778
+ parseHTML: (element) => {
1779
+ return element.getAttribute("data-each") || "{{items}}";
1780
+ },
1781
+ renderHTML: (attributes) => ({ "data-each": attributes.each })
1782
+ } };
1783
+ },
1784
+ addCommands() {
1785
+ return {
1786
+ setRepeat: (attrs) => ({ commands }) => commands.insertContent({
1787
+ type: this.name,
1788
+ attrs: { ...attrs },
1789
+ content: [{ type: MAILY_NODE_TYPES.PARAGRAPH }]
1790
+ }),
1791
+ updateRepeat: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
1792
+ };
1793
+ },
1794
+ addKeyboardShortcuts() {
1795
+ return { "Mod-Backspace": ({ editor }) => editor.commands.deleteNode(this.name) };
1796
+ },
1797
+ parseHTML() {
1798
+ return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${this.name}"]` }];
1799
+ },
1800
+ renderHTML({ HTMLAttributes }) {
1801
+ return [
1802
+ "div",
1803
+ mergeAttributes({ [DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes),
1804
+ 0
1805
+ ];
1806
+ }
1807
+ });
1808
+ //#endregion
1809
+ //#region src/extensions/blockquote/blockquote.ts
1810
+ const BlockquoteExtension = Blockquote.extend({ renderHTML({ HTMLAttributes }) {
1811
+ return [
1812
+ "blockquote",
1813
+ mergeAttributes({ [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.BLOCKQUOTE }, this.options.HTMLAttributes, HTMLAttributes),
1814
+ 0
1815
+ ];
1816
+ } });
1817
+ //#endregion
1818
+ //#region src/extensions/body/body.ts
1819
+ const BodyExtension = Node$1.create({
1820
+ name: MAILY_NODE_TYPES.BODY,
1821
+ content: `${MAILY_NODE_TYPES.CONTAINER}+`,
1822
+ defining: true,
1823
+ parseHTML() {
1824
+ return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${MAILY_NODE_TYPES.BODY}"]` }];
1825
+ },
1826
+ renderHTML({ HTMLAttributes }) {
1827
+ return [
1828
+ "div",
1829
+ mergeAttributes({ [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.BODY }, HTMLAttributes),
1830
+ 0
1831
+ ];
1832
+ }
1833
+ });
1834
+ //#endregion
1835
+ //#region src/utils/table.ts
1836
+ function getSingleCell(element) {
1837
+ if (isDataTable(element)) return null;
1838
+ const cells = element.querySelectorAll(":scope > tbody > tr > td");
1839
+ return cells.length === 1 ? cells[0] : null;
1840
+ }
1841
+ function isDataTable(element) {
1842
+ const border = element.getAttribute("border");
1843
+ return element.querySelector(":scope > thead, :scope > tbody > tr > th") !== null || border !== null && border !== "0";
1844
+ }
1845
+ function isBodyTable(element) {
1846
+ return element.parentElement?.tagName === "BODY";
1847
+ }
1848
+ //#endregion
1849
+ //#region src/utils/style.ts
1850
+ const BOLD_FONT_WEIGHTS = [
1851
+ "bold",
1852
+ "bolder",
1853
+ String(FONT_WEIGHTS.BOLD)
1854
+ ];
1855
+ const MARKED_TEXT_DECORATIONS = ["underline", "line-through"];
1856
+ function isBoldFontWeight(value) {
1857
+ return BOLD_FONT_WEIGHTS.includes(value.trim().toLowerCase());
1858
+ }
1859
+ function isItalicFontStyle(value) {
1860
+ return value.trim().toLowerCase() === FONT_STYLES.ITALIC;
1861
+ }
1862
+ function isMarkedTextDecoration(value) {
1863
+ const decoration = value.toLowerCase();
1864
+ return MARKED_TEXT_DECORATIONS.some((keyword) => {
1865
+ return decoration.includes(keyword);
1866
+ });
1867
+ }
1868
+ const CLAIMED_BY_MARKS = {
1869
+ fontStyle: isItalicFontStyle,
1870
+ fontWeight: isBoldFontWeight,
1871
+ textDecoration: isMarkedTextDecoration,
1872
+ textDecorationLine: isMarkedTextDecoration
1873
+ };
1874
+ const CLAIMED_ON_SPAN = {
1875
+ ...CLAIMED_BY_MARKS,
1876
+ color: true
1877
+ };
1878
+ const CLAIMED_ON_INLINE_IMAGE = { display: true };
1879
+ const CLAIMED_ON_COLUMNS = {
1880
+ gap: true,
1881
+ columnGap: true,
1882
+ rowGap: true
1883
+ };
1884
+ const CLAIMED_ON_COLUMN = {
1885
+ display: true,
1886
+ flexDirection: true,
1887
+ justifyContent: true,
1888
+ maxWidth: true,
1889
+ width: true,
1890
+ verticalAlign: true
1891
+ };
1892
+ function getUnclaimedStyle(options) {
1893
+ const { style, claimed } = options;
1894
+ if (!style) return null;
1895
+ const declarations = parseInlineStyles(style);
1896
+ for (const [property, claims] of Object.entries(claimed)) {
1897
+ const value = declarations[property];
1898
+ if (value === void 0) continue;
1899
+ if (claims === true || claims(value)) delete declarations[property];
1900
+ }
1901
+ return stringifyInlineStyles(declarations) || null;
1902
+ }
1903
+ function getMarkStyle(style) {
1904
+ return getUnclaimedStyle({
1905
+ style,
1906
+ claimed: CLAIMED_BY_MARKS
1907
+ });
1908
+ }
1909
+ function getSpanStyle(style) {
1910
+ return getUnclaimedStyle({
1911
+ style,
1912
+ claimed: CLAIMED_ON_SPAN
1913
+ });
1914
+ }
1915
+ function getInlineImageStyle(element) {
1916
+ return getUnclaimedStyle({
1917
+ style: getElementStyle(element),
1918
+ claimed: CLAIMED_ON_INLINE_IMAGE
1919
+ });
1920
+ }
1921
+ function getColumnsStyle(style) {
1922
+ return getUnclaimedStyle({
1923
+ style,
1924
+ claimed: CLAIMED_ON_COLUMNS
1925
+ });
1926
+ }
1927
+ function getColumnStyle(style) {
1928
+ return getUnclaimedStyle({
1929
+ style,
1930
+ claimed: CLAIMED_ON_COLUMN
1931
+ });
1932
+ }
1933
+ const TABLE_ALIGNMENT = {
1934
+ center: {
1935
+ marginLeft: "auto",
1936
+ marginRight: "auto"
1937
+ },
1938
+ left: { marginRight: "auto" },
1939
+ right: { marginLeft: "auto" }
1940
+ };
1941
+ function toCssLength(value) {
1942
+ const trimmed = value.trim();
1943
+ return /^\d+(?:\.\d+)?$/.test(trimmed) ? `${trimmed}px` : trimmed;
1944
+ }
1945
+ function getPresentationalStyle(element) {
1946
+ const style = {};
1947
+ const width = element.getAttribute("width");
1948
+ const height = element.getAttribute("height");
1949
+ const align = element.getAttribute("align");
1950
+ const verticalAlign = element.getAttribute("valign");
1951
+ const backgroundColor = element.getAttribute("bgcolor");
1952
+ if (width) style.width = toCssLength(width);
1953
+ if (height) style.height = toCssLength(height);
1954
+ if (align) Object.assign(style, element.tagName === "TABLE" ? TABLE_ALIGNMENT[align.toLowerCase()] : { textAlign: align });
1955
+ if (verticalAlign) style.verticalAlign = verticalAlign;
1956
+ if (backgroundColor) style.backgroundColor = backgroundColor;
1957
+ return style;
1958
+ }
1959
+ function getWrapperAlignment(element) {
1960
+ const align = element.getAttribute("align")?.toLowerCase();
1961
+ if (!align || align === TEXT_ALIGNMENTS.LEFT || align === TEXT_ALIGNMENTS.CENTER) return {};
1962
+ return TABLE_ALIGNMENT[align] ?? {};
1963
+ }
1964
+ function getWrapperStyle(element) {
1965
+ const cell = getSingleCell(element);
1966
+ const style = mergeInlineStyles(getWrapperAlignment(element), parseInlineStyles(element.getAttribute("style") ?? ""));
1967
+ const inner = cell?.getAttribute("style");
1968
+ return stringifyInlineStyles(inner ? mergeInlineStyles(style, parseInlineStyles(inner)) : style) || null;
1969
+ }
1970
+ function getElementStyle(element) {
1971
+ const authored = element.getAttribute("style");
1972
+ const presentational = getPresentationalStyle(element);
1973
+ if (Object.keys(presentational).length === 0) return authored;
1974
+ return stringifyInlineStyles(mergeInlineStyles(presentational, authored ? parseInlineStyles(authored) : {})) || null;
1975
+ }
1976
+ function setStyleDeclarations(style, declarations) {
1977
+ const merged = style ? parseInlineStyles(style) : {};
1978
+ for (const [property, value] of Object.entries(declarations)) if (value === null || value === void 0 || value === "") delete merged[property];
1979
+ else merged[property] = value;
1980
+ return stringifyInlineStyles(merged) || null;
1981
+ }
1982
+ //#endregion
1983
+ //#region src/extensions/bold/bold.ts
1984
+ const BoldExtension = Bold.extend({ parseHTML() {
1985
+ return [
1986
+ { tag: "strong" },
1987
+ {
1988
+ tag: "b",
1989
+ getAttrs: (element) => {
1990
+ return element.style.fontWeight !== "normal" && null;
1991
+ }
1992
+ },
1993
+ {
1994
+ style: "font-weight=400",
1995
+ clearMark: (mark) => {
1996
+ return mark.type.name === this.name;
1997
+ }
1998
+ },
1999
+ {
2000
+ style: "font-weight",
2001
+ getAttrs: (value) => {
2002
+ return isBoldFontWeight(value) && null;
2003
+ }
2004
+ }
2005
+ ];
2006
+ } });
2007
+ //#endregion
2008
+ //#region src/extensions/button/button.ts
2009
+ const DEFAULT_BUTTON_ALIGN = TEXT_ALIGNMENTS.CENTER;
2010
+ const ButtonExtension = Node$1.create({
2011
+ name: MAILY_NODE_TYPES.BUTTON,
2012
+ group: "block",
2013
+ content: "(inline)*",
2014
+ defining: true,
2015
+ isolating: true,
2016
+ addOptions() {
2017
+ return { HTMLAttributes: {} };
2018
+ },
2019
+ addAttributes() {
2020
+ return {
2021
+ url: {
2022
+ default: "",
2023
+ parseHTML: (element) => element.getAttribute("data-url") || "",
2024
+ renderHTML: (attributes) => ({ "data-url": attributes.url })
2025
+ },
2026
+ kind: {
2027
+ default: DEFAULT_BUTTON_KIND,
2028
+ parseHTML: (element) => {
2029
+ const kind = element.getAttribute("data-kind");
2030
+ return isAllowedButtonKind(kind) ? kind : DEFAULT_BUTTON_KIND;
2031
+ },
2032
+ renderHTML: (attributes) => ({ "data-kind": attributes.kind })
2033
+ },
2034
+ align: {
2035
+ default: DEFAULT_BUTTON_ALIGN,
2036
+ parseHTML: (element) => {
2037
+ const align = element.getAttribute("data-align");
2038
+ return isAllowedTextAlignment(align) ? align : DEFAULT_BUTTON_ALIGN;
2039
+ },
2040
+ renderHTML: (attributes) => ({ "data-align": attributes.align })
2041
+ }
2042
+ };
2043
+ },
2044
+ addCommands() {
2045
+ return {
2046
+ setButton: (attrs) => ({ commands }) => commands.insertContent({
2047
+ type: this.name,
2048
+ attrs: { ...attrs },
2049
+ content: [{
2050
+ type: MAILY_NODE_TYPES.TEXT,
2051
+ text: "Button"
2052
+ }]
2053
+ }),
2054
+ updateButtonAttributes: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
2055
+ };
2056
+ },
2057
+ addKeyboardShortcuts() {
2058
+ return {
2059
+ "Mod-Backspace": ({ editor }) => editor.commands.deleteNode(this.name),
2060
+ Backspace: ({ editor }) => {
2061
+ const { $anchor, empty } = editor.state.selection;
2062
+ if (!empty || $anchor.parent.type.name !== this.name || $anchor.parent.content.size > 0) return false;
2063
+ return editor.commands.deleteNode(this.name);
2064
+ },
2065
+ Enter: ({ editor }) => {
2066
+ const { $from, empty } = editor.state.selection;
2067
+ if (!empty || $from.parent.type.name !== this.name) return false;
2068
+ if (!($from.parentOffset === $from.parent.nodeSize - 2)) return false;
2069
+ return editor.chain().insertContent({
2070
+ type: MAILY_NODE_TYPES.PARAGRAPH,
2071
+ content: []
2072
+ }).run();
2073
+ }
2074
+ };
2075
+ },
2076
+ parseHTML() {
2077
+ return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${this.name}"]` }];
2078
+ },
2079
+ renderHTML({ HTMLAttributes }) {
2080
+ return [
2081
+ "div",
2082
+ mergeAttributes({ [DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes),
2083
+ 0
2084
+ ];
2085
+ }
2086
+ });
2087
+ //#endregion
2088
+ //#region src/extensions/container/container.ts
2089
+ const ContainerExtension = Node$1.create({
2090
+ name: MAILY_NODE_TYPES.CONTAINER,
2091
+ group: "block",
2092
+ content: "block+",
2093
+ defining: true,
2094
+ isolating: true,
2095
+ parseHTML() {
2096
+ return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${MAILY_NODE_TYPES.CONTAINER}"]` }, {
2097
+ tag: "table",
2098
+ priority: 60,
2099
+ getAttrs: (element) => {
2100
+ if (!element.style.maxWidth) return false;
2101
+ return getSingleCell(element) ? null : false;
2102
+ },
2103
+ contentElement: (element) => getSingleCell(element) ?? element
2104
+ }];
2105
+ },
2106
+ renderHTML({ HTMLAttributes }) {
2107
+ return [
2108
+ "div",
2109
+ mergeAttributes({ [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.CONTAINER }, HTMLAttributes),
2110
+ 0
2111
+ ];
2112
+ }
2113
+ });
2114
+ //#endregion
2115
+ //#region src/extensions/footer/footer.ts
2116
+ const FooterExtension = Node$1.create({
2117
+ name: MAILY_NODE_TYPES.FOOTER,
2118
+ group: "block",
2119
+ content: "inline*",
2120
+ addOptions() {
2121
+ return { HTMLAttributes: {} };
2122
+ },
2123
+ addCommands() {
2124
+ return {
2125
+ setFooter: () => ({ commands }) => commands.setNode(this.name),
2126
+ updateFooterAttributes: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
2127
+ };
2128
+ },
2129
+ parseHTML() {
2130
+ return [{ tag: `small[${DATA_NODE_TYPE_KEY}="${this.name}"]` }];
2131
+ },
2132
+ renderHTML({ HTMLAttributes }) {
2133
+ return [
2134
+ "small",
2135
+ mergeAttributes({ [DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes),
2136
+ 0
2137
+ ];
2138
+ }
2139
+ });
2140
+ //#endregion
2141
+ //#region src/extensions/horizontal-rule/horizontal-rule.ts
2142
+ const HorizontalRuleExtension = HorizontalRule.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.HORIZONTAL_RULE } });
2143
+ //#endregion
2144
+ //#region src/extensions/html-code-block/html-code-block-view.tsx
2145
+ const PREVIEW_RESET = `
2146
+ * { font-family: 'Inter', sans-serif; }
2147
+ blockquote, h1, h2, h3, img, li, ol, p, ul {
2148
+ margin-top: 0;
2149
+ margin-bottom: 0;
2150
+ }
2151
+ `;
2152
+ function HtmlCodeBlockView(props) {
2153
+ const $ = c(16);
2154
+ const { node, updateAttributes } = props;
2155
+ const { activeTab, language } = node.attrs;
2156
+ let parsed;
2157
+ let t0;
2158
+ if ($[0] !== node.content.content) {
2159
+ const source = node.content.content.reduce(_temp$1, "");
2160
+ parsed = new DOMParser().parseFromString(source, "text/html");
2161
+ t0 = Array.from(parsed.querySelectorAll("style")).map(_temp2$1);
2162
+ $[0] = node.content.content;
2163
+ $[1] = parsed;
2164
+ $[2] = t0;
2165
+ } else {
2166
+ parsed = $[1];
2167
+ t0 = $[2];
2168
+ }
2169
+ const html = `<style>${t0.join("\n")}</style>${parsed.body.innerHTML}`;
2170
+ const isEmpty = html === "<style></style>";
2171
+ let t1;
2172
+ if ($[3] !== html) {
2173
+ t1 = (element_0) => {
2174
+ if (!element_0 || element_0.shadowRoot) return;
2175
+ const shadow = element_0.attachShadow({ mode: "open" });
2176
+ const sheet = new CSSStyleSheet();
2177
+ sheet.replaceSync(PREVIEW_RESET);
2178
+ shadow.adoptedStyleSheets = [sheet];
2179
+ const container = document.createElement("div");
2180
+ container.innerHTML = html;
2181
+ shadow.append(container);
2182
+ };
2183
+ $[3] = html;
2184
+ $[4] = t1;
2185
+ } else t1 = $[4];
2186
+ const setPreviewElement = t1;
2187
+ let t2;
2188
+ if ($[5] !== activeTab || $[6] !== language) {
2189
+ t2 = activeTab === HTML_CODE_BLOCK_TABS.CODE && /* @__PURE__ */ jsx("pre", {
2190
+ "data-mly-html-code-block": "",
2191
+ children: /* @__PURE__ */ jsx(NodeViewContent, {
2192
+ as: "code",
2193
+ className: language ? `language-${language}` : void 0
2194
+ })
2195
+ });
2196
+ $[5] = activeTab;
2197
+ $[6] = language;
2198
+ $[7] = t2;
2199
+ } else t2 = $[7];
2200
+ let t3;
2201
+ if ($[8] !== activeTab || $[9] !== isEmpty || $[10] !== setPreviewElement || $[11] !== updateAttributes) {
2202
+ t3 = activeTab === HTML_CODE_BLOCK_TABS.PREVIEW && /* @__PURE__ */ jsx("div", {
2203
+ contentEditable: false,
2204
+ "data-empty": isEmpty ? "" : void 0,
2205
+ "data-mly-html-code-block-preview": "",
2206
+ onClick: () => {
2207
+ if (isEmpty) updateAttributes({ activeTab: HTML_CODE_BLOCK_TABS.CODE });
2208
+ },
2209
+ ref: setPreviewElement
2210
+ });
2211
+ $[8] = activeTab;
2212
+ $[9] = isEmpty;
2213
+ $[10] = setPreviewElement;
2214
+ $[11] = updateAttributes;
2215
+ $[12] = t3;
2216
+ } else t3 = $[12];
2217
+ let t4;
2218
+ if ($[13] !== t2 || $[14] !== t3) {
2219
+ t4 = /* @__PURE__ */ jsxs(NodeViewWrapper, {
2220
+ "data-drag-handle": false,
2221
+ draggable: false,
2222
+ children: [t2, t3]
2223
+ });
2224
+ $[13] = t2;
2225
+ $[14] = t3;
2226
+ $[15] = t4;
2227
+ } else t4 = $[15];
2228
+ return t4;
2229
+ }
2230
+ function _temp2$1(element) {
2231
+ return element.innerHTML;
2232
+ }
2233
+ function _temp$1(text, child) {
2234
+ if (child.type.name !== MAILY_NODE_TYPES.TEXT) return text;
2235
+ return text + child.text;
2236
+ }
2237
+ //#endregion
2238
+ //#region src/extensions/html-code-block/html-code-block.ts
2239
+ const lowlight = createLowlight(common);
2240
+ lowlight.register("html", html);
2241
+ const HtmlCodeBlockExtension = CodeBlockLowlight.extend({
2242
+ name: MAILY_NODE_TYPES.HTML_CODE_BLOCK,
2243
+ content: "(text|variable)*",
2244
+ addAttributes() {
2245
+ return {
2246
+ ...this.parent?.(),
2247
+ activeTab: { default: DEFAULT_HTML_CODE_BLOCK_TAB }
2248
+ };
2249
+ },
2250
+ addNodeView() {
2251
+ return ReactNodeViewRenderer(HtmlCodeBlockView, { attrs: (props) => {
2252
+ const { node } = props;
2253
+ const { activeTab } = node.attrs;
2254
+ return {
2255
+ "data-active-tab": activeTab,
2256
+ [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.HTML_CODE_BLOCK
2257
+ };
2258
+ } });
2259
+ },
2260
+ addCommands() {
2261
+ return {
2262
+ setHtmlCodeBlock: (attrs) => {
2263
+ return ({ commands }) => {
2264
+ return commands.setNode(this.name, attrs);
2265
+ };
2266
+ },
2267
+ updateHtmlCodeBlock: (attrs) => {
2268
+ return ({ commands }) => {
2269
+ return commands.updateAttributes(this.name, attrs);
2270
+ };
2271
+ }
2272
+ };
2273
+ },
2274
+ addKeyboardShortcuts() {
2275
+ return {
2276
+ ...this.parent?.(),
2277
+ /**
2278
+ * Without this the browser selects the whole document from inside a code
2279
+ * block, because the block is one text node and nothing scopes the
2280
+ * selection to it.
2281
+ */
2282
+ "Mod-a": ({ editor }) => {
2283
+ const $pos = editor.state.selection.$anchor;
2284
+ if ($pos.node($pos.depth).type.name !== this.name) return false;
2285
+ let depth = $pos.depth;
2286
+ for (let level = depth; level > 0; level -= 1) if ($pos.node(level).type.name === this.name) {
2287
+ depth = level;
2288
+ break;
2289
+ }
2290
+ const from = editor.state.doc.resolve($pos.before(depth) + 1);
2291
+ const to = editor.state.doc.resolve($pos.after(depth) - 1);
2292
+ const transaction = editor.state.tr.setSelection(TextSelection.between(from, to));
2293
+ editor.view.dispatch(transaction);
2294
+ return true;
2295
+ },
2296
+ "Mod-Backspace": ({ editor }) => {
2297
+ return editor.commands.deleteNode(this.name);
2298
+ }
2299
+ };
2300
+ }
2301
+ }).configure({ lowlight });
2302
+ //#endregion
2303
+ //#region src/extensions/image-upload/upload-image-file.ts
2304
+ function notifyUploadStatusChanged(editor) {
2305
+ editor.view.dispatch(editor.state.tr.setMeta("__mly_image_upload_status_changed", true));
2306
+ }
2307
+ function getUploadOptions(editor) {
2308
+ const extension = editor.extensionManager.extensions.find((candidate) => candidate.name === IMAGE_UPLOAD_EXTENSION_NAME);
2309
+ invariant(extension, `You must add the "${IMAGE_UPLOAD_EXTENSION_NAME}" extension to the editor to upload images.`);
2310
+ return extension.options;
2311
+ }
2312
+ function findImageByBlobUrl(editor, blobUrl) {
2313
+ let found = null;
2314
+ editor.state.doc.descendants((node, pos) => {
2315
+ if (found) return false;
2316
+ if (node.type.name === MAILY_NODE_TYPES.IMAGE && node.attrs.src === blobUrl) {
2317
+ found = {
2318
+ node,
2319
+ pos
2320
+ };
2321
+ return false;
2322
+ }
2323
+ return true;
2324
+ });
2325
+ return found;
2326
+ }
2327
+ function updateImageByBlobUrl(editor, blobUrl, attrs) {
2328
+ const found = findImageByBlobUrl(editor, blobUrl);
2329
+ if (!found) return;
2330
+ const { tr } = editor.state;
2331
+ tr.setNodeMarkup(found.pos, void 0, {
2332
+ ...found.node.attrs,
2333
+ ...attrs
2334
+ });
2335
+ editor.view.dispatch(tr);
2336
+ }
2337
+ function removeImageByBlobUrl(editor, blobUrl) {
2338
+ const found = findImageByBlobUrl(editor, blobUrl);
2339
+ if (!found) return;
2340
+ editor.view.dispatch(editor.state.tr.delete(found.pos, found.pos + found.node.nodeSize));
2341
+ }
2342
+ function uploadImageFile(editor, file, position) {
2343
+ const { onImageUpload, onImageUploadError } = getUploadOptions(editor);
2344
+ if (!onImageUpload) return;
2345
+ const blobUrl = URL.createObjectURL(file);
2346
+ if (!editor.chain().insertContentAt(position, {
2347
+ type: MAILY_NODE_TYPES.IMAGE,
2348
+ attrs: { src: blobUrl }
2349
+ }).run()) {
2350
+ URL.revokeObjectURL(blobUrl);
2351
+ return;
2352
+ }
2353
+ const context = {
2354
+ position,
2355
+ removeImage: () => removeImageByBlobUrl(editor, blobUrl)
2356
+ };
2357
+ const { uploads } = editor.storage.imageUpload;
2358
+ uploads.set(blobUrl, IMAGE_UPLOAD_STATUSES.LOADING);
2359
+ notifyUploadStatusChanged(editor);
2360
+ onImageUpload(file, context).then((url) => {
2361
+ uploads.delete(blobUrl);
2362
+ notifyUploadStatusChanged(editor);
2363
+ updateImageByBlobUrl(editor, blobUrl, { src: url });
2364
+ URL.revokeObjectURL(blobUrl);
2365
+ }).catch((error) => {
2366
+ uploads.set(blobUrl, IMAGE_UPLOAD_STATUSES.ERROR);
2367
+ notifyUploadStatusChanged(editor);
2368
+ onImageUploadError?.(error, file, context);
2369
+ URL.revokeObjectURL(blobUrl);
2370
+ });
2371
+ }
2372
+ //#endregion
2373
+ //#region src/extensions/image-upload/image-upload.ts
2374
+ const IMAGE_UPLOAD_EXTENSION_NAME = "imageUpload";
2375
+ const IMAGE_UPLOAD_STATUSES = {
2376
+ IDLE: "idle",
2377
+ LOADING: "loading",
2378
+ ERROR: "error",
2379
+ LOADED: "loaded"
2380
+ };
2381
+ const ALLOWED_IMAGE_MIME_TYPES = [
2382
+ "image/jpeg",
2383
+ "image/png",
2384
+ "image/gif",
2385
+ "image/webp",
2386
+ "image/svg+xml"
2387
+ ];
2388
+ const ImageUploadExtension = Extension.create({
2389
+ name: IMAGE_UPLOAD_EXTENSION_NAME,
2390
+ addOptions() {
2391
+ return {
2392
+ onImageUpload: void 0,
2393
+ onImageUploadError: void 0
2394
+ };
2395
+ },
2396
+ addStorage() {
2397
+ return { uploads: /* @__PURE__ */ new Map() };
2398
+ },
2399
+ addExtensions() {
2400
+ return [FileHandler.configure({
2401
+ allowedMimeTypes: [...ALLOWED_IMAGE_MIME_TYPES],
2402
+ onDrop: (editor, files, pos) => {
2403
+ for (const file of files) uploadImageFile(editor, file, pos);
2404
+ },
2405
+ onPaste: (editor, files) => {
2406
+ for (const file of files) uploadImageFile(editor, file, editor.state.selection.from);
2407
+ }
2408
+ })];
2409
+ }
2410
+ });
2411
+ //#endregion
2412
+ //#region src/utils/pointer.ts
2413
+ function capturePointer(options) {
2414
+ const { element, pointerId } = options;
2415
+ try {
2416
+ element.setPointerCapture(pointerId);
2417
+ return true;
2418
+ } catch {
2419
+ return false;
2420
+ }
2421
+ }
2422
+ function releasePointer(options) {
2423
+ const { element, pointerId } = options;
2424
+ try {
2425
+ element.releasePointerCapture(pointerId);
2426
+ return true;
2427
+ } catch {
2428
+ return false;
2429
+ }
2430
+ }
2431
+ //#endregion
2432
+ //#region src/hooks/use-image-resize-controller.ts
2433
+ function useImageResizeController(options) {
2434
+ const $ = c(8);
2435
+ const { align, onWidthChange: t0, onWidthCommitted: t1 } = options;
2436
+ const onWidthChange = t0 === void 0 ? noop : t0;
2437
+ const onWidthCommitted = t1 === void 0 ? noop : t1;
2438
+ const containerRef = useRef(null);
2439
+ const imageWrapperRef = useRef(null);
2440
+ const [shouldShowDragHandles, setShouldShowDragHandles] = useState(false);
2441
+ const [isResizing, setIsResizing] = useState(false);
2442
+ let t2;
2443
+ if ($[0] !== align || $[1] !== onWidthChange || $[2] !== onWidthCommitted) {
2444
+ t2 = (event, initialResizeParams) => {
2445
+ let activeResizeState = initialResizeParams;
2446
+ let nextWidth = clampImageWidthPercentage(Math.round(percentage(initialResizeParams.initialWidth, containerRef.current?.clientWidth ?? 0)));
2447
+ const targetElement = event.currentTarget;
2448
+ capturePointer({
2449
+ element: targetElement,
2450
+ pointerId: event.pointerId
2451
+ });
2452
+ const handlePointerMove = (moveEvent) => {
2453
+ const imageWrapper = imageWrapperRef.current;
2454
+ const container = containerRef.current;
2455
+ if (!activeResizeState || !imageWrapper || !container) return;
2456
+ const pointerDeltaX = moveEvent.clientX - activeResizeState.initialClientX;
2457
+ const { handleUsed, initialWidth } = activeResizeState;
2458
+ const delta = handleUsed === "left" ? -pointerDeltaX : pointerDeltaX;
2459
+ const maxWidth = container.clientWidth;
2460
+ const newWidthInPixels = clamp(initialWidth + (align === TEXT_ALIGNMENTS.CENTER ? delta * 2 : delta), [0, maxWidth]);
2461
+ nextWidth = clamp(Math.round(percentage(newWidthInPixels, maxWidth)), [MIN_IMAGE_WIDTH_PERCENTAGE, MAX_IMAGE_WIDTH_PERCENTAGE]);
2462
+ imageWrapper.style.width = `${nextWidth}%`;
2463
+ onWidthChange(nextWidth);
2464
+ };
2465
+ const handlePointerUp = (upEvent) => {
2466
+ activeResizeState = null;
2467
+ setIsResizing(false);
2468
+ releasePointer({
2469
+ element: targetElement,
2470
+ pointerId: upEvent.pointerId
2471
+ });
2472
+ onWidthChange(nextWidth);
2473
+ onWidthCommitted(nextWidth);
2474
+ window.removeEventListener("pointermove", handlePointerMove);
2475
+ window.removeEventListener("pointerup", handlePointerUp);
2476
+ };
2477
+ window.addEventListener("pointermove", handlePointerMove);
2478
+ window.addEventListener("pointerup", handlePointerUp);
2479
+ setIsResizing(true);
2480
+ };
2481
+ $[0] = align;
2482
+ $[1] = onWidthChange;
2483
+ $[2] = onWidthCommitted;
2484
+ $[3] = t2;
2485
+ } else t2 = $[3];
2486
+ const handleResize = t2;
2487
+ let t3;
2488
+ if ($[4] !== handleResize || $[5] !== isResizing || $[6] !== shouldShowDragHandles) {
2489
+ t3 = {
2490
+ containerRef,
2491
+ handleResize,
2492
+ imageWrapperRef,
2493
+ isResizing,
2494
+ setShouldShowDragHandles,
2495
+ shouldShowDragHandles
2496
+ };
2497
+ $[4] = handleResize;
2498
+ $[5] = isResizing;
2499
+ $[6] = shouldShowDragHandles;
2500
+ $[7] = t3;
2501
+ } else t3 = $[7];
2502
+ return t3;
2503
+ }
2504
+ //#endregion
2505
+ //#region src/extensions/image/image-handle.tsx
2506
+ function ImageHandle(props) {
2507
+ const $ = c(6);
2508
+ let handle;
2509
+ let rest;
2510
+ if ($[0] !== props) {
2511
+ ({handle, ...rest} = props);
2512
+ $[0] = props;
2513
+ $[1] = handle;
2514
+ $[2] = rest;
2515
+ } else {
2516
+ handle = $[1];
2517
+ rest = $[2];
2518
+ }
2519
+ let t0;
2520
+ if ($[3] !== handle || $[4] !== rest) {
2521
+ t0 = /* @__PURE__ */ jsx("div", {
2522
+ ...rest,
2523
+ "data-mly-image-handle": "",
2524
+ "data-side": handle
2525
+ });
2526
+ $[3] = handle;
2527
+ $[4] = rest;
2528
+ $[5] = t0;
2529
+ } else t0 = $[5];
2530
+ return t0;
2531
+ }
2532
+ //#endregion
2533
+ //#region src/components/interface/visually-hidden.tsx
2534
+ function VisuallyHidden(props) {
2535
+ const $ = c(8);
2536
+ let rest;
2537
+ let style;
2538
+ if ($[0] !== props) {
2539
+ ({style, ...rest} = props);
2540
+ $[0] = props;
2541
+ $[1] = rest;
2542
+ $[2] = style;
2543
+ } else {
2544
+ rest = $[1];
2545
+ style = $[2];
2546
+ }
2547
+ let t0;
2548
+ if ($[3] !== style) {
2549
+ t0 = {
2550
+ border: 0,
2551
+ clipPath: "inset(50%)",
2552
+ height: 1,
2553
+ margin: -1,
2554
+ overflow: "hidden",
2555
+ padding: 0,
2556
+ position: "absolute",
2557
+ whiteSpace: "nowrap",
2558
+ width: 1,
2559
+ ...style
2560
+ };
2561
+ $[3] = style;
2562
+ $[4] = t0;
2563
+ } else t0 = $[4];
2564
+ let t1;
2565
+ if ($[5] !== rest || $[6] !== t0) {
2566
+ t1 = /* @__PURE__ */ jsx("span", {
2567
+ "data-mly-visually-hidden": "",
2568
+ ...rest,
2569
+ style: t0
2570
+ });
2571
+ $[5] = rest;
2572
+ $[6] = t0;
2573
+ $[7] = t1;
2574
+ } else t1 = $[7];
2575
+ return t1;
2576
+ }
2577
+ //#endregion
2578
+ //#region src/extensions/image/image-state.tsx
2579
+ function ImageState(props) {
2580
+ const $ = c(14);
2581
+ let Icon;
2582
+ let children;
2583
+ let rest;
2584
+ let state;
2585
+ if ($[0] !== props) {
2586
+ ({children, icon: Icon, state, ...rest} = props);
2587
+ $[0] = props;
2588
+ $[1] = Icon;
2589
+ $[2] = children;
2590
+ $[3] = rest;
2591
+ $[4] = state;
2592
+ } else {
2593
+ Icon = $[1];
2594
+ children = $[2];
2595
+ rest = $[3];
2596
+ state = $[4];
2597
+ }
2598
+ let t0;
2599
+ if ($[5] !== Icon) {
2600
+ t0 = Icon ? /* @__PURE__ */ jsx(Icon, {
2601
+ size: 16,
2602
+ strokeWidth: 2.5
2603
+ }) : null;
2604
+ $[5] = Icon;
2605
+ $[6] = t0;
2606
+ } else t0 = $[6];
2607
+ let t1;
2608
+ if ($[7] !== children) {
2609
+ t1 = /* @__PURE__ */ jsx("span", {
2610
+ "data-mly-image-state-label": "",
2611
+ children
2612
+ });
2613
+ $[7] = children;
2614
+ $[8] = t1;
2615
+ } else t1 = $[8];
2616
+ let t2;
2617
+ if ($[9] !== rest || $[10] !== state || $[11] !== t0 || $[12] !== t1) {
2618
+ t2 = /* @__PURE__ */ jsxs("div", {
2619
+ ...rest,
2620
+ "data-mly-image-state": "",
2621
+ "data-state": state,
2622
+ children: [t0, t1]
2623
+ });
2624
+ $[9] = rest;
2625
+ $[10] = state;
2626
+ $[11] = t0;
2627
+ $[12] = t1;
2628
+ $[13] = t2;
2629
+ } else t2 = $[13];
2630
+ return t2;
2631
+ }
2632
+ function ImageIdleState() {
2633
+ const $ = c(1);
2634
+ let t0;
2635
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
2636
+ t0 = /* @__PURE__ */ jsx(ImageState, {
2637
+ state: "idle",
2638
+ children: "No image"
2639
+ });
2640
+ $[0] = t0;
2641
+ } else t0 = $[0];
2642
+ return t0;
2643
+ }
2644
+ function ImageErrorState() {
2645
+ const $ = c(1);
2646
+ let t0;
2647
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
2648
+ t0 = /* @__PURE__ */ jsx(ImageState, {
2649
+ role: "alert",
2650
+ state: "error",
2651
+ children: "Failed to upload image"
2652
+ });
2653
+ $[0] = t0;
2654
+ } else t0 = $[0];
2655
+ return t0;
2656
+ }
2657
+ function ImageVariableState() {
2658
+ const $ = c(1);
2659
+ let t0;
2660
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
2661
+ t0 = /* @__PURE__ */ jsx(ImageState, {
2662
+ state: "variable",
2663
+ children: "Dynamic image source"
2664
+ });
2665
+ $[0] = t0;
2666
+ } else t0 = $[0];
2667
+ return t0;
2668
+ }
2669
+ function ImageLoadingState(props) {
2670
+ const $ = c(7);
2671
+ const { alt, src } = props;
2672
+ const t0 = alt ?? void 0;
2673
+ let t1;
2674
+ if ($[0] !== src || $[1] !== t0) {
2675
+ t1 = /* @__PURE__ */ jsx("img", {
2676
+ alt: t0,
2677
+ "data-mly-image-preview": "",
2678
+ src
2679
+ });
2680
+ $[0] = src;
2681
+ $[1] = t0;
2682
+ $[2] = t1;
2683
+ } else t1 = $[2];
2684
+ let t2;
2685
+ let t3;
2686
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
2687
+ t2 = /* @__PURE__ */ jsx("span", { "data-mly-image-spinner": "" });
2688
+ t3 = /* @__PURE__ */ jsx(VisuallyHidden, {
2689
+ role: "status",
2690
+ children: "Uploading image"
2691
+ });
2692
+ $[3] = t2;
2693
+ $[4] = t3;
2694
+ } else {
2695
+ t2 = $[3];
2696
+ t3 = $[4];
2697
+ }
2698
+ let t4;
2699
+ if ($[5] !== t1) {
2700
+ t4 = /* @__PURE__ */ jsxs("div", {
2701
+ "aria-busy": "true",
2702
+ "data-mly-image-loading": "",
2703
+ children: [
2704
+ t1,
2705
+ t2,
2706
+ t3
2707
+ ]
2708
+ });
2709
+ $[5] = t1;
2710
+ $[6] = t4;
2711
+ } else t4 = $[6];
2712
+ return t4;
2713
+ }
2714
+ function ImagePlaceholder(props) {
2715
+ const $ = c(3);
2716
+ const { onFileSelect } = props;
2717
+ let t0;
2718
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
2719
+ t0 = ALLOWED_IMAGE_MIME_TYPES.join(",");
2720
+ $[0] = t0;
2721
+ } else t0 = $[0];
2722
+ let t1;
2723
+ if ($[1] !== onFileSelect) {
2724
+ t1 = /* @__PURE__ */ jsxs(ImageState, {
2725
+ state: "placeholder",
2726
+ children: ["Click or drop an image here", /* @__PURE__ */ jsx("input", {
2727
+ accept: t0,
2728
+ "data-mly-image-input": "",
2729
+ onChange: (event) => {
2730
+ const file = event.target.files?.[0];
2731
+ if (file) onFileSelect(file);
2732
+ },
2733
+ type: "file"
2734
+ })]
2735
+ });
2736
+ $[1] = onFileSelect;
2737
+ $[2] = t1;
2738
+ } else t1 = $[2];
2739
+ return t1;
2740
+ }
2741
+ //#endregion
2742
+ //#region src/extensions/image/image-view.tsx
2743
+ function useUploadStatus(editor, src) {
2744
+ const $ = c(5);
2745
+ let t0;
2746
+ if ($[0] !== src) {
2747
+ t0 = (ctx) => src ? ctx.editor.storage.imageUpload?.uploads.get(src) : void 0;
2748
+ $[0] = src;
2749
+ $[1] = t0;
2750
+ } else t0 = $[1];
2751
+ let t1;
2752
+ if ($[2] !== editor || $[3] !== t0) {
2753
+ t1 = {
2754
+ editor,
2755
+ selector: t0
2756
+ };
2757
+ $[2] = editor;
2758
+ $[3] = t0;
2759
+ $[4] = t1;
2760
+ } else t1 = $[4];
2761
+ const status = useEditorState(t1);
2762
+ if (!src) return IMAGE_UPLOAD_STATUSES.IDLE;
2763
+ return status ?? IMAGE_UPLOAD_STATUSES.LOADED;
2764
+ }
2765
+ function ImageView(props) {
2766
+ const $ = c(65);
2767
+ const { editor, getPos, node, updateAttributes } = props;
2768
+ const { align, alt, src, width, style } = node.attrs;
2769
+ const t0 = style ?? "";
2770
+ let t1;
2771
+ if ($[0] !== t0) {
2772
+ t1 = parseInlineStyles(t0);
2773
+ $[0] = t0;
2774
+ $[1] = t1;
2775
+ } else t1 = $[1];
2776
+ let authoredStyle;
2777
+ if ($[2] !== t1) {
2778
+ const { width: _width, maxWidth: _maxWidth, height: _height, ...t2 } = t1;
2779
+ authoredStyle = t2;
2780
+ $[2] = t1;
2781
+ $[3] = authoredStyle;
2782
+ } else authoredStyle = $[3];
2783
+ let t2;
2784
+ if ($[4] !== src) {
2785
+ t2 = !!src && hasVariableInText(src);
2786
+ $[4] = src;
2787
+ $[5] = t2;
2788
+ } else t2 = $[5];
2789
+ const isSrcVariable = t2;
2790
+ const status = useUploadStatus(editor, isSrcVariable ? void 0 : src);
2791
+ let t3;
2792
+ if ($[6] !== updateAttributes) {
2793
+ t3 = (committed) => updateAttributes({ width: `${committed}%` });
2794
+ $[6] = updateAttributes;
2795
+ $[7] = t3;
2796
+ } else t3 = $[7];
2797
+ const t4 = t3;
2798
+ let t5;
2799
+ if ($[8] !== align || $[9] !== t4) {
2800
+ t5 = {
2801
+ align,
2802
+ onWidthCommitted: t4
2803
+ };
2804
+ $[8] = align;
2805
+ $[9] = t4;
2806
+ $[10] = t5;
2807
+ } else t5 = $[10];
2808
+ const { containerRef, handleResize, imageWrapperRef, isResizing, setShouldShowDragHandles, shouldShowDragHandles } = useImageResizeController(t5);
2809
+ let t6;
2810
+ if ($[11] !== handleResize || $[12] !== imageWrapperRef) {
2811
+ t6 = (handle, event) => {
2812
+ const imageWrapper = imageWrapperRef.current;
2813
+ if (!imageWrapper) return;
2814
+ event.preventDefault();
2815
+ handleResize(event, {
2816
+ handleUsed: handle,
2817
+ initialClientX: event.clientX,
2818
+ initialWidth: imageWrapper.clientWidth
2819
+ });
2820
+ };
2821
+ $[11] = handleResize;
2822
+ $[12] = imageWrapperRef;
2823
+ $[13] = t6;
2824
+ } else t6 = $[13];
2825
+ const handlePointerDown = t6;
2826
+ let t7;
2827
+ if ($[14] !== editor || $[15] !== getPos || $[16] !== node.nodeSize) {
2828
+ t7 = (file) => {
2829
+ const pos = getPos();
2830
+ if (pos == null) return;
2831
+ editor.view.dispatch(editor.state.tr.delete(pos, pos + node.nodeSize));
2832
+ uploadImageFile(editor, file, pos);
2833
+ };
2834
+ $[14] = editor;
2835
+ $[15] = getPos;
2836
+ $[16] = node.nodeSize;
2837
+ $[17] = t7;
2838
+ } else t7 = $[17];
2839
+ const handleFileSelect = t7;
2840
+ const isLoaded = status === IMAGE_UPLOAD_STATUSES.LOADED;
2841
+ const t8 = editor.isEditable && isLoaded;
2842
+ const t9 = editor.isEditable && isLoaded;
2843
+ let t10;
2844
+ if ($[18] !== editor.isEditable || $[19] !== setShouldShowDragHandles) {
2845
+ t10 = () => setShouldShowDragHandles(editor.isEditable);
2846
+ $[18] = editor.isEditable;
2847
+ $[19] = setShouldShowDragHandles;
2848
+ $[20] = t10;
2849
+ } else t10 = $[20];
2850
+ let t11;
2851
+ if ($[21] !== setShouldShowDragHandles) {
2852
+ t11 = () => setShouldShowDragHandles(false);
2853
+ $[21] = setShouldShowDragHandles;
2854
+ $[22] = t11;
2855
+ } else t11 = $[22];
2856
+ let t12;
2857
+ if ($[23] !== width) {
2858
+ t12 = { width };
2859
+ $[23] = width;
2860
+ $[24] = t12;
2861
+ } else t12 = $[24];
2862
+ let t13;
2863
+ if ($[25] !== isSrcVariable) {
2864
+ t13 = isSrcVariable ? /* @__PURE__ */ jsx(ImageVariableState, {}) : null;
2865
+ $[25] = isSrcVariable;
2866
+ $[26] = t13;
2867
+ } else t13 = $[26];
2868
+ let t14;
2869
+ if ($[27] !== editor.isEditable || $[28] !== handleFileSelect || $[29] !== isSrcVariable || $[30] !== status) {
2870
+ t14 = !isSrcVariable && status === IMAGE_UPLOAD_STATUSES.IDLE ? editor.isEditable ? /* @__PURE__ */ jsx(ImagePlaceholder, { onFileSelect: handleFileSelect }) : /* @__PURE__ */ jsx(ImageIdleState, {}) : null;
2871
+ $[27] = editor.isEditable;
2872
+ $[28] = handleFileSelect;
2873
+ $[29] = isSrcVariable;
2874
+ $[30] = status;
2875
+ $[31] = t14;
2876
+ } else t14 = $[31];
2877
+ let t15;
2878
+ if ($[32] !== alt || $[33] !== isSrcVariable || $[34] !== src || $[35] !== status) {
2879
+ t15 = !isSrcVariable && status === IMAGE_UPLOAD_STATUSES.LOADING ? /* @__PURE__ */ jsx(ImageLoadingState, {
2880
+ alt,
2881
+ src
2882
+ }) : null;
2883
+ $[32] = alt;
2884
+ $[33] = isSrcVariable;
2885
+ $[34] = src;
2886
+ $[35] = status;
2887
+ $[36] = t15;
2888
+ } else t15 = $[36];
2889
+ let t16;
2890
+ if ($[37] !== status) {
2891
+ t16 = status === IMAGE_UPLOAD_STATUSES.ERROR ? /* @__PURE__ */ jsx(ImageErrorState, {}) : null;
2892
+ $[37] = status;
2893
+ $[38] = t16;
2894
+ } else t16 = $[38];
2895
+ let t17;
2896
+ if ($[39] !== alt || $[40] !== authoredStyle || $[41] !== editor.isEditable || $[42] !== handlePointerDown || $[43] !== isLoaded || $[44] !== isResizing || $[45] !== isSrcVariable || $[46] !== shouldShowDragHandles || $[47] !== src) {
2897
+ t17 = !isSrcVariable && isLoaded ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("img", {
2898
+ alt: alt ?? void 0,
2899
+ contentEditable: false,
2900
+ "data-mly-image": "",
2901
+ draggable: editor.isEditable,
2902
+ src,
2903
+ style: authoredStyle
2904
+ }), shouldShowDragHandles || isResizing ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ImageHandle, {
2905
+ handle: "left",
2906
+ onPointerDown: (event_0) => handlePointerDown("left", event_0)
2907
+ }), /* @__PURE__ */ jsx(ImageHandle, {
2908
+ handle: "right",
2909
+ onPointerDown: (event_1) => handlePointerDown("right", event_1)
2910
+ })] }) : null] }) : null;
2911
+ $[39] = alt;
2912
+ $[40] = authoredStyle;
2913
+ $[41] = editor.isEditable;
2914
+ $[42] = handlePointerDown;
2915
+ $[43] = isLoaded;
2916
+ $[44] = isResizing;
2917
+ $[45] = isSrcVariable;
2918
+ $[46] = shouldShowDragHandles;
2919
+ $[47] = src;
2920
+ $[48] = t17;
2921
+ } else t17 = $[48];
2922
+ let t18;
2923
+ if ($[49] !== align || $[50] !== imageWrapperRef || $[51] !== t12 || $[52] !== t13 || $[53] !== t14 || $[54] !== t15 || $[55] !== t16 || $[56] !== t17) {
2924
+ t18 = /* @__PURE__ */ jsxs("div", {
2925
+ "data-align": align,
2926
+ "data-mly-image-wrapper": "",
2927
+ ref: imageWrapperRef,
2928
+ style: t12,
2929
+ children: [
2930
+ t13,
2931
+ t14,
2932
+ t15,
2933
+ t16,
2934
+ t17
2935
+ ]
2936
+ });
2937
+ $[49] = align;
2938
+ $[50] = imageWrapperRef;
2939
+ $[51] = t12;
2940
+ $[52] = t13;
2941
+ $[53] = t14;
2942
+ $[54] = t15;
2943
+ $[55] = t16;
2944
+ $[56] = t17;
2945
+ $[57] = t18;
2946
+ } else t18 = $[57];
2947
+ let t19;
2948
+ if ($[58] !== containerRef || $[59] !== t10 || $[60] !== t11 || $[61] !== t18 || $[62] !== t8 || $[63] !== t9) {
2949
+ t19 = /* @__PURE__ */ jsx(NodeViewWrapper, {
2950
+ "data-drag-handle": t8,
2951
+ "data-mly-image-view": "",
2952
+ draggable: t9,
2953
+ onMouseEnter: t10,
2954
+ onMouseLeave: t11,
2955
+ ref: containerRef,
2956
+ children: t18
2957
+ });
2958
+ $[58] = containerRef;
2959
+ $[59] = t10;
2960
+ $[60] = t11;
2961
+ $[61] = t18;
2962
+ $[62] = t8;
2963
+ $[63] = t9;
2964
+ $[64] = t19;
2965
+ } else t19 = $[64];
2966
+ return t19;
2967
+ }
2968
+ //#endregion
2969
+ //#region src/extensions/image/image.ts
2970
+ const DEFAULT_IMAGE_ALIGN = DEFAULT_TEXT_ALIGN;
2971
+ const DEFAULT_IMAGE_WIDTH = "100%";
2972
+ const UNITLESS_REGEX = /^-?\d*\.?\d+$/;
2973
+ const ImageExtension = Image.extend({
2974
+ name: MAILY_NODE_TYPES.IMAGE,
2975
+ addAttributes() {
2976
+ return {
2977
+ ...this.parent?.(),
2978
+ width: {
2979
+ default: DEFAULT_IMAGE_WIDTH,
2980
+ parseHTML: (element) => {
2981
+ const width = element.style.width || element.getAttribute("width");
2982
+ if (!width) return DEFAULT_IMAGE_WIDTH;
2983
+ return UNITLESS_REGEX.test(width) ? `${width}px` : width;
2984
+ },
2985
+ renderHTML: (attributes) => ({ width: attributes.width })
2986
+ },
2987
+ align: {
2988
+ default: DEFAULT_IMAGE_ALIGN,
2989
+ parseHTML: (element) => {
2990
+ const align = element.getAttribute("data-align");
2991
+ return isAllowedTextAlignment(align) ? align : DEFAULT_IMAGE_ALIGN;
2992
+ },
2993
+ renderHTML: (attributes) => ({ "data-align": attributes.align })
2994
+ },
2995
+ externalLink: {
2996
+ default: null,
2997
+ parseHTML: (element) => element.getAttribute("data-external-link"),
2998
+ renderHTML: (attributes) => attributes.externalLink ? { "data-external-link": attributes.externalLink } : {}
2999
+ }
3000
+ };
3001
+ },
3002
+ addNodeView() {
3003
+ return ReactNodeViewRenderer(ImageView, { attrs: () => ({ [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.IMAGE }) });
3004
+ }
3005
+ }).configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.IMAGE } });
3006
+ //#endregion
3007
+ //#region src/extensions/inline-image/inline-image.ts
3008
+ const DEFAULT_INLINE_IMAGE_SIZE = 20;
3009
+ const INLINE_PARENTS = /* @__PURE__ */ new Set([
3010
+ "A",
3011
+ "B",
3012
+ "EM",
3013
+ "I",
3014
+ "SPAN",
3015
+ "STRONG"
3016
+ ]);
3017
+ const InlineImageExtension = Node$1.create({
3018
+ name: MAILY_NODE_TYPES.INLINE_IMAGE,
3019
+ group: "inline",
3020
+ inline: true,
3021
+ atom: true,
3022
+ selectable: true,
3023
+ addOptions() {
3024
+ return { HTMLAttributes: {} };
3025
+ },
3026
+ addAttributes() {
3027
+ return {
3028
+ src: {
3029
+ default: "",
3030
+ parseHTML: (element) => element.getAttribute("src") || "",
3031
+ renderHTML: (attributes) => attributes.src ? { src: attributes.src } : {}
3032
+ },
3033
+ alt: {
3034
+ default: null,
3035
+ parseHTML: (element) => element.getAttribute("alt"),
3036
+ renderHTML: (attributes) => attributes.alt ? { alt: attributes.alt } : {}
3037
+ },
3038
+ title: {
3039
+ default: null,
3040
+ parseHTML: (element) => element.getAttribute("title"),
3041
+ renderHTML: (attributes) => attributes.title ? { title: attributes.title } : {}
3042
+ },
3043
+ width: {
3044
+ default: DEFAULT_INLINE_IMAGE_SIZE,
3045
+ parseHTML: (element) => Number(element.getAttribute("width")) || DEFAULT_INLINE_IMAGE_SIZE,
3046
+ renderHTML: (attributes) => ({ width: attributes.width })
3047
+ },
3048
+ height: {
3049
+ default: DEFAULT_INLINE_IMAGE_SIZE,
3050
+ parseHTML: (element) => Number(element.getAttribute("height")) || DEFAULT_INLINE_IMAGE_SIZE,
3051
+ renderHTML: (attributes) => ({ height: attributes.height })
3052
+ },
3053
+ externalLink: {
3054
+ default: null,
3055
+ parseHTML: (element) => element.getAttribute("data-external-link"),
3056
+ renderHTML: (attributes) => attributes.externalLink ? { "data-external-link": attributes.externalLink } : {}
3057
+ }
3058
+ };
3059
+ },
3060
+ addCommands() {
3061
+ return {
3062
+ setInlineImage: (attrs) => ({ commands }) => commands.insertContent({
3063
+ type: this.name,
3064
+ attrs
3065
+ }),
3066
+ updateInlineImageAttributes: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
3067
+ };
3068
+ },
3069
+ parseHTML() {
3070
+ return [{ tag: `img[${DATA_NODE_TYPE_KEY}="${this.name}"]` }, {
3071
+ tag: "img[src]",
3072
+ priority: 60,
3073
+ getAttrs: (element) => {
3074
+ const parent = element.parentElement;
3075
+ return parent && INLINE_PARENTS.has(parent.tagName) ? null : false;
3076
+ }
3077
+ }];
3078
+ },
3079
+ renderHTML({ HTMLAttributes }) {
3080
+ return ["img", mergeAttributes({ [DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes)];
3081
+ }
3082
+ });
3083
+ //#endregion
3084
+ //#region src/extensions/inline-span/inline-span.ts
3085
+ const InlineSpanExtension = Node$1.create({
3086
+ name: MAILY_NODE_TYPES.INLINE_SPAN,
3087
+ group: "inline",
3088
+ inline: true,
3089
+ atom: true,
3090
+ selectable: true,
3091
+ parseHTML() {
3092
+ return [{
3093
+ tag: "span[style]",
3094
+ priority: 60,
3095
+ getAttrs: (element) => {
3096
+ return element.childNodes.length === 0 ? null : false;
3097
+ }
3098
+ }];
3099
+ },
3100
+ renderHTML({ HTMLAttributes }) {
3101
+ return ["span", mergeAttributes(HTMLAttributes)];
3102
+ }
3103
+ });
3104
+ //#endregion
3105
+ //#region src/extensions/paragraph/paragraph.ts
3106
+ const ParagraphExtension = Paragraph.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.PARAGRAPH } });
3107
+ //#endregion
3108
+ //#region src/extensions/placeholder/placeholder.ts
3109
+ const PlaceholderExtension = Placeholder.configure({
3110
+ placeholder: ({ node }) => {
3111
+ const { name } = node.type;
3112
+ if (name === MAILY_NODE_TYPES.HEADING) return `Heading ${node.attrs.level}`;
3113
+ else if (name === MAILY_NODE_TYPES.HTML_CODE_BLOCK) return "Type your HTML code...";
3114
+ else if ([
3115
+ MAILY_NODE_TYPES.BUTTON,
3116
+ MAILY_NODE_TYPES.SECTION,
3117
+ MAILY_NODE_TYPES.BULLET_LIST,
3118
+ MAILY_NODE_TYPES.ORDERED_LIST,
3119
+ MAILY_NODE_TYPES.LIST_ITEM,
3120
+ MAILY_NODE_TYPES.COLUMNS,
3121
+ MAILY_NODE_TYPES.COLUMN,
3122
+ MAILY_NODE_TYPES.REPEAT,
3123
+ MAILY_NODE_TYPES.BLOCKQUOTE
3124
+ ].includes(name)) return "";
3125
+ return "Write something or / to see commands";
3126
+ },
3127
+ includeChildren: true
3128
+ });
3129
+ //#endregion
3130
+ //#region src/extensions/section/section.ts
3131
+ const SectionExtension = Node$1.create({
3132
+ name: MAILY_NODE_TYPES.SECTION,
3133
+ group: "block",
3134
+ content: "block+",
3135
+ defining: true,
3136
+ isolating: true,
3137
+ addCommands() {
3138
+ return {
3139
+ setSection: () => ({ commands }) => commands.insertContent({
3140
+ type: this.name,
3141
+ content: [{ type: MAILY_NODE_TYPES.PARAGRAPH }]
3142
+ }),
3143
+ updateSection: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
3144
+ };
3145
+ },
3146
+ addKeyboardShortcuts() {
3147
+ return { Enter: ({ editor }) => {
3148
+ return exitOnTripleEnter({
3149
+ editor,
3150
+ nodeName: this.name
3151
+ });
3152
+ } };
3153
+ },
3154
+ parseHTML() {
3155
+ return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${MAILY_NODE_TYPES.SECTION}"]` }];
3156
+ },
3157
+ renderHTML({ HTMLAttributes }) {
3158
+ return [
3159
+ "div",
3160
+ mergeAttributes({ [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.SECTION }, HTMLAttributes),
3161
+ 0
3162
+ ];
3163
+ }
3164
+ });
3165
+ //#endregion
3166
+ //#region src/extensions/slash-command/default-slash-commands.tsx
3167
+ const DEFAULT_SLASH_COMMANDS = [{
3168
+ title: "Blocks",
3169
+ commands: [
3170
+ text,
3171
+ heading1,
3172
+ heading2,
3173
+ heading3,
3174
+ bulletList,
3175
+ orderedList,
3176
+ blockquote,
3177
+ image,
3178
+ inlineImage,
3179
+ divider,
3180
+ spacer,
3181
+ section,
3182
+ columns,
3183
+ repeat,
3184
+ button,
3185
+ linkCard,
3186
+ footer,
3187
+ hardBreak,
3188
+ clearLine
3189
+ ]
3190
+ }, {
3191
+ title: "Components",
3192
+ commands: [
3193
+ {
3194
+ id: "headers",
3195
+ title: "Headers",
3196
+ icon: /* @__PURE__ */ jsx(Heading1Icon, { size: 16 }),
3197
+ description: "Pre-designed headers block",
3198
+ searchTerms: ["header", "headers"],
3199
+ commands: [
3200
+ headerLogoWithTextVertical,
3201
+ headerLogoWithTextHorizontal,
3202
+ headerLogoWithCoverImage
3203
+ ]
3204
+ },
3205
+ {
3206
+ id: "footers",
3207
+ title: "Footers",
3208
+ icon: /* @__PURE__ */ jsx(FootprintsIcon, { size: 16 }),
3209
+ description: "Pre-designed footers block",
3210
+ searchTerms: ["footer", "footers"],
3211
+ commands: [
3212
+ footerCopyrightText,
3213
+ footerCommunityFeedbackCta,
3214
+ footerCompanySignature
3215
+ ]
3216
+ },
3217
+ htmlCodeBlock
3218
+ ]
3219
+ }];
3220
+ //#endregion
3221
+ //#region src/utils/slash-command.ts
3222
+ const SLASH_COMMAND_SUGGESTION_POPOVER_ID = "mly-slash-command-suggestion-popover";
3223
+ function isNestedCommand(item) {
3224
+ return "commands" in item && Array.isArray(item.commands) && !!item.id;
3225
+ }
3226
+ function match(item, search) {
3227
+ return item.title.toLowerCase().includes(search) || (item.description?.toLowerCase().includes(search) ?? false) || item.searchTerms.some((term) => term.toLowerCase().includes(search));
3228
+ }
3229
+ function findNestedCommand(groups, id) {
3230
+ const lowerId = id.toLowerCase();
3231
+ for (const group of groups) for (const command of group.commands) if (isNestedCommand(command) && command.id.toLowerCase() === lowerId) return command;
3232
+ }
3233
+ function getVisibleGroups(options) {
3234
+ const { editor, groups } = options;
3235
+ const isVisible = (item) => {
3236
+ return item.render?.(editor) !== null;
3237
+ };
3238
+ return groups.map((group) => {
3239
+ return {
3240
+ ...group,
3241
+ commands: group.commands.filter(isVisible).map((item) => {
3242
+ return isNestedCommand(item) ? {
3243
+ ...item,
3244
+ commands: item.commands.filter(isVisible)
3245
+ } : item;
3246
+ })
3247
+ };
3248
+ });
3249
+ }
3250
+ /**
3251
+ * Filters slash command groups by query. Supports nested commands
3252
+ * via dot notation (e.g. "headers.h1"). When a nested group matches,
3253
+ * it's expanded inline and made navigable.
3254
+ */
3255
+ function filterSlashCommands(options) {
3256
+ const { editor, query } = options;
3257
+ const groups = getVisibleGroups({
3258
+ editor,
3259
+ groups: options.groups
3260
+ });
3261
+ const search = query.toLowerCase();
3262
+ const subCommandMatch = /^([^.]+)\./.exec(search);
3263
+ if (subCommandMatch) {
3264
+ const [fullMatch, subCommandId] = subCommandMatch;
3265
+ const subCommand = findNestedCommand(groups, subCommandId);
3266
+ if (!subCommand) return [];
3267
+ const remainingSearch = search.slice(fullMatch.length);
3268
+ const filtered = subCommand.commands.filter((item) => !remainingSearch || match(item, remainingSearch));
3269
+ return filtered.length ? [{
3270
+ ...subCommand,
3271
+ commands: filtered
3272
+ }] : [];
3273
+ }
3274
+ return groups.map((group) => ({
3275
+ ...group,
3276
+ commands: group.commands.flatMap((item) => {
3277
+ if (!isNestedCommand(item)) return !search || match(item, search) ? [item] : [];
3278
+ const navigable = {
3279
+ ...item,
3280
+ command: ({ editor, range }) => {
3281
+ editor.chain().focus().insertContentAt(range, `/${item.id}.`).run();
3282
+ }
3283
+ };
3284
+ if (match(navigable, search)) return [navigable];
3285
+ return item.commands.some((child) => match(child, search)) ? item.commands : [];
3286
+ })
3287
+ })).filter((group) => group.commands.length > 0);
3288
+ }
3289
+ //#endregion
3290
+ //#region src/hooks/use-delayed-state.ts
3291
+ function useDelayedState(isOpen, t0) {
3292
+ const $ = c(6);
3293
+ let t1;
3294
+ if ($[0] !== t0) {
3295
+ t1 = t0 === void 0 ? {} : t0;
3296
+ $[0] = t0;
3297
+ $[1] = t1;
3298
+ } else t1 = $[1];
3299
+ const { delay: t2 } = t1;
3300
+ const delay = t2 === void 0 ? 200 : t2;
3301
+ const [value, setValue] = useState(false);
3302
+ const timerRef = useRef(0);
3303
+ let t3;
3304
+ let t4;
3305
+ if ($[2] !== delay || $[3] !== isOpen) {
3306
+ t3 = () => {
3307
+ window.clearTimeout(timerRef.current);
3308
+ if (!isOpen) {
3309
+ timerRef.current = 0;
3310
+ setValue(false);
3311
+ return;
3312
+ }
3313
+ timerRef.current = window.setTimeout(() => {
3314
+ setValue(true);
3315
+ timerRef.current = 0;
3316
+ }, delay);
3317
+ return () => {
3318
+ if (!timerRef.current) return;
3319
+ window.clearTimeout(timerRef.current);
3320
+ timerRef.current = 0;
3321
+ };
3322
+ };
3323
+ t4 = [delay, isOpen];
3324
+ $[2] = delay;
3325
+ $[3] = isOpen;
3326
+ $[4] = t3;
3327
+ $[5] = t4;
3328
+ } else {
3329
+ t3 = $[4];
3330
+ t4 = $[5];
3331
+ }
3332
+ useEffect(t3, t4);
3333
+ return value;
3334
+ }
3335
+ //#endregion
3336
+ //#region src/extensions/slash-command/slash-command-item.tsx
3337
+ function SlashCommandItem(props) {
3338
+ const $ = c(36);
3339
+ let editor;
3340
+ let hoveredKey;
3341
+ let isSelected;
3342
+ let item;
3343
+ let itemKey;
3344
+ let onHover;
3345
+ let rest;
3346
+ if ($[0] !== props) {
3347
+ ({editor, hoveredKey, isSelected, item, itemKey, onHover, ...rest} = props);
3348
+ $[0] = props;
3349
+ $[1] = editor;
3350
+ $[2] = hoveredKey;
3351
+ $[3] = isSelected;
3352
+ $[4] = item;
3353
+ $[5] = itemKey;
3354
+ $[6] = onHover;
3355
+ $[7] = rest;
3356
+ } else {
3357
+ editor = $[1];
3358
+ hoveredKey = $[2];
3359
+ isSelected = $[3];
3360
+ item = $[4];
3361
+ itemKey = $[5];
3362
+ onHover = $[6];
3363
+ rest = $[7];
3364
+ }
3365
+ const isHovered = hoveredKey === itemKey;
3366
+ const isNested = "commands" in item;
3367
+ const open = useDelayedState(Boolean(item.preview) && (isHovered || isSelected && !hoveredKey));
3368
+ let t0;
3369
+ if ($[8] !== editor || $[9] !== item) {
3370
+ t0 = item.render ? item.render(editor) : null;
3371
+ $[8] = editor;
3372
+ $[9] = item;
3373
+ $[10] = t0;
3374
+ } else t0 = $[10];
3375
+ const rendered = t0;
3376
+ const isCustomRow = rendered !== null && rendered !== true && rendered !== void 0;
3377
+ const t1 = isSelected ? "" : void 0;
3378
+ let t2;
3379
+ let t3;
3380
+ if ($[11] !== onHover) {
3381
+ t2 = () => onHover(true);
3382
+ t3 = () => onHover(false);
3383
+ $[11] = onHover;
3384
+ $[12] = t2;
3385
+ $[13] = t3;
3386
+ } else {
3387
+ t2 = $[12];
3388
+ t3 = $[13];
3389
+ }
3390
+ let t4;
3391
+ if ($[14] !== isCustomRow || $[15] !== isNested || $[16] !== item.description || $[17] !== item.icon || $[18] !== item.title || $[19] !== rendered) {
3392
+ t4 = isCustomRow ? rendered : /* @__PURE__ */ jsxs(Fragment$1, { children: [
3393
+ item.icon ? /* @__PURE__ */ jsx("span", {
3394
+ "data-mly-slash-command-icon": "",
3395
+ children: item.icon
3396
+ }) : null,
3397
+ /* @__PURE__ */ jsxs("span", {
3398
+ "data-mly-slash-command-text": "",
3399
+ children: [/* @__PURE__ */ jsx("span", {
3400
+ "data-mly-slash-command-title": "",
3401
+ children: item.title
3402
+ }), item.description ? /* @__PURE__ */ jsx("span", {
3403
+ "data-mly-slash-command-description": "",
3404
+ children: item.description
3405
+ }) : null]
3406
+ }),
3407
+ isNested ? /* @__PURE__ */ jsx("span", {
3408
+ "data-mly-slash-command-chevron": "",
3409
+ children: /* @__PURE__ */ jsx(ChevronRightIcon, {
3410
+ size: 14,
3411
+ strokeWidth: 2.5
3412
+ })
3413
+ }) : null
3414
+ ] });
3415
+ $[14] = isCustomRow;
3416
+ $[15] = isNested;
3417
+ $[16] = item.description;
3418
+ $[17] = item.icon;
3419
+ $[18] = item.title;
3420
+ $[19] = rendered;
3421
+ $[20] = t4;
3422
+ } else t4 = $[20];
3423
+ let t5;
3424
+ if ($[21] !== rest || $[22] !== t1 || $[23] !== t2 || $[24] !== t3 || $[25] !== t4) {
3425
+ t5 = /* @__PURE__ */ jsx(TooltipTrigger, { render: /* @__PURE__ */ jsx("button", {
3426
+ ...rest,
3427
+ "data-mly-slash-command-item": "",
3428
+ "data-selected": t1,
3429
+ onMouseEnter: t2,
3430
+ onMouseLeave: t3,
3431
+ type: "button",
3432
+ children: t4
3433
+ }) });
3434
+ $[21] = rest;
3435
+ $[22] = t1;
3436
+ $[23] = t2;
3437
+ $[24] = t3;
3438
+ $[25] = t4;
3439
+ $[26] = t5;
3440
+ } else t5 = $[26];
3441
+ let t6;
3442
+ if ($[27] !== editor || $[28] !== item) {
3443
+ t6 = typeof item.preview === "function" ? item.preview(editor) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("figure", {
3444
+ "data-mly-slash-command-preview": "",
3445
+ children: /* @__PURE__ */ jsx("img", {
3446
+ alt: item.title,
3447
+ src: item.preview
3448
+ })
3449
+ }), /* @__PURE__ */ jsx("p", {
3450
+ "data-mly-slash-command-preview-description": "",
3451
+ children: item.description
3452
+ })] });
3453
+ $[27] = editor;
3454
+ $[28] = item;
3455
+ $[29] = t6;
3456
+ } else t6 = $[29];
3457
+ let t7;
3458
+ if ($[30] !== t6) {
3459
+ t7 = /* @__PURE__ */ jsx(TooltipPositioner, {
3460
+ side: "right",
3461
+ sideOffset: 8,
3462
+ children: /* @__PURE__ */ jsx(TooltipPopup, {
3463
+ "data-variant": "preview",
3464
+ children: t6
3465
+ })
3466
+ });
3467
+ $[30] = t6;
3468
+ $[31] = t7;
3469
+ } else t7 = $[31];
3470
+ let t8;
3471
+ if ($[32] !== open || $[33] !== t5 || $[34] !== t7) {
3472
+ t8 = /* @__PURE__ */ jsxs(Tooltip$1, {
3473
+ open,
3474
+ children: [t5, t7]
3475
+ });
3476
+ $[32] = open;
3477
+ $[33] = t5;
3478
+ $[34] = t7;
3479
+ $[35] = t8;
3480
+ } else t8 = $[35];
3481
+ return t8;
3482
+ }
3483
+ //#endregion
3484
+ //#region src/extensions/slash-command/slash-command-suggestion-list.tsx
3485
+ const NAVIGATION_KEYS = /* @__PURE__ */ new Set([
3486
+ ARROW_UP,
3487
+ ARROW_DOWN,
3488
+ ENTER,
3489
+ HOME,
3490
+ "End"
3491
+ ]);
3492
+ const SlashCommandSuggestionList = forwardRef((props, ref) => {
3493
+ const { command: selectItem, editor, items: groups } = props;
3494
+ const flattened = groups.flatMap((group) => group.commands);
3495
+ const [selectedIndex, setSelectedIndex] = useState(0);
3496
+ const [hoveredKey, setHoveredKey] = useState(null);
3497
+ const [prevGroups, setPrevGroups] = useState(groups);
3498
+ const { activeRef: activeItemRef, containerRef: scrollContainerRef } = useScrollIntoView([selectedIndex]);
3499
+ if (prevGroups !== groups) {
3500
+ setPrevGroups(groups);
3501
+ setSelectedIndex(0);
3502
+ if (scrollContainerRef.current) scrollContainerRef.current.scrollTop = 0;
3503
+ }
3504
+ const selectCommand = (item) => {
3505
+ selectItem(item);
3506
+ };
3507
+ useImperativeHandle(ref, () => ({ onKeyDown: ({ event }) => {
3508
+ if (!NAVIGATION_KEYS.has(event.key) || !flattened.length) return false;
3509
+ let newIndex = selectedIndex;
3510
+ let shouldSelect = false;
3511
+ switch (event.key) {
3512
+ case HOME:
3513
+ newIndex = 0;
3514
+ break;
3515
+ case "End":
3516
+ newIndex = flattened.length - 1;
3517
+ break;
3518
+ case ARROW_UP:
3519
+ newIndex = (selectedIndex + flattened.length - 1) % flattened.length;
3520
+ break;
3521
+ case ARROW_DOWN:
3522
+ newIndex = (selectedIndex + 1) % flattened.length;
3523
+ break;
3524
+ case ENTER:
3525
+ shouldSelect = true;
3526
+ break;
3527
+ default: return false;
3528
+ }
3529
+ event.preventDefault();
3530
+ if (shouldSelect) {
3531
+ const item = flattened[selectedIndex];
3532
+ if (item) selectCommand(item);
3533
+ return true;
3534
+ }
3535
+ if (newIndex !== selectedIndex) setSelectedIndex(newIndex);
3536
+ return true;
3537
+ } }));
3538
+ if (!groups || groups.length === 0) return null;
3539
+ let itemIndex = -1;
3540
+ return /* @__PURE__ */ jsxs(SuggestionWrapper, {
3541
+ "data-variant": "slash-command",
3542
+ children: [/* @__PURE__ */ jsx("div", {
3543
+ "data-mly-suggestion-body": "",
3544
+ children: /* @__PURE__ */ jsx("div", {
3545
+ "data-axis": "y",
3546
+ "data-mly-scroll-fade": "",
3547
+ "data-mly-suggestion-scroll": "",
3548
+ ref: scrollContainerRef,
3549
+ children: groups.map((group, groupIndex) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
3550
+ "data-first": groupIndex === 0 ? "" : void 0,
3551
+ "data-mly-slash-command-group": "",
3552
+ children: group.title
3553
+ }), /* @__PURE__ */ jsx("div", {
3554
+ "data-mly-suggestion-items": "",
3555
+ children: group.commands.map((item) => {
3556
+ itemIndex += 1;
3557
+ const isSelected = itemIndex === selectedIndex;
3558
+ const itemKey = `${groupIndex}-${itemIndex}`;
3559
+ return /* @__PURE__ */ jsx(SlashCommandItem, {
3560
+ editor,
3561
+ hoveredKey,
3562
+ isSelected,
3563
+ item,
3564
+ itemKey,
3565
+ onClick: () => selectCommand(item),
3566
+ onHover: (isHovered) => setHoveredKey(isHovered ? itemKey : null),
3567
+ ref: isSelected ? activeItemRef : null
3568
+ }, item.title);
3569
+ })
3570
+ })] }, group.title))
3571
+ })
3572
+ }), /* @__PURE__ */ jsx(SuggestionFooter, {})]
3573
+ });
3574
+ });
3575
+ SlashCommandSuggestionList.displayName = "SlashCommandSuggestionList";
3576
+ //#endregion
3577
+ //#region src/extensions/slash-command/slash-command-suggestion.ts
3578
+ async function updatePosition(editor, element, range) {
3579
+ const position = await computePosition({ getBoundingClientRect: () => posToDOMRect(editor.view, range.from, range.to) }, element, {
3580
+ placement: "bottom-start",
3581
+ strategy: "absolute",
3582
+ middleware: [
3583
+ shift(),
3584
+ flip(),
3585
+ offset(8)
3586
+ ]
3587
+ });
3588
+ element.style.width = "max-content";
3589
+ element.style.position = position.strategy;
3590
+ element.style.left = `${position.x}px`;
3591
+ element.style.top = `${position.y}px`;
3592
+ element.style.zIndex = "9999";
3593
+ }
3594
+ function getSlashCommandSuggestions() {
3595
+ return {
3596
+ char: "/",
3597
+ items: ({ editor, query }) => filterSlashCommands({
3598
+ editor,
3599
+ groups: editor.storage.slashCommand?.commands ?? [],
3600
+ query
3601
+ }),
3602
+ command: ({ editor, props, range }) => {
3603
+ props.command({
3604
+ editor,
3605
+ range
3606
+ });
3607
+ },
3608
+ render: () => {
3609
+ let component = null;
3610
+ return {
3611
+ onStart: async (props) => {
3612
+ const { editor, range } = props;
3613
+ const parentElement = editor.view.dom.parentElement;
3614
+ if (!parentElement) return;
3615
+ component = new ReactRenderer(SlashCommandSuggestionList, {
3616
+ editor,
3617
+ props
3618
+ });
3619
+ if (!props.clientRect) return;
3620
+ component.element.style.position = "absolute";
3621
+ component.element.id = SLASH_COMMAND_SUGGESTION_POPOVER_ID;
3622
+ parentElement.append(component.element);
3623
+ await updatePosition(editor, component.element, range);
3624
+ },
3625
+ onUpdate: async (props) => {
3626
+ const { editor, range } = props;
3627
+ if (!component) return;
3628
+ component.updateProps(props);
3629
+ if (!props.clientRect) return;
3630
+ await updatePosition(editor, component.element, range);
3631
+ },
3632
+ onKeyDown(props) {
3633
+ if (!component) return false;
3634
+ if (props.event.key === "Escape") {
3635
+ component.destroy();
3636
+ return true;
3637
+ }
3638
+ return component.ref?.onKeyDown(props) ?? false;
3639
+ },
3640
+ onExit() {
3641
+ if (!component) return;
3642
+ component.element.remove();
3643
+ component.destroy();
3644
+ }
3645
+ };
3646
+ }
3647
+ };
3648
+ }
3649
+ //#endregion
3650
+ //#region src/extensions/slash-command/slash-command.ts
3651
+ const SlashCommandExtension = Extension.create({
3652
+ name: "slashCommand",
3653
+ priority: 101,
3654
+ addOptions() {
3655
+ return {
3656
+ commands: DEFAULT_SLASH_COMMANDS,
3657
+ suggestion: getSlashCommandSuggestions()
3658
+ };
3659
+ },
3660
+ addStorage() {
3661
+ return { commands: this.options.commands };
3662
+ },
3663
+ addProseMirrorPlugins() {
3664
+ return [Suggestion({
3665
+ editor: this.editor,
3666
+ ...this.options.suggestion
3667
+ })];
3668
+ }
3669
+ });
3670
+ //#endregion
3671
+ //#region src/hooks/use-spacer-resize-controller.ts
3672
+ function useSpacerResizeController(options) {
3673
+ const $ = c(8);
3674
+ const { height, onHeightChange: t0, onHeightCommitted: t1 } = options;
3675
+ const onHeightChange = t0 === void 0 ? noop : t0;
3676
+ const onHeightCommitted = t1 === void 0 ? noop : t1;
3677
+ const containerRef = useRef(null);
3678
+ const spacerWrapperRef = useRef(null);
3679
+ const [shouldShowDragHandles, setShouldShowDragHandles] = useState(false);
3680
+ const [isResizing, setIsResizing] = useState(false);
3681
+ const heightRef = useValueAsRef(height);
3682
+ let t2;
3683
+ if ($[0] !== heightRef || $[1] !== onHeightChange || $[2] !== onHeightCommitted) {
3684
+ t2 = (event, initialResizeParams) => {
3685
+ let activeResizeState = initialResizeParams;
3686
+ let nextHeight = heightRef.current;
3687
+ const targetElement = event.currentTarget;
3688
+ capturePointer({
3689
+ element: targetElement,
3690
+ pointerId: event.pointerId
3691
+ });
3692
+ const handlePointerMove = (moveEvent) => {
3693
+ const spacerWrapper = spacerWrapperRef.current;
3694
+ if (!activeResizeState || !spacerWrapper) return;
3695
+ const pointerDeltaY = moveEvent.clientY - activeResizeState.initialClientY;
3696
+ const { handleUsed, initialHeight } = activeResizeState;
3697
+ const delta = handleUsed === "top" ? -pointerDeltaY : pointerDeltaY;
3698
+ nextHeight = clamp(Math.round(initialHeight + delta), [1, MAX_SPACER_HEIGHT]);
3699
+ spacerWrapper.style.height = `${nextHeight}px`;
3700
+ onHeightChange(nextHeight);
3701
+ };
3702
+ const handlePointerUp = (upEvent) => {
3703
+ activeResizeState = null;
3704
+ setIsResizing(false);
3705
+ releasePointer({
3706
+ element: targetElement,
3707
+ pointerId: upEvent.pointerId
3708
+ });
3709
+ onHeightChange(nextHeight);
3710
+ onHeightCommitted(nextHeight);
3711
+ window.removeEventListener("pointermove", handlePointerMove);
3712
+ window.removeEventListener("pointerup", handlePointerUp);
3713
+ };
3714
+ window.addEventListener("pointermove", handlePointerMove);
3715
+ window.addEventListener("pointerup", handlePointerUp);
3716
+ setIsResizing(true);
3717
+ };
3718
+ $[0] = heightRef;
3719
+ $[1] = onHeightChange;
3720
+ $[2] = onHeightCommitted;
3721
+ $[3] = t2;
3722
+ } else t2 = $[3];
3723
+ const handleResize = t2;
3724
+ let t3;
3725
+ if ($[4] !== handleResize || $[5] !== isResizing || $[6] !== shouldShowDragHandles) {
3726
+ t3 = {
3727
+ containerRef,
3728
+ handleResize,
3729
+ isResizing,
3730
+ setShouldShowDragHandles,
3731
+ shouldShowDragHandles,
3732
+ spacerWrapperRef
3733
+ };
3734
+ $[4] = handleResize;
3735
+ $[5] = isResizing;
3736
+ $[6] = shouldShowDragHandles;
3737
+ $[7] = t3;
3738
+ } else t3 = $[7];
3739
+ return t3;
3740
+ }
3741
+ //#endregion
3742
+ //#region src/extensions/spacer/spacer-handle.tsx
3743
+ function SpacerHandle(props) {
3744
+ const $ = c(6);
3745
+ let handle;
3746
+ let rest;
3747
+ if ($[0] !== props) {
3748
+ ({handle, ...rest} = props);
3749
+ $[0] = props;
3750
+ $[1] = handle;
3751
+ $[2] = rest;
3752
+ } else {
3753
+ handle = $[1];
3754
+ rest = $[2];
3755
+ }
3756
+ let t0;
3757
+ if ($[3] !== handle || $[4] !== rest) {
3758
+ t0 = /* @__PURE__ */ jsx("div", {
3759
+ ...rest,
3760
+ "data-mly-spacer-handle": "",
3761
+ "data-side": handle
3762
+ });
3763
+ $[3] = handle;
3764
+ $[4] = rest;
3765
+ $[5] = t0;
3766
+ } else t0 = $[5];
3767
+ return t0;
3768
+ }
3769
+ //#endregion
3770
+ //#region src/extensions/spacer/spacer-view.tsx
3771
+ function SpacerView(props) {
3772
+ const $ = c(33);
3773
+ const { editor, getPos, node, updateAttributes } = props;
3774
+ const { height } = node.attrs;
3775
+ let t0;
3776
+ if ($[0] !== updateAttributes) {
3777
+ t0 = (committed) => updateAttributes({ height: committed });
3778
+ $[0] = updateAttributes;
3779
+ $[1] = t0;
3780
+ } else t0 = $[1];
3781
+ const t1 = t0;
3782
+ let t2;
3783
+ if ($[2] !== height || $[3] !== t1) {
3784
+ t2 = {
3785
+ height,
3786
+ onHeightCommitted: t1
3787
+ };
3788
+ $[2] = height;
3789
+ $[3] = t1;
3790
+ $[4] = t2;
3791
+ } else t2 = $[4];
3792
+ const { containerRef, handleResize, isResizing, setShouldShowDragHandles, shouldShowDragHandles, spacerWrapperRef } = useSpacerResizeController(t2);
3793
+ let t3;
3794
+ if ($[5] !== handleResize || $[6] !== spacerWrapperRef) {
3795
+ t3 = (handle, event) => {
3796
+ const spacerWrapper = spacerWrapperRef.current;
3797
+ if (!spacerWrapper) return;
3798
+ event.preventDefault();
3799
+ handleResize(event, {
3800
+ handleUsed: handle,
3801
+ initialClientY: event.clientY,
3802
+ initialHeight: spacerWrapper.clientHeight
3803
+ });
3804
+ };
3805
+ $[5] = handleResize;
3806
+ $[6] = spacerWrapperRef;
3807
+ $[7] = t3;
3808
+ } else t3 = $[7];
3809
+ const handlePointerDown = t3;
3810
+ let t4;
3811
+ if ($[8] !== editor.commands || $[9] !== getPos) {
3812
+ t4 = () => {
3813
+ const position = getPos();
3814
+ if (typeof position !== "number") return;
3815
+ editor.commands.setNodeSelection(position);
3816
+ };
3817
+ $[8] = editor.commands;
3818
+ $[9] = getPos;
3819
+ $[10] = t4;
3820
+ } else t4 = $[10];
3821
+ const handleSelect = t4;
3822
+ let t5;
3823
+ if ($[11] !== editor.isEditable || $[12] !== setShouldShowDragHandles) {
3824
+ t5 = () => setShouldShowDragHandles(editor.isEditable);
3825
+ $[11] = editor.isEditable;
3826
+ $[12] = setShouldShowDragHandles;
3827
+ $[13] = t5;
3828
+ } else t5 = $[13];
3829
+ let t6;
3830
+ if ($[14] !== setShouldShowDragHandles) {
3831
+ t6 = () => setShouldShowDragHandles(false);
3832
+ $[14] = setShouldShowDragHandles;
3833
+ $[15] = t6;
3834
+ } else t6 = $[15];
3835
+ const t7 = `${height}px`;
3836
+ let t8;
3837
+ if ($[16] !== t7) {
3838
+ t8 = { height: t7 };
3839
+ $[16] = t7;
3840
+ $[17] = t8;
3841
+ } else t8 = $[17];
3842
+ let t9;
3843
+ if ($[18] !== handlePointerDown || $[19] !== isResizing || $[20] !== shouldShowDragHandles) {
3844
+ t9 = shouldShowDragHandles || isResizing ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(SpacerHandle, {
3845
+ handle: "top",
3846
+ onPointerDown: (event_0) => handlePointerDown("top", event_0)
3847
+ }), /* @__PURE__ */ jsx(SpacerHandle, {
3848
+ handle: "bottom",
3849
+ onPointerDown: (event_1) => handlePointerDown("bottom", event_1)
3850
+ })] }) : null;
3851
+ $[18] = handlePointerDown;
3852
+ $[19] = isResizing;
3853
+ $[20] = shouldShowDragHandles;
3854
+ $[21] = t9;
3855
+ } else t9 = $[21];
3856
+ let t10;
3857
+ if ($[22] !== spacerWrapperRef || $[23] !== t8 || $[24] !== t9) {
3858
+ t10 = /* @__PURE__ */ jsx("div", {
3859
+ "data-mly-spacer-wrapper": "",
3860
+ ref: spacerWrapperRef,
3861
+ style: t8,
3862
+ children: t9
3863
+ });
3864
+ $[22] = spacerWrapperRef;
3865
+ $[23] = t8;
3866
+ $[24] = t9;
3867
+ $[25] = t10;
3868
+ } else t10 = $[25];
3869
+ let t11;
3870
+ if ($[26] !== containerRef || $[27] !== editor.isEditable || $[28] !== handleSelect || $[29] !== t10 || $[30] !== t5 || $[31] !== t6) {
3871
+ t11 = /* @__PURE__ */ jsx(NodeViewWrapper, {
3872
+ "data-drag-handle": editor.isEditable,
3873
+ "data-mly-spacer-view": "",
3874
+ draggable: editor.isEditable,
3875
+ onMouseEnter: t5,
3876
+ onMouseLeave: t6,
3877
+ onPointerDown: handleSelect,
3878
+ ref: containerRef,
3879
+ children: t10
3880
+ });
3881
+ $[26] = containerRef;
3882
+ $[27] = editor.isEditable;
3883
+ $[28] = handleSelect;
3884
+ $[29] = t10;
3885
+ $[30] = t5;
3886
+ $[31] = t6;
3887
+ $[32] = t11;
3888
+ } else t11 = $[32];
3889
+ return t11;
3890
+ }
3891
+ const SpacerExtension = Node$1.create({
3892
+ name: MAILY_NODE_TYPES.SPACER,
3893
+ priority: 1e3,
3894
+ group: "block",
3895
+ draggable: true,
3896
+ addOptions() {
3897
+ return { HTMLAttributes: {} };
3898
+ },
3899
+ addAttributes() {
3900
+ return { height: {
3901
+ default: 8,
3902
+ parseHTML: (element) => Number(element.getAttribute("data-height")) || 8,
3903
+ renderHTML: (attributes) => ({ "data-height": attributes.height })
3904
+ } };
3905
+ },
3906
+ addCommands() {
3907
+ return {
3908
+ setSpacer: (attrs) => ({ commands }) => commands.insertContent({
3909
+ type: this.name,
3910
+ attrs
3911
+ }),
3912
+ unsetSpacer: () => ({ commands }) => commands.deleteNode(this.name),
3913
+ updateSpacerAttributes: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
3914
+ };
3915
+ },
3916
+ parseHTML() {
3917
+ return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${this.name}"]` }];
3918
+ },
3919
+ renderHTML({ HTMLAttributes, node }) {
3920
+ const { height } = node.attrs;
3921
+ return ["div", mergeAttributes({ [DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes, {
3922
+ contenteditable: "false",
3923
+ style: `height:${height}px`
3924
+ })];
3925
+ },
3926
+ addNodeView() {
3927
+ return ReactNodeViewRenderer(SpacerView, { attrs: { [DATA_NODE_TYPE_KEY]: this.name } });
3928
+ }
3929
+ });
3930
+ //#endregion
3931
+ //#region src/extensions/span/span.ts
3932
+ const SpanExtension = Mark.create({
3933
+ name: MAILY_MARK_TYPES.SPAN,
3934
+ addAttributes() {
3935
+ return { style: {
3936
+ default: null,
3937
+ parseHTML: (element) => getSpanStyle(element.getAttribute("style")),
3938
+ renderHTML: (attributes) => {
3939
+ if (typeof attributes.style !== "string") return {};
3940
+ return { style: attributes.style };
3941
+ }
3942
+ } };
3943
+ },
3944
+ parseHTML() {
3945
+ return [{
3946
+ tag: "span[style]",
3947
+ getAttrs: (element) => getSpanStyle(element.getAttribute("style")) ? null : false
3948
+ }];
3949
+ },
3950
+ renderHTML({ HTMLAttributes }) {
3951
+ return [
3952
+ "span",
3953
+ mergeAttributes(HTMLAttributes),
3954
+ 0
3955
+ ];
3956
+ }
3957
+ });
3958
+ //#endregion
3959
+ //#region src/extensions/style/style.ts
3960
+ const WRAPPER_TYPES = [
3961
+ MAILY_NODE_TYPES.BODY,
3962
+ MAILY_NODE_TYPES.CONTAINER,
3963
+ MAILY_NODE_TYPES.SECTION
3964
+ ];
3965
+ const STYLE_SUPPORTED_TYPES = [
3966
+ ...WRAPPER_TYPES,
3967
+ MAILY_NODE_TYPES.COLUMNS,
3968
+ MAILY_NODE_TYPES.COLUMN,
3969
+ MAILY_NODE_TYPES.PARAGRAPH,
3970
+ MAILY_NODE_TYPES.HEADING,
3971
+ MAILY_NODE_TYPES.IMAGE,
3972
+ MAILY_NODE_TYPES.INLINE_IMAGE,
3973
+ MAILY_NODE_TYPES.INLINE_SPAN,
3974
+ MAILY_NODE_TYPES.SPACER,
3975
+ MAILY_NODE_TYPES.BUTTON,
3976
+ MAILY_NODE_TYPES.FOOTER,
3977
+ MAILY_NODE_TYPES.BLOCKQUOTE,
3978
+ MAILY_NODE_TYPES.HORIZONTAL_RULE,
3979
+ MAILY_NODE_TYPES.BULLET_LIST,
3980
+ MAILY_NODE_TYPES.ORDERED_LIST,
3981
+ MAILY_NODE_TYPES.LIST_ITEM,
3982
+ MAILY_NODE_TYPES.TABLE,
3983
+ MAILY_NODE_TYPES.TABLE_ROW,
3984
+ MAILY_NODE_TYPES.TABLE_CELL,
3985
+ MAILY_NODE_TYPES.TABLE_HEADER
3986
+ ];
3987
+ const STYLE_SUPPORTED_MARK_TYPES = [
3988
+ MAILY_MARK_TYPES.BOLD,
3989
+ MAILY_MARK_TYPES.ITALIC,
3990
+ MAILY_MARK_TYPES.STRIKE,
3991
+ MAILY_MARK_TYPES.UNDERLINE,
3992
+ MAILY_MARK_TYPES.LINK,
3993
+ MAILY_MARK_TYPES.CODE
3994
+ ];
3995
+ function getStyleAttribute(parseHTML) {
3996
+ return { style: {
3997
+ default: null,
3998
+ parseHTML,
3999
+ renderHTML: (attributes) => typeof attributes.style === "string" ? { style: attributes.style } : {}
4000
+ } };
4001
+ }
4002
+ const StyleExtension = Extension.create({
4003
+ name: MAILY_EXTENSION_TYPES.STYLE,
4004
+ addOptions() {
4005
+ return {
4006
+ fontFamilies: DEFAULT_FONT_FAMILIES,
4007
+ markTypes: STYLE_SUPPORTED_MARK_TYPES,
4008
+ types: STYLE_SUPPORTED_TYPES
4009
+ };
4010
+ },
4011
+ addCommands() {
4012
+ return { updateNodeStyle: (typeOrName, declarations) => ({ commands, editor }) => commands.updateAttributes(typeOrName, { style: setStyleDeclarations(editor.getAttributes(typeOrName).style, declarations) }) };
4013
+ },
4014
+ addGlobalAttributes() {
4015
+ return [
4016
+ {
4017
+ types: this.options.types.filter((type) => !WRAPPER_TYPES.includes(type) && type !== MAILY_NODE_TYPES.COLUMNS && type !== MAILY_NODE_TYPES.COLUMN && type !== MAILY_NODE_TYPES.INLINE_IMAGE),
4018
+ attributes: getStyleAttribute(getElementStyle)
4019
+ },
4020
+ {
4021
+ types: [MAILY_NODE_TYPES.INLINE_IMAGE],
4022
+ attributes: getStyleAttribute(getInlineImageStyle)
4023
+ },
4024
+ {
4025
+ types: [MAILY_NODE_TYPES.COLUMNS],
4026
+ attributes: getStyleAttribute((element) => getColumnsStyle(getElementStyle(element)))
4027
+ },
4028
+ {
4029
+ types: [MAILY_NODE_TYPES.COLUMN],
4030
+ attributes: getStyleAttribute((element) => getColumnStyle(getElementStyle(element)))
4031
+ },
4032
+ {
4033
+ types: this.options.types.filter((type) => WRAPPER_TYPES.includes(type)),
4034
+ attributes: getStyleAttribute(getWrapperStyle)
4035
+ },
4036
+ {
4037
+ types: this.options.markTypes,
4038
+ attributes: getStyleAttribute((element) => getMarkStyle(element.getAttribute("style")))
4039
+ }
4040
+ ];
4041
+ }
4042
+ });
4043
+ //#endregion
4044
+ //#region src/extensions/table/table.ts
4045
+ function getNumericAttribute(name) {
4046
+ return {
4047
+ default: 0,
4048
+ parseHTML: (element) => Number(element.getAttribute(name)) || 0,
4049
+ renderHTML: (attributes) => ({ [name]: attributes[name] })
4050
+ };
4051
+ }
4052
+ const TableExtension = Table.extend({ addAttributes() {
4053
+ return {
4054
+ ...this.parent?.(),
4055
+ border: getNumericAttribute("border"),
4056
+ cellpadding: getNumericAttribute("cellpadding"),
4057
+ cellspacing: getNumericAttribute("cellspacing"),
4058
+ responsive: {
4059
+ default: false,
4060
+ parseHTML: (element) => {
4061
+ if (element.getAttribute("data-mly-responsive") === "stack") return true;
4062
+ return element.querySelectorAll(":scope > tbody > tr > td[data-id=\"__react-email-column\"]").length > 1;
4063
+ },
4064
+ renderHTML: (attributes) => attributes.responsive ? { "data-mly-responsive": "stack" } : {}
4065
+ }
4066
+ };
4067
+ } }).configure({
4068
+ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.TABLE },
4069
+ resizable: false,
4070
+ View: null
4071
+ });
4072
+ //#endregion
4073
+ //#region src/extensions/table/table-cell.ts
4074
+ const TableCellExtension = TableCell.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.TABLE_CELL } });
4075
+ //#endregion
4076
+ //#region src/extensions/table/table-header.ts
4077
+ const TableHeaderExtension = TableHeader.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.TABLE_HEADER } });
4078
+ //#endregion
4079
+ //#region src/extensions/table/table-row.ts
4080
+ const TableRowExtension = TableRow.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.TABLE_ROW } });
4081
+ //#endregion
4082
+ //#region src/utils/extensions.ts
4083
+ function mergeExtensions(defaults, overrides) {
4084
+ const overrideNames = new Set(overrides.map((extension) => extension.name));
4085
+ return [...defaults.filter((extension) => !overrideNames.has(extension.name)), ...overrides];
4086
+ }
4087
+ //#endregion
4088
+ //#region src/utils/html.ts
4089
+ const LITERAL_SELECTORS = [
4090
+ "code",
4091
+ "pre",
4092
+ "script",
4093
+ "style",
4094
+ `[${DATA_NODE_TYPE_KEY}="${MAILY_NODE_TYPES.VARIABLE}"]`
4095
+ ].join(",");
4096
+ const PHRASING_TAGS = /* @__PURE__ */ new Set([
4097
+ "A",
4098
+ "ABBR",
4099
+ "B",
4100
+ "BR",
4101
+ "CITE",
4102
+ "CODE",
4103
+ "EM",
4104
+ "FONT",
4105
+ "I",
4106
+ "IMG",
4107
+ "KBD",
4108
+ "MARK",
4109
+ "Q",
4110
+ "S",
4111
+ "SMALL",
4112
+ "SPAN",
4113
+ "STRIKE",
4114
+ "STRONG",
4115
+ "SUB",
4116
+ "SUP",
4117
+ "U"
4118
+ ]);
4119
+ const HIDDEN_SELECTORS = ["[data-skip-in-text=\"true\"]", ".preheader"].join(",");
4120
+ const INHERITED_PROPERTIES = /* @__PURE__ */ new Set([
4121
+ "color",
4122
+ "direction",
4123
+ "fontFamily",
4124
+ "fontSize",
4125
+ "fontStyle",
4126
+ "fontVariant",
4127
+ "fontWeight",
4128
+ "letterSpacing",
4129
+ "lineHeight",
4130
+ "listStyle",
4131
+ "listStyleType",
4132
+ "textAlign",
4133
+ "textIndent",
4134
+ "textTransform",
4135
+ "whiteSpace",
4136
+ "wordSpacing"
4137
+ ]);
4138
+ function getRules(document) {
4139
+ const rules = [];
4140
+ for (const source of document.querySelectorAll("style")) {
4141
+ const sheet = window.document.createElement("style");
4142
+ sheet.textContent = source.textContent;
4143
+ window.document.head.append(sheet);
4144
+ for (const rule of Array.from(sheet.sheet?.cssRules ?? [])) if (rule instanceof CSSStyleRule) rules.push(rule);
4145
+ sheet.remove();
4146
+ }
4147
+ return rules;
4148
+ }
4149
+ function setRuleStyles(document) {
4150
+ const declared = /* @__PURE__ */ new Map();
4151
+ for (const rule of getRules(document)) {
4152
+ const style = parseInlineStyles(rule.style.cssText);
4153
+ for (const element of document.querySelectorAll(rule.selectorText)) declared.set(element, {
4154
+ ...declared.get(element),
4155
+ ...style
4156
+ });
4157
+ }
4158
+ const authored = /* @__PURE__ */ new Map();
4159
+ for (const [element] of declared) authored.set(element, parseInlineStyles(element.getAttribute("style") ?? ""));
4160
+ for (const [element, style] of declared) for (const [property, value] of Object.entries(style)) {
4161
+ if (!INHERITED_PROPERTIES.has(property)) continue;
4162
+ for (let ancestor = element.parentElement; ancestor && ancestor !== document.body; ancestor = ancestor.parentElement) {
4163
+ const above = authored.get(ancestor)?.[property] ?? declared.get(ancestor)?.[property];
4164
+ if (above === void 0) continue;
4165
+ if (above === value) delete style[property];
4166
+ break;
4167
+ }
4168
+ }
4169
+ for (const [element, style] of declared) {
4170
+ const merged = stringifyInlineStyles(mergeInlineStyles(style, authored.get(element) ?? {}));
4171
+ if (merged) element.setAttribute("style", merged);
4172
+ }
4173
+ }
4174
+ function removeHidden(document) {
4175
+ for (const element of document.querySelectorAll(HIDDEN_SELECTORS)) element.remove();
4176
+ for (const element of document.querySelectorAll("[style]")) if (element.style.display === "none") element.remove();
4177
+ }
4178
+ function isPhrasing(node) {
4179
+ return node.nodeType === Node.TEXT_NODE || PHRASING_TAGS.has(node.nodeName);
4180
+ }
4181
+ function setCellParagraphs(document) {
4182
+ for (const parent of document.querySelectorAll("td, th")) {
4183
+ const runs = [[]];
4184
+ for (const child of parent.childNodes) if (isPhrasing(child)) runs.at(-1).push(child);
4185
+ else runs.push([]);
4186
+ for (const run of runs) {
4187
+ if (!run.some((node) => node.textContent?.trim())) continue;
4188
+ const paragraph = document.createElement("p");
4189
+ paragraph.setAttribute("style", "margin:0");
4190
+ run[0].before(paragraph);
4191
+ paragraph.append(...run);
4192
+ }
4193
+ }
4194
+ }
4195
+ function getSoleImage(anchor) {
4196
+ const images = anchor.querySelectorAll("img");
4197
+ return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
4198
+ }
4199
+ function getSpacingAsMargin(style) {
4200
+ const moved = {};
4201
+ for (const [property, value] of Object.entries(style)) {
4202
+ const key = property.startsWith("padding") ? property.replace("padding", "margin") : property;
4203
+ moved[key] = value;
4204
+ }
4205
+ return moved;
4206
+ }
4207
+ function setLinkedImages(document) {
4208
+ for (const anchor of document.querySelectorAll("a[href]")) {
4209
+ const image = getSoleImage(anchor);
4210
+ if (!image) continue;
4211
+ const anchorStyle = anchor.getAttribute("style");
4212
+ if (anchorStyle) {
4213
+ image.setAttribute("style", stringifyInlineStyles(mergeInlineStyles(getSpacingAsMargin(parseInlineStyles(anchorStyle)), parseInlineStyles(image.getAttribute("style") ?? ""))));
4214
+ anchor.removeAttribute("style");
4215
+ }
4216
+ image.setAttribute("data-external-link", anchor.getAttribute("href") ?? "");
4217
+ anchor.removeAttribute("href");
4218
+ }
4219
+ }
4220
+ function getBodyWrapper(document) {
4221
+ for (const table of document.body.querySelectorAll("table")) if (!(table.style.maxWidth || !isBodyTable(table)) && getSingleCell(table)) return table;
4222
+ return null;
4223
+ }
4224
+ /**
4225
+ * Every HTML document has exactly one `<body>` and it is the document, so its
4226
+ * style has to reach the body node however the source wrote it. React Email
4227
+ * splits that style in two — background on `<body>`, the rest on an inner cell,
4228
+ * because Yahoo and AOL drop body styles — so the wrapper it writes is merged
4229
+ * in and unwrapped rather than surviving as a stray table.
4230
+ */
4231
+ function getBodyStyle(document) {
4232
+ const authored = parseInlineStyles(document.body.getAttribute("style") ?? "");
4233
+ const wrapper = getBodyWrapper(document);
4234
+ const cell = wrapper ? getSingleCell(wrapper) : null;
4235
+ if (!(wrapper && cell)) return stringifyInlineStyles(authored) || null;
4236
+ const merged = mergeInlineStyles(authored, parseInlineStyles(getWrapperStyle(wrapper) ?? ""));
4237
+ wrapper.replaceWith(...Array.from(cell.childNodes));
4238
+ return stringifyInlineStyles(merged) || null;
4239
+ }
4240
+ function getVariableElement(document, variable) {
4241
+ const element = document.createElement("span");
4242
+ element.setAttribute(DATA_NODE_TYPE_KEY, MAILY_NODE_TYPES.VARIABLE);
4243
+ element.setAttribute("data-id", variable.id);
4244
+ element.setAttribute("data-required", String(variable.required));
4245
+ element.setAttribute("data-is-default-editable", String(variable.isDefaultEditable));
4246
+ if (variable.fallback) element.setAttribute("data-fallback", variable.fallback);
4247
+ if (variable.label) element.setAttribute("data-label", variable.label);
4248
+ if (variable.style) element.setAttribute("style", variable.style);
4249
+ return element;
4250
+ }
4251
+ function setVariables(document) {
4252
+ const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
4253
+ const texts = [];
4254
+ while (walker.nextNode()) {
4255
+ const text = walker.currentNode;
4256
+ if (hasVariableInText(text.data) && !text.parentElement?.closest(LITERAL_SELECTORS)) texts.push(text);
4257
+ }
4258
+ for (const text of texts) text.replaceWith(...getVariableSegments(text.data).map((segment) => {
4259
+ return segment.isReference ? getVariableElement(document, deserializeVariableFromText(segment.text)) : segment.text;
4260
+ }));
4261
+ }
4262
+ function getNormalizedHtml(html) {
4263
+ const parsed = new DOMParser().parseFromString(html, "text/html");
4264
+ if (!parsed.body) return html;
4265
+ setRuleStyles(parsed);
4266
+ removeHidden(parsed);
4267
+ setLinkedImages(parsed);
4268
+ setVariables(parsed);
4269
+ setCellParagraphs(parsed);
4270
+ const style = getBodyStyle(parsed);
4271
+ if (!style) return parsed.body.innerHTML;
4272
+ const wrapper = parsed.createElement("div");
4273
+ wrapper.setAttribute(DATA_NODE_TYPE_KEY, MAILY_NODE_TYPES.BODY);
4274
+ wrapper.setAttribute("style", style);
4275
+ wrapper.append(...Array.from(parsed.body.childNodes));
4276
+ return wrapper.outerHTML;
4277
+ }
4278
+ //#endregion
4279
+ //#region src/utils/paste.ts
4280
+ function isPlainPaste(view) {
4281
+ const { input } = view;
4282
+ return Boolean(input?.shiftKey) || Boolean(view.state.selection.$from.parent.type.spec.code);
4283
+ }
4284
+ function isHtmlSource(text) {
4285
+ return text.startsWith("<") && text.endsWith(">");
4286
+ }
4287
+ function pasteHtmlSource(options) {
4288
+ const { event, view } = options;
4289
+ const text = event.clipboardData?.getData("text/plain")?.trim() ?? "";
4290
+ if (event.clipboardData?.getData("text/html") || isPlainPaste(view) || !isHtmlSource(text)) return false;
4291
+ const element = document.createElement("div");
4292
+ element.innerHTML = getNormalizedHtml(text);
4293
+ const parsed = DOMParser$1.fromSchema(view.state.schema).parse(element);
4294
+ const container = parsed.firstChild?.firstChild;
4295
+ if (!container?.content.size) return false;
4296
+ const wasEmpty = isNodeEmpty(view.state.doc);
4297
+ const from = view.state.selection.from;
4298
+ view.dispatch(view.state.tr.insertText(text).setMeta("paste", true));
4299
+ const converted = closeHistory(view.state.tr);
4300
+ const to = view.state.selection.from;
4301
+ if (wasEmpty) converted.replaceWith(0, view.state.doc.content.size, parsed.content);
4302
+ else converted.replaceRange(from, to, Slice.maxOpen(container.content));
4303
+ view.dispatch(converted.setMeta("paste", true));
4304
+ return true;
4305
+ }
4306
+ //#endregion
4307
+ //#region src/hooks/use-maily-editor.ts
4308
+ const DEFAULT_EXTENSIONS = [
4309
+ Document$1,
4310
+ BodyExtension,
4311
+ ContainerExtension,
4312
+ SectionExtension,
4313
+ RepeatExtension,
4314
+ ColumnsExtension,
4315
+ ColumnExtension,
4316
+ ParagraphExtension,
4317
+ Heading.configure({
4318
+ levels: [
4319
+ 1,
4320
+ 2,
4321
+ 3
4322
+ ],
4323
+ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.HEADING }
4324
+ }),
4325
+ Text,
4326
+ PlaceholderExtension,
4327
+ HardBreak,
4328
+ BoldExtension,
4329
+ Italic,
4330
+ Strike,
4331
+ Underline,
4332
+ Link.configure({
4333
+ openOnClick: false,
4334
+ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_MARK_TYPES.LINK }
4335
+ }),
4336
+ Code.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_MARK_TYPES.CODE } }),
4337
+ TextStyleKit.configure({
4338
+ fontFamily: false,
4339
+ fontSize: false,
4340
+ lineHeight: false,
4341
+ backgroundColor: false,
4342
+ textStyle: false
4343
+ }),
4344
+ TextStyle.extend({ parseHTML() {
4345
+ return [{
4346
+ tag: "span[style]",
4347
+ consuming: false,
4348
+ getAttrs: (element) => element.style.color ? {} : false
4349
+ }];
4350
+ } }),
4351
+ Highlight.configure({ multicolor: true }),
4352
+ SpanExtension,
4353
+ InlineSpanExtension,
4354
+ HorizontalRuleExtension,
4355
+ ImageExtension,
4356
+ ImageUploadExtension,
4357
+ InlineImageExtension,
4358
+ SpacerExtension,
4359
+ ButtonExtension,
4360
+ FooterExtension,
4361
+ BlockquoteExtension,
4362
+ HtmlCodeBlockExtension,
4363
+ BulletList.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.BULLET_LIST } }),
4364
+ ListItem.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.LIST_ITEM } }),
4365
+ OrderedList.configure({ HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.ORDERED_LIST } }),
4366
+ TableExtension,
4367
+ TableRowExtension,
4368
+ TableCellExtension,
4369
+ TableHeaderExtension,
4370
+ StyleExtension,
4371
+ VisibilityExtension,
4372
+ VariableExtension,
4373
+ SlashCommandExtension,
4374
+ Typography,
4375
+ UndoRedo,
4376
+ Dropcursor.configure({
4377
+ color: "#d1d5dc",
4378
+ width: 2
4379
+ }),
4380
+ Gapcursor,
4381
+ Selection$1,
4382
+ Focus,
4383
+ UniqueID.configure({
4384
+ types: [
4385
+ MAILY_NODE_TYPES.HEADING,
4386
+ MAILY_NODE_TYPES.PARAGRAPH,
4387
+ MAILY_NODE_TYPES.SECTION,
4388
+ MAILY_NODE_TYPES.REPEAT,
4389
+ MAILY_NODE_TYPES.COLUMNS,
4390
+ MAILY_NODE_TYPES.COLUMN,
4391
+ MAILY_NODE_TYPES.BULLET_LIST,
4392
+ MAILY_NODE_TYPES.ORDERED_LIST,
4393
+ MAILY_NODE_TYPES.LIST_ITEM,
4394
+ MAILY_NODE_TYPES.HORIZONTAL_RULE,
4395
+ MAILY_NODE_TYPES.BLOCKQUOTE
4396
+ ],
4397
+ filterTransaction: (tr) => !isRemoteChange(tr)
4398
+ })
4399
+ ];
4400
+ function useMailyEditor(options, dependencies) {
4401
+ const $ = c(24);
4402
+ let content;
4403
+ let editorProps;
4404
+ let rest;
4405
+ let userExtensions;
4406
+ if ($[0] !== options) {
4407
+ ({content, editorProps, extensions: userExtensions, ...rest} = options);
4408
+ $[0] = options;
4409
+ $[1] = content;
4410
+ $[2] = editorProps;
4411
+ $[3] = rest;
4412
+ $[4] = userExtensions;
4413
+ } else {
4414
+ content = $[1];
4415
+ editorProps = $[2];
4416
+ rest = $[3];
4417
+ userExtensions = $[4];
4418
+ }
4419
+ let t0;
4420
+ if ($[5] !== userExtensions) {
4421
+ const merged = userExtensions ? mergeExtensions(DEFAULT_EXTENSIONS, userExtensions) : DEFAULT_EXTENSIONS;
4422
+ t0 = merged.some(_temp) ? merged.filter(_temp2) : merged;
4423
+ $[5] = userExtensions;
4424
+ $[6] = t0;
4425
+ } else t0 = $[6];
4426
+ const extensions = t0;
4427
+ const t1 = typeof content !== "string";
4428
+ let t2;
4429
+ if ($[7] !== content) {
4430
+ t2 = typeof content === "string" ? getNormalizedHtml(content) : content;
4431
+ $[7] = content;
4432
+ $[8] = t2;
4433
+ } else t2 = $[8];
4434
+ let t3;
4435
+ let t4;
4436
+ let t5;
4437
+ if ($[9] !== editorProps) {
4438
+ t3 = (state) => ({
4439
+ role: "textbox",
4440
+ spellcheck: "false",
4441
+ ...typeof editorProps?.attributes === "function" ? editorProps.attributes(state) : editorProps?.attributes
4442
+ });
4443
+ t4 = (view, event, slice) => pasteHtmlSource({
4444
+ event,
4445
+ view
4446
+ }) || (editorProps?.handlePaste?.(view, event, slice) ?? false);
4447
+ t5 = (html, view_0) => {
4448
+ const normalized = getNormalizedHtml(html);
4449
+ return editorProps?.transformPastedHTML?.(normalized, view_0) ?? normalized;
4450
+ };
4451
+ $[9] = editorProps;
4452
+ $[10] = t3;
4453
+ $[11] = t4;
4454
+ $[12] = t5;
4455
+ } else {
4456
+ t3 = $[10];
4457
+ t4 = $[11];
4458
+ t5 = $[12];
4459
+ }
4460
+ let t6;
4461
+ if ($[13] !== editorProps || $[14] !== t3 || $[15] !== t4 || $[16] !== t5) {
4462
+ t6 = {
4463
+ ...editorProps,
4464
+ attributes: t3,
4465
+ handlePaste: t4,
4466
+ transformPastedHTML: t5
4467
+ };
4468
+ $[13] = editorProps;
4469
+ $[14] = t3;
4470
+ $[15] = t4;
4471
+ $[16] = t5;
4472
+ $[17] = t6;
4473
+ } else t6 = $[17];
4474
+ let t7;
4475
+ if ($[18] !== extensions || $[19] !== rest || $[20] !== t1 || $[21] !== t2 || $[22] !== t6) {
4476
+ t7 = {
4477
+ enableContentCheck: t1,
4478
+ onContentError: _temp3,
4479
+ ...rest,
4480
+ content: t2,
4481
+ editorProps: t6,
4482
+ extensions
4483
+ };
4484
+ $[18] = extensions;
4485
+ $[19] = rest;
4486
+ $[20] = t1;
4487
+ $[21] = t2;
4488
+ $[22] = t6;
4489
+ $[23] = t7;
4490
+ } else t7 = $[23];
4491
+ return useEditor(t7, dependencies);
4492
+ }
4493
+ function _temp3(t0) {
4494
+ const { error } = t0;
4495
+ console.error(error);
4496
+ }
4497
+ function _temp2(extension) {
4498
+ return extension.name !== UndoRedo.name;
4499
+ }
4500
+ function _temp(extension_0) {
4501
+ return extension_0.name === "collaboration";
4502
+ }
4503
+ //#endregion
4504
+ export { Tooltip$1 as $, ProtectVariableTrigger as A, MIN_SPACER_HEIGHT as B, ContainerExtension as C, BodyExtension as D, setStyleDeclarations as E, addColumn as F, VARIABLE_SUGGESTION_POPOVER_ID as G, SPACING_PRESETS as H, getColumnWidths as I, getMergedNodeTheme as J, filterVariableSuggestions as K, removeColumn as L, VisibilityExtension as M, ColumnsExtension as N, BlockquoteExtension as O, ColumnExtension as P, getThemeCss as Q, updateColumnWidth as R, FooterExtension as S, BoldExtension as T, VariableExtension as U, SPACER_SPACING as V, getVariableSuggestions as W, getNodeTheme as X, getNodeStyleState as Y, getShellNodes as Z, ALLOWED_IMAGE_MIME_TYPES as _, STYLE_SUPPORTED_TYPES as a, FLOATING_ELEMENT_HEIGHT as at, HtmlCodeBlockExtension as b, SpacerExtension as c, clearInitialNodeSelection as ct, SectionExtension as d, useOnSelectionUpdate as dt, TooltipArrow as et, InlineSpanExtension as f, useFloatingStore as ft, VisuallyHidden as g, ImageState as h, useValueAsRef as ht, mergeExtensions as i, TooltipTrigger as it, VISIBILITY_SUPPORTED_TYPES as j, DEFAULT_REPEAT_EACH as k, SlashCommandExtension as l, FLOATING_ELEMENT_IDS as lt, ImageExtension as m, ArrowIcon as mt, useMailyEditor as n, TooltipPositioner as nt, StyleExtension as o, FLOATING_ELEMENT_PADDING as ot, InlineImageExtension as p, useEditorInstance as pt, Document$1 as q, getNormalizedHtml as r, TooltipProvider as rt, SpanExtension as s, FloatingElement as st, DEFAULT_EXTENSIONS as t, TooltipPopup as tt, DEFAULT_SLASH_COMMANDS as u, FLOATING_ELEMENT_ORDER as ut, IMAGE_UPLOAD_STATUSES as v, ButtonExtension as w, HorizontalRuleExtension as x, ImageUploadExtension as y, MAX_SPACER_HEIGHT as z };