mjml-blocks 4.6.0 → 4.7.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 +144 -1200
- package/dist/index.js +76 -1934
- package/dist/models/CreateMjmlNodeSchemaOptions.d.ts +8 -0
- package/dist/models/CreateMjmlRegistryOptions.d.ts +11 -0
- package/dist/models/MjmlAccordionElementNode.d.ts +4 -0
- package/dist/models/MjmlAccordionElementProps.d.ts +18 -0
- package/dist/models/MjmlAccordionNode.d.ts +4 -0
- package/dist/models/MjmlAccordionProps.d.ts +22 -0
- package/dist/models/MjmlAccordionTextNode.d.ts +4 -0
- package/dist/models/MjmlAccordionTextProps.d.ts +17 -0
- package/dist/models/MjmlAccordionTitleNode.d.ts +4 -0
- package/dist/models/MjmlAccordionTitleProps.d.ts +14 -0
- package/dist/models/MjmlAttributeField.d.ts +6 -0
- package/dist/models/MjmlAttributeKind.d.ts +8 -0
- package/dist/models/MjmlAttributeKind.js +11 -0
- package/dist/models/MjmlAttributeSchema.d.ts +2 -0
- package/dist/models/MjmlAttributeType.d.ts +19 -0
- package/dist/models/MjmlBlockTypeDefinition.d.ts +26 -0
- package/dist/models/MjmlBuiltInNode.d.ts +23 -0
- package/dist/models/MjmlButtonNode.d.ts +4 -0
- package/dist/models/MjmlButtonProps.d.ts +37 -0
- package/dist/models/MjmlCarouselImageNode.d.ts +4 -0
- package/dist/models/MjmlCarouselImageProps.d.ts +14 -0
- package/dist/models/MjmlCarouselNode.d.ts +4 -0
- package/dist/models/MjmlCarouselProps.d.ts +22 -0
- package/dist/models/MjmlColumnNode.d.ts +4 -0
- package/dist/models/MjmlColumnProps.d.ts +28 -0
- package/dist/models/MjmlContentKind.d.ts +5 -0
- package/dist/models/MjmlContentKind.js +8 -0
- package/dist/models/MjmlDirection.d.ts +5 -0
- package/dist/models/MjmlDirection.js +8 -0
- package/dist/models/MjmlDividerNode.d.ts +4 -0
- package/dist/models/MjmlDividerProps.d.ts +14 -0
- package/dist/models/MjmlDocument.d.ts +4 -0
- package/dist/models/MjmlFlowNode.d.ts +12 -0
- package/dist/models/MjmlGroupNode.d.ts +4 -0
- package/dist/models/MjmlGroupProps.d.ts +10 -0
- package/dist/models/MjmlHeroNode.d.ts +4 -0
- package/dist/models/MjmlHeroProps.d.ts +26 -0
- package/dist/models/MjmlImageNode.d.ts +4 -0
- package/dist/models/MjmlImageProps.d.ts +32 -0
- package/dist/models/MjmlJson.d.ts +12 -0
- package/dist/models/MjmlLeafNode.d.ts +2 -0
- package/dist/models/MjmlLeafNodeSchema.d.ts +6 -0
- package/dist/models/MjmlLeafNodes.d.ts +1 -0
- package/dist/models/MjmlNavbarLinkNode.d.ts +4 -0
- package/dist/models/MjmlNavbarLinkProps.d.ts +22 -0
- package/dist/models/MjmlNavbarNode.d.ts +4 -0
- package/dist/models/MjmlNavbarProps.d.ts +28 -0
- package/dist/models/MjmlNode.d.ts +3 -0
- package/dist/models/MjmlNodeDefinition.d.ts +3 -0
- package/dist/models/MjmlNodeType.d.ts +24 -0
- package/dist/models/MjmlNodeType.js +27 -0
- package/dist/models/MjmlRawNode.d.ts +4 -0
- package/dist/models/MjmlRawProps.d.ts +5 -0
- package/dist/models/MjmlRegistry.d.ts +7 -0
- package/dist/models/MjmlRenderSpecification.d.ts +9 -0
- package/dist/models/MjmlRichText.d.ts +11 -0
- package/dist/models/MjmlRichTextAttributeValue.d.ts +3 -0
- package/dist/models/MjmlRichTextDefinition.d.ts +7 -0
- package/dist/models/MjmlRichTextTypeOptions.d.ts +10 -0
- package/dist/models/MjmlRootProps.d.ts +20 -0
- package/dist/models/MjmlSectionNode.d.ts +4 -0
- package/dist/models/MjmlSectionProps.d.ts +30 -0
- package/dist/models/MjmlSocialElementNode.d.ts +4 -0
- package/dist/models/MjmlSocialElementProps.d.ts +35 -0
- package/dist/models/MjmlSocialNode.d.ts +4 -0
- package/dist/models/MjmlSocialProps.d.ts +30 -0
- package/dist/models/MjmlSpacerNode.d.ts +4 -0
- package/dist/models/MjmlSpacerProps.d.ts +15 -0
- package/dist/models/MjmlTableNode.d.ts +4 -0
- package/dist/models/MjmlTableProps.d.ts +23 -0
- package/dist/models/MjmlTextNode.d.ts +4 -0
- package/dist/models/MjmlTextProps.d.ts +24 -0
- package/dist/models/MjmlWrapperNode.d.ts +4 -0
- package/dist/models/MjmlWrapperProps.d.ts +31 -0
- package/dist/models/RenderMjmlDocumentOptions.d.ts +4 -0
- package/dist/services/MjmlContentKindSchemaMap.d.ts +3 -0
- package/dist/services/MjmlContentKindSchemaMap.js +9 -0
- package/dist/services/allowedAddressSchema.d.ts +2 -0
- package/dist/services/allowedAddressSchema.js +6 -0
- package/dist/services/checkHasElement.d.ts +1 -0
- package/dist/services/checkHasElement.js +6 -0
- package/dist/services/checkIsMjmlAddressAttribute.d.ts +1 -0
- package/dist/services/checkIsMjmlAddressAttribute.js +7 -0
- package/dist/services/checkIsRepeatedMjmlTag.d.ts +1 -0
- package/dist/services/checkIsRepeatedMjmlTag.js +7 -0
- package/dist/services/checkMjmlAlternativeText.d.ts +5 -0
- package/dist/services/checkMjmlAlternativeText.js +9 -0
- package/dist/services/checkMjmlAttributeValues.d.ts +2 -0
- package/dist/services/checkMjmlAttributeValues.js +23 -0
- package/dist/services/components/createMjmlAccordionTextPropsSchema.d.ts +8 -0
- package/dist/services/components/createMjmlAccordionTextPropsSchema.js +6 -0
- package/dist/services/components/createMjmlAccordionTextType.d.ts +5 -0
- package/dist/services/components/createMjmlAccordionTextType.js +17 -0
- package/dist/services/components/createMjmlRichTextPropsSchema.d.ts +7 -0
- package/dist/services/components/createMjmlRichTextPropsSchema.js +7 -0
- package/dist/services/components/createMjmlRichTextType.d.ts +7 -0
- package/dist/services/components/createMjmlRichTextType.js +22 -0
- package/dist/services/components/createMjmlTextPropsSchema.d.ts +8 -0
- package/dist/services/components/createMjmlTextPropsSchema.js +6 -0
- package/dist/services/components/createMjmlTextType.d.ts +5 -0
- package/dist/services/components/createMjmlTextType.js +20 -0
- package/dist/services/components/mjAccordion.d.ts +23 -0
- package/dist/services/components/mjAccordion.js +52 -0
- package/dist/services/components/mjAccordionElement.d.ts +19 -0
- package/dist/services/components/mjAccordionElement.js +42 -0
- package/dist/services/components/mjAccordionText.d.ts +13 -0
- package/dist/services/components/mjAccordionText.js +13 -0
- package/dist/services/components/mjAccordionTitle.d.ts +19 -0
- package/dist/services/components/mjAccordionTitle.js +42 -0
- package/dist/services/components/mjButton.d.ts +42 -0
- package/dist/services/components/mjButton.js +78 -0
- package/dist/services/components/mjCarousel.d.ts +24 -0
- package/dist/services/components/mjCarousel.js +52 -0
- package/dist/services/components/mjCarouselImage.d.ts +20 -0
- package/dist/services/components/mjCarouselImage.js +44 -0
- package/dist/services/components/mjColumn.d.ts +30 -0
- package/dist/services/components/mjColumn.js +64 -0
- package/dist/services/components/mjDivider.d.ts +18 -0
- package/dist/services/components/mjDivider.js +42 -0
- package/dist/services/components/mjGroup.d.ts +12 -0
- package/dist/services/components/mjGroup.js +31 -0
- package/dist/services/components/mjHero.d.ts +28 -0
- package/dist/services/components/mjHero.js +66 -0
- package/dist/services/components/mjImage.d.ts +37 -0
- package/dist/services/components/mjImage.js +64 -0
- package/dist/services/components/mjNavbar.d.ts +29 -0
- package/dist/services/components/mjNavbar.js +58 -0
- package/dist/services/components/mjNavbarLink.d.ts +27 -0
- package/dist/services/components/mjNavbarLink.js +57 -0
- package/dist/services/components/mjRaw.d.ts +11 -0
- package/dist/services/components/mjRaw.js +31 -0
- package/dist/services/components/mjSection.d.ts +7 -0
- package/dist/services/components/mjSection.js +30 -0
- package/dist/services/components/mjSocial.d.ts +31 -0
- package/dist/services/components/mjSocial.js +59 -0
- package/dist/services/components/mjSocialElement.d.ts +40 -0
- package/dist/services/components/mjSocialElement.js +75 -0
- package/dist/services/components/mjSpacer.d.ts +19 -0
- package/dist/services/components/mjSpacer.js +36 -0
- package/dist/services/components/mjTable.d.ts +28 -0
- package/dist/services/components/mjTable.js +60 -0
- package/dist/services/components/mjText.d.ts +20 -0
- package/dist/services/components/mjText.js +20 -0
- package/dist/services/components/mjWrapper.d.ts +14 -0
- package/dist/services/components/mjWrapper.js +39 -0
- package/dist/services/components/sectionAttributes.d.ts +36 -0
- package/dist/services/components/sectionAttributes.js +40 -0
- package/dist/services/constants.d.ts +23 -0
- package/dist/services/constants.js +207 -0
- package/dist/services/createMjmlAttributeSchema.d.ts +2 -0
- package/dist/services/createMjmlAttributeSchema.js +10 -0
- package/dist/services/createMjmlAttributeShape.d.ts +2 -0
- package/dist/services/createMjmlAttributeShape.js +6 -0
- package/dist/services/createMjmlDocumentSchema.d.ts +6 -0
- package/dist/services/createMjmlDocumentSchema.js +4 -0
- package/dist/services/createMjmlNodeBranch.d.ts +7 -0
- package/dist/services/createMjmlNodeBranch.js +23 -0
- package/dist/services/createMjmlRawContentSchema.d.ts +2 -0
- package/dist/services/createMjmlRawContentSchema.js +6 -0
- package/dist/services/createMjmlRegistry.d.ts +4 -0
- package/dist/services/createMjmlRegistry.js +62 -0
- package/dist/services/createMjmlRootPropsSchema.d.ts +3 -0
- package/dist/services/createMjmlRootPropsSchema.js +49 -0
- package/dist/services/createMjmlSlotSchema.d.ts +6 -0
- package/dist/services/createMjmlSlotSchema.js +5 -0
- package/dist/services/createTypeSchema.d.ts +3 -0
- package/dist/services/createTypeSchema.js +19 -0
- package/dist/services/createUnitPattern.d.ts +1 -0
- package/dist/services/createUnitPattern.js +8 -0
- package/dist/services/escapeMjmlAttributes.d.ts +1 -0
- package/dist/services/escapeMjmlAttributes.js +4 -0
- package/dist/services/getMjmlAttributeFields.d.ts +3 -0
- package/dist/services/getMjmlAttributeFields.js +8 -0
- package/dist/services/getMjmlAttributeSchema.d.ts +2 -0
- package/dist/services/getMjmlAttributeSchema.js +7 -0
- package/dist/services/getMjmlRefusalKey.d.ts +1 -0
- package/dist/services/getMjmlRefusalKey.js +3 -0
- package/dist/services/labelContentSchema.d.ts +2 -0
- package/dist/services/labelContentSchema.js +5 -0
- package/dist/services/mjmlNodeChildren.d.ts +3 -0
- package/dist/services/mjmlNodeChildren.js +31 -0
- package/dist/services/mjmlNodeSchema.d.ts +8 -0
- package/dist/services/mjmlNodeSchema.js +113 -0
- package/dist/services/mjmlRootPropsSchema.d.ts +21 -0
- package/dist/services/mjmlRootPropsSchema.js +25 -0
- package/dist/services/parseMjmlAttributeType.d.ts +2 -0
- package/dist/services/parseMjmlAttributeType.js +31 -0
- package/dist/services/parseMjmlDocument.d.ts +7 -0
- package/dist/services/parseMjmlDocument.js +22 -0
- package/dist/services/readMjmlAttributeRefusal.d.ts +2 -0
- package/dist/services/readMjmlAttributeRefusal.js +4 -0
- package/dist/services/readMjmlContent.d.ts +5 -0
- package/dist/services/readMjmlContent.js +14 -0
- package/dist/services/readMjmlHead.d.ts +2 -0
- package/dist/services/readMjmlHead.js +53 -0
- package/dist/services/readMjmlHeadText.d.ts +2 -0
- package/dist/services/readMjmlHeadText.js +7 -0
- package/dist/services/readMjmlNode.d.ts +8 -0
- package/dist/services/readMjmlNode.js +32 -0
- package/dist/services/readMjmlNodes.d.ts +5 -0
- package/dist/services/readMjmlNodes.js +17 -0
- package/dist/services/readMjmlRoot.d.ts +10 -0
- package/dist/services/readMjmlRoot.js +39 -0
- package/dist/services/readMjmlStrayText.d.ts +2 -0
- package/dist/services/readMjmlStrayText.js +10 -0
- package/dist/services/readMjmlTopLevel.d.ts +2 -0
- package/dist/services/readMjmlTopLevel.js +11 -0
- package/dist/services/renderMjmlDocument.d.ts +5 -0
- package/dist/services/renderMjmlDocument.js +31 -0
- package/dist/services/renderMjmlHead.d.ts +3 -0
- package/dist/services/renderMjmlHead.js +43 -0
- package/dist/services/renderMjmlNode.d.ts +6 -0
- package/dist/services/renderMjmlNode.js +53 -0
- package/dist/services/serializeAttributes.d.ts +1 -0
- package/dist/services/serializeAttributes.js +3 -0
- package/dist/services/serializeMjml.d.ts +2 -0
- package/dist/services/serializeMjml.js +9 -0
- package/dist/services/stampNode.d.ts +3 -0
- package/dist/services/stampNode.js +15 -0
- package/package.json +6 -6
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { checkIsRepeatedMjmlTag } from "./checkIsRepeatedMjmlTag.js";
|
|
2
|
+
import { MJML_HEAD_SINGLE_TAGS } from "./constants.js";
|
|
3
|
+
import { getMjmlRefusalKey } from "./getMjmlRefusalKey.js";
|
|
4
|
+
import { readMjmlAttributeRefusal } from "./readMjmlAttributeRefusal.js";
|
|
5
|
+
import { readMjmlHeadText } from "./readMjmlHeadText.js";
|
|
6
|
+
import { readMjmlStrayText } from "./readMjmlStrayText.js";
|
|
7
|
+
// src/services/readMjmlHead.ts
|
|
8
|
+
const readMjmlHead = (head) => {
|
|
9
|
+
const entries = Object.entries(readMjmlStrayText(head));
|
|
10
|
+
entries.push(...readMjmlAttributeRefusal(head));
|
|
11
|
+
const readTagNames = /* @__PURE__ */ new Set();
|
|
12
|
+
const typeAttributesMap = /* @__PURE__ */ new Map();
|
|
13
|
+
const fonts = [];
|
|
14
|
+
const styles = [];
|
|
15
|
+
for (const child of head.children) {
|
|
16
|
+
if (MJML_HEAD_SINGLE_TAGS.includes(child.rawTagName) && checkIsRepeatedMjmlTag(child.rawTagName, readTagNames)) {
|
|
17
|
+
entries.push([getMjmlRefusalKey(child.rawTagName), child.attributes]);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
switch (child.rawTagName) {
|
|
21
|
+
case "mj-attributes":
|
|
22
|
+
entries.push(...readMjmlAttributeRefusal(child));
|
|
23
|
+
for (const { attributes, rawTagName } of child.children) if (typeAttributesMap.has(rawTagName)) entries.push([getMjmlRefusalKey(rawTagName), attributes]);
|
|
24
|
+
else typeAttributesMap.set(rawTagName, attributes);
|
|
25
|
+
break;
|
|
26
|
+
case "mj-breakpoint":
|
|
27
|
+
entries.push(["breakpoint", child.attributes]);
|
|
28
|
+
break;
|
|
29
|
+
case "mj-font":
|
|
30
|
+
fonts.push(child.attributes);
|
|
31
|
+
break;
|
|
32
|
+
case "mj-preview":
|
|
33
|
+
entries.push(...readMjmlHeadText(child, "preview"));
|
|
34
|
+
break;
|
|
35
|
+
case "mj-style":
|
|
36
|
+
if (Object.entries(child.attributes).every(([name, value]) => name === "inline" && value === "inline")) styles.push({
|
|
37
|
+
css: child.rawText,
|
|
38
|
+
inline: child.attributes.inline === "inline"
|
|
39
|
+
});
|
|
40
|
+
else entries.push([getMjmlRefusalKey(child.rawTagName), child.attributes]);
|
|
41
|
+
break;
|
|
42
|
+
case "mj-title":
|
|
43
|
+
entries.push(...readMjmlHeadText(child, "title"));
|
|
44
|
+
break;
|
|
45
|
+
default: entries.push([getMjmlRefusalKey(child.rawTagName), child.attributes]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (typeAttributesMap.size > 0) entries.push(["attributes", Object.fromEntries(typeAttributesMap)]);
|
|
49
|
+
if (fonts.length > 0) entries.push(["fonts", fonts]);
|
|
50
|
+
if (styles.length > 0) entries.push(["styles", styles]);
|
|
51
|
+
return entries;
|
|
52
|
+
};
|
|
53
|
+
export { readMjmlHead };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { readMjmlAttributeRefusal } from "./readMjmlAttributeRefusal.js";
|
|
2
|
+
// src/services/readMjmlHeadText.ts
|
|
3
|
+
const readMjmlHeadText = (tag, propName) => {
|
|
4
|
+
const refusal = readMjmlAttributeRefusal(tag);
|
|
5
|
+
return refusal.length > 0 ? refusal : [[propName, tag.text]];
|
|
6
|
+
};
|
|
7
|
+
export { readMjmlHeadText };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MjmlRegistry } from "../models/MjmlRegistry.js";
|
|
2
|
+
import { MjmlRichText } from "../models/MjmlRichText.js";
|
|
3
|
+
import { MjmlRichTextDefinition } from "../models/MjmlRichTextDefinition.js";
|
|
4
|
+
import { HTMLElement, Node } from "node-html-parser";
|
|
5
|
+
export declare const readMjmlNode: <TContext, TContent extends MjmlRichText>(element: HTMLElement, registry: MjmlRegistry<TContext>, richText: MjmlRichTextDefinition<TContent>, readChildNodes: (childNodes: Node[]) => unknown[]) => {
|
|
6
|
+
props: Record<string, unknown>;
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "./constants.js";
|
|
2
|
+
import { getMjmlRefusalKey } from "./getMjmlRefusalKey.js";
|
|
3
|
+
import { readMjmlContent } from "./readMjmlContent.js";
|
|
4
|
+
import { getBlockTypeDefinition } from "vue-block-editor-headless";
|
|
5
|
+
// src/services/readMjmlNode.ts
|
|
6
|
+
const readMjmlNode = (element, registry, richText, readChildNodes) => {
|
|
7
|
+
const type = element.rawTagName;
|
|
8
|
+
const definition = getBlockTypeDefinition(registry, type);
|
|
9
|
+
const { alt, id: idAttribute, ...attributes } = element.attributes;
|
|
10
|
+
const isDecorative = definition?.hasAlternativeText === true && alt === "";
|
|
11
|
+
const slotNames = Object.keys(definition?.slots ?? {});
|
|
12
|
+
const reservedNames = /* @__PURE__ */ new Set([
|
|
13
|
+
...slotNames,
|
|
14
|
+
...definition?.contentKind === void 0 ? [] : ["content"],
|
|
15
|
+
...definition?.hasAlternativeText === true ? ["decorative"] : []
|
|
16
|
+
]);
|
|
17
|
+
const entries = [];
|
|
18
|
+
for (const name of Object.keys(attributes)) entries.push([reservedNames.has(name) ? getMjmlRefusalKey(name) : name, attributes[name]]);
|
|
19
|
+
if (isDecorative) entries.push(["decorative", true]);
|
|
20
|
+
else if (alt !== void 0) entries.push(["alt", alt]);
|
|
21
|
+
if (idAttribute !== void 0) entries.push(["#id", idAttribute]);
|
|
22
|
+
entries.push(["id", crypto.randomUUID()]);
|
|
23
|
+
if (definition?.contentKind === void 0) {
|
|
24
|
+
const children = readChildNodes(element.childNodes);
|
|
25
|
+
if (children.length > 0 || slotNames.length > 0) entries.push(["children", children]);
|
|
26
|
+
} else entries.push(["content", readMjmlContent(element, definition.contentKind, richText)]);
|
|
27
|
+
return {
|
|
28
|
+
props: Object.fromEntries(entries),
|
|
29
|
+
type
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export { readMjmlNode };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MjmlRegistry } from "../models/MjmlRegistry.js";
|
|
2
|
+
import { MjmlRichText } from "../models/MjmlRichText.js";
|
|
3
|
+
import { MjmlRichTextDefinition } from "../models/MjmlRichTextDefinition.js";
|
|
4
|
+
import { Node } from "node-html-parser";
|
|
5
|
+
export declare const readMjmlNodes: <TContext, TContent extends MjmlRichText>(children: Node[], registry: MjmlRegistry<TContext>, richText: MjmlRichTextDefinition<TContent>) => unknown[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { STRAY_TEXT_TYPE } from "./constants.js";
|
|
2
|
+
import { readMjmlNode } from "./readMjmlNode.js";
|
|
3
|
+
import { normalizeString } from "@esposter/shared";
|
|
4
|
+
import { HTMLElement, TextNode } from "node-html-parser";
|
|
5
|
+
// src/services/readMjmlNodes.ts
|
|
6
|
+
const readMjmlNodes = (children, registry, richText) => children.flatMap((child) => {
|
|
7
|
+
if (child instanceof HTMLElement) return [readMjmlNode(child, registry, richText, (grandchildren) => readMjmlNodes(grandchildren, registry, richText))];
|
|
8
|
+
if (child instanceof TextNode && normalizeString(child.text) !== "") return [{
|
|
9
|
+
props: {
|
|
10
|
+
content: child.text,
|
|
11
|
+
id: crypto.randomUUID()
|
|
12
|
+
},
|
|
13
|
+
type: STRAY_TEXT_TYPE
|
|
14
|
+
}];
|
|
15
|
+
return [];
|
|
16
|
+
});
|
|
17
|
+
export { readMjmlNodes };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MjmlRegistry } from "../models/MjmlRegistry.js";
|
|
2
|
+
import { MjmlRichText } from "../models/MjmlRichText.js";
|
|
3
|
+
import { MjmlRichTextDefinition } from "../models/MjmlRichTextDefinition.js";
|
|
4
|
+
import { HTMLElement } from "node-html-parser";
|
|
5
|
+
export declare const readMjmlRoot: <TContext, TContent extends MjmlRichText>(mjml: HTMLElement, registry: MjmlRegistry<TContext>, richText: MjmlRichTextDefinition<TContent>) => {
|
|
6
|
+
content: unknown[];
|
|
7
|
+
root: {
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { checkIsRepeatedMjmlTag } from "./checkIsRepeatedMjmlTag.js";
|
|
2
|
+
import "./constants.js";
|
|
3
|
+
import { getMjmlRefusalKey } from "./getMjmlRefusalKey.js";
|
|
4
|
+
import { readMjmlHead } from "./readMjmlHead.js";
|
|
5
|
+
import { readMjmlNodes } from "./readMjmlNodes.js";
|
|
6
|
+
import { readMjmlStrayText } from "./readMjmlStrayText.js";
|
|
7
|
+
// src/services/readMjmlRoot.ts
|
|
8
|
+
const readMjmlRoot = (mjml, registry, richText) => {
|
|
9
|
+
const { ["dir"]: direction, lang, ...refusedAttributes } = mjml.attributes;
|
|
10
|
+
const entries = [
|
|
11
|
+
...Object.entries(readMjmlStrayText(mjml)),
|
|
12
|
+
...direction === void 0 ? [] : [["direction", direction]],
|
|
13
|
+
...lang === void 0 ? [] : [["lang", lang]]
|
|
14
|
+
];
|
|
15
|
+
if (Object.keys(refusedAttributes).length > 0) entries.push([getMjmlRefusalKey("mjml"), refusedAttributes]);
|
|
16
|
+
const readTagNames = /* @__PURE__ */ new Set();
|
|
17
|
+
let content = [];
|
|
18
|
+
for (const child of mjml.children) {
|
|
19
|
+
if (checkIsRepeatedMjmlTag(child.rawTagName, readTagNames)) {
|
|
20
|
+
entries.push([getMjmlRefusalKey(child.rawTagName), child.attributes]);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
switch (child.rawTagName) {
|
|
24
|
+
case "mj-body":
|
|
25
|
+
entries.push(["body", child.attributes]);
|
|
26
|
+
content = readMjmlNodes(child.childNodes, registry, richText);
|
|
27
|
+
break;
|
|
28
|
+
case "mj-head":
|
|
29
|
+
entries.push(...readMjmlHead(child));
|
|
30
|
+
break;
|
|
31
|
+
default: entries.push([getMjmlRefusalKey(child.rawTagName), child.attributes]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
content,
|
|
36
|
+
root: { props: Object.fromEntries(entries) }
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export { readMjmlRoot };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { STRAY_TEXT_TYPE } from "./constants.js";
|
|
2
|
+
import { normalizeString } from "@esposter/shared";
|
|
3
|
+
import { TextNode } from "node-html-parser";
|
|
4
|
+
// src/services/readMjmlStrayText.ts
|
|
5
|
+
const readMjmlStrayText = (element) => {
|
|
6
|
+
const strayText = {};
|
|
7
|
+
for (const text of element.childNodes) if (text instanceof TextNode && normalizeString(text.text) !== "") strayText[STRAY_TEXT_TYPE] = text.text;
|
|
8
|
+
return strayText;
|
|
9
|
+
};
|
|
10
|
+
export { readMjmlStrayText };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getMjmlRefusalKey } from "./getMjmlRefusalKey.js";
|
|
2
|
+
import { readMjmlStrayText } from "./readMjmlStrayText.js";
|
|
3
|
+
// src/services/readMjmlTopLevel.ts
|
|
4
|
+
const readMjmlTopLevel = (root) => {
|
|
5
|
+
const [mjml, ...others] = root.children;
|
|
6
|
+
const strayText = Object.entries(readMjmlStrayText(root));
|
|
7
|
+
if (mjml?.rawTagName !== "mjml") return [...strayText, [mjml === void 0 ? "#document" : getMjmlRefusalKey(mjml.rawTagName), {}]];
|
|
8
|
+
if (others.length > 0) return [...strayText, ["#document", {}]];
|
|
9
|
+
return strayText;
|
|
10
|
+
};
|
|
11
|
+
export { readMjmlTopLevel };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MjmlDocument } from "../models/MjmlDocument.js";
|
|
2
|
+
import { MjmlJson } from "../models/MjmlJson.js";
|
|
3
|
+
import { MjmlRegistry } from "../models/MjmlRegistry.js";
|
|
4
|
+
import { RenderMjmlDocumentOptions } from "../models/RenderMjmlDocumentOptions.js";
|
|
5
|
+
export declare const renderMjmlDocument: <TContext>(document: MjmlDocument, registry: MjmlRegistry<TContext>, options: RenderMjmlDocumentOptions<TContext>) => MjmlJson;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "./constants.js";
|
|
2
|
+
import { escapeMjmlAttributes } from "./escapeMjmlAttributes.js";
|
|
3
|
+
import { renderMjmlHead } from "./renderMjmlHead.js";
|
|
4
|
+
import { stampNode } from "./stampNode.js";
|
|
5
|
+
import { renderBlockNodes } from "vue-block-editor-headless";
|
|
6
|
+
// src/services/renderMjmlDocument.ts
|
|
7
|
+
const renderMjmlDocument = (document, registry, options) => {
|
|
8
|
+
const rootProps = document.root.props;
|
|
9
|
+
const content = renderBlockNodes(document.content, registry, registry.children, (node, definition, slots) => {
|
|
10
|
+
const output = definition.render(node, slots, options.context);
|
|
11
|
+
return stampNode(output, node, options.isStampingIds);
|
|
12
|
+
});
|
|
13
|
+
const head = renderMjmlHead(rootProps);
|
|
14
|
+
const rootAttributes = {};
|
|
15
|
+
if (rootProps.lang !== void 0) rootAttributes.lang = rootProps.lang;
|
|
16
|
+
if (rootProps.direction !== void 0) rootAttributes["dir"] = rootProps.direction;
|
|
17
|
+
return {
|
|
18
|
+
attributes: escapeMjmlAttributes(rootAttributes),
|
|
19
|
+
children: [...head.length > 0 ? [{
|
|
20
|
+
attributes: {},
|
|
21
|
+
children: head,
|
|
22
|
+
tagName: "mj-head"
|
|
23
|
+
}] : [], {
|
|
24
|
+
attributes: escapeMjmlAttributes(rootProps.body ?? {}),
|
|
25
|
+
children: content,
|
|
26
|
+
tagName: "mj-body"
|
|
27
|
+
}],
|
|
28
|
+
tagName: "mjml"
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export { renderMjmlDocument };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { escapeMjmlAttributes } from "./escapeMjmlAttributes.js";
|
|
2
|
+
import { escapeText } from "@esposter/shared";
|
|
3
|
+
// src/services/renderMjmlHead.ts
|
|
4
|
+
const renderMjmlHead = (rootProps) => {
|
|
5
|
+
const head = [];
|
|
6
|
+
if (rootProps.title !== void 0) head.push({
|
|
7
|
+
attributes: {},
|
|
8
|
+
content: escapeText(rootProps.title),
|
|
9
|
+
tagName: "mj-title"
|
|
10
|
+
});
|
|
11
|
+
if (rootProps.preview !== void 0) head.push({
|
|
12
|
+
attributes: {},
|
|
13
|
+
content: escapeText(rootProps.preview),
|
|
14
|
+
tagName: "mj-preview"
|
|
15
|
+
});
|
|
16
|
+
for (const font of rootProps.fonts ?? []) head.push({
|
|
17
|
+
attributes: escapeMjmlAttributes({
|
|
18
|
+
href: font.href,
|
|
19
|
+
name: font.name
|
|
20
|
+
}),
|
|
21
|
+
tagName: "mj-font"
|
|
22
|
+
});
|
|
23
|
+
if (rootProps.breakpoint) head.push({
|
|
24
|
+
attributes: escapeMjmlAttributes(rootProps.breakpoint),
|
|
25
|
+
tagName: "mj-breakpoint"
|
|
26
|
+
});
|
|
27
|
+
const attributesByType = Object.entries(rootProps.attributes ?? {});
|
|
28
|
+
if (attributesByType.length > 0) head.push({
|
|
29
|
+
attributes: {},
|
|
30
|
+
children: attributesByType.map(([type, attributes]) => ({
|
|
31
|
+
attributes: escapeMjmlAttributes(attributes),
|
|
32
|
+
tagName: type
|
|
33
|
+
})),
|
|
34
|
+
tagName: "mj-attributes"
|
|
35
|
+
});
|
|
36
|
+
for (const style of rootProps.styles ?? []) head.push({
|
|
37
|
+
attributes: style.inline ? { inline: "inline" } : {},
|
|
38
|
+
content: style.css,
|
|
39
|
+
tagName: "mj-style"
|
|
40
|
+
});
|
|
41
|
+
return head;
|
|
42
|
+
};
|
|
43
|
+
export { renderMjmlHead };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MjmlJson } from "../models/MjmlJson.js";
|
|
2
|
+
import { MjmlRenderSpecification } from "../models/MjmlRenderSpecification.js";
|
|
3
|
+
import { MjmlRichText } from "../models/MjmlRichText.js";
|
|
4
|
+
import { MjmlRichTextDefinition } from "../models/MjmlRichTextDefinition.js";
|
|
5
|
+
import { BlockNode } from "vue-block-editor-headless";
|
|
6
|
+
export declare const renderMjmlNode: <TContent extends MjmlRichText>(specification: MjmlRenderSpecification, richText?: MjmlRichTextDefinition<TContent>) => (node: BlockNode, slots: Record<string, MjmlJson[]>) => MjmlJson;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import "../models/MjmlAttributeKind.js";
|
|
2
|
+
import "../models/MjmlContentKind.js";
|
|
3
|
+
import { MjmlContentKindSchemaMap } from "./MjmlContentKindSchemaMap.js";
|
|
4
|
+
import { parseMjmlAttributeType } from "./parseMjmlAttributeType.js";
|
|
5
|
+
import { InvalidOperationError, Operation, escapeAttribute, escapeText, exhaustiveGuard } from "@esposter/shared";
|
|
6
|
+
import { getBlockPropValue } from "vue-block-editor-headless";
|
|
7
|
+
// src/services/renderMjmlNode.ts
|
|
8
|
+
const renderMjmlNode = (specification, richText) => {
|
|
9
|
+
const attributeTypes = Object.entries(specification.allowedAttributes).map(([name, grammar]) => ({
|
|
10
|
+
name,
|
|
11
|
+
type: parseMjmlAttributeType(grammar)
|
|
12
|
+
}));
|
|
13
|
+
return (node, slots) => {
|
|
14
|
+
const attributes = {};
|
|
15
|
+
for (const { name, type } of attributeTypes) {
|
|
16
|
+
const value = getBlockPropValue(node.props, name);
|
|
17
|
+
if (typeof value === "string") attributes[name] = type.kind === "boolean" ? value === "true" : escapeAttribute(value);
|
|
18
|
+
}
|
|
19
|
+
if (specification.hasAlternativeText && getBlockPropValue(node.props, "decorative") === true) attributes.alt = "";
|
|
20
|
+
const element = {
|
|
21
|
+
attributes,
|
|
22
|
+
tagName: specification.tagName
|
|
23
|
+
};
|
|
24
|
+
if (specification.hasChildren) return {
|
|
25
|
+
...element,
|
|
26
|
+
children: slots.children ?? []
|
|
27
|
+
};
|
|
28
|
+
switch (specification.contentKind) {
|
|
29
|
+
case "label": {
|
|
30
|
+
const parsedLabel = MjmlContentKindSchemaMap["label"].parse(getBlockPropValue(node.props, "content"));
|
|
31
|
+
return {
|
|
32
|
+
...element,
|
|
33
|
+
content: escapeText(parsedLabel)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
case "raw": return {
|
|
37
|
+
...element,
|
|
38
|
+
content: MjmlContentKindSchemaMap["raw"].parse(getBlockPropValue(node.props, "content"))
|
|
39
|
+
};
|
|
40
|
+
case "richText": {
|
|
41
|
+
if (richText === void 0) throw new InvalidOperationError(Operation.Read, specification.tagName, "needs a rich text definition to render");
|
|
42
|
+
const parsedRichText = richText.schema.parse(getBlockPropValue(node.props, "content"));
|
|
43
|
+
return {
|
|
44
|
+
...element,
|
|
45
|
+
content: richText.renderHtml(parsedRichText)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
case void 0: return element;
|
|
49
|
+
default: return exhaustiveGuard(specification.contentKind);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export { renderMjmlNode };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const serializeAttributes: (attributes: Record<string, boolean | string>) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { serializeAttributes } from "./serializeAttributes.js";
|
|
2
|
+
// src/services/serializeMjml.ts
|
|
3
|
+
const serializeMjml = (json) => {
|
|
4
|
+
const attributes = serializeAttributes(json.attributes);
|
|
5
|
+
if ("children" in json) return `<${json.tagName}${attributes}>${json.children.map((child) => serializeMjml(child)).join("")}</${json.tagName}>`;
|
|
6
|
+
const content = "content" in json ? json.content : "";
|
|
7
|
+
return `<${json.tagName}${attributes}>${content}</${json.tagName}>`;
|
|
8
|
+
};
|
|
9
|
+
export { serializeMjml };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { escapeAttribute } from "@esposter/shared";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/services/stampNode.ts
|
|
4
|
+
const stampNode = (output, node, isStampingIds) => {
|
|
5
|
+
if (!isStampingIds) return output;
|
|
6
|
+
const id = z.string().parse(node.props.id);
|
|
7
|
+
return {
|
|
8
|
+
...output,
|
|
9
|
+
attributes: {
|
|
10
|
+
...output.attributes,
|
|
11
|
+
"css-class": escapeAttribute(id)
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export { stampNode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mjml-blocks",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "MJML's components as block types on the headless block editor — each component's attributes, defaults and nesting rules, a render to MJML's JSON form and source, and a read back from MJML, with no framework, DOM or MJML runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript"
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"typecheck": "tsrs --fast"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@esposter/shared": "4.
|
|
43
|
+
"@esposter/shared": "4.7.0",
|
|
44
44
|
"node-html-parser": "^9.0.7",
|
|
45
|
-
"vue-block-editor-headless": "4.
|
|
45
|
+
"vue-block-editor-headless": "4.7.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@esposter/configuration": "4.
|
|
49
|
-
"@esposter/shared-node": "4.
|
|
48
|
+
"@esposter/configuration": "4.7.0",
|
|
49
|
+
"@esposter/shared-node": "4.7.0",
|
|
50
50
|
"@types/mjml": "^5.4.2",
|
|
51
51
|
"mjml": "^5.4.1",
|
|
52
52
|
"mjml-preset-core": "^5.4.1",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"zod": "^4.6.7"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "c819fd8f6196452894babddc3df9fb20cb0d6add"
|
|
59
59
|
}
|