UNPKG

@atlaskit/adf-schema

Version:

Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs

60 lines 1.83 kB
import { TableSideEffectHandler } from './table'; import { RowsSideEffectHandler } from './rows'; export class SideEffectsHandler { constructor(sideEffects) { this.table = new TableSideEffectHandler(sideEffects && sideEffects.table); this.rows = new RowsSideEffectHandler(sideEffects && sideEffects.rows); } getTableMap(isDelete) { return this.table.getTableMap(isDelete); } map(mapping) { const sideEffects = {}; const tableSideEffect = this.table.map(mapping); const rowsSideEffect = this.rows.map(mapping); if (tableSideEffect) { sideEffects.table = tableSideEffect; } if (rowsSideEffect) { sideEffects.rows = rowsSideEffect; } return sideEffects; } invert(originalDoc, isDelete, map) { const sideEffects = {}; const tableSideEffect = this.table.invert(originalDoc); if (tableSideEffect) { sideEffects.table = tableSideEffect; } const rowsSideEffect = this.rows.invert(originalDoc, isDelete, map); if (rowsSideEffect) { sideEffects.rows = rowsSideEffect; } return sideEffects; } toJSON() { const tableSideEffectJson = this.table.toJSON(); const rowsSideEffectJson = this.rows.toJSON(); if (!tableSideEffectJson && !rowsSideEffectJson) { return; } const sideEffectsJSON = {}; if (tableSideEffectJson) { sideEffectsJSON.table = tableSideEffectJson; } if (rowsSideEffectJson) { sideEffectsJSON.rows = rowsSideEffectJson; } return sideEffectsJSON; } static fromJSON(schema, json) { const sideEffects = {}; if (json.table) { sideEffects.table = TableSideEffectHandler.fromJSON(schema, json.table); } if (json.rows) { sideEffects.rows = RowsSideEffectHandler.fromJSON(schema, json.rows); } return sideEffects; } }