@react-email/editor 0.0.0-experimental.7 → 1.0.0-canary.51

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