UNPKG

@shopware-ag/meteor-component-library

Version:

The meteor component library is a Vue component library developed by Shopware. It is based on the [Meteor Design System](https://shopware.design/).

1,543 lines (1,542 loc) 1.94 MB
import '../mt-text-editor.css'; import { defineComponent, ref, onMounted, onBeforeUnmount, h, getCurrentInstance, watchEffect, nextTick, unref, shallowRef, markRaw, customRef, computed, watch, onUnmounted, reactive, useSlots, openBlock, createElementBlock, normalizeClass, toDisplayString, createCommentVNode, createElementVNode, createBlock, resolveDynamicComponent, withCtx, createVNode, createSlots, renderList, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, Fragment as Fragment$1 } from "vue"; import mtTextEditorToolbar from "./MtTextEditorToolbar.js"; import mtTextEditorToolbarButtonColor, { colorButton } from "./MtTextEditorToolbarButtonColor.js"; import mtTextEditorToolbarButtonLink, { linkButton } from "./MtTextEditorToolbarButtonLink.js"; import mtTextEditorToolbarButtonTable, { tableButton } from "./MtTextEditorToolbarButtonTable.js"; import mtTextEditorToolbarButton from "./MtTextEditorToolbarButton.js"; import mtPopoverItem from "./MtPopoverItem.js"; import mtPopover from "./MtPopover.js"; import MtFieldError from "./MtFieldError.js"; import { useI18n } from "vue-i18n"; import mtTextEditorDiffModal from "./MtTextEditorDiffModal.js"; import MtButton from "./MtButton.js"; import { _ as _export_sfc } from "../_plugin-vue_export-helper-cc2b3d55.mjs"; import "./MtColorpicker.js"; import "../debounce-b18437e2.mjs"; import "../mt-base-field-7a978dcf.mjs"; import "./MtInheritanceSwitch.js"; import "../mt-icon.vue_vue_type_style_index_0_lang-2cc5f73e.mjs"; import "./MtTooltip.js"; import "../floating-ui.vue-fe27ebef.mjs"; import "../floating-ui.dom-f450fda4.mjs"; import "../useIsInsideTooltip-0c3bd290.mjs"; import "../index-221bad05.mjs"; import "./MtFieldCopyable.js"; import "../tooltip.directive-a5042569.mjs"; import "../id-1e5b8276.mjs"; import "./MtHelpText.js"; import "../useFutureFlags-2be3e179.mjs"; import "../mt-floating-ui.vue_vue_type_style_index_0_lang-c9aba54c.mjs"; import "./MtText.js"; import "../focus-trap.esm-3b050c4a.mjs"; import "./MtLoader.js"; import "./MtModalRoot.js"; import "../useModalContext-3b7570bc.mjs"; import "./MtModal.js"; import "../mt-modal-close.vue_vue_type_script_setup_true_lang-15d65d8b.mjs"; import "./MtTextField.js"; import "../mt-switch.vue_vue_type_style_index_0_lang-e05ec27a.mjs"; import "./MtFieldLabel.js"; import "./MtNumberField.js"; import "./MtCheckbox.js"; import "./MtSmoothReflow.js"; import "../_commonjsHelpers-7a77ea84.mjs"; function OrderedMap(content2) { this.content = content2; } OrderedMap.prototype = { constructor: OrderedMap, find: function(key) { for (var i = 0; i < this.content.length; i += 2) if (this.content[i] === key) return i; return -1; }, // :: (string) → ?any // Retrieve the value stored under `key`, or return undefined when // no such key exists. get: function(key) { var found2 = this.find(key); return found2 == -1 ? void 0 : this.content[found2 + 1]; }, // :: (string, any, ?string) → OrderedMap // Create a new map by replacing the value of `key` with a new // value, or adding a binding to the end of the map. If `newKey` is // given, the key of the binding will be replaced with that key. update: function(key, value, newKey) { var self = newKey && newKey != key ? this.remove(newKey) : this; var found2 = self.find(key), content2 = self.content.slice(); if (found2 == -1) { content2.push(newKey || key, value); } else { content2[found2 + 1] = value; if (newKey) content2[found2] = newKey; } return new OrderedMap(content2); }, // :: (string) → OrderedMap // Return a map with the given key removed, if it existed. remove: function(key) { var found2 = this.find(key); if (found2 == -1) return this; var content2 = this.content.slice(); content2.splice(found2, 2); return new OrderedMap(content2); }, // :: (string, any) → OrderedMap // Add a new key to the start of the map. addToStart: function(key, value) { return new OrderedMap([key, value].concat(this.remove(key).content)); }, // :: (string, any) → OrderedMap // Add a new key to the end of the map. addToEnd: function(key, value) { var content2 = this.remove(key).content.slice(); content2.push(key, value); return new OrderedMap(content2); }, // :: (string, string, any) → OrderedMap // Add a key after the given key. If `place` is not found, the new // key is added to the end. addBefore: function(place, key, value) { var without = this.remove(key), content2 = without.content.slice(); var found2 = without.find(place); content2.splice(found2 == -1 ? content2.length : found2, 0, key, value); return new OrderedMap(content2); }, // :: ((key: string, value: any)) // Call the given function for each key/value pair in the map, in // order. forEach: function(f) { for (var i = 0; i < this.content.length; i += 2) f(this.content[i], this.content[i + 1]); }, // :: (union<Object, OrderedMap>) → OrderedMap // Create a new map by prepending the keys in this map that don't // appear in `map` before the keys in `map`. prepend: function(map2) { map2 = OrderedMap.from(map2); if (!map2.size) return this; return new OrderedMap(map2.content.concat(this.subtract(map2).content)); }, // :: (union<Object, OrderedMap>) → OrderedMap // Create a new map by appending the keys in this map that don't // appear in `map` after the keys in `map`. append: function(map2) { map2 = OrderedMap.from(map2); if (!map2.size) return this; return new OrderedMap(this.subtract(map2).content.concat(map2.content)); }, // :: (union<Object, OrderedMap>) → OrderedMap // Create a map containing all the keys in this map that don't // appear in `map`. subtract: function(map2) { var result = this; map2 = OrderedMap.from(map2); for (var i = 0; i < map2.content.length; i += 2) result = result.remove(map2.content[i]); return result; }, // :: () → Object // Turn ordered map into a plain object. toObject: function() { var result = {}; this.forEach(function(key, value) { result[key] = value; }); return result; }, // :: number // The amount of keys in this map. get size() { return this.content.length >> 1; } }; OrderedMap.from = function(value) { if (value instanceof OrderedMap) return value; var content2 = []; if (value) for (var prop in value) content2.push(prop, value[prop]); return new OrderedMap(content2); }; function findDiffStart(a, b, pos) { for (let i = 0; ; i++) { if (i == a.childCount || i == b.childCount) return a.childCount == b.childCount ? null : pos; let childA = a.child(i), childB = b.child(i); if (childA == childB) { pos += childA.nodeSize; continue; } if (!childA.sameMarkup(childB)) return pos; if (childA.isText && childA.text != childB.text) { for (let j = 0; childA.text[j] == childB.text[j]; j++) pos++; return pos; } if (childA.content.size || childB.content.size) { let inner = findDiffStart(childA.content, childB.content, pos + 1); if (inner != null) return inner; } pos += childA.nodeSize; } } function findDiffEnd(a, b, posA, posB) { for (let iA = a.childCount, iB = b.childCount; ; ) { if (iA == 0 || iB == 0) return iA == iB ? null : { a: posA, b: posB }; let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize; if (childA == childB) { posA -= size; posB -= size; continue; } if (!childA.sameMarkup(childB)) return { a: posA, b: posB }; if (childA.isText && childA.text != childB.text) { let same = 0, minSize = Math.min(childA.text.length, childB.text.length); while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) { same++; posA--; posB--; } return { a: posA, b: posB }; } if (childA.content.size || childB.content.size) { let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1); if (inner) return inner; } posA -= size; posB -= size; } } class Fragment { /** @internal */ constructor(content2, size) { this.content = content2; this.size = size || 0; if (size == null) for (let i = 0; i < content2.length; i++) this.size += content2[i].nodeSize; } /** Invoke a callback for all descendant nodes between the given two positions (relative to start of this fragment). Doesn't descend into a node when the callback returns `false`. */ nodesBetween(from2, to, f, nodeStart2 = 0, parent) { for (let i = 0, pos = 0; pos < to; i++) { let child = this.content[i], end2 = pos + child.nodeSize; if (end2 > from2 && f(child, nodeStart2 + pos, parent || null, i) !== false && child.content.size) { let start2 = pos + 1; child.nodesBetween(Math.max(0, from2 - start2), Math.min(child.content.size, to - start2), f, nodeStart2 + start2); } pos = end2; } } /** Call the given callback for every descendant node. `pos` will be relative to the start of the fragment. The callback may return `false` to prevent traversal of a given node's children. */ descendants(f) { this.nodesBetween(0, this.size, f); } /** Extract the text between `from` and `to`. See the same method on [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween). */ textBetween(from2, to, blockSeparator, leafText) { let text = "", first2 = true; this.nodesBetween(from2, to, (node, pos) => { let nodeText = node.isText ? node.text.slice(Math.max(from2, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : ""; if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) { if (first2) first2 = false; else text += blockSeparator; } text += nodeText; }, 0); return text; } /** Create a new fragment containing the combined content of this fragment and the other. */ append(other) { if (!other.size) return this; if (!this.size) return other; let last = this.lastChild, first2 = other.firstChild, content2 = this.content.slice(), i = 0; if (last.isText && last.sameMarkup(first2)) { content2[content2.length - 1] = last.withText(last.text + first2.text); i = 1; } for (; i < other.content.length; i++) content2.push(other.content[i]); return new Fragment(content2, this.size + other.size); } /** Cut out the sub-fragment between the two given positions. */ cut(from2, to = this.size) { if (from2 == 0 && to == this.size) return this; let result = [], size = 0; if (to > from2) for (let i = 0, pos = 0; pos < to; i++) { let child = this.content[i], end2 = pos + child.nodeSize; if (end2 > from2) { if (pos < from2 || end2 > to) { if (child.isText) child = child.cut(Math.max(0, from2 - pos), Math.min(child.text.length, to - pos)); else child = child.cut(Math.max(0, from2 - pos - 1), Math.min(child.content.size, to - pos - 1)); } result.push(child); size += child.nodeSize; } pos = end2; } return new Fragment(result, size); } /** @internal */ cutByIndex(from2, to) { if (from2 == to) return Fragment.empty; if (from2 == 0 && to == this.content.length) return this; return new Fragment(this.content.slice(from2, to)); } /** Create a new fragment in which the node at the given index is replaced by the given node. */ replaceChild(index, node) { let current = this.content[index]; if (current == node) return this; let copy2 = this.content.slice(); let size = this.size + node.nodeSize - current.nodeSize; copy2[index] = node; return new Fragment(copy2, size); } /** Create a new fragment by prepending the given node to this fragment. */ addToStart(node) { return new Fragment([node].concat(this.content), this.size + node.nodeSize); } /** Create a new fragment by appending the given node to this fragment. */ addToEnd(node) { return new Fragment(this.content.concat(node), this.size + node.nodeSize); } /** Compare this fragment to another one. */ eq(other) { if (this.content.length != other.content.length) return false; for (let i = 0; i < this.content.length; i++) if (!this.content[i].eq(other.content[i])) return false; return true; } /** The first child of the fragment, or `null` if it is empty. */ get firstChild() { return this.content.length ? this.content[0] : null; } /** The last child of the fragment, or `null` if it is empty. */ get lastChild() { return this.content.length ? this.content[this.content.length - 1] : null; } /** The number of child nodes in this fragment. */ get childCount() { return this.content.length; } /** Get the child node at the given index. Raise an error when the index is out of range. */ child(index) { let found2 = this.content[index]; if (!found2) throw new RangeError("Index " + index + " out of range for " + this); return found2; } /** Get the child node at the given index, if it exists. */ maybeChild(index) { return this.content[index] || null; } /** Call `f` for every child node, passing the node, its offset into this parent node, and its index. */ forEach(f) { for (let i = 0, p = 0; i < this.content.length; i++) { let child = this.content[i]; f(child, p, i); p += child.nodeSize; } } /** Find the first position at which this fragment and another fragment differ, or `null` if they are the same. */ findDiffStart(other, pos = 0) { return findDiffStart(this, other, pos); } /** Find the first position, searching from the end, at which this fragment and the given fragment differ, or `null` if they are the same. Since this position will not be the same in both nodes, an object with two separate positions is returned. */ findDiffEnd(other, pos = this.size, otherPos = other.size) { return findDiffEnd(this, other, pos, otherPos); } /** Find the index and inner offset corresponding to a given relative position in this fragment. The result object will be reused (overwritten) the next time the function is called. @internal */ findIndex(pos, round2 = -1) { if (pos == 0) return retIndex(0, pos); if (pos == this.size) return retIndex(this.content.length, pos); if (pos > this.size || pos < 0) throw new RangeError(`Position ${pos} outside of fragment (${this})`); for (let i = 0, curPos = 0; ; i++) { let cur2 = this.child(i), end2 = curPos + cur2.nodeSize; if (end2 >= pos) { if (end2 == pos || round2 > 0) return retIndex(i + 1, end2); return retIndex(i, curPos); } curPos = end2; } } /** Return a debugging string that describes this fragment. */ toString() { return "<" + this.toStringInner() + ">"; } /** @internal */ toStringInner() { return this.content.join(", "); } /** Create a JSON-serializeable representation of this fragment. */ toJSON() { return this.content.length ? this.content.map((n) => n.toJSON()) : null; } /** Deserialize a fragment from its JSON representation. */ static fromJSON(schema, value) { if (!value) return Fragment.empty; if (!Array.isArray(value)) throw new RangeError("Invalid input for Fragment.fromJSON"); return new Fragment(value.map(schema.nodeFromJSON)); } /** Build a fragment from an array of nodes. Ensures that adjacent text nodes with the same marks are joined together. */ static fromArray(array) { if (!array.length) return Fragment.empty; let joined, size = 0; for (let i = 0; i < array.length; i++) { let node = array[i]; size += node.nodeSize; if (i && node.isText && array[i - 1].sameMarkup(node)) { if (!joined) joined = array.slice(0, i); joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text); } else if (joined) { joined.push(node); } } return new Fragment(joined || array, size); } /** Create a fragment from something that can be interpreted as a set of nodes. For `null`, it returns the empty fragment. For a fragment, the fragment itself. For a node or array of nodes, a fragment containing those nodes. */ static from(nodes) { if (!nodes) return Fragment.empty; if (nodes instanceof Fragment) return nodes; if (Array.isArray(nodes)) return this.fromArray(nodes); if (nodes.attrs) return new Fragment([nodes], nodes.nodeSize); throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : "")); } } Fragment.empty = new Fragment([], 0); const found = { index: 0, offset: 0 }; function retIndex(index, offset2) { found.index = index; found.offset = offset2; return found; } function compareDeep(a, b) { if (a === b) return true; if (!(a && typeof a == "object") || !(b && typeof b == "object")) return false; let array = Array.isArray(a); if (Array.isArray(b) != array) return false; if (array) { if (a.length != b.length) return false; for (let i = 0; i < a.length; i++) if (!compareDeep(a[i], b[i])) return false; } else { for (let p in a) if (!(p in b) || !compareDeep(a[p], b[p])) return false; for (let p in b) if (!(p in a)) return false; } return true; } let Mark$1 = class Mark { /** @internal */ constructor(type, attrs) { this.type = type; this.attrs = attrs; } /** Given a set of marks, create a new set which contains this one as well, in the right position. If this mark is already in the set, the set itself is returned. If any marks that are set to be [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present, those are replaced by this one. */ addToSet(set) { let copy2, placed = false; for (let i = 0; i < set.length; i++) { let other = set[i]; if (this.eq(other)) return set; if (this.type.excludes(other.type)) { if (!copy2) copy2 = set.slice(0, i); } else if (other.type.excludes(this.type)) { return set; } else { if (!placed && other.type.rank > this.type.rank) { if (!copy2) copy2 = set.slice(0, i); copy2.push(this); placed = true; } if (copy2) copy2.push(other); } } if (!copy2) copy2 = set.slice(); if (!placed) copy2.push(this); return copy2; } /** Remove this mark from the given set, returning a new set. If this mark is not in the set, the set itself is returned. */ removeFromSet(set) { for (let i = 0; i < set.length; i++) if (this.eq(set[i])) return set.slice(0, i).concat(set.slice(i + 1)); return set; } /** Test whether this mark is in the given set of marks. */ isInSet(set) { for (let i = 0; i < set.length; i++) if (this.eq(set[i])) return true; return false; } /** Test whether this mark has the same type and attributes as another mark. */ eq(other) { return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs); } /** Convert this mark to a JSON-serializeable representation. */ toJSON() { let obj = { type: this.type.name }; for (let _ in this.attrs) { obj.attrs = this.attrs; break; } return obj; } /** Deserialize a mark from JSON. */ static fromJSON(schema, json) { if (!json) throw new RangeError("Invalid input for Mark.fromJSON"); let type = schema.marks[json.type]; if (!type) throw new RangeError(`There is no mark type ${json.type} in this schema`); let mark = type.create(json.attrs); type.checkAttrs(mark.attrs); return mark; } /** Test whether two sets of marks are identical. */ static sameSet(a, b) { if (a == b) return true; if (a.length != b.length) return false; for (let i = 0; i < a.length; i++) if (!a[i].eq(b[i])) return false; return true; } /** Create a properly sorted mark set from null, a single mark, or an unsorted array of marks. */ static setFrom(marks) { if (!marks || Array.isArray(marks) && marks.length == 0) return Mark.none; if (marks instanceof Mark) return [marks]; let copy2 = marks.slice(); copy2.sort((a, b) => a.type.rank - b.type.rank); return copy2; } }; Mark$1.none = []; class ReplaceError extends Error { } class Slice { /** Create a slice. When specifying a non-zero open depth, you must make sure that there are nodes of at least that depth at the appropriate side of the fragment—i.e. if the fragment is an empty paragraph node, `openStart` and `openEnd` can't be greater than 1. It is not necessary for the content of open nodes to conform to the schema's content constraints, though it should be a valid start/end/middle for such a node, depending on which sides are open. */ constructor(content2, openStart, openEnd) { this.content = content2; this.openStart = openStart; this.openEnd = openEnd; } /** The size this slice would add when inserted into a document. */ get size() { return this.content.size - this.openStart - this.openEnd; } /** @internal */ insertAt(pos, fragment) { let content2 = insertInto(this.content, pos + this.openStart, fragment); return content2 && new Slice(content2, this.openStart, this.openEnd); } /** @internal */ removeBetween(from2, to) { return new Slice(removeRange(this.content, from2 + this.openStart, to + this.openStart), this.openStart, this.openEnd); } /** Tests whether this slice is equal to another slice. */ eq(other) { return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd; } /** @internal */ toString() { return this.content + "(" + this.openStart + "," + this.openEnd + ")"; } /** Convert a slice to a JSON-serializable representation. */ toJSON() { if (!this.content.size) return null; let json = { content: this.content.toJSON() }; if (this.openStart > 0) json.openStart = this.openStart; if (this.openEnd > 0) json.openEnd = this.openEnd; return json; } /** Deserialize a slice from its JSON representation. */ static fromJSON(schema, json) { if (!json) return Slice.empty; let openStart = json.openStart || 0, openEnd = json.openEnd || 0; if (typeof openStart != "number" || typeof openEnd != "number") throw new RangeError("Invalid input for Slice.fromJSON"); return new Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd); } /** Create a slice from a fragment by taking the maximum possible open value on both side of the fragment. */ static maxOpen(fragment, openIsolating = true) { let openStart = 0, openEnd = 0; for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild) openStart++; for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild) openEnd++; return new Slice(fragment, openStart, openEnd); } } Slice.empty = new Slice(Fragment.empty, 0, 0); function removeRange(content2, from2, to) { let { index, offset: offset2 } = content2.findIndex(from2), child = content2.maybeChild(index); let { index: indexTo, offset: offsetTo } = content2.findIndex(to); if (offset2 == from2 || child.isText) { if (offsetTo != to && !content2.child(indexTo).isText) throw new RangeError("Removing non-flat range"); return content2.cut(0, from2).append(content2.cut(to)); } if (index != indexTo) throw new RangeError("Removing non-flat range"); return content2.replaceChild(index, child.copy(removeRange(child.content, from2 - offset2 - 1, to - offset2 - 1))); } function insertInto(content2, dist2, insert2, parent) { let { index, offset: offset2 } = content2.findIndex(dist2), child = content2.maybeChild(index); if (offset2 == dist2 || child.isText) { if (parent && !parent.canReplace(index, index, insert2)) return null; return content2.cut(0, dist2).append(insert2).append(content2.cut(dist2)); } let inner = insertInto(child.content, dist2 - offset2 - 1, insert2); return inner && content2.replaceChild(index, child.copy(inner)); } function replace$1($from, $to, slice2) { if (slice2.openStart > $from.depth) throw new ReplaceError("Inserted content deeper than insertion position"); if ($from.depth - slice2.openStart != $to.depth - slice2.openEnd) throw new ReplaceError("Inconsistent open depths"); return replaceOuter($from, $to, slice2, 0); } function replaceOuter($from, $to, slice2, depth) { let index = $from.index(depth), node = $from.node(depth); if (index == $to.index(depth) && depth < $from.depth - slice2.openStart) { let inner = replaceOuter($from, $to, slice2, depth + 1); return node.copy(node.content.replaceChild(index, inner)); } else if (!slice2.content.size) { return close(node, replaceTwoWay($from, $to, depth)); } else if (!slice2.openStart && !slice2.openEnd && $from.depth == depth && $to.depth == depth) { let parent = $from.parent, content2 = parent.content; return close(parent, content2.cut(0, $from.parentOffset).append(slice2.content).append(content2.cut($to.parentOffset))); } else { let { start: start2, end: end2 } = prepareSliceForReplace(slice2, $from); return close(node, replaceThreeWay($from, start2, end2, $to, depth)); } } function checkJoin(main2, sub) { if (!sub.type.compatibleContent(main2.type)) throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main2.type.name); } function joinable$1($before, $after, depth) { let node = $before.node(depth); checkJoin(node, $after.node(depth)); return node; } function addNode(child, target) { let last = target.length - 1; if (last >= 0 && child.isText && child.sameMarkup(target[last])) target[last] = child.withText(target[last].text + child.text); else target.push(child); } function addRange$1($start, $end, depth, target) { let node = ($end || $start).node(depth); let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount; if ($start) { startIndex = $start.index(depth); if ($start.depth > depth) { startIndex++; } else if ($start.textOffset) { addNode($start.nodeAfter, target); startIndex++; } } for (let i = startIndex; i < endIndex; i++) addNode(node.child(i), target); if ($end && $end.depth == depth && $end.textOffset) addNode($end.nodeBefore, target); } function close(node, content2) { node.type.checkContent(content2); return node.copy(content2); } function replaceThreeWay($from, $start, $end, $to, depth) { let openStart = $from.depth > depth && joinable$1($from, $start, depth + 1); let openEnd = $to.depth > depth && joinable$1($end, $to, depth + 1); let content2 = []; addRange$1(null, $from, depth, content2); if (openStart && openEnd && $start.index(depth) == $end.index(depth)) { checkJoin(openStart, openEnd); addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content2); } else { if (openStart) addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content2); addRange$1($start, $end, depth, content2); if (openEnd) addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content2); } addRange$1($to, null, depth, content2); return new Fragment(content2); } function replaceTwoWay($from, $to, depth) { let content2 = []; addRange$1(null, $from, depth, content2); if ($from.depth > depth) { let type = joinable$1($from, $to, depth + 1); addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content2); } addRange$1($to, null, depth, content2); return new Fragment(content2); } function prepareSliceForReplace(slice2, $along) { let extra = $along.depth - slice2.openStart, parent = $along.node(extra); let node = parent.copy(slice2.content); for (let i = extra - 1; i >= 0; i--) node = $along.node(i).copy(Fragment.from(node)); return { start: node.resolveNoCache(slice2.openStart + extra), end: node.resolveNoCache(node.content.size - slice2.openEnd - extra) }; } class ResolvedPos { /** @internal */ constructor(pos, path, parentOffset) { this.pos = pos; this.path = path; this.parentOffset = parentOffset; this.depth = path.length / 3 - 1; } /** @internal */ resolveDepth(val) { if (val == null) return this.depth; if (val < 0) return this.depth + val; return val; } /** The parent node that the position points into. Note that even if a position points into a text node, that node is not considered the parent—text nodes are ‘flat’ in this model, and have no content. */ get parent() { return this.node(this.depth); } /** The root node in which the position was resolved. */ get doc() { return this.node(0); } /** The ancestor node at the given level. `p.node(p.depth)` is the same as `p.parent`. */ node(depth) { return this.path[this.resolveDepth(depth) * 3]; } /** The index into the ancestor at the given level. If this points at the 3rd node in the 2nd paragraph on the top level, for example, `p.index(0)` is 1 and `p.index(1)` is 2. */ index(depth) { return this.path[this.resolveDepth(depth) * 3 + 1]; } /** The index pointing after this position into the ancestor at the given level. */ indexAfter(depth) { depth = this.resolveDepth(depth); return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1); } /** The (absolute) position at the start of the node at the given level. */ start(depth) { depth = this.resolveDepth(depth); return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1; } /** The (absolute) position at the end of the node at the given level. */ end(depth) { depth = this.resolveDepth(depth); return this.start(depth) + this.node(depth).content.size; } /** The (absolute) position directly before the wrapping node at the given level, or, when `depth` is `this.depth + 1`, the original position. */ before(depth) { depth = this.resolveDepth(depth); if (!depth) throw new RangeError("There is no position before the top-level node"); return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1]; } /** The (absolute) position directly after the wrapping node at the given level, or the original position when `depth` is `this.depth + 1`. */ after(depth) { depth = this.resolveDepth(depth); if (!depth) throw new RangeError("There is no position after the top-level node"); return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize; } /** When this position points into a text node, this returns the distance between the position and the start of the text node. Will be zero for positions that point between nodes. */ get textOffset() { return this.pos - this.path[this.path.length - 1]; } /** Get the node directly after the position, if any. If the position points into a text node, only the part of that node after the position is returned. */ get nodeAfter() { let parent = this.parent, index = this.index(this.depth); if (index == parent.childCount) return null; let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index); return dOff ? parent.child(index).cut(dOff) : child; } /** Get the node directly before the position, if any. If the position points into a text node, only the part of that node before the position is returned. */ get nodeBefore() { let index = this.index(this.depth); let dOff = this.pos - this.path[this.path.length - 1]; if (dOff) return this.parent.child(index).cut(0, dOff); return index == 0 ? null : this.parent.child(index - 1); } /** Get the position at the given index in the parent node at the given depth (which defaults to `this.depth`). */ posAtIndex(index, depth) { depth = this.resolveDepth(depth); let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1; for (let i = 0; i < index; i++) pos += node.child(i).nodeSize; return pos; } /** Get the marks at this position, factoring in the surrounding marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the position is at the start of a non-empty node, the marks of the node after it (if any) are returned. */ marks() { let parent = this.parent, index = this.index(); if (parent.content.size == 0) return Mark$1.none; if (this.textOffset) return parent.child(index).marks; let main2 = parent.maybeChild(index - 1), other = parent.maybeChild(index); if (!main2) { let tmp = main2; main2 = other; other = tmp; } let marks = main2.marks; for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks))) marks = marks[i--].removeFromSet(marks); return marks; } /** Get the marks after the current position, if any, except those that are non-inclusive and not present at position `$end`. This is mostly useful for getting the set of marks to preserve after a deletion. Will return `null` if this position is at the end of its parent node or its parent node isn't a textblock (in which case no marks should be preserved). */ marksAcross($end) { let after = this.parent.maybeChild(this.index()); if (!after || !after.isInline) return null; let marks = after.marks, next = $end.parent.maybeChild($end.index()); for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks))) marks = marks[i--].removeFromSet(marks); return marks; } /** The depth up to which this position and the given (non-resolved) position share the same parent nodes. */ sharedDepth(pos) { for (let depth = this.depth; depth > 0; depth--) if (this.start(depth) <= pos && this.end(depth) >= pos) return depth; return 0; } /** Returns a range based on the place where this position and the given position diverge around block content. If both point into the same textblock, for example, a range around that textblock will be returned. If they point into different blocks, the range around those blocks in their shared ancestor is returned. You can pass in an optional predicate that will be called with a parent node to see if a range into that parent is acceptable. */ blockRange(other = this, pred) { if (other.pos < this.pos) return other.blockRange(this); for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--) if (other.pos <= this.end(d) && (!pred || pred(this.node(d)))) return new NodeRange(this, other, d); return null; } /** Query whether the given position shares the same parent node. */ sameParent(other) { return this.pos - this.parentOffset == other.pos - other.parentOffset; } /** Return the greater of this and the given position. */ max(other) { return other.pos > this.pos ? other : this; } /** Return the smaller of this and the given position. */ min(other) { return other.pos < this.pos ? other : this; } /** @internal */ toString() { let str = ""; for (let i = 1; i <= this.depth; i++) str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1); return str + ":" + this.parentOffset; } /** @internal */ static resolve(doc2, pos) { if (!(pos >= 0 && pos <= doc2.content.size)) throw new RangeError("Position " + pos + " out of range"); let path = []; let start2 = 0, parentOffset = pos; for (let node = doc2; ; ) { let { index, offset: offset2 } = node.content.findIndex(parentOffset); let rem = parentOffset - offset2; path.push(node, index, start2 + offset2); if (!rem) break; node = node.child(index); if (node.isText) break; parentOffset = rem - 1; start2 += offset2 + 1; } return new ResolvedPos(pos, path, parentOffset); } /** @internal */ static resolveCached(doc2, pos) { let cache2 = resolveCache.get(doc2); if (cache2) { for (let i = 0; i < cache2.elts.length; i++) { let elt = cache2.elts[i]; if (elt.pos == pos) return elt; } } else { resolveCache.set(doc2, cache2 = new ResolveCache()); } let result = cache2.elts[cache2.i] = ResolvedPos.resolve(doc2, pos); cache2.i = (cache2.i + 1) % resolveCacheSize; return result; } } class ResolveCache { constructor() { this.elts = []; this.i = 0; } } const resolveCacheSize = 12, resolveCache = /* @__PURE__ */ new WeakMap(); class NodeRange { /** Construct a node range. `$from` and `$to` should point into the same node until at least the given `depth`, since a node range denotes an adjacent set of nodes in a single parent node. */ constructor($from, $to, depth) { this.$from = $from; this.$to = $to; this.depth = depth; } /** The position at the start of the range. */ get start() { return this.$from.before(this.depth + 1); } /** The position at the end of the range. */ get end() { return this.$to.after(this.depth + 1); } /** The parent node that the range points into. */ get parent() { return this.$from.node(this.depth); } /** The start index of the range in the parent node. */ get startIndex() { return this.$from.index(this.depth); } /** The end index of the range in the parent node. */ get endIndex() { return this.$to.indexAfter(this.depth); } } const emptyAttrs = /* @__PURE__ */ Object.create(null); let Node$1 = class Node { /** @internal */ constructor(type, attrs, content2, marks = Mark$1.none) { this.type = type; this.attrs = attrs; this.marks = marks; this.content = content2 || Fragment.empty; } /** The array of this node's child nodes. */ get children() { return this.content.content; } /** The size of this node, as defined by the integer-based [indexing scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the amount of characters. For other leaf nodes, it is one. For non-leaf nodes, it is the size of the content plus two (the start and end token). */ get nodeSize() { return this.isLeaf ? 1 : 2 + this.content.size; } /** The number of children that the node has. */ get childCount() { return this.content.childCount; } /** Get the child node at the given index. Raises an error when the index is out of range. */ child(index) { return this.content.child(index); } /** Get the child node at the given index, if it exists. */ maybeChild(index) { return this.content.maybeChild(index); } /** Call `f` for every child node, passing the node, its offset into this parent node, and its index. */ forEach(f) { this.content.forEach(f); } /** Invoke a callback for all descendant nodes recursively between the given two positions that are relative to start of this node's content. The callback is invoked with the node, its position relative to the original node (method receiver), its parent node, and its child index. When the callback returns false for a given node, that node's children will not be recursed over. The last parameter can be used to specify a starting position to count from. */ nodesBetween(from2, to, f, startPos = 0) { this.content.nodesBetween(from2, to, f, startPos, this); } /** Call the given callback for every descendant node. Doesn't descend into a node when the callback returns `false`. */ descendants(f) { this.nodesBetween(0, this.content.size, f); } /** Concatenates all the text nodes found in this fragment and its children. */ get textContent() { return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, ""); } /** Get all text between positions `from` and `to`. When `blockSeparator` is given, it will be inserted to separate text from different block nodes. If `leafText` is given, it'll be inserted for every non-text leaf node encountered, otherwise [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used. */ textBetween(from2, to, blockSeparator, leafText) { return this.content.textBetween(from2, to, blockSeparator, leafText); } /** Returns this node's first child, or `null` if there are no children. */ get firstChild() { return this.content.firstChild; } /** Returns this node's last child, or `null` if there are no children. */ get lastChild() { return this.content.lastChild; } /** Test whether two nodes represent the same piece of document. */ eq(other) { return this == other || this.sameMarkup(other) && this.content.eq(other.content); } /** Compare the markup (type, attributes, and marks) of this node to those of another. Returns `true` if both have the same markup. */ sameMarkup(other) { return this.hasMarkup(other.type, other.attrs, other.marks); } /** Check whether this node's markup correspond to the given type, attributes, and marks. */ hasMarkup(type, attrs, marks) { return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark$1.sameSet(this.marks, marks || Mark$1.none); } /** Create a new node with the same markup as this node, containing the given content (or empty, if no content is given). */ copy(content2 = null) { if (content2 == this.content) return this; return new Node(this.type, this.attrs, content2, this.marks); } /** Create a copy of this node, with the given set of marks instead of the node's own marks. */ mark(marks) { return marks == this.marks ? this : new Node(this.type, this.attrs, this.content, marks); } /** Create a copy of this node with only the content between the given positions. If `to` is not given, it defaults to the end of the node. */ cut(from2, to = this.content.size) { if (from2 == 0 && to == this.content.size) return this; return this.copy(this.content.cut(from2, to)); } /** Cut out the part of the document between the given positions, and return it as a `Slice` object. */ slice(from2, to = this.content.size, includeParents = false) { if (from2 == to) return Slice.empty; let $from = this.resolve(from2), $to = this.resolve(to); let depth = includeParents ? 0 : $from.sharedDepth(to); let start2 = $from.start(depth), node = $from.node(depth); let content2 = node.content.cut($from.pos - start2, $to.pos - start2); return new Slice(content2, $from.depth - depth, $to.depth - depth); } /** Replace the part of the document between the given positions with the given slice. The slice must 'fit', meaning its open sides must be able to connect to the surrounding content, and its content nodes must be valid children for the node they are placed into. If any of this is violated, an error of type [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown. */ replace(from2, to, slice2) { return replace$1(this.resolve(from2), this.resolve(to), slice2); } /** Find the node directly after the given position. */ nodeAt(pos) { for (let node = this; ; ) { let { index, offset: offset2 } = node.content.findIndex(pos); node = node.maybeChild(index); if (!node) return null; if (offset2 == pos || node.isText) return node; pos -= offset2 + 1; } } /** Find the (direct) child node after the given offset, if any, and return it along with its index and offset relative to this node. */ childAfter(pos) { let { index, offset: offset2 } = this.content.findIndex(pos); return { node: this.content.maybeChild(index), index, offset: offset2 }; } /** Find the (direct) child node before the given offset, if any, and return it along with its index and offset relative to this node. */ childBefore(pos) { if (pos == 0) return { node: null, index: 0, offset: 0 }; let { index, offset: offset2 } = this.content.findIndex(pos); if (offset2 < pos) return { node: this.content.child(index), index, offset: offset2 }; let node = this.content.child(index - 1); return { node, index: index - 1, offset: offset2 - node.nodeSize }; } /** Resolve the given position in the document, returning an [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context. */ resolve(pos) { return ResolvedPos.resolveCached(this, pos); } /** @internal */ resolveNoCache(pos) { return ResolvedPos.resolve(this, pos); } /** Test whether a given mark or mark type occurs in this document between the two given positions. */ rangeHasMark(from2, to, type) { let found2 = false; if (to > from2) this.nodesBetween(from2, to, (node) => { if (type.isInSet(node.marks)) found2 = true; return !found2; }); return found2; } /** True when this is a block (non-inline node) */ get isBlock() { return this.type.isBlock; } /** True when this is a textblock node, a block node with inline content. */ get isTextblock() { return this.type.isTextblock; } /** True when this node allows inline content. */ get inlineContent() { return this.type.inlineContent; } /** True when this is an inline node (a text node or a node that can appear among text). */ get isInline() { return this.type.isInline; } /** True when this is a text node. */ get isText() { return this.type.isText; } /** True when this is a leaf node. */ get isLeaf() { return this.type.isLeaf; } /** True when this is an atom, i.e. when it does not have directly editable content. This is usually the same as `isLeaf`, but can be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom) on a node's spec (typically used when the node is displayed as an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)). */ get isAtom() { return this.type.isAtom; } /** Return a string representation of this node for debugging purposes. */ toString() { if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this); let name2 = this.type.name; if (this.content.size) name2 += "(" + this.content.toStringInner() + ")"; return wrapMarks$1(this.marks, name2); } /** Get the content match in this node at the given index. */ contentMatchAt(index) { let match = this.type.contentMatch.matchFragment(this.content, 0, index); if (!match) throw new Error("Called contentMatchAt on a node with invalid content"); return match; } /** Test whether replacing the range between `from` and `to` (by child index) with the given replacement fragment (which defaults to the empty fragment) would leave the node's content valid. You can optionally pass `start` and `end` indices into the replacement fragment. */ canReplace(from2, to, replacement = Fragment.empty, start2 = 0, end2 = replacement.childCount) { let one = this.contentMatchAt(from2).matchFragment(replacement, start2, end2); let two = one && one.matchFragment(this.content, to); if (!two || !two.validEnd) return false; for (let i = start2; i < end2; i++) if (!this.type.allowsMarks(replacement.child(i).marks)) return false; return true; } /** Test whether replacing the range `from` to `to` (by index) with a node of the given type would leave the node's content valid. */ canReplaceWith(from2, to, type, marks) { if (marks && !this.type.allowsMarks(marks)) return false; let start2 = this.contentMatchAt(from2).matchType(type); let end2 = start2 && start2.matchFragment(this.content, to); return end2 ? end2.validEnd : false; } /** Test whether the given node's content could be appended to this node. If that node is empty, this will only return true if there is at least one node type that can appear in both nodes (to avoid merging completely incompatible nodes). */ canAppend(other) { if (other.content.size) return this.canReplace(this.childCount, this.childCount, other.content); else return this.type.compatib