react-email-builder
Version:
A simple React drag and drop email builder.
76 lines (75 loc) • 4.68 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextEditor = void 0;
const clsx_1 = __importDefault(require("clsx"));
const react_1 = __importStar(require("react"));
const utils_1 = require("../../utils");
const hooks_1 = require("../../lexical/hooks");
const SvgSymbols_1 = require("../SvgSymbols");
const ToolbarPlugin_1 = require("../../lexical/plugins/ToolbarPlugin");
const DragDropPasteImagePlugin_1 = require("../../lexical/plugins/DragDropPasteImagePlugin");
const LexicalComposer_1 = require("@lexical/react/LexicalComposer");
const LexicalRichTextPlugin_1 = require("@lexical/react/LexicalRichTextPlugin");
const LexicalContentEditable_1 = require("@lexical/react/LexicalContentEditable");
const LexicalErrorBoundary_1 = require("@lexical/react/LexicalErrorBoundary");
const LexicalLinkPlugin_1 = require("@lexical/react/LexicalLinkPlugin");
const LexicalHistoryPlugin_1 = require("@lexical/react/LexicalHistoryPlugin");
const OnChangePlugin_1 = require("../../lexical/plugins/OnChangePlugin");
const LexicalTextEditor = (0, react_1.memo)(function LexicalTextEditor({ style, config, onChange, editorClassName, placeholder, placeholderClassName, upload, ...props }) {
const css = (0, utils_1.getCss)('TextEditor', (ns) => ({
root: (0, clsx_1.default)((0, utils_1.varsClass)(), ns()),
toolbar: ns('toolbar'),
body: ns('body')
}));
const { editorStyle, placeholderStyle } = (0, react_1.useMemo)(() => ({
editorStyle: {
...style,
padding: style?.padding ? style.padding : 16
},
placeholderStyle: {
padding: style?.padding ? style.padding : 16
}
}), [style]);
return (react_1.default.createElement("div", { className: css.root },
react_1.default.createElement(LexicalComposer_1.LexicalComposer, { initialConfig: config },
react_1.default.createElement("div", { className: css.toolbar },
react_1.default.createElement(ToolbarPlugin_1.ToolbarPlugin, { upload: upload, ...props })),
react_1.default.createElement("div", { className: css.body },
react_1.default.createElement(LexicalRichTextPlugin_1.RichTextPlugin, { contentEditable: react_1.default.createElement(LexicalContentEditable_1.ContentEditable, { className: editorClassName, style: editorStyle }), placeholder: react_1.default.createElement("div", { className: placeholderClassName, style: placeholderStyle }, placeholder ?? 'Enter some text...'), ErrorBoundary: LexicalErrorBoundary_1.LexicalErrorBoundary })),
react_1.default.createElement(LexicalLinkPlugin_1.LinkPlugin, { attributes: { target: '_blank', rel: '' } }),
react_1.default.createElement(LexicalHistoryPlugin_1.HistoryPlugin, null),
react_1.default.createElement(OnChangePlugin_1.OnChangePlugin, { onChange: onChange }),
upload ? react_1.default.createElement(DragDropPasteImagePlugin_1.DragDropPasteImagePlugin, { upload: upload }) : null),
react_1.default.createElement(SvgSymbols_1.SvgSymbols, null)));
});
function TextEditor({ placeholder, style, state, setState, ...props }) {
const [{ css, config }] = (0, hooks_1.useLexicalConfig)(state.editorState);
return (react_1.default.createElement(LexicalTextEditor, { config: config, style: style, placeholder: placeholder, onChange: setState, editorClassName: css.editor, placeholderClassName: css.placeholder, ...props }));
}
exports.TextEditor = TextEditor;