提交 f72a835b 编写于 作者: KK's avatar KK

富文本组件

上级 0030ee0f
...@@ -105,5 +105,7 @@ export const AppComponents = { ...@@ -105,5 +105,7 @@ export const AppComponents = {
v.component('app-list-index',() => import('@/components/app-list-index/app-list-index.vue')); v.component('app-list-index',() => import('@/components/app-list-index/app-list-index.vue'));
// 下拉列表组件 // 下拉列表组件
v.component('app-history-list',() => import('@/components/app-history-list/app-history-list.vue')); v.component('app-history-list',() => import('@/components/app-history-list/app-history-list.vue'));
// 富文本
v.component('quill-editor1',() => import('@/components/vue-quill-editor/src/editor.vue'));
}, },
}; };
\ No newline at end of file
## CHANGELOG
### v3.0.6
PR194, Prevents auto-focus when using within components with dynamically set content.
### v3.0.5
update umd module name and rebuild
### v3.0.4
1. fix object assign in spa
### v3.0.3
1. fix import es module bug
2. add test script
### v3.0.2
1. assign options to ssr.js
### v3.0.1
1. add lib object-assign
2. update the options assign logic
### v3.0.0
#### use
1. require styles [#111](https://github.com/surmon-china/vue-quill-editor/issues/111)
2. add global default options [#110](https://github.com/surmon-china/vue-quill-editor/issues/110)
3. update `{ editor, text, html }` to `{ quill, text, html }`
#### project
- add brower support
- add test scripts
- update babel and webpack configs
The MIT License (MIT)
Copyright (c) 2016 Simon Babay
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.
[![GitHub stars](https://img.shields.io/github/stars/surmon-china/vue-quill-editor.svg?style=flat-square)](https://github.com/surmon-china/vue-quill-editor/stargazers)
[![Build Status](https://travis-ci.org/surmon-china/vue-quill-editor.svg?branch=master)](https://travis-ci.org/surmon-china/vue-quill-editor)
[![GitHub issues](https://img.shields.io/github/issues/surmon-china/vue-quill-editor.svg?style=flat-square)](https://github.com/surmon-china/vue-quill-editor/issues)
[![GitHub forks](https://img.shields.io/github/forks/surmon-china/vue-quill-editor.svg?style=flat-square)](https://github.com/surmon-china/vue-quill-editor/network)
[![GitHub last commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square)](https://github.com/surmon-china/vue-quill-editor)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/surmon-china/vue-quill-editor)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/surmon-china/vue-quill-editor.svg?style=flat-square)](https://twitter.com/intent/tweet?url=https://github.com/surmon-china/vue-quill-editor)
[![](https://badge.juejin.im/entry/5852b6fc61ff4b006c89b49d/likes.svg?style=flat-square)](https://juejin.im/entry/5852b6fc61ff4b006c89b49d/detail)
[![NPM](https://nodei.co/npm/vue-quill-editor.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/vue-quill-editor/)
[![NPM](https://nodei.co/npm-dl/vue-quill-editor.png?months=9&height=3)](https://nodei.co/npm/vue-quill-editor/)
# Vue-Quill-Editor
🍡Quill editor component for Vue, support SPA and SSR.
基于 Quill、适用于 Vue 的富文本编辑器,支持服务端渲染和单页应用。
## Example
[Demo Page](https://surmon-china.github.io/vue-quill-editor/)
[CDN Example](https://jsfiddle.net/tng9r8j3/)
[Nuxt.js/SSR example code](https://github.com/surmon-china/vue-quill-editor/blob/master/examples/nuxt-ssr-example)
#### Projects Using Vue-Quill-Editor
[Tamiat CMS](https://github.com/tamiat/tamiat/)
## Install
#### CDN
``` html
<link rel="stylesheet" href="path/to/quill.core.css"/>
<link rel="stylesheet" href="path/to/quill.snow.css"/>
<link rel="stylesheet" href="path/to/quill.bubble.css"/>
<script type="text/javascript" src="path/to/quill.js"></script>
<script type="text/javascript" src="path/to/vue.min.js"></script>
<script type="text/javascript" src="path/to/dist/vue-quill-editor.js"></script>
<script type="text/javascript">
Vue.use(window.VueQuillEditor)
</script>
```
#### NPM
``` bash
npm install vue-quill-editor --save
```
### Mount
#### mount with global
``` javascript
import Vue from 'vue'
import VueQuillEditor from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor, /* { default global options } */)
```
#### mount with component
```javascript
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { quillEditor } from 'vue-quill-editor'
export default {
components: {
quillEditor
}
}
```
#### mount with ssr
```javascript
// if used in nuxt.js/ssr, you should keep require it only in browser build environment
if (process.browser) {
const VueQuillEditor = require('vue-quill-editor/dist/ssr')
Vue.use(VueQuillEditor, /* { default global options } */)
}
```
#### register quill module
```javascript
// register quill modules, you need to introduce and register before the vue program is instantiated
import Quill from 'quill'
import yourQuillModule from '../yourModulePath/yourQuillModule.js'
Quill.register('modules/yourQuillModule', yourQuillModule)
```
### Difference(使用方法的区别)
**SSR and the only difference in the use of the SPA:**
- SPA worked by the `component`, find quill instance by `ref attribute`.
- SSR worked by the `directive`, find quill instance by `directive arg`.
- Other configurations, events are the same.
### SSR
``` vue
<!-- You can custom the "myQuillEditor" name used to find the quill instance in current component -->
<template>
<!-- bidirectional data binding(双向数据绑定) -->
<div class="quill-editor"
v-model="content"
v-quill:myQuillEditor="editorOption">
</div>
<!-- Or manually control the data synchronization(手动控制数据流) -->
<div class="quill-editor"
:content="content"
@change="onEditorChange($event)"
v-quill:myQuillEditor="editorOption">
</div>
</template>
<script>
export default {
data() {
return {
content: '<p>example content</p>',
editorOption: { /* quill options */ }
}
},
mounted() {
console.log('this is current quill instance object', this.myQuillEditor)
},
methods: {
onEditorChange(event) {
console.log('onEditorChange')
}
},
// Omit the same parts as in the following component sample code
// ...
}
</script>
```
### SPA
``` vue
<template>
<!-- bidirectional data binding(双向数据绑定) -->
<quill-editor v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)">
</quill-editor>
<!-- Or manually control the data synchronization(或手动控制数据流) -->
<quill-editor :content="content"
:options="editorOption"
@change="onEditorChange($event)">
</quill-editor>
</template>
<script>
// you can also register quill modules in the component
import Quill from 'quill'
import { someModule } from '../yourModulePath/someQuillModule.js'
Quill.register('modules/someModule', someModule)
export default {
data () {
return {
content: '<h2>I am Example</h2>',
editorOption: {
// some quill options
}
}
},
// manually control the data synchronization
// 如果需要手动控制数据同步,父组件需要显式地处理changed事件
methods: {
onEditorBlur(quill) {
console.log('editor blur!', quill)
},
onEditorFocus(quill) {
console.log('editor focus!', quill)
},
onEditorReady(quill) {
console.log('editor ready!', quill)
},
onEditorChange({ quill, html, text }) {
console.log('editor change!', quill, html, text)
this.content = html
}
},
computed: {
editor() {
return this.$refs.myQuillEditor.quill
}
},
mounted() {
console.log('this is current quill instance object', this.editor)
}
}
</script>
```
## Modules
- [quill-image-extend-module](https://github.com/NextBoy/quill-image-extend-module)
- [quill-image-resize-module](https://github.com/kensnyder/quill-image-resize-module)
- [quill-image-drop-module](https://github.com/kensnyder/quill-image-drop-module)
- [quilljs-table](https://github.com/dost/quilljs-table)
- [more modules...](https://github.com/search?o=desc&q=quill+module&s=stars&type=Repositories&utf8=%E2%9C%93)
## Issues
- [Add attributes from toolbar options](https://github.com/quilljs/quill/issues/1084)
- [Option to insert an image from a URL](https://github.com/quilljs/quill/issues/893)
- [How vue-quill-editor combine with the syntax highlighter module of highlight.js](https://github.com/surmon-china/vue-quill-editor/issues/39)
- [配合 element-ui 实现上传图片/视频到七牛 demo](https://github.com/surmon-china/vue-quill-editor/issues/102)
- [How to fix “Can’t find variable: Quill”, “Quill is undefined”, “window.Quill is undefined” errors when trying to use Quill modules that use Webpack in Nuxt/SSR](https://github.com/surmon-china/vue-quill-editor/issues/171#issuecomment-370253411)
## Quill documents
[Api docs](https://quilljs.com/docs/quickstart/)
## Author
[Surmon](https://surmon.me)
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.install = exports.quillEditor = exports.Quill = undefined;
var _quill = require('quill');
var _quill2 = _interopRequireDefault(_quill);
var _objectAssign = require('object-assign');
var _objectAssign2 = _interopRequireDefault(_objectAssign);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var quillDirective = function quillDirective(globalOptions) {
var getInstanceName = function getInstanceName(el, binding, vnode) {
var instanceName = null;
if (binding.arg) {
instanceName = binding.arg;
} else if (vnode.data.attrs && (vnode.data.attrs.instanceName || vnode.data.attrs['instance-name'])) {
instanceName = vnode.data.attrs.instanceName || vnode.data.attrs['instance-name'];
} else if (el.id) {
instanceName = el.id;
}
return instanceName || 'quill';
};
return {
inserted: function inserted(el, binding, vnode) {
var self = vnode.context;
var options = binding.value || {};
var instanceName = getInstanceName(el, binding, vnode);
var quill = self[instanceName];
var eventEmit = function eventEmit(vnode, name, data) {
var handlers = vnode.data && vnode.data.on || vnode.componentOptions && vnode.componentOptions.listeners;
if (handlers && handlers[name]) handlers[name].fns(data);
};
if (!quill) {
var quillOptions = (0, _objectAssign2.default)({}, {
theme: 'snow',
boundary: document.body,
modules: {
toolbar: [['bold', 'italic', 'underline', 'strike'], ['blockquote', 'code-block'], [{ 'header': 1 }, { 'header': 2 }], [{ 'list': 'ordered' }, { 'list': 'bullet' }], [{ 'script': 'sub' }, { 'script': 'super' }], [{ 'indent': '-1' }, { 'indent': '+1' }], [{ 'direction': 'rtl' }], [{ 'size': ['small', false, 'large', 'huge'] }], [{ 'header': [1, 2, 3, 4, 5, 6, false] }], [{ 'color': [] }, { 'background': [] }], [{ 'font': [] }], [{ 'align': [] }], ['clean'], ['link', 'image', 'video']]
},
placeholder: 'Insert text here ...',
readOnly: false
}, globalOptions, options);
quill = self[instanceName] = new _quill2.default(el, quillOptions);
var model = vnode.data.model;
var _value = vnode.data.attrs ? vnode.data.attrs.value : null;
var _content = vnode.data.attrs ? vnode.data.attrs.content : null;
var disabled = vnode.data.attrs ? vnode.data.attrs.disabled : null;
var content = model ? model.value : _value || _content;
if (content) {
quill.pasteHTML(content);
}
if (disabled) {
quill.enable(false);
}
quill.on('selection-change', function (range) {
if (!range) {
eventEmit(vnode, 'blur', quill);
} else {
eventEmit(vnode, 'focus', quill);
}
});
quill.on('text-change', function (delta, oldDelta, source) {
var html = el.children[0].innerHTML;
var text = quill.getText();
if (html === '<p><br></p>') {
html = '';
quill.root.innerHTML = html;
}
if (model) {
model.callback(html);
}
eventEmit(vnode, 'input', html);
eventEmit(vnode, 'change', { text: text, html: html, quill: quill });
});
eventEmit(vnode, 'ready', quill);
}
},
componentUpdated: function componentUpdated(el, binding, vnode) {
var self = vnode.context;
var instanceName = getInstanceName(el, binding, vnode);
var options = binding.value || {};
var quill = self[instanceName];
if (quill) {
var model = vnode.data.model;
var _value = vnode.data.attrs ? vnode.data.attrs.value : null;
var _content = vnode.data.attrs ? vnode.data.attrs.content : null;
var disabled = vnode.data.attrs ? vnode.data.attrs.disabled : null;
var content = model ? model.value : _value || _content;
var newData = content;
var oldData = el.children[0].innerHTML;
quill.enable(!disabled);
if (newData) {
if (newData != oldData) {
var range = quill.getSelection();
quill.root.innerHTML = newData;
setTimeout(function () {
quill.setSelection(range);
});
}
} else {
quill.setText('');
}
}
},
unbind: function unbind(el, binding, vnode) {
if (vnode.context[binding.arg]) {
vnode.context[binding.arg] = null;
delete vnode.context[binding.arg];
}
}
};
};
var quillEditor = quillDirective({});
var install = function install(Vue) {
var globalOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
Vue.directive('quill', quillDirective(globalOptions));
};
var VueQuillEditor = { Quill: _quill2.default, quillEditor: quillEditor, install: install };
exports.default = VueQuillEditor;
exports.Quill = _quill2.default;
exports.quillEditor = quillEditor;
exports.install = install;
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("quill")):"function"==typeof define&&define.amd?define(["quill"],e):"object"==typeof exports?exports.VueQuillEditor=e(require("quill")):t.VueQuillEditor=e(t.Quill)}(this,function(t){return function(t){function e(i){if(n[i])return n[i].exports;var l=n[i]={i:i,l:!1,exports:{}};return t[i].call(l.exports,l,l.exports,e),l.l=!0,l.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/",e(e.s=2)}([function(e,n){e.exports=t},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),l=n.n(i),o=n(6),r=n(5),u=r(l.a,o.a,!1,null,null,null);e.default=u.exports},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.install=e.quillEditor=e.Quill=void 0;var l=n(0),o=i(l),r=n(1),u=i(r),s=window.Quill||o.default,a=function(t,e){e&&(u.default.props.globalOptions.default=function(){return e}),t.component(u.default.name,u.default)},c={Quill:s,quillEditor:u.default,install:a};e.default=c,e.Quill=s,e.quillEditor=u.default,e.install=a},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={theme:"snow",boundary:document.body,modules:{toolbar:[["bold","italic","underline","strike"],["blockquote","code-block"],[{header:1},{header:2}],[{list:"ordered"},{list:"bullet"}],[{script:"sub"},{script:"super"}],[{indent:"-1"},{indent:"+1"}],[{direction:"rtl"}],[{size:["small",!1,"large","huge"]}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{font:[]}],[{align:[]}],["clean"],["link","image","video"]]},placeholder:"Insert text here ...",readOnly:!1}},function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var l=n(0),o=i(l),r=n(3),u=i(r),s=window.Quill||o.default;"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(t,e){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(t),i=1;i<arguments.length;i++){var l=arguments[i];if(null!=l)for(var o in l)Object.prototype.hasOwnProperty.call(l,o)&&(n[o]=l[o])}return n},writable:!0,configurable:!0}),e.default={name:"quill-editor",data:function(){return{_options:{},_content:"",defaultOptions:u.default}},props:{content:String,value:String,disabled:{type:Boolean,default:!1},options:{type:Object,required:!1,default:function(){return{}}},globalOptions:{type:Object,required:!1,default:function(){return{}}}},mounted:function(){this.initialize()},beforeDestroy:function(){this.quill=null,delete this.quill},methods:{initialize:function(){var t=this;this.$el&&(this._options=Object.assign({},this.defaultOptions,this.globalOptions,this.options),this.quill=new s(this.$refs.editor,this._options),this.quill.enable(!1),(this.value||this.content)&&this.quill.pasteHTML(this.value||this.content),this.disabled||this.quill.enable(!0),this.quill.on("selection-change",function(e){e?t.$emit("focus",t.quill):t.$emit("blur",t.quill)}),this.quill.on("text-change",function(e,n,i){var l=t.$refs.editor.children[0].innerHTML,o=t.quill,r=t.quill.getText();"<p><br></p>"===l&&(l=""),t._content=l,t.$emit("input",t._content),t.$emit("change",{html:l,text:r,quill:o})}),this.$emit("ready",this.quill))}},watch:{content:function(t,e){this.quill&&(t&&t!==this._content?(this._content=t,this.quill.pasteHTML(t)):t||this.quill.setText(""))},value:function(t,e){this.quill&&(t&&t!==this._content?(this._content=t,this.quill.pasteHTML(t)):t||this.quill.setText(""))},disabled:function(t,e){this.quill&&this.quill.enable(!t)}}}},function(t,e){t.exports=function(t,e,n,i,l,o){var r,u=t=t||{},s=typeof t.default;"object"!==s&&"function"!==s||(r=t,u=t.default);var a="function"==typeof u?u.options:u;e&&(a.render=e.render,a.staticRenderFns=e.staticRenderFns,a._compiled=!0),n&&(a.functional=!0),l&&(a._scopeId=l);var c;if(o?(c=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),i&&i.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(o)},a._ssrRegister=c):i&&(c=i),c){var d=a.functional,f=d?a.render:a.beforeCreate;d?(a._injectStyles=c,a.render=function(t,e){return c.call(e),f(t,e)}):a.beforeCreate=f?[].concat(f,c):[c]}return{esModule:r,exports:u,options:a}}},function(t,e,n){"use strict";var i=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",{staticClass:"quill-editor"},[t._t("toolbar"),t._v(" "),n("div",{ref:"editor"})],2)},l=[],o={render:i,staticRenderFns:l};e.a=o}])});
\ No newline at end of file
{
"name": "vue-quill-editor",
"description": "Quill editor component for Vue",
"version": "3.0.6",
"license": "MIT",
"private": false,
"author": {
"name": "Surmon",
"email": "surmon@foxmail.com",
"url": "https://surmon.me"
},
"bugs": {
"url": "https://github.com/surmon-china/vue-quill-editor/issues"
},
"homepage": "https://github.com/surmon-china/vue-quill-editor#readme",
"main": "dist/vue-quill-editor.js",
"unpkg": "dist/vue-quill-editor.js",
"jsnext:main": "dist/vue-quill-editor.js",
"files": [
"dist",
"src"
],
"jspm": {
"main": "dist/vue-quill-editor.js",
"registry": "npm",
"format": "esm"
},
"repository": {
"type": "git",
"url": "https://github.com/surmon-china/vue-quill-editor.git"
},
"keywords": [
"vue-quill-editor",
"vue quill",
"vue text editor",
"vue rich text editor",
"vue web editor",
"vue editor"
],
"scripts": {
"build:spa": "cross-env NODE_ENV=production webpack --config config/build.conf.js",
"build:ssr": "babel src/ssr.js --out-file dist/ssr.js",
"build": "npm run build:spa && npm run build:ssr",
"unit": "cross-env BABEL_ENV=test NODE_ENV=testing karma start test/unit/karma.conf.js --watch",
"test": "cross-env BABEL_ENV=test NODE_ENV=testing karma start test/unit/karma.conf.js --single-run",
"lint": "eslint --ext .js,.vue src test/unit/specs",
"finish": "npm run lint && npm test && npm run build",
"publish": "git push && git push --tags && npm publish"
},
"dependencies": {
"object-assign": "^4.1.1",
"quill": "^1.3.4"
},
"expDependencies": {
"node-sass": "^4.7.2",
"sass-loader": "^6.0.6",
"highlight.js": "^9.12.0",
"quill-image-drop-module": "^1.0.3",
"quill-image-resize-module": "^3.0.0",
"vue-quill-editor": "^3.0.0"
},
"devDependencies": {
"autoprefixer": "^6.7.2",
"babel-cli": "^6.23.0",
"babel-core": "^6.24.1",
"babel-eslint": "^7.1.1",
"babel-helper-vue-jsx-merge-props": "^2.0.2",
"babel-loader": "^6.2.10",
"babel-plugin-istanbul": "^3.1.2",
"babel-plugin-syntax-jsx": "^6.13.0",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-export-extensions": "^6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.0.0",
"chai": "^3.5.0",
"chalk": "^1.1.3",
"connect-history-api-fallback": "^1.1.0",
"copy-webpack-plugin": "^4.0.0",
"cross-env": "^5.0.0",
"cross-spawn": "^5.1.0",
"css-loader": "^0.25.0",
"eslint": "^3.14.1",
"eslint-config-standard": "^6.1.0",
"eslint-friendly-formatter": "^2.0.5",
"eslint-loader": "^1.6.1",
"eslint-plugin-html": "^2.0.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^2.0.0-rc.3",
"file-loader": "^0.10.0",
"friendly-errors-webpack-plugin": "^1.1.3",
"function-bind": "^1.1.0",
"html-loader": "^0.4.4",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"inject-loader": "^2.0.1",
"json-loader": "^0.5.4",
"jstransformer-markdown-it": "^2.0.0",
"karma": "^1.4.1",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sinon-chai": "^1.2.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.26",
"karma-webpack": "^2.0.2",
"lolex": "^1.5.2",
"mocha": "^3.2.0",
"opn": "^4.0.2",
"optimize-css-assets-webpack-plugin": "^1.3.0",
"ora": "^0.3.0",
"phantomjs-prebuilt": "^2.1.3",
"raw-loader": "^0.5.1",
"semver": "^5.3.0",
"shelljs": "^0.7.4",
"sinon": "^2.1.0",
"sinon-chai": "^2.8.0",
"uglify-js": "^3.0.15",
"url-loader": "^0.5.7",
"vue": "^2.5.0",
"vue-hot-reload-api": "^1.2.0",
"vue-html-loader": "^1.0.0",
"vue-loader": "^13.3.0",
"vue-template-compiler": "^2.5.2",
"vue-template-es2015-compiler": "^1.6.0",
"webpack": "^2.2.1",
"webpack-bundle-analyzer": "^2.2.1",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.16.1",
"webpack-merge": "^2.6.1"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
}
}
<template>
<div class="quill-editor">
<slot name="toolbar"></slot>
<div ref="editor"></div>
</div>
</template>
<script>
// require sources
import _Quill from 'quill'
import defaultOptions from './options'
const Quill = window.Quill || _Quill
// pollfill
if (typeof Object.assign != 'function') {
Object.defineProperty(Object, 'assign', {
value(target, varArgs) {
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object')
}
const to = Object(target)
for (let index = 1; index < arguments.length; index++) {
const nextSource = arguments[index]
if (nextSource != null) {
for (const nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey]
}
}
}
}
return to
},
writable: true,
configurable: true
})
}
// export
export default {
name: 'quill-editor',
data() {
return {
_options: {},
_content: '',
defaultOptions
}
},
props: {
content: String,
value: String,
disabled: {
type: Boolean,
default: false
},
options: {
type: Object,
required: false,
default: () => ({})
},
globalOptions: {
type: Object,
required: false,
default: () => ({})
}
},
mounted() {
this.initialize()
},
beforeDestroy() {
this.quill = null
delete this.quill
},
methods: {
// Init Quill instance
initialize() {
if (this.$el) {
// Options
this._options = Object.assign({}, this.defaultOptions, this.globalOptions, this.options)
// Instance
this.quill = new Quill(this.$refs.editor, this._options)
this.quill.enable(false)
// Set editor content
if (this.value || this.content) {
this.quill.pasteHTML(this.value || this.content)
}
// Disabled editor
if (!this.disabled) {
this.quill.enable(true)
}
// Mark model as touched if editor lost focus
this.quill.on('selection-change', range => {
if (!range) {
this.$emit('blur', this.quill)
} else {
this.$emit('focus', this.quill)
}
})
// Update model if text changes
this.quill.on('text-change', (delta, oldDelta, source) => {
let html = this.$refs.editor.children[0].innerHTML
const quill = this.quill
const text = this.quill.getText()
if (html === '<p><br></p>') html = ''
this._content = html
this.$emit('input', this._content)
this.$emit('change', { html, text, quill })
})
// Emit ready event
this.$emit('ready', this.quill)
}
}
},
watch: {
// Watch content change
content(newVal, oldVal) {
if (this.quill) {
if (newVal && newVal !== this._content) {
this._content = newVal
this.quill.pasteHTML(newVal)
} else if(!newVal) {
this.quill.setText('')
}
}
},
// Watch content change
value(newVal, oldVal) {
if (this.quill) {
if (newVal && newVal !== this._content) {
this._content = newVal
this.quill.pasteHTML(newVal)
} else if(!newVal) {
this.quill.setText('')
}
}
},
// Watch disabled change
disabled(newVal, oldVal) {
if (this.quill) {
this.quill.enable(!newVal)
}
}
}
}
</script>
<style >
@import "./quill.bubble.css";
@import "./quill.core.css";
@import "./quill.snow.css";
</style>
/*
* Vue-Quill-Editor index.js
* Author: surmon@foxmail.com
* Github: https://github.com/surmon-china/vue-quill-editor
*/
import _Quill from 'quill'
import quillEditor from './editor.vue'
const Quill = window.Quill || _Quill
const install = (Vue, globalOptions) => {
if (globalOptions) {
quillEditor.props.globalOptions.default = () => globalOptions
}
Vue.component(quillEditor.name, quillEditor)
}
const VueQuillEditor = { Quill, quillEditor, install }
export default VueQuillEditor
export { Quill, quillEditor, install }
export default {
theme: 'snow',
boundary: document.body,
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }],
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'direction': 'rtl' }],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'font': [] }],
[{ 'align': [] }],
['clean'],
['link', 'image', 'video']
]
},
placeholder: 'Insert text here ...',
readOnly: false
}
此差异已折叠。
/*!
* Quill Editor v1.3.7
* https://quilljs.com/
* Copyright (c) 2014, Jason Chen
* Copyright (c) 2013, salesforce.com
*/
.ql-container {
box-sizing: border-box;
font-family: Helvetica, Arial, sans-serif;
font-size: 13px;
height: 100%;
margin: 0px;
position: relative;
}
.ql-container.ql-disabled .ql-tooltip {
visibility: hidden;
}
.ql-container.ql-disabled .ql-editor ul[data-checked] > li::before {
pointer-events: none;
}
.ql-clipboard {
left: -100000px;
height: 1px;
overflow-y: hidden;
position: absolute;
top: 50%;
}
.ql-clipboard p {
margin: 0;
padding: 0;
}
.ql-editor {
box-sizing: border-box;
line-height: 1.42;
height: 100%;
outline: none;
overflow-y: auto;
padding: 12px 15px;
tab-size: 4;
-moz-tab-size: 4;
text-align: left;
white-space: pre-wrap;
word-wrap: break-word;
}
.ql-editor > * {
cursor: text;
}
.ql-editor p,
.ql-editor ol,
.ql-editor ul,
.ql-editor pre,
.ql-editor blockquote,
.ql-editor h1,
.ql-editor h2,
.ql-editor h3,
.ql-editor h4,
.ql-editor h5,
.ql-editor h6 {
margin: 0;
padding: 0;
counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol,
.ql-editor ul {
padding-left: 1.5em;
}
.ql-editor ol > li,
.ql-editor ul > li {
list-style-type: none;
}
.ql-editor ul > li::before {
content: '\2022';
}
.ql-editor ul[data-checked=true],
.ql-editor ul[data-checked=false] {
pointer-events: none;
}
.ql-editor ul[data-checked=true] > li *,
.ql-editor ul[data-checked=false] > li * {
pointer-events: all;
}
.ql-editor ul[data-checked=true] > li::before,
.ql-editor ul[data-checked=false] > li::before {
color: #777;
cursor: pointer;
pointer-events: all;
}
.ql-editor ul[data-checked=true] > li::before {
content: '\2611';
}
.ql-editor ul[data-checked=false] > li::before {
content: '\2610';
}
.ql-editor li::before {
display: inline-block;
white-space: nowrap;
width: 1.2em;
}
.ql-editor li:not(.ql-direction-rtl)::before {
margin-left: -1.5em;
margin-right: 0.3em;
text-align: right;
}
.ql-editor li.ql-direction-rtl::before {
margin-left: 0.3em;
margin-right: -1.5em;
}
.ql-editor ol li:not(.ql-direction-rtl),
.ql-editor ul li:not(.ql-direction-rtl) {
padding-left: 1.5em;
}
.ql-editor ol li.ql-direction-rtl,
.ql-editor ul li.ql-direction-rtl {
padding-right: 1.5em;
}
.ql-editor ol li {
counter-reset: list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;
counter-increment: list-0;
}
.ql-editor ol li:before {
content: counter(list-0, decimal) '. ';
}
.ql-editor ol li.ql-indent-1 {
counter-increment: list-1;
}
.ql-editor ol li.ql-indent-1:before {
content: counter(list-1, lower-alpha) '. ';
}
.ql-editor ol li.ql-indent-1 {
counter-reset: list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-2 {
counter-increment: list-2;
}
.ql-editor ol li.ql-indent-2:before {
content: counter(list-2, lower-roman) '. ';
}
.ql-editor ol li.ql-indent-2 {
counter-reset: list-3 list-4 list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-3 {
counter-increment: list-3;
}
.ql-editor ol li.ql-indent-3:before {
content: counter(list-3, decimal) '. ';
}
.ql-editor ol li.ql-indent-3 {
counter-reset: list-4 list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-4 {
counter-increment: list-4;
}
.ql-editor ol li.ql-indent-4:before {
content: counter(list-4, lower-alpha) '. ';
}
.ql-editor ol li.ql-indent-4 {
counter-reset: list-5 list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-5 {
counter-increment: list-5;
}
.ql-editor ol li.ql-indent-5:before {
content: counter(list-5, lower-roman) '. ';
}
.ql-editor ol li.ql-indent-5 {
counter-reset: list-6 list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-6 {
counter-increment: list-6;
}
.ql-editor ol li.ql-indent-6:before {
content: counter(list-6, decimal) '. ';
}
.ql-editor ol li.ql-indent-6 {
counter-reset: list-7 list-8 list-9;
}
.ql-editor ol li.ql-indent-7 {
counter-increment: list-7;
}
.ql-editor ol li.ql-indent-7:before {
content: counter(list-7, lower-alpha) '. ';
}
.ql-editor ol li.ql-indent-7 {
counter-reset: list-8 list-9;
}
.ql-editor ol li.ql-indent-8 {
counter-increment: list-8;
}
.ql-editor ol li.ql-indent-8:before {
content: counter(list-8, lower-roman) '. ';
}
.ql-editor ol li.ql-indent-8 {
counter-reset: list-9;
}
.ql-editor ol li.ql-indent-9 {
counter-increment: list-9;
}
.ql-editor ol li.ql-indent-9:before {
content: counter(list-9, decimal) '. ';
}
.ql-editor .ql-indent-1:not(.ql-direction-rtl) {
padding-left: 3em;
}
.ql-editor li.ql-indent-1:not(.ql-direction-rtl) {
padding-left: 4.5em;
}
.ql-editor .ql-indent-1.ql-direction-rtl.ql-align-right {
padding-right: 3em;
}
.ql-editor li.ql-indent-1.ql-direction-rtl.ql-align-right {
padding-right: 4.5em;
}
.ql-editor .ql-indent-2:not(.ql-direction-rtl) {
padding-left: 6em;
}
.ql-editor li.ql-indent-2:not(.ql-direction-rtl) {
padding-left: 7.5em;
}
.ql-editor .ql-indent-2.ql-direction-rtl.ql-align-right {
padding-right: 6em;
}
.ql-editor li.ql-indent-2.ql-direction-rtl.ql-align-right {
padding-right: 7.5em;
}
.ql-editor .ql-indent-3:not(.ql-direction-rtl) {
padding-left: 9em;
}
.ql-editor li.ql-indent-3:not(.ql-direction-rtl) {
padding-left: 10.5em;
}
.ql-editor .ql-indent-3.ql-direction-rtl.ql-align-right {
padding-right: 9em;
}
.ql-editor li.ql-indent-3.ql-direction-rtl.ql-align-right {
padding-right: 10.5em;
}
.ql-editor .ql-indent-4:not(.ql-direction-rtl) {
padding-left: 12em;
}
.ql-editor li.ql-indent-4:not(.ql-direction-rtl) {
padding-left: 13.5em;
}
.ql-editor .ql-indent-4.ql-direction-rtl.ql-align-right {
padding-right: 12em;
}
.ql-editor li.ql-indent-4.ql-direction-rtl.ql-align-right {
padding-right: 13.5em;
}
.ql-editor .ql-indent-5:not(.ql-direction-rtl) {
padding-left: 15em;
}
.ql-editor li.ql-indent-5:not(.ql-direction-rtl) {
padding-left: 16.5em;
}
.ql-editor .ql-indent-5.ql-direction-rtl.ql-align-right {
padding-right: 15em;
}
.ql-editor li.ql-indent-5.ql-direction-rtl.ql-align-right {
padding-right: 16.5em;
}
.ql-editor .ql-indent-6:not(.ql-direction-rtl) {
padding-left: 18em;
}
.ql-editor li.ql-indent-6:not(.ql-direction-rtl) {
padding-left: 19.5em;
}
.ql-editor .ql-indent-6.ql-direction-rtl.ql-align-right {
padding-right: 18em;
}
.ql-editor li.ql-indent-6.ql-direction-rtl.ql-align-right {
padding-right: 19.5em;
}
.ql-editor .ql-indent-7:not(.ql-direction-rtl) {
padding-left: 21em;
}
.ql-editor li.ql-indent-7:not(.ql-direction-rtl) {
padding-left: 22.5em;
}
.ql-editor .ql-indent-7.ql-direction-rtl.ql-align-right {
padding-right: 21em;
}
.ql-editor li.ql-indent-7.ql-direction-rtl.ql-align-right {
padding-right: 22.5em;
}
.ql-editor .ql-indent-8:not(.ql-direction-rtl) {
padding-left: 24em;
}
.ql-editor li.ql-indent-8:not(.ql-direction-rtl) {
padding-left: 25.5em;
}
.ql-editor .ql-indent-8.ql-direction-rtl.ql-align-right {
padding-right: 24em;
}
.ql-editor li.ql-indent-8.ql-direction-rtl.ql-align-right {
padding-right: 25.5em;
}
.ql-editor .ql-indent-9:not(.ql-direction-rtl) {
padding-left: 27em;
}
.ql-editor li.ql-indent-9:not(.ql-direction-rtl) {
padding-left: 28.5em;
}
.ql-editor .ql-indent-9.ql-direction-rtl.ql-align-right {
padding-right: 27em;
}
.ql-editor li.ql-indent-9.ql-direction-rtl.ql-align-right {
padding-right: 28.5em;
}
.ql-editor .ql-video {
display: block;
max-width: 100%;
}
.ql-editor .ql-video.ql-align-center {
margin: 0 auto;
}
.ql-editor .ql-video.ql-align-right {
margin: 0 0 0 auto;
}
.ql-editor .ql-bg-black {
background-color: #000;
}
.ql-editor .ql-bg-red {
background-color: #e60000;
}
.ql-editor .ql-bg-orange {
background-color: #f90;
}
.ql-editor .ql-bg-yellow {
background-color: #ff0;
}
.ql-editor .ql-bg-green {
background-color: #008a00;
}
.ql-editor .ql-bg-blue {
background-color: #06c;
}
.ql-editor .ql-bg-purple {
background-color: #93f;
}
.ql-editor .ql-color-white {
color: #fff;
}
.ql-editor .ql-color-red {
color: #e60000;
}
.ql-editor .ql-color-orange {
color: #f90;
}
.ql-editor .ql-color-yellow {
color: #ff0;
}
.ql-editor .ql-color-green {
color: #008a00;
}
.ql-editor .ql-color-blue {
color: #06c;
}
.ql-editor .ql-color-purple {
color: #93f;
}
.ql-editor .ql-font-serif {
font-family: Georgia, Times New Roman, serif;
}
.ql-editor .ql-font-monospace {
font-family: Monaco, Courier New, monospace;
}
.ql-editor .ql-size-small {
font-size: 0.75em;
}
.ql-editor .ql-size-large {
font-size: 1.5em;
}
.ql-editor .ql-size-huge {
font-size: 2.5em;
}
.ql-editor .ql-direction-rtl {
direction: rtl;
text-align: inherit;
}
.ql-editor .ql-align-center {
text-align: center;
}
.ql-editor .ql-align-justify {
text-align: justify;
}
.ql-editor .ql-align-right {
text-align: right;
}
.ql-editor.ql-blank::before {
color: rgba(0,0,0,0.6);
content: attr(data-placeholder);
font-style: italic;
left: 15px;
pointer-events: none;
position: absolute;
right: 15px;
}
此差异已折叠。
/*
* vue-quill-editor ssr.js
* Author: surmon@foxmail.com
* Github: https://github.com/surmon-china/vue-quill-editor
*/
// Require sources
import Quill from 'quill'
import objectAssign from 'object-assign'
const quillDirective = globalOptions => {
// Get quill instace name in directive
const getInstanceName = (el, binding, vnode) => {
let instanceName = null
if (binding.arg) {
instanceName = binding.arg
} else if (vnode.data.attrs && (vnode.data.attrs.instanceName || vnode.data.attrs['instance-name'])) {
instanceName = (vnode.data.attrs.instanceName || vnode.data.attrs['instance-name'])
} else if (el.id) {
instanceName = el.id
}
return instanceName || 'quill'
}
return {
inserted(el, binding, vnode) {
const self = vnode.context
const options = binding.value || {}
const instanceName = getInstanceName(el, binding, vnode)
let quill = self[instanceName]
// Emit event in Vue directive
const eventEmit = (vnode, name, data) => {
const handlers = (vnode.data && vnode.data.on) ||
(vnode.componentOptions && vnode.componentOptions.listeners)
if (handlers && handlers[name]) handlers[name].fns(data)
}
// Initialize quill options
if (!quill) {
// Options
const quillOptions = objectAssign({}, {
theme: 'snow',
boundary: document.body,
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }],
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'direction': 'rtl' }],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'font': [] }],
[{ 'align': [] }],
['clean'],
['link', 'image', 'video']
]
},
placeholder: 'Insert text here ...',
readOnly: false
}, globalOptions, options)
// Instance
quill = self[instanceName] = new Quill(el, quillOptions)
// Data init
const model = vnode.data.model
const _value = vnode.data.attrs ? vnode.data.attrs.value : null
const _content = vnode.data.attrs ? vnode.data.attrs.content : null
const disabled = vnode.data.attrs ? vnode.data.attrs.disabled : null
const content = model ? model.value : (_value || _content)
// Set editor content
if (content) {
quill.pasteHTML(content)
}
// Disabled editor
if (disabled) {
quill.enable(false)
}
// Mark model as touched if editor lost focus
quill.on('selection-change', range => {
if (!range) {
eventEmit(vnode, 'blur', quill)
} else {
eventEmit(vnode, 'focus', quill)
}
})
// Update model if text changes
quill.on('text-change', (delta, oldDelta, source) => {
let html = el.children[0].innerHTML
const text = quill.getText()
if (html === '<p><br></p>') {
html = ''
quill.root.innerHTML = html
}
if (model) {
model.callback(html)
}
eventEmit(vnode, 'input', html)
eventEmit(vnode, 'change', { text, html, quill })
})
// Emit ready event
eventEmit(vnode, 'ready', quill)
}
},
// Parse text model change
componentUpdated(el, binding, vnode) {
const self = vnode.context
const instanceName = getInstanceName(el, binding, vnode)
const options = binding.value || {}
const quill = self[instanceName]
if (quill) {
const model = vnode.data.model
const _value = vnode.data.attrs ? vnode.data.attrs.value : null
const _content = vnode.data.attrs ? vnode.data.attrs.content : null
const disabled = vnode.data.attrs ? vnode.data.attrs.disabled : null
const content = model ? model.value : (_value || _content)
const newData = content
const oldData = el.children[0].innerHTML
quill.enable(!disabled)
if (newData) {
if (newData != oldData) {
const range = quill.getSelection()
quill.root.innerHTML = newData
setTimeout(() => {
quill.setSelection(range)
})
}
} else {
quill.setText('')
}
}
},
// Destroy this directive
unbind(el, binding, vnode) {
if (vnode.context[binding.arg]) {
vnode.context[binding.arg] = null
delete vnode.context[binding.arg]
}
}
}
}
// quillEditor
const quillEditor = quillDirective({})
// Global quill default options
const install = function (Vue, globalOptions = {}) {
// Mount quill directive for Vue global
Vue.directive('quill', quillDirective(globalOptions))
}
const VueQuillEditor = { Quill, quillEditor, install }
export default VueQuillEditor
export { Quill, quillEditor, install }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册