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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/columns-BXN-NNd4.cjs +450 -0
  2. package/dist/columns-Cos2lqfu.mjs +329 -0
  3. package/dist/columns-Cos2lqfu.mjs.map +1 -0
  4. package/dist/core/index.cjs +8 -0
  5. package/dist/core/index.d.cts +2 -0
  6. package/dist/core/index.d.mts +2 -0
  7. package/dist/core/index.mjs +4 -0
  8. package/dist/core-DVox_fis.cjs +2159 -0
  9. package/dist/core-mUMTkab3.mjs +1914 -0
  10. package/dist/core-mUMTkab3.mjs.map +1 -0
  11. package/dist/extensions/index.cjs +48 -0
  12. package/dist/extensions/index.d.cts +395 -0
  13. package/dist/extensions/index.d.cts.map +1 -0
  14. package/dist/extensions/index.d.mts +395 -0
  15. package/dist/extensions/index.d.mts.map +1 -0
  16. package/dist/extensions/index.mjs +5 -0
  17. package/dist/global-content-BRvA4PRG.cjs +89 -0
  18. package/dist/global-content-kdUzYcsA.mjs +78 -0
  19. package/dist/global-content-kdUzYcsA.mjs.map +1 -0
  20. package/dist/index-jGyVEd5q.d.cts +131 -0
  21. package/dist/index-jGyVEd5q.d.cts.map +1 -0
  22. package/dist/index-ozCcANmD.d.mts +131 -0
  23. package/dist/index-ozCcANmD.d.mts.map +1 -0
  24. package/dist/plugins/index.cjs +747 -0
  25. package/dist/plugins/index.d.cts +79 -0
  26. package/dist/plugins/index.d.cts.map +1 -0
  27. package/dist/plugins/index.d.mts +79 -0
  28. package/dist/plugins/index.d.mts.map +1 -0
  29. package/dist/plugins/index.mjs +742 -0
  30. package/dist/plugins/index.mjs.map +1 -0
  31. package/dist/set-text-alignment-BO24ieeE.mjs +19 -0
  32. package/dist/set-text-alignment-BO24ieeE.mjs.map +1 -0
  33. package/dist/set-text-alignment-CbECklB4.cjs +24 -0
  34. package/dist/styles-C-cCyJCn.cjs +211 -0
  35. package/dist/styles-DLviD0JK.mjs +194 -0
  36. package/dist/styles-DLviD0JK.mjs.map +1 -0
  37. package/dist/ui/bubble-menu/bubble-menu.css +146 -0
  38. package/dist/ui/button-bubble-menu/button-bubble-menu.css +29 -0
  39. package/dist/ui/image-bubble-menu/image-bubble-menu.css +29 -0
  40. package/dist/ui/index.cjs +1646 -0
  41. package/dist/ui/index.d.cts +668 -0
  42. package/dist/ui/index.d.cts.map +1 -0
  43. package/dist/ui/index.d.mts +668 -0
  44. package/dist/ui/index.d.mts.map +1 -0
  45. package/dist/ui/index.mjs +1584 -0
  46. package/dist/ui/index.mjs.map +1 -0
  47. package/dist/ui/link-bubble-menu/link-bubble-menu.css +66 -0
  48. package/dist/ui/slash-command/slash-command.css +44 -0
  49. package/dist/ui/themes/default.css +769 -0
  50. package/dist/utils/index.cjs +3 -0
  51. package/dist/utils/index.d.cts +7 -0
  52. package/dist/utils/index.d.cts.map +1 -0
  53. package/dist/utils/index.d.mts +7 -0
  54. package/dist/utils/index.d.mts.map +1 -0
  55. package/dist/utils/index.mjs +3 -0
  56. package/package.json +96 -23
  57. package/dist/index.d.mts +0 -273
  58. package/dist/index.d.mts.map +0 -1
  59. package/dist/index.d.ts +0 -273
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.js +0 -1394
  62. package/dist/index.mjs +0 -1346
  63. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,450 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ const require_styles = require('./styles-C-cCyJCn.cjs');
29
+ let _react_email_components = require("@react-email/components");
30
+ let react_jsx_runtime = require("react/jsx-runtime");
31
+ let _tiptap_core = require("@tiptap/core");
32
+ let _tiptap_pm_state = require("@tiptap/pm/state");
33
+
34
+ //#region src/core/event-bus.ts
35
+ const EVENT_PREFIX = "@react-email/editor:";
36
+ var EditorEventBus = class {
37
+ prefixEventName(eventName) {
38
+ return `${EVENT_PREFIX}${String(eventName)}`;
39
+ }
40
+ dispatch(eventName, payload, options) {
41
+ const target = options?.target ?? window;
42
+ const prefixedEventName = this.prefixEventName(eventName);
43
+ const event = new CustomEvent(prefixedEventName, {
44
+ detail: payload,
45
+ bubbles: false,
46
+ cancelable: false
47
+ });
48
+ target.dispatchEvent(event);
49
+ }
50
+ on(eventName, handler, options) {
51
+ const target = options?.target ?? window;
52
+ const prefixedEventName = this.prefixEventName(eventName);
53
+ const abortController = new AbortController();
54
+ const wrappedHandler = (event) => {
55
+ const customEvent = event;
56
+ const result = handler(customEvent.detail);
57
+ if (result instanceof Promise) result.catch((error) => {
58
+ console.error(`Error in async event handler for ${prefixedEventName}:`, {
59
+ event: customEvent.detail,
60
+ error
61
+ });
62
+ });
63
+ };
64
+ target.addEventListener(prefixedEventName, wrappedHandler, {
65
+ ...options,
66
+ signal: abortController.signal
67
+ });
68
+ return { unsubscribe: () => {
69
+ abortController.abort();
70
+ } };
71
+ }
72
+ };
73
+ const editorEventBus = new EditorEventBus();
74
+
75
+ //#endregion
76
+ //#region src/core/serializer/email-node.ts
77
+ var EmailNode = class EmailNode extends _tiptap_core.Node {
78
+ constructor(config) {
79
+ super(config);
80
+ }
81
+ /**
82
+ * Create a new Node instance
83
+ * @param config - Node configuration object or a function that returns a configuration object
84
+ */
85
+ static create(config) {
86
+ return new EmailNode(typeof config === "function" ? config() : config);
87
+ }
88
+ static from(node, renderToReactEmail) {
89
+ const customNode = EmailNode.create({});
90
+ Object.assign(customNode, { ...node });
91
+ customNode.config = {
92
+ ...node.config,
93
+ renderToReactEmail
94
+ };
95
+ return customNode;
96
+ }
97
+ configure(options) {
98
+ return super.configure(options);
99
+ }
100
+ extend(extendedConfig) {
101
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
102
+ return super.extend(resolvedConfig);
103
+ }
104
+ };
105
+
106
+ //#endregion
107
+ //#region src/utils/attribute-helpers.ts
108
+ /**
109
+ * Creates TipTap attribute definitions for a list of HTML attributes.
110
+ * Each attribute will have the same pattern:
111
+ * - default: null
112
+ * - parseHTML: extracts the attribute from the element
113
+ * - renderHTML: conditionally renders the attribute if it has a value
114
+ *
115
+ * @param attributeNames - Array of HTML attribute names to create definitions for
116
+ * @returns Object with TipTap attribute definitions
117
+ *
118
+ * @example
119
+ * const attrs = createStandardAttributes(['class', 'id', 'title']);
120
+ * // Returns:
121
+ * // {
122
+ * // class: {
123
+ * // default: null,
124
+ * // parseHTML: (element) => element.getAttribute('class'),
125
+ * // renderHTML: (attributes) => attributes.class ? { class: attributes.class } : {}
126
+ * // },
127
+ * // ...
128
+ * // }
129
+ */
130
+ function createStandardAttributes(attributeNames) {
131
+ return Object.fromEntries(attributeNames.map((attr) => [attr, {
132
+ default: null,
133
+ parseHTML: (element) => element.getAttribute(attr),
134
+ renderHTML: (attributes) => {
135
+ if (!attributes[attr]) return {};
136
+ return { [attr]: attributes[attr] };
137
+ }
138
+ }]));
139
+ }
140
+ /**
141
+ * Common HTML attributes used across multiple extensions.
142
+ * These preserve attributes during HTML import and editing for better
143
+ * fidelity when importing existing email templates.
144
+ */
145
+ const COMMON_HTML_ATTRIBUTES = [
146
+ "id",
147
+ "class",
148
+ "title",
149
+ "lang",
150
+ "dir",
151
+ "data-id"
152
+ ];
153
+ /**
154
+ * Layout-specific HTML attributes used for positioning and sizing.
155
+ */
156
+ const LAYOUT_ATTRIBUTES = [
157
+ "align",
158
+ "width",
159
+ "height"
160
+ ];
161
+ /**
162
+ * Table-specific HTML attributes used for table layout and styling.
163
+ */
164
+ const TABLE_ATTRIBUTES = [
165
+ "border",
166
+ "cellpadding",
167
+ "cellspacing"
168
+ ];
169
+ /**
170
+ * Table cell-specific HTML attributes.
171
+ */
172
+ const TABLE_CELL_ATTRIBUTES = [
173
+ "valign",
174
+ "bgcolor",
175
+ "colspan",
176
+ "rowspan"
177
+ ];
178
+ /**
179
+ * Table header cell-specific HTML attributes.
180
+ * These are additional attributes that only apply to <th> elements.
181
+ */
182
+ const TABLE_HEADER_ATTRIBUTES = [...TABLE_CELL_ATTRIBUTES, "scope"];
183
+
184
+ //#endregion
185
+ //#region src/extensions/columns.tsx
186
+ const COLUMN_PARENT_TYPES = [
187
+ "twoColumns",
188
+ "threeColumns",
189
+ "fourColumns"
190
+ ];
191
+ const COLUMN_PARENT_SET = new Set(COLUMN_PARENT_TYPES);
192
+ const MAX_COLUMNS_DEPTH = 3;
193
+ function getColumnsDepth(doc, from) {
194
+ const $from = doc.resolve(from);
195
+ let depth = 0;
196
+ for (let d = $from.depth; d > 0; d--) if (COLUMN_PARENT_SET.has($from.node(d).type.name)) depth++;
197
+ return depth;
198
+ }
199
+ const VARIANTS = [
200
+ {
201
+ name: "twoColumns",
202
+ columnCount: 2,
203
+ content: "columnsColumn columnsColumn",
204
+ dataType: "two-columns"
205
+ },
206
+ {
207
+ name: "threeColumns",
208
+ columnCount: 3,
209
+ content: "columnsColumn columnsColumn columnsColumn",
210
+ dataType: "three-columns"
211
+ },
212
+ {
213
+ name: "fourColumns",
214
+ columnCount: 4,
215
+ content: "columnsColumn{4}",
216
+ dataType: "four-columns"
217
+ }
218
+ ];
219
+ const NODE_TYPE_MAP = {
220
+ 2: "twoColumns",
221
+ 3: "threeColumns",
222
+ 4: "fourColumns"
223
+ };
224
+ function createColumnsNode(config, includeCommands) {
225
+ return EmailNode.create({
226
+ name: config.name,
227
+ group: "block",
228
+ content: config.content,
229
+ isolating: true,
230
+ defining: true,
231
+ addAttributes() {
232
+ return createStandardAttributes([...LAYOUT_ATTRIBUTES, ...COMMON_HTML_ATTRIBUTES]);
233
+ },
234
+ parseHTML() {
235
+ return [{ tag: `div[data-type="${config.dataType}"]` }];
236
+ },
237
+ renderHTML({ HTMLAttributes }) {
238
+ return [
239
+ "div",
240
+ (0, _tiptap_core.mergeAttributes)({
241
+ "data-type": config.dataType,
242
+ class: "node-columns"
243
+ }, HTMLAttributes),
244
+ 0
245
+ ];
246
+ },
247
+ ...includeCommands && { addCommands() {
248
+ return { insertColumns: (count) => ({ commands, state }) => {
249
+ if (getColumnsDepth(state.doc, state.selection.from) >= MAX_COLUMNS_DEPTH) return false;
250
+ const nodeType = NODE_TYPE_MAP[count];
251
+ const children = Array.from({ length: count }, () => ({
252
+ type: "columnsColumn",
253
+ content: [{
254
+ type: "paragraph",
255
+ content: []
256
+ }]
257
+ }));
258
+ return commands.insertContent({
259
+ type: nodeType,
260
+ content: children
261
+ });
262
+ } };
263
+ } },
264
+ renderToReactEmail({ children, node, style }) {
265
+ const inlineStyles = require_styles.inlineCssToJs(node.attrs?.style);
266
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, {
267
+ className: node.attrs?.class || void 0,
268
+ style: {
269
+ ...style,
270
+ ...inlineStyles
271
+ },
272
+ children
273
+ });
274
+ }
275
+ });
276
+ }
277
+ const TwoColumns = createColumnsNode(VARIANTS[0], true);
278
+ const ThreeColumns = createColumnsNode(VARIANTS[1], false);
279
+ const FourColumns = createColumnsNode(VARIANTS[2], false);
280
+ const ColumnsColumn = EmailNode.create({
281
+ name: "columnsColumn",
282
+ group: "columnsColumn",
283
+ content: "block+",
284
+ isolating: true,
285
+ addAttributes() {
286
+ return { ...createStandardAttributes([...LAYOUT_ATTRIBUTES, ...COMMON_HTML_ATTRIBUTES]) };
287
+ },
288
+ parseHTML() {
289
+ return [{ tag: "div[data-type=\"column\"]" }];
290
+ },
291
+ renderHTML({ HTMLAttributes }) {
292
+ return [
293
+ "div",
294
+ (0, _tiptap_core.mergeAttributes)({
295
+ "data-type": "column",
296
+ class: "node-column"
297
+ }, HTMLAttributes),
298
+ 0
299
+ ];
300
+ },
301
+ addKeyboardShortcuts() {
302
+ return {
303
+ Backspace: ({ editor }) => {
304
+ const { state } = editor;
305
+ const { selection } = state;
306
+ const { empty, $from } = selection;
307
+ if (!empty) return false;
308
+ for (let depth = $from.depth; depth >= 1; depth--) {
309
+ if ($from.pos !== $from.start(depth)) break;
310
+ const indexInParent = $from.index(depth - 1);
311
+ if (indexInParent === 0) continue;
312
+ const prevNode = $from.node(depth - 1).child(indexInParent - 1);
313
+ if (COLUMN_PARENT_SET.has(prevNode.type.name)) {
314
+ const deleteFrom = $from.before(depth) - prevNode.nodeSize;
315
+ const deleteTo = $from.before(depth);
316
+ editor.view.dispatch(state.tr.delete(deleteFrom, deleteTo));
317
+ return true;
318
+ }
319
+ break;
320
+ }
321
+ return false;
322
+ },
323
+ "Mod-a": ({ editor }) => {
324
+ const { state } = editor;
325
+ const { $from } = state.selection;
326
+ for (let d = $from.depth; d > 0; d--) {
327
+ if ($from.node(d).type.name !== "columnsColumn") continue;
328
+ const columnStart = $from.start(d);
329
+ const columnEnd = $from.end(d);
330
+ const { from, to } = state.selection;
331
+ if (from === columnStart && to === columnEnd) return false;
332
+ editor.view.dispatch(state.tr.setSelection(_tiptap_pm_state.TextSelection.create(state.doc, columnStart, columnEnd)));
333
+ return true;
334
+ }
335
+ return false;
336
+ }
337
+ };
338
+ },
339
+ renderToReactEmail({ children, node, style }) {
340
+ const inlineStyles = require_styles.inlineCssToJs(node.attrs?.style);
341
+ const width = node.attrs?.width;
342
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
343
+ className: node.attrs?.class || void 0,
344
+ style: {
345
+ ...style,
346
+ ...inlineStyles,
347
+ ...width ? { width } : {}
348
+ },
349
+ children
350
+ });
351
+ }
352
+ });
353
+
354
+ //#endregion
355
+ Object.defineProperty(exports, 'COLUMN_PARENT_TYPES', {
356
+ enumerable: true,
357
+ get: function () {
358
+ return COLUMN_PARENT_TYPES;
359
+ }
360
+ });
361
+ Object.defineProperty(exports, 'COMMON_HTML_ATTRIBUTES', {
362
+ enumerable: true,
363
+ get: function () {
364
+ return COMMON_HTML_ATTRIBUTES;
365
+ }
366
+ });
367
+ Object.defineProperty(exports, 'ColumnsColumn', {
368
+ enumerable: true,
369
+ get: function () {
370
+ return ColumnsColumn;
371
+ }
372
+ });
373
+ Object.defineProperty(exports, 'EmailNode', {
374
+ enumerable: true,
375
+ get: function () {
376
+ return EmailNode;
377
+ }
378
+ });
379
+ Object.defineProperty(exports, 'FourColumns', {
380
+ enumerable: true,
381
+ get: function () {
382
+ return FourColumns;
383
+ }
384
+ });
385
+ Object.defineProperty(exports, 'LAYOUT_ATTRIBUTES', {
386
+ enumerable: true,
387
+ get: function () {
388
+ return LAYOUT_ATTRIBUTES;
389
+ }
390
+ });
391
+ Object.defineProperty(exports, 'MAX_COLUMNS_DEPTH', {
392
+ enumerable: true,
393
+ get: function () {
394
+ return MAX_COLUMNS_DEPTH;
395
+ }
396
+ });
397
+ Object.defineProperty(exports, 'TABLE_ATTRIBUTES', {
398
+ enumerable: true,
399
+ get: function () {
400
+ return TABLE_ATTRIBUTES;
401
+ }
402
+ });
403
+ Object.defineProperty(exports, 'TABLE_CELL_ATTRIBUTES', {
404
+ enumerable: true,
405
+ get: function () {
406
+ return TABLE_CELL_ATTRIBUTES;
407
+ }
408
+ });
409
+ Object.defineProperty(exports, 'TABLE_HEADER_ATTRIBUTES', {
410
+ enumerable: true,
411
+ get: function () {
412
+ return TABLE_HEADER_ATTRIBUTES;
413
+ }
414
+ });
415
+ Object.defineProperty(exports, 'ThreeColumns', {
416
+ enumerable: true,
417
+ get: function () {
418
+ return ThreeColumns;
419
+ }
420
+ });
421
+ Object.defineProperty(exports, 'TwoColumns', {
422
+ enumerable: true,
423
+ get: function () {
424
+ return TwoColumns;
425
+ }
426
+ });
427
+ Object.defineProperty(exports, '__toESM', {
428
+ enumerable: true,
429
+ get: function () {
430
+ return __toESM;
431
+ }
432
+ });
433
+ Object.defineProperty(exports, 'createStandardAttributes', {
434
+ enumerable: true,
435
+ get: function () {
436
+ return createStandardAttributes;
437
+ }
438
+ });
439
+ Object.defineProperty(exports, 'editorEventBus', {
440
+ enumerable: true,
441
+ get: function () {
442
+ return editorEventBus;
443
+ }
444
+ });
445
+ Object.defineProperty(exports, 'getColumnsDepth', {
446
+ enumerable: true,
447
+ get: function () {
448
+ return getColumnsDepth;
449
+ }
450
+ });