UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

105 lines (104 loc) 3.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registry = exports.createRegistry = void 0; const json_crdt_patch_1 = require("../../../json-crdt-patch"); const constants_1 = require("../slice/constants"); const SliceRegistry_1 = require("./SliceRegistry"); const createRegistry = () => { const registry = new SliceRegistry_1.SliceRegistry(); const undefSchema = json_crdt_patch_1.s.con(undefined); // --------------------------------------- Inline elements with "One" behavior const i0 = (tag, fromHtml) => { registry.add(new SliceRegistry_1.SliceRegistryEntry(constants_1.SliceBehavior.One, tag, undefSchema, false, void 0, fromHtml)); }; const i1 = (tag, htmlTags) => { const fromHtml = {}; for (const htmlTag of htmlTags) fromHtml[htmlTag] = () => [tag, null]; i0(tag, fromHtml); }; i1(-4 /* TAG.i */, ['i', 'em']); i1(-3 /* TAG.b */, ['b', 'strong']); i1(-6 /* TAG.s */, ['s', 'strike']); i0(-5 /* TAG.u */); i0(-7 /* TAG.code */); i0(-8 /* TAG.mark */); i0(-19 /* TAG.kbd */); i0(-11 /* TAG.del */); i0(-12 /* TAG.ins */); i0(-13 /* TAG.sup */); i0(-14 /* TAG.sub */); i0(-15 /* TAG.math */); // -------------------------------------- Inline elements with "Many" behavior const aSchema = json_crdt_patch_1.s.obj({ href: json_crdt_patch_1.s.str(''), title: json_crdt_patch_1.s.str(''), }); registry.add(new SliceRegistry_1.SliceRegistryEntry(constants_1.SliceBehavior.Many, -9 /* TAG.a */, aSchema, false, void 0, { a: (jsonml) => { const attr = jsonml[1] || {}; const data = { href: attr.href ?? '', title: attr.title ?? '', }; return [-9 /* TAG.a */, { data, inline: true }]; }, })); // TODO: add more default annotations with "Many" behavior // comment = SliceTypeCon.comment, // font = SliceTypeCon.font, // col = SliceTypeCon.col, // bg = SliceTypeCon.bg, // hidden = SliceTypeCon.hidden, // footnote = SliceTypeCon.footnote, // ref = SliceTypeCon.ref, // iaside = SliceTypeCon.iaside, // iembed = SliceTypeCon.iembed, // bookmark = SliceTypeCon.bookmark, // ------------------------------------- Block elements with "Marker" behavior const commonBlockSchema = json_crdt_patch_1.s.obj({}, { indent: json_crdt_patch_1.s.con(0), align: json_crdt_patch_1.s.str('left'), }); const b0 = (tag, container) => { registry.add(new SliceRegistry_1.SliceRegistryEntry(constants_1.SliceBehavior.Marker, tag, commonBlockSchema, container)); }; b0(0 /* TAG.p */, false); b0(1 /* TAG.blockquote */, true); b0(2 /* TAG.codeblock */, false); b0(3 /* TAG.pre */, false); b0(4 /* TAG.ul */, true); b0(5 /* TAG.ol */, true); b0(6 /* TAG.tl */, true); b0(5 /* TAG.ol */, true); b0(7 /* TAG.li */, true); b0(8 /* TAG.h1 */, false); b0(9 /* TAG.h2 */, false); b0(10 /* TAG.h3 */, false); b0(11 /* TAG.h4 */, false); b0(12 /* TAG.h5 */, false); b0(13 /* TAG.h6 */, false); b0(14 /* TAG.title */, false); b0(15 /* TAG.subtitle */, false); // b0(TAG.br, false); // b0(TAG.nl, false); // b0(TAG.hr, false); // b0(TAG.page, false); // b0(TAG.aside, true); // b0(TAG.embed, false); // b0(TAG.column, true); // b0(TAG.contents, true); // b0(TAG.table, true); // b0(TAG.row, true); // b0(TAG.cell, true); // b0(TAG.collapselist, true); // b0(TAG.collapse, true); // b0(TAG.note, true); // b0(TAG.mathblock, false); return registry; }; exports.createRegistry = createRegistry; /** * Default annotation type registry. */ exports.registry = (0, exports.createRegistry)();