quillTool.js 1.13 KB
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);