@react-email/editor 0.0.0-experimental.3 → 0.0.0-experimental.30

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 (63) hide show
  1. package/dist/columns-BXN-NNd4.cjs +450 -0
  2. package/dist/columns-Cos2lqfu.mjs +329 -0
  3. package/dist/columns-Cos2lqfu.mjs.map +1 -0
  4. package/dist/core/index.cjs +8 -0
  5. package/dist/core/index.d.cts +2 -0
  6. package/dist/core/index.d.mts +2 -0
  7. package/dist/core/index.mjs +4 -0
  8. package/dist/core-DVox_fis.cjs +2159 -0
  9. package/dist/core-mUMTkab3.mjs +1914 -0
  10. package/dist/core-mUMTkab3.mjs.map +1 -0
  11. package/dist/extensions/index.cjs +48 -0
  12. package/dist/extensions/index.d.cts +395 -0
  13. package/dist/extensions/index.d.cts.map +1 -0
  14. package/dist/extensions/index.d.mts +395 -0
  15. package/dist/extensions/index.d.mts.map +1 -0
  16. package/dist/extensions/index.mjs +5 -0
  17. package/dist/global-content-BRvA4PRG.cjs +89 -0
  18. package/dist/global-content-kdUzYcsA.mjs +78 -0
  19. package/dist/global-content-kdUzYcsA.mjs.map +1 -0
  20. package/dist/index-jGyVEd5q.d.cts +131 -0
  21. package/dist/index-jGyVEd5q.d.cts.map +1 -0
  22. package/dist/index-ozCcANmD.d.mts +131 -0
  23. package/dist/index-ozCcANmD.d.mts.map +1 -0
  24. package/dist/plugins/index.cjs +747 -0
  25. package/dist/plugins/index.d.cts +79 -0
  26. package/dist/plugins/index.d.cts.map +1 -0
  27. package/dist/plugins/index.d.mts +79 -0
  28. package/dist/plugins/index.d.mts.map +1 -0
  29. package/dist/plugins/index.mjs +742 -0
  30. package/dist/plugins/index.mjs.map +1 -0
  31. package/dist/set-text-alignment-BO24ieeE.mjs +19 -0
  32. package/dist/set-text-alignment-BO24ieeE.mjs.map +1 -0
  33. package/dist/set-text-alignment-CbECklB4.cjs +24 -0
  34. package/dist/styles-C-cCyJCn.cjs +211 -0
  35. package/dist/styles-DLviD0JK.mjs +194 -0
  36. package/dist/styles-DLviD0JK.mjs.map +1 -0
  37. package/dist/ui/bubble-menu/bubble-menu.css +146 -0
  38. package/dist/ui/button-bubble-menu/button-bubble-menu.css +29 -0
  39. package/dist/ui/image-bubble-menu/image-bubble-menu.css +29 -0
  40. package/dist/ui/index.cjs +1646 -0
  41. package/dist/ui/index.d.cts +668 -0
  42. package/dist/ui/index.d.cts.map +1 -0
  43. package/dist/ui/index.d.mts +668 -0
  44. package/dist/ui/index.d.mts.map +1 -0
  45. package/dist/ui/index.mjs +1584 -0
  46. package/dist/ui/index.mjs.map +1 -0
  47. package/dist/ui/link-bubble-menu/link-bubble-menu.css +66 -0
  48. package/dist/ui/slash-command/slash-command.css +44 -0
  49. package/dist/ui/themes/default.css +769 -0
  50. package/dist/utils/index.cjs +3 -0
  51. package/dist/utils/index.d.cts +7 -0
  52. package/dist/utils/index.d.cts.map +1 -0
  53. package/dist/utils/index.d.mts +7 -0
  54. package/dist/utils/index.d.mts.map +1 -0
  55. package/dist/utils/index.mjs +3 -0
  56. package/package.json +96 -23
  57. package/dist/index.d.mts +0 -273
  58. package/dist/index.d.mts.map +0 -1
  59. package/dist/index.d.ts +0 -273
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.js +0 -1394
  62. package/dist/index.mjs +0 -1346
  63. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,1914 @@
1
+ import { a as ThreeColumns, c as COMMON_HTML_ATTRIBUTES, d as TABLE_CELL_ATTRIBUTES, f as TABLE_HEADER_ATTRIBUTES, h as editorEventBus, l as LAYOUT_ATTRIBUTES, m as EmailNode, n as ColumnsColumn, o as TwoColumns, p as createStandardAttributes, r as FourColumns, u as TABLE_ATTRIBUTES } from "./columns-Cos2lqfu.mjs";
2
+ import { n as inlineCssToJs, r as resolveConflictingStyles } from "./styles-DLviD0JK.mjs";
3
+ import { t as GlobalContent } from "./global-content-kdUzYcsA.mjs";
4
+ import * as ReactEmailComponents from "@react-email/components";
5
+ import { Body, Button, CodeBlock, Column, Head, Heading, Hr, Html, Link, Preview, Row, Section, pretty, render, toPlainText } from "@react-email/components";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { Extension, InputRule, Mark, Node as Node$1, findChildren, mergeAttributes } from "@tiptap/core";
8
+ import { UndoRedo } from "@tiptap/extensions";
9
+ import { NodeViewContent, NodeViewWrapper, ReactNodeViewRenderer, useEditor, useEditorState } from "@tiptap/react";
10
+ import * as React from "react";
11
+ import TipTapStarterKit from "@tiptap/starter-kit";
12
+ import BlockquoteBase from "@tiptap/extension-blockquote";
13
+ import BoldBase from "@tiptap/extension-bold";
14
+ import BulletListBase from "@tiptap/extension-bullet-list";
15
+ import CodeBase from "@tiptap/extension-code";
16
+ import CodeBlock$1 from "@tiptap/extension-code-block";
17
+ import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
18
+ import { Decoration, DecorationSet } from "@tiptap/pm/view";
19
+ import { fromHtml } from "hast-util-from-html";
20
+ import Prism from "prismjs";
21
+ import HorizontalRule from "@tiptap/extension-horizontal-rule";
22
+ import HardBreakBase from "@tiptap/extension-hard-break";
23
+ import { Heading as Heading$1 } from "@tiptap/extension-heading";
24
+ import ItalicBase from "@tiptap/extension-italic";
25
+ import TiptapLink from "@tiptap/extension-link";
26
+ import ListItemBase from "@tiptap/extension-list-item";
27
+ import OrderedListBase from "@tiptap/extension-ordered-list";
28
+ import ParagraphBase from "@tiptap/extension-paragraph";
29
+ import TipTapPlaceholder from "@tiptap/extension-placeholder";
30
+ import StrikeBase from "@tiptap/extension-strike";
31
+ import SuperscriptBase from "@tiptap/extension-superscript";
32
+ import { Text } from "@tiptap/extension-text";
33
+ import UnderlineBase from "@tiptap/extension-underline";
34
+ import { generateJSON } from "@tiptap/html";
35
+
36
+ //#region src/core/is-document-visually-empty.ts
37
+ function isDocumentVisuallyEmpty(doc) {
38
+ let nonGlobalNodeCount = 0;
39
+ let firstNonGlobalNode = null;
40
+ for (let index = 0; index < doc.childCount; index += 1) {
41
+ const node = doc.child(index);
42
+ if (node.type.name === "globalContent") continue;
43
+ nonGlobalNodeCount += 1;
44
+ if (firstNonGlobalNode === null) firstNonGlobalNode = {
45
+ type: node.type,
46
+ textContent: node.textContent,
47
+ childCount: node.content.childCount
48
+ };
49
+ }
50
+ if (nonGlobalNodeCount === 0) return true;
51
+ if (nonGlobalNodeCount !== 1) return false;
52
+ return firstNonGlobalNode?.type.name === "paragraph" && firstNonGlobalNode.textContent.trim().length === 0 && firstNonGlobalNode.childCount === 0;
53
+ }
54
+
55
+ //#endregion
56
+ //#region src/core/serializer/default-base-template.tsx
57
+ function DefaultBaseTemplate({ children, previewText }) {
58
+ return /* @__PURE__ */ jsxs(Html, { children: [
59
+ /* @__PURE__ */ jsxs(Head, { children: [
60
+ /* @__PURE__ */ jsx("meta", {
61
+ content: "width=device-width",
62
+ name: "viewport"
63
+ }),
64
+ /* @__PURE__ */ jsx("meta", {
65
+ content: "IE=edge",
66
+ httpEquiv: "X-UA-Compatible"
67
+ }),
68
+ /* @__PURE__ */ jsx("meta", { name: "x-apple-disable-message-reformatting" }),
69
+ /* @__PURE__ */ jsx("meta", {
70
+ content: "telephone=no,address=no,email=no,date=no,url=no",
71
+ name: "format-detection"
72
+ })
73
+ ] }),
74
+ previewText && previewText !== "" && /* @__PURE__ */ jsx(Preview, { children: previewText }),
75
+ /* @__PURE__ */ jsx(Body, { children: /* @__PURE__ */ jsx(Section, {
76
+ width: "100%",
77
+ align: "center",
78
+ children: /* @__PURE__ */ jsx(Section, {
79
+ style: { width: "100%" },
80
+ children
81
+ })
82
+ }) })
83
+ ] });
84
+ }
85
+
86
+ //#endregion
87
+ //#region src/core/serializer/email-mark.ts
88
+ var EmailMark = class EmailMark extends Mark {
89
+ constructor(config) {
90
+ super(config);
91
+ }
92
+ /**
93
+ * Create a new Mark instance
94
+ * @param config - Mark configuration object or a function that returns a configuration object
95
+ */
96
+ static create(config) {
97
+ return new EmailMark(typeof config === "function" ? config() : config);
98
+ }
99
+ static from(mark, renderToReactEmail) {
100
+ const customMark = EmailMark.create({});
101
+ Object.assign(customMark, { ...mark });
102
+ customMark.config = {
103
+ ...mark.config,
104
+ renderToReactEmail
105
+ };
106
+ return customMark;
107
+ }
108
+ configure(options) {
109
+ return super.configure(options);
110
+ }
111
+ extend(extendedConfig) {
112
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
113
+ return super.extend(resolvedConfig);
114
+ }
115
+ };
116
+
117
+ //#endregion
118
+ //#region src/core/serializer/compose-react-email.tsx
119
+ const NODES_WITH_INCREMENTED_CHILD_DEPTH = new Set(["bulletList", "orderedList"]);
120
+ const composeReactEmail = async ({ editor, preview }) => {
121
+ const data = editor.getJSON();
122
+ const extensions = editor.extensionManager.extensions;
123
+ const serializerPlugin = extensions.map((ext) => ext.options?.serializerPlugin).filter((p) => Boolean(p)).at(-1);
124
+ const typeToExtensionMap = Object.fromEntries(extensions.map((extension) => [extension.name, extension]));
125
+ function parseContent(content, depth = 0) {
126
+ if (!content) return;
127
+ return content.map((node, index) => {
128
+ const style = serializerPlugin?.getNodeStyles(node, depth, editor) ?? {};
129
+ const inlineStyles = inlineCssToJs(node.attrs?.style);
130
+ if (!node.type) return null;
131
+ const emailNode = typeToExtensionMap[node.type];
132
+ if (!emailNode || !(emailNode instanceof EmailNode)) return null;
133
+ const NodeComponent = emailNode.config.renderToReactEmail;
134
+ const childDepth = NODES_WITH_INCREMENTED_CHILD_DEPTH.has(node.type) ? depth + 1 : depth;
135
+ let renderedNode = node.text ? node.text : /* @__PURE__ */ jsx(NodeComponent, {
136
+ node: node.type === "table" && inlineStyles.width && !node.attrs?.width ? {
137
+ ...node,
138
+ attrs: {
139
+ ...node.attrs,
140
+ width: inlineStyles.width
141
+ }
142
+ } : node,
143
+ style,
144
+ extension: emailNode,
145
+ children: parseContent(node.content, childDepth)
146
+ }, index);
147
+ if (node.marks) for (const mark of node.marks) {
148
+ const emailMark = typeToExtensionMap[mark.type];
149
+ if (emailMark instanceof EmailMark) {
150
+ const MarkComponent = emailMark.config.renderToReactEmail;
151
+ renderedNode = /* @__PURE__ */ jsx(MarkComponent, {
152
+ mark,
153
+ node,
154
+ style: serializerPlugin?.getNodeStyles({
155
+ type: mark.type,
156
+ attrs: mark.attrs ?? {}
157
+ }, depth, editor) ?? {},
158
+ extension: emailMark,
159
+ children: renderedNode
160
+ });
161
+ }
162
+ }
163
+ return renderedNode;
164
+ });
165
+ }
166
+ const unformattedHtml = await render(/* @__PURE__ */ jsx(serializerPlugin?.BaseTemplate ?? DefaultBaseTemplate, {
167
+ previewText: preview,
168
+ editor,
169
+ children: parseContent(data.content)
170
+ }));
171
+ const [prettyHtml, text] = await Promise.all([pretty(unformattedHtml), toPlainText(unformattedHtml)]);
172
+ return {
173
+ html: prettyHtml,
174
+ text
175
+ };
176
+ };
177
+
178
+ //#endregion
179
+ //#region src/extensions/alignment-attribute.tsx
180
+ const AlignmentAttribute = Extension.create({
181
+ name: "alignmentAttribute",
182
+ addOptions() {
183
+ return {
184
+ types: [],
185
+ alignments: [
186
+ "left",
187
+ "center",
188
+ "right",
189
+ "justify"
190
+ ]
191
+ };
192
+ },
193
+ addGlobalAttributes() {
194
+ return [{
195
+ types: this.options.types,
196
+ attributes: { alignment: {
197
+ parseHTML: (element) => {
198
+ const explicitAlign = element.getAttribute("align") || element.getAttribute("alignment") || element.style.textAlign;
199
+ if (explicitAlign && this.options.alignments.includes(explicitAlign)) return explicitAlign;
200
+ return null;
201
+ },
202
+ renderHTML: (attributes) => {
203
+ if (attributes.alignment === "left") return {};
204
+ return { alignment: attributes.alignment };
205
+ }
206
+ } }
207
+ }];
208
+ },
209
+ addCommands() {
210
+ return { setAlignment: (alignment) => ({ commands }) => {
211
+ if (!this.options.alignments.includes(alignment)) return false;
212
+ return this.options.types.every((type) => commands.updateAttributes(type, { alignment }));
213
+ } };
214
+ },
215
+ addKeyboardShortcuts() {
216
+ return {
217
+ Enter: () => {
218
+ const { from } = this.editor.state.selection;
219
+ const currentAlignment = this.editor.state.doc.nodeAt(from)?.attrs?.alignment;
220
+ if (currentAlignment) requestAnimationFrame(() => {
221
+ this.editor.commands.setAlignment(currentAlignment);
222
+ });
223
+ return false;
224
+ },
225
+ "Mod-Shift-l": () => this.editor.commands.setAlignment("left"),
226
+ "Mod-Shift-e": () => this.editor.commands.setAlignment("center"),
227
+ "Mod-Shift-r": () => this.editor.commands.setAlignment("right"),
228
+ "Mod-Shift-j": () => this.editor.commands.setAlignment("justify")
229
+ };
230
+ }
231
+ });
232
+
233
+ //#endregion
234
+ //#region src/utils/get-text-alignment.ts
235
+ function getTextAlignment(alignment) {
236
+ switch (alignment) {
237
+ case "left": return { textAlign: "left" };
238
+ case "center": return { textAlign: "center" };
239
+ case "right": return { textAlign: "right" };
240
+ default: return {};
241
+ }
242
+ }
243
+
244
+ //#endregion
245
+ //#region src/extensions/blockquote.tsx
246
+ const Blockquote = EmailNode.from(BlockquoteBase, ({ children, node, style }) => /* @__PURE__ */ jsx("blockquote", {
247
+ className: node.attrs?.class || void 0,
248
+ style: {
249
+ ...style,
250
+ ...inlineCssToJs(node.attrs?.style),
251
+ ...getTextAlignment(node.attrs?.align || node.attrs?.alignment)
252
+ },
253
+ children
254
+ }));
255
+
256
+ //#endregion
257
+ //#region src/extensions/body.tsx
258
+ const Body$1 = EmailNode.create({
259
+ name: "body",
260
+ group: "block",
261
+ content: "block+",
262
+ defining: true,
263
+ isolating: true,
264
+ addAttributes() {
265
+ return { ...createStandardAttributes([...COMMON_HTML_ATTRIBUTES, ...LAYOUT_ATTRIBUTES]) };
266
+ },
267
+ parseHTML() {
268
+ return [{
269
+ tag: "body",
270
+ getAttrs: (node) => {
271
+ if (typeof node === "string") return false;
272
+ const element = node;
273
+ const attrs = {};
274
+ Array.from(element.attributes).forEach((attr) => {
275
+ attrs[attr.name] = attr.value;
276
+ });
277
+ return attrs;
278
+ }
279
+ }];
280
+ },
281
+ renderHTML({ HTMLAttributes }) {
282
+ return [
283
+ "div",
284
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
285
+ 0
286
+ ];
287
+ },
288
+ renderToReactEmail({ children, node, style }) {
289
+ const inlineStyles = inlineCssToJs(node.attrs?.style);
290
+ return /* @__PURE__ */ jsx("div", {
291
+ className: node.attrs?.class || void 0,
292
+ style: {
293
+ ...style,
294
+ ...inlineStyles
295
+ },
296
+ children
297
+ });
298
+ }
299
+ });
300
+
301
+ //#endregion
302
+ //#region src/extensions/bold.tsx
303
+ const BoldWithoutFontWeightInference = BoldBase.extend({ parseHTML() {
304
+ return [
305
+ { tag: "strong" },
306
+ {
307
+ tag: "b",
308
+ getAttrs: (node) => node.style.fontWeight !== "normal" && null
309
+ },
310
+ {
311
+ style: "font-weight=400",
312
+ clearMark: (mark) => mark.type.name === this.name
313
+ }
314
+ ];
315
+ } });
316
+ const Bold = EmailMark.from(BoldWithoutFontWeightInference, ({ children, style }) => /* @__PURE__ */ jsx("strong", {
317
+ style,
318
+ children
319
+ }));
320
+
321
+ //#endregion
322
+ //#region src/extensions/bullet-list.tsx
323
+ const BulletList = EmailNode.from(BulletListBase, ({ children, node, style }) => /* @__PURE__ */ jsx("ul", {
324
+ className: node.attrs?.class || void 0,
325
+ style: {
326
+ ...style,
327
+ ...inlineCssToJs(node.attrs?.style)
328
+ },
329
+ children
330
+ }));
331
+
332
+ //#endregion
333
+ //#region src/extensions/button.tsx
334
+ const Button$1 = EmailNode.create({
335
+ name: "button",
336
+ group: "block",
337
+ content: "inline*",
338
+ defining: true,
339
+ draggable: true,
340
+ marks: "bold",
341
+ addAttributes() {
342
+ return {
343
+ class: { default: "button" },
344
+ href: { default: "#" },
345
+ alignment: { default: "left" }
346
+ };
347
+ },
348
+ parseHTML() {
349
+ return [{
350
+ tag: "a[data-id=\"react-email-button\"]",
351
+ getAttrs: (node) => {
352
+ if (typeof node === "string") return false;
353
+ const element = node;
354
+ const attrs = {};
355
+ Array.from(element.attributes).forEach((attr) => {
356
+ attrs[attr.name] = attr.value;
357
+ });
358
+ return attrs;
359
+ }
360
+ }];
361
+ },
362
+ renderHTML({ HTMLAttributes }) {
363
+ return [
364
+ "div",
365
+ mergeAttributes({ class: `align-${HTMLAttributes?.alignment}` }),
366
+ [
367
+ "a",
368
+ mergeAttributes({
369
+ class: `node-button ${HTMLAttributes?.class}`,
370
+ style: HTMLAttributes?.style,
371
+ "data-id": "react-email-button",
372
+ "data-href": HTMLAttributes?.href
373
+ }),
374
+ 0
375
+ ]
376
+ ];
377
+ },
378
+ addCommands() {
379
+ return {
380
+ updateButton: (attributes) => ({ commands }) => {
381
+ return commands.updateAttributes("button", attributes);
382
+ },
383
+ setButton: () => ({ commands }) => {
384
+ return commands.insertContent({
385
+ type: "button",
386
+ content: [{
387
+ type: "text",
388
+ text: "Button"
389
+ }]
390
+ });
391
+ }
392
+ };
393
+ },
394
+ renderToReactEmail({ children, node, style }) {
395
+ const inlineStyles = inlineCssToJs(node.attrs?.style);
396
+ return /* @__PURE__ */ jsx(Row, { children: /* @__PURE__ */ jsx(Column, {
397
+ align: node.attrs?.align || node.attrs?.alignment,
398
+ children: /* @__PURE__ */ jsx(Button, {
399
+ className: node.attrs?.class || void 0,
400
+ href: node.attrs?.href,
401
+ style: {
402
+ ...style,
403
+ ...inlineStyles
404
+ },
405
+ children
406
+ })
407
+ }) });
408
+ }
409
+ });
410
+
411
+ //#endregion
412
+ //#region src/extensions/class-attribute.tsx
413
+ const ClassAttribute = Extension.create({
414
+ name: "classAttribute",
415
+ addOptions() {
416
+ return {
417
+ types: [],
418
+ class: []
419
+ };
420
+ },
421
+ addGlobalAttributes() {
422
+ return [{
423
+ types: this.options.types,
424
+ attributes: { class: {
425
+ default: "",
426
+ parseHTML: (element) => element.className || "",
427
+ renderHTML: (attributes) => {
428
+ return attributes.class ? { class: attributes.class } : {};
429
+ }
430
+ } }
431
+ }];
432
+ },
433
+ addCommands() {
434
+ return {
435
+ unsetClass: () => ({ commands }) => {
436
+ return this.options.types.every((type) => commands.resetAttributes(type, "class"));
437
+ },
438
+ setClass: (classList) => ({ commands }) => {
439
+ return this.options.types.every((type) => commands.updateAttributes(type, { class: classList }));
440
+ }
441
+ };
442
+ },
443
+ addKeyboardShortcuts() {
444
+ return { Enter: ({ editor }) => {
445
+ requestAnimationFrame(() => {
446
+ editor.commands.resetAttributes("paragraph", "class");
447
+ });
448
+ return false;
449
+ } };
450
+ }
451
+ });
452
+
453
+ //#endregion
454
+ //#region src/extensions/code.tsx
455
+ const Code = EmailMark.from(CodeBase, ({ children, node, style }) => /* @__PURE__ */ jsx("code", {
456
+ style: {
457
+ ...style,
458
+ ...inlineCssToJs(node.attrs?.style)
459
+ },
460
+ children
461
+ }));
462
+
463
+ //#endregion
464
+ //#region src/utils/prism-utils.ts
465
+ const publicURL = "/styles/prism";
466
+ function loadPrismTheme(theme) {
467
+ const link = document.createElement("link");
468
+ link.rel = "stylesheet";
469
+ link.href = `${publicURL}/prism-${theme}.css`;
470
+ link.setAttribute("data-prism-theme", "");
471
+ document.head.appendChild(link);
472
+ }
473
+ function removePrismTheme() {
474
+ const existingTheme = document.querySelectorAll("link[rel=\"stylesheet\"][data-prism-theme]");
475
+ if (existingTheme.length > 0) existingTheme.forEach((cssLinkTag) => {
476
+ cssLinkTag.remove();
477
+ });
478
+ }
479
+ function hasPrismThemeLoaded(theme) {
480
+ return !!document.querySelector(`link[rel="stylesheet"][data-prism-theme][href="${publicURL}/prism-${theme}.css"]`);
481
+ }
482
+
483
+ //#endregion
484
+ //#region src/extensions/prism-plugin.ts
485
+ const PRISM_LANGUAGE_LOADED_META = "prismLanguageLoaded";
486
+ function parseNodes(nodes, className = []) {
487
+ return nodes.flatMap((node) => {
488
+ const classes = [...className, ...node.properties ? node.properties.className : []];
489
+ if (node.children) return parseNodes(node.children, classes);
490
+ return {
491
+ text: node.value ?? "",
492
+ classes
493
+ };
494
+ });
495
+ }
496
+ function getHighlightNodes(html) {
497
+ return fromHtml(html, { fragment: true }).children;
498
+ }
499
+ function registeredLang(aliasOrLanguage) {
500
+ const allSupportLang = Object.keys(Prism.languages).filter((id) => typeof Prism.languages[id] === "object");
501
+ return Boolean(allSupportLang.find((x) => x === aliasOrLanguage));
502
+ }
503
+ function getDecorations({ doc, name, defaultLanguage, defaultTheme, loadingLanguages, onLanguageLoaded }) {
504
+ const decorations = [];
505
+ findChildren(doc, (node) => node.type.name === name).forEach((block) => {
506
+ let from = block.pos + 1;
507
+ const language = block.node.attrs.language || defaultLanguage;
508
+ const theme = block.node.attrs.theme || defaultTheme;
509
+ let html = "";
510
+ try {
511
+ if (!registeredLang(language) && !loadingLanguages.has(language)) {
512
+ loadingLanguages.add(language);
513
+ import(`prismjs/components/prism-${language}`).then(() => {
514
+ loadingLanguages.delete(language);
515
+ onLanguageLoaded(language);
516
+ }).catch(() => {
517
+ loadingLanguages.delete(language);
518
+ });
519
+ }
520
+ if (!hasPrismThemeLoaded(theme)) loadPrismTheme(theme);
521
+ html = Prism.highlight(block.node.textContent, Prism.languages[language], language);
522
+ } catch {
523
+ html = Prism.highlight(block.node.textContent, Prism.languages.javascript, "js");
524
+ }
525
+ parseNodes(getHighlightNodes(html)).forEach((node) => {
526
+ const to = from + node.text.length;
527
+ if (node.classes.length) {
528
+ const decoration = Decoration.inline(from, to, { class: node.classes.join(" ") });
529
+ decorations.push(decoration);
530
+ }
531
+ from = to;
532
+ });
533
+ });
534
+ return DecorationSet.create(doc, decorations);
535
+ }
536
+ function PrismPlugin({ name, defaultLanguage, defaultTheme }) {
537
+ if (!defaultLanguage) throw Error("You must specify the defaultLanguage parameter");
538
+ const loadingLanguages = /* @__PURE__ */ new Set();
539
+ let pluginView = null;
540
+ const onLanguageLoaded = (language) => {
541
+ if (pluginView) pluginView.dispatch(pluginView.state.tr.setMeta(PRISM_LANGUAGE_LOADED_META, language));
542
+ };
543
+ const prismjsPlugin = new Plugin({
544
+ key: new PluginKey("prism"),
545
+ view(view) {
546
+ pluginView = view;
547
+ return { destroy() {
548
+ pluginView = null;
549
+ } };
550
+ },
551
+ state: {
552
+ init: (_, { doc }) => {
553
+ return getDecorations({
554
+ doc,
555
+ name,
556
+ defaultLanguage,
557
+ defaultTheme,
558
+ loadingLanguages,
559
+ onLanguageLoaded
560
+ });
561
+ },
562
+ apply: (transaction, decorationSet, oldState, newState) => {
563
+ const oldNodeName = oldState.selection.$head.parent.type.name;
564
+ const newNodeName = newState.selection.$head.parent.type.name;
565
+ const oldNodes = findChildren(oldState.doc, (node) => node.type.name === name);
566
+ const newNodes = findChildren(newState.doc, (node) => node.type.name === name);
567
+ if (transaction.getMeta(PRISM_LANGUAGE_LOADED_META) || transaction.docChanged && ([oldNodeName, newNodeName].includes(name) || newNodes.length !== oldNodes.length || transaction.steps.some((step) => {
568
+ const rangeStep = step;
569
+ return rangeStep.from !== void 0 && rangeStep.to !== void 0 && oldNodes.some((node) => {
570
+ return node.pos >= rangeStep.from && node.pos + node.node.nodeSize <= rangeStep.to;
571
+ });
572
+ }))) return getDecorations({
573
+ doc: transaction.doc,
574
+ name,
575
+ defaultLanguage,
576
+ defaultTheme,
577
+ loadingLanguages,
578
+ onLanguageLoaded
579
+ });
580
+ return decorationSet.map(transaction.mapping, transaction.doc);
581
+ }
582
+ },
583
+ props: { decorations(state) {
584
+ return prismjsPlugin.getState(state);
585
+ } },
586
+ destroy() {
587
+ pluginView = null;
588
+ removePrismTheme();
589
+ }
590
+ });
591
+ return prismjsPlugin;
592
+ }
593
+
594
+ //#endregion
595
+ //#region src/extensions/code-block.tsx
596
+ const CodeBlockPrism = EmailNode.from(CodeBlock$1.extend({
597
+ addOptions() {
598
+ return {
599
+ languageClassPrefix: "language-",
600
+ exitOnTripleEnter: false,
601
+ exitOnArrowDown: false,
602
+ enableTabIndentation: true,
603
+ tabSize: 2,
604
+ defaultLanguage: "javascript",
605
+ defaultTheme: "default",
606
+ HTMLAttributes: {}
607
+ };
608
+ },
609
+ addAttributes() {
610
+ return {
611
+ ...this.parent?.(),
612
+ language: {
613
+ default: this.options.defaultLanguage,
614
+ parseHTML: (element) => {
615
+ if (!element) return null;
616
+ const { languageClassPrefix } = this.options;
617
+ if (!languageClassPrefix) return null;
618
+ const language = [...element.firstElementChild?.classList || []].filter((className) => className.startsWith(languageClassPrefix || "")).map((className) => className.replace(languageClassPrefix, ""))[0];
619
+ if (!language) return null;
620
+ return language;
621
+ },
622
+ rendered: false
623
+ },
624
+ theme: {
625
+ default: this.options.defaultTheme,
626
+ rendered: false
627
+ }
628
+ };
629
+ },
630
+ renderHTML({ node, HTMLAttributes }) {
631
+ return [
632
+ "pre",
633
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { class: node.attrs.language ? `${this.options.languageClassPrefix}${node.attrs.language}` : null }, { "data-theme": node.attrs.theme }),
634
+ [
635
+ "code",
636
+ { class: node.attrs.language ? `${this.options.languageClassPrefix}${node.attrs.language} node-codeTag` : "node-codeTag" },
637
+ 0
638
+ ]
639
+ ];
640
+ },
641
+ addKeyboardShortcuts() {
642
+ return {
643
+ ...this.parent?.(),
644
+ "Mod-a": ({ editor }) => {
645
+ const { state } = editor;
646
+ const { selection } = state;
647
+ const { $from } = selection;
648
+ for (let depth = $from.depth; depth >= 1; depth--) if ($from.node(depth).type.name === this.name) {
649
+ const blockStart = $from.start(depth);
650
+ const blockEnd = $from.end(depth);
651
+ if (selection.from === blockStart && selection.to === blockEnd) return false;
652
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, blockStart, blockEnd));
653
+ editor.view.dispatch(tr);
654
+ return true;
655
+ }
656
+ return false;
657
+ }
658
+ };
659
+ },
660
+ addProseMirrorPlugins() {
661
+ return [...this.parent?.() || [], PrismPlugin({
662
+ name: this.name,
663
+ defaultLanguage: this.options.defaultLanguage,
664
+ defaultTheme: this.options.defaultTheme
665
+ })];
666
+ }
667
+ }), ({ node, style }) => {
668
+ const language = node.attrs?.language ? `${node.attrs.language}` : "javascript";
669
+ const userTheme = ReactEmailComponents[node.attrs?.theme];
670
+ const theme = userTheme ? {
671
+ ...userTheme,
672
+ base: {
673
+ ...userTheme.base,
674
+ borderRadius: "0.125rem",
675
+ padding: "0.75rem 1rem"
676
+ }
677
+ } : { base: {
678
+ color: "#1e293b",
679
+ background: "#f1f5f9",
680
+ lineHeight: "1.5",
681
+ fontFamily: "\"Fira Code\", \"Fira Mono\", Menlo, Consolas, \"DejaVu Sans Mono\", monospace",
682
+ padding: "0.75rem 1rem",
683
+ borderRadius: "0.125rem"
684
+ } };
685
+ return /* @__PURE__ */ jsx(CodeBlock, {
686
+ code: node.content?.[0]?.text ?? "",
687
+ language,
688
+ theme,
689
+ style: {
690
+ width: "auto",
691
+ ...style
692
+ }
693
+ });
694
+ });
695
+
696
+ //#endregion
697
+ //#region src/extensions/div.tsx
698
+ const Div = EmailNode.create({
699
+ name: "div",
700
+ group: "block",
701
+ content: "block+",
702
+ defining: true,
703
+ isolating: true,
704
+ parseHTML() {
705
+ return [{
706
+ tag: "div:not([data-type])",
707
+ getAttrs: (node) => {
708
+ if (typeof node === "string") return false;
709
+ const element = node;
710
+ const attrs = {};
711
+ Array.from(element.attributes).forEach((attr) => {
712
+ attrs[attr.name] = attr.value;
713
+ });
714
+ return attrs;
715
+ }
716
+ }];
717
+ },
718
+ renderHTML({ HTMLAttributes }) {
719
+ return [
720
+ "div",
721
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
722
+ 0
723
+ ];
724
+ },
725
+ addAttributes() {
726
+ return { ...createStandardAttributes([...COMMON_HTML_ATTRIBUTES, ...LAYOUT_ATTRIBUTES]) };
727
+ },
728
+ renderToReactEmail({ children, node, style }) {
729
+ const inlineStyles = inlineCssToJs(node.attrs?.style);
730
+ return /* @__PURE__ */ jsx("div", {
731
+ className: node.attrs?.class || void 0,
732
+ style: {
733
+ ...style,
734
+ ...inlineStyles
735
+ },
736
+ children
737
+ });
738
+ }
739
+ });
740
+
741
+ //#endregion
742
+ //#region src/extensions/divider.tsx
743
+ const Divider = EmailNode.from(HorizontalRule.extend({
744
+ addAttributes() {
745
+ return { class: { default: "divider" } };
746
+ },
747
+ addInputRules() {
748
+ return [new InputRule({
749
+ find: /^(?:---|—-|___\s|\*\*\*\s)$/,
750
+ handler: ({ state, range }) => {
751
+ const attributes = {};
752
+ const { tr } = state;
753
+ const start = range.from;
754
+ const end = range.to;
755
+ tr.insert(start - 1, this.type.create(attributes)).delete(tr.mapping.map(start), tr.mapping.map(end));
756
+ }
757
+ })];
758
+ },
759
+ addNodeView() {
760
+ return ReactNodeViewRenderer((props) => {
761
+ const node = props.node;
762
+ const { class: className, ...rest } = node.attrs;
763
+ return /* @__PURE__ */ jsx(NodeViewWrapper, { children: /* @__PURE__ */ jsx(Hr, {
764
+ ...rest,
765
+ className: "node-hr",
766
+ style: inlineCssToJs(node.attrs.style)
767
+ }) });
768
+ });
769
+ }
770
+ }), ({ node, style }) => {
771
+ return /* @__PURE__ */ jsx(Hr, {
772
+ className: node.attrs?.class || void 0,
773
+ style: {
774
+ ...style,
775
+ ...inlineCssToJs(node.attrs?.style)
776
+ }
777
+ });
778
+ });
779
+
780
+ //#endregion
781
+ //#region src/extensions/hard-break.tsx
782
+ const HardBreak = EmailNode.from(HardBreakBase, () => /* @__PURE__ */ jsx("br", {}));
783
+
784
+ //#endregion
785
+ //#region src/extensions/heading.tsx
786
+ const Heading$2 = EmailNode.from(Heading$1.extend({ addNodeView() {
787
+ return ReactNodeViewRenderer(({ node }) => {
788
+ const level = node.attrs.level ?? 1;
789
+ const { class: className, ...rest } = node.attrs;
790
+ const attrs = {
791
+ ...rest,
792
+ className: `node-h${level} ${className}`,
793
+ style: inlineCssToJs(node.attrs.style)
794
+ };
795
+ return /* @__PURE__ */ jsx(NodeViewWrapper, { children: /* @__PURE__ */ jsx(Heading, {
796
+ as: `h${level}`,
797
+ ...attrs,
798
+ children: /* @__PURE__ */ jsx(NodeViewContent, {})
799
+ }) });
800
+ });
801
+ } }), ({ children, node, style }) => {
802
+ return /* @__PURE__ */ jsx(Heading, {
803
+ as: `h${node.attrs?.level ?? 1}`,
804
+ className: node.attrs?.class || void 0,
805
+ style: {
806
+ ...style,
807
+ ...inlineCssToJs(node.attrs?.style),
808
+ ...getTextAlignment(node.attrs?.align ?? node.attrs?.alignment)
809
+ },
810
+ children
811
+ });
812
+ });
813
+
814
+ //#endregion
815
+ //#region src/extensions/italic.tsx
816
+ const Italic = EmailMark.from(ItalicBase, ({ children, style }) => /* @__PURE__ */ jsx("em", {
817
+ style,
818
+ children
819
+ }));
820
+
821
+ //#endregion
822
+ //#region src/extensions/preserved-style.tsx
823
+ const PreservedStyle = EmailMark.create({
824
+ name: "preservedStyle",
825
+ addAttributes() {
826
+ return { style: {
827
+ default: null,
828
+ parseHTML: (element) => element.getAttribute("style"),
829
+ renderHTML: (attributes) => {
830
+ if (!attributes.style) return {};
831
+ return { style: attributes.style };
832
+ }
833
+ } };
834
+ },
835
+ parseHTML() {
836
+ return [{
837
+ tag: "span[style]",
838
+ getAttrs: (element) => {
839
+ if (typeof element === "string") return false;
840
+ const style = element.getAttribute("style");
841
+ if (style && hasPreservableStyles(style)) return { style };
842
+ return false;
843
+ }
844
+ }];
845
+ },
846
+ renderHTML({ HTMLAttributes }) {
847
+ return [
848
+ "span",
849
+ mergeAttributes(HTMLAttributes),
850
+ 0
851
+ ];
852
+ },
853
+ renderToReactEmail({ children, mark }) {
854
+ return /* @__PURE__ */ jsx("span", {
855
+ style: mark.attrs?.style ? inlineCssToJs(mark.attrs.style) : void 0,
856
+ children
857
+ });
858
+ }
859
+ });
860
+ const LINK_INDICATOR_STYLES = [
861
+ "color",
862
+ "text-decoration",
863
+ "text-decoration-line",
864
+ "text-decoration-color",
865
+ "text-decoration-style"
866
+ ];
867
+ function parseStyleString(styleString) {
868
+ const temp = document.createElement("div");
869
+ temp.style.cssText = styleString;
870
+ return temp.style;
871
+ }
872
+ function hasBackground(style) {
873
+ const bgColor = style.backgroundColor;
874
+ const bg = style.background;
875
+ if (bgColor && bgColor !== "transparent" && bgColor !== "rgba(0, 0, 0, 0)") return true;
876
+ if (bg && bg !== "transparent" && bg !== "none" && bg !== "rgba(0, 0, 0, 0)") return true;
877
+ return false;
878
+ }
879
+ function hasPreservableStyles(styleString) {
880
+ return processStylesForUnlink(styleString) !== null;
881
+ }
882
+ /**
883
+ * Processes styles when unlinking:
884
+ * - Has background (button-like): preserve all styles
885
+ * - No background: strip link-indicator styles (color, text-decoration), keep the rest
886
+ */
887
+ function processStylesForUnlink(styleString) {
888
+ if (!styleString) return null;
889
+ const style = parseStyleString(styleString);
890
+ if (hasBackground(style)) return styleString;
891
+ const filtered = [];
892
+ for (let i = 0; i < style.length; i++) {
893
+ const prop = style[i];
894
+ if (LINK_INDICATOR_STYLES.includes(prop)) continue;
895
+ const value = style.getPropertyValue(prop);
896
+ if (value) filtered.push(`${prop}: ${value}`);
897
+ }
898
+ return filtered.length > 0 ? filtered.join("; ") : null;
899
+ }
900
+
901
+ //#endregion
902
+ //#region src/extensions/link.tsx
903
+ const Link$1 = EmailMark.from(TiptapLink, ({ children, mark, style }) => {
904
+ const linkMarkStyle = mark.attrs?.style ? inlineCssToJs(mark.attrs.style) : {};
905
+ return /* @__PURE__ */ jsx(Link, {
906
+ href: mark.attrs?.href ?? void 0,
907
+ rel: mark.attrs?.rel ?? void 0,
908
+ style: {
909
+ ...style,
910
+ ...linkMarkStyle
911
+ },
912
+ target: mark.attrs?.target ?? void 0,
913
+ ...mark.attrs?.["ses:no-track"] ? { "ses:no-track": mark.attrs["ses:no-track"] } : {},
914
+ children
915
+ });
916
+ }).extend({
917
+ parseHTML() {
918
+ return [{
919
+ tag: "a[target]:not([data-id=\"react-email-button\"])",
920
+ getAttrs: (node) => {
921
+ if (typeof node === "string") return false;
922
+ const element = node;
923
+ const attrs = {};
924
+ Array.from(element.attributes).forEach((attr) => {
925
+ attrs[attr.name] = attr.value;
926
+ });
927
+ return attrs;
928
+ }
929
+ }, {
930
+ tag: "a[href]:not([data-id=\"react-email-button\"])",
931
+ getAttrs: (node) => {
932
+ if (typeof node === "string") return false;
933
+ const element = node;
934
+ const attrs = {};
935
+ Array.from(element.attributes).forEach((attr) => {
936
+ attrs[attr.name] = attr.value;
937
+ });
938
+ return attrs;
939
+ }
940
+ }];
941
+ },
942
+ addAttributes() {
943
+ return {
944
+ ...this.parent?.(),
945
+ "ses:no-track": {
946
+ default: null,
947
+ parseHTML: (element) => element.getAttribute("ses:no-track")
948
+ }
949
+ };
950
+ },
951
+ addCommands() {
952
+ return {
953
+ ...this.parent?.(),
954
+ unsetLink: () => ({ state, chain }) => {
955
+ const { from } = state.selection;
956
+ const linkStyle = state.doc.resolve(from).marks().find((m) => m.type.name === "link")?.attrs?.style ?? null;
957
+ const preservedStyle = processStylesForUnlink(linkStyle);
958
+ const shouldRemoveUnderline = preservedStyle !== linkStyle;
959
+ if (preservedStyle) {
960
+ const cmd = chain().extendMarkRange("link").unsetMark("link").setMark("preservedStyle", { style: preservedStyle });
961
+ return shouldRemoveUnderline ? cmd.unsetMark("underline").run() : cmd.run();
962
+ }
963
+ return chain().extendMarkRange("link").unsetMark("link").unsetMark("underline").run();
964
+ }
965
+ };
966
+ },
967
+ addKeyboardShortcuts() {
968
+ return { "Mod-k": () => {
969
+ editorEventBus.dispatch("bubble-menu:add-link", void 0);
970
+ return this.editor.chain().focus().toggleLink({ href: "" }).run();
971
+ } };
972
+ }
973
+ });
974
+
975
+ //#endregion
976
+ //#region src/extensions/list-item.tsx
977
+ const ListItem = EmailNode.from(ListItemBase, ({ children, node, style }) => /* @__PURE__ */ jsx("li", {
978
+ className: node.attrs?.class || void 0,
979
+ style: {
980
+ ...style,
981
+ ...inlineCssToJs(node.attrs?.style),
982
+ ...getTextAlignment(node.attrs?.align || node.attrs?.alignment)
983
+ },
984
+ children
985
+ }));
986
+
987
+ //#endregion
988
+ //#region src/extensions/max-nesting.ts
989
+ const MaxNesting = Extension.create({
990
+ name: "maxNesting",
991
+ addOptions() {
992
+ return {
993
+ maxDepth: 3,
994
+ nodeTypes: void 0
995
+ };
996
+ },
997
+ addProseMirrorPlugins() {
998
+ const { maxDepth, nodeTypes } = this.options;
999
+ if (typeof maxDepth !== "number" || maxDepth < 1) throw new Error("maxDepth must be a positive number");
1000
+ return [new Plugin({
1001
+ key: new PluginKey("maxNesting"),
1002
+ appendTransaction(transactions, _oldState, newState) {
1003
+ if (!transactions.some((tr$1) => tr$1.docChanged)) return null;
1004
+ const rangesToLift = [];
1005
+ newState.doc.descendants((node, pos) => {
1006
+ let depth = 0;
1007
+ let currentPos = pos;
1008
+ let currentNode = node;
1009
+ while (currentNode && depth <= maxDepth) {
1010
+ if (!nodeTypes || nodeTypes.includes(currentNode.type.name)) depth++;
1011
+ const $pos = newState.doc.resolve(currentPos);
1012
+ if ($pos.depth === 0) break;
1013
+ currentPos = $pos.before($pos.depth);
1014
+ currentNode = newState.doc.nodeAt(currentPos);
1015
+ }
1016
+ if (depth > maxDepth) {
1017
+ const $pos = newState.doc.resolve(pos);
1018
+ if ($pos.depth > 0) {
1019
+ const range = $pos.blockRange();
1020
+ if (range && "canReplace" in newState.schema.nodes.doc && typeof newState.schema.nodes.doc.canReplace === "function" && newState.schema.nodes.doc.canReplace(range.start - 1, range.end + 1, newState.doc.slice(range.start, range.end).content)) rangesToLift.push({
1021
+ range,
1022
+ target: range.start - 1
1023
+ });
1024
+ }
1025
+ }
1026
+ });
1027
+ if (rangesToLift.length === 0) return null;
1028
+ const tr = newState.tr;
1029
+ for (let i = rangesToLift.length - 1; i >= 0; i--) {
1030
+ const { range, target } = rangesToLift[i];
1031
+ tr.lift(range, target);
1032
+ }
1033
+ return tr;
1034
+ },
1035
+ filterTransaction(tr) {
1036
+ if (!tr.docChanged) return true;
1037
+ let wouldCreateDeepNesting = false;
1038
+ const newDoc = tr.doc;
1039
+ newDoc.descendants((node, pos) => {
1040
+ if (wouldCreateDeepNesting) return false;
1041
+ let depth = 0;
1042
+ let currentPos = pos;
1043
+ let currentNode = node;
1044
+ while (currentNode && depth <= maxDepth) {
1045
+ if (!nodeTypes || nodeTypes.includes(currentNode.type.name)) depth++;
1046
+ const $pos = newDoc.resolve(currentPos);
1047
+ if ($pos.depth === 0) break;
1048
+ currentPos = $pos.before($pos.depth);
1049
+ currentNode = newDoc.nodeAt(currentPos);
1050
+ }
1051
+ if (depth > maxDepth) {
1052
+ wouldCreateDeepNesting = true;
1053
+ return false;
1054
+ }
1055
+ });
1056
+ return !wouldCreateDeepNesting;
1057
+ }
1058
+ })];
1059
+ }
1060
+ });
1061
+
1062
+ //#endregion
1063
+ //#region src/extensions/ordered-list.tsx
1064
+ const OrderedList = EmailNode.from(OrderedListBase, ({ children, node, style }) => /* @__PURE__ */ jsx("ol", {
1065
+ className: node.attrs?.class || void 0,
1066
+ start: node.attrs?.start,
1067
+ style: {
1068
+ ...style,
1069
+ ...inlineCssToJs(node.attrs?.style)
1070
+ },
1071
+ children
1072
+ }));
1073
+
1074
+ //#endregion
1075
+ //#region src/extensions/paragraph.tsx
1076
+ const Paragraph = EmailNode.from(ParagraphBase, ({ children, node, style }) => {
1077
+ const isEmpty = !node.content || node.content.length === 0;
1078
+ return /* @__PURE__ */ jsx("p", {
1079
+ className: node.attrs?.class || void 0,
1080
+ style: {
1081
+ ...style,
1082
+ ...inlineCssToJs(node.attrs?.style),
1083
+ ...getTextAlignment(node.attrs?.align || node.attrs?.alignment)
1084
+ },
1085
+ children: isEmpty ? /* @__PURE__ */ jsx("br", {}) : children
1086
+ });
1087
+ });
1088
+
1089
+ //#endregion
1090
+ //#region src/extensions/placeholder.ts
1091
+ const Placeholder = TipTapPlaceholder.configure({
1092
+ placeholder: ({ node }) => {
1093
+ if (node.type.name === "heading") return `Heading ${node.attrs.level}`;
1094
+ return "Press '/' for commands";
1095
+ },
1096
+ includeChildren: true
1097
+ });
1098
+
1099
+ //#endregion
1100
+ //#region src/extensions/preview-text.ts
1101
+ const PreviewText = Node$1.create({
1102
+ name: "previewText",
1103
+ group: "block",
1104
+ selectable: false,
1105
+ draggable: false,
1106
+ atom: true,
1107
+ addOptions() {
1108
+ return { HTMLAttributes: {} };
1109
+ },
1110
+ addStorage() {
1111
+ return { previewText: null };
1112
+ },
1113
+ renderHTML() {
1114
+ return ["div", { style: "display: none" }];
1115
+ },
1116
+ parseHTML() {
1117
+ return [{
1118
+ tag: "div[data-skip-in-text=\"true\"]",
1119
+ getAttrs: (node) => {
1120
+ if (typeof node === "string") return false;
1121
+ const element = node;
1122
+ let directText = "";
1123
+ for (const child of element.childNodes) if (child.nodeType === 3) directText += child.textContent || "";
1124
+ const cleanText = directText.trim();
1125
+ if (cleanText) this.storage.previewText = cleanText;
1126
+ return false;
1127
+ }
1128
+ }, {
1129
+ tag: "span.preheader",
1130
+ getAttrs: (node) => {
1131
+ if (typeof node === "string") return false;
1132
+ const preheaderText = node.textContent?.trim();
1133
+ if (preheaderText) this.storage.previewText = preheaderText;
1134
+ return false;
1135
+ }
1136
+ }];
1137
+ }
1138
+ });
1139
+
1140
+ //#endregion
1141
+ //#region src/extensions/section.tsx
1142
+ const Section$1 = EmailNode.create({
1143
+ name: "section",
1144
+ group: "block",
1145
+ content: "block+",
1146
+ isolating: true,
1147
+ defining: true,
1148
+ parseHTML() {
1149
+ return [{ tag: "section[data-type=\"section\"]" }];
1150
+ },
1151
+ renderHTML({ HTMLAttributes }) {
1152
+ return [
1153
+ "section",
1154
+ mergeAttributes({
1155
+ "data-type": "section",
1156
+ class: "node-section"
1157
+ }, HTMLAttributes),
1158
+ 0
1159
+ ];
1160
+ },
1161
+ addCommands() {
1162
+ return { insertSection: () => ({ commands }) => {
1163
+ return commands.insertContent({
1164
+ type: this.name,
1165
+ content: [{
1166
+ type: "paragraph",
1167
+ content: []
1168
+ }]
1169
+ });
1170
+ } };
1171
+ },
1172
+ renderToReactEmail({ children, node, style }) {
1173
+ const inlineStyles = inlineCssToJs(node.attrs?.style);
1174
+ const textAlign = node.attrs?.align || node.attrs?.alignment;
1175
+ return /* @__PURE__ */ jsx(Section, {
1176
+ className: node.attrs?.class || void 0,
1177
+ align: textAlign,
1178
+ style: {
1179
+ ...style,
1180
+ ...inlineStyles,
1181
+ ...getTextAlignment(textAlign)
1182
+ },
1183
+ children
1184
+ });
1185
+ }
1186
+ });
1187
+
1188
+ //#endregion
1189
+ //#region src/extensions/strike.tsx
1190
+ const Strike = EmailMark.from(StrikeBase, ({ children, style }) => /* @__PURE__ */ jsx("s", {
1191
+ style,
1192
+ children
1193
+ }));
1194
+
1195
+ //#endregion
1196
+ //#region src/extensions/style-attribute.tsx
1197
+ const StyleAttribute = Extension.create({
1198
+ name: "styleAttribute",
1199
+ priority: 101,
1200
+ addOptions() {
1201
+ return {
1202
+ types: [],
1203
+ style: []
1204
+ };
1205
+ },
1206
+ addGlobalAttributes() {
1207
+ return [{
1208
+ types: this.options.types,
1209
+ attributes: { style: {
1210
+ default: "",
1211
+ parseHTML: (element) => element.getAttribute("style") || "",
1212
+ renderHTML: (attributes) => {
1213
+ return { style: attributes.style ?? "" };
1214
+ }
1215
+ } }
1216
+ }];
1217
+ },
1218
+ addCommands() {
1219
+ return {
1220
+ unsetStyle: () => ({ commands }) => {
1221
+ return this.options.types.every((type) => commands.resetAttributes(type, "style"));
1222
+ },
1223
+ setStyle: (style) => ({ commands }) => {
1224
+ return this.options.types.every((type) => commands.updateAttributes(type, { style }));
1225
+ }
1226
+ };
1227
+ },
1228
+ addKeyboardShortcuts() {
1229
+ return { Enter: ({ editor }) => {
1230
+ const { state } = editor.view;
1231
+ const { selection } = state;
1232
+ const { $from } = selection;
1233
+ const textBefore = $from.nodeBefore?.text || "";
1234
+ if (textBefore.includes("{{") || textBefore.includes("{{{")) return false;
1235
+ requestAnimationFrame(() => {
1236
+ editor.commands.resetAttributes("paragraph", "style");
1237
+ });
1238
+ return false;
1239
+ } };
1240
+ }
1241
+ });
1242
+
1243
+ //#endregion
1244
+ //#region src/extensions/sup.tsx
1245
+ const SupBase = SuperscriptBase.extend({
1246
+ name: "sup",
1247
+ addCommands() {
1248
+ return {
1249
+ ...this.parent?.(),
1250
+ setSup: () => ({ commands }) => {
1251
+ return commands.setMark(this.name);
1252
+ },
1253
+ toggleSup: () => ({ commands }) => {
1254
+ return commands.toggleMark(this.name);
1255
+ },
1256
+ unsetSup: () => ({ commands }) => {
1257
+ return commands.unsetMark(this.name);
1258
+ }
1259
+ };
1260
+ }
1261
+ });
1262
+ const Sup = EmailMark.from(SupBase, ({ children, style }) => /* @__PURE__ */ jsx("sup", {
1263
+ style,
1264
+ children
1265
+ }));
1266
+
1267
+ //#endregion
1268
+ //#region src/extensions/table.tsx
1269
+ const Table = EmailNode.create({
1270
+ name: "table",
1271
+ group: "block",
1272
+ content: "tableRow+",
1273
+ isolating: true,
1274
+ tableRole: "table",
1275
+ addAttributes() {
1276
+ return { ...createStandardAttributes([
1277
+ ...TABLE_ATTRIBUTES,
1278
+ ...LAYOUT_ATTRIBUTES,
1279
+ ...COMMON_HTML_ATTRIBUTES
1280
+ ]) };
1281
+ },
1282
+ parseHTML() {
1283
+ return [{
1284
+ tag: "table",
1285
+ getAttrs: (node) => {
1286
+ if (typeof node === "string") return false;
1287
+ const element = node;
1288
+ const attrs = {};
1289
+ Array.from(element.attributes).forEach((attr) => {
1290
+ attrs[attr.name] = attr.value;
1291
+ });
1292
+ return attrs;
1293
+ }
1294
+ }];
1295
+ },
1296
+ renderHTML({ HTMLAttributes }) {
1297
+ return [
1298
+ "table",
1299
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
1300
+ [
1301
+ "tbody",
1302
+ {},
1303
+ 0
1304
+ ]
1305
+ ];
1306
+ },
1307
+ renderToReactEmail({ children, node, style }) {
1308
+ const inlineStyles = inlineCssToJs(node.attrs?.style);
1309
+ const alignment = node.attrs?.align || node.attrs?.alignment;
1310
+ const width = node.attrs?.width;
1311
+ const centeringStyles = alignment === "center" ? {
1312
+ marginLeft: "auto",
1313
+ marginRight: "auto"
1314
+ } : {};
1315
+ return /* @__PURE__ */ jsx(Section, {
1316
+ className: node.attrs?.class || void 0,
1317
+ align: alignment,
1318
+ style: resolveConflictingStyles(style, {
1319
+ ...inlineStyles,
1320
+ ...centeringStyles
1321
+ }),
1322
+ ...width !== void 0 ? { width } : {},
1323
+ children
1324
+ });
1325
+ }
1326
+ });
1327
+ const TableRow = EmailNode.create({
1328
+ name: "tableRow",
1329
+ group: "tableRow",
1330
+ content: "(tableCell | tableHeader)+",
1331
+ addAttributes() {
1332
+ return { ...createStandardAttributes([
1333
+ ...TABLE_CELL_ATTRIBUTES,
1334
+ ...LAYOUT_ATTRIBUTES,
1335
+ ...COMMON_HTML_ATTRIBUTES
1336
+ ]) };
1337
+ },
1338
+ parseHTML() {
1339
+ return [{
1340
+ tag: "tr",
1341
+ getAttrs: (node) => {
1342
+ if (typeof node === "string") return false;
1343
+ const element = node;
1344
+ const attrs = {};
1345
+ Array.from(element.attributes).forEach((attr) => {
1346
+ attrs[attr.name] = attr.value;
1347
+ });
1348
+ return attrs;
1349
+ }
1350
+ }];
1351
+ },
1352
+ renderHTML({ HTMLAttributes }) {
1353
+ return [
1354
+ "tr",
1355
+ HTMLAttributes,
1356
+ 0
1357
+ ];
1358
+ },
1359
+ renderToReactEmail({ children, node, style }) {
1360
+ const inlineStyles = inlineCssToJs(node.attrs?.style);
1361
+ return /* @__PURE__ */ jsx("tr", {
1362
+ className: node.attrs?.class || void 0,
1363
+ style: {
1364
+ ...style,
1365
+ ...inlineStyles
1366
+ },
1367
+ children
1368
+ });
1369
+ }
1370
+ });
1371
+ const TableCell = EmailNode.create({
1372
+ name: "tableCell",
1373
+ group: "tableCell",
1374
+ content: "block+",
1375
+ isolating: true,
1376
+ addAttributes() {
1377
+ return { ...createStandardAttributes([
1378
+ ...TABLE_CELL_ATTRIBUTES,
1379
+ ...LAYOUT_ATTRIBUTES,
1380
+ ...COMMON_HTML_ATTRIBUTES
1381
+ ]) };
1382
+ },
1383
+ parseHTML() {
1384
+ return [{
1385
+ tag: "td",
1386
+ getAttrs: (node) => {
1387
+ if (typeof node === "string") return false;
1388
+ const element = node;
1389
+ const attrs = {};
1390
+ Array.from(element.attributes).forEach((attr) => {
1391
+ attrs[attr.name] = attr.value;
1392
+ });
1393
+ return attrs;
1394
+ }
1395
+ }];
1396
+ },
1397
+ renderHTML({ HTMLAttributes }) {
1398
+ return [
1399
+ "td",
1400
+ HTMLAttributes,
1401
+ 0
1402
+ ];
1403
+ },
1404
+ renderToReactEmail({ children, node, style }) {
1405
+ const inlineStyles = inlineCssToJs(node.attrs?.style);
1406
+ return /* @__PURE__ */ jsx(Column, {
1407
+ className: node.attrs?.class || void 0,
1408
+ align: node.attrs?.align || node.attrs?.alignment,
1409
+ style: {
1410
+ ...style,
1411
+ ...inlineStyles
1412
+ },
1413
+ children
1414
+ });
1415
+ }
1416
+ });
1417
+ const TableHeader = Node$1.create({
1418
+ name: "tableHeader",
1419
+ group: "tableCell",
1420
+ content: "block+",
1421
+ isolating: true,
1422
+ addAttributes() {
1423
+ return { ...createStandardAttributes([
1424
+ ...TABLE_HEADER_ATTRIBUTES,
1425
+ ...TABLE_CELL_ATTRIBUTES,
1426
+ ...LAYOUT_ATTRIBUTES,
1427
+ ...COMMON_HTML_ATTRIBUTES
1428
+ ]) };
1429
+ },
1430
+ parseHTML() {
1431
+ return [{
1432
+ tag: "th",
1433
+ getAttrs: (node) => {
1434
+ if (typeof node === "string") return false;
1435
+ const element = node;
1436
+ const attrs = {};
1437
+ Array.from(element.attributes).forEach((attr) => {
1438
+ attrs[attr.name] = attr.value;
1439
+ });
1440
+ return attrs;
1441
+ }
1442
+ }];
1443
+ },
1444
+ renderHTML({ HTMLAttributes }) {
1445
+ return [
1446
+ "th",
1447
+ HTMLAttributes,
1448
+ 0
1449
+ ];
1450
+ }
1451
+ });
1452
+
1453
+ //#endregion
1454
+ //#region src/extensions/text.tsx
1455
+ const Text$1 = EmailNode.from(Text, ({ children }) => {
1456
+ return /* @__PURE__ */ jsx(Fragment, { children });
1457
+ });
1458
+
1459
+ //#endregion
1460
+ //#region src/extensions/underline.tsx
1461
+ const Underline = EmailMark.from(UnderlineBase, ({ children, style }) => /* @__PURE__ */ jsx("u", {
1462
+ style,
1463
+ children
1464
+ }));
1465
+
1466
+ //#endregion
1467
+ //#region src/extensions/uppercase.tsx
1468
+ const Uppercase = EmailMark.create({
1469
+ name: "uppercase",
1470
+ addOptions() {
1471
+ return { HTMLAttributes: {} };
1472
+ },
1473
+ parseHTML() {
1474
+ return [{
1475
+ tag: "span",
1476
+ getAttrs: (node) => {
1477
+ if (node.style.textTransform === "uppercase") return {};
1478
+ return false;
1479
+ }
1480
+ }];
1481
+ },
1482
+ renderHTML({ HTMLAttributes }) {
1483
+ return [
1484
+ "span",
1485
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { style: "text-transform: uppercase" }),
1486
+ 0
1487
+ ];
1488
+ },
1489
+ renderToReactEmail({ children, style }) {
1490
+ return /* @__PURE__ */ jsx("span", {
1491
+ style: {
1492
+ ...style,
1493
+ textTransform: "uppercase"
1494
+ },
1495
+ children
1496
+ });
1497
+ },
1498
+ addCommands() {
1499
+ return {
1500
+ setUppercase: () => ({ commands }) => {
1501
+ return commands.setMark(this.name);
1502
+ },
1503
+ toggleUppercase: () => ({ commands }) => {
1504
+ return commands.toggleMark(this.name);
1505
+ },
1506
+ unsetUppercase: () => ({ commands }) => {
1507
+ return commands.unsetMark(this.name);
1508
+ }
1509
+ };
1510
+ }
1511
+ });
1512
+
1513
+ //#endregion
1514
+ //#region src/extensions/index.ts
1515
+ const starterKitExtensions = {
1516
+ CodeBlockPrism,
1517
+ Code,
1518
+ TwoColumns,
1519
+ ThreeColumns,
1520
+ FourColumns,
1521
+ ColumnsColumn,
1522
+ Paragraph,
1523
+ BulletList,
1524
+ OrderedList,
1525
+ Blockquote,
1526
+ ListItem,
1527
+ HardBreak,
1528
+ Italic,
1529
+ Placeholder,
1530
+ PreviewText,
1531
+ Bold,
1532
+ Strike,
1533
+ Heading: Heading$2,
1534
+ Divider,
1535
+ Link: Link$1,
1536
+ Sup,
1537
+ Underline,
1538
+ Uppercase,
1539
+ PreservedStyle,
1540
+ Table,
1541
+ TableRow,
1542
+ TableCell,
1543
+ TableHeader,
1544
+ Body: Body$1,
1545
+ Div,
1546
+ Button: Button$1,
1547
+ Section: Section$1,
1548
+ GlobalContent,
1549
+ Text: Text$1,
1550
+ AlignmentAttribute,
1551
+ StyleAttribute,
1552
+ ClassAttribute,
1553
+ MaxNesting
1554
+ };
1555
+ const StarterKit = Extension.create({
1556
+ name: "reactEmailStarterKit",
1557
+ addOptions() {
1558
+ return {
1559
+ TiptapStarterKit: {},
1560
+ CodeBlockPrism: {
1561
+ defaultLanguage: "javascript",
1562
+ HTMLAttributes: { class: "prism node-codeBlock" }
1563
+ },
1564
+ Code: { HTMLAttributes: {
1565
+ class: "node-inlineCode",
1566
+ spellcheck: "false"
1567
+ } },
1568
+ TwoColumns: {},
1569
+ ThreeColumns: {},
1570
+ FourColumns: {},
1571
+ ColumnsColumn: {},
1572
+ Paragraph: { HTMLAttributes: { class: "node-paragraph" } },
1573
+ BulletList: { HTMLAttributes: { class: "node-bulletList" } },
1574
+ OrderedList: { HTMLAttributes: { class: "node-orderedList" } },
1575
+ Blockquote: { HTMLAttributes: { class: "node-blockquote" } },
1576
+ ListItem: {},
1577
+ HardBreak: {},
1578
+ Italic: {},
1579
+ Placeholder: {},
1580
+ PreviewText: {},
1581
+ Bold: {},
1582
+ Strike: {},
1583
+ Heading: {},
1584
+ Divider: {},
1585
+ Link: {
1586
+ openOnClick: false,
1587
+ HTMLAttributes: { class: "node-link" }
1588
+ },
1589
+ Sup: {},
1590
+ Underline: {},
1591
+ Uppercase: {},
1592
+ PreservedStyle: {},
1593
+ Table: {},
1594
+ TableRow: {},
1595
+ TableCell: {},
1596
+ TableHeader: {},
1597
+ Body: {},
1598
+ Div: {},
1599
+ Button: {},
1600
+ Section: {},
1601
+ GlobalContent: {},
1602
+ AlignmentAttribute: { types: [
1603
+ "heading",
1604
+ "paragraph",
1605
+ "image",
1606
+ "blockquote",
1607
+ "codeBlock",
1608
+ "bulletList",
1609
+ "orderedList",
1610
+ "listItem",
1611
+ "button",
1612
+ "youtube",
1613
+ "twitter",
1614
+ "table",
1615
+ "tableRow",
1616
+ "tableCell",
1617
+ "tableHeader",
1618
+ "columnsColumn"
1619
+ ] },
1620
+ StyleAttribute: { types: [
1621
+ "heading",
1622
+ "paragraph",
1623
+ "image",
1624
+ "blockquote",
1625
+ "codeBlock",
1626
+ "bulletList",
1627
+ "orderedList",
1628
+ "listItem",
1629
+ "button",
1630
+ "youtube",
1631
+ "twitter",
1632
+ "horizontalRule",
1633
+ "footer",
1634
+ "section",
1635
+ "div",
1636
+ "body",
1637
+ "table",
1638
+ "tableRow",
1639
+ "tableCell",
1640
+ "tableHeader",
1641
+ "columnsColumn",
1642
+ "link"
1643
+ ] },
1644
+ Text: {},
1645
+ ClassAttribute: { types: [
1646
+ "heading",
1647
+ "paragraph",
1648
+ "image",
1649
+ "blockquote",
1650
+ "bulletList",
1651
+ "orderedList",
1652
+ "listItem",
1653
+ "button",
1654
+ "youtube",
1655
+ "twitter",
1656
+ "horizontalRule",
1657
+ "footer",
1658
+ "section",
1659
+ "div",
1660
+ "body",
1661
+ "table",
1662
+ "tableRow",
1663
+ "tableCell",
1664
+ "tableHeader",
1665
+ "columnsColumn",
1666
+ "link"
1667
+ ] },
1668
+ MaxNesting: {
1669
+ maxDepth: 50,
1670
+ nodeTypes: [
1671
+ "section",
1672
+ "bulletList",
1673
+ "orderedList"
1674
+ ]
1675
+ }
1676
+ };
1677
+ },
1678
+ addExtensions() {
1679
+ const extensions = [];
1680
+ if (this.options.TiptapStarterKit !== false) extensions.push(TipTapStarterKit.configure({
1681
+ undoRedo: false,
1682
+ heading: false,
1683
+ link: false,
1684
+ underline: false,
1685
+ trailingNode: false,
1686
+ bold: false,
1687
+ italic: false,
1688
+ strike: false,
1689
+ code: false,
1690
+ paragraph: false,
1691
+ bulletList: false,
1692
+ orderedList: false,
1693
+ listItem: false,
1694
+ blockquote: false,
1695
+ hardBreak: false,
1696
+ gapcursor: false,
1697
+ codeBlock: false,
1698
+ text: false,
1699
+ horizontalRule: false,
1700
+ dropcursor: {
1701
+ color: "#61a8f8",
1702
+ class: "rounded-full animate-[fade-in_300ms_ease-in-out] !z-40",
1703
+ width: 4
1704
+ },
1705
+ ...this.options.TiptapStarterKit
1706
+ }));
1707
+ for (const [name, extension] of Object.entries(starterKitExtensions)) {
1708
+ const key = name;
1709
+ const extensionOptions = this.options[key];
1710
+ if (extensionOptions !== false) extensions.push(extension.configure(extensionOptions));
1711
+ }
1712
+ return extensions;
1713
+ }
1714
+ });
1715
+
1716
+ //#endregion
1717
+ //#region src/core/create-drop-handler.ts
1718
+ function createDropHandler({ onPaste, onUploadImage }) {
1719
+ return (view, event, _slice, moved) => {
1720
+ if (!moved && event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
1721
+ event.preventDefault();
1722
+ const file = event.dataTransfer.files[0];
1723
+ if (onPaste?.(file, view)) return true;
1724
+ if (file.type.includes("image/") && onUploadImage) {
1725
+ onUploadImage(file, view, (view.posAtCoords({
1726
+ left: event.clientX,
1727
+ top: event.clientY
1728
+ })?.pos || 0) - 1);
1729
+ return true;
1730
+ }
1731
+ }
1732
+ return false;
1733
+ };
1734
+ }
1735
+
1736
+ //#endregion
1737
+ //#region src/utils/paste-sanitizer.ts
1738
+ /**
1739
+ * Sanitizes pasted HTML.
1740
+ * - From editor (has node-* classes): pass through as-is
1741
+ * - From external: strip all styles/classes, keep only semantic HTML
1742
+ */
1743
+ /**
1744
+ * Detects content from the Resend editor by checking for node-* class names.
1745
+ */
1746
+ const EDITOR_CLASS_PATTERN = /class="[^"]*node-/;
1747
+ /**
1748
+ * Attributes to preserve on specific elements for EXTERNAL content.
1749
+ * Only functional attributes - NO style or class.
1750
+ */
1751
+ const PRESERVED_ATTRIBUTES = {
1752
+ a: [
1753
+ "href",
1754
+ "target",
1755
+ "rel"
1756
+ ],
1757
+ img: [
1758
+ "src",
1759
+ "alt",
1760
+ "width",
1761
+ "height"
1762
+ ],
1763
+ td: ["colspan", "rowspan"],
1764
+ th: [
1765
+ "colspan",
1766
+ "rowspan",
1767
+ "scope"
1768
+ ],
1769
+ table: [
1770
+ "border",
1771
+ "cellpadding",
1772
+ "cellspacing"
1773
+ ],
1774
+ "*": ["id"]
1775
+ };
1776
+ function isFromEditor(html) {
1777
+ return EDITOR_CLASS_PATTERN.test(html);
1778
+ }
1779
+ function sanitizePastedHtml(html) {
1780
+ if (isFromEditor(html)) return html;
1781
+ const doc = new DOMParser().parseFromString(html, "text/html");
1782
+ sanitizeNode(doc.body);
1783
+ return doc.body.innerHTML;
1784
+ }
1785
+ function sanitizeNode(node) {
1786
+ if (node.nodeType === Node.ELEMENT_NODE) sanitizeElement(node);
1787
+ for (const child of Array.from(node.childNodes)) sanitizeNode(child);
1788
+ }
1789
+ function sanitizeElement(el) {
1790
+ const allowedForTag = PRESERVED_ATTRIBUTES[el.tagName.toLowerCase()] || [];
1791
+ const allowedGlobal = PRESERVED_ATTRIBUTES["*"] || [];
1792
+ const allowed = new Set([...allowedForTag, ...allowedGlobal]);
1793
+ const attributesToRemove = [];
1794
+ for (const attr of Array.from(el.attributes)) {
1795
+ if (attr.name.startsWith("data-")) {
1796
+ attributesToRemove.push(attr.name);
1797
+ continue;
1798
+ }
1799
+ if (!allowed.has(attr.name)) attributesToRemove.push(attr.name);
1800
+ }
1801
+ for (const attr of attributesToRemove) el.removeAttribute(attr);
1802
+ }
1803
+
1804
+ //#endregion
1805
+ //#region src/core/create-paste-handler.ts
1806
+ function createPasteHandler({ onPaste, onUploadImage, extensions }) {
1807
+ return (view, event, slice) => {
1808
+ const text = event.clipboardData?.getData("text/plain");
1809
+ if (text && onPaste?.(text, view)) {
1810
+ event.preventDefault();
1811
+ return true;
1812
+ }
1813
+ if (event.clipboardData?.files?.[0]) {
1814
+ const file = event.clipboardData.files[0];
1815
+ if (onPaste?.(file, view)) {
1816
+ event.preventDefault();
1817
+ return true;
1818
+ }
1819
+ if (file.type.includes("image/") && onUploadImage) {
1820
+ const pos = view.state.selection.from;
1821
+ onUploadImage(file, view, pos);
1822
+ return true;
1823
+ }
1824
+ }
1825
+ /**
1826
+ * If the coming content has a single child, we can assume
1827
+ * it's a plain text and doesn't need to be parsed and
1828
+ * be introduced in a new line
1829
+ */
1830
+ if (slice.content.childCount === 1) return false;
1831
+ if (event.clipboardData?.getData?.("text/html")) {
1832
+ event.preventDefault();
1833
+ const jsonContent = generateJSON(sanitizePastedHtml(event.clipboardData.getData("text/html")), extensions);
1834
+ const node = view.state.schema.nodeFromJSON(jsonContent);
1835
+ const transaction = view.state.tr.replaceSelectionWith(node, false);
1836
+ view.dispatch(transaction);
1837
+ return true;
1838
+ }
1839
+ return false;
1840
+ };
1841
+ }
1842
+
1843
+ //#endregion
1844
+ //#region src/core/use-editor.ts
1845
+ const COLLABORATION_EXTENSION_NAMES = new Set(["liveblocksExtension", "collaboration"]);
1846
+ function hasCollaborationExtension(exts) {
1847
+ return exts.some((ext) => COLLABORATION_EXTENSION_NAMES.has(ext.name));
1848
+ }
1849
+ function useEditor$1({ content, extensions = [], onUpdate, onPaste, onUploadImage, onReady, editable = true, ...rest }) {
1850
+ const [contentError, setContentError] = React.useState(null);
1851
+ const isCollaborative = hasCollaborationExtension(extensions);
1852
+ const effectiveExtensions = React.useMemo(() => [
1853
+ StarterKit,
1854
+ ...isCollaborative ? [] : [UndoRedo],
1855
+ ...extensions
1856
+ ], [extensions, isCollaborative]);
1857
+ const editor = useEditor({
1858
+ content: isCollaborative ? void 0 : content,
1859
+ extensions: effectiveExtensions,
1860
+ editable,
1861
+ immediatelyRender: false,
1862
+ enableContentCheck: true,
1863
+ onContentError({ editor: editor$1, error, disableCollaboration }) {
1864
+ disableCollaboration();
1865
+ setContentError(error);
1866
+ console.error(error);
1867
+ editor$1.setEditable(false);
1868
+ },
1869
+ onCreate({ editor: editor$1 }) {
1870
+ onReady?.(editor$1);
1871
+ },
1872
+ onUpdate({ editor: editor$1, transaction }) {
1873
+ onUpdate?.(editor$1, transaction);
1874
+ },
1875
+ editorProps: {
1876
+ handleDOMEvents: { click: (view, event) => {
1877
+ if (!view.editable) {
1878
+ if (event.target.closest("a")) {
1879
+ event.preventDefault();
1880
+ return true;
1881
+ }
1882
+ }
1883
+ return false;
1884
+ } },
1885
+ handlePaste: createPasteHandler({
1886
+ onPaste,
1887
+ onUploadImage,
1888
+ extensions: effectiveExtensions
1889
+ }),
1890
+ handleDrop: createDropHandler({
1891
+ onPaste,
1892
+ onUploadImage
1893
+ })
1894
+ },
1895
+ ...rest
1896
+ });
1897
+ return {
1898
+ editor,
1899
+ isEditorEmpty: useEditorState({
1900
+ editor,
1901
+ selector: (context) => {
1902
+ if (!context.editor) return true;
1903
+ return isDocumentVisuallyEmpty(context.editor.state.doc);
1904
+ }
1905
+ }) ?? true,
1906
+ extensions: effectiveExtensions,
1907
+ contentError,
1908
+ isCollaborative
1909
+ };
1910
+ }
1911
+
1912
+ //#endregion
1913
+ export { ClassAttribute as A, Italic as C, Div as D, Divider as E, Blockquote as F, AlignmentAttribute as I, composeReactEmail as L, BulletList as M, Bold as N, CodeBlockPrism as O, Body$1 as P, isDocumentVisuallyEmpty as R, processStylesForUnlink as S, HardBreak as T, OrderedList as _, Text$1 as a, Link$1 as b, TableHeader as c, StyleAttribute as d, Strike as f, Paragraph as g, Placeholder as h, Underline as i, Button$1 as j, Code as k, TableRow as l, PreviewText as m, StarterKit as n, Table as o, Section$1 as p, Uppercase as r, TableCell as s, useEditor$1 as t, Sup as u, MaxNesting as v, Heading$2 as w, PreservedStyle as x, ListItem as y };
1914
+ //# sourceMappingURL=core-mUMTkab3.mjs.map