How to use the mobiledoc-kit/utils/assert function in mobiledoc-kit

To help you get started, we’ve selected a few mobiledoc-kit 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 bustle / mobiledoc-kit / src / js / editor / post / post-inserter.js View on Github external
visit(node) {
    let method = node.type;
    assert(`Cannot visit node of type ${node.type}`, !!this[method]);
    this[method](node);
  }
github bustle / mobiledoc-kit / src / js / parsers / mobiledoc / 0-3-1.js View on Github external
getAtomTypeFromIndex(index) {
    const atomType = this.atomTypes[index];
    assert(`No atom definition found at index ${index}`, !!atomType);
    return atomType;
  }
github bustle / mobiledoc-kit / src / js / editor / post / post-inserter.js View on Github external
_breakNestedAtCursor() {
    assert('Cannot call _breakNestedAtCursor if not nested', this._isNested);

    let parent = this.cursorSection.parent;
    let cursorAtEndOfList = this.cursorPosition.isEqual(parent.tailPosition());

    if (cursorAtEndOfList) {
      let blank = this.builder.createMarkupSection();
      this._insertSectionAfter(blank, parent);
    } else {
      let [, blank,] = this._breakListAtCursor();
      this.cursorPosition = blank.tailPosition();
    }
  }
github bustle / mobiledoc-kit / src / js / parsers / mobiledoc / 0-3.js View on Github external
buildMarkerType(type, value) {
    switch (type) {
      case MOBILEDOC_MARKUP_MARKER_TYPE:
        return this.builder.createMarker(value, this.markups.slice());
      case MOBILEDOC_ATOM_MARKER_TYPE: {
        const [atomName, atomValue, atomPayload] = this.getAtomTypeFromIndex(value);
        return this.builder.createAtom(atomName, atomValue, atomPayload, this.markups.slice());
      }
      default:
        assert(`Unexpected marker type ${type}`, false);
    }
  }
}
github bustle / mobiledoc-kit / src / js / editor / post / post-inserter.js View on Github external
_insertLeafSection(section) {
    assert('Can only _insertLeafSection when cursor is at end of section',
           this.cursorPosition.isTail());

    this._hasInsertedFirstLeafSection = true;
    section = section.clone();

    if (this.cursorSection.isBlank) {
      assert('Cannot insert leaf non-markerable section when cursor is nested',
             !(section.isMarkerable && this._isNested));
      this._replaceSection(this.cursorSection, [section]);
    } else if (this.cursorSection.next && this.cursorSection.next.isBlank) {
      this._replaceSection(this.cursorSection.next, [section]);
    } else {
      let reference = this.cursorSection.next;
      this._insertSectionBefore(section, reference);
    }
  }
github bustle / mobiledoc-kit / src / js / utils / cursor / range.js View on Github external
move(direction) {
    assert(`Must pass DIRECTION.FORWARD (${DIRECTION.FORWARD}) or DIRECTION.BACKWARD (${DIRECTION.BACKWARD}) to Range#move`,
           direction === DIRECTION.FORWARD || direction === DIRECTION.BACKWARD);

    let { focusedPosition, isCollapsed } = this;

    if (isCollapsed) {
      return new Range(focusedPosition.move(direction));
    } else {
      return this._collapse(direction);
    }
  }
github bustle / mobiledoc-kit / src / js / parsers / mobiledoc / 0-3-1.js View on Github external
buildMarkerType(type, value) {
    switch (type) {
      case MOBILEDOC_MARKUP_MARKER_TYPE:
        return this.builder.createMarker(value, this.markups.slice());
      case MOBILEDOC_ATOM_MARKER_TYPE: {
        const [atomName, atomValue, atomPayload] = this.getAtomTypeFromIndex(value);
        return this.builder.createAtom(atomName, atomValue, atomPayload, this.markups.slice());
      }
      default:
        assert(`Unexpected marker type ${type}`, false);
    }
  }
}
github bustle / mobiledoc-kit / src / js / editor / post / post-inserter.js View on Github external
_insertLeafSection(section) {
    assert('Can only _insertLeafSection when cursor is at end of section',
           this.cursorPosition.isTail());

    this._hasInsertedFirstLeafSection = true;
    section = section.clone();

    if (this.cursorSection.isBlank) {
      assert('Cannot insert leaf non-markerable section when cursor is nested',
             !(section.isMarkerable && this._isNested));
      this._replaceSection(this.cursorSection, [section]);
    } else if (this.cursorSection.next && this.cursorSection.next.isBlank) {
      this._replaceSection(this.cursorSection.next, [section]);
    } else {
      let reference = this.cursorSection.next;
      this._insertSectionBefore(section, reference);
    }
  }
}
github bustle / mobiledoc-kit / src / js / editor / post / post-inserter.js View on Github external
_mergeSection(section) {
    assert('Can only merge markerable sections',
           this._isMarkerable && section.isMarkerable);
    this._hasInsertedFirstLeafSection = true;

    let markers = section.markers.map(m => m.clone());
    let position = this.postEditor.insertMarkers(this.cursorPosition, markers);

    this.cursorPosition = position;
  }
github bustle / mobiledoc-kit / src / js / editor / post / post-inserter.js View on Github external
_insertSectionAfter(section, parent) {
    assert('Cannot _insertSectionAfter nested section', !parent.isNested);
    let reference = parent.next;
    let collection = this._post.sections;
    this.postEditor.insertSectionBefore(collection, section, reference);
    this.cursorPosition = section.tailPosition();
  }