UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

45 lines (44 loc) 1.49 kB
import { printTree } from 'tree-dump/lib/printTree'; import { OverlayPoint } from './OverlayPoint'; export class MarkerOverlayPoint extends OverlayPoint { rga; marker; /** * Hash value of the following text contents, up until the next marker. */ textHash = 0; constructor(rga, id, anchor, marker) { super(rga, id, anchor); this.rga = rga; this.marker = marker; } type() { return this.marker && this.marker.type; } data() { return this.marker && this.marker.data(); } // ---------------------------------------------------------------- Printable toStringName() { return 'MarkerOverlayPoint'; } toStringHeader(tab, lite) { const hash = lite ? '' : `#${this.textHash.toString(36).slice(-4)}`; const tag = lite ? '' : `, type = ${JSON.stringify(this.type())}`; return `${super.toStringHeader(tab, lite)}${lite ? '' : ' '}${hash}${tag}`; } toString(tab = '', lite) { return (this.toStringHeader(tab, lite) + (lite ? '' : printTree(tab, [ (tab) => this.marker.toString(tab), ...this.layers.map((slice) => (tab) => slice.toString(tab)), ...this.markers.map((slice) => (tab) => slice.toString(tab)), ]))); } // ------------------------------------------------------------ HeadlessNode2 p2; l2; r2; }