How to use the prosemirror-state.Selection.jsonID function in prosemirror-state

To help you get started, we’ve selected a few prosemirror-state 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 ProseMirror / prosemirror-tables / src / cellselection.js View on Github external
static fromJSON(doc, json) {
    return new CellSelection(doc.resolve(json.anchor), doc.resolve(json.head))
  }

  // :: (Node, number, ?number) → CellSelection
  static create(doc, anchorCell, headCell = anchorCell) {
    return new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell))
  }

  getBookmark() { return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos) }
}

CellSelection.prototype.visible = false

Selection.jsonID("cell", CellSelection)

class CellBookmark {
  constructor(anchor, head) {
    this.anchor = anchor
    this.head = head
  }
  map(mapping) {
    return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head))
  }
  resolve(doc) {
    let $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head)
    if ($anchorCell.parent.type.spec.tableRole == "row" &&
        $headCell.parent.type.spec.tableRole == "row" &&
        $anchorCell.index() < $anchorCell.parent.childCount &&
        $headCell.index() < $headCell.parent.childCount &&
        inSameTable($anchorCell, $headCell))
github ifiokjr / remirror / @remirror / core / src / selection / gap-cursor.ts View on Github external
}

  public content() {
    return Slice.empty;
  }

  public getBookmark(): SelectionBookmark {
    return new GapCursorBookmark(this.anchor);
  }

  public toJSON() {
    return { pos: this.head, type: GAP_CURSOR_ID };
  }
}

Selection.jsonID(GAP_CURSOR_ID, GapCursorSelection);

export class GapCursorBookmark implements SelectionBookmark {
  constructor(private readonly pos: number) {}

  public map(mapping: Mapping): SelectionBookmark {
    return new GapCursorBookmark(mapping.map(this.pos));
  }

  public resolve(doc: PMNode): Selection {
    const $pos = doc.resolve(this.pos);
    return GapCursorSelection.valid($pos) ? new GapCursorSelection($pos) : Selection.near($pos);
  }
}

export const isGapCursorSelection = (selection: Selection): selection is GapCursorSelection =>
  selection instanceof GapCursorSelection;