UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

36 lines 1.09 kB
import { NestedTag } from './NestedTag'; import * as schema from './schema'; export class NestedType { slice; constructor(slice) { this.slice = slice; } /** Enforces slice type to be an "arr" of tags. */ asArr() { const { slice } = this; const api = slice.typeApi(); if (api && api.node.name() === 'arr') return api; let type; if (!api) type = [0]; else { type = api.view(); if (!Array.isArray(type)) type = typeof type === 'number' || typeof type === 'string' ? [type] : [0]; } slice.update({ type: schema.type(type) }); return slice.typeApi(); } /** * Nested tag API for nested block types. * * @param index The position of the tag in the type array. If not specified, * returns the last tag (255). Maximum index is 255. * @returns Slice tag API for the given position. */ tag(index = 255) { return new NestedTag(this, index); } } //# sourceMappingURL=NestedType.js.map