) → this\n// Insert the given content at the given position.\n\n\nTransform.prototype.insert = function (pos, content) {\n return this.replaceWith(pos, pos, content);\n};\n\nfunction fitsTrivially($from, $to, slice) {\n return !slice.openStart && !slice.openEnd && $from.start() == $to.start() && $from.parent.canReplace($from.index(), $to.index(), slice.content);\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 , 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`.\n\n\nvar Fitter = function Fitter($from, $to, slice) {\n this.$to = $to;\n this.$from = $from;\n this.unplaced = slice;\n this.frontier = [];\n\n for (var i = 0; i <= $from.depth; i++) {\n var node = $from.node(i);\n this.frontier.push({\n type: node.type,\n match: node.contentMatchAt($from.indexAfter(i))\n });\n }\n\n this.placed = Fragment.empty;\n\n for (var i$1 = $from.depth; i$1 > 0; i$1--) {\n this.placed = Fragment.from($from.node(i$1).copy(this.placed));\n }\n};\n\nvar prototypeAccessors$1 = {\n depth: {\n configurable: true\n }\n};\n\nprototypeAccessors$1.depth.get = function () {\n return this.frontier.length - 1;\n};\n\nFitter.prototype.fit = function 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 var fit = this.findFittable();\n\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\n\n var moveInline = this.mustMoveInline(),\n placedSize = this.placed.size - this.depth - this.$from.depth;\n var $from = this.$from,\n $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));\n\n if (!$to) {\n return null;\n } // If closing to `$to` succeeded, create a step\n\n\n var content = this.placed,\n openStart = $from.depth,\n openEnd = $to.depth;\n\n while (openStart && openEnd && content.childCount == 1) {\n // Normalize by dropping open parent nodes\n content = content.firstChild.content;\n openStart--;\n openEnd--;\n }\n\n var slice = new Slice(content, openStart, openEnd);\n\n if (moveInline > -1) {\n return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);\n }\n\n if (slice.size || $from.pos != this.$to.pos) // Don't generate no-op steps\n {\n return new ReplaceStep($from.pos, $to.pos, slice);\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\n\nFitter.prototype.findFittable = function findFittable() {\n // Only try wrapping nodes (pass 2) after finding a place without\n // wrapping failed.\n for (var pass = 1; pass <= 2; pass++) {\n for (var sliceDepth = this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) {\n var fragment = void 0,\n parent = void 0;\n\n if (sliceDepth) {\n parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild;\n fragment = parent.content;\n } else {\n fragment = this.unplaced.content;\n }\n\n var first = fragment.firstChild;\n\n for (var frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) {\n var ref = this.frontier[frontierDepth];\n var type = ref.type;\n var match = ref.match;\n var wrap = void 0,\n inject = void 0; // 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\n if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(Fragment.from(first), false)) : type.compatibleContent(parent.type))) {\n return {\n sliceDepth: sliceDepth,\n frontierDepth: frontierDepth,\n parent: parent,\n inject: inject\n };\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 {\n sliceDepth: sliceDepth,\n frontierDepth: frontierDepth,\n parent: parent,\n wrap: wrap\n };\n } // Don't continue looking further up if the parent node\n // would fit here.\n\n\n if (parent && match.matchType(parent.type)) {\n break;\n }\n }\n }\n }\n};\n\nFitter.prototype.openMore = function openMore() {\n var ref = this.unplaced;\n var content = ref.content;\n var openStart = ref.openStart;\n var openEnd = ref.openEnd;\n var inner = contentAt(content, openStart);\n\n if (!inner.childCount || inner.firstChild.isLeaf) {\n return false;\n }\n\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\nFitter.prototype.dropNode = function dropNode() {\n var ref = this.unplaced;\n var content = ref.content;\n var openStart = ref.openStart;\n var openEnd = ref.openEnd;\n var inner = contentAt(content, openStart);\n\n if (inner.childCount <= 1 && openStart > 0) {\n var openAtEnd = content.size - openStart <= openStart + inner.size;\n this.unplaced = new Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd);\n } else {\n this.unplaced = new Slice(dropFromFragment(content, openStart, 1), openStart, openEnd);\n }\n}; // : ({sliceDepth: number, frontierDepth: number, parent: ?Node, wrap: ?[NodeType], inject: ?Fragment})\n// Move content from the unplaced slice at `sliceDepth` to the\n// frontier node at `frontierDepth`. Close that frontier node when\n// applicable.\n\n\nFitter.prototype.placeNodes = function placeNodes(ref) {\n var sliceDepth = ref.sliceDepth;\n var frontierDepth = ref.frontierDepth;\n var parent = ref.parent;\n var inject = ref.inject;\n var wrap = ref.wrap;\n\n while (this.depth > frontierDepth) {\n this.closeFrontierNode();\n }\n\n if (wrap) {\n for (var i = 0; i < wrap.length; i++) {\n this.openFrontierNode(wrap[i]);\n }\n }\n\n var slice = this.unplaced,\n fragment = parent ? parent.content : slice.content;\n var openStart = slice.openStart - sliceDepth;\n var taken = 0,\n add = [];\n var ref$1 = this.frontier[frontierDepth];\n var match = ref$1.match;\n var type = ref$1.type;\n\n if (inject) {\n for (var i$1 = 0; i$1 < inject.childCount; i$1++) {\n add.push(inject.child(i$1));\n }\n\n match = match.matchFragment(inject);\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\n\n var openEndCount = fragment.size + sliceDepth - (slice.content.size - slice.openEnd); // Scan over the fragment, fitting as many child nodes as\n // possible.\n\n while (taken < fragment.childCount) {\n var next = fragment.child(taken),\n matches = match.matchType(next.type);\n\n if (!matches) {\n break;\n }\n\n taken++;\n\n if (taken > 1 || openStart == 0 || next.content.size) {\n // 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\n var toEnd = taken == fragment.childCount;\n\n if (!toEnd) {\n openEndCount = -1;\n }\n\n this.placed = addToFragment(this.placed, frontierDepth, Fragment.from(add));\n this.frontier[frontierDepth].match = match; // If the parent types match, and the entire node was moved, and\n // it's not open, close this frontier node right away.\n\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\n\n for (var i$2 = 0, cur = fragment; i$2 < openEndCount; i$2++) {\n var node = cur.lastChild;\n this.frontier.push({\n type: node.type,\n match: node.contentMatchAt(node.childCount)\n });\n cur = node.content;\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\n\n this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd) : sliceDepth == 0 ? Slice.empty : new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);\n};\n\nFitter.prototype.mustMoveInline = function mustMoveInline() {\n if (!this.$to.parent.isTextblock || this.$to.end() == this.$to.pos) {\n return -1;\n }\n\n var top = this.frontier[this.depth],\n level;\n\n if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) || this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth) {\n return -1;\n }\n\n var ref = this.$to;\n var depth = ref.depth;\n var after = this.$to.after(depth);\n\n while (depth > 1 && after == this.$to.end(--depth)) {\n ++after;\n }\n\n return after;\n};\n\nFitter.prototype.findCloseLevel = function findCloseLevel($to) {\n scan: for (var i = Math.min(this.depth, $to.depth); i >= 0; i--) {\n var ref = this.frontier[i];\n var match = ref.match;\n var type = ref.type;\n var dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1));\n var fit = contentAfterFits($to, i, type, match, dropInner);\n\n if (!fit) {\n continue;\n }\n\n for (var d = i - 1; d >= 0; d--) {\n var ref$1 = this.frontier[d];\n var match$1 = ref$1.match;\n var type$1 = ref$1.type;\n var matches = contentAfterFits($to, d, type$1, match$1, true);\n\n if (!matches || matches.childCount) {\n continue scan;\n }\n }\n\n return {\n depth: i,\n fit: fit,\n move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to\n };\n }\n};\n\nFitter.prototype.close = function close($to) {\n var close = this.findCloseLevel($to);\n\n if (!close) {\n return null;\n }\n\n while (this.depth > close.depth) {\n this.closeFrontierNode();\n }\n\n if (close.fit.childCount) {\n this.placed = addToFragment(this.placed, close.depth, close.fit);\n }\n\n $to = close.move;\n\n for (var d = close.depth + 1; d <= $to.depth; d++) {\n var node = $to.node(d),\n add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));\n this.openFrontierNode(node.type, node.attrs, add);\n }\n\n return $to;\n};\n\nFitter.prototype.openFrontierNode = function openFrontierNode(type, attrs, content) {\n var 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({\n type: type,\n match: type.contentMatch\n });\n};\n\nFitter.prototype.closeFrontierNode = function closeFrontierNode() {\n var open = this.frontier.pop();\n var add = open.match.fillBefore(Fragment.empty, true);\n\n if (add.childCount) {\n this.placed = addToFragment(this.placed, this.frontier.length, add);\n }\n};\n\nObject.defineProperties(Fitter.prototype, prototypeAccessors$1);\n\nfunction dropFromFragment(fragment, depth, count) {\n if (depth == 0) {\n return fragment.cutByIndex(count);\n }\n\n return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count)));\n}\n\nfunction addToFragment(fragment, depth, content) {\n if (depth == 0) {\n return fragment.append(content);\n }\n\n return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content)));\n}\n\nfunction contentAt(fragment, depth) {\n for (var i = 0; i < depth; i++) {\n fragment = fragment.firstChild.content;\n }\n\n return fragment;\n}\n\nfunction closeNodeStart(node, openStart, openEnd) {\n if (openStart <= 0) {\n return node;\n }\n\n var frag = node.content;\n\n if (openStart > 1) {\n frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0));\n }\n\n if (openStart > 0) {\n frag = node.type.contentMatch.fillBefore(frag).append(frag);\n\n if (openEnd <= 0) {\n frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(Fragment.empty, true));\n }\n }\n\n return node.copy(frag);\n}\n\nfunction contentAfterFits($to, depth, type, match, open) {\n var node = $to.node(depth),\n index = open ? $to.indexAfter(depth) : $to.index(depth);\n\n if (index == node.childCount && !type.compatibleContent(node.type)) {\n return null;\n }\n\n var fit = match.fillBefore(node.content, true, index);\n return fit && !invalidMarks(type, node.content, index) ? fit : null;\n}\n\nfunction invalidMarks(type, fragment, start) {\n for (var i = start; i < fragment.childCount; i++) {\n if (!type.allowsMarks(fragment.child(i).marks)) {\n return true;\n }\n }\n\n return false;\n} // :: (number, number, Slice) → this\n// Replace a range of the document with a given slice, using `from`,\n// `to`, and the slice's [`openStart`](#model.Slice.openStart) property\n// as hints, rather than fixed start and end points. This method may\n// grow the replaced area or close open nodes in the slice in order to\n// get a fit that is more in line with WYSIWYG expectations, by\n// dropping fully covered parent nodes of the replaced region when\n// they are marked [non-defining](#model.NodeSpec.defining), or\n// including an open parent node from the slice that _is_ marked as\n// [defining](#model.NodeSpec.defining).\n//\n// This is the method, for example, to handle paste. The similar\n// [`replace`](#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\nTransform.prototype.replaceRange = function (from, to, slice) {\n if (!slice.size) {\n return this.deleteRange(from, to);\n }\n\n var $from = this.doc.resolve(from),\n $to = this.doc.resolve(to);\n\n if (fitsTrivially($from, $to, slice)) {\n return this.step(new ReplaceStep(from, to, slice));\n }\n\n var targetDepths = coveredDepths($from, this.doc.resolve(to)); // Can't replace the whole document, so remove 0 if it's present\n\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\n\n var preferredTarget = -($from.depth + 1);\n targetDepths.unshift(preferredTarget); // 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\n for (var d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {\n var spec = $from.node(d).type.spec;\n\n if (spec.defining || spec.isolating) {\n break;\n }\n\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\n\n var preferredTargetIndex = targetDepths.indexOf(preferredTarget);\n var leftNodes = [],\n preferredDepth = slice.openStart;\n\n for (var content = slice.content, i = 0;; i++) {\n var node = content.firstChild;\n leftNodes.push(node);\n\n if (i == slice.openStart) {\n break;\n }\n\n content = node.content;\n } // Back up if the node directly above openStart, or the node above\n // that separated only by a non-defining textblock node, is defining.\n\n\n if (preferredDepth > 0 && leftNodes[preferredDepth - 1].type.spec.defining && $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 1].type) {\n preferredDepth -= 1;\n } else if (preferredDepth >= 2 && leftNodes[preferredDepth - 1].isTextblock && leftNodes[preferredDepth - 2].type.spec.defining && $from.node(preferredTargetIndex).type != leftNodes[preferredDepth - 2].type) {\n preferredDepth -= 2;\n }\n\n for (var j = slice.openStart; j >= 0; j--) {\n var openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);\n var insert = leftNodes[openDepth];\n\n if (!insert) {\n continue;\n }\n\n for (var i$1 = 0; i$1 < targetDepths.length; i$1++) {\n // Loop over possible expansion levels, starting with the\n // preferred one\n var targetDepth = targetDepths[(i$1 + preferredTargetIndex) % targetDepths.length],\n expand = true;\n\n if (targetDepth < 0) {\n expand = false;\n targetDepth = -targetDepth;\n }\n\n var parent = $from.node(targetDepth - 1),\n index = $from.index(targetDepth - 1);\n\n if (parent.canReplaceWith(index, index, insert.type, insert.marks)) {\n return this.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd));\n }\n }\n }\n\n var startSteps = this.steps.length;\n\n for (var i$2 = targetDepths.length - 1; i$2 >= 0; i$2--) {\n this.replace(from, to, slice);\n\n if (this.steps.length > startSteps) {\n break;\n }\n\n var depth = targetDepths[i$2];\n\n if (depth < 0) {\n continue;\n }\n\n from = $from.before(depth);\n to = $to.after(depth);\n }\n\n return this;\n};\n\nfunction closeFragment(fragment, depth, oldOpen, newOpen, parent) {\n if (depth < oldOpen) {\n var first = fragment.firstChild;\n fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first)));\n }\n\n if (depth > newOpen) {\n var match = parent.contentMatchAt(0);\n var start = match.fillBefore(fragment).append(fragment);\n fragment = start.append(match.matchFragment(start).fillBefore(Fragment.empty, true));\n }\n\n return fragment;\n} // :: (number, number, Node) → this\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\nTransform.prototype.replaceRangeWith = function (from, to, node) {\n if (!node.isInline && from == to && this.doc.resolve(from).parent.content.size) {\n var point = insertPoint(this.doc, from, node.type);\n\n if (point != null) {\n from = to = point;\n }\n }\n\n return this.replaceRange(from, to, new Slice(Fragment.from(node), 0, 0));\n}; // :: (number, number) → this\n// Delete the given range, expanding it to cover fully covered\n// parent nodes until a valid replace is found.\n\n\nTransform.prototype.deleteRange = function (from, to) {\n var $from = this.doc.resolve(from),\n $to = this.doc.resolve(to);\n var covered = coveredDepths($from, $to);\n\n for (var i = 0; i < covered.length; i++) {\n var depth = covered[i],\n last = i == covered.length - 1;\n\n if (last && depth == 0 || $from.node(depth).type.contentMatch.validEnd) {\n return this.delete($from.start(depth), $to.end(depth));\n }\n\n if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1)))) {\n return this.delete($from.before(depth), $to.after(depth));\n }\n }\n\n for (var 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 return this.delete($from.before(d), to);\n }\n }\n\n return this.delete(from, to);\n}; // : (ResolvedPos, ResolvedPos) → [number]\n// Returns an array of all depths for which $from - $to spans the\n// whole content of the nodes at that depth.\n\n\nfunction coveredDepths($from, $to) {\n var result = [],\n minDepth = Math.min($from.depth, $to.depth);\n\n for (var d = minDepth; d >= 0; d--) {\n var start = $from.start(d);\n\n if (start < $from.pos - ($from.depth - d) || $to.end(d) > $to.pos + ($to.depth - d) || $from.node(d).type.spec.isolating || $to.node(d).type.spec.isolating) {\n break;\n }\n\n if (start == $to.start(d)) {\n result.push(d);\n }\n }\n\n return result;\n}\n\nexport { AddMarkStep, MapResult, Mapping, RemoveMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, TransformError, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep };","function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nimport { Slice, Fragment, Mark, Node } from 'prosemirror-model';\nimport { ReplaceStep, ReplaceAroundStep, Transform } from 'prosemirror-transform';\nvar classesById = Object.create(null); // ::- Superclass for editor selections. Every selection type should\n// extend this. Should not be instantiated directly.\n\nvar Selection = function Selection($anchor, $head, ranges) {\n // :: [SelectionRange]\n // The ranges covered by the selection.\n this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))]; // :: ResolvedPos\n // The resolved anchor of the selection (the side that stays in\n // place when the selection is modified).\n\n this.$anchor = $anchor; // :: ResolvedPos\n // The resolved head of the selection (the side that moves when\n // the selection is modified).\n\n this.$head = $head;\n};\n\nvar prototypeAccessors = {\n anchor: {\n configurable: true\n },\n head: {\n configurable: true\n },\n from: {\n configurable: true\n },\n to: {\n configurable: true\n },\n $from: {\n configurable: true\n },\n $to: {\n configurable: true\n },\n empty: {\n configurable: true\n }\n}; // :: number\n// The selection's anchor, as an unresolved position.\n\nprototypeAccessors.anchor.get = function () {\n return this.$anchor.pos;\n}; // :: number\n// The selection's head.\n\n\nprototypeAccessors.head.get = function () {\n return this.$head.pos;\n}; // :: number\n// The lower bound of the selection's main range.\n\n\nprototypeAccessors.from.get = function () {\n return this.$from.pos;\n}; // :: number\n// The upper bound of the selection's main range.\n\n\nprototypeAccessors.to.get = function () {\n return this.$to.pos;\n}; // :: ResolvedPos\n// The resolved lowerbound of the selection's main range.\n\n\nprototypeAccessors.$from.get = function () {\n return this.ranges[0].$from;\n}; // :: ResolvedPos\n// The resolved upper bound of the selection's main range.\n\n\nprototypeAccessors.$to.get = function () {\n return this.ranges[0].$to;\n}; // :: bool\n// Indicates whether the selection contains any content.\n\n\nprototypeAccessors.empty.get = function () {\n var ranges = this.ranges;\n\n for (var i = 0; i < ranges.length; i++) {\n if (ranges[i].$from.pos != ranges[i].$to.pos) {\n return false;\n }\n }\n\n return true;\n}; // eq:: (Selection) → bool\n// Test whether the selection is the same as another selection.\n// map:: (doc: Node, mapping: Mappable) → Selection\n// Map this selection through a [mappable](#transform.Mappable) thing. `doc`\n// should be the new document to which we are mapping.\n// :: () → Slice\n// Get the content of this selection as a slice.\n\n\nSelection.prototype.content = function content() {\n return this.$from.node(0).slice(this.from, this.to, true);\n}; // :: (Transaction, ?Slice)\n// Replace the selection with a slice or, if no slice is given,\n// delete the selection. Will append to the given transaction.\n\n\nSelection.prototype.replace = function replace(tr, content) {\n if (content === void 0) content = Slice.empty; // Put the new selection at the position after the inserted\n // content. When that ended in an inline node, search backwards,\n // to get the position after that node. If not, search forward.\n\n var lastNode = content.content.lastChild,\n lastParent = null;\n\n for (var i = 0; i < content.openEnd; i++) {\n lastParent = lastNode;\n lastNode = lastNode.lastChild;\n }\n\n var mapFrom = tr.steps.length,\n ranges = this.ranges;\n\n for (var i$1 = 0; i$1 < ranges.length; i$1++) {\n var ref = ranges[i$1];\n var $from = ref.$from;\n var $to = ref.$to;\n var mapping = tr.mapping.slice(mapFrom);\n tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i$1 ? Slice.empty : content);\n\n if (i$1 == 0) {\n selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);\n }\n }\n}; // :: (Transaction, Node)\n// Replace the selection with the given node, appending the changes\n// to the given transaction.\n\n\nSelection.prototype.replaceWith = function replaceWith(tr, node) {\n var mapFrom = tr.steps.length,\n ranges = this.ranges;\n\n for (var i = 0; i < ranges.length; i++) {\n var ref = ranges[i];\n var $from = ref.$from;\n var $to = ref.$to;\n var mapping = tr.mapping.slice(mapFrom);\n var from = mapping.map($from.pos),\n to = mapping.map($to.pos);\n\n if (i) {\n tr.deleteRange(from, to);\n } else {\n tr.replaceRangeWith(from, to, node);\n selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1);\n }\n }\n}; // toJSON:: () → Object\n// Convert the selection to a JSON representation. When implementing\n// this for a custom selection class, make sure to give the object a\n// `type` property whose value matches the ID under which you\n// [registered](#state.Selection^jsonID) your class.\n// :: (ResolvedPos, number, ?bool) → ?Selection\n// Find a valid cursor or leaf node selection starting at the given\n// position and searching back if `dir` is negative, and forward if\n// positive. When `textOnly` is true, only consider cursor\n// selections. Will return null when no valid selection position is\n// found.\n\n\nSelection.findFrom = function findFrom($pos, dir, textOnly) {\n var inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);\n\n if (inner) {\n return inner;\n }\n\n for (var depth = $pos.depth - 1; depth >= 0; depth--) {\n var found = dir < 0 ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly) : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly);\n\n if (found) {\n return found;\n }\n }\n}; // :: (ResolvedPos, ?number) → Selection\n// Find a valid cursor or leaf node selection near the given\n// position. Searches forward first by default, but if `bias` is\n// negative, it will search backwards first.\n\n\nSelection.near = function near($pos, bias) {\n if (bias === void 0) bias = 1;\n return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));\n}; // :: (Node) → Selection\n// Find the cursor or leaf node selection closest to the start of\n// the given document. Will return an\n// [`AllSelection`](#state.AllSelection) if no valid position\n// exists.\n\n\nSelection.atStart = function atStart(doc) {\n return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);\n}; // :: (Node) → Selection\n// Find the cursor or leaf node selection closest to the end of the\n// given document.\n\n\nSelection.atEnd = function atEnd(doc) {\n return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);\n}; // :: (Node, Object) → Selection\n// Deserialize the JSON representation of a selection. Must be\n// implemented for custom classes (as a static class method).\n\n\nSelection.fromJSON = function fromJSON(doc, json) {\n if (!json || !json.type) {\n throw new RangeError(\"Invalid input for Selection.fromJSON\");\n }\n\n var cls = classesById[json.type];\n\n if (!cls) {\n throw new RangeError(\"No selection type \" + json.type + \" defined\");\n }\n\n return cls.fromJSON(doc, json);\n}; // :: (string, constructor)\n// To be able to deserialize selections from JSON, custom selection\n// classes must register themselves with an ID string, so that they\n// can be disambiguated. Try to pick something that's unlikely to\n// clash with classes from other modules.\n\n\nSelection.jsonID = function jsonID(id, selectionClass) {\n if (id in classesById) {\n throw new RangeError(\"Duplicate use of selection JSON ID \" + id);\n }\n\n classesById[id] = selectionClass;\n selectionClass.prototype.jsonID = id;\n return selectionClass;\n}; // :: () → SelectionBookmark\n// Get a [bookmark](#state.SelectionBookmark) for this selection,\n// which is a value that can be mapped without having access to a\n// current document, and later resolved to a real selection for a\n// given document again. (This is used mostly by the history to\n// track and restore old selections.) The default implementation of\n// this method just converts the selection to a text selection and\n// returns the bookmark for that.\n\n\nSelection.prototype.getBookmark = function getBookmark() {\n return TextSelection.between(this.$anchor, this.$head).getBookmark();\n};\n\nObject.defineProperties(Selection.prototype, prototypeAccessors); // :: bool\n// Controls whether, when a selection of this type is active in the\n// browser, the selected range should be visible to the user. Defaults\n// to `true`.\n\nSelection.prototype.visible = true; // SelectionBookmark:: interface\n// A lightweight, document-independent representation of a selection.\n// You can define a custom bookmark type for a custom selection class\n// to make the history handle it well.\n//\n// map:: (mapping: Mapping) → SelectionBookmark\n// Map the bookmark through a set of changes.\n//\n// resolve:: (doc: Node) → Selection\n// Resolve the bookmark to a real selection again. This may need to\n// do some error checking and may fall back to a default (usually\n// [`TextSelection.between`](#state.TextSelection^between)) if\n// mapping made the bookmark invalid.\n// ::- Represents a selected range in a document.\n\nvar SelectionRange = function SelectionRange($from, $to) {\n // :: ResolvedPos\n // The lower bound of the range.\n this.$from = $from; // :: ResolvedPos\n // The upper bound of the range.\n\n this.$to = $to;\n}; // ::- A text selection represents a classical editor selection, with\n// a head (the moving side) and anchor (immobile side), both of which\n// point into textblock nodes. It can be empty (a regular cursor\n// position).\n\n\nvar TextSelection = function (Selection) {\n function TextSelection($anchor, $head) {\n if ($head === void 0) $head = $anchor;\n Selection.call(this, $anchor, $head);\n }\n\n if (Selection) TextSelection.__proto__ = Selection;\n TextSelection.prototype = Object.create(Selection && Selection.prototype);\n TextSelection.prototype.constructor = TextSelection;\n var prototypeAccessors$1 = {\n $cursor: {\n configurable: true\n }\n }; // :: ?ResolvedPos\n // Returns a resolved position if this is a cursor selection (an\n // empty text selection), and null otherwise.\n\n prototypeAccessors$1.$cursor.get = function () {\n return this.$anchor.pos == this.$head.pos ? this.$head : null;\n };\n\n TextSelection.prototype.map = function map(doc, mapping) {\n var $head = doc.resolve(mapping.map(this.head));\n\n if (!$head.parent.inlineContent) {\n return Selection.near($head);\n }\n\n var $anchor = doc.resolve(mapping.map(this.anchor));\n return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);\n };\n\n TextSelection.prototype.replace = function replace(tr, content) {\n if (content === void 0) content = Slice.empty;\n Selection.prototype.replace.call(this, tr, content);\n\n if (content == Slice.empty) {\n var marks = this.$from.marksAcross(this.$to);\n\n if (marks) {\n tr.ensureMarks(marks);\n }\n }\n };\n\n TextSelection.prototype.eq = function eq(other) {\n return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head;\n };\n\n TextSelection.prototype.getBookmark = function getBookmark() {\n return new TextBookmark(this.anchor, this.head);\n };\n\n TextSelection.prototype.toJSON = function toJSON() {\n return {\n type: \"text\",\n anchor: this.anchor,\n head: this.head\n };\n };\n\n TextSelection.fromJSON = function fromJSON(doc, json) {\n if (typeof json.anchor != \"number\" || typeof json.head != \"number\") {\n throw new RangeError(\"Invalid input for TextSelection.fromJSON\");\n }\n\n return new TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));\n }; // :: (Node, number, ?number) → TextSelection\n // Create a text selection from non-resolved positions.\n\n\n TextSelection.create = function create(doc, anchor, head) {\n if (head === void 0) head = anchor;\n var $anchor = doc.resolve(anchor);\n return new this($anchor, head == anchor ? $anchor : doc.resolve(head));\n }; // :: (ResolvedPos, ResolvedPos, ?number) → Selection\n // Return a text selection that spans the given positions or, if\n // they aren't text positions, find a text selection near them.\n // `bias` determines whether the method searches forward (default)\n // or backwards (negative number) first. Will fall back to calling\n // [`Selection.near`](#state.Selection^near) when the document\n // doesn't contain a valid text position.\n\n\n TextSelection.between = function between($anchor, $head, bias) {\n var dPos = $anchor.pos - $head.pos;\n\n if (!bias || dPos) {\n bias = dPos >= 0 ? 1 : -1;\n }\n\n if (!$head.parent.inlineContent) {\n var found = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);\n\n if (found) {\n $head = found.$head;\n } else {\n return Selection.near($head, bias);\n }\n }\n\n if (!$anchor.parent.inlineContent) {\n if (dPos == 0) {\n $anchor = $head;\n } else {\n $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor;\n\n if ($anchor.pos < $head.pos != dPos < 0) {\n $anchor = $head;\n }\n }\n }\n\n return new TextSelection($anchor, $head);\n };\n\n Object.defineProperties(TextSelection.prototype, prototypeAccessors$1);\n return TextSelection;\n}(Selection);\n\nSelection.jsonID(\"text\", TextSelection);\n\nvar TextBookmark = function TextBookmark(anchor, head) {\n this.anchor = anchor;\n this.head = head;\n};\n\nTextBookmark.prototype.map = function map(mapping) {\n return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head));\n};\n\nTextBookmark.prototype.resolve = function resolve(doc) {\n return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));\n}; // ::- A node selection is a selection that points at a single node.\n// All nodes marked [selectable](#model.NodeSpec.selectable) can be\n// the target of a node selection. In such a selection, `from` and\n// `to` point directly before and after the selected node, `anchor`\n// equals `from`, and `head` equals `to`..\n\n\nvar NodeSelection = function (Selection) {\n function NodeSelection($pos) {\n var node = $pos.nodeAfter;\n var $end = $pos.node(0).resolve($pos.pos + node.nodeSize);\n Selection.call(this, $pos, $end); // :: Node The selected node.\n\n this.node = node;\n }\n\n if (Selection) NodeSelection.__proto__ = Selection;\n NodeSelection.prototype = Object.create(Selection && Selection.prototype);\n NodeSelection.prototype.constructor = NodeSelection;\n\n NodeSelection.prototype.map = function map(doc, mapping) {\n var ref = mapping.mapResult(this.anchor);\n var deleted = ref.deleted;\n var pos = ref.pos;\n var $pos = doc.resolve(pos);\n\n if (deleted) {\n return Selection.near($pos);\n }\n\n return new NodeSelection($pos);\n };\n\n NodeSelection.prototype.content = function content() {\n return new Slice(Fragment.from(this.node), 0, 0);\n };\n\n NodeSelection.prototype.eq = function eq(other) {\n return other instanceof NodeSelection && other.anchor == this.anchor;\n };\n\n NodeSelection.prototype.toJSON = function toJSON() {\n return {\n type: \"node\",\n anchor: this.anchor\n };\n };\n\n NodeSelection.prototype.getBookmark = function getBookmark() {\n return new NodeBookmark(this.anchor);\n };\n\n NodeSelection.fromJSON = function fromJSON(doc, json) {\n if (typeof json.anchor != \"number\") {\n throw new RangeError(\"Invalid input for NodeSelection.fromJSON\");\n }\n\n return new NodeSelection(doc.resolve(json.anchor));\n }; // :: (Node, number) → NodeSelection\n // Create a node selection from non-resolved positions.\n\n\n NodeSelection.create = function create(doc, from) {\n return new this(doc.resolve(from));\n }; // :: (Node) → bool\n // Determines whether the given node may be selected as a node\n // selection.\n\n\n NodeSelection.isSelectable = function isSelectable(node) {\n return !node.isText && node.type.spec.selectable !== false;\n };\n\n return NodeSelection;\n}(Selection);\n\nNodeSelection.prototype.visible = false;\nSelection.jsonID(\"node\", NodeSelection);\n\nvar NodeBookmark = function NodeBookmark(anchor) {\n this.anchor = anchor;\n};\n\nNodeBookmark.prototype.map = function map(mapping) {\n var ref = mapping.mapResult(this.anchor);\n var deleted = ref.deleted;\n var pos = ref.pos;\n return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos);\n};\n\nNodeBookmark.prototype.resolve = function resolve(doc) {\n var $pos = doc.resolve(this.anchor),\n node = $pos.nodeAfter;\n\n if (node && NodeSelection.isSelectable(node)) {\n return new NodeSelection($pos);\n }\n\n return Selection.near($pos);\n}; // ::- A selection type that represents selecting the whole document\n// (which can not necessarily be expressed with a text selection, when\n// there are for example leaf block nodes at the start or end of the\n// document).\n\n\nvar AllSelection = function (Selection) {\n function AllSelection(doc) {\n Selection.call(this, doc.resolve(0), doc.resolve(doc.content.size));\n }\n\n if (Selection) AllSelection.__proto__ = Selection;\n AllSelection.prototype = Object.create(Selection && Selection.prototype);\n AllSelection.prototype.constructor = AllSelection;\n\n AllSelection.prototype.replace = function replace(tr, content) {\n if (content === void 0) content = Slice.empty;\n\n if (content == Slice.empty) {\n tr.delete(0, tr.doc.content.size);\n var sel = Selection.atStart(tr.doc);\n\n if (!sel.eq(tr.selection)) {\n tr.setSelection(sel);\n }\n } else {\n Selection.prototype.replace.call(this, tr, content);\n }\n };\n\n AllSelection.prototype.toJSON = function toJSON() {\n return {\n type: \"all\"\n };\n };\n\n AllSelection.fromJSON = function fromJSON(doc) {\n return new AllSelection(doc);\n };\n\n AllSelection.prototype.map = function map(doc) {\n return new AllSelection(doc);\n };\n\n AllSelection.prototype.eq = function eq(other) {\n return other instanceof AllSelection;\n };\n\n AllSelection.prototype.getBookmark = function getBookmark() {\n return AllBookmark;\n };\n\n return AllSelection;\n}(Selection);\n\nSelection.jsonID(\"all\", AllSelection);\nvar AllBookmark = {\n map: function map() {\n return this;\n },\n resolve: function resolve(doc) {\n return new AllSelection(doc);\n }\n}; // FIXME we'll need some awareness of text direction when scanning for selections\n// Try to find a selection inside the given node. `pos` points at the\n// position where the search starts. When `text` is true, only return\n// text selections.\n\nfunction findSelectionIn(doc, node, pos, index, dir, text) {\n if (node.inlineContent) {\n return TextSelection.create(doc, pos);\n }\n\n for (var i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) {\n var child = node.child(i);\n\n if (!child.isAtom) {\n var inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text);\n\n if (inner) {\n return inner;\n }\n } else if (!text && NodeSelection.isSelectable(child)) {\n return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0));\n }\n\n pos += child.nodeSize * dir;\n }\n}\n\nfunction selectionToInsertionEnd(tr, startLen, bias) {\n var last = tr.steps.length - 1;\n\n if (last < startLen) {\n return;\n }\n\n var step = tr.steps[last];\n\n if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {\n return;\n }\n\n var map = tr.mapping.maps[last],\n end;\n map.forEach(function (_from, _to, _newFrom, newTo) {\n if (end == null) {\n end = newTo;\n }\n });\n tr.setSelection(Selection.near(tr.doc.resolve(end), bias));\n}\n\nvar UPDATED_SEL = 1,\n UPDATED_MARKS = 2,\n UPDATED_SCROLL = 4; // ::- An editor state transaction, which can be applied to a state to\n// create an updated state. Use\n// [`EditorState.tr`](#state.EditorState.tr) to create an instance.\n//\n// Transactions track changes to the document (they are a subclass of\n// [`Transform`](#transform.Transform)), but also other state changes,\n// like selection updates and adjustments of the set of [stored\n// marks](#state.EditorState.storedMarks). In addition, you can store\n// metadata properties in a transaction, which are extra pieces of\n// information that client code or plugins can use to describe what a\n// transacion represents, so that they can update their [own\n// state](#state.StateField) accordingly.\n//\n// The [editor view](#view.EditorView) uses a few metadata properties:\n// it will attach a property `\"pointer\"` with the value `true` to\n// selection transactions directly caused by mouse or touch input, and\n// a `\"uiEvent\"` property of that may be `\"paste\"`, `\"cut\"`, or `\"drop\"`.\n\nvar Transaction = function (Transform) {\n function Transaction(state) {\n Transform.call(this, state.doc); // :: number\n // The timestamp associated with this transaction, in the same\n // format as `Date.now()`.\n\n this.time = Date.now();\n this.curSelection = state.selection; // The step count for which the current selection is valid.\n\n this.curSelectionFor = 0; // :: ?[Mark]\n // The stored marks set by this transaction, if any.\n\n this.storedMarks = state.storedMarks; // Bitfield to track which aspects of the state were updated by\n // this transaction.\n\n this.updated = 0; // Object used to store metadata properties for the transaction.\n\n this.meta = Object.create(null);\n }\n\n if (Transform) Transaction.__proto__ = Transform;\n Transaction.prototype = Object.create(Transform && Transform.prototype);\n Transaction.prototype.constructor = Transaction;\n var prototypeAccessors = {\n selection: {\n configurable: true\n },\n selectionSet: {\n configurable: true\n },\n storedMarksSet: {\n configurable: true\n },\n isGeneric: {\n configurable: true\n },\n scrolledIntoView: {\n configurable: true\n }\n }; // :: Selection\n // The transaction's current selection. This defaults to the editor\n // selection [mapped](#state.Selection.map) through the steps in the\n // transaction, but can be overwritten with\n // [`setSelection`](#state.Transaction.setSelection).\n\n prototypeAccessors.selection.get = function () {\n if (this.curSelectionFor < this.steps.length) {\n this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor));\n this.curSelectionFor = this.steps.length;\n }\n\n return this.curSelection;\n }; // :: (Selection) → Transaction\n // Update the transaction's current selection. Will determine the\n // selection that the editor gets when the transaction is applied.\n\n\n Transaction.prototype.setSelection = function setSelection(selection) {\n if (selection.$from.doc != this.doc) {\n throw new RangeError(\"Selection passed to setSelection must point at the current document\");\n }\n\n this.curSelection = selection;\n this.curSelectionFor = this.steps.length;\n this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS;\n this.storedMarks = null;\n return this;\n }; // :: bool\n // Whether the selection was explicitly updated by this transaction.\n\n\n prototypeAccessors.selectionSet.get = function () {\n return (this.updated & UPDATED_SEL) > 0;\n }; // :: (?[Mark]) → Transaction\n // Set the current stored marks.\n\n\n Transaction.prototype.setStoredMarks = function setStoredMarks(marks) {\n this.storedMarks = marks;\n this.updated |= UPDATED_MARKS;\n return this;\n }; // :: ([Mark]) → Transaction\n // Make sure the current stored marks or, if that is null, the marks\n // at the selection, match the given set of marks. Does nothing if\n // this is already the case.\n\n\n Transaction.prototype.ensureMarks = function ensureMarks(marks) {\n if (!Mark.sameSet(this.storedMarks || this.selection.$from.marks(), marks)) {\n this.setStoredMarks(marks);\n }\n\n return this;\n }; // :: (Mark) → Transaction\n // Add a mark to the set of stored marks.\n\n\n Transaction.prototype.addStoredMark = function addStoredMark(mark) {\n return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks()));\n }; // :: (union) → Transaction\n // Remove a mark or mark type from the set of stored marks.\n\n\n Transaction.prototype.removeStoredMark = function removeStoredMark(mark) {\n return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks()));\n }; // :: bool\n // Whether the stored marks were explicitly set for this transaction.\n\n\n prototypeAccessors.storedMarksSet.get = function () {\n return (this.updated & UPDATED_MARKS) > 0;\n };\n\n Transaction.prototype.addStep = function addStep(step, doc) {\n Transform.prototype.addStep.call(this, step, doc);\n this.updated = this.updated & ~UPDATED_MARKS;\n this.storedMarks = null;\n }; // :: (number) → Transaction\n // Update the timestamp for the transaction.\n\n\n Transaction.prototype.setTime = function setTime(time) {\n this.time = time;\n return this;\n }; // :: (Slice) → Transaction\n // Replace the current selection with the given slice.\n\n\n Transaction.prototype.replaceSelection = function replaceSelection(slice) {\n this.selection.replace(this, slice);\n return this;\n }; // :: (Node, ?bool) → Transaction\n // Replace the selection with the given node. When `inheritMarks` is\n // true and the content is inline, it inherits the marks from the\n // place where it is inserted.\n\n\n Transaction.prototype.replaceSelectionWith = function replaceSelectionWith(node, inheritMarks) {\n var selection = this.selection;\n\n if (inheritMarks !== false) {\n node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : selection.$from.marksAcross(selection.$to) || Mark.none));\n }\n\n selection.replaceWith(this, node);\n return this;\n }; // :: () → Transaction\n // Delete the selection.\n\n\n Transaction.prototype.deleteSelection = function deleteSelection() {\n this.selection.replace(this);\n return this;\n }; // :: (string, from: ?number, to: ?number) → Transaction\n // Replace the given range, or the selection if no range is given,\n // with a text node containing the given string.\n\n\n Transaction.prototype.insertText = function insertText(text, from, to) {\n if (to === void 0) to = from;\n var schema = this.doc.type.schema;\n\n if (from == null) {\n if (!text) {\n return this.deleteSelection();\n }\n\n return this.replaceSelectionWith(schema.text(text), true);\n } else {\n if (!text) {\n return this.deleteRange(from, to);\n }\n\n var marks = this.storedMarks;\n\n if (!marks) {\n var $from = this.doc.resolve(from);\n marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to));\n }\n\n this.replaceRangeWith(from, to, schema.text(text, marks));\n\n if (!this.selection.empty) {\n this.setSelection(Selection.near(this.selection.$to));\n }\n\n return this;\n }\n }; // :: (union, any) → Transaction\n // Store a metadata property in this transaction, keyed either by\n // name or by plugin.\n\n\n Transaction.prototype.setMeta = function setMeta(key, value) {\n this.meta[typeof key == \"string\" ? key : key.key] = value;\n return this;\n }; // :: (union) → any\n // Retrieve a metadata property for a given name or plugin.\n\n\n Transaction.prototype.getMeta = function getMeta(key) {\n return this.meta[typeof key == \"string\" ? key : key.key];\n }; // :: bool\n // Returns true if this transaction doesn't contain any metadata,\n // and can thus safely be extended.\n\n\n prototypeAccessors.isGeneric.get = function () {\n for (var _ in this.meta) {\n return false;\n }\n\n return true;\n }; // :: () → Transaction\n // Indicate that the editor should scroll the selection into view\n // when updated to the state produced by this transaction.\n\n\n Transaction.prototype.scrollIntoView = function scrollIntoView() {\n this.updated |= UPDATED_SCROLL;\n return this;\n };\n\n prototypeAccessors.scrolledIntoView.get = function () {\n return (this.updated & UPDATED_SCROLL) > 0;\n };\n\n Object.defineProperties(Transaction.prototype, prototypeAccessors);\n return Transaction;\n}(Transform);\n\nfunction bind(f, self) {\n return !self || !f ? f : f.bind(self);\n}\n\nvar FieldDesc = function FieldDesc(name, desc, self) {\n this.name = name;\n this.init = bind(desc.init, self);\n this.apply = bind(desc.apply, self);\n};\n\nvar baseFields = [new FieldDesc(\"doc\", {\n init: function init(config) {\n return config.doc || config.schema.topNodeType.createAndFill();\n },\n apply: function apply(tr) {\n return tr.doc;\n }\n}), new FieldDesc(\"selection\", {\n init: function init(config, instance) {\n return config.selection || Selection.atStart(instance.doc);\n },\n apply: function apply(tr) {\n return tr.selection;\n }\n}), new FieldDesc(\"storedMarks\", {\n init: function init(config) {\n return config.storedMarks || null;\n },\n apply: function apply(tr, _marks, _old, state) {\n return state.selection.$cursor ? tr.storedMarks : null;\n }\n}), new FieldDesc(\"scrollToSelection\", {\n init: function init() {\n return 0;\n },\n apply: function apply(tr, prev) {\n return tr.scrolledIntoView ? prev + 1 : prev;\n }\n})]; // Object wrapping the part of a state object that stays the same\n// across transactions. Stored in the state's `config` property.\n\nvar Configuration = function Configuration(schema, plugins) {\n var this$1 = this;\n this.schema = schema;\n this.fields = baseFields.concat();\n this.plugins = [];\n this.pluginsByKey = Object.create(null);\n\n if (plugins) {\n plugins.forEach(function (plugin) {\n if (this$1.pluginsByKey[plugin.key]) {\n throw new RangeError(\"Adding different instances of a keyed plugin (\" + plugin.key + \")\");\n }\n\n this$1.plugins.push(plugin);\n this$1.pluginsByKey[plugin.key] = plugin;\n\n if (plugin.spec.state) {\n this$1.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin));\n }\n });\n }\n}; // ::- The state of a ProseMirror editor is represented by an object\n// of this type. A state is a persistent data structure—it isn't\n// updated, but rather a new state value is computed from an old one\n// using the [`apply`](#state.EditorState.apply) method.\n//\n// A state holds a number of built-in fields, and plugins can\n// [define](#state.PluginSpec.state) additional fields.\n\n\nvar EditorState = function EditorState(config) {\n this.config = config;\n};\n\nvar prototypeAccessors$1 = {\n schema: {\n configurable: true\n },\n plugins: {\n configurable: true\n },\n tr: {\n configurable: true\n }\n}; // doc:: Node\n// The current document.\n// selection:: Selection\n// The selection.\n// storedMarks:: ?[Mark]\n// A set of marks to apply to the next input. Will be null when\n// no explicit marks have been set.\n// :: Schema\n// The schema of the state's document.\n\nprototypeAccessors$1.schema.get = function () {\n return this.config.schema;\n}; // :: [Plugin]\n// The plugins that are active in this state.\n\n\nprototypeAccessors$1.plugins.get = function () {\n return this.config.plugins;\n}; // :: (Transaction) → EditorState\n// Apply the given transaction to produce a new state.\n\n\nEditorState.prototype.apply = function apply(tr) {\n return this.applyTransaction(tr).state;\n}; // : (Transaction) → bool\n\n\nEditorState.prototype.filterTransaction = function filterTransaction(tr, ignore) {\n if (ignore === void 0) ignore = -1;\n\n for (var i = 0; i < this.config.plugins.length; i++) {\n if (i != ignore) {\n var plugin = this.config.plugins[i];\n\n if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this)) {\n return false;\n }\n }\n }\n\n return true;\n}; // :: (Transaction) → {state: EditorState, transactions: [Transaction]}\n// Verbose variant of [`apply`](#state.EditorState.apply) that\n// returns the precise transactions that were applied (which might\n// be influenced by the [transaction\n// hooks](#state.PluginSpec.filterTransaction) of\n// plugins) along with the new state.\n\n\nEditorState.prototype.applyTransaction = function applyTransaction(rootTr) {\n if (!this.filterTransaction(rootTr)) {\n return {\n state: this,\n transactions: []\n };\n }\n\n var trs = [rootTr],\n newState = this.applyInner(rootTr),\n seen = null; // This loop repeatedly gives plugins a chance to respond to\n // transactions as new transactions are added, making sure to only\n // pass the transactions the plugin did not see before.\n\n for (;;) {\n var haveNew = false;\n\n for (var i = 0; i < this.config.plugins.length; i++) {\n var plugin = this.config.plugins[i];\n\n if (plugin.spec.appendTransaction) {\n var n = seen ? seen[i].n : 0,\n oldState = seen ? seen[i].state : this;\n var tr = n < trs.length && plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState);\n\n if (tr && newState.filterTransaction(tr, i)) {\n tr.setMeta(\"appendedTransaction\", rootTr);\n\n if (!seen) {\n seen = [];\n\n for (var j = 0; j < this.config.plugins.length; j++) {\n seen.push(j < i ? {\n state: newState,\n n: trs.length\n } : {\n state: this,\n n: 0\n });\n }\n }\n\n trs.push(tr);\n newState = newState.applyInner(tr);\n haveNew = true;\n }\n\n if (seen) {\n seen[i] = {\n state: newState,\n n: trs.length\n };\n }\n }\n }\n\n if (!haveNew) {\n return {\n state: newState,\n transactions: trs\n };\n }\n }\n}; // : (Transaction) → EditorState\n\n\nEditorState.prototype.applyInner = function applyInner(tr) {\n if (!tr.before.eq(this.doc)) {\n throw new RangeError(\"Applying a mismatched transaction\");\n }\n\n var newInstance = new EditorState(this.config),\n fields = this.config.fields;\n\n for (var i = 0; i < fields.length; i++) {\n var field = fields[i];\n newInstance[field.name] = field.apply(tr, this[field.name], this, newInstance);\n }\n\n for (var i$1 = 0; i$1 < applyListeners.length; i$1++) {\n applyListeners[i$1](this, tr, newInstance);\n }\n\n return newInstance;\n}; // :: Transaction\n// Start a [transaction](#state.Transaction) from this state.\n\n\nprototypeAccessors$1.tr.get = function () {\n return new Transaction(this);\n}; // :: (Object) → EditorState\n// Create a new state.\n//\n// config::- Configuration options. Must contain `schema` or `doc` (or both).\n//\n// schema:: ?Schema\n// The schema to use (only relevant if no `doc` is specified).\n//\n// doc:: ?Node\n// The starting document.\n//\n// selection:: ?Selection\n// A valid selection in the document.\n//\n// storedMarks:: ?[Mark]\n// The initial set of [stored marks](#state.EditorState.storedMarks).\n//\n// plugins:: ?[Plugin]\n// The plugins that should be active in this state.\n\n\nEditorState.create = function create(config) {\n var $config = new Configuration(config.doc ? config.doc.type.schema : config.schema, config.plugins);\n var instance = new EditorState($config);\n\n for (var i = 0; i < $config.fields.length; i++) {\n instance[$config.fields[i].name] = $config.fields[i].init(config, instance);\n }\n\n return instance;\n}; // :: (Object) → EditorState\n// Create a new state based on this one, but with an adjusted set of\n// active plugins. State fields that exist in both sets of plugins\n// are kept unchanged. Those that no longer exist are dropped, and\n// those that are new are initialized using their\n// [`init`](#state.StateField.init) method, passing in the new\n// configuration object..\n//\n// config::- configuration options\n//\n// plugins:: [Plugin]\n// New set of active plugins.\n\n\nEditorState.prototype.reconfigure = function reconfigure(config) {\n var $config = new Configuration(this.schema, config.plugins);\n var fields = $config.fields,\n instance = new EditorState($config);\n\n for (var i = 0; i < fields.length; i++) {\n var name = fields[i].name;\n instance[name] = this.hasOwnProperty(name) ? this[name] : fields[i].init(config, instance);\n }\n\n return instance;\n}; // :: (?union