first commit

This commit is contained in:
2026-06-24 09:48:54 +02:00
commit 41e62ddcad
33739 changed files with 4266226 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
Changelog
=========
v0.0.2
------
- Compatible with React 0.12.
v0.0.1
------
- Initial version.
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014, zenoamaro <zenoamaro@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+76
View File
@@ -0,0 +1,76 @@
React-Quill ![](https://travis-ci.org/zenoamaro/react-quill.svg?branch=master)
==============================================================================
A [Quill] component for [React].
[Quill]: http://quilljs.com
[React]: http://facebook.github.io/react/
**Warning**: The project is still in alpha stage. Use with caution.
1. [Quick start](#quick-start)
2. [Usage guide](#usage-guide)
3. [API reference](#api-reference)
4. [Building and testing](#building-and-testing)
5. [Changelog](#changelog)
6. [License](#license)
Quick start
-----------
~~~~html
<ReactQuill value="..."/>
~~~~
Usage guide
-----------
To be done.
API reference
-------------
To be done.
Building and testing
--------------------
You can run the automated test suite:
$ npm test
And build a minificated version of the source:
$ npm run build
More tasks are available on the [Makefile](Makefile):
lint: lints the source
spec: runs the test specs
coverage: runs the code coverage test
test: lint, spec and coverage threshold test
build: builds the minified version
Changelog
---------
#### v0.0.2
- Compatible with React 0.12.
#### v0.0.1
- Initial version.
[Full changelog](CHANGELOG.md)
License
-------
The MIT License (MIT)
Copyright (c) 2014, zenoamaro <zenoamaro@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+460
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("quilljs")):"function"==typeof define&&define.amd?define(["react","quilljs"],t):"object"==typeof exports?exports.ReactQuill=t(require("react"),require("quilljs")):e.ReactQuill=t(e.React,e.Quill)}(this,function(e,t){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(4),e.exports.Mixin=r(2),e.exports.Toolbar=r(3)},function(t){t.exports=e},function(e,t,r){"use strict";var o=r(1),n=r(5),i=(o.PropTypes,{createEditor:function(e,t){var r=new n(e,t);return this.hookEditor(r),r},hookEditor:function(e){var t=this;e.on("text-change",function(r,o){t.onEditorChange&&t.onEditorChange(e.getHTML(),r,o)})},updateEditor:function(){throw new Error("Not implemented")},destroyEditor:function(e){e.removeAllListeners()},setEditorContents:function(e,t){var r=e.getSelection();e.setHTML(t),e.setSelection(r)}});e.exports=i},function(e,t,r){"use strict";var o=r(1),n=o.PropTypes,i=[{label:"Formats",type:"group",items:[{label:"Size",type:"size",items:[{label:"Normal",value:""},{label:"Smaller",value:"0.8em"},{label:"Larger",value:"1.4em"},{label:"Huge",value:"2em"}]},{label:"Alignment",type:"align",items:[{label:"Center",value:"center"},{label:"Left",value:"left"},{label:"Right",value:"right"},{label:"Justify",value:"justify"}]}]},{label:"Text",type:"group",items:[{type:"bold",label:"Bold"},{type:"italic",label:"Italic"},{type:"strike",label:"Strike"},{type:"underline",label:"Underline"},{type:"link",label:"Link"}]},{label:"Blocks",type:"group",items:[{type:"bullet",label:"Bullet"},{type:"list",label:"List"}]}],l=o.createClass({displayName:"Quill Toolbar",propTypes:{id:n.string,className:n.string,items:n.array},getDefaultProps:function(){return{items:i}},renderGroup:function(e){return o.DOM.span({key:e.label,className:"ql-format-group"},e.items.map(this.renderItem))},renderChoiceItem:function(e){return o.DOM.option({key:e.label||e.value,value:e.value},e.label)},renderChoices:function(e){return o.DOM.select({key:e.label,className:"ql-"+e.type},e.items.map(this.renderChoiceItem))},renderAction:function(e){return o.DOM.span({key:e.label||e.value,className:"ql-format-button ql-"+e.type,title:e.label})},renderItem:function(e){var t={group:this.renderGroup,align:this.renderChoices,size:this.renderChoices,action:this.renderAction},r=t[e.type]||t.action;return r(e)},getClassName:function(){return"quill-toolbar "+(this.props.className||"")},render:function(){return o.DOM.div({className:this.getClassName()},this.props.items.map(this.renderItem))}});e.exports=l},function(e,t,r){"use strict";var o=r(1),n=r(3),i=r(2),l=o.PropTypes;o.createFactory&&(n=o.createFactory(n));var s=o.createClass({displayName:"Quill",mixins:[i],propTypes:{id:l.string,className:l.string,value:l.string,defaultValue:l.string,readOnly:l.bool,toolbar:l.object,formats:l.array,styles:l.object,theme:l.string,pollInterval:l.number,onChange:l.func},getDefaultProps:function(){return{className:"",modules:{}}},getInitialState:function(){return{}},componentWillReceiveProps:function(e){"value"in e&&e.value!==this.props.value&&this.setEditorContents(this.state.editor,e.value)},componentDidMount:function(){var e=this.createEditor(this.getEditorElement(),this.getEditorConfig());this.setState({editor:e})},componentWillUnmount:function(){this.destroyEditor(this.state.editor)},shouldComponentUpdate:function(){return!1},componentWillUpdate:function(){this.componentWillUnmount()},componentDidUpdate:function(){this.componentDidMount()},getEditorConfig:function(){var e={readOnly:this.props.readOnly,theme:this.props.theme,formats:this.props.formats,styles:this.props.styles,modules:this.props.modules,pollInterval:this.props.pollInterval};return e.modules.toolbar||(e.modules=JSON.parse(JSON.stringify(e.modules)),e.modules.toolbar={container:this.refs.toolbar.getDOMNode()}),e},getEditorElement:function(){return this.refs.editor.getDOMNode()},getEditorContents:function(){return this.props.value||this.props.defaultValue},getClassName:function(){return["quill",this.props.className].join(" ")},renderContents:function(){return o.Children.count(this.props.children)>0?o.Children.only(this.props.children):[n({key:"toolbar",ref:"toolbar",items:this.props.toolbar}),o.DOM.div({key:"editor",ref:"editor",className:"quill-contents",dangerouslySetInnerHTML:{__html:this.getEditorContents()}})]},render:function(){return o.DOM.div({className:this.getClassName(),onChange:this.preventDefault},this.renderContents())},onEditorChange:function(e){e!==this.state.value&&this.props.onChange&&this.props.onChange(e)},preventDefault:function(e){e.preventDefault(),e.stopPropagation()}});e.exports=s},function(e){e.exports=t}])});
+66
View File
@@ -0,0 +1,66 @@
{
"name": "react-quill",
"version": "0.0.2",
"description": "The Quill rich-text editor as a React component.",
"author": "zenoamaro <zenoamaro@gmail.com>",
"homepage": "https://github.com/zenoamaro/react-quill",
"license": "MIT",
"bugs": {
"url": "https://github.com/zenoamaro/react-quill/issues",
"email": "zenoamaro@gmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/zenoamaro/react-quill.git"
},
"main": "dist/react-quill.js",
"scripts": {
"test": "make test",
"build": "make build"
},
"engines": {
"node": ">= 0.8.x"
},
"keywords": [
"rich",
"text",
"richtext",
"textarea"
],
"files": [
"src/",
"dist/",
"README.md",
"CHANGELOG.md",
"LICENSE"
],
"dependencies": {
"quilljs": "^0.18.1"
},
"peerDependencies": {
"react": ">=0.11.0"
},
"devDependencies": {
"blanket": "^1.1.6",
"jsdom": "^1.2.1",
"jshint": "^2.5.10",
"mocha": "^2.0.1",
"mocha-text-cov": "^0.1.0",
"react": "^0.12.0",
"should": "^4.3.0",
"sinon": "^1.12.1",
"travis-cov": "^0.2.5",
"uglify-js": "^2.4.15",
"webpack": "^1.4.13"
}
}
+179
View File
@@ -0,0 +1,179 @@
'use strict';
var React = require('react'),
QuillToolbar = require('./toolbar'),
QuillMixin = require('./mixin'),
T = React.PropTypes;
// Support React 0.11 and 0.12
// FIXME: Remove with React 0.13
if (React.createFactory) {
QuillToolbar = React.createFactory(QuillToolbar);
}
var QuillComponent = React.createClass({
displayName: 'Quill',
mixins: [ QuillMixin ],
propTypes: {
id: T.string,
className: T.string,
value: T.string,
defaultValue: T.string,
readOnly: T.bool,
toolbar: T.object,
formats: T.array,
styles: T.object,
theme: T.string,
pollInterval: T.number,
onChange: T.func
},
getDefaultProps: function() {
return {
className: '',
modules: {}
};
},
/*
Retrieve the initial value from either `value` (preferred)
or `defaultValue` if you want an un-controlled component.
*/
getInitialState: function() {
return {};
},
/*
Update only if we've been passed a new `value`.
This leaves components using `defaultValue` alone.
*/
componentWillReceiveProps: function(nextProps) {
if ('value' in nextProps) {
if (nextProps.value !== this.props.value) {
this.setEditorContents(this.state.editor, nextProps.value);
}
}
},
componentDidMount: function() {
var editor = this.createEditor(
this.getEditorElement(),
this.getEditorConfig());
this.setState({ editor:editor });
},
componentWillUnmount: function() {
this.destroyEditor(this.state.editor);
},
shouldComponentUpdate: function(nextProps, nextState) {
// Never re-render or we lose the element.
return false;
},
/*
If for whatever reason we are rendering again,
we should tear down the editor and bring it up
again.
*/
componentWillUpdate: function() {
this.componentWillUnmount();
},
componentDidUpdate: function() {
this.componentDidMount();
},
getEditorConfig: function() {
var config = {
readOnly: this.props.readOnly,
theme: this.props.theme,
formats: this.props.formats,
styles: this.props.styles,
modules: this.props.modules,
pollInterval: this.props.pollInterval
};
// Unless we're redefining the toolbar,
// attach to the default one as a ref.
if (!config.modules.toolbar) {
// Don't mutate the original modules
// because it's shared between components.
config.modules = JSON.parse(JSON.stringify(config.modules));
config.modules.toolbar = {
container: this.refs.toolbar.getDOMNode()
};
}
return config;
},
getEditorElement: function() {
return this.refs.editor.getDOMNode();
},
getEditorContents: function() {
return this.props.value || this.props.defaultValue;
},
getClassName: function() {
return ['quill', this.props.className].join(' ');
},
/*
Renders either the specified contents, or a default
configuration of toolbar and contents area.
*/
renderContents: function() {
if (React.Children.count(this.props.children) > 0) {
return React.Children.only(this.props.children);
} else {
return [
QuillToolbar({
key:'toolbar',
ref:'toolbar',
items: this.props.toolbar
}),
React.DOM.div({
key:'editor',
ref:'editor',
className: 'quill-contents',
dangerouslySetInnerHTML: { __html:this.getEditorContents() }
})
];
}
},
render: function() {
return React.DOM.div({
className: this.getClassName(),
onChange: this.preventDefault },
this.renderContents()
);
},
/*
Updates the local state with the new contents,
executes the change handler passed as props.
*/
onEditorChange: function(value) {
if (value !== this.state.value) {
if (this.props.onChange) {
this.props.onChange(value);
}
}
},
/*
Stop change events from the toolbar from
bubbling up outside.
*/
preventDefault: function(event) {
event.preventDefault();
event.stopPropagation();
}
});
module.exports = QuillComponent;
+7
View File
@@ -0,0 +1,7 @@
/*
React-Quill 0.0.2
https://github.com/zenoamaro/react-quill
*/
module.exports = require('./component');
module.exports.Mixin = require('./mixin');
module.exports.Toolbar = require('./toolbar');
+56
View File
@@ -0,0 +1,56 @@
'use strict';
var React = require('react'),
Quill = require('quilljs'),
T = React.PropTypes;
var QuillMixin = {
/**
Creates an editor on the given element. The editor will
be passed the configuration, have its events bound,
*/
createEditor: function($el, config) {
var editor = new Quill($el, config);
this.hookEditor(editor);
return editor;
},
hookEditor: function(editor) {
var self = this;
editor.on('text-change', function(delta, source) {
if (self.onEditorChange) {
self.onEditorChange(editor.getHTML(), delta, source);
}
});
},
updateEditor: function(editor, config) {
// TODO: Unfortunately, while we can add modules and
// stuff, we can't remove them. And there is
// little API to update other parts of the config.
// But if we could tear down the editor, at least
// we could do a re-init with the new config.
throw new Error('Not implemented');
},
destroyEditor: function(editor) {
// TODO: How to destroy this?
// editor.destroy();
editor.removeAllListeners();
},
/*
Replace the contents of the editor, but keep
the previous selection hanging around so that
the cursor won't move.
*/
setEditorContents: function(editor, value) {
var sel = editor.getSelection();
editor.setHTML(value);
editor.setSelection(sel);
}
};
module.exports = QuillMixin;
+110
View File
@@ -0,0 +1,110 @@
'use strict';
var React = require('react'),
T = React.PropTypes;
var defaultItems = [
{ label:'Formats', type:'group', items: [
{ label:'Size', type:'size', items: [
{ label:'Normal', value:'' },
{ label:'Smaller', value:'0.8em' },
{ label:'Larger', value:'1.4em' },
{ label:'Huge', value:'2em' }
]},
{ label:'Alignment', type:'align', items: [
{ label:'Center', value:'center' },
{ label:'Left', value:'left' },
{ label:'Right', value:'right' },
{ label:'Justify', value:'justify' }
]}
]},
{ label:'Text', type:'group', items: [
{ type:'bold', label:'Bold' },
{ type:'italic', label:'Italic' },
{ type:'strike', label:'Strike' },
{ type:'underline', label:'Underline' },
{ type:'link', label:'Link' }
]},
{ label:'Blocks', type:'group', items: [
{ type:'bullet', label:'Bullet' },
{ type:'list', label:'List' }
]}
];
var QuillToolbar = React.createClass({
displayName: 'Quill Toolbar',
propTypes: {
id: T.string,
className: T.string,
items: T.array
},
getDefaultProps: function(){
return {
items: defaultItems
};
},
renderGroup: function(item) {
return React.DOM.span({
key: item.label,
className:'ql-format-group' },
item.items.map(this.renderItem)
);
},
renderChoiceItem: function(item) {
return React.DOM.option({
key: item.label || item.value,
value:item.value },
item.label
);
},
renderChoices: function(item) {
return React.DOM.select({
key: item.label,
className: 'ql-'+item.type },
item.items.map(this.renderChoiceItem)
);
},
renderAction: function(item) {
return React.DOM.span({
key: item.label || item.value,
className: 'ql-format-button ql-'+item.type,
title: item.label }
);
},
renderItem: function(item) {
var mapping = {
'group': this.renderGroup,
'align': this.renderChoices,
'size': this.renderChoices,
'action': this.renderAction
};
var renderer = mapping[item.type] || mapping.action;
return renderer(item);
},
getClassName: function() {
return 'quill-toolbar ' + (this.props.className||'');
},
render: function() {
return React.DOM.div({
className: this.getClassName() },
this.props.items.map(this.renderItem)
);
}
});
module.exports = QuillToolbar;