easy-email-extensions 4.8.0 → 4.11.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/index2.js +194 -2
- package/lib/index2.js.map +1 -1
- package/lib/index3.js +1 -0
- package/lib/index3.js.map +1 -1
- package/lib/typings/mjml-browser.d.ts +37 -0
- package/lib/utils/MjmlToJson.d.ts +5 -0
- package/lib/utils/parseXMLtoBlock.d.ts +2 -0
- package/package.json +18 -7
- package/readme.md +117 -1
package/lib/index.d.ts
CHANGED
@@ -13,3 +13,4 @@ export * from './components/Form';
|
|
13
13
|
export { getContextMergeTags } from './utils/getContextMergeTags';
|
14
14
|
export { getIconNameByBlockType } from './utils/getIconNameByBlockType';
|
15
15
|
export { getBlockTitle } from './utils/getBlockTitle';
|
16
|
+
export { MjmlToJson } from './utils/MjmlToJson';
|
package/lib/index.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
export { e as Align, A as AttributePanel, f as AttributesPanelWrapper,
|
1
|
+
export { e as Align, A as AttributePanel, f as AttributesPanelWrapper, a9 as AutoCompleteField, l as Background, o as BackgroundColor, d as BlockAttributeConfigurationManager, B as BlockLayer, I as BlockMarketManager, J as BlockMaskWrapper, r as Border, t as BorderColor, w as BorderStyle, y as BorderWidth, ac as CheckboxField, G as ClassName, h as CollapseWrapper, C as Color, ag as ColorPickerField, i as Condition, j as ContainerBackgroundColor, D as Decoration, P as DefaultPageConfigPanel, p as Direction, ae as EditGridTabField, ad as EditTabField, X as ExtensionContext, Y as ExtensionProvider, F as FontFamily, u as FontSize, x as FontStyle, z as FontWeight, H as Height, a6 as ImageUploaderField, af as InlineTextField, a0 as InputWithUnitField, O as InteractivePrompt, L as LetterSpacing, m as LineHeight, q as Link, s as Margin, U as MergeTagBadgePrompt, v as MergeTags, M as MjmlToJson, N as NavbarLinkPadding, a3 as NumberField, E as Padding, _ as RICH_TEXT_TOOL_BAR, aa as RadioGroupField, ai as RichTextField, a1 as SearchField, a7 as SelectField, S as ShortcutToolbar, Q as SimpleLayout, a4 as SliderField, K as SourceCodePanel, R as StandardLayout, ab as SwitchField, T as TextAlign, a2 as TextAreaField, k as TextDecoration, $ as TextField, n as TextTransform, a8 as TreeSelectField, a5 as UploadField, V as VerticalAlign, W as Width, ah as enhancer, b as getBlockTitle, g as getContextMergeTags, a as getIconNameByBlockType, Z as useExtensionProps } from "./index2.js";
|
2
2
|
import "react";
|
3
3
|
import "easy-email-editor";
|
4
4
|
import "easy-email-core";
|
5
5
|
import "react-dom";
|
6
6
|
import "react-final-form";
|
7
|
+
import "mjml-browser";
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/lib/index2.js
CHANGED
@@ -57,9 +57,10 @@ var __async = (__this, __arguments, generator) => {
|
|
57
57
|
import * as React from "react";
|
58
58
|
import React__default, { Children, isValidElement, cloneElement, createContext, useContext, Component, useMemo, memo, forwardRef, useEffect, useRef, useLayoutEffect, useState, useImperativeHandle, PureComponent, useCallback, useReducer, createRef, Fragment, createElement, Suspense } from "react";
|
59
59
|
import { IconFont, useEditorProps, Stack as Stack$4, useRefState, getShadowRoot, DATA_CONTENT_EDITABLE_TYPE, ContentEditableType, TextStyle, useEditorContext, useBlock, useFocusIdx, useFocusBlockLayout, MergeTagBadge, FIXED_CONTAINER_ID, getPluginElement, RICH_TEXT_BAR_ID, CONTENT_EDITABLE_CLASS_NAME, getEditorRoot, DATA_CONTENT_EDITABLE_IDX, scrollBlockEleIntoView, useHoverIdx, useDataTransfer, getBlockNodeByChildEle, getDirectionPosition, DATA_ATTRIBUTE_DROP_CONTAINER, BlockAvatarWrapper, isTextBlock, getBlockNodeByIdx, useLazyState, useActiveTab, ActiveTabKeys } from "easy-email-editor";
|
60
|
-
import { BasicType, ImageManager, EMAIL_BLOCK_CLASS_NAME, BlockManager, createBlockDataByType, AdvancedType, Operator, OperatorSymbol, isAdvancedBlock, getParentByIdx, getParentIdx, getIndexByIdx, getSiblingIdx, getNodeIdxFromClassName, getNodeIdxClassName, getPageIdx, getChildIdx,
|
60
|
+
import { BasicType, ImageManager, EMAIL_BLOCK_CLASS_NAME, BlockManager, createBlockDataByType, AdvancedType, Operator, OperatorSymbol, isAdvancedBlock, getParentByIdx, getParentIdx, getIndexByIdx, getSiblingIdx, getNodeIdxFromClassName, getNodeIdxClassName, getPageIdx, getChildIdx, JsonToMjml, getNodeTypeFromClassName } from "easy-email-core";
|
61
61
|
import ReactDOM, { findDOMNode, createPortal } from "react-dom";
|
62
62
|
import { Field, useForm as useForm$1, useField, Form as Form$3, version as version$2, useFormState } from "react-final-form";
|
63
|
+
import mjml from "mjml-browser";
|
63
64
|
var index$2 = "";
|
64
65
|
const title = "_title_1f523_1";
|
65
66
|
var styles$a = {
|
@@ -35162,6 +35163,16 @@ function Text() {
|
|
35162
35163
|
setVisible
|
35163
35164
|
}));
|
35164
35165
|
}
|
35166
|
+
const fullWidthOnMobileAdapter = {
|
35167
|
+
format(obj) {
|
35168
|
+
return Boolean(obj);
|
35169
|
+
},
|
35170
|
+
parse(val) {
|
35171
|
+
if (!val)
|
35172
|
+
return void 0;
|
35173
|
+
return "true";
|
35174
|
+
}
|
35175
|
+
};
|
35165
35176
|
function Image$1() {
|
35166
35177
|
const { focusIdx: focusIdx2 } = useFocusIdx();
|
35167
35178
|
const { onUploadImage } = useEditorProps();
|
@@ -35185,6 +35196,10 @@ function Image$1() {
|
|
35185
35196
|
label: t("Background color"),
|
35186
35197
|
name: `${focusIdx2}.attributes.container-background-color`,
|
35187
35198
|
inline: true
|
35199
|
+
}), /* @__PURE__ */ React__default.createElement(SwitchField, {
|
35200
|
+
label: t("Full width on mobile"),
|
35201
|
+
name: `${focusIdx2}.attributes.fluid-on-mobile `,
|
35202
|
+
config: fullWidthOnMobileAdapter
|
35188
35203
|
}))), /* @__PURE__ */ React__default.createElement(Collapse$1.Item, {
|
35189
35204
|
name: "0",
|
35190
35205
|
header: t("Dimension")
|
@@ -39942,6 +39957,183 @@ function ShortcutToolbar() {
|
|
39942
39957
|
}
|
39943
39958
|
}));
|
39944
39959
|
}
|
39960
|
+
const domParser = new DOMParser();
|
39961
|
+
function parseXMLtoBlock(text) {
|
39962
|
+
const dom = domParser.parseFromString(text, "text/xml");
|
39963
|
+
const root2 = dom.firstChild;
|
39964
|
+
if (!(dom.firstChild instanceof Element)) {
|
39965
|
+
throw new Error("Invalid content");
|
39966
|
+
}
|
39967
|
+
if (root2.tagName === "mjml") {
|
39968
|
+
const { json } = mjml(text, {
|
39969
|
+
validationLevel: "soft"
|
39970
|
+
});
|
39971
|
+
const parseValue2 = MjmlToJson(json);
|
39972
|
+
return parseValue2;
|
39973
|
+
}
|
39974
|
+
const transform = (node) => {
|
39975
|
+
var _a;
|
39976
|
+
if (node.tagName === "parsererror") {
|
39977
|
+
throw new Error("Invalid content");
|
39978
|
+
}
|
39979
|
+
const attributes = {};
|
39980
|
+
node.getAttributeNames().forEach((name2) => {
|
39981
|
+
attributes[name2] = node.getAttribute(name2);
|
39982
|
+
});
|
39983
|
+
const type = node.tagName.replace("mj-", "");
|
39984
|
+
if (!BlockManager.getBlockByType(type)) {
|
39985
|
+
if (!node.parentElement || node.parentElement.tagName !== "mj-text")
|
39986
|
+
throw new Error("Invalid content");
|
39987
|
+
}
|
39988
|
+
const block2 = {
|
39989
|
+
type,
|
39990
|
+
attributes,
|
39991
|
+
data: {
|
39992
|
+
value: {
|
39993
|
+
content: (_a = node.textContent) == null ? void 0 : _a.trim()
|
39994
|
+
}
|
39995
|
+
},
|
39996
|
+
children: [...node.children].filter((item2) => item2 instanceof Element).map(transform)
|
39997
|
+
};
|
39998
|
+
switch (type) {
|
39999
|
+
case BasicType.TEXT:
|
40000
|
+
block2.data.value.content = node.innerHTML;
|
40001
|
+
block2.children = [];
|
40002
|
+
}
|
40003
|
+
return block2;
|
40004
|
+
};
|
40005
|
+
return transform(root2);
|
40006
|
+
}
|
40007
|
+
function MjmlToJson(data) {
|
40008
|
+
if (lodash.exports.isString(data))
|
40009
|
+
return parseXMLtoBlock(data);
|
40010
|
+
const transform = (item2) => {
|
40011
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
40012
|
+
const attributes = item2.attributes;
|
40013
|
+
switch (item2.tagName) {
|
40014
|
+
case "mjml":
|
40015
|
+
const body = (_a = item2.children) == null ? void 0 : _a.find((item22) => item22.tagName === "mj-body");
|
40016
|
+
const head = (_b = item2.children) == null ? void 0 : _b.find((item22) => item22.tagName === "mj-head");
|
40017
|
+
const metaData = getMetaDataFromMjml(head);
|
40018
|
+
const fonts = ((_c = head == null ? void 0 : head.children) == null ? void 0 : _c.filter((child) => child.tagName === "mj-font").map((child) => ({
|
40019
|
+
name: child.attributes.name,
|
40020
|
+
href: child.attributes.href
|
40021
|
+
}))) || [];
|
40022
|
+
const mjAttributes = ((_e = (_d = head == null ? void 0 : head.children) == null ? void 0 : _d.find((item22) => item22.tagName === "mj-attributes")) == null ? void 0 : _e.children) || [];
|
40023
|
+
const headStyles = (_f = head == null ? void 0 : head.children) == null ? void 0 : _f.filter((item22) => item22.tagName === "mj-style").map((item22) => ({ content: item22.content, inline: item22.inline }));
|
40024
|
+
const headAttributes = [
|
40025
|
+
...new Set(mjAttributes.filter((item22) => {
|
40026
|
+
const isFontFamily = item22.tagName === "mj-all" && item22.attributes["font-family"] === metaData["font-family"];
|
40027
|
+
const isTextColor = item22.tagName === "mj-text" && item22.attributes["color"] === metaData["text-color"];
|
40028
|
+
const isContentColor = ["mj-wrapper", "mj-section"].includes(item22.tagName) && item22.attributes["background-color"] === metaData["content-background-color"];
|
40029
|
+
return !isFontFamily && !isTextColor && !isContentColor;
|
40030
|
+
}).map((item22) => `<${item22.tagName} ${Object.keys(item22.attributes).map((key) => `${key}="${item22.attributes[key]}"`).join(" ")} />`))
|
40031
|
+
].join("\n");
|
40032
|
+
const breakpoint = (_g = head == null ? void 0 : head.children) == null ? void 0 : _g.find((item22) => item22.tagName === "mj-breakpoint");
|
40033
|
+
return BlockManager.getBlockByType(BasicType.PAGE).create({
|
40034
|
+
attributes: body.attributes,
|
40035
|
+
children: (_h = body.children) == null ? void 0 : _h.map(transform),
|
40036
|
+
data: {
|
40037
|
+
value: __spreadValues({
|
40038
|
+
headAttributes,
|
40039
|
+
headStyles,
|
40040
|
+
fonts,
|
40041
|
+
breakpoint: breakpoint == null ? void 0 : breakpoint.attributes.breakpoint
|
40042
|
+
}, metaData)
|
40043
|
+
}
|
40044
|
+
});
|
40045
|
+
default:
|
40046
|
+
const tag = item2.tagName.replace("mj-", "").toLowerCase();
|
40047
|
+
const block2 = BlockManager.getBlockByType(tag);
|
40048
|
+
if (!block2) {
|
40049
|
+
throw new Error(`${tag} block no found `);
|
40050
|
+
}
|
40051
|
+
const payload = {
|
40052
|
+
type: block2.type,
|
40053
|
+
attributes,
|
40054
|
+
data: {
|
40055
|
+
value: {}
|
40056
|
+
},
|
40057
|
+
children: []
|
40058
|
+
};
|
40059
|
+
if (item2.content) {
|
40060
|
+
payload.data.value.content = item2.content;
|
40061
|
+
}
|
40062
|
+
if (block2.type === BasicType.CAROUSEL) {
|
40063
|
+
payload.data.value.images = ((_i = item2.children) == null ? void 0 : _i.map((child) => {
|
40064
|
+
return child.attributes;
|
40065
|
+
})) || [];
|
40066
|
+
payload.children = [];
|
40067
|
+
} else if (block2.type === BasicType.NAVBAR) {
|
40068
|
+
payload.data.value.links = ((_j = item2.children) == null ? void 0 : _j.map((child) => {
|
40069
|
+
const navbarLinkData = __spreadProps(__spreadValues({
|
40070
|
+
color: "#1890ff",
|
40071
|
+
"font-size": "13px",
|
40072
|
+
target: "_blank",
|
40073
|
+
padding: "15px 10px"
|
40074
|
+
}, child.attributes), {
|
40075
|
+
content: child.content
|
40076
|
+
});
|
40077
|
+
formatPadding(navbarLinkData, "padding");
|
40078
|
+
return navbarLinkData;
|
40079
|
+
})) || [];
|
40080
|
+
payload.children = [];
|
40081
|
+
} else if (block2.type === BasicType.SOCIAL) {
|
40082
|
+
payload.data.value.elements = ((_k = item2.children) == null ? void 0 : _k.map((child) => {
|
40083
|
+
return __spreadProps(__spreadValues({}, child.attributes), {
|
40084
|
+
content: child.content
|
40085
|
+
});
|
40086
|
+
})) || [];
|
40087
|
+
payload.children = [];
|
40088
|
+
} else if (item2.children) {
|
40089
|
+
payload.children = item2.children.map(transform);
|
40090
|
+
}
|
40091
|
+
const blockData = block2.create(payload);
|
40092
|
+
formatPadding(blockData.attributes, "padding");
|
40093
|
+
formatPadding(blockData.attributes, "inner-padding");
|
40094
|
+
return blockData;
|
40095
|
+
}
|
40096
|
+
};
|
40097
|
+
return transform(data);
|
40098
|
+
}
|
40099
|
+
function getMetaDataFromMjml(data) {
|
40100
|
+
var _a;
|
40101
|
+
const mjmlHtmlAttributes = (_a = data == null ? void 0 : data.children) == null ? void 0 : _a.filter((item2) => item2.tagName === "mj-html-attributes").map((item2) => item2.children).flat().filter((item2) => item2 && item2.attributes.class === "easy-email").reduce((obj, item2) => {
|
40102
|
+
if (!item2)
|
40103
|
+
return obj;
|
40104
|
+
const name2 = item2.attributes["attribute-name"];
|
40105
|
+
const isMultipleAttributes = Boolean(item2.attributes["multiple-attributes"]);
|
40106
|
+
obj[name2] = isMultipleAttributes ? lodash.exports.pickBy(__spreadProps(__spreadValues({}, item2.attributes), {
|
40107
|
+
"attribute-name": void 0,
|
40108
|
+
"multiple-attributes": void 0,
|
40109
|
+
class: void 0
|
40110
|
+
}), lodash.exports.identity) : item2.attributes[name2];
|
40111
|
+
return obj;
|
40112
|
+
}, {});
|
40113
|
+
return lodash.exports.pickBy(mjmlHtmlAttributes, lodash.exports.identity);
|
40114
|
+
}
|
40115
|
+
function formatPadding(attributes, attributeName) {
|
40116
|
+
const ele = document.createElement("div");
|
40117
|
+
Object.keys(attributes).forEach((key) => {
|
40118
|
+
var _a;
|
40119
|
+
if (new RegExp(`^${attributeName}`).test(key)) {
|
40120
|
+
const formatKey = (_a = new RegExp(`^${attributeName}(.*)`).exec(key)) == null ? void 0 : _a[0];
|
40121
|
+
if (formatKey) {
|
40122
|
+
ele.style[formatKey] = attributes[key];
|
40123
|
+
delete attributes[key];
|
40124
|
+
}
|
40125
|
+
}
|
40126
|
+
});
|
40127
|
+
const newPadding = [
|
40128
|
+
ele.style.paddingTop,
|
40129
|
+
ele.style.paddingRight,
|
40130
|
+
ele.style.paddingBottom,
|
40131
|
+
ele.style.paddingLeft
|
40132
|
+
].filter(Boolean).join(" ");
|
40133
|
+
if (newPadding) {
|
40134
|
+
attributes[attributeName] = newPadding;
|
40135
|
+
}
|
40136
|
+
}
|
39945
40137
|
function SourceCodePanel() {
|
39946
40138
|
const { setValueByIdx, focusBlock, values } = useBlock();
|
39947
40139
|
const { focusIdx } = useFocusIdx();
|
@@ -46141,5 +46333,5 @@ const StandardLayout = (props) => {
|
|
46141
46333
|
style: { width: 0, overflow: "hidden" }
|
46142
46334
|
}))), /* @__PURE__ */ React__default.createElement(InteractivePrompt, null), /* @__PURE__ */ React__default.createElement(MergeTagBadgePrompt, null)));
|
46143
46335
|
};
|
46144
|
-
export {
|
46336
|
+
export { TextField as $, AttributePanel as A, BlockLayer as B, Color as C, Decoration as D, Padding as E, FontFamily as F, ClassName as G, Height as H, BlockMarketManager as I, BlockMaskWrapper as J, SourceCodePanel as K, LetterSpacing as L, MjmlToJson as M, NavbarLinkPadding as N, InteractivePrompt as O, Page as P, SimpleLayout as Q, StandardLayout as R, ShortcutToolbar as S, TextAlign as T, MergeTagBadgePrompt as U, VerticalAlign as V, Width as W, ExtensionContext as X, ExtensionProvider as Y, useExtensionProps as Z, RICH_TEXT_TOOL_BAR as _, getIconNameByBlockType as a, InputWithUnitField as a0, SearchField as a1, TextAreaField as a2, NumberField as a3, SliderField as a4, UploadField as a5, ImageUploaderField as a6, SelectField as a7, TreeSelectField as a8, AutoCompleteField as a9, RadioGroupField as aa, SwitchField as ab, CheckboxField as ac, EditTabField as ad, EditGridTabField as ae, InlineTextField as af, ColorPickerField as ag, enhancer as ah, RichTextField as ai, getBlockTitle as b, commonjsGlobal as c, BlockAttributeConfigurationManager as d, Align as e, AttributesPanelWrapper as f, getContextMergeTags as g, CollapseWrapper as h, Condition as i, ContainerBackgroundColor as j, TextDecoration as k, Background as l, LineHeight as m, TextTransform as n, BackgroundColor as o, Direction as p, Link as q, Border as r, Margin as s, BorderColor as t, FontSize$1 as u, MergeTags$1 as v, BorderStyle as w, FontStyle as x, BorderWidth as y, FontWeight as z };
|
46145
46337
|
//# sourceMappingURL=index2.js.map
|