UNPKG

infinity-forge

Version:
52 lines 2.11 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EditorQuill = EditorQuill; var jsx_runtime_1 = require("react/jsx-runtime"); var react_1 = require("react"); var quill_1 = __importDefault(require("quill")); var error_boundary_1 = require("../../error-boundary/index.js"); function EditorQuill(props) { var ID = 'id-' + Math.random().toString(36).substring(2, 9); var quillRef = (0, react_1.useRef)(null); (0, react_1.useEffect)(function () { if (!quillRef.current) { var modules = { toolbar: props.disableToolbar ? false : [ [{ header: [1, 2, false] }], ['bold', 'italic', 'underline', 'strike'], [{ list: 'ordered' }, { list: 'bullet' }], [{ align: [] }], ['link', 'image'], ['clean'], ], }; var reference_1 = new quill_1.default('#' + ID, { theme: 'snow', modules: modules, }); quillRef.current = reference_1; if (props.value) { reference_1.root.innerHTML = props.value; } reference_1.on(quill_1.default.events.TEXT_CHANGE, function () { var html = reference_1.root.innerHTML; props.handleOnChange(html); }); } }, []); (0, react_1.useEffect)(function () { if (quillRef.current && props.value !== undefined) { var editor = quillRef.current; if (editor.root.innerHTML !== props.value) { editor.root.innerHTML = props.value; } } }, [props.value]); return ((0, jsx_runtime_1.jsx)(error_boundary_1.Error, { name: 'react-quill', children: (0, jsx_runtime_1.jsx)("div", { id: ID }) })); } //# sourceMappingURL=quill.js.map