UNPKG

@atlaskit/adf-schema

Version:

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

102 lines 2.73 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import { StepMap } from 'prosemirror-transform'; export var TableSideEffectHandler = /*#__PURE__*/function () { function TableSideEffectHandler(tableSideEffect) { _classCallCheck(this, TableSideEffectHandler); if (tableSideEffect) { this.table = tableSideEffect; } } _createClass(TableSideEffectHandler, [{ key: "addTableSideEffect", value: function addTableSideEffect(from, to, node) { this.table = { from: from, to: to, node: node }; } }, { key: "handleAddTable", value: function handleAddTable(tr, isDelete) { if (isDelete || !this.table) { return false; } tr.insert(this.table.from, this.table.node); return true; } }, { key: "handleRemoveTable", value: function handleRemoveTable(tr, tablePos, tableRect, column, isDelete) { if (isDelete && tableRect.map.width === 1 && column === 0) { // Add side effect this.addTableSideEffect(tablePos, tablePos + tableRect.table.nodeSize, tableRect.table.copy(tableRect.table.content)); tr.delete(tablePos, tablePos + tableRect.table.nodeSize); return true; } return false; } }, { key: "getTableMap", value: function getTableMap(isDelete) { if (!this.table) { return; } var _this$table = this.table, from = _this$table.from, to = _this$table.to; if (isDelete) { return new StepMap([from, to - from, 0]); } return new StepMap([from, 0, to - from]); } }, { key: "map", value: function map(mapping) { if (!this.table) { return; } return { from: mapping.map(this.table.from), to: mapping.map(this.table.to), node: this.table.node }; } }, { key: "invert", value: function invert(doc) { if (!this.table) { return; } var tableNode = doc.nodeAt(this.table.from); return { from: this.table.from, to: this.table.from + tableNode.nodeSize, node: tableNode.copy(tableNode.content) }; } }, { key: "toJSON", value: function toJSON() { if (!this.table) { return; } return { from: this.table.from, to: this.table.to, node: this.table.node.toJSON() }; } }], [{ key: "fromJSON", value: function fromJSON(schema, json) { return { from: json.from, to: json.to, node: schema.nodeFromJSON(json.node) }; } }]); return TableSideEffectHandler; }();