quillTool.js
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Quill } from 'vue-quill-editor'
const Parchment = Quill.imports.parchment;
const Delta = Quill.imports.delta;
class Label extends Parchment.Embed {
static create(value) {
const node = super.create(value.name);
node.setAttribute('keyName', value.key)
node.innerText = value.name;
node.contentEditable = 'false';
// this._addRemovalButton(node, value.key); //创建额外的标签,比如删除键
return node;
}
static value(node) {
return node.childNodes[0].textContent;
}
static _addRemovalButton(node, key) {
// const button = document.createElement('button');
// button.innerText = 'x';
// button.onclick = () => node.remove();
// button.contentEditable = 'false';
// node.appendChild(button);
// Extra span forces the cursor to the end of the label, otherwise it appears inside the removal button
const span = document.createElement('span');
span.setAttribute('keyName', key)
span.innerText = '';
node.appendChild(span);
}
}
Label.blotName = 'label';
Label.tagName = 'SPAN';
Label.className = 'ql-label';
export default Label
// Quill.register(Label);