UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

47 lines (46 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LeafBlock = void 0; const printTree_1 = require("tree-dump/lib/printTree"); const Block_1 = require("./Block"); class LeafBlock extends Block_1.Block { text() { let str = ''; for (let iterator = this.texts0(), inline = iterator(); inline; inline = iterator()) str += inline.text(); return str; } isLeaf() { return true; } // ------------------------------------------------------------------- export toJson() { const data = this.attr(); const attr = data !== void 0 ? { data } : null; const node = [this.tag(), attr]; for (const inline of this.texts()) { const child = inline.toJson(); if (child) node.push(child); } return node; } // ---------------------------------------------------------------- Printable toStringName() { return 'LeafBlock'; } toString(tab = '') { const header = this.toStringHeader(); const texts = [...this.texts()]; const hasSlices = !!texts.length; return (header + (0, printTree_1.printTree)(tab, [ this.marker ? (tab) => this.marker.toString(tab) : null, !hasSlices ? null : (tab) => 'nodes' + (0, printTree_1.printTree)(tab, texts.map((inline) => (tab) => inline.toString(tab))), ])); } } exports.LeafBlock = LeafBlock;