Commit 3a139a6f authored by surmon's avatar surmon
Browse files

optimoze

parent 65f60ad8
## CHANGELOG
### V3.0.1
1. add lib object-assign
2. update the options assign logic
### V3.0.0
#### use
......
......@@ -32,7 +32,7 @@
<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)
Vue.use(window.VueQuillEditor.default)
</script>
```
......@@ -217,7 +217,7 @@ Quill.register('modules/yourQuillModule', yourQuillModule)
## Issues
- [Add attributes from toolbar options](https://github.com/quilljs/quill/issues/1084)
- [Option to insert an image from a URLL](https://github.com/quilljs/quill/issues/893)
- [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)
......
......@@ -10,7 +10,8 @@ module.exports = merge(baseConfig, {
'vue-quill-editor': './src/index.js'
},
externals: {
quill: 'quill'
quill: 'quill',
'object-assign': 'object-assign'
},
output: {
path: path.resolve(__dirname, '../dist'),
......
'use strict';
var Quill = require('quill');
var defaultOptions = require('../utils/options');
Object.defineProperty(exports, "__esModule", {
value: true
});
var _quill = require('quill');
var _quill2 = _interopRequireDefault(_quill);
var _objectAssign = require('object-assign');
var _objectAssign2 = _interopRequireDefault(_objectAssign);
var _options = require('../utils/options');
var _options2 = _interopRequireDefault(_options);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var quillEditor = function quillEditor(globalOptions) {
var getInstanceName = function getInstanceName(el, binding, vnode) {
......@@ -29,29 +44,9 @@ var quillEditor = function quillEditor(globalOptions) {
};
if (!quill) {
var quillOptions = ['theme', 'modules', 'readOnly', 'boundary', 'placeholder'].reduce(function (ops, key) {
var _ref = [options[key], globalOptions[key], defaultOptions[key]],
ov = _ref[0],
gv = _ref[1],
dv = _ref[2];
if (ov !== undefined) {
ops[key] = ov;
} else if (gv !== undefined) {
ops[key] = gv;
} else if (dv !== undefined) {
ops[key] = dv;
}
return ops;
}, {});
var omt = options.modules ? options.modules.toolbar : null,
gomt = globalOptions.modules ? globalOptions.modules.toolbar : null,
domt = defaultOptions.modules ? defaultOptions.modules.toolbar : null;
quillOptions.modules.toolbar = quillOptions.modules.toolbar || (omt ? omt : gomt ? gomt : domt);
var quillOptions = (0, _objectAssign2.default)({}, _options2.default, globalOptions, options);
quill = self[instanceName] = new Quill(el, quillOptions);
quill = self[instanceName] = new _quill2.default(el, quillOptions);
var model = vnode.data.model;
var _value = vnode.data.attrs ? vnode.data.attrs.value : null;
......@@ -129,7 +124,7 @@ var quillEditor = function quillEditor(globalOptions) {
};
var VueQuillEditor = {
Quill: Quill,
Quill: _quill2.default,
quillEditor: quillEditor({}),
......@@ -140,4 +135,4 @@ var VueQuillEditor = {
}
};
module.exports = VueQuillEditor;
exports.default = VueQuillEditor;
!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 o=n[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,e),o.l=!0,o.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(3),o=n.n(i),l=n(5),r=n(4),u=r(o.a,l.a,!1,null,null,null);e.default=u.exports},function(t,e,n){"use strict";var i=window.Quill||n(0),o=n(1).default,l={Quill:i,quillEditor:o,install:function(t,e){e&&(o.props.globalOptions.default=function(){return e}),t.component(o.name,o)}};t.exports=l},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=window.Quill||n(0),o=n(6);e.default={name:"quill-editor",data:function(){return{_options:{},_content:"",defaultOptions:o}},props:{content:String,value:String,disabled:Boolean,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;if(this.$el){var e=this.options,n=this.defaultOptions,o=this.globalOptions;this._options=["theme","modules","readOnly","boundary","placeholder"].reduce(function(t,i){var l=[e[i],o[i],n[i]],r=l[0],u=l[1],s=l[2];return void 0!==r?t[i]=r:void 0!==u?t[i]=u:void 0!==s&&(t[i]=s),t},{});var l=e.modules?e.modules.toolbar:null,r=o.modules?o.modules.toolbar:null,u=n.modules?n.modules.toolbar:null;this._options.modules.toolbar=this._options.modules.toolbar||l||r||u,this.quill=new i(this.$refs.editor,this._options),(this.value||this.content)&&this.quill.pasteHTML(this.value||this.content),this.disabled&&this.quill.enable(!1),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 o=t.$refs.editor.children[0].innerHTML,l=t.quill,r=t.quill.getText();"<p><br></p>"===o&&(o=""),t._content=o,t.$emit("input",t._content),t.$emit("change",{html:o,text:r,quill:l})}),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,o,l){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),o&&(a._scopeId=o);var d;if(l?(d=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(l)},a._ssrRegister=d):i&&(d=i),d){var c=a.functional,f=c?a.render:a.beforeCreate;c?(a._injectStyles=d,a.render=function(t,e){return d.call(e),f(t,e)}):a.beforeCreate=f?[].concat(f,d):[d]}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)},o=[],l={render:i,staticRenderFns:o};e.a=l},function(t,e){t.exports={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}}])});
\ No newline at end of file
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("quill"),require("object-assign")):"function"==typeof define&&define.amd?define(["quill","object-assign"],t):"object"==typeof exports?exports.VueQuillEditor=t(require("quill"),require("object-assign")):e.VueQuillEditor=t(e.quill,e["object-assign"])}(this,function(e,t){return function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/",t(t.s=2)}([function(t,n){t.exports=e},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=n(3),o=n.n(i),l=n(5),r=n(4),u=r(o.a,l.a,!1,null,null,null);t.default=u.exports},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(0),l=i(o),r=n(1),u=i(r),s=window.Quill||l.default,a={Quill:s,quillEditor:u.default,install:function(e,t){t&&(u.default.props.globalOptions.default=function(){return t}),e.component(u.default.name,u.default)}};t.default=a},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(0),l=i(o),r=n(7),u=i(r),s=n(6),a=i(s),c=window.Quill||l.default;t.default={name:"quill-editor",data:function(){return{_options:{},_content:"",defaultOptions:a.default}},props:{content:String,value:String,disabled:Boolean,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 e=this;this.$el&&(this._options=(0,u.default)({},this.defaultOptions,this.globalOptions,this.options),this.quill=new c(this.$refs.editor,this._options),(this.value||this.content)&&this.quill.pasteHTML(this.value||this.content),this.disabled&&this.quill.enable(!1),this.quill.on("selection-change",function(t){t?e.$emit("focus",e.quill):e.$emit("blur",e.quill)}),this.quill.on("text-change",function(t,n,i){var o=e.$refs.editor.children[0].innerHTML,l=e.quill,r=e.quill.getText();"<p><br></p>"===o&&(o=""),e._content=o,e.$emit("input",e._content),e.$emit("change",{html:o,text:r,quill:l})}),this.$emit("ready",this.quill))}},watch:{content:function(e,t){this.quill&&(e&&e!==this._content?(this._content=e,this.quill.pasteHTML(e)):e||this.quill.setText(""))},value:function(e,t){this.quill&&(e&&e!==this._content?(this._content=e,this.quill.pasteHTML(e)):e||this.quill.setText(""))},disabled:function(e,t){this.quill&&this.quill.enable(!e)}}}},function(e,t){e.exports=function(e,t,n,i,o,l){var r,u=e=e||{},s=typeof e.default;"object"!==s&&"function"!==s||(r=e,u=e.default);var a="function"==typeof u?u.options:u;t&&(a.render=t.render,a.staticRenderFns=t.staticRenderFns,a._compiled=!0),n&&(a.functional=!0),o&&(a._scopeId=o);var c;if(l?(c=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),i&&i.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(l)},a._ssrRegister=c):i&&(c=i),c){var d=a.functional,f=d?a.render:a.beforeCreate;d?(a._injectStyles=c,a.render=function(e,t){return c.call(t),f(e,t)}):a.beforeCreate=f?[].concat(f,c):[c]}return{esModule:r,exports:u,options:a}}},function(e,t,n){"use strict";var i=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"quill-editor"},[e._t("toolbar"),e._v(" "),n("div",{ref:"editor"})],2)},o=[],l={render:i,staticRenderFns:o};t.a=l},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.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(e,n){e.exports=t}])});
\ No newline at end of file
......@@ -30,7 +30,7 @@
<script>
import hljs from 'highlight.js'
import { Quill } from 'vue-quill-editor'
import VueQuillEditor, { Quill } from 'vue-quill-editor'
import { ImageDrop } from 'quill-image-drop-module'
import ImageResize from 'quill-image-resize-module'
Quill.register('modules/imageDrop', ImageDrop)
......
import Vue from 'vue'
import VueQuillEditor from 'vue-quill-editor/dist/ssr'
if (process.browser) {
const VueQuillEditor = require('vue-quill-editor/dist/ssr')
Vue.use(VueQuillEditor)
}
Vue.use(VueQuillEditor)
{
"name": "vue-quill-editor",
"description": "Quill editor component for Vue",
"version": "3.0.0",
"version": "3.0.1",
"license": "MIT",
"private": false,
"author": {
......@@ -47,6 +47,7 @@
"finish": "npm run lint && npm test && npm run build"
},
"dependencies": {
"object-assign": "^4.1.1",
"quill": "^1.3.4"
},
"expDependencies": {
......@@ -54,7 +55,8 @@
"sass-loader": "^6.0.6",
"highlight.js": "^9.12.0",
"quill-image-drop-module": "^1.0.3",
"quill-image-resize-module": "^3.0.0"
"quill-image-resize-module": "^3.0.0",
"vue-quill-editor": "^3.0.0"
},
"devDependencies": {
"autoprefixer": "^6.7.2",
......@@ -77,6 +79,7 @@
"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",
......
......@@ -6,9 +6,10 @@
</template>
<script>
const Quill = window.Quill || require('quill')
const defaultOptions = require('../utils/options')
import _Quill from 'quill'
import objectAssign from 'object-assign'
import defaultOptions from '../utils/options'
const Quill = window.Quill || _Quill
export default {
name: 'quill-editor',
data() {
......@@ -41,30 +42,12 @@
delete this.quill
},
methods: {
// Init Quill instance.
// Init Quill instance
initialize() {
if (this.$el) {
// Options
const { options, defaultOptions, globalOptions } = this
this._options = ['theme', 'modules', 'readOnly', 'boundary', 'placeholder'].reduce((ops, key) => {
const [ov, gv, dv] = [options[key], globalOptions[key], defaultOptions[key]]
if (ov !== undefined) {
ops[key] = ov
} else if (gv !== undefined) {
ops[key] = gv
} else if (dv !== undefined) {
ops[key] = dv
}
return ops
}, {})
const [omt, gomt, domt] = [
options.modules ? options.modules.toolbar : null,
globalOptions.modules ? globalOptions.modules.toolbar : null,
defaultOptions.modules ? defaultOptions.modules.toolbar : null
]
this._options.modules.toolbar = this._options.modules.toolbar || (omt ? omt : (gomt ? gomt : domt))
this._options = objectAssign({}, this.defaultOptions, this.globalOptions, this.options)
// Instance
this.quill = new Quill(this.$refs.editor, this._options)
......
......@@ -5,8 +5,10 @@
* Github: https://github.com/surmon-china/vue-quill-editor
*/
const Quill = window.Quill || require('quill')
const quillEditor = require('./editor.vue').default
import _Quill from 'quill'
import quillEditor from './editor.vue'
const Quill = window.Quill || _Quill
const VueQuillEditor = {
Quill,
quillEditor,
......@@ -18,4 +20,4 @@ const VueQuillEditor = {
}
}
module.exports = VueQuillEditor
export default VueQuillEditor
......@@ -5,13 +5,14 @@
* Github: https://github.com/surmon-china/vue-quill-editor
*/
// Require sources.
const Quill = require('quill')
const defaultOptions = require('../utils/options')
// Require sources
import Quill from 'quill'
import objectAssign from 'object-assign'
import defaultOptions from '../utils/options'
const quillEditor = globalOptions => {
// Get quill instace name in directive.
// Get quill instace name in directive
const getInstanceName = (el, binding, vnode) => {
let instanceName = null
if (binding.arg) {
......@@ -31,35 +32,18 @@ const quillEditor = globalOptions => {
const instanceName = getInstanceName(el, binding, vnode)
let quill = self[instanceName]
// Emit event in Vue directive.
// 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.
// Initialize quill options
if (!quill) {
// Options
const quillOptions = ['theme', 'modules', 'readOnly', 'boundary', 'placeholder'].reduce((ops, key) => {
const [ov, gv, dv] = [options[key], globalOptions[key], defaultOptions[key]]
if (ov !== undefined) {
ops[key] = ov
} else if (gv !== undefined) {
ops[key] = gv
} else if (dv !== undefined) {
ops[key] = dv
}
return ops
}, {})
const [omt, gomt, domt] = [
options.modules ? options.modules.toolbar : null,
globalOptions.modules ? globalOptions.modules.toolbar : null,
defaultOptions.modules ? defaultOptions.modules.toolbar : null
]
quillOptions.modules.toolbar = quillOptions.modules.toolbar || (omt ? omt : (gomt ? gomt : domt))
const quillOptions = objectAssign({}, defaultOptions, globalOptions, options)
// Instance
quill = self[instanceName] = new Quill(el, quillOptions)
......@@ -110,7 +94,7 @@ const quillEditor = globalOptions => {
}
},
// Parse text model change.
// Parse text model change
componentUpdated(el, binding, vnode) {
const self = vnode.context
const instanceName = getInstanceName(el, binding, vnode)
......@@ -139,7 +123,7 @@ const quillEditor = globalOptions => {
}
},
// Destroy this directive.
// Destroy this directive
unbind(el, binding, vnode) {
if (vnode.context[binding.arg]) {
vnode.context[binding.arg] = null
......@@ -157,12 +141,12 @@ const VueQuillEditor = {
// quillEditor
quillEditor: quillEditor({}),
// Global quill default options.
// Global quill default options
install(Vue, globalOptions = {}) {
// Mount quill directive for Vue global.
// Mount quill directive for Vue global
Vue.directive('quill', quillEditor(globalOptions))
}
}
module.exports = VueQuillEditor
export default VueQuillEditor
import Quill from 'quill'
import Vue from 'vue/dist/vue.js'
import VueQuillEditor, { Quill } from '../../../src/index.js'
import VueQuillEditor from '../../../src/index.js'
import VueQuillEditorSsr from '../../../src/ssr.js'
window.Vue = Vue
......
module.exports = (Object.assign || ((target, source) => {
const toObject = val => {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined')
}
return Object(val)
}
const applyFn = (a, b, c) => {
if (typeof Reflect !== 'undefined' && Reflect && Reflect.apply) {
return Reflect.apply(a, b, c)
} else {
return a.call(b, c)
}
}
let from
let symbols
const targetObject = toObject(target)
for (let s = 1; s < arguments.length; s++) {
from = Object(arguments[s])
for (const key in from) {
if (applyFn(Object.prototype.hasOwnProperty, from, key)) {
targetObject[key] = from[key]
}
}
if (Object.getOwnPropertySymbols) {
symbols = Object.getOwnPropertySymbols(from)
for (let i = 0; i < symbols.length; i++) {
if (applyFn(Object.prototype.propIsEnumerable, from, symbols[i])) {
targetObject[symbols[i]] = from[symbols[i]]
}
}
}
}
return targetObject
}))
module.exports = {
export default {
theme: 'snow',
boundary: document.body,
modules: {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment