react-email-builder
Version:
A simple React drag and drop email builder.
72 lines (71 loc) • 2.72 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.textBlock = void 0;
const react_1 = __importDefault(require("react"));
const Icon_1 = require("../../components/Icon");
const TextBlock_1 = require("./TextBlock");
const mjml_1 = require("../../utils/mjml");
function textBlock() {
return {
type: 'text',
name: 'Text',
icon: react_1.default.createElement(Icon_1.Icon, { name: 'text' }),
createBlock: (base) => {
const block = base;
return block;
},
blockComponent: TextBlock_1.TextBlock,
exportJSON: (attrs) => {
let editorState;
if (attrs.editorState) {
if (typeof attrs.editorState === 'string') {
try {
editorState = JSON.parse(attrs.editorState);
}
catch (err) {
// ignore
}
}
else {
editorState = attrs.editorState.toJSON();
}
}
return {
html: attrs.html,
editorState
};
},
importJSON: (json) => {
return {
html: json.html,
editorState: JSON.stringify(json.editorState)
};
},
renderMJMLHeadTags: () => {
return (0, mjml_1.renderTag)('mj-style', {
children: [
'.REB-Lexical-editor p { margin: 0px; }',
'.REB-Lexical-editor a { color: #0000EE; text-decoration: none; }',
'.REB-Lexical-editor a:hover { text-decoration: underline; }',
'.REB-Lexical-text-underline { text-decoration: underline; }',
'.REB-Lexical-text-strikethrough { text-decoration: line-through; }',
'.REB-Lexical-text-underline-strikethrough { text-decoration: underline line-through; }',
'.REB-Lexical-text-italic { text-decoration: italic; }'
]
});
},
renderMJML: (block, options) => {
return (0, mjml_1.renderTag)('mj-text', {
attrs: (0, mjml_1.createBlockAttrs)(block, {
'css-class': 'REB-Lexical-editor',
'line-height': '1.45'
}),
children: (0, mjml_1.replaceHtmlVariables)(block.attrs.html, options.replaceVariable)
});
}
};
}
exports.textBlock = textBlock;
;