json-joy
Version:
Collection of libraries for building collaborative editing apps.
18 lines • 735 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromJSON = void 0;
const fromJSON = (schema, json, createFragment) => {
const { type, attrs, content, marks, text } = json;
const _marks = Array.isArray(marks)
? marks.map((mark) => schema.mark(mark.type, mark.attrs))
: void 0;
return type === 'text'
? schema.text(typeof text === 'string' ? text : '', _marks)
: schema
.nodeType(type)
.create(attrs, Array.isArray(content)
? createFragment(content.map((val) => (0, exports.fromJSON)(schema, val, createFragment)))
: createFragment(), _marks);
};
exports.fromJSON = fromJSON;
//# sourceMappingURL=util.js.map