@react-email/editor 0.0.0-experimental.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/columns-BItFgD76.mjs +273 -0
- package/dist/columns-BItFgD76.mjs.map +1 -0
- package/dist/columns-DqFvXgmK.cjs +394 -0
- package/dist/core/index.cjs +10 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.mts +2 -0
- package/dist/core/index.mjs +4 -0
- package/dist/core-CbSTyrV4.mjs +151 -0
- package/dist/core-CbSTyrV4.mjs.map +1 -0
- package/dist/core-D7AzzMLI.cjs +167 -0
- package/dist/email-node-B-_g4X-S.mjs +254 -0
- package/dist/email-node-B-_g4X-S.mjs.map +1 -0
- package/dist/email-node-hLU5bGnX.cjs +288 -0
- package/dist/event-bus-CIJ___tH.cjs +65 -0
- package/dist/event-bus-CqrIUE24.mjs +55 -0
- package/dist/event-bus-CqrIUE24.mjs.map +1 -0
- package/dist/extension-BbjpP9mF.cjs +1625 -0
- package/dist/extension-C5qNDPZL.mjs +154 -0
- package/dist/extension-C5qNDPZL.mjs.map +1 -0
- package/dist/extension-Cs4Yq2gF.cjs +158 -0
- package/dist/extension-DlWknmE5.mjs +1495 -0
- package/dist/extension-DlWknmE5.mjs.map +1 -0
- package/dist/extensions/index.cjs +50 -0
- package/dist/extensions/index.d.cts +392 -0
- package/dist/extensions/index.d.cts.map +1 -0
- package/dist/extensions/index.d.mts +392 -0
- package/dist/extensions/index.d.mts.map +1 -0
- package/dist/extensions/index.mjs +4 -0
- package/dist/extensions-CHIQO3d-.mjs +1745 -0
- package/dist/extensions-CHIQO3d-.mjs.map +1 -0
- package/dist/extensions-DCrDvZ42.cjs +1981 -0
- package/dist/global-content-0-J-Te3N.mjs +77 -0
- package/dist/global-content-0-J-Te3N.mjs.map +1 -0
- package/dist/global-content-8M2KyrOL.cjs +87 -0
- package/dist/image-KwEYzhji.cjs +41 -0
- package/dist/image-Oc789YjV.mjs +37 -0
- package/dist/image-Oc789YjV.mjs.map +1 -0
- package/dist/index-CHAPu71g.d.cts +193 -0
- package/dist/index-CHAPu71g.d.cts.map +1 -0
- package/dist/index-D4UEWmJX.d.mts +193 -0
- package/dist/index-D4UEWmJX.d.mts.map +1 -0
- package/dist/index.cjs +216 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +33 -623
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +189 -2349
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/index.cjs +56 -0
- package/dist/plugins/index.d.cts +114 -0
- package/dist/plugins/index.d.cts.map +1 -0
- package/dist/plugins/index.d.mts +114 -0
- package/dist/plugins/index.d.mts.map +1 -0
- package/dist/plugins/index.mjs +34 -0
- package/dist/plugins/index.mjs.map +1 -0
- package/dist/root-CT5d4CKj.cjs +2798 -0
- package/dist/root-uvdshbyT.mjs +2295 -0
- package/dist/root-uvdshbyT.mjs.map +1 -0
- package/dist/set-text-alignment-BCRnE5So.mjs +19 -0
- package/dist/set-text-alignment-BCRnE5So.mjs.map +1 -0
- package/dist/set-text-alignment-Twg1EG4-.cjs +22 -0
- package/dist/style.css +974 -0
- package/dist/types-BG5XsXt9.d.mts +37 -0
- package/dist/types-BG5XsXt9.d.mts.map +1 -0
- package/dist/types-DnOcnDoO.d.mts +56 -0
- package/dist/types-DnOcnDoO.d.mts.map +1 -0
- package/dist/types-DzPTbbDC.d.cts +56 -0
- package/dist/types-DzPTbbDC.d.cts.map +1 -0
- package/dist/types-hURXpEIO.d.cts +37 -0
- package/dist/types-hURXpEIO.d.cts.map +1 -0
- package/dist/ui/bubble-menu/bubble-menu.css +291 -0
- package/dist/ui/index.cjs +2899 -0
- package/dist/ui/index.d.cts +1155 -0
- package/dist/ui/index.d.cts.map +1 -0
- package/dist/ui/index.d.mts +1157 -0
- package/dist/ui/index.d.mts.map +1 -0
- package/dist/ui/index.mjs +2788 -0
- package/dist/ui/index.mjs.map +1 -0
- package/dist/ui/inspector/inspector.css +293 -0
- package/dist/ui/slash-command/slash-command.css +44 -0
- package/dist/ui/themes/default.css +1140 -0
- package/dist/utils/index.cjs +3 -0
- package/dist/utils/index.d.cts +7 -0
- package/dist/utils/index.d.cts.map +1 -0
- package/dist/utils/index.d.mts +7 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +2 -0
- package/package.json +100 -16
- package/readme.md +69 -0
- package/dist/index.d.ts +0 -628
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2461
package/dist/index.mjs
CHANGED
|
@@ -1,2376 +1,216 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StarterKit } from "
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//#region src/core/event-bus.ts
|
|
50
|
-
const EVENT_PREFIX = "@react-email/editor:";
|
|
51
|
-
var EditorEventBus = class {
|
|
52
|
-
prefixEventName(eventName) {
|
|
53
|
-
return `${EVENT_PREFIX}${String(eventName)}`;
|
|
54
|
-
}
|
|
55
|
-
dispatch(eventName, payload, options) {
|
|
56
|
-
const target = options?.target ?? window;
|
|
57
|
-
const prefixedEventName = this.prefixEventName(eventName);
|
|
58
|
-
const event = new CustomEvent(prefixedEventName, {
|
|
59
|
-
detail: payload,
|
|
60
|
-
bubbles: false,
|
|
61
|
-
cancelable: false
|
|
62
|
-
});
|
|
63
|
-
target.dispatchEvent(event);
|
|
64
|
-
}
|
|
65
|
-
on(eventName, handler, options) {
|
|
66
|
-
const target = options?.target ?? window;
|
|
67
|
-
const prefixedEventName = this.prefixEventName(eventName);
|
|
68
|
-
const abortController = new AbortController();
|
|
69
|
-
const wrappedHandler = (event) => {
|
|
70
|
-
const customEvent = event;
|
|
71
|
-
const result = handler(customEvent.detail);
|
|
72
|
-
if (result instanceof Promise) result.catch((error) => {
|
|
73
|
-
console.error(`Error in async event handler for ${prefixedEventName}:`, {
|
|
74
|
-
event: customEvent.detail,
|
|
75
|
-
error
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
target.addEventListener(prefixedEventName, wrappedHandler, {
|
|
80
|
-
...options,
|
|
81
|
-
signal: abortController.signal
|
|
82
|
-
});
|
|
83
|
-
return { unsubscribe: () => {
|
|
84
|
-
abortController.abort();
|
|
85
|
-
} };
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const editorEventBus = new EditorEventBus();
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/extensions/alignment-attribute.tsx
|
|
92
|
-
const AlignmentAttribute = Extension.create({
|
|
93
|
-
name: "alignmentAttribute",
|
|
94
|
-
addOptions() {
|
|
95
|
-
return {
|
|
96
|
-
types: [],
|
|
97
|
-
alignments: [
|
|
98
|
-
"left",
|
|
99
|
-
"center",
|
|
100
|
-
"right",
|
|
101
|
-
"justify"
|
|
102
|
-
]
|
|
103
|
-
};
|
|
104
|
-
},
|
|
105
|
-
addGlobalAttributes() {
|
|
106
|
-
return [{
|
|
107
|
-
types: this.options.types,
|
|
108
|
-
attributes: { alignment: {
|
|
109
|
-
parseHTML: (element) => {
|
|
110
|
-
const explicitAlign = element.getAttribute("align") || element.getAttribute("alignment") || element.style.textAlign;
|
|
111
|
-
if (explicitAlign && this.options.alignments.includes(explicitAlign)) return explicitAlign;
|
|
112
|
-
return null;
|
|
113
|
-
},
|
|
114
|
-
renderHTML: (attributes) => {
|
|
115
|
-
if (attributes.alignment === "left") return {};
|
|
116
|
-
return { alignment: attributes.alignment };
|
|
117
|
-
}
|
|
118
|
-
} }
|
|
119
|
-
}];
|
|
120
|
-
},
|
|
121
|
-
addCommands() {
|
|
122
|
-
return { setAlignment: (alignment) => ({ commands }) => {
|
|
123
|
-
if (!this.options.alignments.includes(alignment)) return false;
|
|
124
|
-
return this.options.types.every((type) => commands.updateAttributes(type, { alignment }));
|
|
125
|
-
} };
|
|
126
|
-
},
|
|
127
|
-
addKeyboardShortcuts() {
|
|
128
|
-
return {
|
|
129
|
-
Enter: () => {
|
|
130
|
-
const { from } = this.editor.state.selection;
|
|
131
|
-
const currentAlignment = this.editor.state.doc.nodeAt(from)?.attrs?.alignment;
|
|
132
|
-
if (currentAlignment) requestAnimationFrame(() => {
|
|
133
|
-
this.editor.commands.setAlignment(currentAlignment);
|
|
134
|
-
});
|
|
135
|
-
return false;
|
|
136
|
-
},
|
|
137
|
-
"Mod-Shift-l": () => this.editor.commands.setAlignment("left"),
|
|
138
|
-
"Mod-Shift-e": () => this.editor.commands.setAlignment("center"),
|
|
139
|
-
"Mod-Shift-r": () => this.editor.commands.setAlignment("right"),
|
|
140
|
-
"Mod-Shift-j": () => this.editor.commands.setAlignment("justify")
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/utils/attribute-helpers.ts
|
|
147
|
-
/**
|
|
148
|
-
* Creates TipTap attribute definitions for a list of HTML attributes.
|
|
149
|
-
* Each attribute will have the same pattern:
|
|
150
|
-
* - default: null
|
|
151
|
-
* - parseHTML: extracts the attribute from the element
|
|
152
|
-
* - renderHTML: conditionally renders the attribute if it has a value
|
|
153
|
-
*
|
|
154
|
-
* @param attributeNames - Array of HTML attribute names to create definitions for
|
|
155
|
-
* @returns Object with TipTap attribute definitions
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* const attrs = createStandardAttributes(['class', 'id', 'title']);
|
|
159
|
-
* // Returns:
|
|
160
|
-
* // {
|
|
161
|
-
* // class: {
|
|
162
|
-
* // default: null,
|
|
163
|
-
* // parseHTML: (element) => element.getAttribute('class'),
|
|
164
|
-
* // renderHTML: (attributes) => attributes.class ? { class: attributes.class } : {}
|
|
165
|
-
* // },
|
|
166
|
-
* // ...
|
|
167
|
-
* // }
|
|
168
|
-
*/
|
|
169
|
-
function createStandardAttributes(attributeNames) {
|
|
170
|
-
return Object.fromEntries(attributeNames.map((attr) => [attr, {
|
|
171
|
-
default: null,
|
|
172
|
-
parseHTML: (element) => element.getAttribute(attr),
|
|
173
|
-
renderHTML: (attributes) => {
|
|
174
|
-
if (!attributes[attr]) return {};
|
|
175
|
-
return { [attr]: attributes[attr] };
|
|
176
|
-
}
|
|
177
|
-
}]));
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Common HTML attributes used across multiple extensions.
|
|
181
|
-
* These preserve attributes during HTML import and editing for better
|
|
182
|
-
* fidelity when importing existing email templates.
|
|
183
|
-
*/
|
|
184
|
-
const COMMON_HTML_ATTRIBUTES = [
|
|
185
|
-
"id",
|
|
186
|
-
"class",
|
|
187
|
-
"title",
|
|
188
|
-
"lang",
|
|
189
|
-
"dir",
|
|
190
|
-
"data-id"
|
|
191
|
-
];
|
|
192
|
-
/**
|
|
193
|
-
* Layout-specific HTML attributes used for positioning and sizing.
|
|
194
|
-
*/
|
|
195
|
-
const LAYOUT_ATTRIBUTES = [
|
|
196
|
-
"align",
|
|
197
|
-
"width",
|
|
198
|
-
"height"
|
|
199
|
-
];
|
|
200
|
-
/**
|
|
201
|
-
* Table-specific HTML attributes used for table layout and styling.
|
|
202
|
-
*/
|
|
203
|
-
const TABLE_ATTRIBUTES = [
|
|
204
|
-
"border",
|
|
205
|
-
"cellpadding",
|
|
206
|
-
"cellspacing"
|
|
207
|
-
];
|
|
208
|
-
/**
|
|
209
|
-
* Table cell-specific HTML attributes.
|
|
210
|
-
*/
|
|
211
|
-
const TABLE_CELL_ATTRIBUTES = [
|
|
212
|
-
"valign",
|
|
213
|
-
"bgcolor",
|
|
214
|
-
"colspan",
|
|
215
|
-
"rowspan"
|
|
216
|
-
];
|
|
217
|
-
/**
|
|
218
|
-
* Table header cell-specific HTML attributes.
|
|
219
|
-
* These are additional attributes that only apply to <th> elements.
|
|
220
|
-
*/
|
|
221
|
-
const TABLE_HEADER_ATTRIBUTES = [...TABLE_CELL_ATTRIBUTES, "scope"];
|
|
222
|
-
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region src/utils/styles.ts
|
|
225
|
-
const WHITE_SPACE_REGEX = /\s+/;
|
|
226
|
-
const inlineCssToJs = (inlineStyle, options = {}) => {
|
|
227
|
-
const styleObject = {};
|
|
228
|
-
if (!inlineStyle || inlineStyle === "" || typeof inlineStyle === "object") return styleObject;
|
|
229
|
-
inlineStyle.split(";").forEach((style) => {
|
|
230
|
-
if (style.trim()) {
|
|
231
|
-
const [key, value] = style.split(":");
|
|
232
|
-
const valueTrimmed = value?.trim();
|
|
233
|
-
if (!valueTrimmed) return;
|
|
234
|
-
const formattedKey = key.trim().replace(/-\w/g, (match) => match[1].toUpperCase());
|
|
235
|
-
styleObject[formattedKey] = options?.removeUnit ? valueTrimmed.replace(/px|%/g, "") : valueTrimmed;
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
return styleObject;
|
|
1
|
+
import { n as composeReactEmail } from "./core-CbSTyrV4.mjs";
|
|
2
|
+
import { t as StarterKit } from "./extensions-CHIQO3d-.mjs";
|
|
3
|
+
import { t as EmailTheming } from "./extension-DlWknmE5.mjs";
|
|
4
|
+
import { t as createImageExtension } from "./extension-C5qNDPZL.mjs";
|
|
5
|
+
import { t as SlashCommandRoot, x as BubbleMenu } from "./root-uvdshbyT.mjs";
|
|
6
|
+
import { EditorProvider, useCurrentEditor } from "@tiptap/react";
|
|
7
|
+
import { forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef } from "react";
|
|
8
|
+
import { generateJSON } from "@tiptap/html";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { Placeholder } from "@tiptap/extension-placeholder";
|
|
11
|
+
//#region src/utils/paste-sanitizer.ts
|
|
12
|
+
/**
|
|
13
|
+
* Sanitizes pasted HTML.
|
|
14
|
+
* - From editor (has node-* classes): pass through as-is
|
|
15
|
+
* - From external: strip all styles/classes, keep only semantic HTML
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Detects content from the Resend editor by checking for node-* class names.
|
|
19
|
+
*/
|
|
20
|
+
const EDITOR_CLASS_PATTERN = /class="[^"]*node-/;
|
|
21
|
+
/**
|
|
22
|
+
* Attributes to preserve on specific elements for EXTERNAL content.
|
|
23
|
+
* Only functional attributes - NO style or class.
|
|
24
|
+
*/
|
|
25
|
+
const PRESERVED_ATTRIBUTES = {
|
|
26
|
+
a: [
|
|
27
|
+
"href",
|
|
28
|
+
"target",
|
|
29
|
+
"rel"
|
|
30
|
+
],
|
|
31
|
+
img: [
|
|
32
|
+
"src",
|
|
33
|
+
"alt",
|
|
34
|
+
"width",
|
|
35
|
+
"height"
|
|
36
|
+
],
|
|
37
|
+
td: ["colspan", "rowspan"],
|
|
38
|
+
th: [
|
|
39
|
+
"colspan",
|
|
40
|
+
"rowspan",
|
|
41
|
+
"scope"
|
|
42
|
+
],
|
|
43
|
+
table: [
|
|
44
|
+
"border",
|
|
45
|
+
"cellpadding",
|
|
46
|
+
"cellspacing"
|
|
47
|
+
],
|
|
48
|
+
"*": ["id"]
|
|
239
49
|
};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
expanded.marginBottom = values.bottom;
|
|
263
|
-
expanded.marginLeft = values.left;
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
case "padding": {
|
|
267
|
-
const values = parseShorthandValue(value);
|
|
268
|
-
expanded.paddingTop = values.top;
|
|
269
|
-
expanded.paddingRight = values.right;
|
|
270
|
-
expanded.paddingBottom = values.bottom;
|
|
271
|
-
expanded.paddingLeft = values.left;
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
case "border": {
|
|
275
|
-
const values = convertBorderValue(value);
|
|
276
|
-
expanded.borderStyle = values.style;
|
|
277
|
-
expanded.borderWidth = values.width;
|
|
278
|
-
expanded.borderColor = values.color;
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
case "borderTopLeftRadius":
|
|
282
|
-
case "borderTopRightRadius":
|
|
283
|
-
case "borderBottomLeftRadius":
|
|
284
|
-
case "borderBottomRightRadius":
|
|
285
|
-
expanded[key] = value;
|
|
286
|
-
if (styles.borderTopLeftRadius && styles.borderTopRightRadius && styles.borderBottomLeftRadius && styles.borderBottomRightRadius) {
|
|
287
|
-
const values = [
|
|
288
|
-
styles.borderTopLeftRadius,
|
|
289
|
-
styles.borderTopRightRadius,
|
|
290
|
-
styles.borderBottomLeftRadius,
|
|
291
|
-
styles.borderBottomRightRadius
|
|
292
|
-
];
|
|
293
|
-
if (new Set(values).size === 1) expanded.borderRadius = values[0];
|
|
294
|
-
}
|
|
295
|
-
break;
|
|
296
|
-
default: expanded[key] = value;
|
|
50
|
+
function isFromEditor(html) {
|
|
51
|
+
return EDITOR_CLASS_PATTERN.test(html);
|
|
52
|
+
}
|
|
53
|
+
function sanitizePastedHtml(html) {
|
|
54
|
+
if (isFromEditor(html)) return html;
|
|
55
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
56
|
+
sanitizeNode(doc.body);
|
|
57
|
+
return doc.body.innerHTML;
|
|
58
|
+
}
|
|
59
|
+
function sanitizeNode(node) {
|
|
60
|
+
if (node.nodeType === Node.ELEMENT_NODE) sanitizeElement(node);
|
|
61
|
+
for (const child of Array.from(node.childNodes)) sanitizeNode(child);
|
|
62
|
+
}
|
|
63
|
+
function sanitizeElement(el) {
|
|
64
|
+
const allowedForTag = PRESERVED_ATTRIBUTES[el.tagName.toLowerCase()] || [];
|
|
65
|
+
const allowedGlobal = PRESERVED_ATTRIBUTES["*"] || [];
|
|
66
|
+
const allowed = new Set([...allowedForTag, ...allowedGlobal]);
|
|
67
|
+
const attributesToRemove = [];
|
|
68
|
+
for (const attr of Array.from(el.attributes)) {
|
|
69
|
+
if (attr.name.startsWith("data-")) {
|
|
70
|
+
attributesToRemove.push(attr.name);
|
|
71
|
+
continue;
|
|
297
72
|
}
|
|
73
|
+
if (!allowed.has(attr.name)) attributesToRemove.push(attr.name);
|
|
298
74
|
}
|
|
299
|
-
|
|
75
|
+
for (const attr of attributesToRemove) el.removeAttribute(attr);
|
|
300
76
|
}
|
|
301
|
-
/**
|
|
302
|
-
* Parses CSS shorthand value (1-4 values) into individual side values.
|
|
303
|
-
* Follows CSS specification for shorthand property value parsing.
|
|
304
|
-
*
|
|
305
|
-
* @param value - Shorthand value string (e.g., '0', '10px 20px', '5px 10px 15px 20px')
|
|
306
|
-
* @returns Object with top, right, bottom, left values
|
|
307
|
-
*/
|
|
308
|
-
function parseShorthandValue(value) {
|
|
309
|
-
const stringValue = String(value).trim();
|
|
310
|
-
const parts = stringValue.split(WHITE_SPACE_REGEX);
|
|
311
|
-
const len = parts.length;
|
|
312
|
-
if (len === 1) return {
|
|
313
|
-
top: parts[0],
|
|
314
|
-
right: parts[0],
|
|
315
|
-
bottom: parts[0],
|
|
316
|
-
left: parts[0]
|
|
317
|
-
};
|
|
318
|
-
if (len === 2) return {
|
|
319
|
-
top: parts[0],
|
|
320
|
-
right: parts[1],
|
|
321
|
-
bottom: parts[0],
|
|
322
|
-
left: parts[1]
|
|
323
|
-
};
|
|
324
|
-
if (len === 3) return {
|
|
325
|
-
top: parts[0],
|
|
326
|
-
right: parts[1],
|
|
327
|
-
bottom: parts[2],
|
|
328
|
-
left: parts[1]
|
|
329
|
-
};
|
|
330
|
-
if (len === 4) return {
|
|
331
|
-
top: parts[0],
|
|
332
|
-
right: parts[1],
|
|
333
|
-
bottom: parts[2],
|
|
334
|
-
left: parts[3]
|
|
335
|
-
};
|
|
336
|
-
return {
|
|
337
|
-
top: stringValue,
|
|
338
|
-
right: stringValue,
|
|
339
|
-
bottom: stringValue,
|
|
340
|
-
left: stringValue
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
function convertBorderValue(value) {
|
|
344
|
-
const stringValue = String(value).trim();
|
|
345
|
-
const parts = stringValue.split(WHITE_SPACE_REGEX);
|
|
346
|
-
switch (parts.length) {
|
|
347
|
-
case 1: return {
|
|
348
|
-
style: "solid",
|
|
349
|
-
width: parts[0],
|
|
350
|
-
color: "black"
|
|
351
|
-
};
|
|
352
|
-
case 2: return {
|
|
353
|
-
style: parts[1],
|
|
354
|
-
width: parts[0],
|
|
355
|
-
color: "black"
|
|
356
|
-
};
|
|
357
|
-
case 3: return {
|
|
358
|
-
style: parts[1],
|
|
359
|
-
width: parts[0],
|
|
360
|
-
color: parts[2]
|
|
361
|
-
};
|
|
362
|
-
case 4: return {
|
|
363
|
-
style: parts[1],
|
|
364
|
-
width: parts[0],
|
|
365
|
-
color: parts[2]
|
|
366
|
-
};
|
|
367
|
-
default: return {
|
|
368
|
-
style: "solid",
|
|
369
|
-
width: stringValue,
|
|
370
|
-
color: "black"
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Resolves conflicts between reset styles and inline styles by expanding
|
|
376
|
-
* shorthand properties (margin, padding) to longhand before merging.
|
|
377
|
-
* This prevents shorthand properties from overriding specific longhand properties.
|
|
378
|
-
*
|
|
379
|
-
* @param resetStyles - Base reset styles that may contain shorthand properties
|
|
380
|
-
* @param inlineStyles - Inline styles that should override reset styles
|
|
381
|
-
* @returns Merged styles with inline styles taking precedence
|
|
382
|
-
*/
|
|
383
|
-
function resolveConflictingStyles(resetStyles, inlineStyles) {
|
|
384
|
-
const expandedResetStyles = expandShorthandProperties(resetStyles);
|
|
385
|
-
const expandedInlineStyles = expandShorthandProperties(inlineStyles);
|
|
386
|
-
return {
|
|
387
|
-
...expandedResetStyles,
|
|
388
|
-
...expandedInlineStyles
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
77
|
//#endregion
|
|
393
|
-
//#region src/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
addAttributes() {
|
|
401
|
-
return { ...createStandardAttributes([...COMMON_HTML_ATTRIBUTES, ...LAYOUT_ATTRIBUTES]) };
|
|
402
|
-
},
|
|
403
|
-
parseHTML() {
|
|
404
|
-
return [{
|
|
405
|
-
tag: "body",
|
|
406
|
-
getAttrs: (node) => {
|
|
407
|
-
if (typeof node === "string") return false;
|
|
408
|
-
const element = node;
|
|
409
|
-
const attrs = {};
|
|
410
|
-
Array.from(element.attributes).forEach((attr) => {
|
|
411
|
-
attrs[attr.name] = attr.value;
|
|
412
|
-
});
|
|
413
|
-
return attrs;
|
|
414
|
-
}
|
|
415
|
-
}];
|
|
416
|
-
},
|
|
417
|
-
renderHTML({ HTMLAttributes }) {
|
|
418
|
-
return [
|
|
419
|
-
"div",
|
|
420
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
421
|
-
0
|
|
422
|
-
];
|
|
423
|
-
},
|
|
424
|
-
renderToReactEmail({ children, node, style }) {
|
|
425
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
426
|
-
return /* @__PURE__ */ jsx("div", {
|
|
427
|
-
className: node.attrs?.class || void 0,
|
|
428
|
-
style: {
|
|
429
|
-
...style,
|
|
430
|
-
...inlineStyles
|
|
431
|
-
},
|
|
432
|
-
children
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
//#endregion
|
|
438
|
-
//#region src/extensions/bold.ts
|
|
439
|
-
/**
|
|
440
|
-
* Matches bold text via `**` as input.
|
|
441
|
-
*/
|
|
442
|
-
const starInputRegex = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/;
|
|
443
|
-
/**
|
|
444
|
-
* Matches bold text via `**` while pasting.
|
|
445
|
-
*/
|
|
446
|
-
const starPasteRegex = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g;
|
|
447
|
-
/**
|
|
448
|
-
* Matches bold text via `__` as input.
|
|
449
|
-
*/
|
|
450
|
-
const underscoreInputRegex = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/;
|
|
451
|
-
/**
|
|
452
|
-
* Matches bold text via `__` while pasting.
|
|
453
|
-
*/
|
|
454
|
-
const underscorePasteRegex = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g;
|
|
455
|
-
/**
|
|
456
|
-
* This extension allows you to mark text as bold.
|
|
457
|
-
* @see https://tiptap.dev/api/marks/bold
|
|
458
|
-
*/
|
|
459
|
-
const Bold = Mark.create({
|
|
460
|
-
name: "bold",
|
|
461
|
-
addOptions() {
|
|
462
|
-
return { HTMLAttributes: {} };
|
|
463
|
-
},
|
|
464
|
-
parseHTML() {
|
|
465
|
-
return [
|
|
466
|
-
{ tag: "strong" },
|
|
467
|
-
{
|
|
468
|
-
tag: "b",
|
|
469
|
-
getAttrs: (node) => node.style.fontWeight !== "normal" && null
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
style: "font-weight=400",
|
|
473
|
-
clearMark: (mark) => mark.type.name === this.name
|
|
474
|
-
}
|
|
475
|
-
];
|
|
476
|
-
},
|
|
477
|
-
renderHTML({ HTMLAttributes }) {
|
|
478
|
-
return [
|
|
479
|
-
"strong",
|
|
480
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
481
|
-
0
|
|
482
|
-
];
|
|
483
|
-
},
|
|
484
|
-
addCommands() {
|
|
485
|
-
return {
|
|
486
|
-
setBold: () => ({ commands }) => {
|
|
487
|
-
return commands.setMark(this.name);
|
|
488
|
-
},
|
|
489
|
-
toggleBold: () => ({ commands }) => {
|
|
490
|
-
return commands.toggleMark(this.name);
|
|
491
|
-
},
|
|
492
|
-
unsetBold: () => ({ commands }) => {
|
|
493
|
-
return commands.unsetMark(this.name);
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
},
|
|
497
|
-
addKeyboardShortcuts() {
|
|
498
|
-
return {
|
|
499
|
-
"Mod-b": () => this.editor.commands.toggleBold(),
|
|
500
|
-
"Mod-B": () => this.editor.commands.toggleBold()
|
|
501
|
-
};
|
|
502
|
-
},
|
|
503
|
-
addInputRules() {
|
|
504
|
-
return [markInputRule({
|
|
505
|
-
find: starInputRegex,
|
|
506
|
-
type: this.type
|
|
507
|
-
}), markInputRule({
|
|
508
|
-
find: underscoreInputRegex,
|
|
509
|
-
type: this.type
|
|
510
|
-
})];
|
|
511
|
-
},
|
|
512
|
-
addPasteRules() {
|
|
513
|
-
return [markPasteRule({
|
|
514
|
-
find: starPasteRegex,
|
|
515
|
-
type: this.type
|
|
516
|
-
}), markPasteRule({
|
|
517
|
-
find: underscorePasteRegex,
|
|
518
|
-
type: this.type
|
|
519
|
-
})];
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
//#endregion
|
|
524
|
-
//#region src/extensions/button.tsx
|
|
525
|
-
const Button = EmailNode.create({
|
|
526
|
-
name: "button",
|
|
527
|
-
group: "block",
|
|
528
|
-
content: "inline*",
|
|
529
|
-
defining: true,
|
|
530
|
-
draggable: true,
|
|
531
|
-
marks: "bold",
|
|
532
|
-
addAttributes() {
|
|
533
|
-
return {
|
|
534
|
-
class: { default: "button" },
|
|
535
|
-
href: { default: "#" },
|
|
536
|
-
alignment: { default: "left" }
|
|
537
|
-
};
|
|
538
|
-
},
|
|
539
|
-
parseHTML() {
|
|
540
|
-
return [{
|
|
541
|
-
tag: "a[data-id=\"react-email-button\"]",
|
|
542
|
-
getAttrs: (node) => {
|
|
543
|
-
if (typeof node === "string") return false;
|
|
544
|
-
const element = node;
|
|
545
|
-
const attrs = {};
|
|
546
|
-
Array.from(element.attributes).forEach((attr) => {
|
|
547
|
-
attrs[attr.name] = attr.value;
|
|
548
|
-
});
|
|
549
|
-
return attrs;
|
|
550
|
-
}
|
|
551
|
-
}];
|
|
552
|
-
},
|
|
553
|
-
renderHTML({ HTMLAttributes }) {
|
|
554
|
-
return [
|
|
555
|
-
"div",
|
|
556
|
-
mergeAttributes({ class: `align-${HTMLAttributes?.alignment}` }),
|
|
557
|
-
[
|
|
558
|
-
"a",
|
|
559
|
-
mergeAttributes({
|
|
560
|
-
class: `node-button ${HTMLAttributes?.class}`,
|
|
561
|
-
style: HTMLAttributes?.style,
|
|
562
|
-
"data-id": "react-email-button",
|
|
563
|
-
"data-href": HTMLAttributes?.href
|
|
564
|
-
}),
|
|
565
|
-
0
|
|
566
|
-
]
|
|
567
|
-
];
|
|
568
|
-
},
|
|
569
|
-
addCommands() {
|
|
570
|
-
return {
|
|
571
|
-
updateButton: (attributes) => ({ commands }) => {
|
|
572
|
-
return commands.updateAttributes("button", attributes);
|
|
573
|
-
},
|
|
574
|
-
setButton: () => ({ commands }) => {
|
|
575
|
-
return commands.insertContent({
|
|
576
|
-
type: "button",
|
|
577
|
-
content: [{
|
|
578
|
-
type: "text",
|
|
579
|
-
text: "Button"
|
|
580
|
-
}]
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
},
|
|
585
|
-
renderToReactEmail({ children, node, style }) {
|
|
586
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
587
|
-
return /* @__PURE__ */ jsx(Row, { children: /* @__PURE__ */ jsx(Column, {
|
|
588
|
-
align: node.attrs?.align || node.attrs?.alignment,
|
|
589
|
-
children: /* @__PURE__ */ jsx(Button$1, {
|
|
590
|
-
className: node.attrs?.class || void 0,
|
|
591
|
-
href: node.attrs?.href,
|
|
592
|
-
style: {
|
|
593
|
-
...style,
|
|
594
|
-
...inlineStyles
|
|
595
|
-
},
|
|
596
|
-
children
|
|
597
|
-
})
|
|
598
|
-
}) });
|
|
599
|
-
}
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
//#endregion
|
|
603
|
-
//#region src/extensions/class-attribute.tsx
|
|
604
|
-
const ClassAttribute = Extension.create({
|
|
605
|
-
name: "classAttribute",
|
|
606
|
-
addOptions() {
|
|
607
|
-
return {
|
|
608
|
-
types: [],
|
|
609
|
-
class: []
|
|
610
|
-
};
|
|
611
|
-
},
|
|
612
|
-
addGlobalAttributes() {
|
|
613
|
-
return [{
|
|
614
|
-
types: this.options.types,
|
|
615
|
-
attributes: { class: {
|
|
616
|
-
default: "",
|
|
617
|
-
parseHTML: (element) => element.className || "",
|
|
618
|
-
renderHTML: (attributes) => {
|
|
619
|
-
return attributes.class ? { class: attributes.class } : {};
|
|
620
|
-
}
|
|
621
|
-
} }
|
|
622
|
-
}];
|
|
623
|
-
},
|
|
624
|
-
addCommands() {
|
|
625
|
-
return {
|
|
626
|
-
unsetClass: () => ({ commands }) => {
|
|
627
|
-
return this.options.types.every((type) => commands.resetAttributes(type, "class"));
|
|
628
|
-
},
|
|
629
|
-
setClass: (classList) => ({ commands }) => {
|
|
630
|
-
return this.options.types.every((type) => commands.updateAttributes(type, { class: classList }));
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
},
|
|
634
|
-
addKeyboardShortcuts() {
|
|
635
|
-
return { Enter: ({ editor }) => {
|
|
636
|
-
requestAnimationFrame(() => {
|
|
637
|
-
editor.commands.resetAttributes("paragraph", "class");
|
|
638
|
-
});
|
|
639
|
-
return false;
|
|
640
|
-
} };
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
//#endregion
|
|
645
|
-
//#region src/utils/prism-utils.ts
|
|
646
|
-
const publicURL = "/styles/prism";
|
|
647
|
-
function loadPrismTheme(theme) {
|
|
648
|
-
const link = document.createElement("link");
|
|
649
|
-
link.rel = "stylesheet";
|
|
650
|
-
link.href = `${publicURL}/prism-${theme}.css`;
|
|
651
|
-
link.setAttribute("data-prism-theme", "");
|
|
652
|
-
document.head.appendChild(link);
|
|
653
|
-
}
|
|
654
|
-
function removePrismTheme() {
|
|
655
|
-
const existingTheme = document.querySelectorAll("link[rel=\"stylesheet\"][data-prism-theme]");
|
|
656
|
-
if (existingTheme.length > 0) existingTheme.forEach((cssLinkTag) => {
|
|
657
|
-
cssLinkTag.remove();
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
function hasPrismThemeLoaded(theme) {
|
|
661
|
-
return !!document.querySelector(`link[rel="stylesheet"][data-prism-theme][href="${publicURL}/prism-${theme}.css"]`);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
//#endregion
|
|
665
|
-
//#region src/extensions/prism-plugin.ts
|
|
666
|
-
const PRISM_LANGUAGE_LOADED_META = "prismLanguageLoaded";
|
|
667
|
-
function parseNodes(nodes, className = []) {
|
|
668
|
-
return nodes.flatMap((node) => {
|
|
669
|
-
const classes = [...className, ...node.properties ? node.properties.className : []];
|
|
670
|
-
if (node.children) return parseNodes(node.children, classes);
|
|
671
|
-
return {
|
|
672
|
-
text: node.value ?? "",
|
|
673
|
-
classes
|
|
674
|
-
};
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
function getHighlightNodes(html) {
|
|
678
|
-
return fromHtml(html, { fragment: true }).children;
|
|
679
|
-
}
|
|
680
|
-
function registeredLang(aliasOrLanguage) {
|
|
681
|
-
const allSupportLang = Object.keys(Prism.languages).filter((id) => typeof Prism.languages[id] === "object");
|
|
682
|
-
return Boolean(allSupportLang.find((x) => x === aliasOrLanguage));
|
|
683
|
-
}
|
|
684
|
-
function getDecorations({ doc, name, defaultLanguage, defaultTheme, loadingLanguages, onLanguageLoaded }) {
|
|
685
|
-
const decorations = [];
|
|
686
|
-
findChildren(doc, (node) => node.type.name === name).forEach((block) => {
|
|
687
|
-
let from = block.pos + 1;
|
|
688
|
-
const language = block.node.attrs.language || defaultLanguage;
|
|
689
|
-
const theme = block.node.attrs.theme || defaultTheme;
|
|
690
|
-
let html = "";
|
|
691
|
-
try {
|
|
692
|
-
if (!registeredLang(language) && !loadingLanguages.has(language)) {
|
|
693
|
-
loadingLanguages.add(language);
|
|
694
|
-
import(`prismjs/components/prism-${language}`).then(() => {
|
|
695
|
-
loadingLanguages.delete(language);
|
|
696
|
-
onLanguageLoaded(language);
|
|
697
|
-
}).catch(() => {
|
|
698
|
-
loadingLanguages.delete(language);
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
if (!hasPrismThemeLoaded(theme)) loadPrismTheme(theme);
|
|
702
|
-
html = Prism.highlight(block.node.textContent, Prism.languages[language], language);
|
|
703
|
-
} catch {
|
|
704
|
-
html = Prism.highlight(block.node.textContent, Prism.languages.javascript, "js");
|
|
705
|
-
}
|
|
706
|
-
parseNodes(getHighlightNodes(html)).forEach((node) => {
|
|
707
|
-
const to = from + node.text.length;
|
|
708
|
-
if (node.classes.length) {
|
|
709
|
-
const decoration = Decoration.inline(from, to, { class: node.classes.join(" ") });
|
|
710
|
-
decorations.push(decoration);
|
|
711
|
-
}
|
|
712
|
-
from = to;
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
return DecorationSet.create(doc, decorations);
|
|
716
|
-
}
|
|
717
|
-
function PrismPlugin({ name, defaultLanguage, defaultTheme }) {
|
|
718
|
-
if (!defaultLanguage) throw Error("You must specify the defaultLanguage parameter");
|
|
719
|
-
const loadingLanguages = /* @__PURE__ */ new Set();
|
|
720
|
-
let pluginView = null;
|
|
721
|
-
const onLanguageLoaded = (language) => {
|
|
722
|
-
if (pluginView) pluginView.dispatch(pluginView.state.tr.setMeta(PRISM_LANGUAGE_LOADED_META, language));
|
|
723
|
-
};
|
|
724
|
-
const prismjsPlugin = new Plugin({
|
|
725
|
-
key: new PluginKey("prism"),
|
|
726
|
-
view(view) {
|
|
727
|
-
pluginView = view;
|
|
728
|
-
return { destroy() {
|
|
729
|
-
pluginView = null;
|
|
730
|
-
} };
|
|
731
|
-
},
|
|
732
|
-
state: {
|
|
733
|
-
init: (_, { doc }) => {
|
|
734
|
-
return getDecorations({
|
|
735
|
-
doc,
|
|
736
|
-
name,
|
|
737
|
-
defaultLanguage,
|
|
738
|
-
defaultTheme,
|
|
739
|
-
loadingLanguages,
|
|
740
|
-
onLanguageLoaded
|
|
741
|
-
});
|
|
742
|
-
},
|
|
743
|
-
apply: (transaction, decorationSet, oldState, newState) => {
|
|
744
|
-
const oldNodeName = oldState.selection.$head.parent.type.name;
|
|
745
|
-
const newNodeName = newState.selection.$head.parent.type.name;
|
|
746
|
-
const oldNodes = findChildren(oldState.doc, (node) => node.type.name === name);
|
|
747
|
-
const newNodes = findChildren(newState.doc, (node) => node.type.name === name);
|
|
748
|
-
if (transaction.getMeta(PRISM_LANGUAGE_LOADED_META) || transaction.docChanged && ([oldNodeName, newNodeName].includes(name) || newNodes.length !== oldNodes.length || transaction.steps.some((step) => {
|
|
749
|
-
const rangeStep = step;
|
|
750
|
-
return rangeStep.from !== void 0 && rangeStep.to !== void 0 && oldNodes.some((node) => {
|
|
751
|
-
return node.pos >= rangeStep.from && node.pos + node.node.nodeSize <= rangeStep.to;
|
|
752
|
-
});
|
|
753
|
-
}))) return getDecorations({
|
|
754
|
-
doc: transaction.doc,
|
|
755
|
-
name,
|
|
756
|
-
defaultLanguage,
|
|
757
|
-
defaultTheme,
|
|
758
|
-
loadingLanguages,
|
|
759
|
-
onLanguageLoaded
|
|
760
|
-
});
|
|
761
|
-
return decorationSet.map(transaction.mapping, transaction.doc);
|
|
762
|
-
}
|
|
763
|
-
},
|
|
764
|
-
props: { decorations(state) {
|
|
765
|
-
return prismjsPlugin.getState(state);
|
|
766
|
-
} },
|
|
767
|
-
destroy() {
|
|
768
|
-
pluginView = null;
|
|
769
|
-
removePrismTheme();
|
|
78
|
+
//#region src/core/create-paste-handler.ts
|
|
79
|
+
function createPasteHandler({ onPaste, extensions }) {
|
|
80
|
+
return (view, event, slice) => {
|
|
81
|
+
const text = event.clipboardData?.getData("text/plain");
|
|
82
|
+
if (text && onPaste?.(text, view)) {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
return true;
|
|
770
85
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
//#region src/extensions/code-block.tsx
|
|
777
|
-
const CodeBlockPrism = EmailNode.from(CodeBlock$1.extend({
|
|
778
|
-
addOptions() {
|
|
779
|
-
return {
|
|
780
|
-
languageClassPrefix: "language-",
|
|
781
|
-
exitOnTripleEnter: false,
|
|
782
|
-
exitOnArrowDown: false,
|
|
783
|
-
enableTabIndentation: true,
|
|
784
|
-
tabSize: 2,
|
|
785
|
-
defaultLanguage: "javascript",
|
|
786
|
-
defaultTheme: "default",
|
|
787
|
-
HTMLAttributes: {}
|
|
788
|
-
};
|
|
789
|
-
},
|
|
790
|
-
addAttributes() {
|
|
791
|
-
return {
|
|
792
|
-
...this.parent?.(),
|
|
793
|
-
language: {
|
|
794
|
-
default: this.options.defaultLanguage,
|
|
795
|
-
parseHTML: (element) => {
|
|
796
|
-
if (!element) return null;
|
|
797
|
-
const { languageClassPrefix } = this.options;
|
|
798
|
-
if (!languageClassPrefix) return null;
|
|
799
|
-
const language = [...element.firstElementChild?.classList || []].filter((className) => className.startsWith(languageClassPrefix || "")).map((className) => className.replace(languageClassPrefix, ""))[0];
|
|
800
|
-
if (!language) return null;
|
|
801
|
-
return language;
|
|
802
|
-
},
|
|
803
|
-
rendered: false
|
|
804
|
-
},
|
|
805
|
-
theme: {
|
|
806
|
-
default: this.options.defaultTheme,
|
|
807
|
-
rendered: false
|
|
86
|
+
if (event.clipboardData?.files?.[0]) {
|
|
87
|
+
const file = event.clipboardData.files[0];
|
|
88
|
+
if (onPaste?.(file, view)) {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
return true;
|
|
808
91
|
}
|
|
809
|
-
};
|
|
810
|
-
},
|
|
811
|
-
renderHTML({ node, HTMLAttributes }) {
|
|
812
|
-
return [
|
|
813
|
-
"pre",
|
|
814
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { class: node.attrs.language ? `${this.options.languageClassPrefix}${node.attrs.language}` : null }, { "data-theme": node.attrs.theme }),
|
|
815
|
-
[
|
|
816
|
-
"code",
|
|
817
|
-
{ class: node.attrs.language ? `${this.options.languageClassPrefix}${node.attrs.language} node-codeTag` : "node-codeTag" },
|
|
818
|
-
0
|
|
819
|
-
]
|
|
820
|
-
];
|
|
821
|
-
},
|
|
822
|
-
addKeyboardShortcuts() {
|
|
823
|
-
return {
|
|
824
|
-
...this.parent?.(),
|
|
825
|
-
"Mod-a": ({ editor }) => {
|
|
826
|
-
const { state } = editor;
|
|
827
|
-
const { selection } = state;
|
|
828
|
-
const { $from } = selection;
|
|
829
|
-
for (let depth = $from.depth; depth >= 1; depth--) if ($from.node(depth).type.name === this.name) {
|
|
830
|
-
const blockStart = $from.start(depth);
|
|
831
|
-
const blockEnd = $from.end(depth);
|
|
832
|
-
if (selection.from === blockStart && selection.to === blockEnd) return false;
|
|
833
|
-
const tr = state.tr.setSelection(TextSelection.create(state.doc, blockStart, blockEnd));
|
|
834
|
-
editor.view.dispatch(tr);
|
|
835
|
-
return true;
|
|
836
|
-
}
|
|
837
|
-
return false;
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
},
|
|
841
|
-
addProseMirrorPlugins() {
|
|
842
|
-
return [...this.parent?.() || [], PrismPlugin({
|
|
843
|
-
name: this.name,
|
|
844
|
-
defaultLanguage: this.options.defaultLanguage,
|
|
845
|
-
defaultTheme: this.options.defaultTheme
|
|
846
|
-
})];
|
|
847
|
-
}
|
|
848
|
-
}), ({ node, style }) => {
|
|
849
|
-
const language = node.attrs?.language ? `${node.attrs.language}` : "javascript";
|
|
850
|
-
const userTheme = ReactEmailComponents[node.attrs?.theme];
|
|
851
|
-
const theme = userTheme ? {
|
|
852
|
-
...userTheme,
|
|
853
|
-
base: {
|
|
854
|
-
...userTheme.base,
|
|
855
|
-
borderRadius: "0.125rem",
|
|
856
|
-
padding: "0.75rem 1rem"
|
|
857
92
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
return /* @__PURE__ */ jsx(CodeBlock, {
|
|
867
|
-
code: node.content?.[0]?.text ?? "",
|
|
868
|
-
language,
|
|
869
|
-
theme,
|
|
870
|
-
style: {
|
|
871
|
-
width: "auto",
|
|
872
|
-
...style
|
|
93
|
+
if (slice.content.childCount === 1) return false;
|
|
94
|
+
if (event.clipboardData?.getData?.("text/html")) {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
const jsonContent = generateJSON(sanitizePastedHtml(event.clipboardData.getData("text/html")), extensions);
|
|
97
|
+
const node = view.state.schema.nodeFromJSON(jsonContent);
|
|
98
|
+
const transaction = view.state.tr.replaceSelectionWith(node, false);
|
|
99
|
+
view.dispatch(transaction);
|
|
100
|
+
return true;
|
|
873
101
|
}
|
|
874
|
-
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
//#endregion
|
|
878
|
-
//#region src/extensions/div.tsx
|
|
879
|
-
const Div = EmailNode.create({
|
|
880
|
-
name: "div",
|
|
881
|
-
group: "block",
|
|
882
|
-
content: "block+",
|
|
883
|
-
defining: true,
|
|
884
|
-
isolating: true,
|
|
885
|
-
parseHTML() {
|
|
886
|
-
return [{
|
|
887
|
-
tag: "div:not([data-type])",
|
|
888
|
-
getAttrs: (node) => {
|
|
889
|
-
if (typeof node === "string") return false;
|
|
890
|
-
const element = node;
|
|
891
|
-
const attrs = {};
|
|
892
|
-
Array.from(element.attributes).forEach((attr) => {
|
|
893
|
-
attrs[attr.name] = attr.value;
|
|
894
|
-
});
|
|
895
|
-
return attrs;
|
|
896
|
-
}
|
|
897
|
-
}];
|
|
898
|
-
},
|
|
899
|
-
renderHTML({ HTMLAttributes }) {
|
|
900
|
-
return [
|
|
901
|
-
"div",
|
|
902
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
903
|
-
0
|
|
904
|
-
];
|
|
905
|
-
},
|
|
906
|
-
addAttributes() {
|
|
907
|
-
return { ...createStandardAttributes([...COMMON_HTML_ATTRIBUTES, ...LAYOUT_ATTRIBUTES]) };
|
|
908
|
-
},
|
|
909
|
-
renderToReactEmail({ children, node, style }) {
|
|
910
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
911
|
-
return /* @__PURE__ */ jsx("div", {
|
|
912
|
-
className: node.attrs?.class || void 0,
|
|
913
|
-
style: {
|
|
914
|
-
...style,
|
|
915
|
-
...inlineStyles
|
|
916
|
-
},
|
|
917
|
-
children
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
});
|
|
921
|
-
|
|
922
|
-
//#endregion
|
|
923
|
-
//#region src/extensions/max-nesting.ts
|
|
924
|
-
const MaxNesting = Extension.create({
|
|
925
|
-
name: "maxNesting",
|
|
926
|
-
addOptions() {
|
|
927
|
-
return {
|
|
928
|
-
maxDepth: 3,
|
|
929
|
-
nodeTypes: void 0
|
|
930
|
-
};
|
|
931
|
-
},
|
|
932
|
-
addProseMirrorPlugins() {
|
|
933
|
-
const { maxDepth, nodeTypes } = this.options;
|
|
934
|
-
if (typeof maxDepth !== "number" || maxDepth < 1) throw new Error("maxDepth must be a positive number");
|
|
935
|
-
return [new Plugin({
|
|
936
|
-
key: new PluginKey("maxNesting"),
|
|
937
|
-
appendTransaction(transactions, _oldState, newState) {
|
|
938
|
-
if (!transactions.some((tr$1) => tr$1.docChanged)) return null;
|
|
939
|
-
const rangesToLift = [];
|
|
940
|
-
newState.doc.descendants((node, pos) => {
|
|
941
|
-
let depth = 0;
|
|
942
|
-
let currentPos = pos;
|
|
943
|
-
let currentNode = node;
|
|
944
|
-
while (currentNode && depth <= maxDepth) {
|
|
945
|
-
if (!nodeTypes || nodeTypes.includes(currentNode.type.name)) depth++;
|
|
946
|
-
const $pos = newState.doc.resolve(currentPos);
|
|
947
|
-
if ($pos.depth === 0) break;
|
|
948
|
-
currentPos = $pos.before($pos.depth);
|
|
949
|
-
currentNode = newState.doc.nodeAt(currentPos);
|
|
950
|
-
}
|
|
951
|
-
if (depth > maxDepth) {
|
|
952
|
-
const $pos = newState.doc.resolve(pos);
|
|
953
|
-
if ($pos.depth > 0) {
|
|
954
|
-
const range = $pos.blockRange();
|
|
955
|
-
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({
|
|
956
|
-
range,
|
|
957
|
-
target: range.start - 1
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
});
|
|
962
|
-
if (rangesToLift.length === 0) return null;
|
|
963
|
-
const tr = newState.tr;
|
|
964
|
-
for (let i = rangesToLift.length - 1; i >= 0; i--) {
|
|
965
|
-
const { range, target } = rangesToLift[i];
|
|
966
|
-
tr.lift(range, target);
|
|
967
|
-
}
|
|
968
|
-
return tr;
|
|
969
|
-
},
|
|
970
|
-
filterTransaction(tr) {
|
|
971
|
-
if (!tr.docChanged) return true;
|
|
972
|
-
let wouldCreateDeepNesting = false;
|
|
973
|
-
const newDoc = tr.doc;
|
|
974
|
-
newDoc.descendants((node, pos) => {
|
|
975
|
-
if (wouldCreateDeepNesting) return false;
|
|
976
|
-
let depth = 0;
|
|
977
|
-
let currentPos = pos;
|
|
978
|
-
let currentNode = node;
|
|
979
|
-
while (currentNode && depth <= maxDepth) {
|
|
980
|
-
if (!nodeTypes || nodeTypes.includes(currentNode.type.name)) depth++;
|
|
981
|
-
const $pos = newDoc.resolve(currentPos);
|
|
982
|
-
if ($pos.depth === 0) break;
|
|
983
|
-
currentPos = $pos.before($pos.depth);
|
|
984
|
-
currentNode = newDoc.nodeAt(currentPos);
|
|
985
|
-
}
|
|
986
|
-
if (depth > maxDepth) {
|
|
987
|
-
wouldCreateDeepNesting = true;
|
|
988
|
-
return false;
|
|
989
|
-
}
|
|
990
|
-
});
|
|
991
|
-
return !wouldCreateDeepNesting;
|
|
992
|
-
}
|
|
993
|
-
})];
|
|
994
|
-
}
|
|
995
|
-
});
|
|
996
|
-
|
|
997
|
-
//#endregion
|
|
998
|
-
//#region src/extensions/placeholder.ts
|
|
999
|
-
const Placeholder = TipTapPlaceholder.configure({
|
|
1000
|
-
placeholder: ({ node }) => {
|
|
1001
|
-
if (node.type.name === "heading") return `Heading ${node.attrs.level}`;
|
|
1002
|
-
return "Press '/' for commands";
|
|
1003
|
-
},
|
|
1004
|
-
includeChildren: true
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
//#endregion
|
|
1008
|
-
//#region src/extensions/preserved-style.ts
|
|
1009
|
-
const PreservedStyle = Mark.create({
|
|
1010
|
-
name: "preservedStyle",
|
|
1011
|
-
addAttributes() {
|
|
1012
|
-
return { style: {
|
|
1013
|
-
default: null,
|
|
1014
|
-
parseHTML: (element) => element.getAttribute("style"),
|
|
1015
|
-
renderHTML: (attributes) => {
|
|
1016
|
-
if (!attributes.style) return {};
|
|
1017
|
-
return { style: attributes.style };
|
|
1018
|
-
}
|
|
1019
|
-
} };
|
|
1020
|
-
},
|
|
1021
|
-
parseHTML() {
|
|
1022
|
-
return [{
|
|
1023
|
-
tag: "span[style]",
|
|
1024
|
-
getAttrs: (element) => {
|
|
1025
|
-
if (typeof element === "string") return false;
|
|
1026
|
-
const style = element.getAttribute("style");
|
|
1027
|
-
if (style && hasPreservableStyles(style)) return { style };
|
|
1028
|
-
return false;
|
|
1029
|
-
}
|
|
1030
|
-
}];
|
|
1031
|
-
},
|
|
1032
|
-
renderHTML({ HTMLAttributes }) {
|
|
1033
|
-
return [
|
|
1034
|
-
"span",
|
|
1035
|
-
mergeAttributes(HTMLAttributes),
|
|
1036
|
-
0
|
|
1037
|
-
];
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
const LINK_INDICATOR_STYLES = [
|
|
1041
|
-
"color",
|
|
1042
|
-
"text-decoration",
|
|
1043
|
-
"text-decoration-line",
|
|
1044
|
-
"text-decoration-color",
|
|
1045
|
-
"text-decoration-style"
|
|
1046
|
-
];
|
|
1047
|
-
function parseStyleString(styleString) {
|
|
1048
|
-
const temp = document.createElement("div");
|
|
1049
|
-
temp.style.cssText = styleString;
|
|
1050
|
-
return temp.style;
|
|
1051
|
-
}
|
|
1052
|
-
function hasBackground(style) {
|
|
1053
|
-
const bgColor = style.backgroundColor;
|
|
1054
|
-
const bg = style.background;
|
|
1055
|
-
if (bgColor && bgColor !== "transparent" && bgColor !== "rgba(0, 0, 0, 0)") return true;
|
|
1056
|
-
if (bg && bg !== "transparent" && bg !== "none" && bg !== "rgba(0, 0, 0, 0)") return true;
|
|
1057
|
-
return false;
|
|
1058
|
-
}
|
|
1059
|
-
function hasPreservableStyles(styleString) {
|
|
1060
|
-
return processStylesForUnlink(styleString) !== null;
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Processes styles when unlinking:
|
|
1064
|
-
* - Has background (button-like): preserve all styles
|
|
1065
|
-
* - No background: strip link-indicator styles (color, text-decoration), keep the rest
|
|
1066
|
-
*/
|
|
1067
|
-
function processStylesForUnlink(styleString) {
|
|
1068
|
-
if (!styleString) return null;
|
|
1069
|
-
const style = parseStyleString(styleString);
|
|
1070
|
-
if (hasBackground(style)) return styleString;
|
|
1071
|
-
const filtered = [];
|
|
1072
|
-
for (let i = 0; i < style.length; i++) {
|
|
1073
|
-
const prop = style[i];
|
|
1074
|
-
if (LINK_INDICATOR_STYLES.includes(prop)) continue;
|
|
1075
|
-
const value = style.getPropertyValue(prop);
|
|
1076
|
-
if (value) filtered.push(`${prop}: ${value}`);
|
|
1077
|
-
}
|
|
1078
|
-
return filtered.length > 0 ? filtered.join("; ") : null;
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
//#endregion
|
|
1082
|
-
//#region src/extensions/preview-text.ts
|
|
1083
|
-
const PreviewText = Node.create({
|
|
1084
|
-
name: "previewText",
|
|
1085
|
-
group: "block",
|
|
1086
|
-
selectable: false,
|
|
1087
|
-
draggable: false,
|
|
1088
|
-
atom: true,
|
|
1089
|
-
addOptions() {
|
|
1090
|
-
return { HTMLAttributes: {} };
|
|
1091
|
-
},
|
|
1092
|
-
addStorage() {
|
|
1093
|
-
return { previewText: null };
|
|
1094
|
-
},
|
|
1095
|
-
renderHTML() {
|
|
1096
|
-
return ["div", { style: "display: none" }];
|
|
1097
|
-
},
|
|
1098
|
-
parseHTML() {
|
|
1099
|
-
return [{
|
|
1100
|
-
tag: "div[data-skip-in-text=\"true\"]",
|
|
1101
|
-
getAttrs: (node) => {
|
|
1102
|
-
if (typeof node === "string") return false;
|
|
1103
|
-
const element = node;
|
|
1104
|
-
let directText = "";
|
|
1105
|
-
for (const child of element.childNodes) if (child.nodeType === 3) directText += child.textContent || "";
|
|
1106
|
-
const cleanText = directText.trim();
|
|
1107
|
-
if (cleanText) this.storage.previewText = cleanText;
|
|
1108
|
-
return false;
|
|
1109
|
-
}
|
|
1110
|
-
}, {
|
|
1111
|
-
tag: "span.preheader",
|
|
1112
|
-
getAttrs: (node) => {
|
|
1113
|
-
if (typeof node === "string") return false;
|
|
1114
|
-
const preheaderText = node.textContent?.trim();
|
|
1115
|
-
if (preheaderText) this.storage.previewText = preheaderText;
|
|
1116
|
-
return false;
|
|
1117
|
-
}
|
|
1118
|
-
}];
|
|
1119
|
-
}
|
|
1120
|
-
});
|
|
1121
|
-
|
|
1122
|
-
//#endregion
|
|
1123
|
-
//#region src/utils/get-text-alignment.ts
|
|
1124
|
-
function getTextAlignment(alignment) {
|
|
1125
|
-
switch (alignment) {
|
|
1126
|
-
case "left": return { textAlign: "left" };
|
|
1127
|
-
case "center": return { textAlign: "center" };
|
|
1128
|
-
case "right": return { textAlign: "right" };
|
|
1129
|
-
default: return {};
|
|
1130
|
-
}
|
|
102
|
+
return false;
|
|
103
|
+
};
|
|
1131
104
|
}
|
|
1132
|
-
|
|
1133
105
|
//#endregion
|
|
1134
|
-
//#region src/
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
},
|
|
1144
|
-
renderHTML({ HTMLAttributes }) {
|
|
1145
|
-
return [
|
|
1146
|
-
"section",
|
|
1147
|
-
mergeAttributes({
|
|
1148
|
-
"data-type": "section",
|
|
1149
|
-
class: "node-section"
|
|
1150
|
-
}, HTMLAttributes),
|
|
1151
|
-
0
|
|
1152
|
-
];
|
|
1153
|
-
},
|
|
1154
|
-
addCommands() {
|
|
1155
|
-
return { insertSection: () => ({ commands }) => {
|
|
1156
|
-
return commands.insertContent({
|
|
1157
|
-
type: this.name,
|
|
1158
|
-
content: [{
|
|
1159
|
-
type: "paragraph",
|
|
1160
|
-
content: []
|
|
1161
|
-
}]
|
|
1162
|
-
});
|
|
1163
|
-
} };
|
|
1164
|
-
},
|
|
1165
|
-
renderToReactEmail({ children, node, style }) {
|
|
1166
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
1167
|
-
const textAlign = node.attrs?.align || node.attrs?.alignment;
|
|
1168
|
-
return /* @__PURE__ */ jsx(Section$1, {
|
|
1169
|
-
className: node.attrs?.class || void 0,
|
|
1170
|
-
align: textAlign,
|
|
1171
|
-
style: {
|
|
1172
|
-
...style,
|
|
1173
|
-
...inlineStyles,
|
|
1174
|
-
...getTextAlignment(textAlign)
|
|
1175
|
-
},
|
|
1176
|
-
children
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
|
-
|
|
1181
|
-
//#endregion
|
|
1182
|
-
//#region src/extensions/style-attribute.tsx
|
|
1183
|
-
const StyleAttribute = Extension.create({
|
|
1184
|
-
name: "styleAttribute",
|
|
1185
|
-
priority: 101,
|
|
1186
|
-
addOptions() {
|
|
1187
|
-
return {
|
|
1188
|
-
types: [],
|
|
1189
|
-
style: []
|
|
1190
|
-
};
|
|
1191
|
-
},
|
|
1192
|
-
addGlobalAttributes() {
|
|
1193
|
-
return [{
|
|
1194
|
-
types: this.options.types,
|
|
1195
|
-
attributes: { style: {
|
|
1196
|
-
default: "",
|
|
1197
|
-
parseHTML: (element) => element.getAttribute("style") || "",
|
|
1198
|
-
renderHTML: (attributes) => {
|
|
1199
|
-
return { style: attributes.style ?? "" };
|
|
1200
|
-
}
|
|
1201
|
-
} }
|
|
1202
|
-
}];
|
|
1203
|
-
},
|
|
1204
|
-
addCommands() {
|
|
1205
|
-
return {
|
|
1206
|
-
unsetStyle: () => ({ commands }) => {
|
|
1207
|
-
return this.options.types.every((type) => commands.resetAttributes(type, "style"));
|
|
1208
|
-
},
|
|
1209
|
-
setStyle: (style) => ({ commands }) => {
|
|
1210
|
-
return this.options.types.every((type) => commands.updateAttributes(type, { style }));
|
|
1211
|
-
}
|
|
1212
|
-
};
|
|
1213
|
-
},
|
|
1214
|
-
addKeyboardShortcuts() {
|
|
1215
|
-
return { Enter: ({ editor }) => {
|
|
1216
|
-
const { state } = editor.view;
|
|
1217
|
-
const { selection } = state;
|
|
1218
|
-
const { $from } = selection;
|
|
1219
|
-
const textBefore = $from.nodeBefore?.text || "";
|
|
1220
|
-
if (textBefore.includes("{{") || textBefore.includes("{{{")) return false;
|
|
1221
|
-
requestAnimationFrame(() => {
|
|
1222
|
-
editor.commands.resetAttributes("paragraph", "style");
|
|
1223
|
-
});
|
|
1224
|
-
return false;
|
|
1225
|
-
} };
|
|
1226
|
-
}
|
|
1227
|
-
});
|
|
1228
|
-
|
|
1229
|
-
//#endregion
|
|
1230
|
-
//#region src/extensions/sup.ts
|
|
1231
|
-
/**
|
|
1232
|
-
* This extension allows you to mark text as superscript.
|
|
1233
|
-
* @see https://tiptap.dev/api/marks/superscript
|
|
1234
|
-
*/
|
|
1235
|
-
const Sup = Mark.create({
|
|
1236
|
-
name: "sup",
|
|
1237
|
-
addOptions() {
|
|
1238
|
-
return { HTMLAttributes: {} };
|
|
1239
|
-
},
|
|
1240
|
-
parseHTML() {
|
|
1241
|
-
return [{ tag: "sup" }];
|
|
1242
|
-
},
|
|
1243
|
-
renderHTML({ HTMLAttributes }) {
|
|
1244
|
-
return [
|
|
1245
|
-
"sup",
|
|
1246
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
1247
|
-
0
|
|
1248
|
-
];
|
|
1249
|
-
},
|
|
1250
|
-
addCommands() {
|
|
1251
|
-
return {
|
|
1252
|
-
setSup: () => ({ commands }) => {
|
|
1253
|
-
return commands.setMark(this.name);
|
|
1254
|
-
},
|
|
1255
|
-
toggleSup: () => ({ commands }) => {
|
|
1256
|
-
return commands.toggleMark(this.name);
|
|
1257
|
-
},
|
|
1258
|
-
unsetSup: () => ({ commands }) => {
|
|
1259
|
-
return commands.unsetMark(this.name);
|
|
1260
|
-
}
|
|
1261
|
-
};
|
|
1262
|
-
}
|
|
1263
|
-
});
|
|
1264
|
-
|
|
1265
|
-
//#endregion
|
|
1266
|
-
//#region src/extensions/table.tsx
|
|
1267
|
-
const Table = EmailNode.create({
|
|
1268
|
-
name: "table",
|
|
1269
|
-
group: "block",
|
|
1270
|
-
content: "tableRow+",
|
|
1271
|
-
isolating: true,
|
|
1272
|
-
tableRole: "table",
|
|
1273
|
-
addAttributes() {
|
|
1274
|
-
return { ...createStandardAttributes([
|
|
1275
|
-
...TABLE_ATTRIBUTES,
|
|
1276
|
-
...LAYOUT_ATTRIBUTES,
|
|
1277
|
-
...COMMON_HTML_ATTRIBUTES
|
|
1278
|
-
]) };
|
|
1279
|
-
},
|
|
1280
|
-
parseHTML() {
|
|
1281
|
-
return [{
|
|
1282
|
-
tag: "table",
|
|
1283
|
-
getAttrs: (node) => {
|
|
1284
|
-
if (typeof node === "string") return false;
|
|
1285
|
-
const element = node;
|
|
1286
|
-
const attrs = {};
|
|
1287
|
-
Array.from(element.attributes).forEach((attr) => {
|
|
1288
|
-
attrs[attr.name] = attr.value;
|
|
1289
|
-
});
|
|
1290
|
-
return attrs;
|
|
1291
|
-
}
|
|
1292
|
-
}];
|
|
1293
|
-
},
|
|
1294
|
-
renderHTML({ HTMLAttributes }) {
|
|
1295
|
-
return [
|
|
1296
|
-
"table",
|
|
1297
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
1298
|
-
[
|
|
1299
|
-
"tbody",
|
|
1300
|
-
{},
|
|
1301
|
-
0
|
|
1302
|
-
]
|
|
1303
|
-
];
|
|
1304
|
-
},
|
|
1305
|
-
renderToReactEmail({ children, node, style }) {
|
|
1306
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
1307
|
-
const alignment = node.attrs?.align || node.attrs?.alignment;
|
|
1308
|
-
const width = node.attrs?.width;
|
|
1309
|
-
const centeringStyles = alignment === "center" ? {
|
|
1310
|
-
marginLeft: "auto",
|
|
1311
|
-
marginRight: "auto"
|
|
1312
|
-
} : {};
|
|
1313
|
-
return /* @__PURE__ */ jsx(Section$1, {
|
|
1314
|
-
className: node.attrs?.class || void 0,
|
|
1315
|
-
align: alignment,
|
|
1316
|
-
style: resolveConflictingStyles(style, {
|
|
1317
|
-
...inlineStyles,
|
|
1318
|
-
...centeringStyles
|
|
1319
|
-
}),
|
|
1320
|
-
...width !== void 0 ? { width } : {},
|
|
1321
|
-
children
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
});
|
|
1325
|
-
const TableRow = EmailNode.create({
|
|
1326
|
-
name: "tableRow",
|
|
1327
|
-
group: "tableRow",
|
|
1328
|
-
content: "(tableCell | tableHeader)+",
|
|
1329
|
-
addAttributes() {
|
|
1330
|
-
return { ...createStandardAttributes([
|
|
1331
|
-
...TABLE_CELL_ATTRIBUTES,
|
|
1332
|
-
...LAYOUT_ATTRIBUTES,
|
|
1333
|
-
...COMMON_HTML_ATTRIBUTES
|
|
1334
|
-
]) };
|
|
1335
|
-
},
|
|
1336
|
-
parseHTML() {
|
|
1337
|
-
return [{
|
|
1338
|
-
tag: "tr",
|
|
1339
|
-
getAttrs: (node) => {
|
|
1340
|
-
if (typeof node === "string") return false;
|
|
1341
|
-
const element = node;
|
|
1342
|
-
const attrs = {};
|
|
1343
|
-
Array.from(element.attributes).forEach((attr) => {
|
|
1344
|
-
attrs[attr.name] = attr.value;
|
|
1345
|
-
});
|
|
1346
|
-
return attrs;
|
|
1347
|
-
}
|
|
1348
|
-
}];
|
|
1349
|
-
},
|
|
1350
|
-
renderHTML({ HTMLAttributes }) {
|
|
1351
|
-
return [
|
|
1352
|
-
"tr",
|
|
1353
|
-
HTMLAttributes,
|
|
1354
|
-
0
|
|
1355
|
-
];
|
|
1356
|
-
},
|
|
1357
|
-
renderToReactEmail({ children, node, style }) {
|
|
1358
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
1359
|
-
return /* @__PURE__ */ jsx("tr", {
|
|
1360
|
-
className: node.attrs?.class || void 0,
|
|
1361
|
-
style: {
|
|
1362
|
-
...style,
|
|
1363
|
-
...inlineStyles
|
|
1364
|
-
},
|
|
1365
|
-
children
|
|
1366
|
-
});
|
|
1367
|
-
}
|
|
1368
|
-
});
|
|
1369
|
-
const TableCell = EmailNode.create({
|
|
1370
|
-
name: "tableCell",
|
|
1371
|
-
group: "tableCell",
|
|
1372
|
-
content: "block+",
|
|
1373
|
-
isolating: true,
|
|
1374
|
-
addAttributes() {
|
|
1375
|
-
return { ...createStandardAttributes([
|
|
1376
|
-
...TABLE_CELL_ATTRIBUTES,
|
|
1377
|
-
...LAYOUT_ATTRIBUTES,
|
|
1378
|
-
...COMMON_HTML_ATTRIBUTES
|
|
1379
|
-
]) };
|
|
1380
|
-
},
|
|
1381
|
-
parseHTML() {
|
|
1382
|
-
return [{
|
|
1383
|
-
tag: "td",
|
|
1384
|
-
getAttrs: (node) => {
|
|
1385
|
-
if (typeof node === "string") return false;
|
|
1386
|
-
const element = node;
|
|
1387
|
-
const attrs = {};
|
|
1388
|
-
Array.from(element.attributes).forEach((attr) => {
|
|
1389
|
-
attrs[attr.name] = attr.value;
|
|
1390
|
-
});
|
|
1391
|
-
return attrs;
|
|
1392
|
-
}
|
|
1393
|
-
}];
|
|
1394
|
-
},
|
|
1395
|
-
renderHTML({ HTMLAttributes }) {
|
|
1396
|
-
return [
|
|
1397
|
-
"td",
|
|
1398
|
-
HTMLAttributes,
|
|
1399
|
-
0
|
|
1400
|
-
];
|
|
1401
|
-
},
|
|
1402
|
-
renderToReactEmail({ children, node, style }) {
|
|
1403
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
1404
|
-
return /* @__PURE__ */ jsx(Column, {
|
|
1405
|
-
className: node.attrs?.class || void 0,
|
|
1406
|
-
align: node.attrs?.align || node.attrs?.alignment,
|
|
1407
|
-
style: {
|
|
1408
|
-
...style,
|
|
1409
|
-
...inlineStyles
|
|
1410
|
-
},
|
|
1411
|
-
children
|
|
1412
|
-
});
|
|
1413
|
-
}
|
|
1414
|
-
});
|
|
1415
|
-
const TableHeader = Node.create({
|
|
1416
|
-
name: "tableHeader",
|
|
1417
|
-
group: "tableCell",
|
|
1418
|
-
content: "block+",
|
|
1419
|
-
isolating: true,
|
|
1420
|
-
addAttributes() {
|
|
1421
|
-
return { ...createStandardAttributes([
|
|
1422
|
-
...TABLE_HEADER_ATTRIBUTES,
|
|
1423
|
-
...TABLE_CELL_ATTRIBUTES,
|
|
1424
|
-
...LAYOUT_ATTRIBUTES,
|
|
1425
|
-
...COMMON_HTML_ATTRIBUTES
|
|
1426
|
-
]) };
|
|
1427
|
-
},
|
|
1428
|
-
parseHTML() {
|
|
1429
|
-
return [{
|
|
1430
|
-
tag: "th",
|
|
1431
|
-
getAttrs: (node) => {
|
|
1432
|
-
if (typeof node === "string") return false;
|
|
1433
|
-
const element = node;
|
|
1434
|
-
const attrs = {};
|
|
1435
|
-
Array.from(element.attributes).forEach((attr) => {
|
|
1436
|
-
attrs[attr.name] = attr.value;
|
|
1437
|
-
});
|
|
1438
|
-
return attrs;
|
|
1439
|
-
}
|
|
1440
|
-
}];
|
|
1441
|
-
},
|
|
1442
|
-
renderHTML({ HTMLAttributes }) {
|
|
1443
|
-
return [
|
|
1444
|
-
"th",
|
|
1445
|
-
HTMLAttributes,
|
|
1446
|
-
0
|
|
1447
|
-
];
|
|
1448
|
-
}
|
|
1449
|
-
});
|
|
1450
|
-
|
|
1451
|
-
//#endregion
|
|
1452
|
-
//#region src/extensions/uppercase.ts
|
|
1453
|
-
const Uppercase = Mark.create({
|
|
1454
|
-
name: "uppercase",
|
|
1455
|
-
addOptions() {
|
|
1456
|
-
return { HTMLAttributes: {} };
|
|
1457
|
-
},
|
|
1458
|
-
parseHTML() {
|
|
1459
|
-
return [{
|
|
1460
|
-
tag: "span",
|
|
1461
|
-
getAttrs: (node) => {
|
|
1462
|
-
if (node.style.textTransform === "uppercase") return {};
|
|
1463
|
-
return false;
|
|
1464
|
-
}
|
|
1465
|
-
}];
|
|
1466
|
-
},
|
|
1467
|
-
renderHTML({ HTMLAttributes }) {
|
|
1468
|
-
return [
|
|
1469
|
-
"span",
|
|
1470
|
-
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { style: "text-transform: uppercase" }),
|
|
1471
|
-
0
|
|
1472
|
-
];
|
|
1473
|
-
},
|
|
1474
|
-
addCommands() {
|
|
1475
|
-
return {
|
|
1476
|
-
setUppercase: () => ({ commands }) => {
|
|
1477
|
-
return commands.setMark(this.name);
|
|
1478
|
-
},
|
|
1479
|
-
toggleUppercase: () => ({ commands }) => {
|
|
1480
|
-
return commands.toggleMark(this.name);
|
|
1481
|
-
},
|
|
1482
|
-
unsetUppercase: () => ({ commands }) => {
|
|
1483
|
-
return commands.unsetMark(this.name);
|
|
1484
|
-
}
|
|
1485
|
-
};
|
|
1486
|
-
}
|
|
1487
|
-
});
|
|
1488
|
-
|
|
1489
|
-
//#endregion
|
|
1490
|
-
//#region src/extensions/columns.tsx
|
|
1491
|
-
const COLUMN_PARENT_TYPES = [
|
|
1492
|
-
"twoColumns",
|
|
1493
|
-
"threeColumns",
|
|
1494
|
-
"fourColumns"
|
|
1495
|
-
];
|
|
1496
|
-
const COLUMN_PARENT_SET = new Set(COLUMN_PARENT_TYPES);
|
|
1497
|
-
const MAX_COLUMNS_DEPTH = 3;
|
|
1498
|
-
function getColumnsDepth(doc, from) {
|
|
1499
|
-
const $from = doc.resolve(from);
|
|
1500
|
-
let depth = 0;
|
|
1501
|
-
for (let d = $from.depth; d > 0; d--) if (COLUMN_PARENT_SET.has($from.node(d).type.name)) depth++;
|
|
1502
|
-
return depth;
|
|
1503
|
-
}
|
|
1504
|
-
const VARIANTS = [
|
|
1505
|
-
{
|
|
1506
|
-
name: "twoColumns",
|
|
1507
|
-
columnCount: 2,
|
|
1508
|
-
content: "columnsColumn columnsColumn",
|
|
1509
|
-
dataType: "two-columns"
|
|
1510
|
-
},
|
|
1511
|
-
{
|
|
1512
|
-
name: "threeColumns",
|
|
1513
|
-
columnCount: 3,
|
|
1514
|
-
content: "columnsColumn columnsColumn columnsColumn",
|
|
1515
|
-
dataType: "three-columns"
|
|
1516
|
-
},
|
|
1517
|
-
{
|
|
1518
|
-
name: "fourColumns",
|
|
1519
|
-
columnCount: 4,
|
|
1520
|
-
content: "columnsColumn{4}",
|
|
1521
|
-
dataType: "four-columns"
|
|
1522
|
-
}
|
|
1523
|
-
];
|
|
1524
|
-
const NODE_TYPE_MAP = {
|
|
1525
|
-
2: "twoColumns",
|
|
1526
|
-
3: "threeColumns",
|
|
1527
|
-
4: "fourColumns"
|
|
1528
|
-
};
|
|
1529
|
-
function createColumnsNode(config, includeCommands) {
|
|
1530
|
-
return EmailNode.create({
|
|
1531
|
-
name: config.name,
|
|
1532
|
-
group: "block",
|
|
1533
|
-
content: config.content,
|
|
1534
|
-
isolating: true,
|
|
1535
|
-
defining: true,
|
|
1536
|
-
addAttributes() {
|
|
1537
|
-
return createStandardAttributes([...LAYOUT_ATTRIBUTES, ...COMMON_HTML_ATTRIBUTES]);
|
|
106
|
+
//#region src/email-editor/email-editor.tsx
|
|
107
|
+
function buildRef(editor) {
|
|
108
|
+
return {
|
|
109
|
+
getEmail: async () => {
|
|
110
|
+
if (!editor) return {
|
|
111
|
+
html: "",
|
|
112
|
+
text: ""
|
|
113
|
+
};
|
|
114
|
+
return composeReactEmail({ editor });
|
|
1538
115
|
},
|
|
1539
|
-
|
|
1540
|
-
|
|
116
|
+
getEmailHTML: async () => {
|
|
117
|
+
if (!editor) return "";
|
|
118
|
+
return (await composeReactEmail({ editor })).html;
|
|
1541
119
|
},
|
|
1542
|
-
|
|
1543
|
-
return
|
|
1544
|
-
|
|
1545
|
-
mergeAttributes({
|
|
1546
|
-
"data-type": config.dataType,
|
|
1547
|
-
class: "node-columns"
|
|
1548
|
-
}, HTMLAttributes),
|
|
1549
|
-
0
|
|
1550
|
-
];
|
|
120
|
+
getEmailText: async () => {
|
|
121
|
+
if (!editor) return "";
|
|
122
|
+
return (await composeReactEmail({ editor })).text;
|
|
1551
123
|
},
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
type: "columnsColumn",
|
|
1558
|
-
content: [{
|
|
1559
|
-
type: "paragraph",
|
|
1560
|
-
content: []
|
|
1561
|
-
}]
|
|
1562
|
-
}));
|
|
1563
|
-
return commands.insertContent({
|
|
1564
|
-
type: nodeType,
|
|
1565
|
-
content: children
|
|
1566
|
-
});
|
|
1567
|
-
} };
|
|
1568
|
-
} },
|
|
1569
|
-
renderToReactEmail({ children, node, style }) {
|
|
1570
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
1571
|
-
return /* @__PURE__ */ jsx(Row, {
|
|
1572
|
-
className: node.attrs?.class || void 0,
|
|
1573
|
-
style: {
|
|
1574
|
-
...style,
|
|
1575
|
-
...inlineStyles
|
|
1576
|
-
},
|
|
1577
|
-
children
|
|
1578
|
-
});
|
|
1579
|
-
}
|
|
1580
|
-
});
|
|
1581
|
-
}
|
|
1582
|
-
const TwoColumns = createColumnsNode(VARIANTS[0], true);
|
|
1583
|
-
const ThreeColumns = createColumnsNode(VARIANTS[1], false);
|
|
1584
|
-
const FourColumns = createColumnsNode(VARIANTS[2], false);
|
|
1585
|
-
const ColumnsColumn = EmailNode.create({
|
|
1586
|
-
name: "columnsColumn",
|
|
1587
|
-
group: "columnsColumn",
|
|
1588
|
-
content: "block+",
|
|
1589
|
-
isolating: true,
|
|
1590
|
-
addAttributes() {
|
|
1591
|
-
return { ...createStandardAttributes([...LAYOUT_ATTRIBUTES, ...COMMON_HTML_ATTRIBUTES]) };
|
|
1592
|
-
},
|
|
1593
|
-
parseHTML() {
|
|
1594
|
-
return [{ tag: "div[data-type=\"column\"]" }];
|
|
1595
|
-
},
|
|
1596
|
-
renderHTML({ HTMLAttributes }) {
|
|
1597
|
-
return [
|
|
1598
|
-
"div",
|
|
1599
|
-
mergeAttributes({
|
|
1600
|
-
"data-type": "column",
|
|
1601
|
-
class: "node-column"
|
|
1602
|
-
}, HTMLAttributes),
|
|
1603
|
-
0
|
|
1604
|
-
];
|
|
1605
|
-
},
|
|
1606
|
-
addKeyboardShortcuts() {
|
|
1607
|
-
return {
|
|
1608
|
-
Backspace: ({ editor }) => {
|
|
1609
|
-
const { state } = editor;
|
|
1610
|
-
const { selection } = state;
|
|
1611
|
-
const { empty, $from } = selection;
|
|
1612
|
-
if (!empty) return false;
|
|
1613
|
-
for (let depth = $from.depth; depth >= 1; depth--) {
|
|
1614
|
-
if ($from.pos !== $from.start(depth)) break;
|
|
1615
|
-
const indexInParent = $from.index(depth - 1);
|
|
1616
|
-
if (indexInParent === 0) continue;
|
|
1617
|
-
const prevNode = $from.node(depth - 1).child(indexInParent - 1);
|
|
1618
|
-
if (COLUMN_PARENT_SET.has(prevNode.type.name)) {
|
|
1619
|
-
const deleteFrom = $from.before(depth) - prevNode.nodeSize;
|
|
1620
|
-
const deleteTo = $from.before(depth);
|
|
1621
|
-
editor.view.dispatch(state.tr.delete(deleteFrom, deleteTo));
|
|
1622
|
-
return true;
|
|
1623
|
-
}
|
|
1624
|
-
break;
|
|
1625
|
-
}
|
|
1626
|
-
return false;
|
|
1627
|
-
},
|
|
1628
|
-
"Mod-a": ({ editor }) => {
|
|
1629
|
-
const { state } = editor;
|
|
1630
|
-
const { $from } = state.selection;
|
|
1631
|
-
for (let d = $from.depth; d > 0; d--) {
|
|
1632
|
-
if ($from.node(d).type.name !== "columnsColumn") continue;
|
|
1633
|
-
const columnStart = $from.start(d);
|
|
1634
|
-
const columnEnd = $from.end(d);
|
|
1635
|
-
const { from, to } = state.selection;
|
|
1636
|
-
if (from === columnStart && to === columnEnd) return false;
|
|
1637
|
-
editor.view.dispatch(state.tr.setSelection(TextSelection.create(state.doc, columnStart, columnEnd)));
|
|
1638
|
-
return true;
|
|
1639
|
-
}
|
|
1640
|
-
return false;
|
|
1641
|
-
}
|
|
1642
|
-
};
|
|
1643
|
-
},
|
|
1644
|
-
renderToReactEmail({ children, node, style }) {
|
|
1645
|
-
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
1646
|
-
const width = node.attrs?.width;
|
|
1647
|
-
return /* @__PURE__ */ jsx(Column, {
|
|
1648
|
-
className: node.attrs?.class || void 0,
|
|
1649
|
-
style: {
|
|
1650
|
-
...style,
|
|
1651
|
-
...inlineStyles,
|
|
1652
|
-
...width ? { width } : {}
|
|
1653
|
-
},
|
|
1654
|
-
children
|
|
1655
|
-
});
|
|
1656
|
-
}
|
|
1657
|
-
});
|
|
1658
|
-
|
|
1659
|
-
//#endregion
|
|
1660
|
-
//#region src/extensions/index.ts
|
|
1661
|
-
const coreExtensions = [
|
|
1662
|
-
StarterKit.configure({
|
|
1663
|
-
undoRedo: false,
|
|
1664
|
-
heading: false,
|
|
1665
|
-
link: false,
|
|
1666
|
-
underline: false,
|
|
1667
|
-
trailingNode: false,
|
|
1668
|
-
bold: false,
|
|
1669
|
-
gapcursor: false,
|
|
1670
|
-
listItem: {},
|
|
1671
|
-
bulletList: { HTMLAttributes: { class: "node-bulletList" } },
|
|
1672
|
-
paragraph: { HTMLAttributes: { class: "node-paragraph" } },
|
|
1673
|
-
orderedList: { HTMLAttributes: { class: "node-orderedList" } },
|
|
1674
|
-
blockquote: { HTMLAttributes: { class: "node-blockquote" } },
|
|
1675
|
-
codeBlock: false,
|
|
1676
|
-
code: { HTMLAttributes: {
|
|
1677
|
-
class: "node-inlineCode",
|
|
1678
|
-
spellcheck: "false"
|
|
1679
|
-
} },
|
|
1680
|
-
horizontalRule: false,
|
|
1681
|
-
dropcursor: {
|
|
1682
|
-
color: "#61a8f8",
|
|
1683
|
-
class: "rounded-full animate-[fade-in_300ms_ease-in-out] !z-40",
|
|
1684
|
-
width: 4
|
|
1685
|
-
}
|
|
1686
|
-
}),
|
|
1687
|
-
CodeBlockPrism.configure({
|
|
1688
|
-
defaultLanguage: "javascript",
|
|
1689
|
-
HTMLAttributes: { class: "prism node-codeBlock" }
|
|
1690
|
-
}),
|
|
1691
|
-
Placeholder,
|
|
1692
|
-
PreviewText,
|
|
1693
|
-
Bold,
|
|
1694
|
-
Sup,
|
|
1695
|
-
Uppercase,
|
|
1696
|
-
PreservedStyle,
|
|
1697
|
-
Table,
|
|
1698
|
-
TableRow,
|
|
1699
|
-
TableCell,
|
|
1700
|
-
TableHeader,
|
|
1701
|
-
Body,
|
|
1702
|
-
Div,
|
|
1703
|
-
Button,
|
|
1704
|
-
Section,
|
|
1705
|
-
AlignmentAttribute.configure({ types: [
|
|
1706
|
-
"heading",
|
|
1707
|
-
"paragraph",
|
|
1708
|
-
"image",
|
|
1709
|
-
"blockquote",
|
|
1710
|
-
"codeBlock",
|
|
1711
|
-
"bulletList",
|
|
1712
|
-
"orderedList",
|
|
1713
|
-
"listItem",
|
|
1714
|
-
"button",
|
|
1715
|
-
"youtube",
|
|
1716
|
-
"twitter",
|
|
1717
|
-
"table",
|
|
1718
|
-
"tableRow",
|
|
1719
|
-
"tableCell",
|
|
1720
|
-
"tableHeader",
|
|
1721
|
-
"columnsColumn"
|
|
1722
|
-
] }),
|
|
1723
|
-
StyleAttribute.configure({ types: [
|
|
1724
|
-
"heading",
|
|
1725
|
-
"paragraph",
|
|
1726
|
-
"image",
|
|
1727
|
-
"blockquote",
|
|
1728
|
-
"codeBlock",
|
|
1729
|
-
"bulletList",
|
|
1730
|
-
"orderedList",
|
|
1731
|
-
"listItem",
|
|
1732
|
-
"button",
|
|
1733
|
-
"youtube",
|
|
1734
|
-
"twitter",
|
|
1735
|
-
"horizontalRule",
|
|
1736
|
-
"footer",
|
|
1737
|
-
"section",
|
|
1738
|
-
"div",
|
|
1739
|
-
"body",
|
|
1740
|
-
"table",
|
|
1741
|
-
"tableRow",
|
|
1742
|
-
"tableCell",
|
|
1743
|
-
"tableHeader",
|
|
1744
|
-
"columnsColumn",
|
|
1745
|
-
"link"
|
|
1746
|
-
] }),
|
|
1747
|
-
ClassAttribute.configure({ types: [
|
|
1748
|
-
"heading",
|
|
1749
|
-
"paragraph",
|
|
1750
|
-
"image",
|
|
1751
|
-
"blockquote",
|
|
1752
|
-
"bulletList",
|
|
1753
|
-
"orderedList",
|
|
1754
|
-
"listItem",
|
|
1755
|
-
"button",
|
|
1756
|
-
"youtube",
|
|
1757
|
-
"twitter",
|
|
1758
|
-
"horizontalRule",
|
|
1759
|
-
"footer",
|
|
1760
|
-
"section",
|
|
1761
|
-
"div",
|
|
1762
|
-
"body",
|
|
1763
|
-
"table",
|
|
1764
|
-
"tableRow",
|
|
1765
|
-
"tableCell",
|
|
1766
|
-
"tableHeader",
|
|
1767
|
-
"columnsColumn",
|
|
1768
|
-
"link"
|
|
1769
|
-
] }),
|
|
1770
|
-
MaxNesting.configure({
|
|
1771
|
-
maxDepth: 50,
|
|
1772
|
-
nodeTypes: [
|
|
1773
|
-
"section",
|
|
1774
|
-
"bulletList",
|
|
1775
|
-
"orderedList"
|
|
1776
|
-
]
|
|
1777
|
-
})
|
|
1778
|
-
];
|
|
1779
|
-
|
|
1780
|
-
//#endregion
|
|
1781
|
-
//#region src/utils/set-text-alignment.ts
|
|
1782
|
-
function setTextAlignment(editor, alignment) {
|
|
1783
|
-
const { from, to } = editor.state.selection;
|
|
1784
|
-
const tr = editor.state.tr;
|
|
1785
|
-
editor.state.doc.nodesBetween(from, to, (node, pos) => {
|
|
1786
|
-
if (node.isTextblock) {
|
|
1787
|
-
const prop = "align" in node.attrs ? "align" : "alignment";
|
|
1788
|
-
tr.setNodeMarkup(pos, null, {
|
|
1789
|
-
...node.attrs,
|
|
1790
|
-
[prop]: alignment
|
|
1791
|
-
});
|
|
1792
|
-
}
|
|
1793
|
-
});
|
|
1794
|
-
editor.view.dispatch(tr);
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
//#endregion
|
|
1798
|
-
//#region src/ui/bubble-menu/context.tsx
|
|
1799
|
-
const BubbleMenuContext = React.createContext(null);
|
|
1800
|
-
function useBubbleMenuContext() {
|
|
1801
|
-
const context = React.useContext(BubbleMenuContext);
|
|
1802
|
-
if (!context) throw new Error("BubbleMenu compound components must be used within <BubbleMenu.Root>");
|
|
1803
|
-
return context;
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
//#endregion
|
|
1807
|
-
//#region src/ui/bubble-menu/item.tsx
|
|
1808
|
-
function BubbleMenuItem({ name, isActive, onCommand, className, children,...rest }) {
|
|
1809
|
-
return /* @__PURE__ */ jsx("button", {
|
|
1810
|
-
type: "button",
|
|
1811
|
-
"aria-label": name,
|
|
1812
|
-
"aria-pressed": isActive,
|
|
1813
|
-
className,
|
|
1814
|
-
"data-re-bubble-menu-item": "",
|
|
1815
|
-
"data-item": name,
|
|
1816
|
-
...isActive ? { "data-active": "" } : {},
|
|
1817
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
1818
|
-
onClick: onCommand,
|
|
1819
|
-
...rest,
|
|
1820
|
-
children
|
|
1821
|
-
});
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
//#endregion
|
|
1825
|
-
//#region src/ui/bubble-menu/align-center.tsx
|
|
1826
|
-
function BubbleMenuAlignCenter({ className, children }) {
|
|
1827
|
-
const { editor } = useBubbleMenuContext();
|
|
1828
|
-
return /* @__PURE__ */ jsx(BubbleMenuItem, {
|
|
1829
|
-
name: "align-center",
|
|
1830
|
-
isActive: useEditorState({
|
|
1831
|
-
editor,
|
|
1832
|
-
selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "center" }) ?? false
|
|
1833
|
-
}),
|
|
1834
|
-
onCommand: () => setTextAlignment(editor, "center"),
|
|
1835
|
-
className,
|
|
1836
|
-
children: children ?? /* @__PURE__ */ jsx(AlignCenterIcon, {})
|
|
1837
|
-
});
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
//#endregion
|
|
1841
|
-
//#region src/ui/bubble-menu/align-left.tsx
|
|
1842
|
-
function BubbleMenuAlignLeft({ className, children }) {
|
|
1843
|
-
const { editor } = useBubbleMenuContext();
|
|
1844
|
-
return /* @__PURE__ */ jsx(BubbleMenuItem, {
|
|
1845
|
-
name: "align-left",
|
|
1846
|
-
isActive: useEditorState({
|
|
1847
|
-
editor,
|
|
1848
|
-
selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "left" }) ?? false
|
|
1849
|
-
}),
|
|
1850
|
-
onCommand: () => setTextAlignment(editor, "left"),
|
|
1851
|
-
className,
|
|
1852
|
-
children: children ?? /* @__PURE__ */ jsx(AlignLeftIcon, {})
|
|
1853
|
-
});
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
|
-
//#endregion
|
|
1857
|
-
//#region src/ui/bubble-menu/align-right.tsx
|
|
1858
|
-
function BubbleMenuAlignRight({ className, children }) {
|
|
1859
|
-
const { editor } = useBubbleMenuContext();
|
|
1860
|
-
return /* @__PURE__ */ jsx(BubbleMenuItem, {
|
|
1861
|
-
name: "align-right",
|
|
1862
|
-
isActive: useEditorState({
|
|
1863
|
-
editor,
|
|
1864
|
-
selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "right" }) ?? false
|
|
1865
|
-
}),
|
|
1866
|
-
onCommand: () => setTextAlignment(editor, "right"),
|
|
1867
|
-
className,
|
|
1868
|
-
children: children ?? /* @__PURE__ */ jsx(AlignRightIcon, {})
|
|
1869
|
-
});
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
//#endregion
|
|
1873
|
-
//#region src/ui/bubble-menu/create-mark-bubble-item.tsx
|
|
1874
|
-
function createMarkBubbleItem(config) {
|
|
1875
|
-
function MarkBubbleItem({ className, children }) {
|
|
1876
|
-
const { editor } = useBubbleMenuContext();
|
|
1877
|
-
const isActive = useEditorState({
|
|
1878
|
-
editor,
|
|
1879
|
-
selector: ({ editor: editor$1 }) => {
|
|
1880
|
-
if (config.activeParams) return editor$1?.isActive(config.activeName, config.activeParams) ?? false;
|
|
1881
|
-
return editor$1?.isActive(config.activeName) ?? false;
|
|
1882
|
-
}
|
|
1883
|
-
});
|
|
1884
|
-
const handleCommand = () => {
|
|
1885
|
-
const chain = editor.chain().focus();
|
|
1886
|
-
const method = chain[config.command];
|
|
1887
|
-
if (method) method.call(chain).run();
|
|
1888
|
-
};
|
|
1889
|
-
return /* @__PURE__ */ jsx(BubbleMenuItem, {
|
|
1890
|
-
name: config.name,
|
|
1891
|
-
isActive,
|
|
1892
|
-
onCommand: handleCommand,
|
|
1893
|
-
className,
|
|
1894
|
-
children: children ?? config.icon
|
|
1895
|
-
});
|
|
1896
|
-
}
|
|
1897
|
-
MarkBubbleItem.displayName = `BubbleMenu${config.name.charAt(0).toUpperCase() + config.name.slice(1)}`;
|
|
1898
|
-
return MarkBubbleItem;
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
//#endregion
|
|
1902
|
-
//#region src/ui/bubble-menu/bold.tsx
|
|
1903
|
-
const BubbleMenuBold = createMarkBubbleItem({
|
|
1904
|
-
name: "bold",
|
|
1905
|
-
activeName: "bold",
|
|
1906
|
-
command: "toggleBold",
|
|
1907
|
-
icon: /* @__PURE__ */ jsx(BoldIcon, {})
|
|
1908
|
-
});
|
|
1909
|
-
|
|
1910
|
-
//#endregion
|
|
1911
|
-
//#region src/ui/bubble-menu/code.tsx
|
|
1912
|
-
const BubbleMenuCode = createMarkBubbleItem({
|
|
1913
|
-
name: "code",
|
|
1914
|
-
activeName: "code",
|
|
1915
|
-
command: "toggleCode",
|
|
1916
|
-
icon: /* @__PURE__ */ jsx(CodeIcon, {})
|
|
1917
|
-
});
|
|
1918
|
-
|
|
1919
|
-
//#endregion
|
|
1920
|
-
//#region src/ui/bubble-menu/group.tsx
|
|
1921
|
-
function BubbleMenuItemGroup({ className, children }) {
|
|
1922
|
-
return /* @__PURE__ */ jsx("fieldset", {
|
|
1923
|
-
className,
|
|
1924
|
-
"data-re-bubble-menu-group": "",
|
|
1925
|
-
children
|
|
1926
|
-
});
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
//#endregion
|
|
1930
|
-
//#region src/ui/bubble-menu/italic.tsx
|
|
1931
|
-
const BubbleMenuItalic = createMarkBubbleItem({
|
|
1932
|
-
name: "italic",
|
|
1933
|
-
activeName: "italic",
|
|
1934
|
-
command: "toggleItalic",
|
|
1935
|
-
icon: /* @__PURE__ */ jsx(ItalicIcon, {})
|
|
1936
|
-
});
|
|
1937
|
-
|
|
1938
|
-
//#endregion
|
|
1939
|
-
//#region src/ui/bubble-menu/utils.ts
|
|
1940
|
-
const SAFE_PROTOCOLS = new Set([
|
|
1941
|
-
"http:",
|
|
1942
|
-
"https:",
|
|
1943
|
-
"mailto:",
|
|
1944
|
-
"tel:"
|
|
1945
|
-
]);
|
|
1946
|
-
/**
|
|
1947
|
-
* Basic URL validation and auto-prefixing.
|
|
1948
|
-
* Rejects dangerous schemes (javascript:, data:, vbscript:, etc.).
|
|
1949
|
-
* Returns the valid URL string or null.
|
|
1950
|
-
*/
|
|
1951
|
-
function getUrlFromString(str) {
|
|
1952
|
-
if (str === "#") return str;
|
|
1953
|
-
try {
|
|
1954
|
-
const url = new URL(str);
|
|
1955
|
-
if (SAFE_PROTOCOLS.has(url.protocol)) return str;
|
|
1956
|
-
return null;
|
|
1957
|
-
} catch {}
|
|
1958
|
-
try {
|
|
1959
|
-
if (str.includes(".") && !str.includes(" ")) return new URL(`https://${str}`).toString();
|
|
1960
|
-
} catch {}
|
|
1961
|
-
return null;
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
//#endregion
|
|
1965
|
-
//#region src/ui/bubble-menu/link-selector.tsx
|
|
1966
|
-
function BubbleMenuLinkSelector({ className, showToggle = true, validateUrl, onLinkApply, onLinkRemove, children }) {
|
|
1967
|
-
const { editor } = useBubbleMenuContext();
|
|
1968
|
-
const [isOpen, setIsOpen] = React.useState(false);
|
|
1969
|
-
const editorState = useEditorState({
|
|
1970
|
-
editor,
|
|
1971
|
-
selector: ({ editor: editor$1 }) => ({
|
|
1972
|
-
isLinkActive: editor$1?.isActive("link") ?? false,
|
|
1973
|
-
hasLink: Boolean(editor$1?.getAttributes("link").href),
|
|
1974
|
-
currentHref: editor$1?.getAttributes("link").href || ""
|
|
1975
|
-
})
|
|
1976
|
-
});
|
|
1977
|
-
React.useEffect(() => {
|
|
1978
|
-
const subscription = editorEventBus.on("bubble-menu:add-link", () => {
|
|
1979
|
-
setIsOpen(true);
|
|
1980
|
-
});
|
|
1981
|
-
return () => {
|
|
1982
|
-
setIsOpen(false);
|
|
1983
|
-
subscription.unsubscribe();
|
|
1984
|
-
};
|
|
1985
|
-
}, []);
|
|
1986
|
-
if (!editorState) return null;
|
|
1987
|
-
const handleOpenLink = () => {
|
|
1988
|
-
setIsOpen(!isOpen);
|
|
124
|
+
getJSON: () => editor?.getJSON() ?? {
|
|
125
|
+
type: "doc",
|
|
126
|
+
content: []
|
|
127
|
+
},
|
|
128
|
+
editor
|
|
1989
129
|
};
|
|
1990
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1991
|
-
"data-re-link-selector": "",
|
|
1992
|
-
...isOpen ? { "data-open": "" } : {},
|
|
1993
|
-
...editorState.hasLink ? { "data-has-link": "" } : {},
|
|
1994
|
-
className,
|
|
1995
|
-
children: [showToggle && /* @__PURE__ */ jsx("button", {
|
|
1996
|
-
type: "button",
|
|
1997
|
-
"aria-expanded": isOpen,
|
|
1998
|
-
"aria-haspopup": "true",
|
|
1999
|
-
"aria-label": "Add link",
|
|
2000
|
-
"aria-pressed": editorState.isLinkActive && editorState.hasLink,
|
|
2001
|
-
"data-re-link-selector-trigger": "",
|
|
2002
|
-
onClick: handleOpenLink,
|
|
2003
|
-
children: /* @__PURE__ */ jsx(LinkIcon, {})
|
|
2004
|
-
}), isOpen && /* @__PURE__ */ jsx(LinkForm, {
|
|
2005
|
-
editor,
|
|
2006
|
-
currentHref: editorState.currentHref,
|
|
2007
|
-
validateUrl,
|
|
2008
|
-
onLinkApply,
|
|
2009
|
-
onLinkRemove,
|
|
2010
|
-
setIsOpen,
|
|
2011
|
-
children
|
|
2012
|
-
})]
|
|
2013
|
-
});
|
|
2014
130
|
}
|
|
2015
|
-
function
|
|
2016
|
-
const
|
|
2017
|
-
const
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
const
|
|
2022
|
-
|
|
2023
|
-
}
|
|
2024
|
-
|
|
2025
|
-
}, []);
|
|
2026
|
-
React.useEffect(() => {
|
|
2027
|
-
const handleKeyDown = (event) => {
|
|
2028
|
-
if (event.key === "Escape") {
|
|
2029
|
-
if (editor.getAttributes("link").href === "#") editor.chain().unsetLink().run();
|
|
2030
|
-
setIsOpen(false);
|
|
2031
|
-
}
|
|
2032
|
-
};
|
|
2033
|
-
const handleClickOutside = (event) => {
|
|
2034
|
-
if (formRef.current && !formRef.current.contains(event.target)) {
|
|
2035
|
-
const form = formRef.current;
|
|
2036
|
-
const submitEvent = new Event("submit", {
|
|
2037
|
-
bubbles: true,
|
|
2038
|
-
cancelable: true
|
|
2039
|
-
});
|
|
2040
|
-
form.dispatchEvent(submitEvent);
|
|
2041
|
-
setIsOpen(false);
|
|
2042
|
-
}
|
|
2043
|
-
};
|
|
2044
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
2045
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
131
|
+
function RefBridge({ editorRef, onUpdateRef }) {
|
|
132
|
+
const { editor } = useCurrentEditor();
|
|
133
|
+
const emailEditorRef = useMemo(() => buildRef(editor), [editor]);
|
|
134
|
+
useImperativeHandle(editorRef, () => emailEditorRef, [emailEditorRef]);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (!editor) return;
|
|
137
|
+
const handler = () => {
|
|
138
|
+
onUpdateRef.current?.(emailEditorRef);
|
|
139
|
+
};
|
|
140
|
+
editor.on("update", handler);
|
|
2046
141
|
return () => {
|
|
2047
|
-
|
|
2048
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
142
|
+
editor.off("update", handler);
|
|
2049
143
|
};
|
|
2050
|
-
}, [
|
|
2051
|
-
function handleSubmit(e) {
|
|
2052
|
-
e.preventDefault();
|
|
2053
|
-
const value = inputValue.trim();
|
|
2054
|
-
if (value === "") {
|
|
2055
|
-
setLinkHref(editor, "");
|
|
2056
|
-
setIsOpen(false);
|
|
2057
|
-
focusEditor(editor);
|
|
2058
|
-
onLinkRemove?.();
|
|
2059
|
-
return;
|
|
2060
|
-
}
|
|
2061
|
-
const finalValue = (validateUrl ?? getUrlFromString)(value);
|
|
2062
|
-
if (!finalValue) {
|
|
2063
|
-
setLinkHref(editor, "");
|
|
2064
|
-
setIsOpen(false);
|
|
2065
|
-
focusEditor(editor);
|
|
2066
|
-
onLinkRemove?.();
|
|
2067
|
-
return;
|
|
2068
|
-
}
|
|
2069
|
-
setLinkHref(editor, finalValue);
|
|
2070
|
-
setIsOpen(false);
|
|
2071
|
-
focusEditor(editor);
|
|
2072
|
-
onLinkApply?.(finalValue);
|
|
2073
|
-
}
|
|
2074
|
-
function handleUnlink(e) {
|
|
2075
|
-
e.stopPropagation();
|
|
2076
|
-
setLinkHref(editor, "");
|
|
2077
|
-
setIsOpen(false);
|
|
2078
|
-
focusEditor(editor);
|
|
2079
|
-
onLinkRemove?.();
|
|
2080
|
-
}
|
|
2081
|
-
return /* @__PURE__ */ jsxs("form", {
|
|
2082
|
-
ref: formRef,
|
|
2083
|
-
"data-re-link-selector-form": "",
|
|
2084
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
2085
|
-
onClick: (e) => e.stopPropagation(),
|
|
2086
|
-
onKeyDown: (e) => e.stopPropagation(),
|
|
2087
|
-
onSubmit: handleSubmit,
|
|
2088
|
-
children: [
|
|
2089
|
-
/* @__PURE__ */ jsx("input", {
|
|
2090
|
-
ref: inputRef,
|
|
2091
|
-
"data-re-link-selector-input": "",
|
|
2092
|
-
value: inputValue,
|
|
2093
|
-
onFocus: (e) => e.stopPropagation(),
|
|
2094
|
-
onChange: (e) => setInputValue(e.target.value),
|
|
2095
|
-
placeholder: "Paste a link",
|
|
2096
|
-
type: "text"
|
|
2097
|
-
}),
|
|
2098
|
-
children,
|
|
2099
|
-
displayHref ? /* @__PURE__ */ jsx("button", {
|
|
2100
|
-
type: "button",
|
|
2101
|
-
"aria-label": "Remove link",
|
|
2102
|
-
"data-re-link-selector-unlink": "",
|
|
2103
|
-
onClick: handleUnlink,
|
|
2104
|
-
children: /* @__PURE__ */ jsx(UnlinkIcon, {})
|
|
2105
|
-
}) : /* @__PURE__ */ jsx("button", {
|
|
2106
|
-
type: "submit",
|
|
2107
|
-
"aria-label": "Apply link",
|
|
2108
|
-
"data-re-link-selector-apply": "",
|
|
2109
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
2110
|
-
children: /* @__PURE__ */ jsx(Check, {})
|
|
2111
|
-
})
|
|
2112
|
-
]
|
|
2113
|
-
});
|
|
2114
|
-
}
|
|
2115
|
-
function setLinkHref(editor, href) {
|
|
2116
|
-
if (href.length === 0) {
|
|
2117
|
-
editor.chain().unsetLink().run();
|
|
2118
|
-
return;
|
|
2119
|
-
}
|
|
2120
|
-
const { from, to } = editor.state.selection;
|
|
2121
|
-
if (from === to) {
|
|
2122
|
-
editor.chain().extendMarkRange("link").setLink({ href }).setTextSelection({
|
|
2123
|
-
from,
|
|
2124
|
-
to
|
|
2125
|
-
}).run();
|
|
2126
|
-
return;
|
|
2127
|
-
}
|
|
2128
|
-
editor.chain().setLink({ href }).run();
|
|
2129
|
-
}
|
|
2130
|
-
function focusEditor(editor) {
|
|
2131
|
-
setTimeout(() => {
|
|
2132
|
-
editor.commands.focus();
|
|
2133
|
-
}, 0);
|
|
2134
|
-
}
|
|
2135
|
-
|
|
2136
|
-
//#endregion
|
|
2137
|
-
//#region src/ui/bubble-menu/node-selector.tsx
|
|
2138
|
-
const NodeSelectorContext = React.createContext(null);
|
|
2139
|
-
function useNodeSelectorContext() {
|
|
2140
|
-
const context = React.useContext(NodeSelectorContext);
|
|
2141
|
-
if (!context) throw new Error("NodeSelector compound components must be used within <NodeSelector.Root>");
|
|
2142
|
-
return context;
|
|
2143
|
-
}
|
|
2144
|
-
function NodeSelectorRoot({ omit = [], open: controlledOpen, onOpenChange, className, children }) {
|
|
2145
|
-
const { editor } = useBubbleMenuContext();
|
|
2146
|
-
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
|
|
2147
|
-
const isControlled = controlledOpen !== void 0;
|
|
2148
|
-
const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
|
|
2149
|
-
const setIsOpen = React.useCallback((value) => {
|
|
2150
|
-
if (!isControlled) setUncontrolledOpen(value);
|
|
2151
|
-
onOpenChange?.(value);
|
|
2152
|
-
}, [isControlled, onOpenChange]);
|
|
2153
|
-
const editorState = useEditorState({
|
|
144
|
+
}, [
|
|
2154
145
|
editor,
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
isHeading1Active: editor$1?.isActive("heading", { level: 1 }) ?? false,
|
|
2158
|
-
isHeading2Active: editor$1?.isActive("heading", { level: 2 }) ?? false,
|
|
2159
|
-
isHeading3Active: editor$1?.isActive("heading", { level: 3 }) ?? false,
|
|
2160
|
-
isBulletListActive: editor$1?.isActive("bulletList") ?? false,
|
|
2161
|
-
isOrderedListActive: editor$1?.isActive("orderedList") ?? false,
|
|
2162
|
-
isBlockquoteActive: editor$1?.isActive("blockquote") ?? false,
|
|
2163
|
-
isCodeBlockActive: editor$1?.isActive("codeBlock") ?? false
|
|
2164
|
-
})
|
|
2165
|
-
});
|
|
2166
|
-
const allItems = React.useMemo(() => [
|
|
2167
|
-
{
|
|
2168
|
-
name: "Text",
|
|
2169
|
-
icon: TextIcon,
|
|
2170
|
-
command: () => editor.chain().focus().clearNodes().toggleNode("paragraph", "paragraph").run(),
|
|
2171
|
-
isActive: editorState?.isParagraphActive ?? false
|
|
2172
|
-
},
|
|
2173
|
-
{
|
|
2174
|
-
name: "Title",
|
|
2175
|
-
icon: Heading1,
|
|
2176
|
-
command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 1 }).run(),
|
|
2177
|
-
isActive: editorState?.isHeading1Active ?? false
|
|
2178
|
-
},
|
|
2179
|
-
{
|
|
2180
|
-
name: "Subtitle",
|
|
2181
|
-
icon: Heading2,
|
|
2182
|
-
command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 2 }).run(),
|
|
2183
|
-
isActive: editorState?.isHeading2Active ?? false
|
|
2184
|
-
},
|
|
2185
|
-
{
|
|
2186
|
-
name: "Heading",
|
|
2187
|
-
icon: Heading3,
|
|
2188
|
-
command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 3 }).run(),
|
|
2189
|
-
isActive: editorState?.isHeading3Active ?? false
|
|
2190
|
-
},
|
|
2191
|
-
{
|
|
2192
|
-
name: "Bullet List",
|
|
2193
|
-
icon: List,
|
|
2194
|
-
command: () => editor.chain().focus().clearNodes().toggleBulletList().run(),
|
|
2195
|
-
isActive: editorState?.isBulletListActive ?? false
|
|
2196
|
-
},
|
|
2197
|
-
{
|
|
2198
|
-
name: "Numbered List",
|
|
2199
|
-
icon: ListOrdered,
|
|
2200
|
-
command: () => editor.chain().focus().clearNodes().toggleOrderedList().run(),
|
|
2201
|
-
isActive: editorState?.isOrderedListActive ?? false
|
|
2202
|
-
},
|
|
2203
|
-
{
|
|
2204
|
-
name: "Quote",
|
|
2205
|
-
icon: TextQuote,
|
|
2206
|
-
command: () => editor.chain().focus().clearNodes().toggleNode("paragraph", "paragraph").toggleBlockquote().run(),
|
|
2207
|
-
isActive: editorState?.isBlockquoteActive ?? false
|
|
2208
|
-
},
|
|
2209
|
-
{
|
|
2210
|
-
name: "Code",
|
|
2211
|
-
icon: Code,
|
|
2212
|
-
command: () => editor.chain().focus().clearNodes().toggleCodeBlock().run(),
|
|
2213
|
-
isActive: editorState?.isCodeBlockActive ?? false
|
|
2214
|
-
}
|
|
2215
|
-
], [editor, editorState]);
|
|
2216
|
-
const items = React.useMemo(() => allItems.filter((item) => !omit.includes(item.name)), [allItems, omit]);
|
|
2217
|
-
const activeItem = React.useMemo(() => items.find((item) => item.isActive) ?? { name: "Multiple" }, [items]);
|
|
2218
|
-
const contextValue = React.useMemo(() => ({
|
|
2219
|
-
items,
|
|
2220
|
-
activeItem,
|
|
2221
|
-
isOpen,
|
|
2222
|
-
setIsOpen
|
|
2223
|
-
}), [
|
|
2224
|
-
items,
|
|
2225
|
-
activeItem,
|
|
2226
|
-
isOpen,
|
|
2227
|
-
setIsOpen
|
|
146
|
+
emailEditorRef,
|
|
147
|
+
onUpdateRef
|
|
2228
148
|
]);
|
|
2229
|
-
|
|
2230
|
-
return /* @__PURE__ */ jsx(NodeSelectorContext.Provider, {
|
|
2231
|
-
value: contextValue,
|
|
2232
|
-
children: /* @__PURE__ */ jsx(Popover.Root, {
|
|
2233
|
-
open: isOpen,
|
|
2234
|
-
onOpenChange: setIsOpen,
|
|
2235
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
2236
|
-
"data-re-node-selector": "",
|
|
2237
|
-
...isOpen ? { "data-open": "" } : {},
|
|
2238
|
-
className,
|
|
2239
|
-
children
|
|
2240
|
-
})
|
|
2241
|
-
})
|
|
2242
|
-
});
|
|
2243
|
-
}
|
|
2244
|
-
function NodeSelectorTrigger({ className, children }) {
|
|
2245
|
-
const { activeItem, isOpen, setIsOpen } = useNodeSelectorContext();
|
|
2246
|
-
return /* @__PURE__ */ jsx(Popover.Trigger, {
|
|
2247
|
-
"data-re-node-selector-trigger": "",
|
|
2248
|
-
className,
|
|
2249
|
-
onClick: () => setIsOpen(!isOpen),
|
|
2250
|
-
children: children ?? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", { children: activeItem.name }), /* @__PURE__ */ jsx(ChevronDown, {})] })
|
|
2251
|
-
});
|
|
2252
|
-
}
|
|
2253
|
-
function NodeSelectorContent({ className, align = "start", children }) {
|
|
2254
|
-
const { items, setIsOpen } = useNodeSelectorContext();
|
|
2255
|
-
return /* @__PURE__ */ jsx(Popover.Content, {
|
|
2256
|
-
align,
|
|
2257
|
-
"data-re-node-selector-content": "",
|
|
2258
|
-
className,
|
|
2259
|
-
children: children ? children(items, () => setIsOpen(false)) : items.map((item) => {
|
|
2260
|
-
const Icon = item.icon;
|
|
2261
|
-
return /* @__PURE__ */ jsxs("button", {
|
|
2262
|
-
type: "button",
|
|
2263
|
-
"data-re-node-selector-item": "",
|
|
2264
|
-
...item.isActive ? { "data-active": "" } : {},
|
|
2265
|
-
onClick: () => {
|
|
2266
|
-
item.command();
|
|
2267
|
-
setIsOpen(false);
|
|
2268
|
-
},
|
|
2269
|
-
children: [
|
|
2270
|
-
/* @__PURE__ */ jsx(Icon, {}),
|
|
2271
|
-
/* @__PURE__ */ jsx("span", { children: item.name }),
|
|
2272
|
-
item.isActive && /* @__PURE__ */ jsx(Check, {})
|
|
2273
|
-
]
|
|
2274
|
-
}, item.name);
|
|
2275
|
-
})
|
|
2276
|
-
});
|
|
2277
|
-
}
|
|
2278
|
-
function BubbleMenuNodeSelector({ omit = [], className, triggerContent, open, onOpenChange }) {
|
|
2279
|
-
return /* @__PURE__ */ jsxs(NodeSelectorRoot, {
|
|
2280
|
-
omit,
|
|
2281
|
-
open,
|
|
2282
|
-
onOpenChange,
|
|
2283
|
-
className,
|
|
2284
|
-
children: [/* @__PURE__ */ jsx(NodeSelectorTrigger, { children: triggerContent }), /* @__PURE__ */ jsx(NodeSelectorContent, {})]
|
|
2285
|
-
});
|
|
149
|
+
return null;
|
|
2286
150
|
}
|
|
2287
|
-
|
|
2288
|
-
//#endregion
|
|
2289
|
-
//#region src/ui/bubble-menu/root.tsx
|
|
2290
|
-
function BubbleMenuRoot({ excludeNodes = [], placement = "bottom", offset = 8, onHide, className, children }) {
|
|
151
|
+
function EmailEditorReadyBridge({ onReadyRef }) {
|
|
2291
152
|
const { editor } = useCurrentEditor();
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
editor
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
for (const node of excludeNodes) if (editor$1.isActive(node)) return false;
|
|
2298
|
-
if (view.dom.classList.contains("dragging")) return false;
|
|
2299
|
-
return editor$1.view.state.selection.content().size > 0;
|
|
2300
|
-
},
|
|
2301
|
-
options: {
|
|
2302
|
-
placement,
|
|
2303
|
-
offset,
|
|
2304
|
-
onHide
|
|
2305
|
-
},
|
|
2306
|
-
className,
|
|
2307
|
-
children: /* @__PURE__ */ jsx(BubbleMenuContext.Provider, {
|
|
2308
|
-
value: { editor },
|
|
2309
|
-
children
|
|
2310
|
-
})
|
|
2311
|
-
});
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
//#endregion
|
|
2315
|
-
//#region src/ui/bubble-menu/separator.tsx
|
|
2316
|
-
function BubbleMenuSeparator({ className }) {
|
|
2317
|
-
return /* @__PURE__ */ jsx("hr", {
|
|
2318
|
-
className,
|
|
2319
|
-
"data-re-bubble-menu-separator": ""
|
|
2320
|
-
});
|
|
153
|
+
useLayoutEffect(() => {
|
|
154
|
+
if (!editor) return;
|
|
155
|
+
onReadyRef.current?.(buildRef(editor));
|
|
156
|
+
}, [editor, onReadyRef]);
|
|
157
|
+
return null;
|
|
2321
158
|
}
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
const
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
});
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
159
|
+
const EmailEditor = forwardRef(({ content, onUpdate, onReady, theme = "basic", editable = true, placeholder, bubbleMenu, extensions: extensionsProp, onUploadImage, className, children }, ref) => {
|
|
160
|
+
const onUpdateRef = useRef(onUpdate);
|
|
161
|
+
onUpdateRef.current = onUpdate;
|
|
162
|
+
const onReadyRef = useRef(onReady);
|
|
163
|
+
onReadyRef.current = onReady;
|
|
164
|
+
const imageExtension = useMemo(() => {
|
|
165
|
+
if (!onUploadImage) return null;
|
|
166
|
+
return createImageExtension({ uploadImage: onUploadImage });
|
|
167
|
+
}, [onUploadImage]);
|
|
168
|
+
const extensions = useMemo(() => {
|
|
169
|
+
const base = extensionsProp ?? [
|
|
170
|
+
StarterKit.configure(),
|
|
171
|
+
Placeholder.configure({
|
|
172
|
+
placeholder: placeholder ?? (({ node }) => {
|
|
173
|
+
if (node.type.name === "heading") return `Heading ${node.attrs.level}`;
|
|
174
|
+
return "Press '/' for commands";
|
|
175
|
+
}),
|
|
176
|
+
includeChildren: true
|
|
177
|
+
}),
|
|
178
|
+
EmailTheming.configure({ theme })
|
|
179
|
+
];
|
|
180
|
+
return imageExtension ? [...base, imageExtension] : base;
|
|
181
|
+
}, [
|
|
182
|
+
extensionsProp,
|
|
183
|
+
theme,
|
|
184
|
+
placeholder,
|
|
185
|
+
imageExtension
|
|
186
|
+
]);
|
|
187
|
+
return /* @__PURE__ */ jsxs(EditorProvider, {
|
|
188
|
+
extensions,
|
|
189
|
+
content,
|
|
190
|
+
editable,
|
|
191
|
+
immediatelyRender: false,
|
|
192
|
+
editorProps: useMemo(() => ({ handlePaste: createPasteHandler({ extensions }) }), [extensions]),
|
|
193
|
+
editorContainerProps: { className },
|
|
194
|
+
children: [
|
|
195
|
+
/* @__PURE__ */ jsx(RefBridge, {
|
|
196
|
+
editorRef: ref,
|
|
197
|
+
onUpdateRef
|
|
198
|
+
}),
|
|
199
|
+
/* @__PURE__ */ jsx(EmailEditorReadyBridge, { onReadyRef }),
|
|
200
|
+
/* @__PURE__ */ jsx(BubbleMenu, {
|
|
201
|
+
hideWhenActiveNodes: bubbleMenu?.hideWhenActiveNodes ?? ["button"],
|
|
202
|
+
hideWhenActiveMarks: bubbleMenu?.hideWhenActiveMarks ?? ["link"]
|
|
203
|
+
}),
|
|
204
|
+
/* @__PURE__ */ jsx(BubbleMenu.LinkDefault, {}),
|
|
205
|
+
/* @__PURE__ */ jsx(BubbleMenu.ButtonDefault, {}),
|
|
206
|
+
/* @__PURE__ */ jsx(BubbleMenu.ImageDefault, {}),
|
|
207
|
+
/* @__PURE__ */ jsx(SlashCommandRoot, {}),
|
|
208
|
+
children
|
|
209
|
+
]
|
|
210
|
+
}, typeof theme === "string" ? theme : JSON.stringify(theme));
|
|
2348
211
|
});
|
|
2349
|
-
|
|
212
|
+
EmailEditor.displayName = "EmailEditor";
|
|
2350
213
|
//#endregion
|
|
2351
|
-
|
|
2352
|
-
const BubbleMenu = {
|
|
2353
|
-
Root: BubbleMenuRoot,
|
|
2354
|
-
ItemGroup: BubbleMenuItemGroup,
|
|
2355
|
-
Separator: BubbleMenuSeparator,
|
|
2356
|
-
Item: BubbleMenuItem,
|
|
2357
|
-
Bold: BubbleMenuBold,
|
|
2358
|
-
Italic: BubbleMenuItalic,
|
|
2359
|
-
Underline: BubbleMenuUnderline,
|
|
2360
|
-
Strike: BubbleMenuStrike,
|
|
2361
|
-
Code: BubbleMenuCode,
|
|
2362
|
-
Uppercase: BubbleMenuUppercase,
|
|
2363
|
-
AlignLeft: BubbleMenuAlignLeft,
|
|
2364
|
-
AlignCenter: BubbleMenuAlignCenter,
|
|
2365
|
-
AlignRight: BubbleMenuAlignRight,
|
|
2366
|
-
NodeSelector: Object.assign(BubbleMenuNodeSelector, {
|
|
2367
|
-
Root: NodeSelectorRoot,
|
|
2368
|
-
Trigger: NodeSelectorTrigger,
|
|
2369
|
-
Content: NodeSelectorContent
|
|
2370
|
-
}),
|
|
2371
|
-
LinkSelector: BubbleMenuLinkSelector
|
|
2372
|
-
};
|
|
214
|
+
export { EmailEditor };
|
|
2373
215
|
|
|
2374
|
-
//#endregion
|
|
2375
|
-
export { AlignmentAttribute, Body, Bold, BubbleMenu, BubbleMenuAlignCenter, BubbleMenuAlignLeft, BubbleMenuAlignRight, BubbleMenuBold, BubbleMenuCode, BubbleMenuItalic, BubbleMenuItem, BubbleMenuItemGroup, BubbleMenuLinkSelector, BubbleMenuNodeSelector, BubbleMenuRoot, BubbleMenuSeparator, BubbleMenuStrike, BubbleMenuUnderline, BubbleMenuUppercase, Button, COLUMN_PARENT_TYPES, ClassAttribute, CodeBlockPrism, ColumnsColumn, Div, EmailNode, FourColumns, MAX_COLUMNS_DEPTH, MaxNesting, NodeSelectorContent, NodeSelectorRoot, NodeSelectorTrigger, Placeholder, PreservedStyle, PreviewText, Section, StyleAttribute, Sup, Table, TableCell, TableHeader, TableRow, ThreeColumns, TwoColumns, Uppercase, coreExtensions, editorEventBus, getColumnsDepth, processStylesForUnlink, setTextAlignment };
|
|
2376
216
|
//# sourceMappingURL=index.mjs.map
|