How to use the quill-delta function in quill-delta

To help you get started, we’ve selected a few quill-delta 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 ximing / weditor / src / lib / initQuill.js View on Github external
function traverse(node, elementMatchers, textMatchers) {  // Post-order
    if (node.nodeType === node.TEXT_NODE) {
        return textMatchers.reduce(function (delta, matcher) {
            return matcher(node, delta);
        }, new Delta());
    } else if (node.nodeType === node.ELEMENT_NODE) {
        return [].reduce.call(node.childNodes || [], (delta, childNode) => {
            let childrenDelta = traverse(childNode, elementMatchers, textMatchers);
            if (childNode.nodeType === node.ELEMENT_NODE) {
                childrenDelta = elementMatchers.reduce(function (childrenDelta, matcher) {
                    return matcher(childNode, childrenDelta);
                }, childrenDelta);
                childrenDelta = (childNode[DOM_KEY] || []).reduce(function (childrenDelta, matcher) {
                    return matcher(childNode, childrenDelta);
                }, childrenDelta);
            }
            return delta.concat(childrenDelta);
        }, new Delta());
    } else {
        return new Delta();
    }
github llaske / sugarizer / activities / Write.activity / lib / quill / modules / clipboard.js View on Github external
function traverse(scroll, node, elementMatchers, textMatchers, nodeMatches) {
  // Post-order
  if (node.nodeType === node.TEXT_NODE) {
    return textMatchers.reduce((delta, matcher) => {
      return matcher(node, delta, scroll);
    }, new Delta());
  }
  if (node.nodeType === node.ELEMENT_NODE) {
    return Array.from(node.childNodes || []).reduce((delta, childNode) => {
      let childrenDelta = traverse(
        scroll,
        childNode,
        elementMatchers,
        textMatchers,
        nodeMatches,
      );
      if (childNode.nodeType === node.ELEMENT_NODE) {
        childrenDelta = elementMatchers.reduce((reducedDelta, matcher) => {
          return matcher(childNode, reducedDelta, scroll);
        }, childrenDelta);
        childrenDelta = (nodeMatches.get(childNode) || []).reduce(
          (reducedDelta, matcher) => {
github quilljs / quill / test / unit / modules / table.js View on Github external
it('insertText before', function() {
      this.quill.updateContents(new Delta().insert('\n'));
      expect(this.quill.root).toEqualHTML(`
        <p><br></p>
        <table>
          <tbody>
            <tr><td>a1</td><td>a2</td><td>a3</td></tr>
            <tr><td>b1</td><td>b2</td><td>b3</td></tr>
          </tbody>
        </table>
      `);
    });
github webiny / Webiny / Js / Webiny / Assets / node_modules / quill / themes / base.js View on Github external
reader.onload = (e) => {
                  let range = this.quill.getSelection(true);
                  this.quill.updateContents(new Delta()
                    .retain(range.index)
                    .delete(range.length)
                    .insert({ image: e.target.result })
                  , Emitter.sources.USER);
                  fileInput.value = "";
                }
                reader.readAsDataURL(fileInput.files[0]);
github webiny / Webiny / Js / Webiny / Assets / node_modules / quill / core / quill.js View on Github external
return modify.call(this, () => {
      delta = new Delta(delta);
      let length = this.getLength();
      let deleted = this.editor.deleteText(0, length);
      let applied = this.editor.applyDelta(delta);
      let lastOp = applied.ops[applied.ops.length - 1];
      if (lastOp != null && lastOp.insert[lastOp.insert.length-1] === '\n') {
        this.editor.deleteText(this.getLength() - 1, 1);
        applied.delete(1);
      }
      let ret = deleted.compose(applied);
      return ret;
    }, source);
  }
github llaske / sugarizer / activities / Write.activity / lib / quill / modules / uploader.js View on Github external
Promise.all(promises).then(images => {
      const update = images.reduce((delta, image) => {
        return delta.insert({ image });
      }, new Delta().retain(range.index).delete(range.length));
      this.quill.updateContents(update, Emitter.sources.USER);
      this.quill.setSelection(
        range.index + images.length,
        Emitter.sources.SILENT,
      );
    });
  },
github quilljs / quill / core / quill.js View on Github external
() => {
        delta = new Delta(delta);
        const length = this.getLength();
        const deleted = this.editor.deleteText(0, length);
        const applied = this.editor.applyDelta(delta);
        const lastOp = applied.ops[applied.ops.length - 1];
        if (
          lastOp != null &&
          typeof lastOp.insert === 'string' &&
          lastOp.insert[lastOp.insert.length - 1] === '\n'
        ) {
          this.editor.deleteText(this.getLength() - 1, 1);
          applied.delete(1);
        }
        return deleted.compose(applied);
      },
      source,
github quilljs / quill / core / editor.js View on Github external
function normalizeDelta(delta) {
  return delta.reduce((normalizedDelta, op) => {
    if (typeof op.insert === 'string') {
      const text = op.insert.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
      return normalizedDelta.insert(text, op.attributes);
    }
    return normalizedDelta.push(op);
  }, new Delta());
}
github quilljs / quill / core / editor.js View on Github external
getDelta() {
    return this.scroll.lines().reduce((delta, line) => {
      return delta.concat(line.delta());
    }, new Delta());
  }
github amytfang / CaseNote / frontend / components / opinions / opinion_detail_body.jsx View on Github external
processAnnotations(opinion = this.props.opinion) {
    const { body, annotations } = opinion;
    let bodyDelta = new Delta(JSON.parse(body));
    if (!annotations) return bodyDelta;
    let annoDelta = new Delta();
    const annoArray = toArray(annotations).sort((a, b) =&gt; {
      if (a.start_idx &lt; b.start_idx) {
        return -1;
      } else if (a.start_idx &gt; b.start_idx) {
        return 1;
      } else {
        return 0;
      }
    });

    let index = 0;

    annoArray.forEach((anno) =&gt; {
      annoDelta.retain(anno.start_idx - index);
      annoDelta.retain(anno.length, { annotation_id: `${anno.id}` });
      index = anno.start_idx + anno.length;

quill-delta

Format for representing rich text documents and changes.

BSD-3-Clause
Latest version published 1 year ago

Package Health Score

76 / 100
Full package analysis