'use strict'; let React = require('react'), ReactDOM = require('react-dom'), QuillMixin = require('./mixin'), InsertImageWithUrl = require('./insert-image-with-url'), T = React.PropTypes; let find = function(arr, predicate) { if (!arr) { return; } for (let i=0; i { evt.stopPropagation(); } }); } }, componentDidMount: function() { let editor = this.createEditor( this.getEditorElement(), this.getEditorConfig()); // Style the font options to match their font family let fontOptions = document.querySelectorAll('.ql-toolbar .ql-font.ql-picker .ql-picker-item'); for (let i=0; i { if (this.props.value) { this.setEditorContents(editor, this.props.value); } if (this.props.config.stopEventPropInDynamics === true) { this.editorSentinel(); } }); }, componentWillUnmount: function() { // NOTE: Don't set the state to null here // as it would generate a loop. }, shouldComponentUpdate: function(nextProps, nextState) { // Check if one of the changes should trigger a re-render. for (let i=0; i); } let editor = find(children, function(child) { return child.ref === 'editor'; }); contents.push(editor ? editor : React.DOM.div({ key: 'editor-' + Math.random(), ref: 'editor', className: 'sh-quill-contents', dangerouslySetInnerHTML: { __html:this.getEditorContents() } })); return contents; }, render: function() { return React.DOM.div({ id: this.props.id, style: this.props.style, className: ['sh-quill'].concat(this.props.className).join(' '), onKeyPress: this.props.onKeyPress, onKeyDown: this.props.onKeyDown, onKeyUp: this.props.onKeyUp, onChange: this.preventDefault }, this.renderContents() ); }, onEditorChange: function(value, delta, source, editor) { if (value !== this.getEditorContents()) { this.setState({ value: value }); if (this.props.onChange) { this.props.onChange(value, delta, source, editor); } } }, onEditorChangeSelection: function(range, source, editor) { let s = this.getEditorSelection() || {}; let r = range || {}; if (r.length !== s.length || r.index !== s.index) { this.setState({ selection: range }); if (this.props.onChangeSelection) { this.props.onChangeSelection(range, source, editor); } } }, focus: function() { this.state.editor.focus(); }, blur: function() { this.setEditorSelection(this.state.editor, null); }, /* Stop change events from the toolbar from bubbling up outside. */ preventDefault: function(event) { event.preventDefault(); event.stopPropagation(); } }); module.exports = QuillComponent;