quill.js官方文档(五)【API之Model,Extension】

Model

find

静态方法,给定一个DOM节点,返回对应的QuillBlot实例。
返回后者时,参数bubbletrue时,将向上搜索给定DOM的祖先节点,知道找到对应的Blot

方法

Quill.find(domNode: Node, bubble: boolean = false): Blot | Quill

示例

var container = document.querySelector("#container");
var quill = new Quill(container);
console.log(Quill.find(container) === quill);   // Should be true

quill.insertText(0, 'Hello', 'link', 'https://world.com');
var linkNode = document.querySelector('#container a');
var linkBlot = Quill.find(linkNode);

getIndex

返回文档开始至给定Blot对象位置的距离。

方法

getIndex(blot: Blot): Number

示例

let [line, offset] = quill.getLine(10);
let index = quill.getIndex(line);   // index + offset should == 10

getLeaf

指定文档中的距离,返回对应的叶Blot实例。

方法

getLeaf(index: Number): Blot

示例

quill.setText('Hello Good World!');
quill.formatText(6, 4, "bold", true);

let [leaf, offset] = quill.getLeaf(7);
// leaf should be a Text Blot with value "Good"
// offset should be 1, since the returned leaf started at index 6

getLine

指定文档中的距离,返回行Blot
方法

getLine(index: Number): [Blot, Number]

示例

quill.setText('Hello\nWorld!');

let [line, offset] = quill.getLine(7);
// line should be a Block Blot representing the 2nd "World!" line
// offset should be 1, since the returned line started at index 6

getLines

返回指定位置包含的行。

方法

getLines(index: Number = 0, length: Number = remaining): Blot[]
getLines(range: Range): Blot[]

示例

quill.setText('Hello\nGood\nWorld!');
quill.formatLine(1, 1, 'list', 'bullet');

let lines = quill.getLines(2, 5);
// array with a ListItem and Block Blot,
// representing the first two lines

Extension

debug

启用记录信息的静态方法,给定的级别有:’error’, ‘warn’, ‘log‘或’info’。传入true等同于传入’log’。传入false表示停用所有级别的消息记录。

方法

Quill.debug(level: String | Boolean)

示例

Quill.debug('info');

import

返回Quill库、格式、模块或主题的静态方法。一般,路径应该准确映射到Quill源码的目录结构。除非另有说明,对返回实体的修改可能打断已经引入的Quill功能,所以千万不要这么做。

方法

Quill.import(path): any

示例

var Parchment = Quill.import('parchment');
var Delta = Quill.import('delta');

var Toolbar = Quill.import('modules/toolbar');
var Link = Quill.import('formats/link');
// Similar to ES6 syntax `import Link from 'quill/formats/link';`

register

注册一个模块、主题或格式,让它们可用于添加到编辑器上。注册之后,可用Quill.import引入。使用’formats/’, ‘modules/‘或’themes/’ 路径前缀来分别注册格式、模块和主题。对于格式,特有一个简短的方法,只需要传入格式对象,路径将会自动生成。如果传入路径将会直接覆盖已经定义的路径。

方法

Quill.register(format: Attributor | BlotDefinintion, supressWarning: Boolean = false)
Quill.register(path: String, def: any, supressWarning: Boolean = false)
Quill.register(defs: {
    
     [String]: any }, supressWarning: Boolean = false)

示例

var Module = Quill.import('core/module');

class CustomModule extends Module {
    
    }

Quill.register('modules/custom-module', CustomModule);
Quill.register({
    
    
  'formats/custom-format': CustomFormat,
  'modules/custom-module-a': CustomModuleA,
  'modules/custom-module-b': CustomModuleB,
});

Quill.register(CustomFormat);
// You cannot do Quill.register(CustomModuleA); as CustomModuleA is not a format

addContainer

Quill容器内部新增并返回一个容器元素,和编辑器本身是兄弟关系。按照惯例,Quill模块应该有一个带前缀ql-的类名。可指定一个引用节点,新节点会插入改节点的前面。

方法

addContainer(className: String, refNode?: Node): Element
addContainer(domNode: Node, refNode?: Node): Element

示例

var container = quill.addContainer('ql-custom');

getModule

返回一个已经添加到编辑器的模块。

方法

getModule(name: String): any

示例

var toolbar = quill.getModule('toolbar');

disable

enable(false)的快捷方法。

enable

让通过鼠标或键盘等输入设备设置让用户能够编辑内容。当source为"api"或"silent`"时,不影响API的调用。

方法

enable(value: Boolean = true)

示例

quill.enable();
quill.enable(false);   // Disables user input

猜你喜欢

转载自blog.csdn.net/WuLex/article/details/108277769