quill.js official document (5) [API Model, Extension]

Model

find

Static method, given a DOMnode, return the corresponding Quillor Blotinstance.
Return the latter parameter bubbleis true, the search for a given direction DOMof ancestor nodes, find the corresponding known Blot.

method

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

Example

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

Returns Blotthe distance from the beginning of the document to the given object position.

method

getIndex(blot: Blot): Number

Example

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

getLeaf

Specify the distance in the document and return the corresponding leaf Blotinstance.

method

getLeaf(index: Number): Blot

Example

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

Specify the distance in the document and return the line Blot.
method

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

Example

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

Returns the row contained in the specified position.

method

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

Example

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

Enable the static method of logging information, the given levels are: ' error',' warn', ' log' or ' info'. Incoming is trueequivalent to incoming ' log'. Incoming falsemeans to disable all levels of message logging.

method

Quill.debug(level: String | Boolean)

Example

Quill.debug('info');

import

QuillStatic methods that return libraries, formats, modules, or themes. Generally, the path should accurately map to Quillthe directory structure of the source code. Unless otherwise stated, modifications to the returned entity may interrupt the Quillfunctionality that has already been introduced , so never do this.

method

Quill.import(path): any

Example

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

Register a module, theme or format to make them available for adding to the editor. After registration, it can be Quill.importimported. Use the ' formats/',' modules/'or' themes/'path prefix to register the format, module and theme respectively. For the format, there is a short method that only needs to pass in the format object, and the path will be automatically generated. If the path is passed in, it will directly overwrite the path already defined.

method

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)

Example

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

In the Quillnew and returning a container element, inside the container itself and editors are brothers. By convention, Quillmodules should have a prefixed ql-class name. You can specify a reference node, and the new node will be inserted before the changed node.

method

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

Example

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

getModule

Return a module that has been added to the editor.

method

getModule(name: String): any

Example

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

disable

enable(false)The shortcut method.

enable

Allow users to edit content through input device settings such as a mouse or keyboard. When it sourceis " api" or "silent`", it does not affect API calls.

method

enable(value: Boolean = true)

Example

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

Guess you like

Origin blog.csdn.net/WuLex/article/details/108277769