Commit 62522c47 authored by lihaochen's avatar lihaochen

对quill做适配

parent 426460eb
Pipeline #284 canceled with stages
...@@ -14,6 +14,12 @@ import Clipboard from './modules/clipboard'; ...@@ -14,6 +14,12 @@ import Clipboard from './modules/clipboard';
import History from './modules/history'; import History from './modules/history';
import Keyboard from './modules/keyboard'; import Keyboard from './modules/keyboard';
class DividerBlot extends BlockEmbed { }
DividerBlot.blotName = 'divider';
DividerBlot.tagName = 'hr';
Quill.register(DividerBlot);
Quill.register({ Quill.register({
'blots/block' : Block, 'blots/block' : Block,
'blots/block/embed' : BlockEmbed, 'blots/block/embed' : BlockEmbed,
......
...@@ -56,7 +56,7 @@ class Quill { ...@@ -56,7 +56,7 @@ class Quill {
} }
} }
constructor(container, options = {}) { constructor(container, options = {}, shadowRoot, id) {
this.options = expandConfig(container, options); this.options = expandConfig(container, options);
this.container = this.options.container; this.container = this.options.container;
if (this.container == null) { if (this.container == null) {
...@@ -78,8 +78,9 @@ class Quill { ...@@ -78,8 +78,9 @@ class Quill {
emitter: this.emitter, emitter: this.emitter,
whitelist: this.options.formats whitelist: this.options.formats
}); });
this._id = id
this.editor = new Editor(this.scroll); this.editor = new Editor(this.scroll);
this.selection = new Selection(this.scroll, this.emitter); this.selection = new Selection(this.scroll, this.emitter, shadowRoot);
this.theme = new this.options.theme(this, this.options); this.theme = new this.options.theme(this, this.options);
this.keyboard = this.theme.addModule('keyboard'); this.keyboard = this.theme.addModule('keyboard');
this.clipboard = this.theme.addModule('clipboard'); this.clipboard = this.theme.addModule('clipboard');
...@@ -147,14 +148,15 @@ class Quill { ...@@ -147,14 +148,15 @@ class Quill {
format(name, value, source = Emitter.sources.API, shadowRoot = document) { format(name, value, source = Emitter.sources.API, shadowRoot = document) {
return modify.call(this, () => { return modify.call(this, () => {
let range = this.getSelection(true, shadowRoot); // focus = true的情况下会导致焦点回到第一个字符串前面
let range = this.getSelection(false, shadowRoot);
let change = new Delta(); let change = new Delta();
if (range == null) { if (range == null) {
return change; return change;
} else if (Parchment.query(name, Parchment.Scope.BLOCK)) { } else if (Parchment.query(name, Parchment.Scope.BLOCK)) {
change = this.editor.formatLine(range.index, range.length, { [name]: value }); change = this.editor.formatLine(range.index, range.length, { [name]: value });
} else if (range.length === 0) { } else if (range.length === 0) {
this.selection.format(name, value); this.selection.format(name, value, shadowRoot);
return change; return change;
} else { } else {
change = this.editor.formatText(range.index, range.length, { [name]: value }); change = this.editor.formatText(range.index, range.length, { [name]: value });
...@@ -239,7 +241,15 @@ class Quill { ...@@ -239,7 +241,15 @@ class Quill {