UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

101 lines (100 loc) 3.46 kB
import { s } from '../../../json-crdt-patch'; import { SliceBehavior } from '../slice/constants'; import { SliceRegistry, SliceRegistryEntry } from './SliceRegistry'; export const createRegistry = () => { const registry = new SliceRegistry(); const undefSchema = s.con(undefined); // --------------------------------------- Inline elements with "One" behavior const i0 = (tag, fromHtml) => { registry.add(new SliceRegistryEntry(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 = s.obj({ href: s.str(''), title: s.str(''), }); registry.add(new SliceRegistryEntry(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 = s.obj({}, { indent: s.con(0), align: s.str('left'), }); const b0 = (tag, container) => { registry.add(new SliceRegistryEntry(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; }; /** * Default annotation type registry. */ export const registry = createRegistry();