How to use the parchment.find function in parchment

To help you get started, we’ve selected a few parchment examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webiny / Webiny / Js / Webiny / Assets / node_modules / quill / core / selection.js View on Github external
format(format, value) {
    this.scroll.update();
    let nativeRange = this.getNativeRange();
    if (nativeRange == null || !nativeRange.native.collapsed || Parchment.query(format, Parchment.Scope.BLOCK)) return;
    if (nativeRange.start.node !== this.cursor.textNode) {
      let blot = Parchment.find(nativeRange.start.node, false);
      if (blot == null) return;
      // TODO Give blot ability to not split
      if (blot instanceof Parchment.Leaf) {
        let after = blot.split(nativeRange.start.offset);
        blot.parent.insertBefore(this.cursor, after);
      } else {
        blot.insertBefore(this.cursor, nativeRange.start.node);  // Should never happen
      }
      this.cursor.attach();
    }
    this.cursor.format(format, value);
    this.scroll.optimize();
    this.setNativeRange(this.cursor.textNode, this.cursor.textNode.data.length);
    this.update();
  }
github ximing / weditor / src / lib / modules / quill-image-resize-module.js View on Github external
show(img) {
        // keep track of this img element
        this.img = img;
        const rect = this.img.getBoundingClientRect();
        const rootRect = this.quill.root.getBoundingClientRect();
        this.showBox(rect, rootRect);
        // 移动游标到图片右侧
        let blot = Parchment.find(img);
        let index = blot.offset(this.quill.scroll);
        console.log('image index', index);
        this.quill.setSelection(index + 1, 0);
        //鼠标点击,删除键等操作的时候,去掉选中态
        this.quill.once('editor-change',()=>{this.hide();});
    }
github webiny / Webiny / Js / Webiny / Assets / node_modules / quill / core / selection.js View on Github external
let indexes = positions.map((position) => {
      let [node, offset] = position;
      let blot = Parchment.find(node, true);
      let index = blot.offset(this.scroll);
      if (offset === 0) {
        return index;
      } else if (blot instanceof Parchment.Container) {
        return index + blot.length();
      } else {
        return index + blot.index(node, offset);
      }
    });
    let start = Math.min(...indexes), end = Math.max(...indexes);
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / FocusModule.ts View on Github external
public getEmbedBlotForFocusedElement() {
        if (!(document.activeElement instanceof Element)) {
            return;
        }

        let activeElement = document.activeElement;
        if (!activeElement.classList.contains("js-embed")) {
            const closestEmbed = activeElement.closest(".js-embed");
            if (!closestEmbed) {
                return;
            }

            activeElement = closestEmbed;
        }

        return Parchment.find(activeElement);
    }
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / FocusModule.ts View on Github external
(event, clickedElement) => {
                if (isEditorWalledEvent(event)) {
                    return;
                }
                const embed = Parchment.find(clickedElement);
                if (embed instanceof FocusableEmbedBlot) {
                    embed.focus();
                }
            },
            this.quill.container,
github quilljs / quill / formats / code.js View on Github external
[].slice.call(this.domNode.querySelectorAll('*')).forEach(function(node) {
      let blot = Parchment.find(node);
      if (blot == null) {
        node.parentNode.removeChild(node);
      } else if (blot instanceof Parchment.Embed) {
        blot.remove();
      } else {
        blot.unwrap();
      }
    });
  }
github austintoddj / canvas / resources / js / components / editor / QuillEditor.vue View on Github external
this.editor.root.addEventListener('click', (event) => {
                let blot = Parchment.find(event.target, true);

                if (blot instanceof EmbedImageBlot) {
                    let values = blot.value(blot.domNode)['embed-image'];
                    values.existingBlot = blot;
                    this.showEmbedImageModal(values);
                }

                if (blot instanceof EmbedContentBlot) {
                    let content = blot.value(blot.domNode)['embed-content'];
                    content.existingBlot = blot;
                    this.showEmbedContentModal(content);
                }
            });
        },