@marlinjai/email-editor-core 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,437 +1,6 @@
1
1
  import * as mobx_state_tree from 'mobx-state-tree';
2
2
  import { Instance, SnapshotIn, SnapshotOut, IType } from 'mobx-state-tree';
3
-
4
- interface GradientStop {
5
- color: string;
6
- position: number;
7
- }
8
- interface BackgroundGradient {
9
- type: 'linear' | 'radial';
10
- angle: number;
11
- stops: GradientStop[];
12
- }
13
- /**
14
- * Converts a BackgroundGradient to a CSS background-image value.
15
- * Returns undefined when stops array is empty.
16
- *
17
- * Examples:
18
- * buildGradientCSS({ type: 'linear', angle: 90, stops: [{color:'#f00',position:0},{color:'#00f',position:100}] })
19
- * // => "linear-gradient(90deg, #f00 0%, #00f 100%)"
20
- *
21
- * buildGradientCSS({ type: 'radial', angle: 0, stops: [{color:'#f00',position:0},{color:'#00f',position:100}] })
22
- * // => "radial-gradient(circle, #f00 0%, #00f 100%)"
23
- */
24
- declare function buildGradientCSS(gradient: BackgroundGradient): string | undefined;
25
-
26
- /**
27
- * Spacing configuration for padding/margin
28
- */
29
- interface Spacing {
30
- top?: string;
31
- right?: string;
32
- bottom?: string;
33
- left?: string;
34
- }
35
- /**
36
- * Custom font definition
37
- */
38
- interface FontDefinition {
39
- name: string;
40
- href: string;
41
- }
42
- /**
43
- * Theme color for reusable brand colors
44
- */
45
- interface ThemeColor {
46
- name: string;
47
- value: string;
48
- }
49
- /**
50
- * MJML attributes the editor has no control for, kept as found (values as they
51
- * stood in the source, XML entities included) and emitted again by the
52
- * compiler after the attributes the editor sets. Written by the MJML import,
53
- * so an imported document compiles the way its source did: a `css-class` the
54
- * author's `mj-style` rules target, an `mj-class`, a button's `font-weight`.
55
- */
56
- type ExtraAttributes = Record<string, string>;
57
- /**
58
- * What an imported document's `<mj-head>` and `<mj-body>` carried beyond the
59
- * fields the editor has (title, preview, fonts, breakpoint, styles). When
60
- * present, the compiler emits `attributes` instead of its own default
61
- * `<mj-attributes>` (so the source's `mj-all`, per-component defaults and
62
- * `mj-class` definitions apply as they did), `bodyAttributes` on `<mj-body>`,
63
- * and `headRaw` (for example `mj-html-attributes`) verbatim inside `<mj-head>`.
64
- */
65
- interface MjmlHead {
66
- /** The inner markup of `<mj-attributes>`, verbatim. An empty string means "no defaults at all". */
67
- attributes?: string;
68
- /** Attributes of `<mj-body>`, e.g. `background-color`, `width`. */
69
- bodyAttributes?: ExtraAttributes;
70
- /** Other head elements, verbatim, in source order. */
71
- headRaw?: string;
72
- }
73
- /**
74
- * Email template metadata
75
- */
76
- interface TemplateMetadata {
77
- subject?: string;
78
- previewText?: string;
79
- title?: string;
80
- /** Epoch milliseconds (what the editor emits) or an ISO 8601 string */
81
- createdAt?: string | number;
82
- /** Epoch milliseconds (what the editor emits) or an ISO 8601 string */
83
- updatedAt?: string | number;
84
- fonts?: FontDefinition[];
85
- themeColors?: ThemeColor[];
86
- breakpoint?: string;
87
- customCSS?: string;
88
- inlineCSS?: string;
89
- /** Set by the MJML import; see {@link MjmlHead}. */
90
- mjmlHead?: MjmlHead;
91
- }
92
- /**
93
- * Base block interface - all blocks extend this
94
- */
95
- interface BaseBlock {
96
- id: string;
97
- type: string;
98
- hidden?: boolean;
99
- /** See {@link ExtraAttributes}. */
100
- extraAttributes?: ExtraAttributes;
101
- }
102
- /**
103
- * Text block with rich content
104
- */
105
- interface TextBlock extends BaseBlock {
106
- type: 'text';
107
- content: string;
108
- align?: 'left' | 'center' | 'right' | 'justify';
109
- color?: string;
110
- fontSize?: string;
111
- fontFamily?: string;
112
- padding?: Spacing;
113
- lineHeight?: string;
114
- }
115
- /**
116
- * Image block
117
- */
118
- interface ImageBlock extends BaseBlock {
119
- type: 'image';
120
- src: string;
121
- alt?: string;
122
- width?: string;
123
- height?: string;
124
- align?: 'left' | 'center' | 'right';
125
- href?: string;
126
- padding?: Spacing;
127
- borderRadius?: string;
128
- }
129
- /**
130
- * Button block
131
- */
132
- interface ButtonBlock extends BaseBlock {
133
- type: 'button';
134
- label: string;
135
- href: string;
136
- align?: 'left' | 'center' | 'right';
137
- backgroundColor?: string;
138
- color?: string;
139
- borderRadius?: string;
140
- border?: string;
141
- padding?: Spacing;
142
- innerPadding?: string;
143
- }
144
- /**
145
- * Divider block
146
- */
147
- interface DividerBlock extends BaseBlock {
148
- type: 'divider';
149
- borderColor?: string;
150
- borderWidth?: string;
151
- borderStyle?: 'solid' | 'dashed' | 'dotted';
152
- width?: string;
153
- padding?: Spacing;
154
- }
155
- /**
156
- * Spacer block for vertical spacing
157
- */
158
- interface SpacerBlock extends BaseBlock {
159
- type: 'spacer';
160
- height: string;
161
- }
162
- /**
163
- * Custom branded header block (locked)
164
- */
165
- interface HeaderBlock extends BaseBlock {
166
- type: 'header';
167
- locked: true;
168
- }
169
- /**
170
- * Custom branded footer block (locked)
171
- */
172
- interface FooterBlock extends BaseBlock {
173
- type: 'footer';
174
- locked: true;
175
- }
176
- /**
177
- * Social link definition
178
- */
179
- interface SocialLink {
180
- platform: string;
181
- url: string;
182
- color?: string;
183
- }
184
- /**
185
- * Social block for social media icons
186
- */
187
- interface SocialBlock extends BaseBlock {
188
- type: 'social';
189
- links: SocialLink[];
190
- iconSize?: string;
191
- iconPadding?: string;
192
- borderRadius?: string;
193
- align?: 'left' | 'center' | 'right';
194
- mode?: 'horizontal' | 'vertical';
195
- }
196
- /**
197
- * Hero block with background image
198
- */
199
- interface HeroBlock extends BaseBlock {
200
- type: 'hero';
201
- backgroundImage: string;
202
- backgroundHeight?: string;
203
- backgroundWidth?: string;
204
- backgroundColor?: string;
205
- verticalAlign?: 'top' | 'middle' | 'bottom';
206
- mode?: 'fixed-height' | 'fluid-height';
207
- }
208
- /**
209
- * Accordion item
210
- */
211
- interface AccordionItem {
212
- title: string;
213
- content: string;
214
- }
215
- /**
216
- * Accordion block for collapsible content
217
- */
218
- interface AccordionBlock extends BaseBlock {
219
- type: 'accordion';
220
- items: AccordionItem[];
221
- iconPosition?: 'left' | 'right';
222
- borderColor?: string;
223
- fontFamily?: string;
224
- }
225
- /**
226
- * Raw HTML block
227
- */
228
- interface RawBlock extends BaseBlock {
229
- type: 'raw';
230
- html: string;
231
- }
232
- /**
233
- * Navbar link definition
234
- */
235
- interface NavbarLink {
236
- href: string;
237
- label: string;
238
- color?: string;
239
- }
240
- /**
241
- * Navbar block for navigation
242
- */
243
- interface NavbarBlock extends BaseBlock {
244
- type: 'navbar';
245
- links: NavbarLink[];
246
- hamburger?: boolean;
247
- baseUrl?: string;
248
- align?: 'left' | 'center' | 'right';
249
- icoColor?: string;
250
- padding?: Spacing;
251
- }
252
- /**
253
- * Carousel image definition
254
- */
255
- interface CarouselImage {
256
- src: string;
257
- alt?: string;
258
- href?: string;
259
- thumbnailSrc?: string;
260
- }
261
- /**
262
- * Carousel block for image slideshows
263
- */
264
- interface CarouselBlock extends BaseBlock {
265
- type: 'carousel';
266
- images: CarouselImage[];
267
- thumbnails?: 'visible' | 'hidden';
268
- borderRadius?: string;
269
- iconWidth?: string;
270
- tbBorderRadius?: string;
271
- padding?: Spacing;
272
- }
273
- /**
274
- * Table block for tabular data
275
- */
276
- interface TableBlock extends BaseBlock {
277
- type: 'table';
278
- headers: string[];
279
- rows: string[][];
280
- align?: 'left' | 'center' | 'right';
281
- color?: string;
282
- fontFamily?: string;
283
- fontSize?: string;
284
- cellpadding?: string;
285
- cellspacing?: string;
286
- border?: string;
287
- padding?: Spacing;
288
- }
289
- /**
290
- * Union type of all possible blocks
291
- */
292
- type Block = TextBlock | ImageBlock | ButtonBlock | DividerBlock | SpacerBlock | HeaderBlock | FooterBlock | SocialBlock | HeroBlock | AccordionBlock | RawBlock | NavbarBlock | CarouselBlock | TableBlock;
293
- /**
294
- * Column within a section
295
- */
296
- interface Column {
297
- id: string;
298
- width?: number;
299
- blocks: Block[];
300
- hidden?: boolean;
301
- backgroundColor?: string;
302
- backgroundGradient?: BackgroundGradient;
303
- verticalAlign?: 'top' | 'middle' | 'bottom';
304
- padding?: Spacing;
305
- /**
306
- * Optional sub-columns. When non-empty, `blocks` MUST be empty
307
- * (a column is either a leaf with blocks, or a group with sub-columns).
308
- * See `docs/superpowers/specs/2026-04-26-nested-columns-design.md`.
309
- */
310
- subColumns?: SubColumn[];
311
- /** See {@link ExtraAttributes}. */
312
- extraAttributes?: ExtraAttributes;
313
- }
314
- /**
315
- * Sub-column inside a "group"-kind Column. Holds only leaf blocks
316
- * (text, image, button, divider, spacer, social). Cannot itself contain
317
- * sub-columns (no nesting beyond depth 2).
318
- */
319
- interface SubColumn {
320
- id: string;
321
- width: number;
322
- blocks: Block[];
323
- backgroundColor?: string;
324
- verticalAlign?: 'top' | 'middle' | 'bottom';
325
- paddingTop?: string;
326
- paddingRight?: string;
327
- paddingBottom?: string;
328
- paddingLeft?: string;
329
- }
330
- /**
331
- * Section containing columns
332
- */
333
- interface Section {
334
- id: string;
335
- type: 'section';
336
- backgroundColor?: string;
337
- backgroundImage?: string;
338
- backgroundGradient?: BackgroundGradient;
339
- backgroundPosition?: string;
340
- backgroundRepeat?: 'repeat' | 'no-repeat';
341
- backgroundSize?: string;
342
- /**
343
- * Full width (`full-width` in MJML). Inside a full-width {@link Wrapper},
344
- * MJML renders the section at standard width whatever this says.
345
- */
346
- fullWidth?: boolean;
347
- noStack?: boolean;
348
- hidden?: boolean;
349
- padding?: Spacing;
350
- columns: Column[];
351
- /**
352
- * Emit the section's raw blocks straight into the parent (`<mj-body>`, or
353
- * the `<mj-wrapper>` the section sits in) instead of inside an
354
- * `<mj-section>`: markup that sat there in an imported document. Ignored as
355
- * soon as the section holds any block that is not raw.
356
- */
357
- bodyRaw?: boolean;
358
- /** See {@link ExtraAttributes}. */
359
- extraAttributes?: ExtraAttributes;
360
- }
361
- /**
362
- * A container around several sections (`<mj-wrapper>`): one background,
363
- * border, radius and padding shared by the sections inside, with an optional
364
- * vertical `gap` between them. Sits at the top level of a document, next to
365
- * sections; it never holds another wrapper and never sits inside a section.
366
- * It may be empty (it keeps its styling, and sections can be moved back in).
367
- * Added in schema version 1.1.
368
- */
369
- interface Wrapper {
370
- id: string;
371
- type: 'wrapper';
372
- hidden?: boolean;
373
- backgroundColor?: string;
374
- /** `background-url` in MJML. */
375
- backgroundImage?: string;
376
- backgroundGradient?: BackgroundGradient;
377
- backgroundPosition?: string;
378
- backgroundRepeat?: 'repeat' | 'no-repeat';
379
- backgroundSize?: string;
380
- /** CSS border shorthand for all four sides, e.g. `1px solid #dddddd`. */
381
- border?: string;
382
- borderTop?: string;
383
- borderRight?: string;
384
- borderBottom?: string;
385
- borderLeft?: string;
386
- borderRadius?: string;
387
- /** MJML's default when unset is `20px 0`. */
388
- padding?: Spacing;
389
- /** Full width (`full-width`): the background spans the whole mail width; the sections inside stay at standard width. */
390
- fullWidth?: boolean;
391
- /** Class names for `css-class`, space separated, for the document's own `mj-style` rules. */
392
- cssClass?: string;
393
- /** Vertical space between the sections inside, in px (`gap`, MJML 4.15 and later). */
394
- gap?: string;
395
- textAlign?: 'left' | 'center' | 'right';
396
- /** See {@link ExtraAttributes}. */
397
- extraAttributes?: ExtraAttributes;
398
- sections: Section[];
399
- }
400
- /** What the top level of a document holds, in order: sections and wrappers. */
401
- type TopLevelItem = Section | Wrapper;
402
- /** The document schema versions: 1.1 added {@link Wrapper}. */
403
- type TemplateVersion = '1.0' | '1.1';
404
- /**
405
- * Complete email template structure
406
- */
407
- interface EmailTemplate {
408
- /**
409
- * The document's id. Optional: a document without one is valid, and the
410
- * editor store assigns one when it opens it (see `TemplateModel`).
411
- * `migrateTemplate` never adds or changes it.
412
- */
413
- id?: string;
414
- /**
415
- * The schema version. `migrateTemplate` brings every document it accepts to
416
- * the current one (1.1); a 1.0 document cannot hold a wrapper.
417
- */
418
- version: TemplateVersion;
419
- metadata: TemplateMetadata;
420
- /** The document's top level, in order: sections and wrappers (see {@link TopLevelItem}). */
421
- sections: TopLevelItem[];
422
- }
423
- /** Whether a top-level item is a {@link Wrapper}. */
424
- declare function isWrapper(item: TopLevelItem): item is Wrapper;
425
- /** Every section of a document in order, the ones inside wrappers included. */
426
- declare function allSections(items: readonly TopLevelItem[]): Section[];
427
- /**
428
- * Result of MJML compilation
429
- */
430
- interface CompileResult {
431
- mjml: string;
432
- html: string;
433
- errors?: string[];
434
- }
3
+ import { d as BackgroundGradient, e as MjmlHead } from './MjmlBuilder-DsiOyhiL.mjs';
435
4
 
436
5
  /**
437
6
  * The store's models give most fields a default (`hidden: false`, a column
@@ -8783,4 +8352,4 @@ declare function createTemplateWithDefaultSection(options?: {
8783
8352
  title?: string;
8784
8353
  }): TemplateSnapshotIn;
8785
8354
 
8786
- export { type SpacerBlock as $, type AccordionBlock as A, type Block as B, type CSSProperties as C, type DividerBlock as D, type EmailTemplate as E, type Filled as F, type FontDefinition as G, FontDefinitionModel as H, type FooterBlock as I, type GradientStop as J, type HeaderBlock as K, type HeroBlock as L, type MjmlHead as M, type ImageBlock as N, MJML_WRAPPER_DEFAULT_PADDING as O, type NavbarBlock as P, type NavbarLink as Q, NavbarLinkModel as R, type Section as S, type TemplateSnapshotIn as T, type RawBlock as U, SectionModel as V, type WrapperProperties as W, type SectionSnapshotOut as X, type SocialBlock as Y, type SocialLink as Z, SocialLinkModel as _, BlockType as a, type Spacing as a0, SpacingModel as a1, type SubColumn as a2, type TableBlock as a3, type TemplateInstance as a4, type TemplateMetadata as a5, type TemplateMetadataInstance as a6, TemplateMetadataModel as a7, type TemplateSnapshotOut as a8, type TemplateVersion as a9, type TextBlock as aa, type ThemeColor as ab, ThemeColorModel as ac, type TopLevelItem as ad, TopLevelItemModel as ae, type Wrapper as af, WrapperModel as ag, type WrapperSnapshotOut as ah, allSections as ai, buildGradientCSS as aj, cloneSectionSnapshot as ak, createColumn as al, createSection as am, createTemplate as an, createTemplateWithDefaultSection as ao, createWrapper as ap, isWrapper as aq, isWrapperInstance as ar, type BackgroundGradient as b, type BlockSnapshotIn as c, type BlockInstance as d, TemplateModel as e, type ColumnSnapshotIn as f, type ColumnInstance as g, type SectionInstance as h, type WrapperInstance as i, type SectionSnapshotIn as j, type WrapperSnapshotIn as k, type TopLevelItemInstance as l, type AccordionItem as m, AccordionItemModel as n, type BaseBlock as o, BlockModel as p, type BlockSnapshotOut as q, type ButtonBlock as r, type CarouselBlock as s, type CarouselImage as t, CarouselImageModel as u, type Column as v, ColumnModel as w, type ColumnSnapshotOut as x, type CompileResult as y, type ExtraAttributes as z };
8355
+ export { AccordionItemModel as A, BlockType as B, type CSSProperties as C, type WrapperSnapshotOut as D, cloneSectionSnapshot as E, type Filled as F, createColumn as G, createSection as H, createTemplate as I, createTemplateWithDefaultSection as J, createWrapper as K, isWrapperInstance as L, MJML_WRAPPER_DEFAULT_PADDING as M, NavbarLinkModel as N, type SectionInstance as S, type TemplateSnapshotIn as T, type WrapperProperties as W, type BlockSnapshotIn as a, type BlockInstance as b, TemplateModel as c, type ColumnSnapshotIn as d, type ColumnInstance as e, type WrapperInstance as f, type SectionSnapshotIn as g, type WrapperSnapshotIn as h, type TopLevelItemInstance as i, BlockModel as j, type BlockSnapshotOut as k, CarouselImageModel as l, ColumnModel as m, type ColumnSnapshotOut as n, FontDefinitionModel as o, SectionModel as p, type SectionSnapshotOut as q, SocialLinkModel as r, SpacingModel as s, type TemplateInstance as t, type TemplateMetadataInstance as u, TemplateMetadataModel as v, type TemplateSnapshotOut as w, ThemeColorModel as x, TopLevelItemModel as y, WrapperModel as z };
@@ -0,0 +1,13 @@
1
+ import { C as CompileOptions, B as BuildOptions, E as EmailTemplate, a as CompileResult } from './MjmlBuilder-DsiOyhiL.mjs';
2
+ export { b as EDITOR_MARKER, M as MjmlBuilder, m as mjmlOptions, s as stripEditorMarkup } from './MjmlBuilder-DsiOyhiL.mjs';
3
+
4
+ /** Options of {@link compileInBrowser}: the shared mjml options plus the editor's affordances. */
5
+ type BrowserCompileOptions = CompileOptions & BuildOptions;
6
+ /**
7
+ * Compile a document to HTML in the browser. Same result shape as the server
8
+ * compiler's `compile`; `editor: true` adds the fenced affordances the canvas
9
+ * needs (see `BuildOptions`), which the server never emits.
10
+ */
11
+ declare function compileInBrowser(template: EmailTemplate, options?: BrowserCompileOptions): Promise<CompileResult>;
12
+
13
+ export { type BrowserCompileOptions, BuildOptions, CompileOptions, compileInBrowser };
@@ -0,0 +1,13 @@
1
+ import { C as CompileOptions, B as BuildOptions, E as EmailTemplate, a as CompileResult } from './MjmlBuilder-DsiOyhiL.js';
2
+ export { b as EDITOR_MARKER, M as MjmlBuilder, m as mjmlOptions, s as stripEditorMarkup } from './MjmlBuilder-DsiOyhiL.js';
3
+
4
+ /** Options of {@link compileInBrowser}: the shared mjml options plus the editor's affordances. */
5
+ type BrowserCompileOptions = CompileOptions & BuildOptions;
6
+ /**
7
+ * Compile a document to HTML in the browser. Same result shape as the server
8
+ * compiler's `compile`; `editor: true` adds the fenced affordances the canvas
9
+ * needs (see `BuildOptions`), which the server never emits.
10
+ */
11
+ declare function compileInBrowser(template: EmailTemplate, options?: BrowserCompileOptions): Promise<CompileResult>;
12
+
13
+ export { type BrowserCompileOptions, BuildOptions, CompileOptions, compileInBrowser };