slab / quill

Quill is a modern WYSIWYG editor built for compatibility and extensibility
https://quilljs.com
BSD 3-Clause "New" or "Revised" License
43.52k stars 3.38k forks source link

How to get quill instance in blot's create func? #3432

Closed YNestA closed 8 months ago

vtejuf commented 3 years ago

I do it like 这样式儿的

  static create({value, quill}) {
    let node = super.create();
    node.setAttribute('data-val', value);
    if (quill) {
      node.setAttribute('rendered', 1);
    }
    return node;
  }

  constructor(domNode) {
    super(domNode);
    if (!domNode.hasAttribute('rendered')) {
      setTimeout(() => {
        const quill = Quill.find(this.scroll.domNode.parentNode);
        const value = domNode?.getAttribute('data-val');
        this.replaceWith(this.statics.blotName, {
          value,
          quill
        });
      }, 0);
    }
  }
YNestA commented 3 years ago

I do it like 这样式儿的

  static create({value, quill}) {
    let node = super.create();
    node.setAttribute('data-val', value);
    if (quill) {
      node.setAttribute('rendered', 1);
    }
    return node;
  }

  constructor(domNode) {
    super(domNode);
    if (!domNode.hasAttribute('rendered')) {
      setTimeout(() => {
        const quill = Quill.find(this.scroll.domNode.parentNode);
        const value = domNode?.getAttribute('data-val');
        this.replaceWith(this.statics.blotName, {
          value,
          quill
        });
      }, 0);
    }
  }

solved in quill2.