@react-email/editor 0.0.0-experimental.26 → 0.0.0-experimental.27

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 (44) hide show
  1. package/dist/{columns-ZSaLdkg9.cjs → columns-BXN-NNd4.cjs} +3 -183
  2. package/dist/{columns-CUxUEHje.mjs → columns-Cos2lqfu.mjs} +3 -171
  3. package/dist/columns-Cos2lqfu.mjs.map +1 -0
  4. package/dist/core/index.cjs +2 -2
  5. package/dist/core/index.d.cts +1 -1
  6. package/dist/core/index.d.mts +1 -1
  7. package/dist/core/index.mjs +2 -2
  8. package/dist/{core-DpfUR_iP.cjs → core-B1NP2Drs.cjs} +25 -109
  9. package/dist/{core-C0EkaM-K.mjs → core-Dr1J3aZd.mjs} +5 -77
  10. package/dist/core-Dr1J3aZd.mjs.map +1 -0
  11. package/dist/extensions/index.cjs +5 -4
  12. package/dist/extensions/index.d.cts +1 -1
  13. package/dist/extensions/index.d.mts +1 -1
  14. package/dist/extensions/index.mjs +3 -2
  15. package/dist/global-content-BRvA4PRG.cjs +89 -0
  16. package/dist/global-content-kdUzYcsA.mjs +78 -0
  17. package/dist/global-content-kdUzYcsA.mjs.map +1 -0
  18. package/dist/{index-BPjgJSQh.d.cts → index-jGyVEd5q.d.cts} +1 -1
  19. package/dist/{index-BPjgJSQh.d.cts.map → index-jGyVEd5q.d.cts.map} +1 -1
  20. package/dist/{index-4EvOA-Ll.d.mts → index-ozCcANmD.d.mts} +1 -1
  21. package/dist/{index-4EvOA-Ll.d.mts.map → index-ozCcANmD.d.mts.map} +1 -1
  22. package/dist/plugins/index.cjs +747 -0
  23. package/dist/plugins/index.d.cts +79 -0
  24. package/dist/plugins/index.d.cts.map +1 -0
  25. package/dist/plugins/index.d.mts +79 -0
  26. package/dist/plugins/index.d.mts.map +1 -0
  27. package/dist/plugins/index.mjs +742 -0
  28. package/dist/plugins/index.mjs.map +1 -0
  29. package/dist/{set-text-alignment-DZvgnbvz.mjs → set-text-alignment-BO24ieeE.mjs} +1 -1
  30. package/dist/{set-text-alignment-DZvgnbvz.mjs.map → set-text-alignment-BO24ieeE.mjs.map} +1 -1
  31. package/dist/styles-C-cCyJCn.cjs +211 -0
  32. package/dist/styles-DLviD0JK.mjs +194 -0
  33. package/dist/styles-DLviD0JK.mjs.map +1 -0
  34. package/dist/ui/index.cjs +2 -2
  35. package/dist/ui/index.d.cts +42 -42
  36. package/dist/ui/index.d.cts.map +1 -1
  37. package/dist/ui/index.d.mts +42 -42
  38. package/dist/ui/index.mjs +2 -2
  39. package/dist/utils/index.cjs +1 -1
  40. package/dist/utils/index.mjs +1 -1
  41. package/package.json +13 -3
  42. package/dist/columns-CUxUEHje.mjs.map +0 -1
  43. package/dist/core-C0EkaM-K.mjs.map +0 -1
  44. /package/dist/{set-text-alignment-Bx3bPteH.cjs → set-text-alignment-CbECklB4.cjs} +0 -0
@@ -0,0 +1,742 @@
1
+ import { t as ensureBorderStyleFallback } from "../styles-DLviD0JK.mjs";
2
+ import { n as getGlobalContent } from "../global-content-kdUzYcsA.mjs";
3
+ import { Body, Head, Html, Preview, Section } from "@react-email/components";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { Extension } from "@tiptap/core";
6
+ import { useEditorState } from "@tiptap/react";
7
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
8
+
9
+ //#region src/plugins/email-theming/css-transforms.ts
10
+ function transformToCssJs(styleArray) {
11
+ const cssJS = {};
12
+ if (!Array.isArray(styleArray)) return cssJS;
13
+ for (const style of styleArray) for (const input of style.inputs) {
14
+ let value = input.value;
15
+ if (input.unit && typeof value === "number") if (input.prop === "fontSize") value = `${value / 13}em`;
16
+ else value = `${value}${input.unit}`;
17
+ if (!input.classReference) continue;
18
+ if (!cssJS[input.classReference]) cssJS[input.classReference] = {};
19
+ if (input.prop === "h-padding") {
20
+ cssJS[input.classReference].paddingLeft = value;
21
+ cssJS[input.classReference].paddingRight = value;
22
+ continue;
23
+ }
24
+ cssJS[input.classReference][input.prop] = value;
25
+ }
26
+ for (const key of Object.keys(cssJS)) ensureBorderStyleFallback(cssJS[key]);
27
+ return cssJS;
28
+ }
29
+ function mergeCssJs(original, newCssJs) {
30
+ const merged = { ...original };
31
+ for (const key in newCssJs) {
32
+ const keyType = key;
33
+ if (Object.hasOwn(merged, key) && typeof merged[keyType] === "object" && !Array.isArray(merged[keyType])) merged[keyType] = {
34
+ ...merged[keyType],
35
+ ...newCssJs[keyType]
36
+ };
37
+ else merged[keyType] = newCssJs[keyType];
38
+ }
39
+ return merged;
40
+ }
41
+ function injectThemeCss(styles, options = {}) {
42
+ const container = options.scopeSelector ?? ".tiptap-extended .tiptap.ProseMirror";
43
+ const prefix = ".node-";
44
+ const styleId = options.styleId ?? "tiptap-extended-theme-css";
45
+ const css = Object.entries(styles).reduce((acc, [key, value]) => {
46
+ return `${acc}${`${container} ${prefix}${key}`}{${Object.entries(value).reduce((acc$1, [prop, val]) => {
47
+ return `${acc$1}${prop.replace(/([A-Z])/g, "-$1").toLowerCase()}:${val};`;
48
+ }, "")}}`;
49
+ }, "");
50
+ let styleTag = document.getElementById(styleId);
51
+ if (!styleTag) {
52
+ styleTag = document.createElement("style");
53
+ styleTag.textContent = css;
54
+ styleTag.id = styleId;
55
+ document.head.appendChild(styleTag);
56
+ return;
57
+ }
58
+ styleTag.textContent = css;
59
+ }
60
+ function injectGlobalPlainCss(css, options = {}) {
61
+ if (!css) return;
62
+ const styleId = options.styleId ?? "global-editor-style";
63
+ const container = options.scopeSelector ?? ".tiptap-extended .ProseMirror";
64
+ let styleElement = document.getElementById(styleId);
65
+ if (!styleElement) {
66
+ styleElement = document.createElement("style");
67
+ styleElement.id = styleId;
68
+ document.head.appendChild(styleElement);
69
+ }
70
+ const cleanedCSS = css.replace(/@media\s?\(prefers-color-scheme:\s?dark\)\s?{([\s\S]+?})\s*}/g, "");
71
+ styleElement.textContent = `${container} { ${cleanedCSS} }`;
72
+ }
73
+
74
+ //#endregion
75
+ //#region src/plugins/email-theming/themes.ts
76
+ const THEME_BASIC = [
77
+ {
78
+ id: "body",
79
+ title: "Background",
80
+ classReference: "body",
81
+ inputs: []
82
+ },
83
+ {
84
+ id: "container",
85
+ title: "Content",
86
+ classReference: "container",
87
+ inputs: [
88
+ {
89
+ label: "Align",
90
+ type: "select",
91
+ value: "left",
92
+ options: {
93
+ left: "Left",
94
+ center: "Center",
95
+ right: "Right"
96
+ },
97
+ prop: "align",
98
+ classReference: "container"
99
+ },
100
+ {
101
+ label: "Width",
102
+ type: "number",
103
+ value: 600,
104
+ unit: "px",
105
+ prop: "width",
106
+ classReference: "container"
107
+ },
108
+ {
109
+ label: "Padding Left",
110
+ type: "number",
111
+ value: 0,
112
+ unit: "px",
113
+ prop: "paddingLeft",
114
+ classReference: "container"
115
+ },
116
+ {
117
+ label: "Padding Right",
118
+ type: "number",
119
+ value: 0,
120
+ unit: "px",
121
+ prop: "paddingRight",
122
+ classReference: "container"
123
+ }
124
+ ]
125
+ },
126
+ {
127
+ id: "typography",
128
+ title: "Typography",
129
+ classReference: "body",
130
+ inputs: [{
131
+ label: "Font size",
132
+ type: "number",
133
+ value: 14,
134
+ unit: "px",
135
+ prop: "fontSize",
136
+ classReference: "body"
137
+ }, {
138
+ label: "Line Height",
139
+ type: "number",
140
+ value: 155,
141
+ unit: "%",
142
+ prop: "lineHeight",
143
+ classReference: "container"
144
+ }]
145
+ },
146
+ {
147
+ id: "link",
148
+ title: "Link",
149
+ classReference: "link",
150
+ inputs: [{
151
+ label: "Color",
152
+ type: "color",
153
+ value: "#0670DB",
154
+ prop: "color",
155
+ classReference: "link"
156
+ }, {
157
+ label: "Decoration",
158
+ type: "select",
159
+ value: "underline",
160
+ prop: "textDecoration",
161
+ options: {
162
+ underline: "Underline",
163
+ none: "None"
164
+ },
165
+ classReference: "link"
166
+ }]
167
+ },
168
+ {
169
+ id: "image",
170
+ title: "Image",
171
+ classReference: "image",
172
+ inputs: [{
173
+ label: "Border radius",
174
+ type: "number",
175
+ value: 8,
176
+ unit: "px",
177
+ prop: "borderRadius",
178
+ classReference: "image"
179
+ }]
180
+ },
181
+ {
182
+ id: "button",
183
+ title: "Button",
184
+ classReference: "button",
185
+ inputs: [
186
+ {
187
+ label: "Background",
188
+ type: "color",
189
+ value: "#000000",
190
+ prop: "backgroundColor",
191
+ classReference: "button"
192
+ },
193
+ {
194
+ label: "Text color",
195
+ type: "color",
196
+ value: "#ffffff",
197
+ prop: "color",
198
+ classReference: "button"
199
+ },
200
+ {
201
+ label: "Radius",
202
+ type: "number",
203
+ value: 4,
204
+ unit: "px",
205
+ prop: "borderRadius",
206
+ classReference: "button"
207
+ },
208
+ {
209
+ label: "Padding Top",
210
+ type: "number",
211
+ value: 7,
212
+ unit: "px",
213
+ prop: "paddingTop",
214
+ classReference: "button"
215
+ },
216
+ {
217
+ label: "Padding Right",
218
+ type: "number",
219
+ value: 12,
220
+ unit: "px",
221
+ prop: "paddingRight",
222
+ classReference: "button"
223
+ },
224
+ {
225
+ label: "Padding Bottom",
226
+ type: "number",
227
+ value: 7,
228
+ unit: "px",
229
+ prop: "paddingBottom",
230
+ classReference: "button"
231
+ },
232
+ {
233
+ label: "Padding Left",
234
+ type: "number",
235
+ value: 12,
236
+ unit: "px",
237
+ prop: "paddingLeft",
238
+ classReference: "button"
239
+ }
240
+ ]
241
+ },
242
+ {
243
+ id: "code-block",
244
+ title: "Code Block",
245
+ classReference: "codeBlock",
246
+ inputs: [
247
+ {
248
+ label: "Border Radius",
249
+ type: "number",
250
+ value: 4,
251
+ unit: "px",
252
+ prop: "borderRadius",
253
+ classReference: "codeBlock"
254
+ },
255
+ {
256
+ label: "Padding Top",
257
+ type: "number",
258
+ value: 12,
259
+ unit: "px",
260
+ prop: "paddingTop",
261
+ classReference: "codeBlock"
262
+ },
263
+ {
264
+ label: "Padding Bottom",
265
+ type: "number",
266
+ value: 12,
267
+ unit: "px",
268
+ prop: "paddingBottom",
269
+ classReference: "codeBlock"
270
+ },
271
+ {
272
+ label: "Padding Left",
273
+ type: "number",
274
+ value: 16,
275
+ unit: "px",
276
+ prop: "paddingLeft",
277
+ classReference: "codeBlock"
278
+ },
279
+ {
280
+ label: "Padding Right",
281
+ type: "number",
282
+ value: 16,
283
+ unit: "px",
284
+ prop: "paddingRight",
285
+ classReference: "codeBlock"
286
+ }
287
+ ]
288
+ },
289
+ {
290
+ id: "inline-code",
291
+ title: "Inline Code",
292
+ classReference: "inlineCode",
293
+ inputs: [
294
+ {
295
+ label: "Background",
296
+ type: "color",
297
+ value: "#e5e7eb",
298
+ prop: "backgroundColor",
299
+ classReference: "inlineCode"
300
+ },
301
+ {
302
+ label: "Text color",
303
+ type: "color",
304
+ value: "#1e293b",
305
+ prop: "color",
306
+ classReference: "inlineCode"
307
+ },
308
+ {
309
+ label: "Radius",
310
+ type: "number",
311
+ value: 4,
312
+ unit: "px",
313
+ prop: "borderRadius",
314
+ classReference: "inlineCode"
315
+ }
316
+ ]
317
+ }
318
+ ];
319
+ const THEME_MINIMAL = THEME_BASIC.map((item) => ({
320
+ ...item,
321
+ inputs: []
322
+ }));
323
+ const RESET_BASIC = {
324
+ reset: {
325
+ margin: "0",
326
+ padding: "0"
327
+ },
328
+ body: {
329
+ fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif",
330
+ fontSize: "16px",
331
+ minHeight: "100%",
332
+ lineHeight: "155%"
333
+ },
334
+ container: {},
335
+ h1: {
336
+ fontSize: "2.25em",
337
+ lineHeight: "1.44em",
338
+ paddingTop: "0.389em",
339
+ fontWeight: 600
340
+ },
341
+ h2: {
342
+ fontSize: "1.8em",
343
+ lineHeight: "1.44em",
344
+ paddingTop: "0.389em",
345
+ fontWeight: 600
346
+ },
347
+ h3: {
348
+ fontSize: "1.4em",
349
+ lineHeight: "1.08em",
350
+ paddingTop: "0.389em",
351
+ fontWeight: 600
352
+ },
353
+ paragraph: {
354
+ fontSize: "1em",
355
+ paddingTop: "0.5em",
356
+ paddingBottom: "0.5em"
357
+ },
358
+ list: {
359
+ paddingLeft: "1.1em",
360
+ paddingBottom: "1em"
361
+ },
362
+ nestedList: {
363
+ paddingLeft: "1.1em",
364
+ paddingBottom: "0"
365
+ },
366
+ listItem: {
367
+ marginLeft: "1em",
368
+ marginBottom: "0.3em",
369
+ marginTop: "0.3em"
370
+ },
371
+ listParagraph: {
372
+ padding: "0",
373
+ margin: "0"
374
+ },
375
+ blockquote: {
376
+ borderLeft: "3px solid #acb3be",
377
+ color: "#7e8a9a",
378
+ marginLeft: 0,
379
+ paddingLeft: "0.8em",
380
+ fontSize: "1.1em",
381
+ fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif"
382
+ },
383
+ link: { textDecoration: "underline" },
384
+ footer: { fontSize: "0.8em" },
385
+ hr: {
386
+ paddingBottom: "1em",
387
+ borderWidth: "2px"
388
+ },
389
+ image: { maxWidth: "100%" },
390
+ button: {
391
+ lineHeight: "100%",
392
+ display: "inline-block"
393
+ },
394
+ inlineCode: {
395
+ paddingTop: "0.25em",
396
+ paddingBottom: "0.25em",
397
+ paddingLeft: "0.4em",
398
+ paddingRight: "0.4em",
399
+ background: "#e5e7eb",
400
+ color: "#1e293b",
401
+ borderRadius: "4px"
402
+ },
403
+ codeBlock: {
404
+ fontFamily: "monospace",
405
+ fontWeight: "500",
406
+ fontSize: ".92em"
407
+ },
408
+ codeTag: {
409
+ lineHeight: "130%",
410
+ fontFamily: "monospace",
411
+ fontSize: ".92em"
412
+ },
413
+ section: {
414
+ padding: "10px 20px 10px 20px",
415
+ boxSizing: "border-box"
416
+ }
417
+ };
418
+ const RESET_MINIMAL = {
419
+ ...Object.keys(RESET_BASIC).reduce((acc, key) => {
420
+ acc[key] = {};
421
+ return acc;
422
+ }, {}),
423
+ reset: RESET_BASIC.reset
424
+ };
425
+ const RESET_THEMES = {
426
+ basic: RESET_BASIC,
427
+ minimal: RESET_MINIMAL
428
+ };
429
+ const EDITOR_THEMES = {
430
+ minimal: THEME_MINIMAL,
431
+ basic: THEME_BASIC
432
+ };
433
+
434
+ //#endregion
435
+ //#region src/plugins/email-theming/normalization.ts
436
+ const PANEL_SECTION_IDS = new Set([
437
+ "body",
438
+ "container",
439
+ "typography",
440
+ "link",
441
+ "image",
442
+ "button",
443
+ "code-block",
444
+ "inline-code"
445
+ ]);
446
+ const PANEL_SECTION_IDS_BY_TITLE = {
447
+ background: "body",
448
+ body: "body",
449
+ content: "container",
450
+ container: "container",
451
+ typography: "typography",
452
+ link: "link",
453
+ image: "image",
454
+ button: "button",
455
+ "code block": "code-block",
456
+ "inline code": "inline-code"
457
+ };
458
+ const PANEL_SECTION_IDS_BY_CLASS_REFERENCE = {
459
+ container: "container",
460
+ link: "link",
461
+ image: "image",
462
+ button: "button",
463
+ codeBlock: "code-block",
464
+ inlineCode: "inline-code"
465
+ };
466
+ function isPanelSectionId(value) {
467
+ return typeof value === "string" && PANEL_SECTION_IDS.has(value);
468
+ }
469
+ function normalizeTitle(title) {
470
+ return title?.trim().toLowerCase().replace(/\s+/g, " ") ?? "";
471
+ }
472
+ function resolvePanelSectionId(group) {
473
+ if (isPanelSectionId(group.id)) return group.id;
474
+ const normalizedTitle = normalizeTitle(group.title);
475
+ if (group.classReference === "body") {
476
+ if (normalizedTitle === "typography") return "typography";
477
+ return "body";
478
+ }
479
+ if (group.classReference && PANEL_SECTION_IDS_BY_CLASS_REFERENCE[group.classReference]) return PANEL_SECTION_IDS_BY_CLASS_REFERENCE[group.classReference] ?? null;
480
+ return PANEL_SECTION_IDS_BY_TITLE[normalizedTitle] ?? null;
481
+ }
482
+ function normalizePanelInputs(inputs, defaultInputs, fallbackClassReference) {
483
+ if (!Array.isArray(inputs)) return [];
484
+ return inputs.map((input) => {
485
+ const defaultInput = defaultInputs.find((candidate) => candidate.prop === input.prop);
486
+ return {
487
+ ...defaultInput,
488
+ ...input,
489
+ classReference: input.classReference ?? defaultInput?.classReference ?? fallbackClassReference
490
+ };
491
+ });
492
+ }
493
+ function inferThemeFromPanelStyles(panelStyles) {
494
+ if (!Array.isArray(panelStyles) || panelStyles.length === 0) return null;
495
+ let finalTheme = null;
496
+ for (const group of panelStyles) {
497
+ if (!Array.isArray(group?.inputs)) {
498
+ finalTheme = null;
499
+ break;
500
+ }
501
+ if (group.inputs.length !== 0) {
502
+ finalTheme = "basic";
503
+ break;
504
+ }
505
+ finalTheme = "minimal";
506
+ }
507
+ return finalTheme;
508
+ }
509
+ function normalizeThemePanelStyles(theme, panelStyles) {
510
+ if (!Array.isArray(panelStyles)) return null;
511
+ return panelStyles.map((group) => {
512
+ const panelId = resolvePanelSectionId(group);
513
+ if (!panelId) return group;
514
+ const defaultGroup = EDITOR_THEMES[theme].find((candidate) => candidate.id === panelId);
515
+ if (!defaultGroup) return group;
516
+ return {
517
+ ...group,
518
+ id: panelId,
519
+ title: defaultGroup.title,
520
+ classReference: defaultGroup.classReference,
521
+ inputs: normalizePanelInputs(group.inputs, defaultGroup.inputs, defaultGroup.classReference)
522
+ };
523
+ });
524
+ }
525
+
526
+ //#endregion
527
+ //#region src/plugins/email-theming/extension.tsx
528
+ /**
529
+ * Maps a document node (type + attrs) to the theme component key used for style lookup.
530
+ * Centralizes all node-type → theme-component knowledge.
531
+ */
532
+ function getThemeComponentKey(nodeType, depth, attrs = {}) {
533
+ switch (nodeType) {
534
+ case "paragraph":
535
+ if (depth > 0) return "listParagraph";
536
+ return "paragraph";
537
+ case "heading": return `h${attrs.level ?? 1}`;
538
+ case "blockquote": return "blockquote";
539
+ case "button": return "button";
540
+ case "section": return "section";
541
+ case "footer": return "footer";
542
+ case "image": return "image";
543
+ case "youtube":
544
+ case "twitter": return "image";
545
+ case "orderedList":
546
+ case "bulletList":
547
+ if (depth > 0) return "nestedList";
548
+ return "list";
549
+ case "listItem": return "listItem";
550
+ case "codeBlock": return "codeBlock";
551
+ case "code": return "inlineCode";
552
+ case "link": return "link";
553
+ case "horizontalRule": return "hr";
554
+ default: return null;
555
+ }
556
+ }
557
+ /**
558
+ * Returns merged theme styles (reset + panel styles) for the given editor.
559
+ * Use when you have editor access and need the full CssJs map.
560
+ */
561
+ function getMergedCssJs(theme, panelStyles) {
562
+ const parsed = transformToCssJs(normalizeThemePanelStyles(theme, panelStyles) ?? EDITOR_THEMES[theme]);
563
+ return mergeCssJs(RESET_THEMES[theme], parsed);
564
+ }
565
+ /**
566
+ * Returns resolved React.CSSProperties for a node when you already have merged CssJs
567
+ * (e.g. in the serializer where there is no editor). Centralizes which theme keys
568
+ * apply to which node type.
569
+ */
570
+ const RESET_NODE_TYPES = new Set([
571
+ "body",
572
+ "bulletList",
573
+ "button",
574
+ "columns",
575
+ "div",
576
+ "h1",
577
+ "h2",
578
+ "h3",
579
+ "list",
580
+ "listItem",
581
+ "listParagraph",
582
+ "nestedList",
583
+ "orderedList",
584
+ "table",
585
+ "paragraph",
586
+ "tableCell",
587
+ "tableHeader",
588
+ "tableRow",
589
+ "youtube"
590
+ ]);
591
+ function getResolvedNodeStyles(node, depth, mergedCssJs) {
592
+ const key = getThemeComponentKey(node.type ?? "", depth, node.attrs ?? {});
593
+ if (!key) {
594
+ if (RESET_NODE_TYPES.has(node.type ?? "")) return mergedCssJs.reset ?? {};
595
+ return {};
596
+ }
597
+ const component = mergedCssJs[key] ?? {};
598
+ if (RESET_NODE_TYPES.has(key) || RESET_NODE_TYPES.has(node.type ?? "")) return {
599
+ ...mergedCssJs.reset ?? {},
600
+ ...component
601
+ };
602
+ return { ...component };
603
+ }
604
+ function stylesToCss(styles, theme) {
605
+ const parsed = transformToCssJs(normalizeThemePanelStyles(theme, styles) ?? EDITOR_THEMES[theme]);
606
+ return mergeCssJs(RESET_THEMES[theme], parsed);
607
+ }
608
+ function getEmailTheming(editor) {
609
+ const theme = getEmailTheme(editor);
610
+ return {
611
+ styles: normalizeThemePanelStyles(theme, getEmailStyles(editor)) ?? EDITOR_THEMES[theme],
612
+ theme,
613
+ css: getEmailCss(editor)
614
+ };
615
+ }
616
+ function useEmailTheming(editor) {
617
+ return useEditorState({
618
+ editor,
619
+ selector({ editor: ed }) {
620
+ if (!ed) return null;
621
+ return getEmailTheming(ed);
622
+ }
623
+ });
624
+ }
625
+ function getEmailStyles(editor) {
626
+ return getGlobalContent("styles", editor);
627
+ }
628
+ function getEmailTheme(editor) {
629
+ const extensionTheme = editor.extensionManager.extensions.find((extension) => extension.name === "theming")?.options?.theme;
630
+ if (extensionTheme === "basic" || extensionTheme === "minimal") return extensionTheme;
631
+ const globalTheme = getGlobalContent("theme", editor);
632
+ if (globalTheme === "basic" || globalTheme === "minimal") return globalTheme;
633
+ const inferredTheme = inferThemeFromPanelStyles(getEmailStyles(editor));
634
+ if (inferredTheme) return inferredTheme;
635
+ return "basic";
636
+ }
637
+ function getEmailCss(editor) {
638
+ return getGlobalContent("css", editor);
639
+ }
640
+ const EmailTheming = Extension.create({
641
+ name: "theming",
642
+ addOptions() {
643
+ return {
644
+ theme: void 0,
645
+ serializerPlugin: {
646
+ getNodeStyles(node, depth, editor) {
647
+ const theming = getEmailTheming(editor);
648
+ return getResolvedNodeStyles(node, depth, getMergedCssJs(theming.theme, theming.styles));
649
+ },
650
+ BaseTemplate({ previewText, children, editor }) {
651
+ const { css: globalCss, styles, theme } = getEmailTheming(editor);
652
+ const mergedStyles = getMergedCssJs(theme, styles);
653
+ return /* @__PURE__ */ jsxs(Html, { children: [
654
+ /* @__PURE__ */ jsxs(Head, { children: [
655
+ /* @__PURE__ */ jsx("meta", {
656
+ content: "width=device-width",
657
+ name: "viewport"
658
+ }),
659
+ /* @__PURE__ */ jsx("meta", {
660
+ content: "IE=edge",
661
+ httpEquiv: "X-UA-Compatible"
662
+ }),
663
+ /* @__PURE__ */ jsx("meta", { name: "x-apple-disable-message-reformatting" }),
664
+ /* @__PURE__ */ jsx("meta", {
665
+ content: "telephone=no,address=no,email=no,date=no,url=no",
666
+ name: "format-detection"
667
+ }),
668
+ globalCss && /* @__PURE__ */ jsx("style", { children: globalCss })
669
+ ] }),
670
+ previewText && previewText !== "" && /* @__PURE__ */ jsx(Preview, { children: previewText }),
671
+ /* @__PURE__ */ jsx(Body, { children: /* @__PURE__ */ jsx(Section, {
672
+ width: "100%",
673
+ align: "center",
674
+ style: mergedStyles.body,
675
+ children: /* @__PURE__ */ jsx(Section, {
676
+ align: mergedStyles.container?.align,
677
+ style: {
678
+ ...mergedStyles.container,
679
+ width: "100%",
680
+ maxWidth: mergedStyles.container?.width,
681
+ fontFamily: mergedStyles.body?.fontFamily
682
+ },
683
+ children
684
+ })
685
+ }) })
686
+ ] });
687
+ }
688
+ }
689
+ };
690
+ },
691
+ addProseMirrorPlugins() {
692
+ const { editor } = this;
693
+ const scopeId = `tiptap-theme-${Math.random().toString(36).slice(2, 10)}`;
694
+ const scopeAttribute = "data-editor-theme-scope";
695
+ const scopeSelector = `.tiptap.ProseMirror[${scopeAttribute}="${scopeId}"]`;
696
+ const themeStyleId = `${scopeId}-theme`;
697
+ const globalStyleId = `${scopeId}-global`;
698
+ return [new Plugin({
699
+ key: new PluginKey("themingStyleInjector"),
700
+ view(view) {
701
+ let prevStyles = null;
702
+ let prevTheme = null;
703
+ let prevCss = null;
704
+ view.dom.setAttribute(scopeAttribute, scopeId);
705
+ const sync = () => {
706
+ const theme = getEmailTheme(editor);
707
+ const styles = getEmailStyles(editor);
708
+ const resolvedStyles = styles ?? EDITOR_THEMES[theme];
709
+ const css = getEmailCss(editor);
710
+ if (styles !== prevStyles || theme !== prevTheme) {
711
+ prevStyles = styles;
712
+ prevTheme = theme;
713
+ injectThemeCss(getMergedCssJs(theme, resolvedStyles), {
714
+ scopeSelector,
715
+ styleId: themeStyleId
716
+ });
717
+ }
718
+ if (css !== prevCss) {
719
+ prevCss = css;
720
+ injectGlobalPlainCss(css, {
721
+ scopeSelector,
722
+ styleId: globalStyleId
723
+ });
724
+ }
725
+ };
726
+ sync();
727
+ return {
728
+ update: sync,
729
+ destroy() {
730
+ document.getElementById(themeStyleId)?.remove();
731
+ document.getElementById(globalStyleId)?.remove();
732
+ view.dom.removeAttribute(scopeAttribute);
733
+ }
734
+ };
735
+ }
736
+ })];
737
+ }
738
+ });
739
+
740
+ //#endregion
741
+ export { EmailTheming, getMergedCssJs, getResolvedNodeStyles, getThemeComponentKey, stylesToCss, useEmailTheming };
742
+ //# sourceMappingURL=index.mjs.map