json-joy
Version:
Collection of libraries for building collaborative editing apps.
40 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestedType = void 0;
const tslib_1 = require("tslib");
const NestedTag_1 = require("./NestedTag");
const schema = tslib_1.__importStar(require("./schema"));
class NestedType {
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_1.NestedTag(this, index);
}
}
exports.NestedType = NestedType;
//# sourceMappingURL=NestedType.js.map