UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

20 lines (19 loc) 831 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.step = exports.type = void 0; const json_crdt_patch_1 = require("../../../json-crdt-patch"); const type = (sliceType) => Array.isArray(sliceType) ? json_crdt_patch_1.s.arr(sliceType.map(exports.step)) : json_crdt_patch_1.s.con(sliceType); exports.type = type; const step = (sliceStep) => { if (Array.isArray(sliceStep)) { const tuple = [json_crdt_patch_1.s.con(sliceStep[0])]; const length = sliceStep.length; if (length > 1) tuple.push(json_crdt_patch_1.s.con(+(sliceStep[1] ?? 0))); if (length > 2) tuple.push(json_crdt_patch_1.s.json(sliceStep[2] ?? {})); return json_crdt_patch_1.s.vec(...tuple); } return json_crdt_patch_1.s.con(sliceStep); }; exports.step = step;