{"version":3,"file":"vendors-97350007.740bf39458569ccd8477.bundle.js","mappings":"AAOA","sources":["webpack://lernplattform-admin-frontend/../common/node_modules/prosemirror-tables/dist/index.js","webpack://lernplattform-admin-frontend/../common/node_modules/prosemirror-transform/dist/index.js"],"sourcesContent":["import { NodeSelection, Plugin, PluginKey, Selection, SelectionRange, TextSelection } from \"prosemirror-state\";\nimport { Fragment, Slice } from \"prosemirror-model\";\nimport { Decoration, DecorationSet } from \"prosemirror-view\";\nimport { keydownHandler } from \"prosemirror-keymap\";\nimport { Transform } from \"prosemirror-transform\";\n\n//#region src/tablemap.ts\nlet readFromCache;\nlet addToCache;\nif (typeof WeakMap != \"undefined\") {\n\tlet cache = /* @__PURE__ */ new WeakMap();\n\treadFromCache = (key) => cache.get(key);\n\taddToCache = (key, value) => {\n\t\tcache.set(key, value);\n\t\treturn value;\n\t};\n} else {\n\tconst cache = [];\n\tconst cacheSize = 10;\n\tlet cachePos = 0;\n\treadFromCache = (key) => {\n\t\tfor (let i = 0; i < cache.length; i += 2) if (cache[i] == key) return cache[i + 1];\n\t};\n\taddToCache = (key, value) => {\n\t\tif (cachePos == cacheSize) cachePos = 0;\n\t\tcache[cachePos++] = key;\n\t\treturn cache[cachePos++] = value;\n\t};\n}\n/**\n* A table map describes the structure of a given table. To avoid\n* recomputing them all the time, they are cached per table node. To\n* be able to do that, positions saved in the map are relative to the\n* start of the table, rather than the start of the document.\n*\n* @public\n*/\nvar TableMap = class {\n\tconstructor(width, height, map, problems) {\n\t\tthis.width = width;\n\t\tthis.height = height;\n\t\tthis.map = map;\n\t\tthis.problems = problems;\n\t}\n\tfindCell(pos) {\n\t\tfor (let i = 0; i < this.map.length; i++) {\n\t\t\tconst curPos = this.map[i];\n\t\t\tif (curPos != pos) continue;\n\t\t\tconst left = i % this.width;\n\t\t\tconst top = i / this.width | 0;\n\t\t\tlet right = left + 1;\n\t\t\tlet bottom = top + 1;\n\t\t\tfor (let j = 1; right < this.width && this.map[i + j] == curPos; j++) right++;\n\t\t\tfor (let j = 1; bottom < this.height && this.map[i + this.width * j] == curPos; j++) bottom++;\n\t\t\treturn {\n\t\t\t\tleft,\n\t\t\t\ttop,\n\t\t\t\tright,\n\t\t\t\tbottom\n\t\t\t};\n\t\t}\n\t\tthrow new RangeError(`No cell with offset ${pos} found`);\n\t}\n\tcolCount(pos) {\n\t\tfor (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width;\n\t\tthrow new RangeError(`No cell with offset ${pos} found`);\n\t}\n\tnextCell(pos, axis, dir) {\n\t\tconst { left, right, top, bottom } = this.findCell(pos);\n\t\tif (axis == \"horiz\") {\n\t\t\tif (dir < 0 ? left == 0 : right == this.width) return null;\n\t\t\treturn this.map[top * this.width + (dir < 0 ? left - 1 : right)];\n\t\t} else {\n\t\t\tif (dir < 0 ? top == 0 : bottom == this.height) return null;\n\t\t\treturn this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];\n\t\t}\n\t}\n\trectBetween(a, b) {\n\t\tconst { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a);\n\t\tconst { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b);\n\t\treturn {\n\t\t\tleft: Math.min(leftA, leftB),\n\t\t\ttop: Math.min(topA, topB),\n\t\t\tright: Math.max(rightA, rightB),\n\t\t\tbottom: Math.max(bottomA, bottomB)\n\t\t};\n\t}\n\tcellsInRect(rect) {\n\t\tconst result = [];\n\t\tconst seen = {};\n\t\tfor (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {\n\t\t\tconst index = row * this.width + col;\n\t\t\tconst pos = this.map[index];\n\t\t\tif (seen[pos]) continue;\n\t\t\tseen[pos] = true;\n\t\t\tif (col == rect.left && col && this.map[index - 1] == pos || row == rect.top && row && this.map[index - this.width] == pos) continue;\n\t\t\tresult.push(pos);\n\t\t}\n\t\treturn result;\n\t}\n\tpositionAt(row, col, table) {\n\t\tfor (let i = 0, rowStart = 0;; i++) {\n\t\t\tconst rowEnd = rowStart + table.child(i).nodeSize;\n\t\t\tif (i == row) {\n\t\t\t\tlet index = col + row * this.width;\n\t\t\t\tconst rowEndIndex = (row + 1) * this.width;\n\t\t\t\twhile (index < rowEndIndex && this.map[index] < rowStart) index++;\n\t\t\t\treturn index == rowEndIndex ? rowEnd - 1 : this.map[index];\n\t\t\t}\n\t\t\trowStart = rowEnd;\n\t\t}\n\t}\n\tstatic get(table) {\n\t\treturn readFromCache(table) || addToCache(table, computeMap(table));\n\t}\n};\nfunction computeMap(table) {\n\tif (table.type.spec.tableRole != \"table\") throw new RangeError(\"Not a table node: \" + table.type.name);\n\tconst width = findWidth(table), height = table.childCount;\n\tconst map = [];\n\tlet mapPos = 0;\n\tlet problems = null;\n\tconst colWidths = [];\n\tfor (let i = 0, e = width * height; i < e; i++) map[i] = 0;\n\tfor (let row = 0, pos = 0; row < height; row++) {\n\t\tconst rowNode = table.child(row);\n\t\tpos++;\n\t\tfor (let i = 0;; i++) {\n\t\t\twhile (mapPos < map.length && map[mapPos] != 0) mapPos++;\n\t\t\tif (i == rowNode.childCount) break;\n\t\t\tconst cellNode = rowNode.child(i);\n\t\t\tconst { colspan, rowspan, colwidth } = cellNode.attrs;\n\t\t\tfor (let h = 0; h < rowspan; h++) {\n\t\t\t\tif (h + row >= height) {\n\t\t\t\t\t(problems || (problems = [])).push({\n\t\t\t\t\t\ttype: \"overlong_rowspan\",\n\t\t\t\t\t\tpos,\n\t\t\t\t\t\tn: rowspan - h\n\t\t\t\t\t});\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tconst start = mapPos + h * width;\n\t\t\t\tfor (let w = 0; w < colspan; w++) {\n\t\t\t\t\tif (map[start + w] == 0) map[start + w] = pos;\n\t\t\t\t\telse (problems || (problems = [])).push({\n\t\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\t\trow,\n\t\t\t\t\t\tpos,\n\t\t\t\t\t\tn: colspan - w\n\t\t\t\t\t});\n\t\t\t\t\tconst colW = colwidth && colwidth[w];\n\t\t\t\t\tif (colW) {\n\t\t\t\t\t\tconst widthIndex = (start + w) % width * 2, prev = colWidths[widthIndex];\n\t\t\t\t\t\tif (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {\n\t\t\t\t\t\t\tcolWidths[widthIndex] = colW;\n\t\t\t\t\t\t\tcolWidths[widthIndex + 1] = 1;\n\t\t\t\t\t\t} else if (prev == colW) colWidths[widthIndex + 1]++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tmapPos += colspan;\n\t\t\tpos += cellNode.nodeSize;\n\t\t}\n\t\tconst expectedPos = (row + 1) * width;\n\t\tlet missing = 0;\n\t\twhile (mapPos < expectedPos) if (map[mapPos++] == 0) missing++;\n\t\tif (missing) (problems || (problems = [])).push({\n\t\t\ttype: \"missing\",\n\t\t\trow,\n\t\t\tn: missing\n\t\t});\n\t\tpos++;\n\t}\n\tif (width === 0 || height === 0) (problems || (problems = [])).push({ type: \"zero_sized\" });\n\tconst tableMap = new TableMap(width, height, map, problems);\n\tlet badWidths = false;\n\tfor (let i = 0; !badWidths && i < colWidths.length; i += 2) if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;\n\tif (badWidths) findBadColWidths(tableMap, colWidths, table);\n\treturn tableMap;\n}\nfunction findWidth(table) {\n\tlet width = -1;\n\tlet hasRowSpan = false;\n\tfor (let row = 0; row < table.childCount; row++) {\n\t\tconst rowNode = table.child(row);\n\t\tlet rowWidth = 0;\n\t\tif (hasRowSpan) for (let j = 0; j < row; j++) {\n\t\t\tconst prevRow = table.child(j);\n\t\t\tfor (let i = 0; i < prevRow.childCount; i++) {\n\t\t\t\tconst cell = prevRow.child(i);\n\t\t\t\tif (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;\n\t\t\t}\n\t\t}\n\t\tfor (let i = 0; i < rowNode.childCount; i++) {\n\t\t\tconst cell = rowNode.child(i);\n\t\t\trowWidth += cell.attrs.colspan;\n\t\t\tif (cell.attrs.rowspan > 1) hasRowSpan = true;\n\t\t}\n\t\tif (width == -1) width = rowWidth;\n\t\telse if (width != rowWidth) width = Math.max(width, rowWidth);\n\t}\n\treturn width;\n}\nfunction findBadColWidths(map, colWidths, table) {\n\tif (!map.problems) map.problems = [];\n\tconst seen = {};\n\tfor (let i = 0; i < map.map.length; i++) {\n\t\tconst pos = map.map[i];\n\t\tif (seen[pos]) continue;\n\t\tseen[pos] = true;\n\t\tconst node = table.nodeAt(pos);\n\t\tif (!node) throw new RangeError(`No cell with offset ${pos} found`);\n\t\tlet updated = null;\n\t\tconst attrs = node.attrs;\n\t\tfor (let j = 0; j < attrs.colspan; j++) {\n\t\t\tconst colWidth = colWidths[(i + j) % map.width * 2];\n\t\t\tif (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j] = colWidth;\n\t\t}\n\t\tif (updated) map.problems.unshift({\n\t\t\ttype: \"colwidth mismatch\",\n\t\t\tpos,\n\t\t\tcolwidth: updated\n\t\t});\n\t}\n}\nfunction freshColWidth(attrs) {\n\tif (attrs.colwidth) return attrs.colwidth.slice();\n\tconst result = [];\n\tfor (let i = 0; i < attrs.colspan; i++) result.push(0);\n\treturn result;\n}\n\n//#endregion\n//#region src/schema.ts\nfunction getCellAttrs(dom, extraAttrs) {\n\tif (typeof dom === \"string\") return {};\n\tconst widthAttr = dom.getAttribute(\"data-colwidth\");\n\tconst widths = widthAttr && /^\\d+(,\\d+)*$/.test(widthAttr) ? widthAttr.split(\",\").map((s) => Number(s)) : null;\n\tconst colspan = Number(dom.getAttribute(\"colspan\") || 1);\n\tconst result = {\n\t\tcolspan,\n\t\trowspan: Number(dom.getAttribute(\"rowspan\") || 1),\n\t\tcolwidth: widths && widths.length == colspan ? widths : null\n\t};\n\tfor (const prop in extraAttrs) {\n\t\tconst getter = extraAttrs[prop].getFromDOM;\n\t\tconst value = getter && getter(dom);\n\t\tif (value != null) result[prop] = value;\n\t}\n\treturn result;\n}\nfunction setCellAttrs(node, extraAttrs) {\n\tconst attrs = {};\n\tif (node.attrs.colspan != 1) attrs.colspan = node.attrs.colspan;\n\tif (node.attrs.rowspan != 1) attrs.rowspan = node.attrs.rowspan;\n\tif (node.attrs.colwidth) attrs[\"data-colwidth\"] = node.attrs.colwidth.join(\",\");\n\tfor (const prop in extraAttrs) {\n\t\tconst setter = extraAttrs[prop].setDOMAttr;\n\t\tif (setter) setter(node.attrs[prop], attrs);\n\t}\n\treturn attrs;\n}\nfunction validateColwidth(value) {\n\tif (value === null) return;\n\tif (!Array.isArray(value)) throw new TypeError(\"colwidth must be null or an array\");\n\tfor (const item of value) if (typeof item !== \"number\") throw new TypeError(\"colwidth must be null or an array of numbers\");\n}\n/**\n* This function creates a set of [node\n* specs](http://prosemirror.net/docs/ref/#model.SchemaSpec.nodes) for\n* `table`, `table_row`, and `table_cell` nodes types as used by this\n* module. The result can then be added to the set of nodes when\n* creating a schema.\n*\n* @public\n*/\nfunction tableNodes(options) {\n\tconst extraAttrs = options.cellAttributes || {};\n\tconst cellAttrs = {\n\t\tcolspan: {\n\t\t\tdefault: 1,\n\t\t\tvalidate: \"number\"\n\t\t},\n\t\trowspan: {\n\t\t\tdefault: 1,\n\t\t\tvalidate: \"number\"\n\t\t},\n\t\tcolwidth: {\n\t\t\tdefault: null,\n\t\t\tvalidate: validateColwidth\n\t\t}\n\t};\n\tfor (const prop in extraAttrs) cellAttrs[prop] = {\n\t\tdefault: extraAttrs[prop].default,\n\t\tvalidate: extraAttrs[prop].validate\n\t};\n\treturn {\n\t\ttable: {\n\t\t\tcontent: \"table_row+\",\n\t\t\ttableRole: \"table\",\n\t\t\tisolating: true,\n\t\t\tgroup: options.tableGroup,\n\t\t\tparseDOM: [{ tag: \"table\" }],\n\t\t\ttoDOM() {\n\t\t\t\treturn [\"table\", [\"tbody\", 0]];\n\t\t\t}\n\t\t},\n\t\ttable_row: {\n\t\t\tcontent: \"(table_cell | table_header)*\",\n\t\t\ttableRole: \"row\",\n\t\t\tparseDOM: [{ tag: \"tr\" }],\n\t\t\ttoDOM() {\n\t\t\t\treturn [\"tr\", 0];\n\t\t\t}\n\t\t},\n\t\ttable_cell: {\n\t\t\tcontent: options.cellContent,\n\t\t\tattrs: cellAttrs,\n\t\t\ttableRole: \"cell\",\n\t\t\tisolating: true,\n\t\t\tparseDOM: [{\n\t\t\t\ttag: \"td\",\n\t\t\t\tgetAttrs: (dom) => getCellAttrs(dom, extraAttrs)\n\t\t\t}],\n\t\t\ttoDOM(node) {\n\t\t\t\treturn [\n\t\t\t\t\t\"td\",\n\t\t\t\t\tsetCellAttrs(node, extraAttrs),\n\t\t\t\t\t0\n\t\t\t\t];\n\t\t\t}\n\t\t},\n\t\ttable_header: {\n\t\t\tcontent: options.cellContent,\n\t\t\tattrs: cellAttrs,\n\t\t\ttableRole: \"header_cell\",\n\t\t\tisolating: true,\n\t\t\tparseDOM: [{\n\t\t\t\ttag: \"th\",\n\t\t\t\tgetAttrs: (dom) => getCellAttrs(dom, extraAttrs)\n\t\t\t}],\n\t\t\ttoDOM(node) {\n\t\t\t\treturn [\n\t\t\t\t\t\"th\",\n\t\t\t\t\tsetCellAttrs(node, extraAttrs),\n\t\t\t\t\t0\n\t\t\t\t];\n\t\t\t}\n\t\t}\n\t};\n}\n/**\n* @public\n*/\nfunction tableNodeTypes(schema) {\n\tlet result = schema.cached.tableNodeTypes;\n\tif (!result) {\n\t\tresult = schema.cached.tableNodeTypes = {};\n\t\tfor (const name in schema.nodes) {\n\t\t\tconst type = schema.nodes[name], role = type.spec.tableRole;\n\t\t\tif (role) result[role] = type;\n\t\t}\n\t}\n\treturn result;\n}\n\n//#endregion\n//#region src/util.ts\n/**\n* @public\n*/\nconst tableEditingKey = new PluginKey(\"selectingCells\");\n/**\n* @public\n*/\nfunction cellAround($pos) {\n\tfor (let d = $pos.depth - 1; d > 0; d--) if ($pos.node(d).type.spec.tableRole == \"row\") return $pos.node(0).resolve($pos.before(d + 1));\n\treturn null;\n}\nfunction cellWrapping($pos) {\n\tfor (let d = $pos.depth; d > 0; d--) {\n\t\tconst role = $pos.node(d).type.spec.tableRole;\n\t\tif (role === \"cell\" || role === \"header_cell\") return $pos.node(d);\n\t}\n\treturn null;\n}\n/**\n* @public\n*/\nfunction isInTable(state) {\n\tconst $head = state.selection.$head;\n\tfor (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec.tableRole == \"row\") return true;\n\treturn false;\n}\n/**\n* @internal\n*/\nfunction selectionCell(state) {\n\tconst sel = state.selection;\n\tif (\"$anchorCell\" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;\n\telse if (\"node\" in sel && sel.node && sel.node.type.spec.tableRole == \"cell\") return sel.$anchor;\n\tconst $cell = cellAround(sel.$head) || cellNear(sel.$head);\n\tif ($cell) return $cell;\n\tthrow new RangeError(`No cell found around position ${sel.head}`);\n}\n/**\n* @public\n*/\nfunction cellNear($pos) {\n\tfor (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {\n\t\tconst role = after.type.spec.tableRole;\n\t\tif (role == \"cell\" || role == \"header_cell\") return $pos.doc.resolve(pos);\n\t}\n\tfor (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {\n\t\tconst role = before.type.spec.tableRole;\n\t\tif (role == \"cell\" || role == \"header_cell\") return $pos.doc.resolve(pos - before.nodeSize);\n\t}\n}\n/**\n* @public\n*/\nfunction pointsAtCell($pos) {\n\treturn $pos.parent.type.spec.tableRole == \"row\" && !!$pos.nodeAfter;\n}\n/**\n* @public\n*/\nfunction moveCellForward($pos) {\n\treturn $pos.node(0).resolve($pos.pos + $pos.nodeAfter.nodeSize);\n}\n/**\n* @internal\n*/\nfunction inSameTable($cellA, $cellB) {\n\treturn $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1);\n}\n/**\n* @public\n*/\nfunction findCell($pos) {\n\treturn TableMap.get($pos.node(-1)).findCell($pos.pos - $pos.start(-1));\n}\n/**\n* @public\n*/\nfunction colCount($pos) {\n\treturn TableMap.get($pos.node(-1)).colCount($pos.pos - $pos.start(-1));\n}\n/**\n* @public\n*/\nfunction nextCell($pos, axis, dir) {\n\tconst table = $pos.node(-1);\n\tconst map = TableMap.get(table);\n\tconst tableStart = $pos.start(-1);\n\tconst moved = map.nextCell($pos.pos - tableStart, axis, dir);\n\treturn moved == null ? null : $pos.node(0).resolve(tableStart + moved);\n}\n/**\n* @public\n*/\nfunction removeColSpan(attrs, pos, n = 1) {\n\tconst result = {\n\t\t...attrs,\n\t\tcolspan: attrs.colspan - n\n\t};\n\tif (result.colwidth) {\n\t\tresult.colwidth = result.colwidth.slice();\n\t\tresult.colwidth.splice(pos, n);\n\t\tif (!result.colwidth.some((w) => w > 0)) result.colwidth = null;\n\t}\n\treturn result;\n}\n/**\n* @public\n*/\nfunction addColSpan(attrs, pos, n = 1) {\n\tconst result = {\n\t\t...attrs,\n\t\tcolspan: attrs.colspan + n\n\t};\n\tif (result.colwidth) {\n\t\tresult.colwidth = result.colwidth.slice();\n\t\tfor (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);\n\t}\n\treturn result;\n}\n/**\n* @public\n*/\nfunction columnIsHeader(map, table, col) {\n\tconst headerCell = tableNodeTypes(table.type.schema).header_cell;\n\tfor (let row = 0; row < map.height; row++) if (table.nodeAt(map.map[col + row * map.width]).type != headerCell) return false;\n\treturn true;\n}\n\n//#endregion\n//#region src/cellselection.ts\n/**\n* A [`Selection`](http://prosemirror.net/docs/ref/#state.Selection)\n* subclass that represents a cell selection spanning part of a table.\n* With the plugin enabled, these will be created when the user\n* selects across cells, and will be drawn by giving selected cells a\n* `selectedCell` CSS class.\n*\n* @public\n*/\nvar CellSelection = class CellSelection extends Selection {\n\tconstructor($anchorCell, $headCell = $anchorCell) {\n\t\tconst table = $anchorCell.node(-1);\n\t\tconst map = TableMap.get(table);\n\t\tconst tableStart = $anchorCell.start(-1);\n\t\tconst rect = map.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart);\n\t\tconst doc = $anchorCell.node(0);\n\t\tconst cells = map.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);\n\t\tcells.unshift($headCell.pos - tableStart);\n\t\tconst ranges = cells.map((pos) => {\n\t\t\tconst cell = table.nodeAt(pos);\n\t\t\tif (!cell) throw new RangeError(`No cell with offset ${pos} found`);\n\t\t\tconst from = tableStart + pos + 1;\n\t\t\treturn new SelectionRange(doc.resolve(from), doc.resolve(from + cell.content.size));\n\t\t});\n\t\tsuper(ranges[0].$from, ranges[0].$to, ranges);\n\t\tthis.$anchorCell = $anchorCell;\n\t\tthis.$headCell = $headCell;\n\t}\n\tmap(doc, mapping) {\n\t\tconst $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));\n\t\tconst $headCell = doc.resolve(mapping.map(this.$headCell.pos));\n\t\tif (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {\n\t\t\tconst tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);\n\t\t\tif (tableChanged && this.isRowSelection()) return CellSelection.rowSelection($anchorCell, $headCell);\n\t\t\telse if (tableChanged && this.isColSelection()) return CellSelection.colSelection($anchorCell, $headCell);\n\t\t\telse return new CellSelection($anchorCell, $headCell);\n\t\t}\n\t\treturn TextSelection.between($anchorCell, $headCell);\n\t}\n\tcontent() {\n\t\tconst table = this.$anchorCell.node(-1);\n\t\tconst map = TableMap.get(table);\n\t\tconst tableStart = this.$anchorCell.start(-1);\n\t\tconst rect = map.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart);\n\t\tconst seen = {};\n\t\tconst rows = [];\n\t\tfor (let row = rect.top; row < rect.bottom; row++) {\n\t\t\tconst rowContent = [];\n\t\t\tfor (let index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {\n\t\t\t\tconst pos = map.map[index];\n\t\t\t\tif (seen[pos]) continue;\n\t\t\t\tseen[pos] = true;\n\t\t\t\tconst cellRect = map.findCell(pos);\n\t\t\t\tlet cell = table.nodeAt(pos);\n\t\t\t\tif (!cell) throw new RangeError(`No cell with offset ${pos} found`);\n\t\t\t\tconst extraLeft = rect.left - cellRect.left;\n\t\t\t\tconst extraRight = cellRect.right - rect.right;\n\t\t\t\tif (extraLeft > 0 || extraRight > 0) {\n\t\t\t\t\tlet attrs = cell.attrs;\n\t\t\t\t\tif (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft);\n\t\t\t\t\tif (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight);\n\t\t\t\t\tif (cellRect.left < rect.left) {\n\t\t\t\t\t\tcell = cell.type.createAndFill(attrs);\n\t\t\t\t\t\tif (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`);\n\t\t\t\t\t} else cell = cell.type.create(attrs, cell.content);\n\t\t\t\t}\n\t\t\t\tif (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {\n\t\t\t\t\tconst attrs = {\n\t\t\t\t\t\t...cell.attrs,\n\t\t\t\t\t\trowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)\n\t\t\t\t\t};\n\t\t\t\t\tif (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs);\n\t\t\t\t\telse cell = cell.type.create(attrs, cell.content);\n\t\t\t\t}\n\t\t\t\trowContent.push(cell);\n\t\t\t}\n\t\t\trows.push(table.child(row).copy(Fragment.from(rowContent)));\n\t\t}\n\t\tconst fragment = this.isColSelection() && this.isRowSelection() ? table : rows;\n\t\treturn new Slice(Fragment.from(fragment), 1, 1);\n\t}\n\treplace(tr, content = Slice.empty) {\n\t\tconst mapFrom = tr.steps.length, ranges = this.ranges;\n\t\tfor (let i = 0; i < ranges.length; i++) {\n\t\t\tconst { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);\n\t\t\ttr.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);\n\t\t}\n\t\tconst sel = Selection.findFrom(tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1);\n\t\tif (sel) tr.setSelection(sel);\n\t}\n\treplaceWith(tr, node) {\n\t\tthis.replace(tr, new Slice(Fragment.from(node), 0, 0));\n\t}\n\tforEachCell(f) {\n\t\tconst table = this.$anchorCell.node(-1);\n\t\tconst map = TableMap.get(table);\n\t\tconst tableStart = this.$anchorCell.start(-1);\n\t\tconst cells = map.cellsInRect(map.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart));\n\t\tfor (let i = 0; i < cells.length; i++) f(table.nodeAt(cells[i]), tableStart + cells[i]);\n\t}\n\tisColSelection() {\n\t\tconst anchorTop = this.$anchorCell.index(-1);\n\t\tconst headTop = this.$headCell.index(-1);\n\t\tif (Math.min(anchorTop, headTop) > 0) return false;\n\t\tconst anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;\n\t\tconst headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;\n\t\treturn Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;\n\t}\n\tstatic colSelection($anchorCell, $headCell = $anchorCell) {\n\t\tconst table = $anchorCell.node(-1);\n\t\tconst map = TableMap.get(table);\n\t\tconst tableStart = $anchorCell.start(-1);\n\t\tconst anchorRect = map.findCell($anchorCell.pos - tableStart);\n\t\tconst headRect = map.findCell($headCell.pos - tableStart);\n\t\tconst doc = $anchorCell.node(0);\n\t\tif (anchorRect.top <= headRect.top) {\n\t\t\tif (anchorRect.top > 0) $anchorCell = doc.resolve(tableStart + map.map[anchorRect.left]);\n\t\t\tif (headRect.bottom < map.height) $headCell = doc.resolve(tableStart + map.map[map.width * (map.height - 1) + headRect.right - 1]);\n\t\t} else {\n\t\t\tif (headRect.top > 0) $headCell = doc.resolve(tableStart + map.map[headRect.left]);\n\t\t\tif (anchorRect.bottom < map.height) $anchorCell = doc.resolve(tableStart + map.map[map.width * (map.height - 1) + anchorRect.right - 1]);\n\t\t}\n\t\treturn new CellSelection($anchorCell, $headCell);\n\t}\n\tisRowSelection() {\n\t\tconst table = this.$anchorCell.node(-1);\n\t\tconst map = TableMap.get(table);\n\t\tconst tableStart = this.$anchorCell.start(-1);\n\t\tconst anchorLeft = map.colCount(this.$anchorCell.pos - tableStart);\n\t\tconst headLeft = map.colCount(this.$headCell.pos - tableStart);\n\t\tif (Math.min(anchorLeft, headLeft) > 0) return false;\n\t\tconst anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;\n\t\tconst headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;\n\t\treturn Math.max(anchorRight, headRight) == map.width;\n\t}\n\teq(other) {\n\t\treturn other instanceof CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;\n\t}\n\tstatic rowSelection($anchorCell, $headCell = $anchorCell) {\n\t\tconst table = $anchorCell.node(-1);\n\t\tconst map = TableMap.get(table);\n\t\tconst tableStart = $anchorCell.start(-1);\n\t\tconst anchorRect = map.findCell($anchorCell.pos - tableStart);\n\t\tconst headRect = map.findCell($headCell.pos - tableStart);\n\t\tconst doc = $anchorCell.node(0);\n\t\tif (anchorRect.left <= headRect.left) {\n\t\t\tif (anchorRect.left > 0) $anchorCell = doc.resolve(tableStart + map.map[anchorRect.top * map.width]);\n\t\t\tif (headRect.right < map.width) $headCell = doc.resolve(tableStart + map.map[map.width * (headRect.top + 1) - 1]);\n\t\t} else {\n\t\t\tif (headRect.left > 0) $headCell = doc.resolve(tableStart + map.map[headRect.top * map.width]);\n\t\t\tif (anchorRect.right < map.width) $anchorCell = doc.resolve(tableStart + map.map[map.width * (anchorRect.top + 1) - 1]);\n\t\t}\n\t\treturn new CellSelection($anchorCell, $headCell);\n\t}\n\ttoJSON() {\n\t\treturn {\n\t\t\ttype: \"cell\",\n\t\t\tanchor: this.$anchorCell.pos,\n\t\t\thead: this.$headCell.pos\n\t\t};\n\t}\n\tstatic fromJSON(doc, json) {\n\t\treturn new CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));\n\t}\n\tstatic create(doc, anchorCell, headCell = anchorCell) {\n\t\treturn new CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));\n\t}\n\tgetBookmark() {\n\t\treturn new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);\n\t}\n};\nCellSelection.prototype.visible = false;\nSelection.jsonID(\"cell\", CellSelection);\n/**\n* @public\n*/\nvar CellBookmark = class CellBookmark {\n\tconstructor(anchor, head) {\n\t\tthis.anchor = anchor;\n\t\tthis.head = head;\n\t}\n\tmap(mapping) {\n\t\treturn new CellBookmark(mapping.map(this.anchor), mapping.map(this.head));\n\t}\n\tresolve(doc) {\n\t\tconst $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head);\n\t\tif ($anchorCell.parent.type.spec.tableRole == \"row\" && $headCell.parent.type.spec.tableRole == \"row\" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell)) return new CellSelection($anchorCell, $headCell);\n\t\telse return Selection.near($headCell, 1);\n\t}\n};\nfunction drawCellSelection(state) {\n\tif (!(state.selection instanceof CellSelection)) return null;\n\tconst cells = [];\n\tstate.selection.forEachCell((node, pos) => {\n\t\tcells.push(Decoration.node(pos, pos + node.nodeSize, { class: \"selectedCell\" }));\n\t});\n\treturn DecorationSet.create(state.doc, cells);\n}\nfunction isCellBoundarySelection({ $from, $to }) {\n\tif ($from.pos == $to.pos || $from.pos < $to.pos - 6) return false;\n\tlet afterFrom = $from.pos;\n\tlet beforeTo = $to.pos;\n\tlet depth = $from.depth;\n\tfor (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break;\n\tfor (let d = $to.depth; d >= 0; d--, beforeTo--) if ($to.before(d + 1) > $to.start(d)) break;\n\treturn afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);\n}\nfunction isTextSelectionAcrossCells({ $from, $to }) {\n\tlet fromCellBoundaryNode;\n\tlet toCellBoundaryNode;\n\tfor (let i = $from.depth; i > 0; i--) {\n\t\tconst node = $from.node(i);\n\t\tif (node.type.spec.tableRole === \"cell\" || node.type.spec.tableRole === \"header_cell\") {\n\t\t\tfromCellBoundaryNode = node;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor (let i = $to.depth; i > 0; i--) {\n\t\tconst node = $to.node(i);\n\t\tif (node.type.spec.tableRole === \"cell\" || node.type.spec.tableRole === \"header_cell\") {\n\t\t\ttoCellBoundaryNode = node;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;\n}\nfunction normalizeSelection(state, tr, allowTableNodeSelection) {\n\tconst sel = (tr || state).selection;\n\tconst doc = (tr || state).doc;\n\tlet normalize;\n\tlet role;\n\tif (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) {\n\t\tif (role == \"cell\" || role == \"header_cell\") normalize = CellSelection.create(doc, sel.from);\n\t\telse if (role == \"row\") {\n\t\t\tconst $cell = doc.resolve(sel.from + 1);\n\t\t\tnormalize = CellSelection.rowSelection($cell, $cell);\n\t\t} else if (!allowTableNodeSelection) {\n\t\t\tconst map = TableMap.get(sel.node);\n\t\t\tconst start = sel.from + 1;\n\t\t\tconst lastCell = start + map.map[map.width * map.height - 1];\n\t\t\tnormalize = CellSelection.create(doc, start + 1, lastCell);\n\t\t}\n\t} else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) normalize = TextSelection.create(doc, sel.from);\n\telse if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());\n\tif (normalize) (tr || (tr = state.tr)).setSelection(normalize);\n\treturn tr;\n}\n\n//#endregion\n//#region src/fixtables.ts\n/**\n* @public\n*/\nconst fixTablesKey = new PluginKey(\"fix-tables\");\n/**\n* Helper for iterating through the nodes in a document that changed\n* compared to the given previous document. Useful for avoiding\n* duplicate work on each transaction.\n*\n* @public\n*/\nfunction changedDescendants(old, cur, offset, f) {\n\tconst oldSize = old.childCount, curSize = cur.childCount;\n\touter: for (let i = 0, j = 0; i < curSize; i++) {\n\t\tconst child = cur.child(i);\n\t\tfor (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) if (old.child(scan) == child) {\n\t\t\tj = scan + 1;\n\t\t\toffset += child.nodeSize;\n\t\t\tcontinue outer;\n\t\t}\n\t\tf(child, offset);\n\t\tif (j < oldSize && old.child(j).sameMarkup(child)) changedDescendants(old.child(j), child, offset + 1, f);\n\t\telse child.nodesBetween(0, child.content.size, f, offset + 1);\n\t\toffset += child.nodeSize;\n\t}\n}\n/**\n* Inspect all tables in the given state's document and return a\n* transaction that fixes them, if necessary. If `oldState` was\n* provided, that is assumed to hold a previous, known-good state,\n* which will be used to avoid re-scanning unchanged parts of the\n* document.\n*\n* @public\n*/\nfunction fixTables(state, oldState) {\n\tlet tr;\n\tconst check = (node, pos) => {\n\t\tif (node.type.spec.tableRole == \"table\") tr = fixTable(state, node, pos, tr);\n\t};\n\tif (!oldState) state.doc.descendants(check);\n\telse if (oldState.doc != state.doc) changedDescendants(oldState.doc, state.doc, 0, check);\n\treturn tr;\n}\nfunction fixTable(state, table, tablePos, tr) {\n\tconst map = TableMap.get(table);\n\tif (!map.problems) return tr;\n\tif (!tr) tr = state.tr;\n\tconst mustAdd = [];\n\tfor (let i = 0; i < map.height; i++) mustAdd.push(0);\n\tfor (let i = 0; i < map.problems.length; i++) {\n\t\tconst prob = map.problems[i];\n\t\tif (prob.type == \"collision\") {\n\t\t\tconst cell = table.nodeAt(prob.pos);\n\t\t\tif (!cell) continue;\n\t\t\tconst attrs = cell.attrs;\n\t\t\tfor (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;\n\t\t\ttr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n));\n\t\t} else if (prob.type == \"missing\") mustAdd[prob.row] += prob.n;\n\t\telse if (prob.type == \"overlong_rowspan\") {\n\t\t\tconst cell = table.nodeAt(prob.pos);\n\t\t\tif (!cell) continue;\n\t\t\ttr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {\n\t\t\t\t...cell.attrs,\n\t\t\t\trowspan: cell.attrs.rowspan - prob.n\n\t\t\t});\n\t\t} else if (prob.type == \"colwidth mismatch\") {\n\t\t\tconst cell = table.nodeAt(prob.pos);\n\t\t\tif (!cell) continue;\n\t\t\ttr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {\n\t\t\t\t...cell.attrs,\n\t\t\t\tcolwidth: prob.colwidth\n\t\t\t});\n\t\t} else if (prob.type == \"zero_sized\") {\n\t\t\tconst pos = tr.mapping.map(tablePos);\n\t\t\ttr.delete(pos, pos + table.nodeSize);\n\t\t}\n\t}\n\tlet first, last;\n\tfor (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) {\n\t\tif (first == null) first = i;\n\t\tlast = i;\n\t}\n\tfor (let i = 0, pos = tablePos + 1; i < map.height; i++) {\n\t\tconst row = table.child(i);\n\t\tconst end = pos + row.nodeSize;\n\t\tconst add = mustAdd[i];\n\t\tif (add > 0) {\n\t\t\tlet role = \"cell\";\n\t\t\tif (row.firstChild) role = row.firstChild.type.spec.tableRole;\n\t\t\tconst nodes = [];\n\t\t\tfor (let j = 0; j < add; j++) {\n\t\t\t\tconst node = tableNodeTypes(state.schema)[role].createAndFill();\n\t\t\t\tif (node) nodes.push(node);\n\t\t\t}\n\t\t\tconst side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1;\n\t\t\ttr.insert(tr.mapping.map(side), nodes);\n\t\t}\n\t\tpos = end;\n\t}\n\treturn tr.setMeta(fixTablesKey, { fixTables: true });\n}\n\n//#endregion\n//#region src/utils/convert.ts\n/**\n* This function will transform the table node into a matrix of rows and columns\n* respecting merged cells, for example this table:\n*\n* ```\n* ┌──────┬──────┬─────────────┐\n* │  A1  │  B1  │     C1      │\n* ├──────┼──────┴──────┬──────┤\n* │  A2  │     B2      │      │\n* ├──────┼─────────────┤  D1  │\n* │  A3  │  B3  │  C3  │      │\n* └──────┴──────┴──────┴──────┘\n* ```\n*\n* will be converted to the below:\n*\n* ```javascript\n* [\n*   [A1, B1, C1, null],\n*   [A2, B2, null, D1],\n*   [A3, B3, C3, null],\n* ]\n* ```\n* @internal\n*/\nfunction convertTableNodeToArrayOfRows(tableNode) {\n\tconst map = TableMap.get(tableNode);\n\tconst rows = [];\n\tconst rowCount = map.height;\n\tconst colCount$1 = map.width;\n\tfor (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n\t\tconst row = [];\n\t\tfor (let colIndex = 0; colIndex < colCount$1; colIndex++) {\n\t\t\tconst cellIndex = rowIndex * colCount$1 + colIndex;\n\t\t\tconst cellPos = map.map[cellIndex];\n\t\t\tif (rowIndex > 0) {\n\t\t\t\tconst topCellIndex = cellIndex - colCount$1;\n\t\t\t\tif (cellPos === map.map[topCellIndex]) {\n\t\t\t\t\trow.push(null);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (colIndex > 0) {\n\t\t\t\tconst leftCellIndex = cellIndex - 1;\n\t\t\t\tif (cellPos === map.map[leftCellIndex]) {\n\t\t\t\t\trow.push(null);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\trow.push(tableNode.nodeAt(cellPos));\n\t\t}\n\t\trows.push(row);\n\t}\n\treturn rows;\n}\n/**\n* Convert an array of rows to a table node.\n*\n* @internal\n*/\nfunction convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) {\n\tconst newRows = [];\n\tconst map = TableMap.get(tableNode);\n\tconst rowCount = map.height;\n\tconst colCount$1 = map.width;\n\tfor (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n\t\tconst oldRow = tableNode.child(rowIndex);\n\t\tconst newCells = [];\n\t\tfor (let colIndex = 0; colIndex < colCount$1; colIndex++) {\n\t\t\tconst cell = arrayOfNodes[rowIndex][colIndex];\n\t\t\tif (!cell) continue;\n\t\t\tconst cellPos = map.map[rowIndex * map.width + colIndex];\n\t\t\tconst oldCell = tableNode.nodeAt(cellPos);\n\t\t\tif (!oldCell) continue;\n\t\t\tconst newCell = oldCell.type.createChecked(cell.attrs, cell.content, cell.marks);\n\t\t\tnewCells.push(newCell);\n\t\t}\n\t\tconst newRow = oldRow.type.createChecked(oldRow.attrs, newCells, oldRow.marks);\n\t\tnewRows.push(newRow);\n\t}\n\treturn tableNode.type.createChecked(tableNode.attrs, newRows, tableNode.marks);\n}\n\n//#endregion\n//#region src/utils/move-row-in-array-of-rows.ts\n/**\n* Move a row in an array of rows.\n*\n* @internal\n*/\nfunction moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, directionOverride) {\n\tconst direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;\n\tconst rowsExtracted = rows.splice(indexesOrigin[0], indexesOrigin.length);\n\tconst positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;\n\tlet target;\n\tif (directionOverride === -1 && direction === 1) target = indexesTarget[0] - 1;\n\telse if (directionOverride === 1 && direction === -1) target = indexesTarget[indexesTarget.length - 1] - positionOffset + 1;\n\telse target = direction === -1 ? indexesTarget[0] : indexesTarget[indexesTarget.length - 1] - positionOffset;\n\trows.splice(target, 0, ...rowsExtracted);\n\treturn rows;\n}\n\n//#endregion\n//#region src/utils/query.ts\n/**\n* Checks if the given object is a `CellSelection` instance.\n*\n* @internal\n*/\nfunction isCellSelection(value) {\n\treturn value instanceof CellSelection;\n}\n/**\n* Find the closest table node for a given position.\n*\n* @public\n*/\nfunction findTable($pos) {\n\treturn findParentNode((node) => node.type.spec.tableRole === \"table\", $pos);\n}\n/**\n* Try to find the anchor and head cell in the same table by using the given\n* anchor and head as hit points, or fallback to the selection's anchor and\n* head.\n*\n* @public\n*/\nfunction findCellRange(selection, anchorHit, headHit) {\n\tvar _ref, _ref2;\n\tif (anchorHit == null && headHit == null && isCellSelection(selection)) return [selection.$anchorCell, selection.$headCell];\n\tconst anchor = (_ref = anchorHit !== null && anchorHit !== void 0 ? anchorHit : headHit) !== null && _ref !== void 0 ? _ref : selection.anchor;\n\tconst head = (_ref2 = headHit !== null && headHit !== void 0 ? headHit : anchorHit) !== null && _ref2 !== void 0 ? _ref2 : selection.head;\n\tconst doc = selection.$head.doc;\n\tconst $anchorCell = findCellPos(doc, anchor);\n\tconst $headCell = findCellPos(doc, head);\n\tif ($anchorCell && $headCell && inSameTable($anchorCell, $headCell)) return [$anchorCell, $headCell];\n\treturn null;\n}\n/**\n* Try to find a resolved pos of a cell by using the given pos as a hit point.\n*\n* @public\n*/\nfunction findCellPos(doc, pos) {\n\tconst $pos = doc.resolve(pos);\n\treturn cellAround($pos) || cellNear($pos);\n}\n/**\n* Find the closest parent node that satisfies the predicate.\n*\n* @internal\n*/\nfunction findParentNode(predicate, $pos) {\n\tfor (let depth = $pos.depth; depth >= 0; depth -= 1) {\n\t\tconst node = $pos.node(depth);\n\t\tif (predicate(node)) return {\n\t\t\tnode,\n\t\t\tpos: depth === 0 ? 0 : $pos.before(depth),\n\t\t\tstart: $pos.start(depth),\n\t\t\tdepth\n\t\t};\n\t}\n\treturn null;\n}\n\n//#endregion\n//#region src/utils/get-cells.ts\n/**\n* Returns an array of cells in a column at the specified column index.\n*\n* @internal\n*/\nfunction getCellsInColumn(columnIndex, selection) {\n\tconst table = findTable(selection.$from);\n\tif (!table) return;\n\tconst map = TableMap.get(table.node);\n\tif (columnIndex < 0 || columnIndex > map.width - 1) return;\n\treturn map.cellsInRect({\n\t\tleft: columnIndex,\n\t\tright: columnIndex + 1,\n\t\ttop: 0,\n\t\tbottom: map.height\n\t}).map((nodePos) => {\n\t\tconst node = table.node.nodeAt(nodePos);\n\t\tconst pos = nodePos + table.start;\n\t\treturn {\n\t\t\tpos,\n\t\t\tstart: pos + 1,\n\t\t\tnode,\n\t\t\tdepth: table.depth + 2\n\t\t};\n\t});\n}\n/**\n* Returns an array of cells in a row at the specified row index.\n*\n* @internal\n*/\nfunction getCellsInRow(rowIndex, selection) {\n\tconst table = findTable(selection.$from);\n\tif (!table) return;\n\tconst map = TableMap.get(table.node);\n\tif (rowIndex < 0 || rowIndex > map.height - 1) return;\n\treturn map.cellsInRect({\n\t\tleft: 0,\n\t\tright: map.width,\n\t\ttop: rowIndex,\n\t\tbottom: rowIndex + 1\n\t}).map((nodePos) => {\n\t\tconst node = table.node.nodeAt(nodePos);\n\t\tconst pos = nodePos + table.start;\n\t\treturn {\n\t\t\tpos,\n\t\t\tstart: pos + 1,\n\t\t\tnode,\n\t\t\tdepth: table.depth + 2\n\t\t};\n\t});\n}\n\n//#endregion\n//#region src/utils/selection-range.ts\n/**\n* Returns a range of rectangular selection spanning all merged cells around a\n* column at index `columnIndex`.\n*\n* Original implementation from Atlassian (Apache License 2.0)\n*\n* https://bitbucket.org/atlassian/atlassian-frontend-mirror/src/5f91cb871e8248bc3bae5ddc30bb9fd9200fadbb/editor/editor-tables/src/utils/get-selection-range-in-column.ts#editor/editor-tables/src/utils/get-selection-range-in-column.ts\n*\n* @internal\n*/\nfunction getSelectionRangeInColumn(tr, startColIndex, endColIndex = startColIndex) {\n\tlet startIndex = startColIndex;\n\tlet endIndex = endColIndex;\n\tfor (let i = startColIndex; i >= 0; i--) {\n\t\tconst cells = getCellsInColumn(i, tr.selection);\n\t\tif (cells) cells.forEach((cell) => {\n\t\t\tconst maybeEndIndex = cell.node.attrs.colspan + i - 1;\n\t\t\tif (maybeEndIndex >= startIndex) startIndex = i;\n\t\t\tif (maybeEndIndex > endIndex) endIndex = maybeEndIndex;\n\t\t});\n\t}\n\tfor (let i = startColIndex; i <= endIndex; i++) {\n\t\tconst cells = getCellsInColumn(i, tr.selection);\n\t\tif (cells) cells.forEach((cell) => {\n\t\t\tconst maybeEndIndex = cell.node.attrs.colspan + i - 1;\n\t\t\tif (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex) endIndex = maybeEndIndex;\n\t\t});\n\t}\n\tconst indexes = [];\n\tfor (let i = startIndex; i <= endIndex; i++) {\n\t\tconst maybeCells = getCellsInColumn(i, tr.selection);\n\t\tif (maybeCells && maybeCells.length > 0) indexes.push(i);\n\t}\n\tstartIndex = indexes[0];\n\tendIndex = indexes[indexes.length - 1];\n\tconst firstSelectedColumnCells = getCellsInColumn(startIndex, tr.selection);\n\tconst firstRowCells = getCellsInRow(0, tr.selection);\n\tif (!firstSelectedColumnCells || !firstRowCells) return;\n\tconst $anchor = tr.doc.resolve(firstSelectedColumnCells[firstSelectedColumnCells.length - 1].pos);\n\tlet headCell;\n\tfor (let i = endIndex; i >= startIndex; i--) {\n\t\tconst columnCells = getCellsInColumn(i, tr.selection);\n\t\tif (columnCells && columnCells.length > 0) {\n\t\t\tfor (let j = firstRowCells.length - 1; j >= 0; j--) if (firstRowCells[j].pos === columnCells[0].pos) {\n\t\t\t\theadCell = columnCells[0];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (headCell) break;\n\t\t}\n\t}\n\tif (!headCell) return;\n\treturn {\n\t\t$anchor,\n\t\t$head: tr.doc.resolve(headCell.pos),\n\t\tindexes\n\t};\n}\n/**\n* Returns a range of rectangular selection spanning all merged cells around a\n* row at index `rowIndex`.\n*\n* Original implementation from Atlassian (Apache License 2.0)\n*\n* https://bitbucket.org/atlassian/atlassian-frontend-mirror/src/5f91cb871e8248bc3bae5ddc30bb9fd9200fadbb/editor/editor-tables/src/utils/get-selection-range-in-row.ts#editor/editor-tables/src/utils/get-selection-range-in-row.ts\n*\n* @internal\n*/\nfunction getSelectionRangeInRow(tr, startRowIndex, endRowIndex = startRowIndex) {\n\tlet startIndex = startRowIndex;\n\tlet endIndex = endRowIndex;\n\tfor (let i = startRowIndex; i >= 0; i--) {\n\t\tconst cells = getCellsInRow(i, tr.selection);\n\t\tif (cells) cells.forEach((cell) => {\n\t\t\tconst maybeEndIndex = cell.node.attrs.rowspan + i - 1;\n\t\t\tif (maybeEndIndex >= startIndex) startIndex = i;\n\t\t\tif (maybeEndIndex > endIndex) endIndex = maybeEndIndex;\n\t\t});\n\t}\n\tfor (let i = startRowIndex; i <= endIndex; i++) {\n\t\tconst cells = getCellsInRow(i, tr.selection);\n\t\tif (cells) cells.forEach((cell) => {\n\t\t\tconst maybeEndIndex = cell.node.attrs.rowspan + i - 1;\n\t\t\tif (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex) endIndex = maybeEndIndex;\n\t\t});\n\t}\n\tconst indexes = [];\n\tfor (let i = startIndex; i <= endIndex; i++) {\n\t\tconst maybeCells = getCellsInRow(i, tr.selection);\n\t\tif (maybeCells && maybeCells.length > 0) indexes.push(i);\n\t}\n\tstartIndex = indexes[0];\n\tendIndex = indexes[indexes.length - 1];\n\tconst firstSelectedRowCells = getCellsInRow(startIndex, tr.selection);\n\tconst firstColumnCells = getCellsInColumn(0, tr.selection);\n\tif (!firstSelectedRowCells || !firstColumnCells) return;\n\tconst $anchor = tr.doc.resolve(firstSelectedRowCells[firstSelectedRowCells.length - 1].pos);\n\tlet headCell;\n\tfor (let i = endIndex; i >= startIndex; i--) {\n\t\tconst rowCells = getCellsInRow(i, tr.selection);\n\t\tif (rowCells && rowCells.length > 0) {\n\t\t\tfor (let j = firstColumnCells.length - 1; j >= 0; j--) if (firstColumnCells[j].pos === rowCells[0].pos) {\n\t\t\t\theadCell = rowCells[0];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (headCell) break;\n\t\t}\n\t}\n\tif (!headCell) return;\n\treturn {\n\t\t$anchor,\n\t\t$head: tr.doc.resolve(headCell.pos),\n\t\tindexes\n\t};\n}\n\n//#endregion\n//#region src/utils/transpose.ts\n/**\n* Transposes a 2D array by flipping columns to rows.\n*\n* Transposition is a familiar algebra concept where the matrix is flipped\n* along its diagonal. For more details, see:\n* https://en.wikipedia.org/wiki/Transpose\n*\n* @example\n* ```javascript\n* const arr = [\n*   ['a1', 'a2', 'a3'],\n*   ['b1', 'b2', 'b3'],\n*   ['c1', 'c2', 'c3'],\n*   ['d1', 'd2', 'd3'],\n* ];\n*\n* const result = transpose(arr);\n* result === [\n*   ['a1', 'b1', 'c1', 'd1'],\n*   ['a2', 'b2', 'c2', 'd2'],\n*   ['a3', 'b3', 'c3', 'd3'],\n* ]\n* ```\n*/\nfunction transpose(array) {\n\treturn array[0].map((_, i) => {\n\t\treturn array.map((column) => column[i]);\n\t});\n}\n\n//#endregion\n//#region src/utils/move-column.ts\n/**\n* Move a column from index `origin` to index `target`.\n*\n* @internal\n*/\nfunction moveColumn(moveColParams) {\n\tvar _getSelectionRangeInC, _getSelectionRangeInC2;\n\tconst { tr, originIndex, targetIndex, select, pos } = moveColParams;\n\tconst table = findTable(tr.doc.resolve(pos));\n\tif (!table) return false;\n\tconst indexesOriginColumn = (_getSelectionRangeInC = getSelectionRangeInColumn(tr, originIndex)) === null || _getSelectionRangeInC === void 0 ? void 0 : _getSelectionRangeInC.indexes;\n\tconst indexesTargetColumn = (_getSelectionRangeInC2 = getSelectionRangeInColumn(tr, targetIndex)) === null || _getSelectionRangeInC2 === void 0 ? void 0 : _getSelectionRangeInC2.indexes;\n\tif (!indexesOriginColumn || !indexesTargetColumn) return false;\n\tif (indexesOriginColumn.includes(targetIndex)) return false;\n\tconst newTable = moveTableColumn$1(table.node, indexesOriginColumn, indexesTargetColumn, 0);\n\ttr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);\n\tif (!select) return true;\n\tconst map = TableMap.get(newTable);\n\tconst start = table.start;\n\tconst index = targetIndex;\n\tconst lastCell = map.positionAt(map.height - 1, index, newTable);\n\tconst $lastCell = tr.doc.resolve(start + lastCell);\n\tconst firstCell = map.positionAt(0, index, newTable);\n\tconst $firstCell = tr.doc.resolve(start + firstCell);\n\ttr.setSelection(CellSelection.colSelection($lastCell, $firstCell));\n\treturn true;\n}\nfunction moveTableColumn$1(table, indexesOrigin, indexesTarget, direction) {\n\tlet rows = transpose(convertTableNodeToArrayOfRows(table));\n\trows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);\n\trows = transpose(rows);\n\treturn convertArrayOfRowsToTableNode(table, rows);\n}\n\n//#endregion\n//#region src/utils/move-row.ts\n/**\n* Move a row from index `origin` to index `target`.\n*\n* @internal\n*/\nfunction moveRow(moveRowParams) {\n\tvar _getSelectionRangeInR, _getSelectionRangeInR2;\n\tconst { tr, originIndex, targetIndex, select, pos } = moveRowParams;\n\tconst table = findTable(tr.doc.resolve(pos));\n\tif (!table) return false;\n\tconst indexesOriginRow = (_getSelectionRangeInR = getSelectionRangeInRow(tr, originIndex)) === null || _getSelectionRangeInR === void 0 ? void 0 : _getSelectionRangeInR.indexes;\n\tconst indexesTargetRow = (_getSelectionRangeInR2 = getSelectionRangeInRow(tr, targetIndex)) === null || _getSelectionRangeInR2 === void 0 ? void 0 : _getSelectionRangeInR2.indexes;\n\tif (!indexesOriginRow || !indexesTargetRow) return false;\n\tif (indexesOriginRow.includes(targetIndex)) return false;\n\tconst newTable = moveTableRow$1(table.node, indexesOriginRow, indexesTargetRow, 0);\n\ttr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);\n\tif (!select) return true;\n\tconst map = TableMap.get(newTable);\n\tconst start = table.start;\n\tconst index = targetIndex;\n\tconst lastCell = map.positionAt(index, map.width - 1, newTable);\n\tconst $lastCell = tr.doc.resolve(start + lastCell);\n\tconst firstCell = map.positionAt(index, 0, newTable);\n\tconst $firstCell = tr.doc.resolve(start + firstCell);\n\ttr.setSelection(CellSelection.rowSelection($lastCell, $firstCell));\n\treturn true;\n}\nfunction moveTableRow$1(table, indexesOrigin, indexesTarget, direction) {\n\tlet rows = convertTableNodeToArrayOfRows(table);\n\trows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);\n\treturn convertArrayOfRowsToTableNode(table, rows);\n}\n\n//#endregion\n//#region src/commands.ts\n/**\n* Helper to get the selected rectangle in a table, if any. Adds table\n* map, table node, and table start offset to the object for\n* convenience.\n*\n* @public\n*/\nfunction selectedRect(state) {\n\tconst sel = state.selection;\n\tconst $pos = selectionCell(state);\n\tconst table = $pos.node(-1);\n\tconst tableStart = $pos.start(-1);\n\tconst map = TableMap.get(table);\n\treturn {\n\t\t...sel instanceof CellSelection ? map.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart) : map.findCell($pos.pos - tableStart),\n\t\ttableStart,\n\t\tmap,\n\t\ttable\n\t};\n}\n/**\n* Add a column at the given position in a table.\n*\n* @public\n*/\nfunction addColumn(tr, { map, tableStart, table }, col) {\n\tlet refColumn = col > 0 ? -1 : 0;\n\tif (columnIsHeader(map, table, col + refColumn)) refColumn = col == 0 || col == map.width ? null : 0;\n\tfor (let row = 0; row < map.height; row++) {\n\t\tconst index = row * map.width + col;\n\t\tif (col > 0 && col < map.width && map.map[index - 1] == map.map[index]) {\n\t\t\tconst pos = map.map[index];\n\t\t\tconst cell = table.nodeAt(pos);\n\t\t\ttr.setNodeMarkup(tr.mapping.map(tableStart + pos), null, addColSpan(cell.attrs, col - map.colCount(pos)));\n\t\t\trow += cell.attrs.rowspan - 1;\n\t\t} else {\n\t\t\tconst type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + refColumn]).type;\n\t\t\tconst pos = map.positionAt(row, col, table);\n\t\t\ttr.insert(tr.mapping.map(tableStart + pos), type.createAndFill());\n\t\t}\n\t}\n\treturn tr;\n}\n/**\n* Command to add a column before the column with the selection.\n*\n* @public\n*/\nfunction addColumnBefore(state, dispatch) {\n\tif (!isInTable(state)) return false;\n\tif (dispatch) {\n\t\tconst rect = selectedRect(state);\n\t\tdispatch(addColumn(state.tr, rect, rect.left));\n\t}\n\treturn true;\n}\n/**\n* Command to add a column after the column with the selection.\n*\n* @public\n*/\nfunction addColumnAfter(state, dispatch) {\n\tif (!isInTable(state)) return false;\n\tif (dispatch) {\n\t\tconst rect = selectedRect(state);\n\t\tdispatch(addColumn(state.tr, rect, rect.right));\n\t}\n\treturn true;\n}\n/**\n* @public\n*/\nfunction removeColumn(tr, { map, table, tableStart }, col) {\n\tconst mapStart = tr.mapping.maps.length;\n\tfor (let row = 0; row < map.height;) {\n\t\tconst index = row * map.width + col;\n\t\tconst pos = map.map[index];\n\t\tconst cell = table.nodeAt(pos);\n\t\tconst attrs = cell.attrs;\n\t\tif (col > 0 && map.map[index - 1] == pos || col < map.width - 1 && map.map[index + 1] == pos) tr.setNodeMarkup(tr.mapping.slice(mapStart).map(tableStart + pos), null, removeColSpan(attrs, col - map.colCount(pos)));\n\t\telse {\n\t\t\tconst start = tr.mapping.slice(mapStart).map(tableStart + pos);\n\t\t\ttr.delete(start, start + cell.nodeSize);\n\t\t}\n\t\trow += attrs.rowspan;\n\t}\n}\n/**\n* Command function that removes the selected columns from a table.\n*\n* @public\n*/\nfunction deleteColumn(state, dispatch) {\n\tif (!isInTable(state)) return false;\n\tif (dispatch) {\n\t\tconst rect = selectedRect(state);\n\t\tconst tr = state.tr;\n\t\tif (rect.left == 0 && rect.right == rect.map.width) return false;\n\t\tfor (let i = rect.right - 1;; i--) {\n\t\t\tremoveColumn(tr, rect, i);\n\t\t\tif (i == rect.left) break;\n\t\t\tconst table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;\n\t\t\tif (!table) throw new RangeError(\"No table found\");\n\t\t\trect.table = table;\n\t\t\trect.map = TableMap.get(table);\n\t\t}\n\t\tdispatch(tr);\n\t}\n\treturn true;\n}\n/**\n* @public\n*/\nfunction rowIsHeader(map, table, row) {\n\tvar _table$nodeAt;\n\tconst headerCell = tableNodeTypes(table.type.schema).header_cell;\n\tfor (let col = 0; col < map.width; col++) if (((_table$nodeAt = table.nodeAt(map.map[col + row * map.width])) === null || _table$nodeAt === void 0 ? void 0 : _table$nodeAt.type) != headerCell) return false;\n\treturn true;\n}\n/**\n* @public\n*/\nfunction addRow(tr, { map, tableStart, table }, row) {\n\tlet rowPos = tableStart;\n\tfor (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;\n\tconst cells = [];\n\tlet refRow = row > 0 ? -1 : 0;\n\tif (rowIsHeader(map, table, row + refRow)) refRow = row == 0 || row == map.height ? null : 0;\n\tfor (let col = 0, index = map.width * row; col < map.width; col++, index++) if (row > 0 && row < map.height && map.map[index] == map.map[index - map.width]) {\n\t\tconst pos = map.map[index];\n\t\tconst attrs = table.nodeAt(pos).attrs;\n\t\ttr.setNodeMarkup(tableStart + pos, null, {\n\t\t\t...attrs,\n\t\t\trowspan: attrs.rowspan + 1\n\t\t});\n\t\tcol += attrs.colspan - 1;\n\t} else {\n\t\tvar _table$nodeAt2;\n\t\tconst type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_table$nodeAt2 = table.nodeAt(map.map[index + refRow * map.width])) === null || _table$nodeAt2 === void 0 ? void 0 : _table$nodeAt2.type;\n\t\tconst node = type === null || type === void 0 ? void 0 : type.createAndFill();\n\t\tif (node) cells.push(node);\n\t}\n\ttr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));\n\treturn tr;\n}\n/**\n* Add a table row before the selection.\n*\n* @public\n*/\nfunction addRowBefore(state, dispatch) {\n\tif (!isInTable(state)) return false;\n\tif (dispatch) {\n\t\tconst rect = selectedRect(state);\n\t\tdispatch(addRow(state.tr, rect, rect.top));\n\t}\n\treturn true;\n}\n/**\n* Add a table row after the selection.\n*\n* @public\n*/\nfunction addRowAfter(state, dispatch) {\n\tif (!isInTable(state)) return false;\n\tif (dispatch) {\n\t\tconst rect = selectedRect(state);\n\t\tdispatch(addRow(state.tr, rect, rect.bottom));\n\t}\n\treturn true;\n}\n/**\n* @public\n*/\nfunction removeRow(tr, { map, table, tableStart }, row) {\n\tlet rowPos = 0;\n\tfor (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;\n\tconst nextRow = rowPos + table.child(row).nodeSize;\n\tconst mapFrom = tr.mapping.maps.length;\n\ttr.delete(rowPos + tableStart, nextRow + tableStart);\n\tconst seen = /* @__PURE__ */ new Set();\n\tfor (let col = 0, index = row * map.width; col < map.width; col++, index++) {\n\t\tconst pos = map.map[index];\n\t\tif (seen.has(pos)) continue;\n\t\tseen.add(pos);\n\t\tif (row > 0 && pos == map.map[index - map.width]) {\n\t\t\tconst attrs = table.nodeAt(pos).attrs;\n\t\t\ttr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), null, {\n\t\t\t\t...attrs,\n\t\t\t\trowspan: attrs.rowspan - 1\n\t\t\t});\n\t\t\tcol += attrs.colspan - 1;\n\t\t} else if (row < map.height && pos == map.map[index + map.width]) {\n\t\t\tconst cell = table.nodeAt(pos);\n\t\t\tconst attrs = cell.attrs;\n\t\t\tconst copy = cell.type.create({\n\t\t\t\t...attrs,\n\t\t\t\trowspan: cell.attrs.rowspan - 1\n\t\t\t}, cell.content);\n\t\t\tconst newPos = map.positionAt(row + 1, col, table);\n\t\t\ttr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);\n\t\t\tcol += attrs.colspan - 1;\n\t\t}\n\t}\n}\n/**\n* Remove the selected rows from a table.\n*\n* @public\n*/\nfunction deleteRow(state, dispatch) {\n\tif (!isInTable(state)) return false;\n\tif (dispatch) {\n\t\tconst rect = selectedRect(state), tr = state.tr;\n\t\tif (rect.top == 0 && rect.bottom == rect.map.height) return false;\n\t\tfor (let i = rect.bottom - 1;; i--) {\n\t\t\tremoveRow(tr, rect, i);\n\t\t\tif (i == rect.top) break;\n\t\t\tconst table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;\n\t\t\tif (!table) throw new RangeError(\"No table found\");\n\t\t\trect.table = table;\n\t\t\trect.map = TableMap.get(rect.table);\n\t\t}\n\t\tdispatch(tr);\n\t}\n\treturn true;\n}\nfunction isEmpty(cell) {\n\tconst c = cell.content;\n\treturn c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0;\n}\nfunction cellsOverlapRectangle({ width, height, map }, rect) {\n\tlet indexTop = rect.top * width + rect.left, indexLeft = indexTop;\n\tlet indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);\n\tfor (let i = rect.top; i < rect.bottom; i++) {\n\t\tif (rect.left > 0 && map[indexLeft] == map[indexLeft - 1] || rect.right < width && map[indexRight] == map[indexRight + 1]) return true;\n\t\tindexLeft += width;\n\t\tindexRight += width;\n\t}\n\tfor (let i = rect.left; i < rect.right; i++) {\n\t\tif (rect.top > 0 && map[indexTop] == map[indexTop - width] || rect.bottom < height && map[indexBottom] == map[indexBottom + width]) return true;\n\t\tindexTop++;\n\t\tindexBottom++;\n\t}\n\treturn false;\n}\n/**\n* Merge the selected cells into a single cell. Only available when\n* the selected cells' outline forms a rectangle.\n*\n* @public\n*/\nfunction mergeCells(state, dispatch) {\n\tconst sel = state.selection;\n\tif (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false;\n\tconst rect = selectedRect(state), { map } = rect;\n\tif (cellsOverlapRectangle(map, rect)) return false;\n\tif (dispatch) {\n\t\tconst tr = state.tr;\n\t\tconst seen = {};\n\t\tlet content = Fragment.empty;\n\t\tlet mergedPos;\n\t\tlet mergedCell;\n\t\tfor (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) {\n\t\t\tconst cellPos = map.map[row * map.width + col];\n\t\t\tconst cell = rect.table.nodeAt(cellPos);\n\t\t\tif (seen[cellPos] || !cell) continue;\n\t\t\tseen[cellPos] = true;\n\t\t\tif (mergedPos == null) {\n\t\t\t\tmergedPos = cellPos;\n\t\t\t\tmergedCell = cell;\n\t\t\t} else {\n\t\t\t\tif (!isEmpty(cell)) content = content.append(cell.content);\n\t\t\t\tconst mapped = tr.mapping.map(cellPos + rect.tableStart);\n\t\t\t\ttr.delete(mapped, mapped + cell.nodeSize);\n\t\t\t}\n\t\t}\n\t\tif (mergedPos == null || mergedCell == null) return true;\n\t\ttr.setNodeMarkup(mergedPos + rect.tableStart, null, {\n\t\t\t...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan),\n\t\t\trowspan: rect.bottom - rect.top\n\t\t});\n\t\tif (content.size > 0) {\n\t\t\tconst end = mergedPos + 1 + mergedCell.content.size;\n\t\t\tconst start = isEmpty(mergedCell) ? mergedPos + 1 : end;\n\t\t\ttr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);\n\t\t}\n\t\ttr.setSelection(new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart)));\n\t\tdispatch(tr);\n\t}\n\treturn true;\n}\n/**\n* Split a selected cell, whose rowpan or colspan is greater than one,\n* into smaller cells. Use the first cell type for the new cells.\n*\n* @public\n*/\nfunction splitCell(state, dispatch) {\n\tconst nodeTypes = tableNodeTypes(state.schema);\n\treturn splitCellWithType(({ node }) => {\n\t\treturn nodeTypes[node.type.spec.tableRole];\n\t})(state, dispatch);\n}\n/**\n* Split a selected cell, whose rowpan or colspan is greater than one,\n* into smaller cells with the cell type (th, td) returned by getType function.\n*\n* @public\n*/\nfunction splitCellWithType(getCellType) {\n\treturn (state, dispatch) => {\n\t\tconst sel = state.selection;\n\t\tlet cellNode;\n\t\tlet cellPos;\n\t\tif (!(sel instanceof CellSelection)) {\n\t\t\tvar _cellAround;\n\t\t\tcellNode = cellWrapping(sel.$from);\n\t\t\tif (!cellNode) return false;\n\t\t\tcellPos = (_cellAround = cellAround(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos;\n\t\t} else {\n\t\t\tif (sel.$anchorCell.pos != sel.$headCell.pos) return false;\n\t\t\tcellNode = sel.$anchorCell.nodeAfter;\n\t\t\tcellPos = sel.$anchorCell.pos;\n\t\t}\n\t\tif (cellNode == null || cellPos == null) return false;\n\t\tif (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false;\n\t\tif (dispatch) {\n\t\t\tlet baseAttrs = cellNode.attrs;\n\t\t\tconst attrs = [];\n\t\t\tconst colwidth = baseAttrs.colwidth;\n\t\t\tif (baseAttrs.rowspan > 1) baseAttrs = {\n\t\t\t\t...baseAttrs,\n\t\t\t\trowspan: 1\n\t\t\t};\n\t\t\tif (baseAttrs.colspan > 1) baseAttrs = {\n\t\t\t\t...baseAttrs,\n\t\t\t\tcolspan: 1\n\t\t\t};\n\t\t\tconst rect = selectedRect(state), tr = state.tr;\n\t\t\tfor (let i = 0; i < rect.right - rect.left; i++) attrs.push(colwidth ? {\n\t\t\t\t...baseAttrs,\n\t\t\t\tcolwidth: colwidth && colwidth[i] ? [colwidth[i]] : null\n\t\t\t} : baseAttrs);\n\t\t\tlet lastCell;\n\t\t\tfor (let row = rect.top; row < rect.bottom; row++) {\n\t\t\t\tlet pos = rect.map.positionAt(row, rect.left, rect.table);\n\t\t\t\tif (row == rect.top) pos += cellNode.nodeSize;\n\t\t\t\tfor (let col = rect.left, i = 0; col < rect.right; col++, i++) {\n\t\t\t\t\tif (col == rect.left && row == rect.top) continue;\n\t\t\t\t\ttr.insert(lastCell = tr.mapping.map(pos + rect.tableStart, 1), getCellType({\n\t\t\t\t\t\tnode: cellNode,\n\t\t\t\t\t\trow,\n\t\t\t\t\t\tcol\n\t\t\t\t\t}).createAndFill(attrs[i]));\n\t\t\t\t}\n\t\t\t}\n\t\t\ttr.setNodeMarkup(cellPos, getCellType({\n\t\t\t\tnode: cellNode,\n\t\t\t\trow: rect.top,\n\t\t\t\tcol: rect.left\n\t\t\t}), attrs[0]);\n\t\t\tif (sel instanceof CellSelection) tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), lastCell ? tr.doc.resolve(lastCell) : void 0));\n\t\t\tdispatch(tr);\n\t\t}\n\t\treturn true;\n\t};\n}\n/**\n* Returns a command that sets the given attribute to the given value,\n* and is only available when the currently selected cell doesn't\n* already have that attribute set to that value.\n*\n* @public\n*/\nfunction setCellAttr(name, value) {\n\treturn function(state, dispatch) {\n\t\tif (!isInTable(state)) return false;\n\t\tconst $cell = selectionCell(state);\n\t\tif ($cell.nodeAfter.attrs[name] === value) return false;\n\t\tif (dispatch) {\n\t\t\tconst tr = state.tr;\n\t\t\tif (state.selection instanceof CellSelection) state.selection.forEachCell((node, pos) => {\n\t\t\t\tif (node.attrs[name] !== value) tr.setNodeMarkup(pos, null, {\n\t\t\t\t\t...node.attrs,\n\t\t\t\t\t[name]: value\n\t\t\t\t});\n\t\t\t});\n\t\t\telse tr.setNodeMarkup($cell.pos, null, {\n\t\t\t\t...$cell.nodeAfter.attrs,\n\t\t\t\t[name]: value\n\t\t\t});\n\t\t\tdispatch(tr);\n\t\t}\n\t\treturn true;\n\t};\n}\nfunction deprecated_toggleHeader(type) {\n\treturn function(state, dispatch) {\n\t\tif (!isInTable(state)) return false;\n\t\tif (dispatch) {\n\t\t\tconst types = tableNodeTypes(state.schema);\n\t\t\tconst rect = selectedRect(state), tr = state.tr;\n\t\t\tconst cells = rect.map.cellsInRect(type == \"column\" ? {\n\t\t\t\tleft: rect.left,\n\t\t\t\ttop: 0,\n\t\t\t\tright: rect.right,\n\t\t\t\tbottom: rect.map.height\n\t\t\t} : type == \"row\" ? {\n\t\t\t\tleft: 0,\n\t\t\t\ttop: rect.top,\n\t\t\t\tright: rect.map.width,\n\t\t\t\tbottom: rect.bottom\n\t\t\t} : rect);\n\t\t\tconst nodes = cells.map((pos) => rect.table.nodeAt(pos));\n\t\t\tfor (let i = 0; i < cells.length; i++) if (nodes[i].type == types.header_cell) tr.setNodeMarkup(rect.tableStart + cells[i], types.cell, nodes[i].attrs);\n\t\t\tif (tr.steps.length === 0) for (let i = 0; i < cells.length; i++) tr.setNodeMarkup(rect.tableStart + cells[i], types.header_cell, nodes[i].attrs);\n\t\t\tdispatch(tr);\n\t\t}\n\t\treturn true;\n\t};\n}\nfunction isHeaderEnabledByType(type, rect, types) {\n\tconst cellPositions = rect.map.cellsInRect({\n\t\tleft: 0,\n\t\ttop: 0,\n\t\tright: type == \"row\" ? rect.map.width : 1,\n\t\tbottom: type == \"column\" ? rect.map.height : 1\n\t});\n\tfor (let i = 0; i < cellPositions.length; i++) {\n\t\tconst cell = rect.table.nodeAt(cellPositions[i]);\n\t\tif (cell && cell.type !== types.header_cell) return false;\n\t}\n\treturn true;\n}\n/**\n* Toggles between row/column header and normal cells (Only applies to first row/column).\n* For deprecated behavior pass `useDeprecatedLogic` in options with true.\n*\n* @public\n*/\nfunction toggleHeader(type, options) {\n\toptions = options || { useDeprecatedLogic: false };\n\tif (options.useDeprecatedLogic) return deprecated_toggleHeader(type);\n\treturn function(state, dispatch) {\n\t\tif (!isInTable(state)) return false;\n\t\tif (dispatch) {\n\t\t\tconst types = tableNodeTypes(state.schema);\n\t\t\tconst rect = selectedRect(state), tr = state.tr;\n\t\t\tconst isHeaderRowEnabled = isHeaderEnabledByType(\"row\", rect, types);\n\t\t\tconst isHeaderColumnEnabled = isHeaderEnabledByType(\"column\", rect, types);\n\t\t\tconst selectionStartsAt = (type === \"column\" ? isHeaderRowEnabled : type === \"row\" ? isHeaderColumnEnabled : false) ? 1 : 0;\n\t\t\tconst cellsRect = type == \"column\" ? {\n\t\t\t\tleft: 0,\n\t\t\t\ttop: selectionStartsAt,\n\t\t\t\tright: 1,\n\t\t\t\tbottom: rect.map.height\n\t\t\t} : type == \"row\" ? {\n\t\t\t\tleft: selectionStartsAt,\n\t\t\t\ttop: 0,\n\t\t\t\tright: rect.map.width,\n\t\t\t\tbottom: 1\n\t\t\t} : rect;\n\t\t\tconst newType = type == \"column\" ? isHeaderColumnEnabled ? types.cell : types.header_cell : type == \"row\" ? isHeaderRowEnabled ? types.cell : types.header_cell : types.cell;\n\t\t\trect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {\n\t\t\t\tconst cellPos = relativeCellPos + rect.tableStart;\n\t\t\t\tconst cell = tr.doc.nodeAt(cellPos);\n\t\t\t\tif (cell) tr.setNodeMarkup(cellPos, newType, cell.attrs);\n\t\t\t});\n\t\t\tdispatch(tr);\n\t\t}\n\t\treturn true;\n\t};\n}\n/**\n* Toggles whether the selected row contains header cells.\n*\n* @public\n*/\nconst toggleHeaderRow = toggleHeader(\"row\", { useDeprecatedLogic: true });\n/**\n* Toggles whether the selected column contains header cells.\n*\n* @public\n*/\nconst toggleHeaderColumn = toggleHeader(\"column\", { useDeprecatedLogic: true });\n/**\n* Toggles whether the selected cells are header cells.\n*\n* @public\n*/\nconst toggleHeaderCell = toggleHeader(\"cell\", { useDeprecatedLogic: true });\nfunction findNextCell($cell, dir) {\n\tif (dir < 0) {\n\t\tconst before = $cell.nodeBefore;\n\t\tif (before) return $cell.pos - before.nodeSize;\n\t\tfor (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {\n\t\t\tconst rowNode = $cell.node(-1).child(row);\n\t\t\tconst lastChild = rowNode.lastChild;\n\t\t\tif (lastChild) return rowEnd - 1 - lastChild.nodeSize;\n\t\t\trowEnd -= rowNode.nodeSize;\n\t\t}\n\t} else {\n\t\tif ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize;\n\t\tconst table = $cell.node(-1);\n\t\tfor (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {\n\t\t\tconst rowNode = table.child(row);\n\t\t\tif (rowNode.childCount) return rowStart + 1;\n\t\t\trowStart += rowNode.nodeSize;\n\t\t}\n\t}\n\treturn null;\n}\n/**\n* Returns a command for selecting the next (direction=1) or previous\n* (direction=-1) cell in a table.\n*\n* @public\n*/\nfunction goToNextCell(direction) {\n\treturn function(state, dispatch) {\n\t\tif (!isInTable(state)) return false;\n\t\tconst cell = findNextCell(selectionCell(state), direction);\n\t\tif (cell == null) return false;\n\t\tif (dispatch) {\n\t\t\tconst $cell = state.doc.resolve(cell);\n\t\t\tdispatch(state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());\n\t\t}\n\t\treturn true;\n\t};\n}\n/**\n* Deletes the table around the selection, if any.\n*\n* @public\n*/\nfunction deleteTable(state, dispatch) {\n\tconst $pos = state.selection.$anchor;\n\tfor (let d = $pos.depth; d > 0; d--) if ($pos.node(d).type.spec.tableRole == \"table\") {\n\t\tif (dispatch) dispatch(state.tr.delete($pos.before(d), $pos.after(d)).scrollIntoView());\n\t\treturn true;\n\t}\n\treturn false;\n}\n/**\n* Deletes the content of the selected cells, if they are not empty.\n*\n* @public\n*/\nfunction deleteCellSelection(state, dispatch) {\n\tconst sel = state.selection;\n\tif (!(sel instanceof CellSelection)) return false;\n\tif (dispatch) {\n\t\tconst tr = state.tr;\n\t\tconst baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;\n\t\tsel.forEachCell((cell, pos) => {\n\t\t\tif (!cell.content.eq(baseContent)) tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0));\n\t\t});\n\t\tif (tr.docChanged) dispatch(tr);\n\t}\n\treturn true;\n}\n/**\n* Move a table row from index `from` to index `to`.\n*\n* @public\n*/\nfunction moveTableRow(options) {\n\treturn (state, dispatch) => {\n\t\tconst { from: originIndex, to: targetIndex, select = true, pos = state.selection.from } = options;\n\t\tconst tr = state.tr;\n\t\tif (moveRow({\n\t\t\ttr,\n\t\t\toriginIndex,\n\t\t\ttargetIndex,\n\t\t\tselect,\n\t\t\tpos\n\t\t})) {\n\t\t\tdispatch === null || dispatch === void 0 || dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t};\n}\n/**\n* Move a table column from index `from` to index `to`.\n*\n* @public\n*/\nfunction moveTableColumn(options) {\n\treturn (state, dispatch) => {\n\t\tconst { from: originIndex, to: targetIndex, select = true, pos = state.selection.from } = options;\n\t\tconst tr = state.tr;\n\t\tif (moveColumn({\n\t\t\ttr,\n\t\t\toriginIndex,\n\t\t\ttargetIndex,\n\t\t\tselect,\n\t\t\tpos\n\t\t})) {\n\t\t\tdispatch === null || dispatch === void 0 || dispatch(tr);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t};\n}\n\n//#endregion\n//#region src/copypaste.ts\n/**\n* Get a rectangular area of cells from a slice, or null if the outer\n* nodes of the slice aren't table cells or rows.\n*\n* @internal\n*/\nfunction pastedCells(slice) {\n\tif (slice.size === 0) return null;\n\tlet { content, openStart, openEnd } = slice;\n\twhile (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == \"table\")) {\n\t\topenStart--;\n\t\topenEnd--;\n\t\tcontent = content.child(0).content;\n\t}\n\tconst first = content.child(0);\n\tconst role = first.type.spec.tableRole;\n\tconst schema = first.type.schema, rows = [];\n\tif (role == \"row\") for (let i = 0; i < content.childCount; i++) {\n\t\tlet cells = content.child(i).content;\n\t\tconst left = i ? 0 : Math.max(0, openStart - 1);\n\t\tconst right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);\n\t\tif (left || right) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left, right)).content;\n\t\trows.push(cells);\n\t}\n\telse if (role == \"cell\" || role == \"header_cell\") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content : content);\n\telse return null;\n\treturn ensureRectangular(schema, rows);\n}\nfunction ensureRectangular(schema, rows) {\n\tconst widths = [];\n\tfor (let i = 0; i < rows.length; i++) {\n\t\tconst row = rows[i];\n\t\tfor (let j = row.childCount - 1; j >= 0; j--) {\n\t\t\tconst { rowspan, colspan } = row.child(j).attrs;\n\t\t\tfor (let r = i; r < i + rowspan; r++) widths[r] = (widths[r] || 0) + colspan;\n\t\t}\n\t}\n\tlet width = 0;\n\tfor (let r = 0; r < widths.length; r++) width = Math.max(width, widths[r]);\n\tfor (let r = 0; r < widths.length; r++) {\n\t\tif (r >= rows.length) rows.push(Fragment.empty);\n\t\tif (widths[r] < width) {\n\t\t\tconst empty = tableNodeTypes(schema).cell.createAndFill();\n\t\t\tconst cells = [];\n\t\t\tfor (let i = widths[r]; i < width; i++) cells.push(empty);\n\t\t\trows[r] = rows[r].append(Fragment.from(cells));\n\t\t}\n\t}\n\treturn {\n\t\theight: rows.length,\n\t\twidth,\n\t\trows\n\t};\n}\nfunction fitSlice(nodeType, slice) {\n\tconst node = nodeType.createAndFill();\n\treturn new Transform(node).replace(0, node.content.size, slice).doc;\n}\n/**\n* Clip or extend (repeat) the given set of cells to cover the given\n* width and height. Will clip rowspan/colspan cells at the edges when\n* they stick out.\n*\n* @internal\n*/\nfunction clipCells({ width, height, rows }, newWidth, newHeight) {\n\tif (width != newWidth) {\n\t\tconst added = [];\n\t\tconst newRows = [];\n\t\tfor (let row = 0; row < rows.length; row++) {\n\t\t\tconst frag = rows[row], cells = [];\n\t\t\tfor (let col = added[row] || 0, i = 0; col < newWidth; i++) {\n\t\t\t\tlet cell = frag.child(i % frag.childCount);\n\t\t\t\tif (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content);\n\t\t\t\tcells.push(cell);\n\t\t\t\tcol += cell.attrs.colspan;\n\t\t\t\tfor (let j = 1; j < cell.attrs.rowspan; j++) added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;\n\t\t\t}\n\t\t\tnewRows.push(Fragment.from(cells));\n\t\t}\n\t\trows = newRows;\n\t\twidth = newWidth;\n\t}\n\tif (height != newHeight) {\n\t\tconst newRows = [];\n\t\tfor (let row = 0, i = 0; row < newHeight; row++, i++) {\n\t\t\tconst cells = [], source = rows[i % height];\n\t\t\tfor (let j = 0; j < source.childCount; j++) {\n\t\t\t\tlet cell = source.child(j);\n\t\t\t\tif (row + cell.attrs.rowspan > newHeight) cell = cell.type.create({\n\t\t\t\t\t...cell.attrs,\n\t\t\t\t\trowspan: Math.max(1, newHeight - cell.attrs.rowspan)\n\t\t\t\t}, cell.content);\n\t\t\t\tcells.push(cell);\n\t\t\t}\n\t\t\tnewRows.push(Fragment.from(cells));\n\t\t}\n\t\trows = newRows;\n\t\theight = newHeight;\n\t}\n\treturn {\n\t\twidth,\n\t\theight,\n\t\trows\n\t};\n}\nfunction growTable(tr, map, table, start, width, height, mapFrom) {\n\tconst schema = tr.doc.type.schema;\n\tconst types = tableNodeTypes(schema);\n\tlet empty;\n\tlet emptyHead;\n\tif (width > map.width) for (let row = 0, rowEnd = 0; row < map.height; row++) {\n\t\tconst rowNode = table.child(row);\n\t\trowEnd += rowNode.nodeSize;\n\t\tconst cells = [];\n\t\tlet add;\n\t\tif (rowNode.lastChild == null || rowNode.lastChild.type == types.cell) add = empty || (empty = types.cell.createAndFill());\n\t\telse add = emptyHead || (emptyHead = types.header_cell.createAndFill());\n\t\tfor (let i = map.width; i < width; i++) cells.push(add);\n\t\ttr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);\n\t}\n\tif (height > map.height) {\n\t\tconst cells = [];\n\t\tfor (let i = 0, start$1 = (map.height - 1) * map.width; i < Math.max(map.width, width); i++) {\n\t\t\tconst header = i >= map.width ? false : table.nodeAt(map.map[start$1 + i]).type == types.header_cell;\n\t\t\tcells.push(header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty || (empty = types.cell.createAndFill()));\n\t\t}\n\t\tconst emptyRow = types.row.create(null, Fragment.from(cells)), rows = [];\n\t\tfor (let i = map.height; i < height; i++) rows.push(emptyRow);\n\t\ttr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows);\n\t}\n\treturn !!(empty || emptyHead);\n}\nfunction isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {\n\tif (top == 0 || top == map.height) return false;\n\tlet found = false;\n\tfor (let col = left; col < right; col++) {\n\t\tconst index = top * map.width + col, pos = map.map[index];\n\t\tif (map.map[index - map.width] == pos) {\n\t\t\tfound = true;\n\t\t\tconst cell = table.nodeAt(pos);\n\t\t\tconst { top: cellTop, left: cellLeft } = map.findCell(pos);\n\t\t\ttr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, {\n\t\t\t\t...cell.attrs,\n\t\t\t\trowspan: top - cellTop\n\t\t\t});\n\t\t\ttr.insert(tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)), cell.type.createAndFill({\n\t\t\t\t...cell.attrs,\n\t\t\t\trowspan: cellTop + cell.attrs.rowspan - top\n\t\t\t}));\n\t\t\tcol += cell.attrs.colspan - 1;\n\t\t}\n\t}\n\treturn found;\n}\nfunction isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {\n\tif (left == 0 || left == map.width) return false;\n\tlet found = false;\n\tfor (let row = top; row < bottom; row++) {\n\t\tconst index = row * map.width + left, pos = map.map[index];\n\t\tif (map.map[index - 1] == pos) {\n\t\t\tfound = true;\n\t\t\tconst cell = table.nodeAt(pos);\n\t\t\tconst cellLeft = map.colCount(pos);\n\t\t\tconst updatePos = tr.mapping.slice(mapFrom).map(pos + start);\n\t\t\ttr.setNodeMarkup(updatePos, null, removeColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft)));\n\t\t\ttr.insert(updatePos + cell.nodeSize, cell.type.createAndFill(removeColSpan(cell.attrs, 0, left - cellLeft)));\n\t\t\trow += cell.attrs.rowspan - 1;\n\t\t}\n\t}\n\treturn found;\n}\n/**\n* Insert the given set of cells (as returned by `pastedCells`) into a\n* table, at the position pointed at by rect.\n*\n* @internal\n*/\nfunction insertCells(state, dispatch, tableStart, rect, cells) {\n\tlet table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;\n\tif (!table) throw new Error(\"No table found\");\n\tlet map = TableMap.get(table);\n\tconst { top, left } = rect;\n\tconst right = left + cells.width, bottom = top + cells.height;\n\tconst tr = state.tr;\n\tlet mapFrom = 0;\n\tfunction recomp() {\n\t\ttable = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;\n\t\tif (!table) throw new Error(\"No table found\");\n\t\tmap = TableMap.get(table);\n\t\tmapFrom = tr.mapping.maps.length;\n\t}\n\tif (growTable(tr, map, table, tableStart, right, bottom, mapFrom)) recomp();\n\tif (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom)) recomp();\n\tif (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom)) recomp();\n\tif (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom)) recomp();\n\tif (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom)) recomp();\n\tfor (let row = top; row < bottom; row++) {\n\t\tconst from = map.positionAt(row, left, table), to = map.positionAt(row, right, table);\n\t\ttr.replace(tr.mapping.slice(mapFrom).map(from + tableStart), tr.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row - top], 0, 0));\n\t}\n\trecomp();\n\ttr.setSelection(new CellSelection(tr.doc.resolve(tableStart + map.positionAt(top, left, table)), tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table))));\n\tdispatch(tr);\n}\n\n//#endregion\n//#region src/input.ts\nconst handleKeyDown = keydownHandler({\n\tArrowLeft: arrow(\"horiz\", -1),\n\tArrowRight: arrow(\"horiz\", 1),\n\tArrowUp: arrow(\"vert\", -1),\n\tArrowDown: arrow(\"vert\", 1),\n\t\"Shift-ArrowLeft\": shiftArrow(\"horiz\", -1),\n\t\"Shift-ArrowRight\": shiftArrow(\"horiz\", 1),\n\t\"Shift-ArrowUp\": shiftArrow(\"vert\", -1),\n\t\"Shift-ArrowDown\": shiftArrow(\"vert\", 1),\n\tBackspace: deleteCellSelection,\n\t\"Mod-Backspace\": deleteCellSelection,\n\tDelete: deleteCellSelection,\n\t\"Mod-Delete\": deleteCellSelection\n});\nfunction maybeSetSelection(state, dispatch, selection) {\n\tif (selection.eq(state.selection)) return false;\n\tif (dispatch) dispatch(state.tr.setSelection(selection).scrollIntoView());\n\treturn true;\n}\n/**\n* @internal\n*/\nfunction arrow(axis, dir) {\n\treturn (state, dispatch, view) => {\n\t\tif (!view) return false;\n\t\tconst sel = state.selection;\n\t\tif (sel instanceof CellSelection) return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir));\n\t\tif (axis != \"horiz\" && !sel.empty) return false;\n\t\tconst end = atEndOfCell(view, axis, dir);\n\t\tif (end == null) return false;\n\t\tif (axis == \"horiz\") return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir));\n\t\telse {\n\t\t\tconst $cell = state.doc.resolve(end);\n\t\t\tconst $next = nextCell($cell, axis, dir);\n\t\t\tlet newSel;\n\t\t\tif ($next) newSel = Selection.near($next, 1);\n\t\t\telse if (dir < 0) newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);\n\t\t\telse newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);\n\t\t\treturn maybeSetSelection(state, dispatch, newSel);\n\t\t}\n\t};\n}\nfunction shiftArrow(axis, dir) {\n\treturn (state, dispatch, view) => {\n\t\tif (!view) return false;\n\t\tconst sel = state.selection;\n\t\tlet cellSel;\n\t\tif (sel instanceof CellSelection) cellSel = sel;\n\t\telse {\n\t\t\tconst end = atEndOfCell(view, axis, dir);\n\t\t\tif (end == null) return false;\n\t\t\tcellSel = new CellSelection(state.doc.resolve(end));\n\t\t}\n\t\tconst $head = nextCell(cellSel.$headCell, axis, dir);\n\t\tif (!$head) return false;\n\t\treturn maybeSetSelection(state, dispatch, new CellSelection(cellSel.$anchorCell, $head));\n\t};\n}\nfunction handleTripleClick(view, pos) {\n\tconst doc = view.state.doc, $cell = cellAround(doc.resolve(pos));\n\tif (!$cell) return false;\n\tview.dispatch(view.state.tr.setSelection(new CellSelection($cell)));\n\treturn true;\n}\n/**\n* @public\n*/\nfunction handlePaste(view, _, slice) {\n\tif (!isInTable(view.state)) return false;\n\tlet cells = pastedCells(slice);\n\tconst sel = view.state.selection;\n\tif (sel instanceof CellSelection) {\n\t\tif (!cells) cells = {\n\t\t\twidth: 1,\n\t\t\theight: 1,\n\t\t\trows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice))]\n\t\t};\n\t\tconst table = sel.$anchorCell.node(-1);\n\t\tconst start = sel.$anchorCell.start(-1);\n\t\tconst rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start, sel.$headCell.pos - start);\n\t\tcells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);\n\t\tinsertCells(view.state, view.dispatch, start, rect, cells);\n\t\treturn true;\n\t} else if (cells) {\n\t\tconst $cell = selectionCell(view.state);\n\t\tconst start = $cell.start(-1);\n\t\tinsertCells(view.state, view.dispatch, start, TableMap.get($cell.node(-1)).findCell($cell.pos - start), cells);\n\t\treturn true;\n\t} else return false;\n}\nfunction handleMouseDown$1(view, startEvent) {\n\tvar _cellUnderMouse;\n\tif (startEvent.button != 0) return;\n\tif (startEvent.ctrlKey || startEvent.metaKey) return;\n\tconst startDOMCell = domInCell(view, startEvent.target);\n\tlet $anchor;\n\tif (startEvent.shiftKey && view.state.selection instanceof CellSelection) {\n\t\tsetCellSelection(view.state.selection.$anchorCell, startEvent);\n\t\tstartEvent.preventDefault();\n\t} else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_cellUnderMouse = cellUnderMouse(view, startEvent)) === null || _cellUnderMouse === void 0 ? void 0 : _cellUnderMouse.pos) != $anchor.pos) {\n\t\tsetCellSelection($anchor, startEvent);\n\t\tstartEvent.preventDefault();\n\t} else if (!startDOMCell) return;\n\tfunction setCellSelection($anchor$1, event) {\n\t\tlet $head = cellUnderMouse(view, event);\n\t\tconst starting = tableEditingKey.getState(view.state) == null;\n\t\tif (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1;\n\t\telse return;\n\t\tconst selection = new CellSelection($anchor$1, $head);\n\t\tif (starting || !view.state.selection.eq(selection)) {\n\t\t\tconst tr = view.state.tr.setSelection(selection);\n\t\t\tif (starting) tr.setMeta(tableEditingKey, $anchor$1.pos);\n\t\t\tview.dispatch(tr);\n\t\t}\n\t}\n\tfunction stop() {\n\t\tview.root.removeEventListener(\"mouseup\", stop);\n\t\tview.root.removeEventListener(\"dragstart\", stop);\n\t\tview.root.removeEventListener(\"mousemove\", move);\n\t\tif (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));\n\t}\n\tfunction move(_event) {\n\t\tconst event = _event;\n\t\tconst anchor = tableEditingKey.getState(view.state);\n\t\tlet $anchor$1;\n\t\tif (anchor != null) $anchor$1 = view.state.doc.resolve(anchor);\n\t\telse if (domInCell(view, event.target) != startDOMCell) {\n\t\t\t$anchor$1 = cellUnderMouse(view, startEvent);\n\t\t\tif (!$anchor$1) return stop();\n\t\t}\n\t\tif ($anchor$1) setCellSelection($anchor$1, event);\n\t}\n\tview.root.addEventListener(\"mouseup\", stop);\n\tview.root.addEventListener(\"dragstart\", stop);\n\tview.root.addEventListener(\"mousemove\", move);\n}\nfunction atEndOfCell(view, axis, dir) {\n\tif (!(view.state.selection instanceof TextSelection)) return null;\n\tconst { $head } = view.state.selection;\n\tfor (let d = $head.depth - 1; d >= 0; d--) {\n\t\tconst parent = $head.node(d);\n\t\tif ((dir < 0 ? $head.index(d) : $head.indexAfter(d)) != (dir < 0 ? 0 : parent.childCount)) return null;\n\t\tif (parent.type.spec.tableRole == \"cell\" || parent.type.spec.tableRole == \"header_cell\") {\n\t\t\tconst cellPos = $head.before(d);\n\t\t\tconst dirStr = axis == \"vert\" ? dir > 0 ? \"down\" : \"up\" : dir > 0 ? \"right\" : \"left\";\n\t\t\treturn view.endOfTextblock(dirStr) ? cellPos : null;\n\t\t}\n\t}\n\treturn null;\n}\nfunction domInCell(view, dom) {\n\tfor (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == \"TD\" || dom.nodeName == \"TH\") return dom;\n\treturn null;\n}\nfunction cellUnderMouse(view, event) {\n\tconst mousePos = view.posAtCoords({\n\t\tleft: event.clientX,\n\t\ttop: event.clientY\n\t});\n\tif (!mousePos) return null;\n\tlet { inside, pos } = mousePos;\n\treturn inside >= 0 && cellAround(view.state.doc.resolve(inside)) || cellAround(view.state.doc.resolve(pos));\n}\n\n//#endregion\n//#region src/tableview.ts\n/**\n* @public\n*/\nvar TableView = class {\n\tconstructor(node, defaultCellMinWidth) {\n\t\tthis.node = node;\n\t\tthis.defaultCellMinWidth = defaultCellMinWidth;\n\t\tthis.dom = document.createElement(\"div\");\n\t\tthis.dom.className = \"tableWrapper\";\n\t\tthis.table = this.dom.appendChild(document.createElement(\"table\"));\n\t\tthis.table.style.setProperty(\"--default-cell-min-width\", `${defaultCellMinWidth}px`);\n\t\tthis.colgroup = this.table.appendChild(document.createElement(\"colgroup\"));\n\t\tupdateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);\n\t\tthis.contentDOM = this.table.appendChild(document.createElement(\"tbody\"));\n\t}\n\tupdate(node) {\n\t\tif (node.type != this.node.type) return false;\n\t\tthis.node = node;\n\t\tupdateColumnsOnResize(node, this.colgroup, this.table, this.defaultCellMinWidth);\n\t\treturn true;\n\t}\n\tignoreMutation(record) {\n\t\treturn record.type == \"attributes\" && (record.target == this.table || this.colgroup.contains(record.target));\n\t}\n};\n/**\n* @public\n*/\nfunction updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {\n\tlet totalWidth = 0;\n\tlet fixedWidth = true;\n\tlet nextDOM = colgroup.firstChild;\n\tconst row = node.firstChild;\n\tif (!row) return;\n\tfor (let i = 0, col = 0; i < row.childCount; i++) {\n\t\tconst { colspan, colwidth } = row.child(i).attrs;\n\t\tfor (let j = 0; j < colspan; j++, col++) {\n\t\t\tconst hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j];\n\t\t\tconst cssWidth = hasWidth ? hasWidth + \"px\" : \"\";\n\t\t\ttotalWidth += hasWidth || defaultCellMinWidth;\n\t\t\tif (!hasWidth) fixedWidth = false;\n\t\t\tif (!nextDOM) {\n\t\t\t\tconst col$1 = document.createElement(\"col\");\n\t\t\t\tcol$1.style.width = cssWidth;\n\t\t\t\tcolgroup.appendChild(col$1);\n\t\t\t} else {\n\t\t\t\tif (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth;\n\t\t\t\tnextDOM = nextDOM.nextSibling;\n\t\t\t}\n\t\t}\n\t}\n\twhile (nextDOM) {\n\t\tvar _nextDOM$parentNode;\n\t\tconst after = nextDOM.nextSibling;\n\t\t(_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM);\n\t\tnextDOM = after;\n\t}\n\tif (fixedWidth) {\n\t\ttable.style.width = totalWidth + \"px\";\n\t\ttable.style.minWidth = \"\";\n\t} else {\n\t\ttable.style.width = \"\";\n\t\ttable.style.minWidth = totalWidth + \"px\";\n\t}\n}\n\n//#endregion\n//#region src/columnresizing.ts\n/**\n* @public\n*/\nconst columnResizingPluginKey = new PluginKey(\"tableColumnResizing\");\n/**\n* @public\n*/\nfunction columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCellMinWidth = 100, View = TableView, lastColumnResizable = true } = {}) {\n\tconst plugin = new Plugin({\n\t\tkey: columnResizingPluginKey,\n\t\tstate: {\n\t\t\tinit(_, state) {\n\t\t\t\tvar _plugin$spec;\n\t\t\t\tconst nodeViews = (_plugin$spec = plugin.spec) === null || _plugin$spec === void 0 || (_plugin$spec = _plugin$spec.props) === null || _plugin$spec === void 0 ? void 0 : _plugin$spec.nodeViews;\n\t\t\t\tconst tableName = tableNodeTypes(state.schema).table.name;\n\t\t\t\tif (View && nodeViews) nodeViews[tableName] = (node, view) => {\n\t\t\t\t\treturn new View(node, defaultCellMinWidth, view);\n\t\t\t\t};\n\t\t\t\treturn new ResizeState(-1, false);\n\t\t\t},\n\t\t\tapply(tr, prev) {\n\t\t\t\treturn prev.apply(tr);\n\t\t\t}\n\t\t},\n\t\tprops: {\n\t\t\tattributes: (state) => {\n\t\t\t\tconst pluginState = columnResizingPluginKey.getState(state);\n\t\t\t\treturn pluginState && pluginState.activeHandle > -1 ? { class: \"resize-cursor\" } : {};\n\t\t\t},\n\t\t\thandleDOMEvents: {\n\t\t\t\tmousemove: (view, event) => {\n\t\t\t\t\thandleMouseMove(view, event, handleWidth, lastColumnResizable);\n\t\t\t\t},\n\t\t\t\tmouseleave: (view) => {\n\t\t\t\t\thandleMouseLeave(view);\n\t\t\t\t},\n\t\t\t\tmousedown: (view, event) => {\n\t\t\t\t\thandleMouseDown(view, event, cellMinWidth, defaultCellMinWidth);\n\t\t\t\t}\n\t\t\t},\n\t\t\tdecorations: (state) => {\n\t\t\t\tconst pluginState = columnResizingPluginKey.getState(state);\n\t\t\t\tif (pluginState && pluginState.activeHandle > -1) return handleDecorations(state, pluginState.activeHandle);\n\t\t\t},\n\t\t\tnodeViews: {}\n\t\t}\n\t});\n\treturn plugin;\n}\n/**\n* @public\n*/\nvar ResizeState = class ResizeState {\n\tconstructor(activeHandle, dragging) {\n\t\tthis.activeHandle = activeHandle;\n\t\tthis.dragging = dragging;\n\t}\n\tapply(tr) {\n\t\tconst state = this;\n\t\tconst action = tr.getMeta(columnResizingPluginKey);\n\t\tif (action && action.setHandle != null) return new ResizeState(action.setHandle, false);\n\t\tif (action && action.setDragging !== void 0) return new ResizeState(state.activeHandle, action.setDragging);\n\t\tif (state.activeHandle > -1 && tr.docChanged) {\n\t\t\tlet handle = tr.mapping.map(state.activeHandle, -1);\n\t\t\tif (!pointsAtCell(tr.doc.resolve(handle))) handle = -1;\n\t\t\treturn new ResizeState(handle, state.dragging);\n\t\t}\n\t\treturn state;\n\t}\n};\nfunction handleMouseMove(view, event, handleWidth, lastColumnResizable) {\n\tif (!view.editable) return;\n\tconst pluginState = columnResizingPluginKey.getState(view.state);\n\tif (!pluginState) return;\n\tif (!pluginState.dragging) {\n\t\tconst target = domCellAround(event.target);\n\t\tlet cell = -1;\n\t\tif (target) {\n\t\t\tconst { left, right } = target.getBoundingClientRect();\n\t\t\tif (event.clientX - left <= handleWidth) cell = edgeCell(view, event, \"left\", handleWidth);\n\t\t\telse if (right - event.clientX <= handleWidth) cell = edgeCell(view, event, \"right\", handleWidth);\n\t\t}\n\t\tif (cell != pluginState.activeHandle) {\n\t\t\tif (!lastColumnResizable && cell !== -1) {\n\t\t\t\tconst $cell = view.state.doc.resolve(cell);\n\t\t\t\tconst table = $cell.node(-1);\n\t\t\t\tconst map = TableMap.get(table);\n\t\t\t\tconst tableStart = $cell.start(-1);\n\t\t\t\tif (map.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map.width - 1) return;\n\t\t\t}\n\t\t\tupdateHandle(view, cell);\n\t\t}\n\t}\n}\nfunction handleMouseLeave(view) {\n\tif (!view.editable) return;\n\tconst pluginState = columnResizingPluginKey.getState(view.state);\n\tif (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1);\n}\nfunction handleMouseDown(view, event, cellMinWidth, defaultCellMinWidth) {\n\tvar _view$dom$ownerDocume;\n\tif (!view.editable) return false;\n\tconst win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window;\n\tconst pluginState = columnResizingPluginKey.getState(view.state);\n\tif (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false;\n\tconst cell = view.state.doc.nodeAt(pluginState.activeHandle);\n\tconst width = currentColWidth(view, pluginState.activeHandle, cell.attrs);\n\tview.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: {\n\t\tstartX: event.clientX,\n\t\tstartWidth: width\n\t} }));\n\tfunction finish(event$1) {\n\t\twin.removeEventListener(\"mouseup\", finish);\n\t\twin.removeEventListener(\"mousemove\", move);\n\t\tconst pluginState$1 = columnResizingPluginKey.getState(view.state);\n\t\tif (pluginState$1 === null || pluginState$1 === void 0 ? void 0 : pluginState$1.dragging) {\n\t\t\tupdateColumnWidth(view, pluginState$1.activeHandle, draggedWidth(pluginState$1.dragging, event$1, cellMinWidth));\n\t\t\tview.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null }));\n\t\t}\n\t}\n\tfunction move(event$1) {\n\t\tif (!event$1.which) return finish(event$1);\n\t\tconst pluginState$1 = columnResizingPluginKey.getState(view.state);\n\t\tif (!pluginState$1) return;\n\t\tif (pluginState$1.dragging) {\n\t\t\tconst dragged = draggedWidth(pluginState$1.dragging, event$1, cellMinWidth);\n\t\t\tdisplayColumnWidth(view, pluginState$1.activeHandle, dragged, defaultCellMinWidth);\n\t\t}\n\t}\n\tdisplayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth);\n\twin.addEventListener(\"mouseup\", finish);\n\twin.addEventListener(\"mousemove\", move);\n\tevent.preventDefault();\n\treturn true;\n}\nfunction currentColWidth(view, cellPos, { colspan, colwidth }) {\n\tconst width = colwidth && colwidth[colwidth.length - 1];\n\tif (width) return width;\n\tconst dom = view.domAtPos(cellPos);\n\tlet domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan;\n\tif (colwidth) {\n\t\tfor (let i = 0; i < colspan; i++) if (colwidth[i]) {\n\t\t\tdomWidth -= colwidth[i];\n\t\t\tparts--;\n\t\t}\n\t}\n\treturn domWidth / parts;\n}\nfunction domCellAround(target) {\n\twhile (target && target.nodeName != \"TD\" && target.nodeName != \"TH\") target = target.classList && target.classList.contains(\"ProseMirror\") ? null : target.parentNode;\n\treturn target;\n}\nfunction edgeCell(view, event, side, handleWidth) {\n\tconst offset = side == \"right\" ? -handleWidth : handleWidth;\n\tconst found = view.posAtCoords({\n\t\tleft: event.clientX + offset,\n\t\ttop: event.clientY\n\t});\n\tif (!found) return -1;\n\tconst { pos } = found;\n\tconst $cell = cellAround(view.state.doc.resolve(pos));\n\tif (!$cell) return -1;\n\tif (side == \"right\") return $cell.pos;\n\tconst map = TableMap.get($cell.node(-1)), start = $cell.start(-1);\n\tconst index = map.map.indexOf($cell.pos - start);\n\treturn index % map.width == 0 ? -1 : start + map.map[index - 1];\n}\nfunction draggedWidth(dragging, event, resizeMinWidth) {\n\tconst offset = event.clientX - dragging.startX;\n\treturn Math.max(resizeMinWidth, dragging.startWidth + offset);\n}\nfunction updateHandle(view, value) {\n\tview.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value }));\n}\nfunction updateColumnWidth(view, cell, width) {\n\tconst $cell = view.state.doc.resolve(cell);\n\tconst table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);\n\tconst col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;\n\tconst tr = view.state.tr;\n\tfor (let row = 0; row < map.height; row++) {\n\t\tconst mapIndex = row * map.width + col;\n\t\tif (row && map.map[mapIndex] == map.map[mapIndex - map.width]) continue;\n\t\tconst pos = map.map[mapIndex];\n\t\tconst attrs = table.nodeAt(pos).attrs;\n\t\tconst index = attrs.colspan == 1 ? 0 : col - map.colCount(pos);\n\t\tif (attrs.colwidth && attrs.colwidth[index] == width) continue;\n\t\tconst colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);\n\t\tcolwidth[index] = width;\n\t\ttr.setNodeMarkup(start + pos, null, {\n\t\t\t...attrs,\n\t\t\tcolwidth\n\t\t});\n\t}\n\tif (tr.docChanged) view.dispatch(tr);\n}\nfunction displayColumnWidth(view, cell, width, defaultCellMinWidth) {\n\tconst $cell = view.state.doc.resolve(cell);\n\tconst table = $cell.node(-1), start = $cell.start(-1);\n\tconst col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;\n\tlet dom = view.domAtPos($cell.start(-1)).node;\n\twhile (dom && dom.nodeName != \"TABLE\") dom = dom.parentNode;\n\tif (!dom) return;\n\tupdateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width);\n}\nfunction zeroes(n) {\n\treturn Array(n).fill(0);\n}\nfunction handleDecorations(state, cell) {\n\tconst decorations = [];\n\tconst $cell = state.doc.resolve(cell);\n\tconst table = $cell.node(-1);\n\tif (!table) return DecorationSet.empty;\n\tconst map = TableMap.get(table);\n\tconst start = $cell.start(-1);\n\tconst col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;\n\tfor (let row = 0; row < map.height; row++) {\n\t\tconst index = col + row * map.width;\n\t\tif ((col == map.width - 1 || map.map[index] != map.map[index + 1]) && (row == 0 || map.map[index] != map.map[index - map.width])) {\n\t\t\tvar _columnResizingPlugin;\n\t\t\tconst cellPos = map.map[index];\n\t\t\tconst pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;\n\t\t\tconst dom = document.createElement(\"div\");\n\t\t\tdom.className = \"column-resize-handle\";\n\t\t\tif ((_columnResizingPlugin = columnResizingPluginKey.getState(state)) === null || _columnResizingPlugin === void 0 ? void 0 : _columnResizingPlugin.dragging) decorations.push(Decoration.node(start + cellPos, start + cellPos + table.nodeAt(cellPos).nodeSize, { class: \"column-resize-dragging\" }));\n\t\t\tdecorations.push(Decoration.widget(pos, dom));\n\t\t}\n\t}\n\treturn DecorationSet.create(state.doc, decorations);\n}\n\n//#endregion\n//#region src/index.ts\n/**\n* Creates a [plugin](http://prosemirror.net/docs/ref/#state.Plugin)\n* that, when added to an editor, enables cell-selection, handles\n* cell-based copy/paste, and makes sure tables stay well-formed (each\n* row has the same width, and cells don't overlap).\n*\n* You should probably put this plugin near the end of your array of\n* plugins, since it handles mouse and arrow key events in tables\n* rather broadly, and other plugins, like the gap cursor or the\n* column-width dragging plugin, might want to get a turn first to\n* perform more specific behavior.\n*\n* @public\n*/\nfunction tableEditing({ allowTableNodeSelection = false } = {}) {\n\treturn new Plugin({\n\t\tkey: tableEditingKey,\n\t\tstate: {\n\t\t\tinit() {\n\t\t\t\treturn null;\n\t\t\t},\n\t\t\tapply(tr, cur) {\n\t\t\t\tconst set = tr.getMeta(tableEditingKey);\n\t\t\t\tif (set != null) return set == -1 ? null : set;\n\t\t\t\tif (cur == null || !tr.docChanged) return cur;\n\t\t\t\tconst { deleted, pos } = tr.mapping.mapResult(cur);\n\t\t\t\treturn deleted ? null : pos;\n\t\t\t}\n\t\t},\n\t\tprops: {\n\t\t\tdecorations: drawCellSelection,\n\t\t\thandleDOMEvents: { mousedown: handleMouseDown$1 },\n\t\t\tcreateSelectionBetween(view) {\n\t\t\t\treturn tableEditingKey.getState(view.state) != null ? view.state.selection : null;\n\t\t\t},\n\t\t\thandleTripleClick,\n\t\t\thandleKeyDown,\n\t\t\thandlePaste\n\t\t},\n\t\tappendTransaction(_, oldState, state) {\n\t\t\treturn normalizeSelection(state, fixTables(state, oldState), allowTableNodeSelection);\n\t\t}\n\t});\n}\n\n//#endregion\nexport { CellBookmark, CellSelection, ResizeState, TableMap, TableView, clipCells as __clipCells, insertCells as __insertCells, pastedCells as __pastedCells, addColSpan, addColumn, addColumnAfter, addColumnBefore, addRow, addRowAfter, addRowBefore, cellAround, cellNear, colCount, columnIsHeader, columnResizing, columnResizingPluginKey, deleteCellSelection, deleteColumn, deleteRow, deleteTable, findCell, findCellPos, findCellRange, findTable, fixTables, fixTablesKey, goToNextCell, handlePaste, inSameTable, isInTable, mergeCells, moveCellForward, moveTableColumn, moveTableRow, nextCell, pointsAtCell, removeColSpan, removeColumn, removeRow, rowIsHeader, selectedRect, selectionCell, setCellAttr, splitCell, splitCellWithType, tableEditing, tableEditingKey, tableNodeTypes, tableNodes, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, updateColumnsOnResize };\n//# sourceMappingURL=index.js.map","import { ReplaceError, Slice, Fragment, MarkType, Mark } from 'prosemirror-model';\n\n// Recovery values encode a range index and an offset. They are\n// represented as numbers, because tons of them will be created when\n// mapping, for example, a large number of decorations. The number's\n// lower 16 bits provide the index, the remaining bits the offset.\n//\n// Note: We intentionally don't use bit shift operators to en- and\n// decode these, since those clip to 32 bits, which we might in rare\n// cases want to overflow. A 64-bit float can represent 48-bit\n// integers precisely.\nconst lower16 = 0xffff;\nconst factor16 = Math.pow(2, 16);\nfunction makeRecover(index, offset) { return index + offset * factor16; }\nfunction recoverIndex(value) { return value & lower16; }\nfunction recoverOffset(value) { return (value - (value & lower16)) / factor16; }\nconst DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8;\n/**\nAn object representing a mapped position with extra\ninformation.\n*/\nclass MapResult {\n    /**\n    @internal\n    */\n    constructor(\n    /**\n    The mapped version of the position.\n    */\n    pos, \n    /**\n    @internal\n    */\n    delInfo, \n    /**\n    @internal\n    */\n    recover) {\n        this.pos = pos;\n        this.delInfo = delInfo;\n        this.recover = recover;\n    }\n    /**\n    Tells you whether the position was deleted, that is, whether the\n    step removed the token on the side queried (via the `assoc`)\n    argument from the document.\n    */\n    get deleted() { return (this.delInfo & DEL_SIDE) > 0; }\n    /**\n    Tells you whether the token before the mapped position was deleted.\n    */\n    get deletedBefore() { return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; }\n    /**\n    True when the token after the mapped position was deleted.\n    */\n    get deletedAfter() { return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; }\n    /**\n    Tells whether any of the steps mapped through deletes across the\n    position (including both the token before and after the\n    position).\n    */\n    get deletedAcross() { return (this.delInfo & DEL_ACROSS) > 0; }\n}\n/**\nA map describing the deletions and insertions made by a step, which\ncan be used to find the correspondence between positions in the\npre-step version of a document and the same position in the\npost-step version.\n*/\nclass StepMap {\n    /**\n    Create a position map. The modifications to the document are\n    represented as an array of numbers, in which each group of three\n    represents a modified chunk as `[start, oldSize, newSize]`.\n    */\n    constructor(\n    /**\n    @internal\n    */\n    ranges, \n    /**\n    @internal\n    */\n    inverted = false) {\n        this.ranges = ranges;\n        this.inverted = inverted;\n        if (!ranges.length && StepMap.empty)\n            return StepMap.empty;\n    }\n    /**\n    @internal\n    */\n    recover(value) {\n        let diff = 0, index = recoverIndex(value);\n        if (!this.inverted)\n            for (let i = 0; i < index; i++)\n                diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];\n        return this.ranges[index * 3] + diff + recoverOffset(value);\n    }\n    mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }\n    map(pos, assoc = 1) { return this._map(pos, assoc, true); }\n    /**\n    @internal\n    */\n    _map(pos, assoc, simple) {\n        let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;\n        for (let i = 0; i < this.ranges.length; i += 3) {\n            let start = this.ranges[i] - (this.inverted ? diff : 0);\n            if (start > pos)\n                break;\n            let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;\n            if (pos <= end) {\n                let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;\n                let result = start + diff + (side < 0 ? 0 : newSize);\n                if (simple)\n                    return result;\n                let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);\n                let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;\n                if (assoc < 0 ? pos != start : pos != end)\n                    del |= DEL_SIDE;\n                return new MapResult(result, del, recover);\n            }\n            diff += newSize - oldSize;\n        }\n        return simple ? pos + diff : new MapResult(pos + diff, 0, null);\n    }\n    /**\n    @internal\n    */\n    touches(pos, recover) {\n        let diff = 0, index = recoverIndex(recover);\n        let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;\n        for (let i = 0; i < this.ranges.length; i += 3) {\n            let start = this.ranges[i] - (this.inverted ? diff : 0);\n            if (start > pos)\n                break;\n            let oldSize = this.ranges[i + oldIndex], end = start + oldSize;\n            if (pos <= end && i == index * 3)\n                return true;\n            diff += this.ranges[i + newIndex] - oldSize;\n        }\n        return false;\n    }\n    /**\n    Calls the given function on each of the changed ranges included in\n    this map.\n    */\n    forEach(f) {\n        let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;\n        for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {\n            let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);\n            let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];\n            f(oldStart, oldStart + oldSize, newStart, newStart + newSize);\n            diff += newSize - oldSize;\n        }\n    }\n    /**\n    Create an inverted version of this map. The result can be used to\n    map positions in the post-step document to the pre-step document.\n    */\n    invert() {\n        return new StepMap(this.ranges, !this.inverted);\n    }\n    /**\n    @internal\n    */\n    toString() {\n        return (this.inverted ? \"-\" : \"\") + JSON.stringify(this.ranges);\n    }\n    /**\n    Create a map that moves all positions by offset `n` (which may be\n    negative). This can be useful when applying steps meant for a\n    sub-document to a larger document, or vice-versa.\n    */\n    static offset(n) {\n        return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);\n    }\n}\n/**\nA StepMap that contains no changed ranges.\n*/\nStepMap.empty = new StepMap([]);\n/**\nA mapping represents a pipeline of zero or more [step\nmaps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly\nhandling mapping positions through a series of steps in which some\nsteps are inverted versions of earlier steps. (This comes up when\n‘[rebasing](https://prosemirror.net/docs/guide/#transform.rebasing)’ steps for\ncollaboration or history management.)\n*/\nclass Mapping {\n    /**\n    Create a new mapping with the given position maps.\n    */\n    constructor(maps, \n    /**\n    @internal\n    */\n    mirror, \n    /**\n    The starting position in the `maps` array, used when `map` or\n    `mapResult` is called.\n    */\n    from = 0, \n    /**\n    The end position in the `maps` array.\n    */\n    to = maps ? maps.length : 0) {\n        this.mirror = mirror;\n        this.from = from;\n        this.to = to;\n        this._maps = maps || [];\n        this.ownData = !(maps || mirror);\n    }\n    /**\n    The step maps in this mapping.\n    */\n    get maps() { return this._maps; }\n    /**\n    Create a mapping that maps only through a part of this one.\n    */\n    slice(from = 0, to = this.maps.length) {\n        return new Mapping(this._maps, this.mirror, from, to);\n    }\n    /**\n    Add a step map to the end of this mapping. If `mirrors` is\n    given, it should be the index of the step map that is the mirror\n    image of this one.\n    */\n    appendMap(map, mirrors) {\n        if (!this.ownData) {\n            this._maps = this._maps.slice();\n            this.mirror = this.mirror && this.mirror.slice();\n            this.ownData = true;\n        }\n        this.to = this._maps.push(map);\n        if (mirrors != null)\n            this.setMirror(this._maps.length - 1, mirrors);\n    }\n    /**\n    Add all the step maps in a given mapping to this one (preserving\n    mirroring information).\n    */\n    appendMapping(mapping) {\n        for (let i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) {\n            let mirr = mapping.getMirror(i);\n            this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);\n        }\n    }\n    /**\n    Finds the offset of the step map that mirrors the map at the\n    given offset, in this mapping (as per the second argument to\n    `appendMap`).\n    */\n    getMirror(n) {\n        if (this.mirror)\n            for (let i = 0; i < this.mirror.length; i++)\n                if (this.mirror[i] == n)\n                    return this.mirror[i + (i % 2 ? -1 : 1)];\n    }\n    /**\n    @internal\n    */\n    setMirror(n, m) {\n        if (!this.mirror)\n            this.mirror = [];\n        this.mirror.push(n, m);\n    }\n    /**\n    Append the inverse of the given mapping to this one.\n    */\n    appendMappingInverted(mapping) {\n        for (let i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) {\n            let mirr = mapping.getMirror(i);\n            this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);\n        }\n    }\n    /**\n    Create an inverted version of this mapping.\n    */\n    invert() {\n        let inverse = new Mapping;\n        inverse.appendMappingInverted(this);\n        return inverse;\n    }\n    /**\n    Map a position through this mapping.\n    */\n    map(pos, assoc = 1) {\n        if (this.mirror)\n            return this._map(pos, assoc, true);\n        for (let i = this.from; i < this.to; i++)\n            pos = this._maps[i].map(pos, assoc);\n        return pos;\n    }\n    /**\n    Map a position through this mapping, returning a mapping\n    result.\n    */\n    mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }\n    /**\n    @internal\n    */\n    _map(pos, assoc, simple) {\n        let delInfo = 0;\n        for (let i = this.from; i < this.to; i++) {\n            let map = this._maps[i], result = map.mapResult(pos, assoc);\n            if (result.recover != null) {\n                let corr = this.getMirror(i);\n                if (corr != null && corr > i && corr < this.to) {\n                    i = corr;\n                    pos = this._maps[corr].recover(result.recover);\n                    continue;\n                }\n            }\n            delInfo |= result.delInfo;\n            pos = result.pos;\n        }\n        return simple ? pos : new MapResult(pos, delInfo, null);\n    }\n}\n\nconst stepsByID = Object.create(null);\n/**\nA step object represents an atomic change. It generally applies\nonly to the document it was created for, since the positions\nstored in it will only make sense for that document.\n\nNew steps are defined by creating classes that extend `Step`,\noverriding the `apply`, `invert`, `map`, `getMap` and `fromJSON`\nmethods, and registering your class with a unique\nJSON-serialization identifier using\n[`Step.jsonID`](https://prosemirror.net/docs/ref/#transform.Step^jsonID).\n*/\nclass Step {\n    /**\n    Get the step map that represents the changes made by this step,\n    and which can be used to transform between positions in the old\n    and the new document.\n    */\n    getMap() { return StepMap.empty; }\n    /**\n    Try to merge this step with another one, to be applied directly\n    after it. Returns the merged step when possible, null if the\n    steps can't be merged.\n    */\n    merge(other) { return null; }\n    /**\n    Deserialize a step from its JSON representation. Will call\n    through to the step class' own implementation of this method.\n    */\n    static fromJSON(schema, json) {\n        if (!json || !json.stepType)\n            throw new RangeError(\"Invalid input for Step.fromJSON\");\n        let type = stepsByID[json.stepType];\n        if (!type)\n            throw new RangeError(`No step type ${json.stepType} defined`);\n        return type.fromJSON(schema, json);\n    }\n    /**\n    To be able to serialize steps to JSON, each step needs a string\n    ID to attach to its JSON representation. Use this method to\n    register an ID for your step classes. Try to pick something\n    that's unlikely to clash with steps from other modules.\n    */\n    static jsonID(id, stepClass) {\n        if (id in stepsByID)\n            throw new RangeError(\"Duplicate use of step JSON ID \" + id);\n        stepsByID[id] = stepClass;\n        stepClass.prototype.jsonID = id;\n        return stepClass;\n    }\n}\n/**\nThe result of [applying](https://prosemirror.net/docs/ref/#transform.Step.apply) a step. Contains either a\nnew document or a failure value.\n*/\nclass StepResult {\n    /**\n    @internal\n    */\n    constructor(\n    /**\n    The transformed document, if successful.\n    */\n    doc, \n    /**\n    The failure message, if unsuccessful.\n    */\n    failed) {\n        this.doc = doc;\n        this.failed = failed;\n    }\n    /**\n    Create a successful step result.\n    */\n    static ok(doc) { return new StepResult(doc, null); }\n    /**\n    Create a failed step result.\n    */\n    static fail(message) { return new StepResult(null, message); }\n    /**\n    Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given\n    arguments. Create a successful result if it succeeds, and a\n    failed one if it throws a `ReplaceError`.\n    */\n    static fromReplace(doc, from, to, slice) {\n        try {\n            return StepResult.ok(doc.replace(from, to, slice));\n        }\n        catch (e) {\n            if (e instanceof ReplaceError)\n                return StepResult.fail(e.message);\n            throw e;\n        }\n    }\n}\n\nfunction mapFragment(fragment, f, parent) {\n    let mapped = [];\n    for (let i = 0; i < fragment.childCount; i++) {\n        let child = fragment.child(i);\n        if (child.content.size)\n            child = child.copy(mapFragment(child.content, f, child));\n        if (child.isInline)\n            child = f(child, parent, i);\n        mapped.push(child);\n    }\n    return Fragment.fromArray(mapped);\n}\n/**\nAdd a mark to all inline content between two positions.\n*/\nclass AddMarkStep extends Step {\n    /**\n    Create a mark step.\n    */\n    constructor(\n    /**\n    The start of the marked range.\n    */\n    from, \n    /**\n    The end of the marked range.\n    */\n    to, \n    /**\n    The mark to add.\n    */\n    mark) {\n        super();\n        this.from = from;\n        this.to = to;\n        this.mark = mark;\n    }\n    apply(doc) {\n        let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);\n        let parent = $from.node($from.sharedDepth(this.to));\n        let slice = new Slice(mapFragment(oldSlice.content, (node, parent) => {\n            if (!node.isAtom || !parent.type.allowsMarkType(this.mark.type))\n                return node;\n            return node.mark(this.mark.addToSet(node.marks));\n        }, parent), oldSlice.openStart, oldSlice.openEnd);\n        return StepResult.fromReplace(doc, this.from, this.to, slice);\n    }\n    invert() {\n        return new RemoveMarkStep(this.from, this.to, this.mark);\n    }\n    map(mapping) {\n        let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);\n        if (from.deleted && to.deleted || from.pos >= to.pos)\n            return null;\n        return new AddMarkStep(from.pos, to.pos, this.mark);\n    }\n    merge(other) {\n        if (other instanceof AddMarkStep &&\n            other.mark.eq(this.mark) &&\n            this.from <= other.to && this.to >= other.from)\n            return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);\n        return null;\n    }\n    toJSON() {\n        return { stepType: \"addMark\", mark: this.mark.toJSON(),\n            from: this.from, to: this.to };\n    }\n    /**\n    @internal\n    */\n    static fromJSON(schema, json) {\n        if (typeof json.from != \"number\" || typeof json.to != \"number\")\n            throw new RangeError(\"Invalid input for AddMarkStep.fromJSON\");\n        return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));\n    }\n}\nStep.jsonID(\"addMark\", AddMarkStep);\n/**\nRemove a mark from all inline content between two positions.\n*/\nclass RemoveMarkStep extends Step {\n    /**\n    Create a mark-removing step.\n    */\n    constructor(\n    /**\n    The start of the unmarked range.\n    */\n    from, \n    /**\n    The end of the unmarked range.\n    */\n    to, \n    /**\n    The mark to remove.\n    */\n    mark) {\n        super();\n        this.from = from;\n        this.to = to;\n        this.mark = mark;\n    }\n    apply(doc) {\n        let oldSlice = doc.slice(this.from, this.to);\n        let slice = new Slice(mapFragment(oldSlice.content, node => {\n            return node.mark(this.mark.removeFromSet(node.marks));\n        }, doc), oldSlice.openStart, oldSlice.openEnd);\n        return StepResult.fromReplace(doc, this.from, this.to, slice);\n    }\n    invert() {\n        return new AddMarkStep(this.from, this.to, this.mark);\n    }\n    map(mapping) {\n        let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);\n        if (from.deleted && to.deleted || from.pos >= to.pos)\n            return null;\n        return new RemoveMarkStep(from.pos, to.pos, this.mark);\n    }\n    merge(other) {\n        if (other instanceof RemoveMarkStep &&\n            other.mark.eq(this.mark) &&\n            this.from <= other.to && this.to >= other.from)\n            return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);\n        return null;\n    }\n    toJSON() {\n        return { stepType: \"removeMark\", mark: this.mark.toJSON(),\n            from: this.from, to: this.to };\n    }\n    /**\n    @internal\n    */\n    static fromJSON(schema, json) {\n        if (typeof json.from != \"number\" || typeof json.to != \"number\")\n            throw new RangeError(\"Invalid input for RemoveMarkStep.fromJSON\");\n        return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));\n    }\n}\nStep.jsonID(\"removeMark\", RemoveMarkStep);\n/**\nAdd a mark to a specific node.\n*/\nclass AddNodeMarkStep extends Step {\n    /**\n    Create a node mark step.\n    */\n    constructor(\n    /**\n    The position of the target node.\n    */\n    pos, \n    /**\n    The mark to add.\n    */\n    mark) {\n        super();\n        this.pos = pos;\n        this.mark = mark;\n    }\n    apply(doc) {\n        let node = doc.nodeAt(this.pos);\n        if (!node)\n            return StepResult.fail(\"No node at mark step's position\");\n        let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));\n        return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));\n    }\n    invert(doc) {\n        let node = doc.nodeAt(this.pos);\n        if (node) {\n            let newSet = this.mark.addToSet(node.marks);\n            if (newSet.length == node.marks.length) {\n                for (let i = 0; i < node.marks.length; i++)\n                    if (!node.marks[i].isInSet(newSet))\n                        return new AddNodeMarkStep(this.pos, node.marks[i]);\n                return new AddNodeMarkStep(this.pos, this.mark);\n            }\n        }\n        return new RemoveNodeMarkStep(this.pos, this.mark);\n    }\n    map(mapping) {\n        let pos = mapping.mapResult(this.pos, 1);\n        return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);\n    }\n    toJSON() {\n        return { stepType: \"addNodeMark\", pos: this.pos, mark: this.mark.toJSON() };\n    }\n    /**\n    @internal\n    */\n    static fromJSON(schema, json) {\n        if (typeof json.pos != \"number\")\n            throw new RangeError(\"Invalid input for AddNodeMarkStep.fromJSON\");\n        return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));\n    }\n}\nStep.jsonID(\"addNodeMark\", AddNodeMarkStep);\n/**\nRemove a mark from a specific node.\n*/\nclass RemoveNodeMarkStep extends Step {\n    /**\n    Create a mark-removing step.\n    */\n    constructor(\n    /**\n    The position of the target node.\n    */\n    pos, \n    /**\n    The mark to remove.\n    */\n    mark) {\n        super();\n        this.pos = pos;\n        this.mark = mark;\n    }\n    apply(doc) {\n        let node = doc.nodeAt(this.pos);\n        if (!node)\n            return StepResult.fail(\"No node at mark step's position\");\n        let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));\n        return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));\n    }\n    invert(doc) {\n        let node = doc.nodeAt(this.pos);\n        if (!node || !this.mark.isInSet(node.marks))\n            return this;\n        return new AddNodeMarkStep(this.pos, this.mark);\n    }\n    map(mapping) {\n        let pos = mapping.mapResult(this.pos, 1);\n        return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);\n    }\n    toJSON() {\n        return { stepType: \"removeNodeMark\", pos: this.pos, mark: this.mark.toJSON() };\n    }\n    /**\n    @internal\n    */\n    static fromJSON(schema, json) {\n        if (typeof json.pos != \"number\")\n            throw new RangeError(\"Invalid input for RemoveNodeMarkStep.fromJSON\");\n        return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));\n    }\n}\nStep.jsonID(\"removeNodeMark\", RemoveNodeMarkStep);\n\n/**\nReplace a part of the document with a slice of new content.\n*/\nclass ReplaceStep extends Step {\n    /**\n    The given `slice` should fit the 'gap' between `from` and\n    `to`—the depths must line up, and the surrounding nodes must be\n    able to be joined with the open sides of the slice. When\n    `structure` is true, the step will fail if the content between\n    from and to is not just a sequence of closing and then opening\n    tokens (this is to guard against rebased replace steps\n    overwriting something they weren't supposed to).\n    */\n    constructor(\n    /**\n    The start position of the replaced range.\n    */\n    from, \n    /**\n    The end position of the replaced range.\n    */\n    to, \n    /**\n    The slice to insert.\n    */\n    slice, \n    /**\n    @internal\n    */\n    structure = false) {\n        super();\n        this.from = from;\n        this.to = to;\n        this.slice = slice;\n        this.structure = structure;\n    }\n    apply(doc) {\n        if (this.structure && contentBetween(doc, this.from, this.to))\n            return StepResult.fail(\"Structure replace would overwrite content\");\n        return StepResult.fromReplace(doc, this.from, this.to, this.slice);\n    }\n    getMap() {\n        return new StepMap([this.from, this.to - this.from, this.slice.size]);\n    }\n    invert(doc) {\n        return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));\n    }\n    map(mapping) {\n        let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);\n        if (from.deletedAcross && to.deletedAcross)\n            return null;\n        return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);\n    }\n    merge(other) {\n        if (!(other instanceof ReplaceStep) || other.structure || this.structure)\n            return null;\n        if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {\n            let slice = this.slice.size + other.slice.size == 0 ? Slice.empty\n                : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);\n            return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);\n        }\n        else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {\n            let slice = this.slice.size + other.slice.size == 0 ? Slice.empty\n                : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);\n            return new ReplaceStep(other.from, this.to, slice, this.structure);\n        }\n        else {\n            return null;\n        }\n    }\n    toJSON() {\n        let json = { stepType: \"replace\", from: this.from, to: this.to };\n        if (this.slice.size)\n            json.slice = this.slice.toJSON();\n        if (this.structure)\n            json.structure = true;\n        return json;\n    }\n    /**\n    @internal\n    */\n    static fromJSON(schema, json) {\n        if (typeof json.from != \"number\" || typeof json.to != \"number\")\n            throw new RangeError(\"Invalid input for ReplaceStep.fromJSON\");\n        return new ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);\n    }\n}\nStep.jsonID(\"replace\", ReplaceStep);\n/**\nReplace a part of the document with a slice of content, but\npreserve a range of the replaced content by moving it into the\nslice.\n*/\nclass ReplaceAroundStep extends Step {\n    /**\n    Create a replace-around step with the given range and gap.\n    `insert` should be the point in the slice into which the content\n    of the gap should be moved. `structure` has the same meaning as\n    it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.\n    */\n    constructor(\n    /**\n    The start position of the replaced range.\n    */\n    from, \n    /**\n    The end position of the replaced range.\n    */\n    to, \n    /**\n    The start of preserved range.\n    */\n    gapFrom, \n    /**\n    The end of preserved range.\n    */\n    gapTo, \n    /**\n    The slice to insert.\n    */\n    slice, \n    /**\n    The position in the slice where the preserved range should be\n    inserted.\n    */\n    insert, \n    /**\n    @internal\n    */\n    structure = false) {\n        super();\n        this.from = from;\n        this.to = to;\n        this.gapFrom = gapFrom;\n        this.gapTo = gapTo;\n        this.slice = slice;\n        this.insert = insert;\n        this.structure = structure;\n    }\n    apply(doc) {\n        if (this.structure && (contentBetween(doc, this.from, this.gapFrom) ||\n            contentBetween(doc, this.gapTo, this.to)))\n            return StepResult.fail(\"Structure gap-replace would overwrite content\");\n        let gap = doc.slice(this.gapFrom, this.gapTo);\n        if (gap.openStart || gap.openEnd)\n            return StepResult.fail(\"Gap is not a flat range\");\n        let inserted = this.slice.insertAt(this.insert, gap.content);\n        if (!inserted)\n            return StepResult.fail(\"Content does not fit in gap\");\n        return StepResult.fromReplace(doc, this.from, this.to, inserted);\n    }\n    getMap() {\n        return new StepMap([this.from, this.gapFrom - this.from, this.insert,\n            this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]);\n    }\n    invert(doc) {\n        let gap = this.gapTo - this.gapFrom;\n        return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);\n    }\n    map(mapping) {\n        let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);\n        let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);\n        let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);\n        if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos)\n            return null;\n        return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);\n    }\n    toJSON() {\n        let json = { stepType: \"replaceAround\", from: this.from, to: this.to,\n            gapFrom: this.gapFrom, gapTo: this.gapTo, insert: this.insert };\n        if (this.slice.size)\n            json.slice = this.slice.toJSON();\n        if (this.structure)\n            json.structure = true;\n        return json;\n    }\n    /**\n    @internal\n    */\n    static fromJSON(schema, json) {\n        if (typeof json.from != \"number\" || typeof json.to != \"number\" ||\n            typeof json.gapFrom != \"number\" || typeof json.gapTo != \"number\" || typeof json.insert != \"number\")\n            throw new RangeError(\"Invalid input for ReplaceAroundStep.fromJSON\");\n        return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);\n    }\n}\nStep.jsonID(\"replaceAround\", ReplaceAroundStep);\nfunction contentBetween(doc, from, to) {\n    let $from = doc.resolve(from), dist = to - from, depth = $from.depth;\n    while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {\n        depth--;\n        dist--;\n    }\n    if (dist > 0) {\n        let next = $from.node(depth).maybeChild($from.indexAfter(depth));\n        while (dist > 0) {\n            if (!next || next.isLeaf)\n                return true;\n            next = next.firstChild;\n            dist--;\n        }\n    }\n    return false;\n}\n\nfunction addMark(tr, from, to, mark) {\n    let removed = [], added = [];\n    let removing, adding;\n    tr.doc.nodesBetween(from, to, (node, pos, parent) => {\n        if (!node.isInline)\n            return;\n        let marks = node.marks;\n        if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {\n            let start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);\n            let newSet = mark.addToSet(marks);\n            for (let i = 0; i < marks.length; i++) {\n                if (!marks[i].isInSet(newSet)) {\n                    if (removing && removing.to == start && removing.mark.eq(marks[i]))\n                        removing.to = end;\n                    else\n                        removed.push(removing = new RemoveMarkStep(start, end, marks[i]));\n                }\n            }\n            if (adding && adding.to == start)\n                adding.to = end;\n            else\n                added.push(adding = new AddMarkStep(start, end, mark));\n        }\n    });\n    removed.forEach(s => tr.step(s));\n    added.forEach(s => tr.step(s));\n}\nfunction removeMark(tr, from, to, mark) {\n    let matched = [], step = 0;\n    tr.doc.nodesBetween(from, to, (node, pos) => {\n        if (!node.isInline)\n            return;\n        step++;\n        let toRemove = null;\n        if (mark instanceof MarkType) {\n            let set = node.marks, found;\n            while (found = mark.isInSet(set)) {\n                (toRemove || (toRemove = [])).push(found);\n                set = found.removeFromSet(set);\n            }\n        }\n        else if (mark) {\n            if (mark.isInSet(node.marks))\n                toRemove = [mark];\n        }\n        else {\n            toRemove = node.marks;\n        }\n        if (toRemove && toRemove.length) {\n            let end = Math.min(pos + node.nodeSize, to);\n            for (let i = 0; i < toRemove.length; i++) {\n                let style = toRemove[i], found;\n                for (let j = 0; j < matched.length; j++) {\n                    let m = matched[j];\n                    if (m.step == step - 1 && style.eq(matched[j].style))\n                        found = m;\n                }\n                if (found) {\n                    found.to = end;\n                    found.step = step;\n                }\n                else {\n                    matched.push({ style, from: Math.max(pos, from), to: end, step });\n                }\n            }\n        }\n    });\n    matched.forEach(m => tr.step(new RemoveMarkStep(m.from, m.to, m.style)));\n}\nfunction clearIncompatible(tr, pos, parentType, match = parentType.contentMatch, clearNewlines = true) {\n    let node = tr.doc.nodeAt(pos);\n    let replSteps = [], cur = pos + 1;\n    for (let i = 0; i < node.childCount; i++) {\n        let child = node.child(i), end = cur + child.nodeSize;\n        let allowed = match.matchType(child.type);\n        if (!allowed) {\n            replSteps.push(new ReplaceStep(cur, end, Slice.empty));\n        }\n        else {\n            match = allowed;\n            for (let j = 0; j < child.marks.length; j++)\n                if (!parentType.allowsMarkType(child.marks[j].type))\n                    tr.step(new RemoveMarkStep(cur, end, child.marks[j]));\n            if (clearNewlines && child.isText && parentType.whitespace != \"pre\") {\n                let m, newline = /\\r?\\n|\\r/g, slice;\n                while (m = newline.exec(child.text)) {\n                    if (!slice)\n                        slice = new Slice(Fragment.from(parentType.schema.text(\" \", parentType.allowedMarks(child.marks))), 0, 0);\n                    replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice));\n                }\n            }\n        }\n        cur = end;\n    }\n    if (!match.validEnd) {\n        let fill = match.fillBefore(Fragment.empty, true);\n        tr.replace(cur, cur, new Slice(fill, 0, 0));\n    }\n    for (let i = replSteps.length - 1; i >= 0; i--)\n        tr.step(replSteps[i]);\n}\n\nfunction canCut(node, start, end) {\n    return (start == 0 || node.canReplace(start, node.childCount)) &&\n        (end == node.childCount || node.canReplace(0, end));\n}\n/**\nTry to find a target depth to which the content in the given range\ncan be lifted. Will not go across\n[isolating](https://prosemirror.net/docs/ref/#model.NodeSpec.isolating) parent nodes.\n*/\nfunction liftTarget(range) {\n    let parent = range.parent;\n    let content = parent.content.cutByIndex(range.startIndex, range.endIndex);\n    for (let depth = range.depth, contentBefore = 0, contentAfter = 0;; --depth) {\n        let node = range.$from.node(depth);\n        let index = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter;\n        if (depth < range.depth && node.canReplace(index, endIndex, content))\n            return depth;\n        if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))\n            break;\n        if (index)\n            contentBefore = 1;\n        if (endIndex < node.childCount)\n            contentAfter = 1;\n    }\n    return null;\n}\nfunction lift(tr, range, target) {\n    let { $from, $to, depth } = range;\n    let gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1);\n    let start = gapStart, end = gapEnd;\n    let before = Fragment.empty, openStart = 0;\n    for (let d = depth, splitting = false; d > target; d--)\n        if (splitting || $from.index(d) > 0) {\n            splitting = true;\n            before = Fragment.from($from.node(d).copy(before));\n            openStart++;\n        }\n        else {\n            start--;\n        }\n    let after = Fragment.empty, openEnd = 0;\n    for (let d = depth, splitting = false; d > target; d--)\n        if (splitting || $to.after(d + 1) < $to.end(d)) {\n            splitting = true;\n            after = Fragment.from($to.node(d).copy(after));\n            openEnd++;\n        }\n        else {\n            end++;\n        }\n    tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));\n}\n/**\nTry to find a valid way to wrap the content in the given range in a\nnode of the given type. May introduce extra nodes around and inside\nthe wrapper node, if necessary. Returns null if no valid wrapping\ncould be found. When `innerRange` is given, that range's content is\nused as the content to fit into the wrapping, instead of the\ncontent of `range`.\n*/\nfunction findWrapping(range, nodeType, attrs = null, innerRange = range) {\n    let around = findWrappingOutside(range, nodeType);\n    let inner = around && findWrappingInside(innerRange, nodeType);\n    if (!inner)\n        return null;\n    return around.map(withAttrs)\n        .concat({ type: nodeType, attrs }).concat(inner.map(withAttrs));\n}\nfunction withAttrs(type) { return { type, attrs: null }; }\nfunction findWrappingOutside(range, type) {\n    let { parent, startIndex, endIndex } = range;\n    let around = parent.contentMatchAt(startIndex).findWrapping(type);\n    if (!around)\n        return null;\n    let outer = around.length ? around[0] : type;\n    return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null;\n}\nfunction findWrappingInside(range, type) {\n    let { parent, startIndex, endIndex } = range;\n    let inner = parent.child(startIndex);\n    let inside = type.contentMatch.findWrapping(inner.type);\n    if (!inside)\n        return null;\n    let lastType = inside.length ? inside[inside.length - 1] : type;\n    let innerMatch = lastType.contentMatch;\n    for (let i = startIndex; innerMatch && i < endIndex; i++)\n        innerMatch = innerMatch.matchType(parent.child(i).type);\n    if (!innerMatch || !innerMatch.validEnd)\n        return null;\n    return inside;\n}\nfunction wrap(tr, range, wrappers) {\n    let content = Fragment.empty;\n    for (let i = wrappers.length - 1; i >= 0; i--) {\n        if (content.size) {\n            let match = wrappers[i].type.contentMatch.matchFragment(content);\n            if (!match || !match.validEnd)\n                throw new RangeError(\"Wrapper type given to Transform.wrap does not form valid content of its parent wrapper\");\n        }\n        content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));\n    }\n    let start = range.start, end = range.end;\n    tr.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true));\n}\nfunction setBlockType(tr, from, to, type, attrs) {\n    if (!type.isTextblock)\n        throw new RangeError(\"Type given to setBlockType should be a textblock\");\n    let mapFrom = tr.steps.length;\n    tr.doc.nodesBetween(from, to, (node, pos) => {\n        let attrsHere = typeof attrs == \"function\" ? attrs(node) : attrs;\n        if (node.isTextblock && !node.hasMarkup(type, attrsHere) &&\n            canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) {\n            let convertNewlines = null;\n            if (type.schema.linebreakReplacement) {\n                let pre = type.whitespace == \"pre\", supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement);\n                if (pre && !supportLinebreak)\n                    convertNewlines = false;\n                else if (!pre && supportLinebreak)\n                    convertNewlines = true;\n            }\n            // Ensure all markup that isn't allowed in the new node type is cleared\n            if (convertNewlines === false)\n                replaceLinebreaks(tr, node, pos, mapFrom);\n            clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type, undefined, convertNewlines === null);\n            let mapping = tr.mapping.slice(mapFrom);\n            let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);\n            tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true));\n            if (convertNewlines === true)\n                replaceNewlines(tr, node, pos, mapFrom);\n            return false;\n        }\n    });\n}\nfunction replaceNewlines(tr, node, pos, mapFrom) {\n    node.forEach((child, offset) => {\n        if (child.isText) {\n            let m, newline = /\\r?\\n|\\r/g;\n            while (m = newline.exec(child.text)) {\n                let start = tr.mapping.slice(mapFrom).map(pos + 1 + offset + m.index);\n                tr.replaceWith(start, start + 1, node.type.schema.linebreakReplacement.create());\n            }\n        }\n    });\n}\nfunction replaceLinebreaks(tr, node, pos, mapFrom) {\n    node.forEach((child, offset) => {\n        if (child.type == child.type.schema.linebreakReplacement) {\n            let start = tr.mapping.slice(mapFrom).map(pos + 1 + offset);\n            tr.replaceWith(start, start + 1, node.type.schema.text(\"\\n\"));\n        }\n    });\n}\nfunction canChangeType(doc, pos, type) {\n    let $pos = doc.resolve(pos), index = $pos.index();\n    return $pos.parent.canReplaceWith(index, index + 1, type);\n}\n/**\nChange the type, attributes, and/or marks of the node at `pos`.\nWhen `type` isn't given, the existing node type is preserved,\n*/\nfunction setNodeMarkup(tr, pos, type, attrs, marks) {\n    let node = tr.doc.nodeAt(pos);\n    if (!node)\n        throw new RangeError(\"No node at given position\");\n    if (!type)\n        type = node.type;\n    let newNode = type.create(attrs, null, marks || node.marks);\n    if (node.isLeaf)\n        return tr.replaceWith(pos, pos + node.nodeSize, newNode);\n    if (!type.validContent(node.content))\n        throw new RangeError(\"Invalid content for node type \" + type.name);\n    tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));\n}\n/**\nCheck whether splitting at the given position is allowed.\n*/\nfunction canSplit(doc, pos, depth = 1, typesAfter) {\n    let $pos = doc.resolve(pos), base = $pos.depth - depth;\n    let innerType = (typesAfter && typesAfter[typesAfter.length - 1]) || $pos.parent;\n    if (base < 0 || $pos.parent.type.spec.isolating ||\n        !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) ||\n        !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount)))\n        return false;\n    for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) {\n        let node = $pos.node(d), index = $pos.index(d);\n        if (node.type.spec.isolating)\n            return false;\n        let rest = node.content.cutByIndex(index, node.childCount);\n        let overrideChild = typesAfter && typesAfter[i + 1];\n        if (overrideChild)\n            rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));\n        let after = (typesAfter && typesAfter[i]) || node;\n        if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))\n            return false;\n    }\n    let index = $pos.indexAfter(base);\n    let baseType = typesAfter && typesAfter[0];\n    return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type);\n}\nfunction split(tr, pos, depth = 1, typesAfter) {\n    let $pos = tr.doc.resolve(pos), before = Fragment.empty, after = Fragment.empty;\n    for (let d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) {\n        before = Fragment.from($pos.node(d).copy(before));\n        let typeAfter = typesAfter && typesAfter[i];\n        after = Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after));\n    }\n    tr.step(new ReplaceStep(pos, pos, new Slice(before.append(after), depth, depth), true));\n}\n/**\nTest whether the blocks before and after a given position can be\njoined.\n*/\nfunction canJoin(doc, pos) {\n    let $pos = doc.resolve(pos), index = $pos.index();\n    return joinable($pos.nodeBefore, $pos.nodeAfter) &&\n        $pos.parent.canReplace(index, index + 1);\n}\nfunction canAppendWithSubstitutedLinebreaks(a, b) {\n    if (!b.content.size)\n        a.type.compatibleContent(b.type);\n    let match = a.contentMatchAt(a.childCount);\n    let { linebreakReplacement } = a.type.schema;\n    for (let i = 0; i < b.childCount; i++) {\n        let child = b.child(i);\n        let type = child.type == linebreakReplacement ? a.type.schema.nodes.text : child.type;\n        match = match.matchType(type);\n        if (!match)\n            return false;\n        if (!a.type.allowsMarks(child.marks))\n            return false;\n    }\n    return match.validEnd;\n}\nfunction joinable(a, b) {\n    return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b));\n}\n/**\nFind an ancestor of the given position that can be joined to the\nblock before (or after if `dir` is positive). Returns the joinable\npoint, if any.\n*/\nfunction joinPoint(doc, pos, dir = -1) {\n    let $pos = doc.resolve(pos);\n    for (let d = $pos.depth;; d--) {\n        let before, after, index = $pos.index(d);\n        if (d == $pos.depth) {\n            before = $pos.nodeBefore;\n            after = $pos.nodeAfter;\n        }\n        else if (dir > 0) {\n            before = $pos.node(d + 1);\n            index++;\n            after = $pos.node(d).maybeChild(index);\n        }\n        else {\n            before = $pos.node(d).maybeChild(index - 1);\n            after = $pos.node(d + 1);\n        }\n        if (before && !before.isTextblock && joinable(before, after) &&\n            $pos.node(d).canReplace(index, index + 1))\n            return pos;\n        if (d == 0)\n            break;\n        pos = dir < 0 ? $pos.before(d) : $pos.after(d);\n    }\n}\nfunction join(tr, pos, depth) {\n    let convertNewlines = null;\n    let { linebreakReplacement } = tr.doc.type.schema;\n    let $before = tr.doc.resolve(pos - depth), beforeType = $before.node().type;\n    if (linebreakReplacement && beforeType.inlineContent) {\n        let pre = beforeType.whitespace == \"pre\";\n        let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement);\n        if (pre && !supportLinebreak)\n            convertNewlines = false;\n        else if (!pre && supportLinebreak)\n            convertNewlines = true;\n    }\n    let mapFrom = tr.steps.length;\n    if (convertNewlines === false) {\n        let $after = tr.doc.resolve(pos + depth);\n        replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom);\n    }\n    if (beforeType.inlineContent)\n        clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null);\n    let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos - depth);\n    tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), Slice.empty, true));\n    if (convertNewlines === true) {\n        let $full = tr.doc.resolve(start);\n        replaceNewlines(tr, $full.node(), $full.before(), tr.steps.length);\n    }\n    return tr;\n}\n/**\nTry to find a point where a node of the given type can be inserted\nnear `pos`, by searching up the node hierarchy when `pos` itself\nisn't a valid place but is at the start or end of a node. Return\nnull if no position was found.\n*/\nfunction insertPoint(doc, pos, nodeType) {\n    let $pos = doc.resolve(pos);\n    if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType))\n        return pos;\n    if ($pos.parentOffset == 0)\n        for (let d = $pos.depth - 1; d >= 0; d--) {\n            let index = $pos.index(d);\n            if ($pos.node(d).canReplaceWith(index, index, nodeType))\n                return $pos.before(d + 1);\n            if (index > 0)\n                return null;\n        }\n    if ($pos.parentOffset == $pos.parent.content.size)\n        for (let d = $pos.depth - 1; d >= 0; d--) {\n            let index = $pos.indexAfter(d);\n            if ($pos.node(d).canReplaceWith(index, index, nodeType))\n                return $pos.after(d + 1);\n            if (index < $pos.node(d).childCount)\n                return null;\n        }\n    return null;\n}\n/**\nFinds a position at or around the given position where the given\nslice can be inserted. Will look at parent nodes' nearest boundary\nand try there, even if the original position wasn't directly at the\nstart or end of that node. Returns null when no position was found.\n*/\nfunction dropPoint(doc, pos, slice) {\n    let $pos = doc.resolve(pos);\n    if (!slice.content.size)\n        return pos;\n    let content = slice.content;\n    for (let i = 0; i < slice.openStart; i++)\n        content = content.firstChild.content;\n    for (let pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) {\n        for (let d = $pos.depth; d >= 0; d--) {\n            let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;\n            let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);\n            let parent = $pos.node(d), fits = false;\n            if (pass == 1) {\n                fits = parent.canReplace(insertPos, insertPos, content);\n            }\n            else {\n                let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);\n                fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);\n            }\n            if (fits)\n                return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);\n        }\n    }\n    return null;\n}\n\n/**\n‘Fit’ a slice into a given position in the document, producing a\n[step](https://prosemirror.net/docs/ref/#transform.Step) that inserts it. Will return null if\nthere's no meaningful way to insert the slice here, or inserting it\nwould be a no-op (an empty slice over an empty range).\n*/\nfunction replaceStep(doc, from, to = from, slice = Slice.empty) {\n    if (from == to && !slice.size)\n        return null;\n    let $from = doc.resolve(from), $to = doc.resolve(to);\n    // Optimization -- avoid work if it's obvious that it's not needed.\n    if (fitsTrivially($from, $to, slice))\n        return new ReplaceStep(from, to, slice);\n    return new Fitter($from, $to, slice).fit();\n}\nfunction fitsTrivially($from, $to, slice) {\n    return !slice.openStart && !slice.openEnd && $from.start() == $to.start() &&\n        $from.parent.canReplace($from.index(), $to.index(), slice.content);\n}\n// Algorithm for 'placing' the elements of a slice into a gap:\n//\n// We consider the content of each node that is open to the left to be\n// independently placeable. I.e. in <p(\"foo\"), p(\"bar\")>, when the\n// paragraph on the left is open, \"foo\" can be placed (somewhere on\n// the left side of the replacement gap) independently from p(\"bar\").\n//\n// This class tracks the state of the placement progress in the\n// following properties:\n//\n//  - `frontier` holds a stack of `{type, match}` objects that\n//    represent the open side of the replacement. It starts at\n//    `$from`, then moves forward as content is placed, and is finally\n//    reconciled with `$to`.\n//\n//  - `unplaced` is a slice that represents the content that hasn't\n//    been placed yet.\n//\n//  - `placed` is a fragment of placed content. Its open-start value\n//    is implicit in `$from`, and its open-end value in `frontier`.\nclass Fitter {\n    constructor($from, $to, unplaced) {\n        this.$from = $from;\n        this.$to = $to;\n        this.unplaced = unplaced;\n        this.frontier = [];\n        this.placed = Fragment.empty;\n        for (let i = 0; i <= $from.depth; i++) {\n            let node = $from.node(i);\n            this.frontier.push({\n                type: node.type,\n                match: node.contentMatchAt($from.indexAfter(i))\n            });\n        }\n        for (let i = $from.depth; i > 0; i--)\n            this.placed = Fragment.from($from.node(i).copy(this.placed));\n    }\n    get depth() { return this.frontier.length - 1; }\n    fit() {\n        // As long as there's unplaced content, try to place some of it.\n        // If that fails, either increase the open score of the unplaced\n        // slice, or drop nodes from it, and then try again.\n        while (this.unplaced.size) {\n            let fit = this.findFittable();\n            if (fit)\n                this.placeNodes(fit);\n            else\n                this.openMore() || this.dropNode();\n        }\n        // When there's inline content directly after the frontier _and_\n        // directly after `this.$to`, we must generate a `ReplaceAround`\n        // step that pulls that content into the node after the frontier.\n        // That means the fitting must be done to the end of the textblock\n        // node after `this.$to`, not `this.$to` itself.\n        let moveInline = this.mustMoveInline(), placedSize = this.placed.size - this.depth - this.$from.depth;\n        let $from = this.$from, $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));\n        if (!$to)\n            return null;\n        // If closing to `$to` succeeded, create a step\n        let content = this.placed, openStart = $from.depth, openEnd = $to.depth;\n        while (openStart && openEnd && content.childCount == 1) { // Normalize by dropping open parent nodes\n            content = content.firstChild.content;\n            openStart--;\n            openEnd--;\n        }\n        let slice = new Slice(content, openStart, openEnd);\n        if (moveInline > -1)\n            return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);\n        if (slice.size || $from.pos != this.$to.pos) // Don't generate no-op steps\n            return new ReplaceStep($from.pos, $to.pos, slice);\n        return null;\n    }\n    // Find a position on the start spine of `this.unplaced` that has\n    // content that can be moved somewhere on the frontier. Returns two\n    // depths, one for the slice and one for the frontier.\n    findFittable() {\n        let startDepth = this.unplaced.openStart;\n        for (let cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) {\n            let node = cur.firstChild;\n            if (cur.childCount > 1)\n                openEnd = 0;\n            if (node.type.spec.isolating && openEnd <= d) {\n                startDepth = d;\n                break;\n            }\n            cur = node.content;\n        }\n        // Only try wrapping nodes (pass 2) after finding a place without\n        // wrapping failed.\n        for (let pass = 1; pass <= 2; pass++) {\n            for (let sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) {\n                let fragment, parent = null;\n                if (sliceDepth) {\n                    parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild;\n                    fragment = parent.content;\n                }\n                else {\n                    fragment = this.unplaced.content;\n                }\n                let first = fragment.firstChild;\n                for (let frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) {\n                    let { type, match } = this.frontier[frontierDepth], wrap, inject = null;\n                    // In pass 1, if the next node matches, or there is no next\n                    // node but the parents look compatible, we've found a\n                    // place.\n                    if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(Fragment.from(first), false))\n                        : parent && type.compatibleContent(parent.type)))\n                        return { sliceDepth, frontierDepth, parent, inject };\n                    // In pass 2, look for a set of wrapping nodes that make\n                    // `first` fit here.\n                    else if (pass == 2 && first && (wrap = match.findWrapping(first.type)))\n                        return { sliceDepth, frontierDepth, parent, wrap };\n                    // Don't continue looking further up if the parent node\n                    // would fit here.\n                    if (parent && match.matchType(parent.type))\n                        break;\n                }\n            }\n        }\n    }\n    openMore() {\n        let { content, openStart, openEnd } = this.unplaced;\n        let inner = contentAt(content, openStart);\n        if (!inner.childCount || inner.firstChild.isLeaf)\n            return false;\n        this.unplaced = new Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0));\n        return true;\n    }\n    dropNode() {\n        let { content, openStart, openEnd } = this.unplaced;\n        let inner = contentAt(content, openStart);\n        if (inner.childCount <= 1 && openStart > 0) {\n            let openAtEnd = content.size - openStart <= openStart + inner.size;\n            this.unplaced = new Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd);\n        }\n        else {\n            this.unplaced = new Slice(dropFromFragment(content, openStart, 1), openStart, openEnd);\n        }\n    }\n    // Move content from the unplaced slice at `sliceDepth` to the\n    // frontier node at `frontierDepth`. Close that frontier node when\n    // applicable.\n    placeNodes({ sliceDepth, frontierDepth, parent, inject, wrap }) {\n        while (this.depth > frontierDepth)\n            this.closeFrontierNode();\n        if (wrap)\n            for (let i = 0; i < wrap.length; i++)\n                this.openFrontierNode(wrap[i]);\n        let slice = this.unplaced, fragment = parent ? parent.content : slice.content;\n        let openStart = slice.openStart - sliceDepth;\n        let taken = 0, add = [];\n        let { match, type } = this.frontier[frontierDepth];\n        if (inject) {\n            for (let i = 0; i < inject.childCount; i++)\n                add.push(inject.child(i));\n            match = match.matchFragment(inject);\n        }\n        // Computes the amount of (end) open nodes at the end of the\n        // fragment. When 0, the parent is open, but no more. When\n        // negative, nothing is open.\n        let openEndCount = (fragment.size + sliceDepth) - (slice.content.size - slice.openEnd);\n        // Scan over the fragment, fitting as many child nodes as\n        // possible.\n        while (taken < fragment.childCount) {\n            let next = fragment.child(taken), matches = match.matchType(next.type);\n            if (!matches)\n                break;\n            taken++;\n            if (taken > 1 || openStart == 0 || next.content.size) { // Drop empty open nodes\n                match = matches;\n                add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1));\n            }\n        }\n        let toEnd = taken == fragment.childCount;\n        if (!toEnd)\n            openEndCount = -1;\n        this.placed = addToFragment(this.placed, frontierDepth, Fragment.from(add));\n        this.frontier[frontierDepth].match = match;\n        // If the parent types match, and the entire node was moved, and\n        // it's not open, close this frontier node right away.\n        if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1)\n            this.closeFrontierNode();\n        // Add new frontier nodes for any open nodes at the end.\n        for (let i = 0, cur = fragment; i < openEndCount; i++) {\n            let node = cur.lastChild;\n            this.frontier.push({ type: node.type, match: node.contentMatchAt(node.childCount) });\n            cur = node.content;\n        }\n        // Update `this.unplaced`. Drop the entire node from which we\n        // placed it we got to its end, otherwise just drop the placed\n        // nodes.\n        this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd)\n            : sliceDepth == 0 ? Slice.empty\n                : new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);\n    }\n    mustMoveInline() {\n        if (!this.$to.parent.isTextblock)\n            return -1;\n        let top = this.frontier[this.depth], level;\n        if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) ||\n            (this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth))\n            return -1;\n        let { depth } = this.$to, after = this.$to.after(depth);\n        while (depth > 1 && after == this.$to.end(--depth))\n            ++after;\n        return after;\n    }\n    findCloseLevel($to) {\n        scan: for (let i = Math.min(this.depth, $to.depth); i >= 0; i--) {\n            let { match, type } = this.frontier[i];\n            let dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1));\n            let fit = contentAfterFits($to, i, type, match, dropInner);\n            if (!fit)\n                continue;\n            for (let d = i - 1; d >= 0; d--) {\n                let { match, type } = this.frontier[d];\n                let matches = contentAfterFits($to, d, type, match, true);\n                if (!matches || matches.childCount)\n                    continue scan;\n            }\n            return { depth: i, fit, move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to };\n        }\n    }\n    close($to) {\n        let close = this.findCloseLevel($to);\n        if (!close)\n            return null;\n        while (this.depth > close.depth)\n            this.closeFrontierNode();\n        if (close.fit.childCount)\n            this.placed = addToFragment(this.placed, close.depth, close.fit);\n        $to = close.move;\n        for (let d = close.depth + 1; d <= $to.depth; d++) {\n            let node = $to.node(d), add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));\n            this.openFrontierNode(node.type, node.attrs, add);\n        }\n        return $to;\n    }\n    openFrontierNode(type, attrs = null, content) {\n        let top = this.frontier[this.depth];\n        top.match = top.match.matchType(type);\n        this.placed = addToFragment(this.placed, this.depth, Fragment.from(type.create(attrs, content)));\n        this.frontier.push({ type, match: type.contentMatch });\n    }\n    closeFrontierNode() {\n        let open = this.frontier.pop();\n        let add = open.match.fillBefore(Fragment.empty, true);\n        if (add.childCount)\n            this.placed = addToFragment(this.placed, this.frontier.length, add);\n    }\n}\nfunction dropFromFragment(fragment, depth, count) {\n    if (depth == 0)\n        return fragment.cutByIndex(count, fragment.childCount);\n    return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count)));\n}\nfunction addToFragment(fragment, depth, content) {\n    if (depth == 0)\n        return fragment.append(content);\n    return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content)));\n}\nfunction contentAt(fragment, depth) {\n    for (let i = 0; i < depth; i++)\n        fragment = fragment.firstChild.content;\n    return fragment;\n}\nfunction closeNodeStart(node, openStart, openEnd) {\n    if (openStart <= 0)\n        return node;\n    let frag = node.content;\n    if (openStart > 1)\n        frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0));\n    if (openStart > 0) {\n        frag = node.type.contentMatch.fillBefore(frag).append(frag);\n        if (openEnd <= 0)\n            frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(Fragment.empty, true));\n    }\n    return node.copy(frag);\n}\nfunction contentAfterFits($to, depth, type, match, open) {\n    let node = $to.node(depth), index = open ? $to.indexAfter(depth) : $to.index(depth);\n    if (index == node.childCount && !type.compatibleContent(node.type))\n        return null;\n    let fit = match.fillBefore(node.content, true, index);\n    return fit && !invalidMarks(type, node.content, index) ? fit : null;\n}\nfunction invalidMarks(type, fragment, start) {\n    for (let i = start; i < fragment.childCount; i++)\n        if (!type.allowsMarks(fragment.child(i).marks))\n            return true;\n    return false;\n}\nfunction definesContent(type) {\n    return type.spec.defining || type.spec.definingForContent;\n}\nfunction replaceRange(tr, from, to, slice) {\n    if (!slice.size)\n        return tr.deleteRange(from, to);\n    let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);\n    if (fitsTrivially($from, $to, slice))\n        return tr.step(new ReplaceStep(from, to, slice));\n    let targetDepths = coveredDepths($from, $to);\n    // Can't replace the whole document, so remove 0 if it's present\n    if (targetDepths[targetDepths.length - 1] == 0)\n        targetDepths.pop();\n    // Negative numbers represent not expansion over the whole node at\n    // that depth, but replacing from $from.before(-D) to $to.pos.\n    let preferredTarget = -($from.depth + 1);\n    targetDepths.unshift(preferredTarget);\n    // This loop picks a preferred target depth, if one of the covering\n    // depths is not outside of a defining node, and adds negative\n    // depths for any depth that has $from at its start and does not\n    // cross a defining node.\n    for (let d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {\n        let spec = $from.node(d).type.spec;\n        if (spec.defining || spec.definingAsContext || spec.isolating)\n            break;\n        if (targetDepths.indexOf(d) > -1)\n            preferredTarget = d;\n        else if ($from.before(d) == pos)\n            targetDepths.splice(1, 0, -d);\n    }\n    // Try to fit each possible depth of the slice into each possible\n    // target depth, starting with the preferred depths.\n    let preferredTargetIndex = targetDepths.indexOf(preferredTarget);\n    let leftNodes = [], preferredDepth = slice.openStart;\n    for (let content = slice.content, i = 0;; i++) {\n        let node = content.firstChild;\n        leftNodes.push(node);\n        if (i == slice.openStart)\n            break;\n        content = node.content;\n    }\n    // Back up preferredDepth to cover defining textblocks directly\n    // above it, possibly skipping a non-defining textblock.\n    for (let d = preferredDepth - 1; d >= 0; d--) {\n        let leftNode = leftNodes[d], def = definesContent(leftNode.type);\n        if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1)))\n            preferredDepth = d;\n        else if (def || !leftNode.type.isTextblock)\n            break;\n    }\n    for (let j = slice.openStart; j >= 0; j--) {\n        let openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);\n        let insert = leftNodes[openDepth];\n        if (!insert)\n            continue;\n        for (let i = 0; i < targetDepths.length; i++) {\n            // Loop over possible expansion levels, starting with the\n            // preferred one\n            let targetDepth = targetDepths[(i + preferredTargetIndex) % targetDepths.length], expand = true;\n            if (targetDepth < 0) {\n                expand = false;\n                targetDepth = -targetDepth;\n            }\n            let parent = $from.node(targetDepth - 1), index = $from.index(targetDepth - 1);\n            if (parent.canReplaceWith(index, index, insert.type, insert.marks))\n                return tr.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd));\n        }\n    }\n    let startSteps = tr.steps.length;\n    for (let i = targetDepths.length - 1; i >= 0; i--) {\n        tr.replace(from, to, slice);\n        if (tr.steps.length > startSteps)\n            break;\n        let depth = targetDepths[i];\n        if (depth < 0)\n            continue;\n        from = $from.before(depth);\n        to = $to.after(depth);\n    }\n}\nfunction closeFragment(fragment, depth, oldOpen, newOpen, parent) {\n    if (depth < oldOpen) {\n        let first = fragment.firstChild;\n        fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first)));\n    }\n    if (depth > newOpen) {\n        let match = parent.contentMatchAt(0);\n        let start = match.fillBefore(fragment).append(fragment);\n        fragment = start.append(match.matchFragment(start).fillBefore(Fragment.empty, true));\n    }\n    return fragment;\n}\nfunction replaceRangeWith(tr, from, to, node) {\n    if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) {\n        let point = insertPoint(tr.doc, from, node.type);\n        if (point != null)\n            from = to = point;\n    }\n    tr.replaceRange(from, to, new Slice(Fragment.from(node), 0, 0));\n}\nfunction deleteRange(tr, from, to) {\n    let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);\n    let covered = coveredDepths($from, $to);\n    for (let i = 0; i < covered.length; i++) {\n        let depth = covered[i], last = i == covered.length - 1;\n        if ((last && depth == 0) || $from.node(depth).type.contentMatch.validEnd)\n            return tr.delete($from.start(depth), $to.end(depth));\n        if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1))))\n            return tr.delete($from.before(depth), $to.after(depth));\n    }\n    for (let d = 1; d <= $from.depth && d <= $to.depth; d++) {\n        if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d &&\n            $from.start(d - 1) == $to.start(d - 1) && $from.node(d - 1).canReplace($from.index(d - 1), $to.index(d - 1)))\n            return tr.delete($from.before(d), to);\n    }\n    tr.delete(from, to);\n}\n// Returns an array of all depths for which $from - $to spans the\n// whole content of the nodes at that depth.\nfunction coveredDepths($from, $to) {\n    let result = [], minDepth = Math.min($from.depth, $to.depth);\n    for (let d = minDepth; d >= 0; d--) {\n        let start = $from.start(d);\n        if (start < $from.pos - ($from.depth - d) ||\n            $to.end(d) > $to.pos + ($to.depth - d) ||\n            $from.node(d).type.spec.isolating ||\n            $to.node(d).type.spec.isolating)\n            break;\n        if (start == $to.start(d) ||\n            (d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent &&\n                d && $to.start(d - 1) == start - 1))\n            result.push(d);\n    }\n    return result;\n}\n\n/**\nUpdate an attribute in a specific node.\n*/\nclass AttrStep extends Step {\n    /**\n    Construct an attribute step.\n    */\n    constructor(\n    /**\n    The position of the target node.\n    */\n    pos, \n    /**\n    The attribute to set.\n    */\n    attr, \n    // The attribute's new value.\n    value) {\n        super();\n        this.pos = pos;\n        this.attr = attr;\n        this.value = value;\n    }\n    apply(doc) {\n        let node = doc.nodeAt(this.pos);\n        if (!node)\n            return StepResult.fail(\"No node at attribute step's position\");\n        let attrs = Object.create(null);\n        for (let name in node.attrs)\n            attrs[name] = node.attrs[name];\n        attrs[this.attr] = this.value;\n        let updated = node.type.create(attrs, null, node.marks);\n        return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));\n    }\n    getMap() {\n        return StepMap.empty;\n    }\n    invert(doc) {\n        return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);\n    }\n    map(mapping) {\n        let pos = mapping.mapResult(this.pos, 1);\n        return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);\n    }\n    toJSON() {\n        return { stepType: \"attr\", pos: this.pos, attr: this.attr, value: this.value };\n    }\n    static fromJSON(schema, json) {\n        if (typeof json.pos != \"number\" || typeof json.attr != \"string\")\n            throw new RangeError(\"Invalid input for AttrStep.fromJSON\");\n        return new AttrStep(json.pos, json.attr, json.value);\n    }\n}\nStep.jsonID(\"attr\", AttrStep);\n/**\nUpdate an attribute in the doc node.\n*/\nclass DocAttrStep extends Step {\n    /**\n    Construct an attribute step.\n    */\n    constructor(\n    /**\n    The attribute to set.\n    */\n    attr, \n    // The attribute's new value.\n    value) {\n        super();\n        this.attr = attr;\n        this.value = value;\n    }\n    apply(doc) {\n        let attrs = Object.create(null);\n        for (let name in doc.attrs)\n            attrs[name] = doc.attrs[name];\n        attrs[this.attr] = this.value;\n        let updated = doc.type.create(attrs, doc.content, doc.marks);\n        return StepResult.ok(updated);\n    }\n    getMap() {\n        return StepMap.empty;\n    }\n    invert(doc) {\n        return new DocAttrStep(this.attr, doc.attrs[this.attr]);\n    }\n    map(mapping) {\n        return this;\n    }\n    toJSON() {\n        return { stepType: \"docAttr\", attr: this.attr, value: this.value };\n    }\n    static fromJSON(schema, json) {\n        if (typeof json.attr != \"string\")\n            throw new RangeError(\"Invalid input for DocAttrStep.fromJSON\");\n        return new DocAttrStep(json.attr, json.value);\n    }\n}\nStep.jsonID(\"docAttr\", DocAttrStep);\n\n/**\n@internal\n*/\nlet TransformError = class extends Error {\n};\nTransformError = function TransformError(message) {\n    let err = Error.call(this, message);\n    err.__proto__ = TransformError.prototype;\n    return err;\n};\nTransformError.prototype = Object.create(Error.prototype);\nTransformError.prototype.constructor = TransformError;\nTransformError.prototype.name = \"TransformError\";\n/**\nAbstraction to build up and track an array of\n[steps](https://prosemirror.net/docs/ref/#transform.Step) representing a document transformation.\n\nMost transforming methods return the `Transform` object itself, so\nthat they can be chained.\n*/\nclass Transform {\n    /**\n    Create a transform that starts with the given document.\n    */\n    constructor(\n    /**\n    The current document (the result of applying the steps in the\n    transform).\n    */\n    doc) {\n        this.doc = doc;\n        /**\n        The steps in this transform.\n        */\n        this.steps = [];\n        /**\n        The documents before each of the steps.\n        */\n        this.docs = [];\n        /**\n        A mapping with the maps for each of the steps in this transform.\n        */\n        this.mapping = new Mapping;\n    }\n    /**\n    The starting document.\n    */\n    get before() { return this.docs.length ? this.docs[0] : this.doc; }\n    /**\n    Apply a new step in this transform, saving the result. Throws an\n    error when the step fails.\n    */\n    step(step) {\n        let result = this.maybeStep(step);\n        if (result.failed)\n            throw new TransformError(result.failed);\n        return this;\n    }\n    /**\n    Try to apply a step in this transformation, ignoring it if it\n    fails. Returns the step result.\n    */\n    maybeStep(step) {\n        let result = step.apply(this.doc);\n        if (!result.failed)\n            this.addStep(step, result.doc);\n        return result;\n    }\n    /**\n    True when the document has been changed (when there are any\n    steps).\n    */\n    get docChanged() {\n        return this.steps.length > 0;\n    }\n    /**\n    Return a single range, in post-transform document positions,\n    that covers all content changed by this transform. Returns null\n    if no replacements are made. Note that this will ignore changes\n    that add/remove marks without replacing the underlying content.\n    */\n    changedRange() {\n        let from = 1e9, to = -1e9;\n        for (let i = 0; i < this.mapping.maps.length; i++) {\n            let map = this.mapping.maps[i];\n            if (i) {\n                from = map.map(from, 1);\n                to = map.map(to, -1);\n            }\n            map.forEach((_f, _t, fromB, toB) => {\n                from = Math.min(from, fromB);\n                to = Math.max(to, toB);\n            });\n        }\n        return from == 1e9 ? null : { from, to };\n    }\n    /**\n    @internal\n    */\n    addStep(step, doc) {\n        this.docs.push(this.doc);\n        this.steps.push(step);\n        this.mapping.appendMap(step.getMap());\n        this.doc = doc;\n    }\n    /**\n    Replace the part of the document between `from` and `to` with the\n    given `slice`.\n    */\n    replace(from, to = from, slice = Slice.empty) {\n        let step = replaceStep(this.doc, from, to, slice);\n        if (step)\n            this.step(step);\n        return this;\n    }\n    /**\n    Replace the given range with the given content, which may be a\n    fragment, node, or array of nodes.\n    */\n    replaceWith(from, to, content) {\n        return this.replace(from, to, new Slice(Fragment.from(content), 0, 0));\n    }\n    /**\n    Delete the content between the given positions.\n    */\n    delete(from, to) {\n        return this.replace(from, to, Slice.empty);\n    }\n    /**\n    Insert the given content at the given position.\n    */\n    insert(pos, content) {\n        return this.replaceWith(pos, pos, content);\n    }\n    /**\n    Replace a range of the document with a given slice, using\n    `from`, `to`, and the slice's\n    [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather\n    than fixed start and end points. This method may grow the\n    replaced area or close open nodes in the slice in order to get a\n    fit that is more in line with WYSIWYG expectations, by dropping\n    fully covered parent nodes of the replaced region when they are\n    marked [non-defining as\n    context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an\n    open parent node from the slice that _is_ marked as [defining\n    its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).\n    \n    This is the method, for example, to handle paste. The similar\n    [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more\n    primitive tool which will _not_ move the start and end of its given\n    range, and is useful in situations where you need more precise\n    control over what happens.\n    */\n    replaceRange(from, to, slice) {\n        replaceRange(this, from, to, slice);\n        return this;\n    }\n    /**\n    Replace the given range with a node, but use `from` and `to` as\n    hints, rather than precise positions. When from and to are the same\n    and are at the start or end of a parent node in which the given\n    node doesn't fit, this method may _move_ them out towards a parent\n    that does allow the given node to be placed. When the given range\n    completely covers a parent node, this method may completely replace\n    that parent node.\n    */\n    replaceRangeWith(from, to, node) {\n        replaceRangeWith(this, from, to, node);\n        return this;\n    }\n    /**\n    Delete the given range, expanding it to cover fully covered\n    parent nodes until a valid replace is found.\n    */\n    deleteRange(from, to) {\n        deleteRange(this, from, to);\n        return this;\n    }\n    /**\n    Split the content in the given range off from its parent, if there\n    is sibling content before or after it, and move it up the tree to\n    the depth specified by `target`. You'll probably want to use\n    [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make\n    sure the lift is valid.\n    */\n    lift(range, target) {\n        lift(this, range, target);\n        return this;\n    }\n    /**\n    Join the blocks around the given position. If depth is 2, their\n    last and first siblings are also joined, and so on.\n    */\n    join(pos, depth = 1) {\n        join(this, pos, depth);\n        return this;\n    }\n    /**\n    Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers.\n    The wrappers are assumed to be valid in this position, and should\n    probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping).\n    */\n    wrap(range, wrappers) {\n        wrap(this, range, wrappers);\n        return this;\n    }\n    /**\n    Set the type of all textblocks (partly) between `from` and `to` to\n    the given node type with the given attributes.\n    */\n    setBlockType(from, to = from, type, attrs = null) {\n        setBlockType(this, from, to, type, attrs);\n        return this;\n    }\n    /**\n    Change the type, attributes, and/or marks of the node at `pos`.\n    When `type` isn't given, the existing node type is preserved,\n    */\n    setNodeMarkup(pos, type, attrs = null, marks) {\n        setNodeMarkup(this, pos, type, attrs, marks);\n        return this;\n    }\n    /**\n    Set a single attribute on a given node to a new value.\n    The `pos` addresses the document content. Use `setDocAttribute`\n    to set attributes on the document itself.\n    */\n    setNodeAttribute(pos, attr, value) {\n        this.step(new AttrStep(pos, attr, value));\n        return this;\n    }\n    /**\n    Set a single attribute on the document to a new value.\n    */\n    setDocAttribute(attr, value) {\n        this.step(new DocAttrStep(attr, value));\n        return this;\n    }\n    /**\n    Add a mark to the node at position `pos`.\n    */\n    addNodeMark(pos, mark) {\n        this.step(new AddNodeMarkStep(pos, mark));\n        return this;\n    }\n    /**\n    Remove a mark (or all marks of the given type) from the node at\n    position `pos`.\n    */\n    removeNodeMark(pos, mark) {\n        let node = this.doc.nodeAt(pos);\n        if (!node)\n            throw new RangeError(\"No node at position \" + pos);\n        if (mark instanceof Mark) {\n            if (mark.isInSet(node.marks))\n                this.step(new RemoveNodeMarkStep(pos, mark));\n        }\n        else {\n            let set = node.marks, found, steps = [];\n            while (found = mark.isInSet(set)) {\n                steps.push(new RemoveNodeMarkStep(pos, found));\n                set = found.removeFromSet(set);\n            }\n            for (let i = steps.length - 1; i >= 0; i--)\n                this.step(steps[i]);\n        }\n        return this;\n    }\n    /**\n    Split the node at the given position, and optionally, if `depth` is\n    greater than one, any number of nodes above that. By default, the\n    parts split off will inherit the node type of the original node.\n    This can be changed by passing an array of types and attributes to\n    use after the split (with the outermost nodes coming first).\n    */\n    split(pos, depth = 1, typesAfter) {\n        split(this, pos, depth, typesAfter);\n        return this;\n    }\n    /**\n    Add the given mark to the inline content between `from` and `to`.\n    */\n    addMark(from, to, mark) {\n        addMark(this, from, to, mark);\n        return this;\n    }\n    /**\n    Remove marks from inline nodes between `from` and `to`. When\n    `mark` is a single mark, remove precisely that mark. When it is\n    a mark type, remove all marks of that type. When it is null,\n    remove all marks of any type.\n    */\n    removeMark(from, to, mark) {\n        removeMark(this, from, to, mark);\n        return this;\n    }\n    /**\n    Removes all marks and nodes from the content of the node at\n    `pos` that don't match the given new parent node type. Accepts\n    an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as\n    third argument.\n    */\n    clearIncompatible(pos, parentType, match) {\n        clearIncompatible(this, pos, parentType, match);\n        return this;\n    }\n}\n\nexport { AddMarkStep, AddNodeMarkStep, AttrStep, DocAttrStep, MapResult, Mapping, RemoveMarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, TransformError, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep };\n"],"names":[],"sourceRoot":""}