@react-email/editor 0.0.0-experimental.22 → 0.0.0-experimental.24
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-CUxUEHje.mjs +497 -0
- package/dist/columns-CUxUEHje.mjs.map +1 -0
- package/dist/columns-ZSaLdkg9.cjs +630 -0
- package/dist/core/index.cjs +8 -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-BjmRceVw.mjs +1999 -0
- package/dist/core-BjmRceVw.mjs.map +1 -0
- package/dist/core-iuG1UrYN.cjs +2250 -0
- package/dist/extensions/index.cjs +46 -0
- package/dist/extensions/index.d.cts +389 -0
- package/dist/extensions/index.d.cts.map +1 -0
- package/dist/extensions/index.d.mts +389 -0
- package/dist/extensions/index.d.mts.map +1 -0
- package/dist/extensions/index.mjs +4 -0
- package/dist/index-CfslA7KT.d.cts +130 -0
- package/dist/index-CfslA7KT.d.cts.map +1 -0
- package/dist/index-hbHRR7oB.d.mts +130 -0
- package/dist/index-hbHRR7oB.d.mts.map +1 -0
- package/dist/set-text-alignment-Bx3bPteH.cjs +24 -0
- package/dist/set-text-alignment-DZvgnbvz.mjs +19 -0
- package/dist/set-text-alignment-DZvgnbvz.mjs.map +1 -0
- package/dist/ui/index.cjs +1646 -0
- package/dist/ui/index.d.cts +668 -0
- package/dist/ui/index.d.cts.map +1 -0
- package/dist/ui/index.d.mts +668 -0
- package/dist/ui/index.d.mts.map +1 -0
- package/dist/ui/index.mjs +1584 -0
- package/dist/ui/index.mjs.map +1 -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 +3 -0
- package/package.json +38 -11
- package/dist/index.cjs +0 -4228
- package/dist/index.d.cts +0 -1175
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -1175
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -4072
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import { Column, Row } from "@react-email/components";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Node, mergeAttributes } from "@tiptap/core";
|
|
4
|
+
import { TextSelection } from "@tiptap/pm/state";
|
|
5
|
+
|
|
6
|
+
//#region src/core/event-bus.ts
|
|
7
|
+
const EVENT_PREFIX = "@react-email/editor:";
|
|
8
|
+
var EditorEventBus = class {
|
|
9
|
+
prefixEventName(eventName) {
|
|
10
|
+
return `${EVENT_PREFIX}${String(eventName)}`;
|
|
11
|
+
}
|
|
12
|
+
dispatch(eventName, payload, options) {
|
|
13
|
+
const target = options?.target ?? window;
|
|
14
|
+
const prefixedEventName = this.prefixEventName(eventName);
|
|
15
|
+
const event = new CustomEvent(prefixedEventName, {
|
|
16
|
+
detail: payload,
|
|
17
|
+
bubbles: false,
|
|
18
|
+
cancelable: false
|
|
19
|
+
});
|
|
20
|
+
target.dispatchEvent(event);
|
|
21
|
+
}
|
|
22
|
+
on(eventName, handler, options) {
|
|
23
|
+
const target = options?.target ?? window;
|
|
24
|
+
const prefixedEventName = this.prefixEventName(eventName);
|
|
25
|
+
const abortController = new AbortController();
|
|
26
|
+
const wrappedHandler = (event) => {
|
|
27
|
+
const customEvent = event;
|
|
28
|
+
const result = handler(customEvent.detail);
|
|
29
|
+
if (result instanceof Promise) result.catch((error) => {
|
|
30
|
+
console.error(`Error in async event handler for ${prefixedEventName}:`, {
|
|
31
|
+
event: customEvent.detail,
|
|
32
|
+
error
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
target.addEventListener(prefixedEventName, wrappedHandler, {
|
|
37
|
+
...options,
|
|
38
|
+
signal: abortController.signal
|
|
39
|
+
});
|
|
40
|
+
return { unsubscribe: () => {
|
|
41
|
+
abortController.abort();
|
|
42
|
+
} };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const editorEventBus = new EditorEventBus();
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/utils/styles.ts
|
|
49
|
+
const WHITE_SPACE_REGEX = /\s+/;
|
|
50
|
+
const inlineCssToJs = (inlineStyle, options = {}) => {
|
|
51
|
+
const styleObject = {};
|
|
52
|
+
if (!inlineStyle || inlineStyle === "" || typeof inlineStyle === "object") return styleObject;
|
|
53
|
+
inlineStyle.split(";").forEach((style) => {
|
|
54
|
+
if (style.trim()) {
|
|
55
|
+
const [key, value] = style.split(":");
|
|
56
|
+
const valueTrimmed = value?.trim();
|
|
57
|
+
if (!valueTrimmed) return;
|
|
58
|
+
const formattedKey = key.trim().replace(/-\w/g, (match) => match[1].toUpperCase());
|
|
59
|
+
styleObject[formattedKey] = options?.removeUnit ? valueTrimmed.replace(/px|%/g, "") : valueTrimmed;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return styleObject;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Expands CSS shorthand properties (margin, padding) into their longhand equivalents.
|
|
66
|
+
* This prevents shorthand properties from overriding specific longhand properties in email clients.
|
|
67
|
+
*
|
|
68
|
+
* @param styles - Style object that may contain shorthand properties
|
|
69
|
+
* @returns New style object with shorthand properties expanded to longhand
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* expandShorthandProperties({ margin: '0', paddingTop: '10px' })
|
|
73
|
+
* // Returns: { marginTop: '0', marginRight: '0', marginBottom: '0', marginLeft: '0', paddingTop: '10px' }
|
|
74
|
+
*/
|
|
75
|
+
function expandShorthandProperties(styles) {
|
|
76
|
+
if (!styles || typeof styles !== "object") return {};
|
|
77
|
+
const expanded = {};
|
|
78
|
+
for (const key in styles) {
|
|
79
|
+
const value = styles[key];
|
|
80
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
81
|
+
switch (key) {
|
|
82
|
+
case "margin": {
|
|
83
|
+
const values = parseShorthandValue(value);
|
|
84
|
+
expanded.marginTop = values.top;
|
|
85
|
+
expanded.marginRight = values.right;
|
|
86
|
+
expanded.marginBottom = values.bottom;
|
|
87
|
+
expanded.marginLeft = values.left;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case "padding": {
|
|
91
|
+
const values = parseShorthandValue(value);
|
|
92
|
+
expanded.paddingTop = values.top;
|
|
93
|
+
expanded.paddingRight = values.right;
|
|
94
|
+
expanded.paddingBottom = values.bottom;
|
|
95
|
+
expanded.paddingLeft = values.left;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "border": {
|
|
99
|
+
const values = convertBorderValue(value);
|
|
100
|
+
expanded.borderStyle = values.style;
|
|
101
|
+
expanded.borderWidth = values.width;
|
|
102
|
+
expanded.borderColor = values.color;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "borderTopLeftRadius":
|
|
106
|
+
case "borderTopRightRadius":
|
|
107
|
+
case "borderBottomLeftRadius":
|
|
108
|
+
case "borderBottomRightRadius":
|
|
109
|
+
expanded[key] = value;
|
|
110
|
+
if (styles.borderTopLeftRadius && styles.borderTopRightRadius && styles.borderBottomLeftRadius && styles.borderBottomRightRadius) {
|
|
111
|
+
const values = [
|
|
112
|
+
styles.borderTopLeftRadius,
|
|
113
|
+
styles.borderTopRightRadius,
|
|
114
|
+
styles.borderBottomLeftRadius,
|
|
115
|
+
styles.borderBottomRightRadius
|
|
116
|
+
];
|
|
117
|
+
if (new Set(values).size === 1) expanded.borderRadius = values[0];
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
default: expanded[key] = value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return expanded;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Parses CSS shorthand value (1-4 values) into individual side values.
|
|
127
|
+
* Follows CSS specification for shorthand property value parsing.
|
|
128
|
+
*
|
|
129
|
+
* @param value - Shorthand value string (e.g., '0', '10px 20px', '5px 10px 15px 20px')
|
|
130
|
+
* @returns Object with top, right, bottom, left values
|
|
131
|
+
*/
|
|
132
|
+
function parseShorthandValue(value) {
|
|
133
|
+
const stringValue = String(value).trim();
|
|
134
|
+
const parts = stringValue.split(WHITE_SPACE_REGEX);
|
|
135
|
+
const len = parts.length;
|
|
136
|
+
if (len === 1) return {
|
|
137
|
+
top: parts[0],
|
|
138
|
+
right: parts[0],
|
|
139
|
+
bottom: parts[0],
|
|
140
|
+
left: parts[0]
|
|
141
|
+
};
|
|
142
|
+
if (len === 2) return {
|
|
143
|
+
top: parts[0],
|
|
144
|
+
right: parts[1],
|
|
145
|
+
bottom: parts[0],
|
|
146
|
+
left: parts[1]
|
|
147
|
+
};
|
|
148
|
+
if (len === 3) return {
|
|
149
|
+
top: parts[0],
|
|
150
|
+
right: parts[1],
|
|
151
|
+
bottom: parts[2],
|
|
152
|
+
left: parts[1]
|
|
153
|
+
};
|
|
154
|
+
if (len === 4) return {
|
|
155
|
+
top: parts[0],
|
|
156
|
+
right: parts[1],
|
|
157
|
+
bottom: parts[2],
|
|
158
|
+
left: parts[3]
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
top: stringValue,
|
|
162
|
+
right: stringValue,
|
|
163
|
+
bottom: stringValue,
|
|
164
|
+
left: stringValue
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function convertBorderValue(value) {
|
|
168
|
+
const stringValue = String(value).trim();
|
|
169
|
+
const parts = stringValue.split(WHITE_SPACE_REGEX);
|
|
170
|
+
switch (parts.length) {
|
|
171
|
+
case 1: return {
|
|
172
|
+
style: "solid",
|
|
173
|
+
width: parts[0],
|
|
174
|
+
color: "black"
|
|
175
|
+
};
|
|
176
|
+
case 2: return {
|
|
177
|
+
style: parts[1],
|
|
178
|
+
width: parts[0],
|
|
179
|
+
color: "black"
|
|
180
|
+
};
|
|
181
|
+
case 3: return {
|
|
182
|
+
style: parts[1],
|
|
183
|
+
width: parts[0],
|
|
184
|
+
color: parts[2]
|
|
185
|
+
};
|
|
186
|
+
case 4: return {
|
|
187
|
+
style: parts[1],
|
|
188
|
+
width: parts[0],
|
|
189
|
+
color: parts[2]
|
|
190
|
+
};
|
|
191
|
+
default: return {
|
|
192
|
+
style: "solid",
|
|
193
|
+
width: stringValue,
|
|
194
|
+
color: "black"
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Resolves conflicts between reset styles and inline styles by expanding
|
|
200
|
+
* shorthand properties (margin, padding) to longhand before merging.
|
|
201
|
+
* This prevents shorthand properties from overriding specific longhand properties.
|
|
202
|
+
*
|
|
203
|
+
* @param resetStyles - Base reset styles that may contain shorthand properties
|
|
204
|
+
* @param inlineStyles - Inline styles that should override reset styles
|
|
205
|
+
* @returns Merged styles with inline styles taking precedence
|
|
206
|
+
*/
|
|
207
|
+
function resolveConflictingStyles(resetStyles, inlineStyles) {
|
|
208
|
+
const expandedResetStyles = expandShorthandProperties(resetStyles);
|
|
209
|
+
const expandedInlineStyles = expandShorthandProperties(inlineStyles);
|
|
210
|
+
return {
|
|
211
|
+
...expandedResetStyles,
|
|
212
|
+
...expandedInlineStyles
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/core/serializer/email-node.ts
|
|
218
|
+
var EmailNode = class EmailNode extends Node {
|
|
219
|
+
constructor(config) {
|
|
220
|
+
super(config);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Create a new Node instance
|
|
224
|
+
* @param config - Node configuration object or a function that returns a configuration object
|
|
225
|
+
*/
|
|
226
|
+
static create(config) {
|
|
227
|
+
return new EmailNode(typeof config === "function" ? config() : config);
|
|
228
|
+
}
|
|
229
|
+
static from(node, renderToReactEmail) {
|
|
230
|
+
const customNode = EmailNode.create({});
|
|
231
|
+
Object.assign(customNode, { ...node });
|
|
232
|
+
customNode.config = {
|
|
233
|
+
...node.config,
|
|
234
|
+
renderToReactEmail
|
|
235
|
+
};
|
|
236
|
+
return customNode;
|
|
237
|
+
}
|
|
238
|
+
configure(options) {
|
|
239
|
+
return super.configure(options);
|
|
240
|
+
}
|
|
241
|
+
extend(extendedConfig) {
|
|
242
|
+
const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
|
|
243
|
+
return super.extend(resolvedConfig);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/utils/attribute-helpers.ts
|
|
249
|
+
/**
|
|
250
|
+
* Creates TipTap attribute definitions for a list of HTML attributes.
|
|
251
|
+
* Each attribute will have the same pattern:
|
|
252
|
+
* - default: null
|
|
253
|
+
* - parseHTML: extracts the attribute from the element
|
|
254
|
+
* - renderHTML: conditionally renders the attribute if it has a value
|
|
255
|
+
*
|
|
256
|
+
* @param attributeNames - Array of HTML attribute names to create definitions for
|
|
257
|
+
* @returns Object with TipTap attribute definitions
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* const attrs = createStandardAttributes(['class', 'id', 'title']);
|
|
261
|
+
* // Returns:
|
|
262
|
+
* // {
|
|
263
|
+
* // class: {
|
|
264
|
+
* // default: null,
|
|
265
|
+
* // parseHTML: (element) => element.getAttribute('class'),
|
|
266
|
+
* // renderHTML: (attributes) => attributes.class ? { class: attributes.class } : {}
|
|
267
|
+
* // },
|
|
268
|
+
* // ...
|
|
269
|
+
* // }
|
|
270
|
+
*/
|
|
271
|
+
function createStandardAttributes(attributeNames) {
|
|
272
|
+
return Object.fromEntries(attributeNames.map((attr) => [attr, {
|
|
273
|
+
default: null,
|
|
274
|
+
parseHTML: (element) => element.getAttribute(attr),
|
|
275
|
+
renderHTML: (attributes) => {
|
|
276
|
+
if (!attributes[attr]) return {};
|
|
277
|
+
return { [attr]: attributes[attr] };
|
|
278
|
+
}
|
|
279
|
+
}]));
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Common HTML attributes used across multiple extensions.
|
|
283
|
+
* These preserve attributes during HTML import and editing for better
|
|
284
|
+
* fidelity when importing existing email templates.
|
|
285
|
+
*/
|
|
286
|
+
const COMMON_HTML_ATTRIBUTES = [
|
|
287
|
+
"id",
|
|
288
|
+
"class",
|
|
289
|
+
"title",
|
|
290
|
+
"lang",
|
|
291
|
+
"dir",
|
|
292
|
+
"data-id"
|
|
293
|
+
];
|
|
294
|
+
/**
|
|
295
|
+
* Layout-specific HTML attributes used for positioning and sizing.
|
|
296
|
+
*/
|
|
297
|
+
const LAYOUT_ATTRIBUTES = [
|
|
298
|
+
"align",
|
|
299
|
+
"width",
|
|
300
|
+
"height"
|
|
301
|
+
];
|
|
302
|
+
/**
|
|
303
|
+
* Table-specific HTML attributes used for table layout and styling.
|
|
304
|
+
*/
|
|
305
|
+
const TABLE_ATTRIBUTES = [
|
|
306
|
+
"border",
|
|
307
|
+
"cellpadding",
|
|
308
|
+
"cellspacing"
|
|
309
|
+
];
|
|
310
|
+
/**
|
|
311
|
+
* Table cell-specific HTML attributes.
|
|
312
|
+
*/
|
|
313
|
+
const TABLE_CELL_ATTRIBUTES = [
|
|
314
|
+
"valign",
|
|
315
|
+
"bgcolor",
|
|
316
|
+
"colspan",
|
|
317
|
+
"rowspan"
|
|
318
|
+
];
|
|
319
|
+
/**
|
|
320
|
+
* Table header cell-specific HTML attributes.
|
|
321
|
+
* These are additional attributes that only apply to <th> elements.
|
|
322
|
+
*/
|
|
323
|
+
const TABLE_HEADER_ATTRIBUTES = [...TABLE_CELL_ATTRIBUTES, "scope"];
|
|
324
|
+
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/extensions/columns.tsx
|
|
327
|
+
const COLUMN_PARENT_TYPES = [
|
|
328
|
+
"twoColumns",
|
|
329
|
+
"threeColumns",
|
|
330
|
+
"fourColumns"
|
|
331
|
+
];
|
|
332
|
+
const COLUMN_PARENT_SET = new Set(COLUMN_PARENT_TYPES);
|
|
333
|
+
const MAX_COLUMNS_DEPTH = 3;
|
|
334
|
+
function getColumnsDepth(doc, from) {
|
|
335
|
+
const $from = doc.resolve(from);
|
|
336
|
+
let depth = 0;
|
|
337
|
+
for (let d = $from.depth; d > 0; d--) if (COLUMN_PARENT_SET.has($from.node(d).type.name)) depth++;
|
|
338
|
+
return depth;
|
|
339
|
+
}
|
|
340
|
+
const VARIANTS = [
|
|
341
|
+
{
|
|
342
|
+
name: "twoColumns",
|
|
343
|
+
columnCount: 2,
|
|
344
|
+
content: "columnsColumn columnsColumn",
|
|
345
|
+
dataType: "two-columns"
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: "threeColumns",
|
|
349
|
+
columnCount: 3,
|
|
350
|
+
content: "columnsColumn columnsColumn columnsColumn",
|
|
351
|
+
dataType: "three-columns"
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: "fourColumns",
|
|
355
|
+
columnCount: 4,
|
|
356
|
+
content: "columnsColumn{4}",
|
|
357
|
+
dataType: "four-columns"
|
|
358
|
+
}
|
|
359
|
+
];
|
|
360
|
+
const NODE_TYPE_MAP = {
|
|
361
|
+
2: "twoColumns",
|
|
362
|
+
3: "threeColumns",
|
|
363
|
+
4: "fourColumns"
|
|
364
|
+
};
|
|
365
|
+
function createColumnsNode(config, includeCommands) {
|
|
366
|
+
return EmailNode.create({
|
|
367
|
+
name: config.name,
|
|
368
|
+
group: "block",
|
|
369
|
+
content: config.content,
|
|
370
|
+
isolating: true,
|
|
371
|
+
defining: true,
|
|
372
|
+
addAttributes() {
|
|
373
|
+
return createStandardAttributes([...LAYOUT_ATTRIBUTES, ...COMMON_HTML_ATTRIBUTES]);
|
|
374
|
+
},
|
|
375
|
+
parseHTML() {
|
|
376
|
+
return [{ tag: `div[data-type="${config.dataType}"]` }];
|
|
377
|
+
},
|
|
378
|
+
renderHTML({ HTMLAttributes }) {
|
|
379
|
+
return [
|
|
380
|
+
"div",
|
|
381
|
+
mergeAttributes({
|
|
382
|
+
"data-type": config.dataType,
|
|
383
|
+
class: "node-columns"
|
|
384
|
+
}, HTMLAttributes),
|
|
385
|
+
0
|
|
386
|
+
];
|
|
387
|
+
},
|
|
388
|
+
...includeCommands && { addCommands() {
|
|
389
|
+
return { insertColumns: (count) => ({ commands, state }) => {
|
|
390
|
+
if (getColumnsDepth(state.doc, state.selection.from) >= MAX_COLUMNS_DEPTH) return false;
|
|
391
|
+
const nodeType = NODE_TYPE_MAP[count];
|
|
392
|
+
const children = Array.from({ length: count }, () => ({
|
|
393
|
+
type: "columnsColumn",
|
|
394
|
+
content: [{
|
|
395
|
+
type: "paragraph",
|
|
396
|
+
content: []
|
|
397
|
+
}]
|
|
398
|
+
}));
|
|
399
|
+
return commands.insertContent({
|
|
400
|
+
type: nodeType,
|
|
401
|
+
content: children
|
|
402
|
+
});
|
|
403
|
+
} };
|
|
404
|
+
} },
|
|
405
|
+
renderToReactEmail({ children, node, style }) {
|
|
406
|
+
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
407
|
+
return /* @__PURE__ */ jsx(Row, {
|
|
408
|
+
className: node.attrs?.class || void 0,
|
|
409
|
+
style: {
|
|
410
|
+
...style,
|
|
411
|
+
...inlineStyles
|
|
412
|
+
},
|
|
413
|
+
children
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
const TwoColumns = createColumnsNode(VARIANTS[0], true);
|
|
419
|
+
const ThreeColumns = createColumnsNode(VARIANTS[1], false);
|
|
420
|
+
const FourColumns = createColumnsNode(VARIANTS[2], false);
|
|
421
|
+
const ColumnsColumn = EmailNode.create({
|
|
422
|
+
name: "columnsColumn",
|
|
423
|
+
group: "columnsColumn",
|
|
424
|
+
content: "block+",
|
|
425
|
+
isolating: true,
|
|
426
|
+
addAttributes() {
|
|
427
|
+
return { ...createStandardAttributes([...LAYOUT_ATTRIBUTES, ...COMMON_HTML_ATTRIBUTES]) };
|
|
428
|
+
},
|
|
429
|
+
parseHTML() {
|
|
430
|
+
return [{ tag: "div[data-type=\"column\"]" }];
|
|
431
|
+
},
|
|
432
|
+
renderHTML({ HTMLAttributes }) {
|
|
433
|
+
return [
|
|
434
|
+
"div",
|
|
435
|
+
mergeAttributes({
|
|
436
|
+
"data-type": "column",
|
|
437
|
+
class: "node-column"
|
|
438
|
+
}, HTMLAttributes),
|
|
439
|
+
0
|
|
440
|
+
];
|
|
441
|
+
},
|
|
442
|
+
addKeyboardShortcuts() {
|
|
443
|
+
return {
|
|
444
|
+
Backspace: ({ editor }) => {
|
|
445
|
+
const { state } = editor;
|
|
446
|
+
const { selection } = state;
|
|
447
|
+
const { empty, $from } = selection;
|
|
448
|
+
if (!empty) return false;
|
|
449
|
+
for (let depth = $from.depth; depth >= 1; depth--) {
|
|
450
|
+
if ($from.pos !== $from.start(depth)) break;
|
|
451
|
+
const indexInParent = $from.index(depth - 1);
|
|
452
|
+
if (indexInParent === 0) continue;
|
|
453
|
+
const prevNode = $from.node(depth - 1).child(indexInParent - 1);
|
|
454
|
+
if (COLUMN_PARENT_SET.has(prevNode.type.name)) {
|
|
455
|
+
const deleteFrom = $from.before(depth) - prevNode.nodeSize;
|
|
456
|
+
const deleteTo = $from.before(depth);
|
|
457
|
+
editor.view.dispatch(state.tr.delete(deleteFrom, deleteTo));
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
return false;
|
|
463
|
+
},
|
|
464
|
+
"Mod-a": ({ editor }) => {
|
|
465
|
+
const { state } = editor;
|
|
466
|
+
const { $from } = state.selection;
|
|
467
|
+
for (let d = $from.depth; d > 0; d--) {
|
|
468
|
+
if ($from.node(d).type.name !== "columnsColumn") continue;
|
|
469
|
+
const columnStart = $from.start(d);
|
|
470
|
+
const columnEnd = $from.end(d);
|
|
471
|
+
const { from, to } = state.selection;
|
|
472
|
+
if (from === columnStart && to === columnEnd) return false;
|
|
473
|
+
editor.view.dispatch(state.tr.setSelection(TextSelection.create(state.doc, columnStart, columnEnd)));
|
|
474
|
+
return true;
|
|
475
|
+
}
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
},
|
|
480
|
+
renderToReactEmail({ children, node, style }) {
|
|
481
|
+
const inlineStyles = inlineCssToJs(node.attrs?.style);
|
|
482
|
+
const width = node.attrs?.width;
|
|
483
|
+
return /* @__PURE__ */ jsx(Column, {
|
|
484
|
+
className: node.attrs?.class || void 0,
|
|
485
|
+
style: {
|
|
486
|
+
...style,
|
|
487
|
+
...inlineStyles,
|
|
488
|
+
...width ? { width } : {}
|
|
489
|
+
},
|
|
490
|
+
children
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
//#endregion
|
|
496
|
+
export { editorEventBus as _, ThreeColumns as a, COMMON_HTML_ATTRIBUTES as c, TABLE_CELL_ATTRIBUTES as d, TABLE_HEADER_ATTRIBUTES as f, resolveConflictingStyles as g, inlineCssToJs as h, MAX_COLUMNS_DEPTH as i, LAYOUT_ATTRIBUTES as l, EmailNode as m, ColumnsColumn as n, TwoColumns as o, createStandardAttributes as p, FourColumns as r, getColumnsDepth as s, COLUMN_PARENT_TYPES as t, TABLE_ATTRIBUTES as u };
|
|
497
|
+
//# sourceMappingURL=columns-CUxUEHje.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columns-CUxUEHje.mjs","names":[],"sources":["../src/core/event-bus.ts","../src/utils/styles.ts","../src/core/serializer/email-node.ts","../src/utils/attribute-helpers.ts","../src/extensions/columns.tsx"],"sourcesContent":["const EVENT_PREFIX = '@react-email/editor:';\n\n/**\n * Base event map interface for the editor event bus.\n *\n * Components extend this via TypeScript module augmentation:\n * ```ts\n * declare module '@react-email/editor' {\n * interface EditorEventMap {\n * 'my-component:custom-event': { data: string };\n * }\n * }\n * ```\n */\nexport interface EditorEventMap {\n 'bubble-menu:add-link': undefined;\n}\n\nexport type EditorEventName = keyof EditorEventMap;\n\nexport type EditorEventHandler<T extends EditorEventName> = (\n payload: EditorEventMap[T],\n) => void | Promise<void>;\n\nexport interface EditorEventSubscription {\n unsubscribe: () => void;\n}\n\nclass EditorEventBus {\n private prefixEventName(eventName: EditorEventName): string {\n return `${EVENT_PREFIX}${String(eventName)}`;\n }\n\n dispatch<T extends EditorEventName>(\n eventName: T,\n payload: EditorEventMap[T],\n options?: { target?: EventTarget },\n ): void {\n const target = options?.target ?? window;\n const prefixedEventName = this.prefixEventName(eventName);\n const event = new CustomEvent(prefixedEventName, {\n detail: payload,\n bubbles: false,\n cancelable: false,\n });\n target.dispatchEvent(event);\n }\n\n on<T extends EditorEventName>(\n eventName: T,\n handler: EditorEventHandler<T>,\n options?: AddEventListenerOptions & { target?: EventTarget },\n ): EditorEventSubscription {\n const target = options?.target ?? window;\n const prefixedEventName = this.prefixEventName(eventName);\n const abortController = new AbortController();\n\n const wrappedHandler = (event: Event) => {\n const customEvent = event as CustomEvent<EditorEventMap[T]>;\n const result = handler(customEvent.detail);\n\n if (result instanceof Promise) {\n result.catch((error) => {\n console.error(\n `Error in async event handler for ${prefixedEventName}:`,\n { event: customEvent.detail, error },\n );\n });\n }\n };\n\n target.addEventListener(prefixedEventName, wrappedHandler, {\n ...options,\n signal: abortController.signal,\n });\n\n return {\n unsubscribe: () => {\n abortController.abort();\n },\n };\n }\n}\n\nexport const editorEventBus = new EditorEventBus();\n","import type { CssJs } from './types';\n\nconst WHITE_SPACE_REGEX = /\\s+/;\n\nexport const jsToInlineCss = (styleObject: { [key: string]: any }) => {\n const parts: string[] = [];\n\n for (const key in styleObject) {\n const value = styleObject[key];\n if (value !== 0 && value !== undefined && value !== null && value !== '') {\n const KEBAB_CASE_REGEX = /[A-Z]/g;\n const formattedKey = key.replace(\n KEBAB_CASE_REGEX,\n (match) => `-${match.toLowerCase()}`,\n );\n parts.push(`${formattedKey}:${value}`);\n }\n }\n\n return parts.join(';') + (parts.length ? ';' : '');\n};\n\nexport const inlineCssToJs = (\n inlineStyle: string,\n options: { removeUnit?: boolean } = {},\n) => {\n const styleObject: { [key: string]: string } = {};\n\n if (!inlineStyle || inlineStyle === '' || typeof inlineStyle === 'object') {\n return styleObject;\n }\n\n inlineStyle.split(';').forEach((style: string) => {\n if (style.trim()) {\n const [key, value] = style.split(':');\n const valueTrimmed = value?.trim();\n\n if (!valueTrimmed) {\n return;\n }\n\n const formattedKey = key\n .trim()\n .replace(/-\\w/g, (match) => match[1].toUpperCase());\n\n const UNIT_REGEX = /px|%/g;\n const sanitizedValue = options?.removeUnit\n ? valueTrimmed.replace(UNIT_REGEX, '')\n : valueTrimmed;\n\n styleObject[formattedKey] = sanitizedValue;\n }\n });\n\n return styleObject;\n};\n\n/**\n * Expands CSS shorthand properties (margin, padding) into their longhand equivalents.\n * This prevents shorthand properties from overriding specific longhand properties in email clients.\n *\n * @param styles - Style object that may contain shorthand properties\n * @returns New style object with shorthand properties expanded to longhand\n *\n * @example\n * expandShorthandProperties({ margin: '0', paddingTop: '10px' })\n * // Returns: { marginTop: '0', marginRight: '0', marginBottom: '0', marginLeft: '0', paddingTop: '10px' }\n */\nexport function expandShorthandProperties(\n styles: Record<string, string>,\n): Record<string, string> {\n if (!styles || typeof styles !== 'object') {\n return {};\n }\n\n const expanded: Record<string, any> = {};\n\n for (const key in styles) {\n const value = styles[key];\n if (value === undefined || value === null || value === '') {\n continue;\n }\n\n switch (key) {\n case 'margin': {\n const values = parseShorthandValue(value);\n expanded.marginTop = values.top;\n expanded.marginRight = values.right;\n expanded.marginBottom = values.bottom;\n expanded.marginLeft = values.left;\n break;\n }\n case 'padding': {\n const values = parseShorthandValue(value);\n expanded.paddingTop = values.top;\n expanded.paddingRight = values.right;\n expanded.paddingBottom = values.bottom;\n expanded.paddingLeft = values.left;\n break;\n }\n case 'border': {\n const values = convertBorderValue(value);\n expanded.borderStyle = values.style;\n expanded.borderWidth = values.width;\n expanded.borderColor = values.color;\n break;\n }\n case 'borderTopLeftRadius':\n case 'borderTopRightRadius':\n case 'borderBottomLeftRadius':\n case 'borderBottomRightRadius': {\n // Always preserve the longhand property\n expanded[key] = value;\n\n // When all four corners are present and identical, also add the shorthand\n if (\n styles.borderTopLeftRadius &&\n styles.borderTopRightRadius &&\n styles.borderBottomLeftRadius &&\n styles.borderBottomRightRadius\n ) {\n const values = [\n styles.borderTopLeftRadius,\n styles.borderTopRightRadius,\n styles.borderBottomLeftRadius,\n styles.borderBottomRightRadius,\n ];\n\n if (new Set(values).size === 1) {\n expanded.borderRadius = values[0];\n }\n }\n\n break;\n }\n\n default: {\n // Keep all other properties as-is\n expanded[key] = value;\n }\n }\n }\n\n return expanded;\n}\n\n/**\n * Parses CSS shorthand value (1-4 values) into individual side values.\n * Follows CSS specification for shorthand property value parsing.\n *\n * @param value - Shorthand value string (e.g., '0', '10px 20px', '5px 10px 15px 20px')\n * @returns Object with top, right, bottom, left values\n */\nfunction parseShorthandValue(value: string | number): {\n top: string;\n right: string;\n bottom: string;\n left: string;\n} {\n const stringValue = String(value).trim();\n const parts = stringValue.split(WHITE_SPACE_REGEX);\n const len = parts.length;\n\n if (len === 1) {\n return { top: parts[0], right: parts[0], bottom: parts[0], left: parts[0] };\n }\n if (len === 2) {\n return { top: parts[0], right: parts[1], bottom: parts[0], left: parts[1] };\n }\n if (len === 3) {\n return { top: parts[0], right: parts[1], bottom: parts[2], left: parts[1] };\n }\n if (len === 4) {\n return { top: parts[0], right: parts[1], bottom: parts[2], left: parts[3] };\n }\n\n return {\n top: stringValue,\n right: stringValue,\n bottom: stringValue,\n left: stringValue,\n };\n}\n\nfunction convertBorderValue(value: string | number): {\n style: string;\n width: string;\n color: string;\n} {\n const stringValue = String(value).trim();\n const parts = stringValue.split(WHITE_SPACE_REGEX);\n\n switch (parts.length) {\n case 1:\n // border: 1px → all sides\n return {\n style: 'solid',\n width: parts[0],\n color: 'black',\n };\n case 2:\n // border: 1px solid → top/bottom, left/right\n return {\n style: parts[1],\n width: parts[0],\n color: 'black',\n };\n case 3:\n // border: 1px solid #000 → top, left/right, bottom\n return {\n style: parts[1],\n width: parts[0],\n color: parts[2],\n };\n case 4:\n // border: 1px solid #000 #fff → top, right, bottom, left\n return {\n style: parts[1],\n width: parts[0],\n color: parts[2],\n };\n default:\n // Invalid format, return the original value for all sides\n return {\n style: 'solid',\n width: stringValue,\n color: 'black',\n };\n }\n}\n\n/**\n * Resolves conflicts between reset styles and inline styles by expanding\n * shorthand properties (margin, padding) to longhand before merging.\n * This prevents shorthand properties from overriding specific longhand properties.\n *\n * @param resetStyles - Base reset styles that may contain shorthand properties\n * @param inlineStyles - Inline styles that should override reset styles\n * @returns Merged styles with inline styles taking precedence\n */\nexport function resolveConflictingStyles(\n resetStyles: CssJs['reset'],\n inlineStyles: Record<string, string>,\n) {\n const expandedResetStyles = expandShorthandProperties(\n resetStyles as Record<string, string>,\n );\n const expandedInlineStyles = expandShorthandProperties(inlineStyles);\n\n return {\n ...expandedResetStyles,\n ...expandedInlineStyles,\n };\n}\n","import {\n type Editor,\n type JSONContent,\n Node,\n type NodeConfig,\n type NodeType,\n} from '@tiptap/core';\n\nexport type RendererComponent = (props: {\n node: JSONContent;\n style: React.CSSProperties;\n children?: React.ReactNode;\n}) => React.ReactNode;\n\nexport interface EmailNodeConfig<Options, Storage>\n extends NodeConfig<Options, Storage> {\n renderToReactEmail: RendererComponent;\n}\n\ntype ConfigParameter<Options, Storage> = Partial<\n Omit<EmailNodeConfig<Options, Storage>, 'renderToReactEmail'>\n> &\n Pick<EmailNodeConfig<Options, Storage>, 'renderToReactEmail'> &\n ThisType<{\n name: string;\n options: Options;\n storage: Storage;\n editor: Editor;\n type: NodeType;\n parent: (...args: any[]) => any;\n }>;\n\nexport class EmailNode<\n Options = Record<string, never>,\n Storage = Record<string, never>,\n> extends Node<Options, Storage> {\n declare config: EmailNodeConfig<Options, Storage>;\n\n // biome-ignore lint/complexity/noUselessConstructor: This is only meant to change the types for config, hence why we keep it\n constructor(config: ConfigParameter<Options, Storage>) {\n super(config);\n }\n\n /**\n * Create a new Node instance\n * @param config - Node configuration object or a function that returns a configuration object\n */\n static create<O = Record<string, never>, S = Record<string, never>>(\n config: ConfigParameter<O, S> | (() => ConfigParameter<O, S>),\n ) {\n // If the config is a function, execute it to get the configuration object\n const resolvedConfig = typeof config === 'function' ? config() : config;\n return new EmailNode<O, S>(resolvedConfig);\n }\n\n static from<O, S>(\n node: Node<O, S>,\n renderToReactEmail: RendererComponent,\n ): EmailNode<O, S> {\n const customNode = EmailNode.create({} as ConfigParameter<O, S>);\n // This only makes a shallow copy, so if there's nested objects here mutating things will be dangerous\n Object.assign(customNode, { ...node });\n customNode.config = { ...node.config, renderToReactEmail };\n return customNode;\n }\n\n // Subclass return types for configure/extend; safe at runtime. TipTap's Node typings cause TS2416 when returning EmailNode.\n // @ts-expect-error - EmailNode is a valid Node subclass; base typings don't support subclass return types\n configure(options?: Partial<Options>) {\n return super.configure(options) as EmailNode<Options, Storage>;\n }\n\n // @ts-expect-error - same as configure: extend returns EmailNode for chaining; base typings are incompatible\n extend<\n ExtendedOptions = Options,\n ExtendedStorage = Storage,\n ExtendedConfig extends NodeConfig<\n ExtendedOptions,\n ExtendedStorage\n > = EmailNodeConfig<ExtendedOptions, ExtendedStorage>,\n >(\n extendedConfig?:\n | (() => Partial<ExtendedConfig>)\n | (Partial<ExtendedConfig> &\n ThisType<{\n name: string;\n options: ExtendedOptions;\n storage: ExtendedStorage;\n editor: Editor;\n type: NodeType;\n }>),\n ): EmailNode<ExtendedOptions, ExtendedStorage> {\n // If the extended config is a function, execute it to get the configuration object\n const resolvedConfig =\n typeof extendedConfig === 'function' ? extendedConfig() : extendedConfig;\n return super.extend(resolvedConfig) as EmailNode<\n ExtendedOptions,\n ExtendedStorage\n >;\n }\n}\n","/**\n * Creates TipTap attribute definitions for a list of HTML attributes.\n * Each attribute will have the same pattern:\n * - default: null\n * - parseHTML: extracts the attribute from the element\n * - renderHTML: conditionally renders the attribute if it has a value\n *\n * @param attributeNames - Array of HTML attribute names to create definitions for\n * @returns Object with TipTap attribute definitions\n *\n * @example\n * const attrs = createStandardAttributes(['class', 'id', 'title']);\n * // Returns:\n * // {\n * // class: {\n * // default: null,\n * // parseHTML: (element) => element.getAttribute('class'),\n * // renderHTML: (attributes) => attributes.class ? { class: attributes.class } : {}\n * // },\n * // ...\n * // }\n */\nexport function createStandardAttributes(attributeNames: readonly string[]) {\n return Object.fromEntries(\n attributeNames.map((attr) => [\n attr,\n {\n default: null,\n parseHTML: (element: HTMLElement) => element.getAttribute(attr),\n renderHTML: (attributes: Record<string, unknown>) => {\n if (!attributes[attr]) {\n return {};\n }\n\n return {\n [attr]: attributes[attr],\n };\n },\n },\n ]),\n );\n}\n\n/**\n * Common HTML attributes used across multiple extensions.\n * These preserve attributes during HTML import and editing for better\n * fidelity when importing existing email templates.\n */\nexport const COMMON_HTML_ATTRIBUTES = [\n 'id',\n 'class',\n 'title',\n 'lang',\n 'dir',\n 'data-id',\n] as const;\n\n/**\n * Layout-specific HTML attributes used for positioning and sizing.\n */\nexport const LAYOUT_ATTRIBUTES = ['align', 'width', 'height'] as const;\n\n/**\n * Table-specific HTML attributes used for table layout and styling.\n */\nexport const TABLE_ATTRIBUTES = [\n 'border',\n 'cellpadding',\n 'cellspacing',\n] as const;\n\n/**\n * Table cell-specific HTML attributes.\n */\nexport const TABLE_CELL_ATTRIBUTES = [\n 'valign',\n 'bgcolor',\n 'colspan',\n 'rowspan',\n] as const;\n\n/**\n * Table header cell-specific HTML attributes.\n * These are additional attributes that only apply to <th> elements.\n */\nexport const TABLE_HEADER_ATTRIBUTES = [\n ...TABLE_CELL_ATTRIBUTES,\n 'scope',\n] as const;\n","import { Column, Row } from '@react-email/components';\nimport { type CommandProps, mergeAttributes } from '@tiptap/core';\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model';\nimport { TextSelection } from '@tiptap/pm/state';\nimport { EmailNode } from '../core/serializer/email-node';\nimport {\n COMMON_HTML_ATTRIBUTES,\n createStandardAttributes,\n LAYOUT_ATTRIBUTES,\n} from '../utils/attribute-helpers';\nimport { inlineCssToJs } from '../utils/styles';\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n columns: {\n insertColumns: (count: 2 | 3 | 4) => ReturnType;\n };\n }\n}\n\nexport const COLUMN_PARENT_TYPES = [\n 'twoColumns',\n 'threeColumns',\n 'fourColumns',\n] as const;\n\nconst COLUMN_PARENT_SET = new Set<string>(COLUMN_PARENT_TYPES);\n\nexport const MAX_COLUMNS_DEPTH = 3;\n\nexport function getColumnsDepth(doc: ProseMirrorNode, from: number): number {\n const $from = doc.resolve(from);\n let depth = 0;\n for (let d = $from.depth; d > 0; d--) {\n if (COLUMN_PARENT_SET.has($from.node(d).type.name)) {\n depth++;\n }\n }\n return depth;\n}\n\ninterface ColumnsVariantConfig {\n name: (typeof COLUMN_PARENT_TYPES)[number];\n columnCount: number;\n content: string;\n dataType: string;\n}\n\nconst VARIANTS: ColumnsVariantConfig[] = [\n {\n name: 'twoColumns',\n columnCount: 2,\n content: 'columnsColumn columnsColumn',\n dataType: 'two-columns',\n },\n {\n name: 'threeColumns',\n columnCount: 3,\n content: 'columnsColumn columnsColumn columnsColumn',\n dataType: 'three-columns',\n },\n {\n name: 'fourColumns',\n columnCount: 4,\n content: 'columnsColumn{4}',\n dataType: 'four-columns',\n },\n];\n\nconst NODE_TYPE_MAP: Record<number, (typeof COLUMN_PARENT_TYPES)[number]> = {\n 2: 'twoColumns',\n 3: 'threeColumns',\n 4: 'fourColumns',\n};\n\nfunction createColumnsNode(\n config: ColumnsVariantConfig,\n includeCommands: boolean,\n) {\n return EmailNode.create({\n name: config.name,\n group: 'block',\n content: config.content,\n isolating: true,\n defining: true,\n\n addAttributes() {\n return createStandardAttributes([\n ...LAYOUT_ATTRIBUTES,\n ...COMMON_HTML_ATTRIBUTES,\n ]);\n },\n\n parseHTML() {\n return [{ tag: `div[data-type=\"${config.dataType}\"]` }];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'div',\n mergeAttributes(\n { 'data-type': config.dataType, class: 'node-columns' },\n HTMLAttributes,\n ),\n 0,\n ];\n },\n\n ...(includeCommands && {\n addCommands() {\n return {\n insertColumns:\n (count: 2 | 3 | 4) =>\n ({\n commands,\n state,\n }: CommandProps & {\n state: { doc: ProseMirrorNode; selection: { from: number } };\n }) => {\n if (\n getColumnsDepth(state.doc, state.selection.from) >=\n MAX_COLUMNS_DEPTH\n ) {\n return false;\n }\n const nodeType = NODE_TYPE_MAP[count];\n const children = Array.from({ length: count }, () => ({\n type: 'columnsColumn',\n content: [{ type: 'paragraph', content: [] }],\n }));\n return commands.insertContent({\n type: nodeType,\n content: children,\n });\n },\n };\n },\n }),\n\n renderToReactEmail({ children, node, style }) {\n const inlineStyles = inlineCssToJs(node.attrs?.style);\n return (\n <Row\n className={node.attrs?.class || undefined}\n style={{ ...style, ...inlineStyles }}\n >\n {children}\n </Row>\n );\n },\n });\n}\n\nexport const TwoColumns = createColumnsNode(VARIANTS[0], true);\nexport const ThreeColumns = createColumnsNode(VARIANTS[1], false);\nexport const FourColumns = createColumnsNode(VARIANTS[2], false);\n\nexport const ColumnsColumn = EmailNode.create({\n name: 'columnsColumn',\n group: 'columnsColumn',\n content: 'block+',\n isolating: true,\n\n addAttributes() {\n return {\n ...createStandardAttributes([\n ...LAYOUT_ATTRIBUTES,\n ...COMMON_HTML_ATTRIBUTES,\n ]),\n };\n },\n\n parseHTML() {\n return [{ tag: 'div[data-type=\"column\"]' }];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'div',\n mergeAttributes(\n { 'data-type': 'column', class: 'node-column' },\n HTMLAttributes,\n ),\n 0,\n ];\n },\n\n addKeyboardShortcuts() {\n return {\n Backspace: ({ editor }) => {\n const { state } = editor;\n const { selection } = state;\n const { empty, $from } = selection;\n\n if (!empty) return false;\n\n for (let depth = $from.depth; depth >= 1; depth--) {\n if ($from.pos !== $from.start(depth)) break;\n\n const indexInParent = $from.index(depth - 1);\n\n if (indexInParent === 0) continue;\n\n const parent = $from.node(depth - 1);\n const prevNode = parent.child(indexInParent - 1);\n\n if (COLUMN_PARENT_SET.has(prevNode.type.name)) {\n const deleteFrom = $from.before(depth) - prevNode.nodeSize;\n const deleteTo = $from.before(depth);\n editor.view.dispatch(state.tr.delete(deleteFrom, deleteTo));\n return true;\n }\n\n break;\n }\n\n return false;\n },\n 'Mod-a': ({ editor }) => {\n const { state } = editor;\n const { $from } = state.selection;\n\n for (let d = $from.depth; d > 0; d--) {\n if ($from.node(d).type.name !== 'columnsColumn') {\n continue;\n }\n\n const columnStart = $from.start(d);\n const columnEnd = $from.end(d);\n const { from, to } = state.selection;\n\n if (from === columnStart && to === columnEnd) {\n return false;\n }\n\n editor.view.dispatch(\n state.tr.setSelection(\n TextSelection.create(state.doc, columnStart, columnEnd),\n ),\n );\n return true;\n }\n\n return false;\n },\n };\n },\n\n renderToReactEmail({ children, node, style }) {\n const inlineStyles = inlineCssToJs(node.attrs?.style);\n const width = node.attrs?.width;\n return (\n <Column\n className={node.attrs?.class || undefined}\n style={{\n ...style,\n ...inlineStyles,\n ...(width ? { width } : {}),\n }}\n >\n {children}\n </Column>\n );\n },\n});\n"],"mappings":";;;;;;AAAA,MAAM,eAAe;AA4BrB,IAAM,iBAAN,MAAqB;CACnB,AAAQ,gBAAgB,WAAoC;AAC1D,SAAO,GAAG,eAAe,OAAO,UAAU;;CAG5C,SACE,WACA,SACA,SACM;EACN,MAAM,SAAS,SAAS,UAAU;EAClC,MAAM,oBAAoB,KAAK,gBAAgB,UAAU;EACzD,MAAM,QAAQ,IAAI,YAAY,mBAAmB;GAC/C,QAAQ;GACR,SAAS;GACT,YAAY;GACb,CAAC;AACF,SAAO,cAAc,MAAM;;CAG7B,GACE,WACA,SACA,SACyB;EACzB,MAAM,SAAS,SAAS,UAAU;EAClC,MAAM,oBAAoB,KAAK,gBAAgB,UAAU;EACzD,MAAM,kBAAkB,IAAI,iBAAiB;EAE7C,MAAM,kBAAkB,UAAiB;GACvC,MAAM,cAAc;GACpB,M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