@lit-pigeon/core 0.3.2 → 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.
package/dist/index.d.ts CHANGED
@@ -106,6 +106,17 @@ export declare interface BlockDefinition {
106
106
 
107
107
  export declare type BlockType = ContentBlock['type'];
108
108
 
109
+ /**
110
+ * A border applied to all four sides. Structured here and serialised to the
111
+ * CSS shorthand at the MJML boundary, the same way {@link Spacing} is.
112
+ * Per-side borders are deliberately not modelled until something needs them.
113
+ */
114
+ export declare interface Border {
115
+ width: number;
116
+ style: 'solid' | 'dashed' | 'dotted';
117
+ color: string;
118
+ }
119
+
109
120
  /**
110
121
  * A single saved color in a brand kit. Hex (`#rrggbb`/`#rgb`) recommended;
111
122
  * any CSS color string is accepted at storage time.
@@ -168,18 +179,24 @@ export declare interface BrandLogo {
168
179
  export declare interface ButtonBlock {
169
180
  id: string;
170
181
  type: 'button';
171
- values: {
182
+ values: DeviceVisibility & {
183
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
184
+ condition?: string;
172
185
  content: string;
173
186
  href: string;
174
187
  backgroundColor: string;
175
188
  textColor: string;
176
189
  borderRadius: number;
190
+ /** Omitted for a borderless button; MJML's own default is `border: none`. */
191
+ border?: Border;
177
192
  padding: Spacing;
178
193
  innerPadding: Spacing;
179
194
  fontSize: number;
180
195
  fontWeight: string;
181
196
  alignment: 'left' | 'center' | 'right';
182
197
  fullWidth: boolean;
198
+ /** Written out as MJML `css-class`. */
199
+ cssClass?: string;
183
200
  };
184
201
  }
185
202
 
@@ -197,11 +214,13 @@ export declare function cloneRowWithNewIds(row: RowNode): RowNode;
197
214
  export declare interface ColumnNode {
198
215
  id: string;
199
216
  type: 'column';
200
- attributes: {
217
+ attributes: DeviceVisibility & {
201
218
  backgroundColor?: string;
202
219
  padding: Spacing;
203
220
  borderRadius?: number;
204
221
  verticalAlign: 'top' | 'middle' | 'bottom';
222
+ /** Written out as MJML `css-class`. */
223
+ cssClass?: string;
205
224
  };
206
225
  blocks: ContentBlock[];
207
226
  }
@@ -232,6 +251,12 @@ export declare function createRow(columns?: ColumnNode[], columnRatios?: number[
232
251
 
233
252
  export declare function createRowSelection(rowId: string): Selection_2;
234
253
 
254
+ /**
255
+ * Reads back what {@link linkStyleToCss} wrote. Returns undefined for anything
256
+ * that is not our own generated block, so hand-written CSS is left alone.
257
+ */
258
+ export declare function cssToLinkStyle(css: string): LinkStyle_2 | undefined;
259
+
235
260
  /**
236
261
  * A block whose `type` was contributed at runtime via the block registry
237
262
  * (`registerBlock`) rather than being one of the built-in {@link ContentBlock}
@@ -252,10 +277,21 @@ export declare function deleteBlock(rowId: string, columnId: string, blockId: st
252
277
 
253
278
  export declare function deleteRow(rowId: string): Command;
254
279
 
280
+ /**
281
+ * Hides a block or column at one breakpoint. Rendered as an MJML `css-class`
282
+ * (`pigeon-hide-mobile` / `pigeon-hide-desktop`) plus a media query.
283
+ */
284
+ export declare type DeviceVisibility = {
285
+ hideOnMobile?: boolean;
286
+ hideOnDesktop?: boolean;
287
+ };
288
+
255
289
  export declare interface DividerBlock {
256
290
  id: string;
257
291
  type: 'divider';
258
- values: {
292
+ values: DeviceVisibility & {
293
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
294
+ condition?: string;
259
295
  borderColor: string;
260
296
  borderWidth: number;
261
297
  borderStyle: 'solid' | 'dashed' | 'dotted';
@@ -307,6 +343,17 @@ export declare interface EditorConfig {
307
343
  * (`SYSTEM_LINK_TYPES`). The host/SSR resolves any `{{…}}` templates at send.
308
344
  */
309
345
  linkTypes?: LinkType[];
346
+ /**
347
+ * Block types this editor offers, in palette order. Unset means every
348
+ * registered block, which is the default. A type nobody registered is
349
+ * ignored.
350
+ *
351
+ * The restriction is enforced in the `insertBlock` command, not just in the
352
+ * palette, so the keyboard, the MCP server and the REST handler are held to
353
+ * it too. It gates insertion only — a document that already contains an
354
+ * omitted type still renders.
355
+ */
356
+ blocks?: string[];
310
357
  /** Active locale code (e.g. 'fr', 'ar'). Defaults to 'en'. */
311
358
  locale?: string;
312
359
  /** Host-supplied per-locale catalogs, merged over the built-in `en` baseline. */
@@ -347,10 +394,23 @@ export declare interface FontDefinition {
347
394
  url?: string;
348
395
  }
349
396
 
397
+ /** The comment that opens a generated style block. */
398
+ export declare function generatedStyleMarker(name: string): string;
399
+
400
+ /** The name in `css`'s marker, or undefined if the renderer did not write it. */
401
+ export declare function generatedStyleName(css: string): string | undefined;
402
+
350
403
  export declare function generateId(): string;
351
404
 
352
405
  export declare function getAllBlockDefinitions(): BlockDefinition[];
353
406
 
407
+ /**
408
+ * The definitions the palette offers: every registered block by default, or
409
+ * the host's list in its own order. A listed type nobody registered is
410
+ * skipped rather than rendered as a broken chip.
411
+ */
412
+ export declare function getAvailableBlockDefinitions(): BlockDefinition[];
413
+
354
414
  export declare function getBlockDefinition(type: string): BlockDefinition | undefined;
355
415
 
356
416
  export declare function getDefaultValues(type: BlockType): ContentBlock['values'];
@@ -362,7 +422,9 @@ export declare function getStarterTemplates(): Template[];
362
422
  export declare interface HeroBlock {
363
423
  id: string;
364
424
  type: 'hero';
365
- values: {
425
+ values: DeviceVisibility & {
426
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
427
+ condition?: string;
366
428
  backgroundUrl: string;
367
429
  backgroundPosition: 'center center' | 'top center' | 'bottom center' | 'left center' | 'right center';
368
430
  mode: 'fixed-height' | 'fluid-height';
@@ -392,7 +454,9 @@ export declare interface HistoryState {
392
454
  export declare interface HtmlBlock {
393
455
  id: string;
394
456
  type: 'html';
395
- values: {
457
+ values: DeviceVisibility & {
458
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
459
+ condition?: string;
396
460
  content: string;
397
461
  padding: Spacing;
398
462
  };
@@ -401,7 +465,9 @@ export declare interface HtmlBlock {
401
465
  export declare interface ImageBlock {
402
466
  id: string;
403
467
  type: 'image';
404
- values: {
468
+ values: DeviceVisibility & {
469
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
470
+ condition?: string;
405
471
  src: string;
406
472
  alt: string;
407
473
  width: number | 'auto';
@@ -409,6 +475,8 @@ export declare interface ImageBlock {
409
475
  padding: Spacing;
410
476
  alignment: 'left' | 'center' | 'right';
411
477
  borderRadius?: number;
478
+ /** Written out as MJML `css-class`. */
479
+ cssClass?: string;
412
480
  };
413
481
  }
414
482
 
@@ -479,15 +547,22 @@ export declare interface InMemoryRowLibraryStorageOptions {
479
547
  */
480
548
  export declare class InMemoryTemplateStorage implements TemplateStorage {
481
549
  private readonly _byId;
550
+ private readonly _includeGallery;
551
+ private _gallery?;
482
552
  constructor(opts?: InMemoryTemplateStorageOptions);
483
553
  list(): Promise<Template[]>;
484
554
  get(id: string): Promise<Template | null>;
485
555
  save(template: Template): Promise<void>;
486
556
  delete(id: string): Promise<void>;
557
+ /** Merges the gallery once; seeded or saved templates with the same id win. */
558
+ private _ready;
487
559
  }
488
560
 
489
561
  export declare interface InMemoryTemplateStorageOptions {
490
- /** When true (default), the storage is seeded with the built-in starter templates. */
562
+ /**
563
+ * When true (default), the storage is seeded with the built-in starter
564
+ * templates, and the lazily loaded gallery is merged in on first access.
565
+ */
491
566
  includeStarters?: boolean;
492
567
  /** Additional templates to seed alongside the starters. */
493
568
  seed?: Template[];
@@ -497,6 +572,13 @@ export declare function insertBlock(rowId: string, columnId: string, block: Cont
497
572
 
498
573
  export declare function insertRow(row: RowNode, index?: number): Command;
499
574
 
575
+ /**
576
+ * Whether a block of `type` may be inserted. Enforced in `insertBlock`, so
577
+ * the palette, the keyboard, the MCP server and the REST handler are all held
578
+ * to it rather than only the palette.
579
+ */
580
+ export declare function isBlockTypeAvailable(type: string): boolean;
581
+
500
582
  export declare function isKnownBlockType(type: string): type is BlockType;
501
583
 
502
584
  export declare function isValidDocument(doc: unknown): doc is PigeonDocument;
@@ -516,6 +598,32 @@ export declare interface LibraryEntry {
516
598
  updatedAt: string;
517
599
  }
518
600
 
601
+ /** The name this block carries in its generated-style marker. */
602
+ export declare const LINK_STYLE_NAME = "link-style";
603
+
604
+ /**
605
+ * Document-level link styling. A brand setting rather than a per-link
606
+ * decision, so it lives on the body and is rendered as one `<mj-style>` rule
607
+ * targeting `a`. Each part is optional; whatever is unset stays at the
608
+ * client's default.
609
+ */
610
+ declare interface LinkStyle_2 {
611
+ color?: string;
612
+ underline?: boolean;
613
+ }
614
+ export { LinkStyle_2 as LinkStyle }
615
+
616
+ /**
617
+ * Builds the CSS for a document's link style, or undefined when neither part
618
+ * is set and there is nothing to say.
619
+ *
620
+ * Apple Mail is the client that will otherwise override this: it wraps dates,
621
+ * addresses and phone numbers in its own `<a x-apple-data-detectors>`, which
622
+ * would pick the brand link colour up from the rule above it, so those get
623
+ * reset to whatever text surrounds them.
624
+ */
625
+ export declare function linkStyleToCss(style: LinkStyle_2): string | undefined;
626
+
519
627
  /** A selectable "special link" surfaced in the link editor and button panel. */
520
628
  export declare interface LinkType {
521
629
  /** Stable id (also the picker option value). */
@@ -528,6 +636,13 @@ export declare interface LinkType {
528
636
  prompt?: 'email' | 'tel';
529
637
  }
530
638
 
639
+ /**
640
+ * The deeper gallery (order confirmation, shipping update, password reset,
641
+ * invoice, event invite, product launch, abandoned cart, monthly digest).
642
+ * Code-split so the documents only download when a picker asks for them.
643
+ */
644
+ export declare function loadGalleryTemplates(): Promise<Template[]>;
645
+
531
646
  export declare interface MergeTag {
532
647
  name: string;
533
648
  label: string;
@@ -547,7 +662,9 @@ export declare function moveRow(rowId: string, toIndex: number): Command;
547
662
  export declare interface NavBarBlock {
548
663
  id: string;
549
664
  type: 'navbar';
550
- values: {
665
+ values: DeviceVisibility & {
666
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
667
+ condition?: string;
551
668
  links: NavLink[];
552
669
  hamburger: 'hamburger' | 'none';
553
670
  alignment: 'left' | 'center' | 'right';
@@ -581,6 +698,25 @@ export declare interface PigeonDocument {
581
698
  backgroundColor: string;
582
699
  fontFamily: string;
583
700
  contentAlignment: 'center' | 'left';
701
+ /**
702
+ * Link colour and underline for the whole document. Omitted, or with a
703
+ * part omitted, links fall back to whatever each client defaults to —
704
+ * blue and underlined in most, purple once visited in some.
705
+ */
706
+ linkStyle?: LinkStyle_2;
707
+ /**
708
+ * BCP 47 tag, e.g. `"en"`, `"pt-BR"`. Written out as `lang` on `<mjml>`,
709
+ * which MJML copies onto `<html>` and the `role="article"` wrapper.
710
+ * Left unset, the output keeps MJML's own `lang="und"`.
711
+ */
712
+ language?: string;
713
+ /**
714
+ * Written out as `dir` on `<mjml>`. Defaults to the natural direction of
715
+ * `language`, so it only needs setting to override that.
716
+ */
717
+ direction?: 'ltr' | 'rtl';
718
+ /** Document-level CSS, written out as a non-inline `<mj-style>`. */
719
+ css?: string;
584
720
  };
585
721
  rows: RowNode[];
586
722
  };
@@ -687,6 +823,28 @@ export declare interface RenderResult {
687
823
 
688
824
  export declare function resizeColumns(rowId: string, ratios: number[]): Command;
689
825
 
826
+ /**
827
+ * Resolve text direction for a BCP 47 tag: an explicit override wins, else the
828
+ * language subtag decides (`ar`, `pt-BR` → `rtl`, `ltr`). Shared by the editor
829
+ * chrome and the renderer so the RTL list is defined once.
830
+ */
831
+ export declare function resolveDirection(language?: string, override?: 'ltr' | 'rtl'): 'ltr' | 'rtl';
832
+
833
+ /** A row's background image with every MJML attribute resolved. */
834
+ export declare interface ResolvedRowBackground {
835
+ url: string;
836
+ repeat: 'repeat' | 'no-repeat';
837
+ size: string;
838
+ position: string;
839
+ }
840
+
841
+ /**
842
+ * Resolves a row's background image to the values the renderer emits, so the
843
+ * canvas and the export cannot disagree about how the image is cropped.
844
+ * Returns undefined when the row has no background image.
845
+ */
846
+ export declare function resolveRowBackground(row: RowNode): ResolvedRowBackground | undefined;
847
+
690
848
  /** Pluggable persistence for the row library. Mirrors {@link TemplateStorage}. */
691
849
  export declare interface RowLibraryStorage {
692
850
  list(): Promise<LibraryEntry[]>;
@@ -698,9 +856,18 @@ export declare interface RowLibraryStorage {
698
856
  export declare interface RowNode {
699
857
  id: string;
700
858
  type: 'row';
701
- attributes: {
859
+ attributes: DeviceVisibility & {
702
860
  backgroundColor?: string;
703
861
  backgroundImage?: string;
862
+ /**
863
+ * MJML `background-repeat` for {@link backgroundImage}. Absent means the
864
+ * legacy `no-repeat`; see {@link resolveRowBackground}.
865
+ */
866
+ backgroundRepeat?: 'repeat' | 'no-repeat';
867
+ /** MJML `background-size`: `cover`, `contain`, `auto` or a CSS length. */
868
+ backgroundSize?: string;
869
+ /** MJML `background-position`, e.g. `top center`. */
870
+ backgroundPosition?: string;
704
871
  padding: Spacing;
705
872
  fullWidth: boolean;
706
873
  /**
@@ -710,6 +877,21 @@ export declare interface RowNode {
710
877
  * / Liquid-style, passed through verbatim), e.g. `condition: "user.premium"`.
711
878
  */
712
879
  condition?: string;
880
+ /**
881
+ * Optional array merge-tag path. When set, the row repeats once per item:
882
+ * the renderer wraps the section in `{{#each <repeat>}} … {{/each}}`
883
+ * (Handlebars), inside any `condition`, e.g. `repeat: "order.items"`.
884
+ * Merge tags inside the row then resolve against the item (`{{name}}`).
885
+ */
886
+ repeat?: string;
887
+ /** Written out as MJML `css-class`. */
888
+ cssClass?: string;
889
+ /**
890
+ * When true, the columns keep their widths on mobile instead of stacking.
891
+ * Rendered as MJML `<mj-group>`, which is what holds a logo beside a nav
892
+ * on a phone. Off by default: columns stack.
893
+ */
894
+ noStackOnMobile?: boolean;
713
895
  };
714
896
  columns: ColumnNode[];
715
897
  columnRatios: number[];
@@ -726,10 +908,20 @@ export { Selection_2 as Selection }
726
908
 
727
909
  export declare function selectionsEqual(a: Selection_2 | null, b: Selection_2 | null): boolean;
728
910
 
911
+ /**
912
+ * Restricts the editor to `types`, in the order given. Pass `undefined` to
913
+ * lift the restriction. Availability gates *insertion*, not rendering: a
914
+ * document that already contains a type the host left out still renders, so
915
+ * narrowing the palette never blanks a saved template.
916
+ */
917
+ export declare function setAvailableBlockTypes(types: readonly string[] | undefined): void;
918
+
729
919
  export declare interface SocialBlock {
730
920
  id: string;
731
921
  type: 'social';
732
- values: {
922
+ values: DeviceVisibility & {
923
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
924
+ condition?: string;
733
925
  icons: SocialIcon[];
734
926
  iconSize: number;
735
927
  spacing: number;
@@ -748,7 +940,9 @@ export declare interface SocialIcon {
748
940
  export declare interface SpacerBlock {
749
941
  id: string;
750
942
  type: 'spacer';
751
- values: {
943
+ values: DeviceVisibility & {
944
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
945
+ condition?: string;
752
946
  height: number;
753
947
  };
754
948
  }
@@ -827,11 +1021,15 @@ export declare interface TemplateStorage {
827
1021
  export declare interface TextBlock {
828
1022
  id: string;
829
1023
  type: 'text';
830
- values: {
1024
+ values: DeviceVisibility & {
1025
+ /** Display condition; see {@link RowNode} `condition`. Wraps just this block. */
1026
+ condition?: string;
831
1027
  content: string;
832
1028
  padding: Spacing;
833
1029
  lineHeight: string;
834
1030
  textAlign: 'left' | 'center' | 'right';
1031
+ /** Written out as MJML `css-class`. */
1032
+ cssClass?: string;
835
1033
  };
836
1034
  }
837
1035
 
@@ -869,6 +1067,8 @@ export declare function undo(state: EditorStateSnapshot, dispatch?: (tr: Transac
869
1067
 
870
1068
  export declare function updateBlock(rowId: string, columnId: string, blockId: string, values: Record<string, unknown>): Command;
871
1069
 
1070
+ export declare function updateColumnAttributes(rowId: string, columnId: string, attributes: Partial<ColumnNode['attributes']>): Command;
1071
+
872
1072
  export declare function updateRowAttributes(rowId: string, attributes: Partial<RowNode['attributes']>): Command;
873
1073
 
874
1074
  export declare function validateDocument(doc: unknown): ValidationError[];