easy-email-extensions 4.7.2 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ export { Height } from './Height';
4
4
  export { TextAlign } from './TextAlign';
5
5
  export { AttributesPanelWrapper } from './AttributesPanelWrapper';
6
6
  export { CollapseWrapper } from './CollapseWrapper';
7
+ export { Condition } from './Condition';
7
8
  export { ContainerBackgroundColor } from './ContainerBackgroundColor';
8
9
  export { LetterSpacing } from './LetterSpacing';
9
10
  export { TextDecoration } from './TextDecoration';
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, a7 as AutoCompleteField, k as Background, n as BackgroundColor, d as BlockAttributeConfigurationManager, B as BlockLayer, E as BlockMarketManager, G as BlockMaskWrapper, q as Border, r as BorderColor, u as BorderStyle, w as BorderWidth, aa as CheckboxField, z as ClassName, h as CollapseWrapper, C as Color, ae as ColorPickerField, i as ContainerBackgroundColor, D as Decoration, P as DefaultPageConfigPanel, o as Direction, ac as EditGridTabField, ab as EditTabField, R as ExtensionContext, U as ExtensionProvider, F as FontFamily, s as FontSize, v as FontStyle, x as FontWeight, H as Height, a4 as ImageUploaderField, ad as InlineTextField, _ as InputWithUnitField, J as InteractivePrompt, L as LetterSpacing, l as LineHeight, p as Link, M as Margin, Q as MergeTagBadgePrompt, t as MergeTags, N as NavbarLinkPadding, a1 as NumberField, y as Padding, Y as RICH_TEXT_TOOL_BAR, a8 as RadioGroupField, ag as RichTextField, $ as SearchField, a5 as SelectField, S as ShortcutToolbar, K as SimpleLayout, a2 as SliderField, I as SourceCodePanel, O as StandardLayout, a9 as SwitchField, T as TextAlign, a0 as TextAreaField, j as TextDecoration, Z as TextField, m as TextTransform, a6 as TreeSelectField, a3 as UploadField, V as VerticalAlign, W as Width, af as enhancer, b as getBlockTitle, g as getContextMergeTags, a as getIconNameByBlockType, X as useExtensionProps } from "./index2.js";
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, MjmlToJson, JsonToMjml, getNodeTypeFromClassName } from "easy-email-core";
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 = {
@@ -39942,6 +39943,183 @@ function ShortcutToolbar() {
39942
39943
  }
39943
39944
  }));
39944
39945
  }
39946
+ const domParser = new DOMParser();
39947
+ function parseXMLtoBlock(text) {
39948
+ const dom = domParser.parseFromString(text, "text/xml");
39949
+ const root2 = dom.firstChild;
39950
+ if (!(dom.firstChild instanceof Element)) {
39951
+ throw new Error("Invalid content");
39952
+ }
39953
+ if (root2.tagName === "mjml") {
39954
+ const { json } = mjml(text, {
39955
+ validationLevel: "soft"
39956
+ });
39957
+ const parseValue2 = MjmlToJson(json);
39958
+ return parseValue2;
39959
+ }
39960
+ const transform = (node) => {
39961
+ var _a;
39962
+ if (node.tagName === "parsererror") {
39963
+ throw new Error("Invalid content");
39964
+ }
39965
+ const attributes = {};
39966
+ node.getAttributeNames().forEach((name2) => {
39967
+ attributes[name2] = node.getAttribute(name2);
39968
+ });
39969
+ const type = node.tagName.replace("mj-", "");
39970
+ if (!BlockManager.getBlockByType(type)) {
39971
+ if (!node.parentElement || node.parentElement.tagName !== "mj-text")
39972
+ throw new Error("Invalid content");
39973
+ }
39974
+ const block2 = {
39975
+ type,
39976
+ attributes,
39977
+ data: {
39978
+ value: {
39979
+ content: (_a = node.textContent) == null ? void 0 : _a.trim()
39980
+ }
39981
+ },
39982
+ children: [...node.children].filter((item2) => item2 instanceof Element).map(transform)
39983
+ };
39984
+ switch (type) {
39985
+ case BasicType.TEXT:
39986
+ block2.data.value.content = node.innerHTML;
39987
+ block2.children = [];
39988
+ }
39989
+ return block2;
39990
+ };
39991
+ return transform(root2);
39992
+ }
39993
+ function MjmlToJson(data) {
39994
+ if (lodash.exports.isString(data))
39995
+ return parseXMLtoBlock(data);
39996
+ const transform = (item2) => {
39997
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
39998
+ const attributes = item2.attributes;
39999
+ switch (item2.tagName) {
40000
+ case "mjml":
40001
+ const body = (_a = item2.children) == null ? void 0 : _a.find((item22) => item22.tagName === "mj-body");
40002
+ const head = (_b = item2.children) == null ? void 0 : _b.find((item22) => item22.tagName === "mj-head");
40003
+ const metaData = getMetaDataFromMjml(head);
40004
+ const fonts = ((_c = head == null ? void 0 : head.children) == null ? void 0 : _c.filter((child) => child.tagName === "mj-font").map((child) => ({
40005
+ name: child.attributes.name,
40006
+ href: child.attributes.href
40007
+ }))) || [];
40008
+ 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) || [];
40009
+ 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 }));
40010
+ const headAttributes = [
40011
+ ...new Set(mjAttributes.filter((item22) => {
40012
+ const isFontFamily = item22.tagName === "mj-all" && item22.attributes["font-family"] === metaData["font-family"];
40013
+ const isTextColor = item22.tagName === "mj-text" && item22.attributes["color"] === metaData["text-color"];
40014
+ const isContentColor = ["mj-wrapper", "mj-section"].includes(item22.tagName) && item22.attributes["background-color"] === metaData["content-background-color"];
40015
+ return !isFontFamily && !isTextColor && !isContentColor;
40016
+ }).map((item22) => `<${item22.tagName} ${Object.keys(item22.attributes).map((key) => `${key}="${item22.attributes[key]}"`).join(" ")} />`))
40017
+ ].join("\n");
40018
+ const breakpoint = (_g = head == null ? void 0 : head.children) == null ? void 0 : _g.find((item22) => item22.tagName === "mj-breakpoint");
40019
+ return BlockManager.getBlockByType(BasicType.PAGE).create({
40020
+ attributes: body.attributes,
40021
+ children: (_h = body.children) == null ? void 0 : _h.map(transform),
40022
+ data: {
40023
+ value: __spreadValues({
40024
+ headAttributes,
40025
+ headStyles,
40026
+ fonts,
40027
+ breakpoint: breakpoint == null ? void 0 : breakpoint.attributes.breakpoint
40028
+ }, metaData)
40029
+ }
40030
+ });
40031
+ default:
40032
+ const tag = item2.tagName.replace("mj-", "").toLowerCase();
40033
+ const block2 = BlockManager.getBlockByType(tag);
40034
+ if (!block2) {
40035
+ throw new Error(`${tag} block no found `);
40036
+ }
40037
+ const payload = {
40038
+ type: block2.type,
40039
+ attributes,
40040
+ data: {
40041
+ value: {}
40042
+ },
40043
+ children: []
40044
+ };
40045
+ if (item2.content) {
40046
+ payload.data.value.content = item2.content;
40047
+ }
40048
+ if (block2.type === BasicType.CAROUSEL) {
40049
+ payload.data.value.images = ((_i = item2.children) == null ? void 0 : _i.map((child) => {
40050
+ return child.attributes;
40051
+ })) || [];
40052
+ payload.children = [];
40053
+ } else if (block2.type === BasicType.NAVBAR) {
40054
+ payload.data.value.links = ((_j = item2.children) == null ? void 0 : _j.map((child) => {
40055
+ const navbarLinkData = __spreadProps(__spreadValues({
40056
+ color: "#1890ff",
40057
+ "font-size": "13px",
40058
+ target: "_blank",
40059
+ padding: "15px 10px"
40060
+ }, child.attributes), {
40061
+ content: child.content
40062
+ });
40063
+ formatPadding(navbarLinkData, "padding");
40064
+ return navbarLinkData;
40065
+ })) || [];
40066
+ payload.children = [];
40067
+ } else if (block2.type === BasicType.SOCIAL) {
40068
+ payload.data.value.elements = ((_k = item2.children) == null ? void 0 : _k.map((child) => {
40069
+ return __spreadProps(__spreadValues({}, child.attributes), {
40070
+ content: child.content
40071
+ });
40072
+ })) || [];
40073
+ payload.children = [];
40074
+ } else if (item2.children) {
40075
+ payload.children = item2.children.map(transform);
40076
+ }
40077
+ const blockData = block2.create(payload);
40078
+ formatPadding(blockData.attributes, "padding");
40079
+ formatPadding(blockData.attributes, "inner-padding");
40080
+ return blockData;
40081
+ }
40082
+ };
40083
+ return transform(data);
40084
+ }
40085
+ function getMetaDataFromMjml(data) {
40086
+ var _a;
40087
+ 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) => {
40088
+ if (!item2)
40089
+ return obj;
40090
+ const name2 = item2.attributes["attribute-name"];
40091
+ const isMultipleAttributes = Boolean(item2.attributes["multiple-attributes"]);
40092
+ obj[name2] = isMultipleAttributes ? lodash.exports.pickBy(__spreadProps(__spreadValues({}, item2.attributes), {
40093
+ "attribute-name": void 0,
40094
+ "multiple-attributes": void 0,
40095
+ class: void 0
40096
+ }), lodash.exports.identity) : item2.attributes[name2];
40097
+ return obj;
40098
+ }, {});
40099
+ return lodash.exports.pickBy(mjmlHtmlAttributes, lodash.exports.identity);
40100
+ }
40101
+ function formatPadding(attributes, attributeName) {
40102
+ const ele = document.createElement("div");
40103
+ Object.keys(attributes).forEach((key) => {
40104
+ var _a;
40105
+ if (new RegExp(`^${attributeName}`).test(key)) {
40106
+ const formatKey = (_a = new RegExp(`^${attributeName}(.*)`).exec(key)) == null ? void 0 : _a[0];
40107
+ if (formatKey) {
40108
+ ele.style[formatKey] = attributes[key];
40109
+ delete attributes[key];
40110
+ }
40111
+ }
40112
+ });
40113
+ const newPadding = [
40114
+ ele.style.paddingTop,
40115
+ ele.style.paddingRight,
40116
+ ele.style.paddingBottom,
40117
+ ele.style.paddingLeft
40118
+ ].filter(Boolean).join(" ");
40119
+ if (newPadding) {
40120
+ attributes[attributeName] = newPadding;
40121
+ }
40122
+ }
39945
40123
  function SourceCodePanel() {
39946
40124
  const { setValueByIdx, focusBlock, values } = useBlock();
39947
40125
  const { focusIdx } = useFocusIdx();
@@ -46141,5 +46319,5 @@ const StandardLayout = (props) => {
46141
46319
  style: { width: 0, overflow: "hidden" }
46142
46320
  }))), /* @__PURE__ */ React__default.createElement(InteractivePrompt, null), /* @__PURE__ */ React__default.createElement(MergeTagBadgePrompt, null)));
46143
46321
  };
46144
- export { SearchField as $, AttributePanel as A, BlockLayer as B, Color as C, Decoration as D, BlockMarketManager as E, FontFamily as F, BlockMaskWrapper as G, Height as H, SourceCodePanel as I, InteractivePrompt as J, SimpleLayout as K, LetterSpacing as L, Margin as M, NavbarLinkPadding as N, StandardLayout as O, Page as P, MergeTagBadgePrompt as Q, ExtensionContext as R, ShortcutToolbar as S, TextAlign as T, ExtensionProvider as U, VerticalAlign as V, Width as W, useExtensionProps as X, RICH_TEXT_TOOL_BAR as Y, TextField as Z, InputWithUnitField as _, getIconNameByBlockType as a, TextAreaField as a0, NumberField as a1, SliderField as a2, UploadField as a3, ImageUploaderField as a4, SelectField as a5, TreeSelectField as a6, AutoCompleteField as a7, RadioGroupField as a8, SwitchField as a9, CheckboxField as aa, EditTabField as ab, EditGridTabField as ac, InlineTextField as ad, ColorPickerField as ae, enhancer as af, RichTextField as ag, getBlockTitle as b, commonjsGlobal as c, BlockAttributeConfigurationManager as d, Align as e, AttributesPanelWrapper as f, getContextMergeTags as g, CollapseWrapper as h, ContainerBackgroundColor as i, TextDecoration as j, Background as k, LineHeight as l, TextTransform as m, BackgroundColor as n, Direction as o, Link as p, Border as q, BorderColor as r, FontSize$1 as s, MergeTags$1 as t, BorderStyle as u, FontStyle as v, BorderWidth as w, FontWeight as x, Padding as y, ClassName as z };
46322
+ 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
46323
  //# sourceMappingURL=index2.js.map