) → 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\nfunction _get(target, property, receiver) { if (typeof Reflect !== \"undefined\" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }\n\nfunction _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nimport { Slice, Fragment, Mark, Node } from 'prosemirror-model';\nimport { ReplaceStep, ReplaceAroundStep, Transform } from 'prosemirror-transform';\nvar classesById = Object.create(null);\n/**\nSuperclass for editor selections. Every selection type should\nextend this. Should not be instantiated directly.\n*/\n\nvar Selection = /*#__PURE__*/function () {\n /**\n Initialize a selection with the head and anchor and ranges. If no\n ranges are given, constructs a single range across `$anchor` and\n `$head`.\n */\n function Selection(\n /**\n The resolved anchor of the selection (the side that stays in\n place when the selection is modified).\n */\n $anchor,\n /**\n The resolved head of the selection (the side that moves when\n the selection is modified).\n */\n $head, ranges) {\n _classCallCheck(this, Selection);\n\n this.$anchor = $anchor;\n this.$head = $head;\n this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))];\n }\n /**\n The selection's anchor, as an unresolved position.\n */\n\n\n _createClass(Selection, [{\n key: \"anchor\",\n get: function get() {\n return this.$anchor.pos;\n }\n /**\n The selection's head.\n */\n\n }, {\n key: \"head\",\n get: function get() {\n return this.$head.pos;\n }\n /**\n The lower bound of the selection's main range.\n */\n\n }, {\n key: \"from\",\n get: function get() {\n return this.$from.pos;\n }\n /**\n The upper bound of the selection's main range.\n */\n\n }, {\n key: \"to\",\n get: function get() {\n return this.$to.pos;\n }\n /**\n The resolved lower bound of the selection's main range.\n */\n\n }, {\n key: \"$from\",\n get: function get() {\n return this.ranges[0].$from;\n }\n /**\n The resolved upper bound of the selection's main range.\n */\n\n }, {\n key: \"$to\",\n get: function get() {\n return this.ranges[0].$to;\n }\n /**\n Indicates whether the selection contains any content.\n */\n\n }, {\n key: \"empty\",\n get: function get() {\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) return false;\n }\n\n return true;\n }\n /**\n Get the content of this selection as a slice.\n */\n\n }, {\n key: \"content\",\n value: function content() {\n return this.$from.doc.slice(this.from, this.to, true);\n }\n /**\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\n }, {\n key: \"replace\",\n value: function replace(tr) {\n var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Slice.empty;\n // 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 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 = 0; _i < ranges.length; _i++) {\n var _ranges$_i = ranges[_i],\n $from = _ranges$_i.$from,\n $to = _ranges$_i.$to,\n mapping = tr.mapping.slice(mapFrom);\n tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), _i ? Slice.empty : content);\n if (_i == 0) selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);\n }\n }\n /**\n Replace the selection with the given node, appending the changes\n to the given transaction.\n */\n\n }, {\n key: \"replaceWith\",\n value: 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 _ranges$i = ranges[i],\n $from = _ranges$i.$from,\n $to = _ranges$i.$to,\n 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 }\n /**\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\n }, {\n key: \"getBookmark\",\n value:\n /**\n Get a [bookmark](https://prosemirror.net/docs/ref/#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 function getBookmark() {\n return TextSelection.between(this.$anchor, this.$head).getBookmark();\n }\n }], [{\n key: \"findFrom\",\n value: function findFrom($pos, dir) {\n var textOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;\n var inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);\n if (inner) return inner;\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 if (found) return found;\n }\n\n return null;\n }\n /**\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\n }, {\n key: \"near\",\n value: function near($pos) {\n var bias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;\n return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));\n }\n /**\n Find the cursor or leaf node selection closest to the start of\n the given document. Will return an\n [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position\n exists.\n */\n\n }, {\n key: \"atStart\",\n value: function atStart(doc) {\n return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);\n }\n /**\n Find the cursor or leaf node selection closest to the end of the\n given document.\n */\n\n }, {\n key: \"atEnd\",\n value: function atEnd(doc) {\n return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);\n }\n /**\n Deserialize the JSON representation of a selection. Must be\n implemented for custom classes (as a static class method).\n */\n\n }, {\n key: \"fromJSON\",\n value: function fromJSON(doc, json) {\n if (!json || !json.type) throw new RangeError(\"Invalid input for Selection.fromJSON\");\n var cls = classesById[json.type];\n if (!cls) throw new RangeError(\"No selection type \".concat(json.type, \" defined\"));\n return cls.fromJSON(doc, json);\n }\n /**\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\n }, {\n key: \"jsonID\",\n value: function jsonID(id, selectionClass) {\n if (id in classesById) throw new RangeError(\"Duplicate use of selection JSON ID \" + id);\n classesById[id] = selectionClass;\n selectionClass.prototype.jsonID = id;\n return selectionClass;\n }\n }]);\n\n return Selection;\n}();\n\nSelection.prototype.visible = true;\n/**\nRepresents a selected range in a document.\n*/\n\nvar SelectionRange =\n/**\nCreate a range.\n*/\nfunction SelectionRange(\n/**\nThe lower bound of the range.\n*/\n$from,\n/**\nThe upper bound of the range.\n*/\n$to) {\n _classCallCheck(this, SelectionRange);\n\n this.$from = $from;\n this.$to = $to;\n};\n\nvar warnedAboutTextSelection = false;\n\nfunction checkTextSelection($pos) {\n if (!warnedAboutTextSelection && !$pos.parent.inlineContent) {\n warnedAboutTextSelection = true;\n console[\"warn\"](\"TextSelection endpoint not pointing into a node with inline content (\" + $pos.parent.type.name + \")\");\n }\n}\n/**\nA text selection represents a classical editor selection, with a\nhead (the moving side) and anchor (immobile side), both of which\npoint into textblock nodes. It can be empty (a regular cursor\nposition).\n*/\n\n\nvar TextSelection = /*#__PURE__*/function (_Selection) {\n _inherits(TextSelection, _Selection);\n\n var _super = _createSuper(TextSelection);\n\n /**\n Construct a text selection between the given points.\n */\n function TextSelection($anchor) {\n var $head = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : $anchor;\n\n _classCallCheck(this, TextSelection);\n\n checkTextSelection($anchor);\n checkTextSelection($head);\n return _super.call(this, $anchor, $head);\n }\n /**\n Returns a resolved position if this is a cursor selection (an\n empty text selection), and null otherwise.\n */\n\n\n _createClass(TextSelection, [{\n key: \"$cursor\",\n get: function get() {\n return this.$anchor.pos == this.$head.pos ? this.$head : null;\n }\n }, {\n key: \"map\",\n value: function map(doc, mapping) {\n var $head = doc.resolve(mapping.map(this.head));\n if (!$head.parent.inlineContent) return Selection.near($head);\n var $anchor = doc.resolve(mapping.map(this.anchor));\n return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);\n }\n }, {\n key: \"replace\",\n value: function replace(tr) {\n var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Slice.empty;\n\n _get(_getPrototypeOf(TextSelection.prototype), \"replace\", this).call(this, tr, content);\n\n if (content == Slice.empty) {\n var marks = this.$from.marksAcross(this.$to);\n if (marks) tr.ensureMarks(marks);\n }\n }\n }, {\n key: \"eq\",\n value: function eq(other) {\n return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head;\n }\n }, {\n key: \"getBookmark\",\n value: function getBookmark() {\n return new TextBookmark(this.anchor, this.head);\n }\n }, {\n key: \"toJSON\",\n value: function toJSON() {\n return {\n type: \"text\",\n anchor: this.anchor,\n head: this.head\n };\n }\n /**\n @internal\n */\n\n }], [{\n key: \"fromJSON\",\n value: function fromJSON(doc, json) {\n if (typeof json.anchor != \"number\" || typeof json.head != \"number\") throw new RangeError(\"Invalid input for TextSelection.fromJSON\");\n return new TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));\n }\n /**\n Create a text selection from non-resolved positions.\n */\n\n }, {\n key: \"create\",\n value: function create(doc, anchor) {\n var head = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : anchor;\n var $anchor = doc.resolve(anchor);\n return new this($anchor, head == anchor ? $anchor : doc.resolve(head));\n }\n /**\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`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document\n doesn't contain a valid text position.\n */\n\n }, {\n key: \"between\",\n value: function between($anchor, $head, bias) {\n var dPos = $anchor.pos - $head.pos;\n if (!bias || dPos) bias = dPos >= 0 ? 1 : -1;\n\n if (!$head.parent.inlineContent) {\n var found = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);\n if (found) $head = found.$head;else return Selection.near($head, bias);\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 if ($anchor.pos < $head.pos != dPos < 0) $anchor = $head;\n }\n }\n\n return new TextSelection($anchor, $head);\n }\n }]);\n\n return TextSelection;\n}(Selection);\n\nSelection.jsonID(\"text\", TextSelection);\n\nvar TextBookmark = /*#__PURE__*/function () {\n function TextBookmark(anchor, head) {\n _classCallCheck(this, TextBookmark);\n\n this.anchor = anchor;\n this.head = head;\n }\n\n _createClass(TextBookmark, [{\n key: \"map\",\n value: function map(mapping) {\n return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head));\n }\n }, {\n key: \"resolve\",\n value: function resolve(doc) {\n return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));\n }\n }]);\n\n return TextBookmark;\n}();\n/**\nA node selection is a selection that points at a single node. All\nnodes marked [selectable](https://prosemirror.net/docs/ref/#model.NodeSpec.selectable) can be the\ntarget of a node selection. In such a selection, `from` and `to`\npoint directly before and after the selected node, `anchor` equals\n`from`, and `head` equals `to`..\n*/\n\n\nvar NodeSelection = /*#__PURE__*/function (_Selection2) {\n _inherits(NodeSelection, _Selection2);\n\n var _super2 = _createSuper(NodeSelection);\n\n /**\n Create a node selection. Does not verify the validity of its\n argument.\n */\n function NodeSelection($pos) {\n var _this;\n\n _classCallCheck(this, NodeSelection);\n\n var node = $pos.nodeAfter;\n var $end = $pos.node(0).resolve($pos.pos + node.nodeSize);\n _this = _super2.call(this, $pos, $end);\n _this.node = node;\n return _this;\n }\n\n _createClass(NodeSelection, [{\n key: \"map\",\n value: function map(doc, mapping) {\n var _mapping$mapResult = mapping.mapResult(this.anchor),\n deleted = _mapping$mapResult.deleted,\n pos = _mapping$mapResult.pos;\n\n var $pos = doc.resolve(pos);\n if (deleted) return Selection.near($pos);\n return new NodeSelection($pos);\n }\n }, {\n key: \"content\",\n value: function content() {\n return new Slice(Fragment.from(this.node), 0, 0);\n }\n }, {\n key: \"eq\",\n value: function eq(other) {\n return other instanceof NodeSelection && other.anchor == this.anchor;\n }\n }, {\n key: \"toJSON\",\n value: function toJSON() {\n return {\n type: \"node\",\n anchor: this.anchor\n };\n }\n }, {\n key: \"getBookmark\",\n value: function getBookmark() {\n return new NodeBookmark(this.anchor);\n }\n /**\n @internal\n */\n\n }], [{\n key: \"fromJSON\",\n value: function fromJSON(doc, json) {\n if (typeof json.anchor != \"number\") throw new RangeError(\"Invalid input for NodeSelection.fromJSON\");\n return new NodeSelection(doc.resolve(json.anchor));\n }\n /**\n Create a node selection from non-resolved positions.\n */\n\n }, {\n key: \"create\",\n value: function create(doc, from) {\n return new NodeSelection(doc.resolve(from));\n }\n /**\n Determines whether the given node may be selected as a node\n selection.\n */\n\n }, {\n key: \"isSelectable\",\n value: function isSelectable(node) {\n return !node.isText && node.type.spec.selectable !== false;\n }\n }]);\n\n return NodeSelection;\n}(Selection);\n\nNodeSelection.prototype.visible = false;\nSelection.jsonID(\"node\", NodeSelection);\n\nvar NodeBookmark = /*#__PURE__*/function () {\n function NodeBookmark(anchor) {\n _classCallCheck(this, NodeBookmark);\n\n this.anchor = anchor;\n }\n\n _createClass(NodeBookmark, [{\n key: \"map\",\n value: function map(mapping) {\n var _mapping$mapResult2 = mapping.mapResult(this.anchor),\n deleted = _mapping$mapResult2.deleted,\n pos = _mapping$mapResult2.pos;\n\n return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos);\n }\n }, {\n key: \"resolve\",\n value: function resolve(doc) {\n var $pos = doc.resolve(this.anchor),\n node = $pos.nodeAfter;\n if (node && NodeSelection.isSelectable(node)) return new NodeSelection($pos);\n return Selection.near($pos);\n }\n }]);\n\n return NodeBookmark;\n}();\n/**\nA selection type that represents selecting the whole document\n(which can not necessarily be expressed with a text selection, when\nthere are for example leaf block nodes at the start or end of the\ndocument).\n*/\n\n\nvar AllSelection = /*#__PURE__*/function (_Selection3) {\n _inherits(AllSelection, _Selection3);\n\n var _super3 = _createSuper(AllSelection);\n\n /**\n Create an all-selection over the given document.\n */\n function AllSelection(doc) {\n _classCallCheck(this, AllSelection);\n\n return _super3.call(this, doc.resolve(0), doc.resolve(doc.content.size));\n }\n\n _createClass(AllSelection, [{\n key: \"replace\",\n value: function replace(tr) {\n var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Slice.empty;\n\n if (content == Slice.empty) {\n tr.delete(0, tr.doc.content.size);\n var sel = Selection.atStart(tr.doc);\n if (!sel.eq(tr.selection)) tr.setSelection(sel);\n } else {\n _get(_getPrototypeOf(AllSelection.prototype), \"replace\", this).call(this, tr, content);\n }\n }\n }, {\n key: \"toJSON\",\n value: function toJSON() {\n return {\n type: \"all\"\n };\n }\n /**\n @internal\n */\n\n }, {\n key: \"map\",\n value: function map(doc) {\n return new AllSelection(doc);\n }\n }, {\n key: \"eq\",\n value: function eq(other) {\n return other instanceof AllSelection;\n }\n }, {\n key: \"getBookmark\",\n value: function getBookmark() {\n return AllBookmark;\n }\n }], [{\n key: \"fromJSON\",\n value: function fromJSON(doc) {\n return new AllSelection(doc);\n }\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) {\n var text = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;\n if (node.inlineContent) return TextSelection.create(doc, pos);\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 if (inner) return inner;\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 return null;\n}\n\nfunction selectionToInsertionEnd(tr, startLen, bias) {\n var last = tr.steps.length - 1;\n if (last < startLen) return;\n var step = tr.steps[last];\n if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) return;\n var map = tr.mapping.maps[last],\n end;\n map.forEach(function (_from, _to, _newFrom, newTo) {\n if (end == null) end = newTo;\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;\n/**\nAn editor state transaction, which can be applied to a state to\ncreate an updated state. Use\n[`EditorState.tr`](https://prosemirror.net/docs/ref/#state.EditorState.tr) to create an instance.\n\nTransactions track changes to the document (they are a subclass of\n[`Transform`](https://prosemirror.net/docs/ref/#transform.Transform)), but also other state changes,\nlike selection updates and adjustments of the set of [stored\nmarks](https://prosemirror.net/docs/ref/#state.EditorState.storedMarks). In addition, you can store\nmetadata properties in a transaction, which are extra pieces of\ninformation that client code or plugins can use to describe what a\ntransaction represents, so that they can update their [own\nstate](https://prosemirror.net/docs/ref/#state.StateField) accordingly.\n\nThe [editor view](https://prosemirror.net/docs/ref/#view.EditorView) uses a few metadata properties:\nit will attach a property `\"pointer\"` with the value `true` to\nselection transactions directly caused by mouse or touch input, and\na `\"uiEvent\"` property of that may be `\"paste\"`, `\"cut\"`, or `\"drop\"`.\n*/\n\nvar Transaction = /*#__PURE__*/function (_Transform) {\n _inherits(Transaction, _Transform);\n\n var _super4 = _createSuper(Transaction);\n\n /**\n @internal\n */\n function Transaction(state) {\n var _this2;\n\n _classCallCheck(this, Transaction);\n\n _this2 = _super4.call(this, state.doc); // The step count for which the current selection is valid.\n\n _this2.curSelectionFor = 0; // Bitfield to track which aspects of the state were updated by\n // this transaction.\n\n _this2.updated = 0; // Object used to store metadata properties for the transaction.\n\n _this2.meta = Object.create(null);\n _this2.time = Date.now();\n _this2.curSelection = state.selection;\n _this2.storedMarks = state.storedMarks;\n return _this2;\n }\n /**\n The transaction's current selection. This defaults to the editor\n selection [mapped](https://prosemirror.net/docs/ref/#state.Selection.map) through the steps in the\n transaction, but can be overwritten with\n [`setSelection`](https://prosemirror.net/docs/ref/#state.Transaction.setSelection).\n */\n\n\n _createClass(Transaction, [{\n key: \"selection\",\n get: function get() {\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 }\n /**\n Update the transaction's current selection. Will determine the\n selection that the editor gets when the transaction is applied.\n */\n\n }, {\n key: \"setSelection\",\n value: function setSelection(selection) {\n if (selection.$from.doc != this.doc) throw new RangeError(\"Selection passed to setSelection must point at the current document\");\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 }\n /**\n Whether the selection was explicitly updated by this transaction.\n */\n\n }, {\n key: \"selectionSet\",\n get: function get() {\n return (this.updated & UPDATED_SEL) > 0;\n }\n /**\n Set the current stored marks.\n */\n\n }, {\n key: \"setStoredMarks\",\n value: function setStoredMarks(marks) {\n this.storedMarks = marks;\n this.updated |= UPDATED_MARKS;\n return this;\n }\n /**\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 }, {\n key: \"ensureMarks\",\n value: function ensureMarks(marks) {\n if (!Mark.sameSet(this.storedMarks || this.selection.$from.marks(), marks)) this.setStoredMarks(marks);\n return this;\n }\n /**\n Add a mark to the set of stored marks.\n */\n\n }, {\n key: \"addStoredMark\",\n value: function addStoredMark(mark) {\n return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks()));\n }\n /**\n Remove a mark or mark type from the set of stored marks.\n */\n\n }, {\n key: \"removeStoredMark\",\n value: function removeStoredMark(mark) {\n return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks()));\n }\n /**\n Whether the stored marks were explicitly set for this transaction.\n */\n\n }, {\n key: \"storedMarksSet\",\n get: function get() {\n return (this.updated & UPDATED_MARKS) > 0;\n }\n /**\n @internal\n */\n\n }, {\n key: \"addStep\",\n value: function addStep(step, doc) {\n _get(_getPrototypeOf(Transaction.prototype), \"addStep\", this).call(this, step, doc);\n\n this.updated = this.updated & ~UPDATED_MARKS;\n this.storedMarks = null;\n }\n /**\n Update the timestamp for the transaction.\n */\n\n }, {\n key: \"setTime\",\n value: function setTime(time) {\n this.time = time;\n return this;\n }\n /**\n Replace the current selection with the given slice.\n */\n\n }, {\n key: \"replaceSelection\",\n value: function replaceSelection(slice) {\n this.selection.replace(this, slice);\n return this;\n }\n /**\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 }, {\n key: \"replaceSelectionWith\",\n value: function replaceSelectionWith(node) {\n var inheritMarks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n var selection = this.selection;\n if (inheritMarks) node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : selection.$from.marksAcross(selection.$to) || Mark.none));\n selection.replaceWith(this, node);\n return this;\n }\n /**\n Delete the selection.\n */\n\n }, {\n key: \"deleteSelection\",\n value: function deleteSelection() {\n this.selection.replace(this);\n return this;\n }\n /**\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 }, {\n key: \"insertText\",\n value: function insertText(text, from, to) {\n var schema = this.doc.type.schema;\n\n if (from == null) {\n if (!text) return this.deleteSelection();\n return this.replaceSelectionWith(schema.text(text), true);\n } else {\n if (to == null) to = from;\n to = to == null ? from : to;\n if (!text) return this.deleteRange(from, to);\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 if (!this.selection.empty) this.setSelection(Selection.near(this.selection.$to));\n return this;\n }\n }\n /**\n Store a metadata property in this transaction, keyed either by\n name or by plugin.\n */\n\n }, {\n key: \"setMeta\",\n value: function setMeta(key, value) {\n this.meta[typeof key == \"string\" ? key : key.key] = value;\n return this;\n }\n /**\n Retrieve a metadata property for a given name or plugin.\n */\n\n }, {\n key: \"getMeta\",\n value: function getMeta(key) {\n return this.meta[typeof key == \"string\" ? key : key.key];\n }\n /**\n Returns true if this transaction doesn't contain any metadata,\n and can thus safely be extended.\n */\n\n }, {\n key: \"isGeneric\",\n get: function get() {\n for (var _ in this.meta) {\n return false;\n }\n\n return true;\n }\n /**\n Indicate that the editor should scroll the selection into view\n when updated to the state produced by this transaction.\n */\n\n }, {\n key: \"scrollIntoView\",\n value: function scrollIntoView() {\n this.updated |= UPDATED_SCROLL;\n return this;\n }\n /**\n True when this transaction has had `scrollIntoView` called on it.\n */\n\n }, {\n key: \"scrolledIntoView\",\n get: function get() {\n return (this.updated & UPDATED_SCROLL) > 0;\n }\n }]);\n\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 _classCallCheck(this, FieldDesc);\n\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 _this3 = this;\n\n _classCallCheck(this, Configuration);\n\n this.schema = schema;\n this.plugins = [];\n this.pluginsByKey = Object.create(null);\n this.fields = baseFields.slice();\n if (plugins) plugins.forEach(function (plugin) {\n if (_this3.pluginsByKey[plugin.key]) throw new RangeError(\"Adding different instances of a keyed plugin (\" + plugin.key + \")\");\n\n _this3.plugins.push(plugin);\n\n _this3.pluginsByKey[plugin.key] = plugin;\n if (plugin.spec.state) _this3.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin));\n });\n};\n/**\nThe state of a ProseMirror editor is represented by an object of\nthis type. A state is a persistent data structure—it isn't\nupdated, but rather a new state value is computed from an old one\nusing the [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) method.\n\nA state holds a number of built-in fields, and plugins can\n[define](https://prosemirror.net/docs/ref/#state.PluginSpec.state) additional fields.\n*/\n\n\nvar EditorState = /*#__PURE__*/function () {\n /**\n @internal\n */\n function EditorState(\n /**\n @internal\n */\n config) {\n _classCallCheck(this, EditorState);\n\n this.config = config;\n }\n /**\n The schema of the state's document.\n */\n\n\n _createClass(EditorState, [{\n key: \"schema\",\n get: function get() {\n return this.config.schema;\n }\n /**\n The plugins that are active in this state.\n */\n\n }, {\n key: \"plugins\",\n get: function get() {\n return this.config.plugins;\n }\n /**\n Apply the given transaction to produce a new state.\n */\n\n }, {\n key: \"apply\",\n value: function apply(tr) {\n return this.applyTransaction(tr).state;\n }\n /**\n @internal\n */\n\n }, {\n key: \"filterTransaction\",\n value: function filterTransaction(tr) {\n var ignore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -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 if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this)) return false;\n }\n }\n\n return true;\n }\n /**\n Verbose variant of [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) that\n returns the precise transactions that were applied (which might\n be influenced by the [transaction\n hooks](https://prosemirror.net/docs/ref/#state.PluginSpec.filterTransaction) of\n plugins) along with the new state.\n */\n\n }, {\n key: \"applyTransaction\",\n value: function applyTransaction(rootTr) {\n if (!this.filterTransaction(rootTr)) return {\n state: this,\n transactions: []\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) seen[i] = {\n state: newState,\n n: trs.length\n };\n }\n }\n\n if (!haveNew) return {\n state: newState,\n transactions: trs\n };\n }\n }\n /**\n @internal\n */\n\n }, {\n key: \"applyInner\",\n value: function applyInner(tr) {\n if (!tr.before.eq(this.doc)) throw new RangeError(\"Applying a mismatched transaction\");\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 return newInstance;\n }\n /**\n Start a [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.\n */\n\n }, {\n key: \"tr\",\n get: function get() {\n return new Transaction(this);\n }\n /**\n Create a new state.\n */\n\n }, {\n key: \"reconfigure\",\n value:\n /**\n Create a new state based on this one, but with an adjusted set\n of active plugins. State fields that exist in both sets of\n plugins are kept unchanged. Those that no longer exist are\n dropped, and those that are new are initialized using their\n [`init`](https://prosemirror.net/docs/ref/#state.StateField.init) method, passing in the new\n configuration object..\n */\n 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 }\n /**\n Serialize this state to JSON. If you want to serialize the state\n of plugins, pass an object mapping property names to use in the\n resulting JSON object to plugin objects. The argument may also be\n a string or number, in which case it is ignored, to support the\n way `JSON.stringify` calls `toString` methods.\n */\n\n }, {\n key: \"toJSON\",\n value: function toJSON(pluginFields) {\n var result = {\n doc: this.doc.toJSON(),\n selection: this.selection.toJSON()\n };\n if (this.storedMarks) result.storedMarks = this.storedMarks.map(function (m) {\n return m.toJSON();\n });\n if (pluginFields && _typeof(pluginFields) == 'object') for (var prop in pluginFields) {\n if (prop == \"doc\" || prop == \"selection\") throw new RangeError(\"The JSON fields `doc` and `selection` are reserved\");\n var plugin = pluginFields[prop],\n state = plugin.spec.state;\n if (state && state.toJSON) result[prop] = state.toJSON.call(plugin, this[plugin.key]);\n }\n return result;\n }\n /**\n Deserialize a JSON representation of a state. `config` should\n have at least a `schema` field, and should contain array of\n plugins to initialize the state with. `pluginFields` can be used\n to deserialize the state of plugins, by associating plugin\n instances with the property names they use in the JSON object.\n */\n\n }], [{\n key: \"create\",\n value: 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 }\n }, {\n key: \"fromJSON\",\n value: function fromJSON(config, json, pluginFields) {\n if (!json) throw new RangeError(\"Invalid input for EditorState.fromJSON\");\n if (!config.schema) throw new RangeError(\"Required config field 'schema' missing\");\n var $config = new Configuration(config.schema, config.plugins);\n var instance = new EditorState($config);\n $config.fields.forEach(function (field) {\n if (field.name == \"doc\") {\n instance.doc = Node.fromJSON(config.schema, json.doc);\n } else if (field.name == \"selection\") {\n instance.selection = Selection.fromJSON(instance.doc, json.selection);\n } else if (field.name == \"storedMarks\") {\n if (json.storedMarks) instance.storedMarks = json.storedMarks.map(config.schema.markFromJSON);\n } else {\n if (pluginFields) for (var prop in pluginFields) {\n var plugin = pluginFields[prop],\n state = plugin.spec.state;\n\n if (plugin.key == field.name && state && state.fromJSON && Object.prototype.hasOwnProperty.call(json, prop)) {\n instance[field.name] = state.fromJSON.call(plugin, config, json[prop], instance);\n return;\n }\n }\n instance[field.name] = field.init(config, instance);\n }\n });\n return instance;\n }\n }]);\n\n return EditorState;\n}();\n\nfunction bindProps(obj, self, target) {\n for (var prop in obj) {\n var val = obj[prop];\n if (val instanceof Function) val = val.bind(self);else if (prop == \"handleDOMEvents\") val = bindProps(val, self, {});\n target[prop] = val;\n }\n\n return target;\n}\n/**\nPlugins bundle functionality that can be added to an editor.\nThey are part of the [editor state](https://prosemirror.net/docs/ref/#state.EditorState) and\nmay influence that state and the view that contains it.\n*/\n\n\nvar Plugin = /*#__PURE__*/function () {\n /**\n Create a plugin.\n */\n function Plugin(\n /**\n The plugin's [spec object](https://prosemirror.net/docs/ref/#state.PluginSpec).\n */\n spec) {\n _classCallCheck(this, Plugin);\n\n this.spec = spec;\n /**\n The [props](https://prosemirror.net/docs/ref/#view.EditorProps) exported by this plugin.\n */\n\n this.props = {};\n if (spec.props) bindProps(spec.props, this, this.props);\n this.key = spec.key ? spec.key.key : createKey(\"plugin\");\n }\n /**\n Extract the plugin's state field from an editor state.\n */\n\n\n _createClass(Plugin, [{\n key: \"getState\",\n value: function getState(state) {\n return state[this.key];\n }\n }]);\n\n return Plugin;\n}();\n\nvar keys = Object.create(null);\n\nfunction createKey(name) {\n if (name in keys) return name + \"$\" + ++keys[name];\n keys[name] = 0;\n return name + \"$\";\n}\n/**\nA key is used to [tag](https://prosemirror.net/docs/ref/#state.PluginSpec.key) plugins in a way\nthat makes it possible to find them, given an editor state.\nAssigning a key does mean only one plugin of that type can be\nactive in a state.\n*/\n\n\nvar PluginKey = /*#__PURE__*/function () {\n /**\n Create a plugin key.\n */\n function PluginKey() {\n var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : \"key\";\n\n _classCallCheck(this, PluginKey);\n\n this.key = createKey(name);\n }\n /**\n Get the active plugin with this key, if any, from an editor\n state.\n */\n\n\n _createClass(PluginKey, [{\n key: \"get\",\n value: function get(state) {\n return state.config.pluginsByKey[this.key];\n }\n /**\n Get the plugin's state from an editor state.\n */\n\n }, {\n key: \"getState\",\n value: function getState(state) {\n return state[this.key];\n }\n }]);\n\n return PluginKey;\n}();\n\nexport { AllSelection, EditorState, NodeSelection, Plugin, PluginKey, Selection, SelectionRange, TextSelection, Transaction };","// ::- Persistent data structure representing an ordered mapping from\n// strings to values, with some convenient update methods.\nfunction OrderedMap(content) {\n this.content = content;\n}\n\nOrderedMap.prototype = {\n constructor: OrderedMap,\n find: function find(key) {\n for (var i = 0; i < this.content.length; i += 2) {\n if (this.content[i] === key) return i;\n }\n\n return -1;\n },\n // :: (string) → ?any\n // Retrieve the value stored under `key`, or return undefined when\n // no such key exists.\n get: function get(key) {\n var found = this.find(key);\n return found == -1 ? undefined : this.content[found + 1];\n },\n // :: (string, any, ?string) → OrderedMap\n // Create a new map by replacing the value of `key` with a new\n // value, or adding a binding to the end of the map. If `newKey` is\n // given, the key of the binding will be replaced with that key.\n update: function update(key, value, newKey) {\n var self = newKey && newKey != key ? this.remove(newKey) : this;\n var found = self.find(key),\n content = self.content.slice();\n\n if (found == -1) {\n content.push(newKey || key, value);\n } else {\n content[found + 1] = value;\n if (newKey) content[found] = newKey;\n }\n\n return new OrderedMap(content);\n },\n // :: (string) → OrderedMap\n // Return a map with the given key removed, if it existed.\n remove: function remove(key) {\n var found = this.find(key);\n if (found == -1) return this;\n var content = this.content.slice();\n content.splice(found, 2);\n return new OrderedMap(content);\n },\n // :: (string, any) → OrderedMap\n // Add a new key to the start of the map.\n addToStart: function addToStart(key, value) {\n return new OrderedMap([key, value].concat(this.remove(key).content));\n },\n // :: (string, any) → OrderedMap\n // Add a new key to the end of the map.\n addToEnd: function addToEnd(key, value) {\n var content = this.remove(key).content.slice();\n content.push(key, value);\n return new OrderedMap(content);\n },\n // :: (string, string, any) → OrderedMap\n // Add a key after the given key. If `place` is not found, the new\n // key is added to the end.\n addBefore: function addBefore(place, key, value) {\n var without = this.remove(key),\n content = without.content.slice();\n var found = without.find(place);\n content.splice(found == -1 ? content.length : found, 0, key, value);\n return new OrderedMap(content);\n },\n // :: ((key: string, value: any))\n // Call the given function for each key/value pair in the map, in\n // order.\n forEach: function forEach(f) {\n for (var i = 0; i < this.content.length; i += 2) {\n f(this.content[i], this.content[i + 1]);\n }\n },\n // :: (union