UNPKG

rich-text-editor

Version:
25 lines (24 loc) 1.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); const text_area_1 = __importDefault(require("./components/text-area")); const state_1 = require("./state"); const RichTextEditor = (0, react_1.forwardRef)((props, ref) => { const { allowedFileTypes, baseUrl, getPasteSource, initialValue, language, onValueChange, textAreaProps, toolbarRoot, invalidImageSelector, onLatexUpdate, } = props; const [toolbarRootElement, setToolbarRootElement] = (0, react_1.useState)(toolbarRoot); const toolbarRootRef = (0, react_1.useRef)(null); (0, react_1.useEffect)(() => { if (toolbarRoot) { setToolbarRootElement(toolbarRoot); } else if (toolbarRootRef.current) { setToolbarRootElement(toolbarRootRef.current); } }, [toolbarRoot, toolbarRootRef]); return ((0, jsx_runtime_1.jsxs)(state_1.EditorStateProvider, { allowedFileTypes: allowedFileTypes, baseUrl: baseUrl, getPasteSource: getPasteSource, initialValue: initialValue, language: language, onValueChange: onValueChange, invalidImageSelector: invalidImageSelector, onLatexUpdate: onLatexUpdate, children: [toolbarRoot ? null : (0, jsx_runtime_1.jsx)("div", { ref: toolbarRootRef, className: "rich-text-editor-toolbar-root" }), (0, jsx_runtime_1.jsx)(text_area_1.default, Object.assign({}, textAreaProps, { toolbarRoot: toolbarRootElement, ref: ref }))] })); }); exports.default = RichTextEditor;