@underverse-ui/underverse 0.2.77 → 0.2.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3240,7 +3240,7 @@ var Tooltip = ({
3240
3240
  children,
3241
3241
  content,
3242
3242
  placement = "top",
3243
- delay = { open: 700, close: 300 },
3243
+ delay = { open: 200, close: 300 },
3244
3244
  className,
3245
3245
  disabled = false,
3246
3246
  variant = "default"
@@ -13479,14 +13479,14 @@ function useStickyColumns(columns, visibleKeys) {
13479
13479
  // ../../components/ui/DataTable/utils/validation.ts
13480
13480
  function validateColumns(columns) {
13481
13481
  const warnings = [];
13482
- const keys = /* @__PURE__ */ new Set();
13482
+ const keys2 = /* @__PURE__ */ new Set();
13483
13483
  function validate(cols, path = "") {
13484
13484
  for (const col of cols) {
13485
13485
  const fullPath = path ? `${path}.${col.key}` : col.key;
13486
- if (keys.has(col.key)) {
13486
+ if (keys2.has(col.key)) {
13487
13487
  warnings.push(`Duplicate key "${col.key}" at ${fullPath}`);
13488
13488
  }
13489
- keys.add(col.key);
13489
+ keys2.add(col.key);
13490
13490
  const isGroup = col.children && col.children.length > 0;
13491
13491
  if (isGroup) {
13492
13492
  if (col.dataIndex) {
@@ -15573,9 +15573,3152 @@ var SlashCommand = import_core.Extension.create({
15573
15573
  }
15574
15574
  });
15575
15575
 
15576
+ // ../../components/ui/UEditor/clipboard-images.ts
15577
+ var import_core2 = require("@tiptap/core");
15578
+
15579
+ // ../../node_modules/prosemirror-model/dist/index.js
15580
+ function findDiffStart(a, b, pos) {
15581
+ for (let i = 0; ; i++) {
15582
+ if (i == a.childCount || i == b.childCount)
15583
+ return a.childCount == b.childCount ? null : pos;
15584
+ let childA = a.child(i), childB = b.child(i);
15585
+ if (childA == childB) {
15586
+ pos += childA.nodeSize;
15587
+ continue;
15588
+ }
15589
+ if (!childA.sameMarkup(childB))
15590
+ return pos;
15591
+ if (childA.isText && childA.text != childB.text) {
15592
+ for (let j = 0; childA.text[j] == childB.text[j]; j++)
15593
+ pos++;
15594
+ return pos;
15595
+ }
15596
+ if (childA.content.size || childB.content.size) {
15597
+ let inner = findDiffStart(childA.content, childB.content, pos + 1);
15598
+ if (inner != null)
15599
+ return inner;
15600
+ }
15601
+ pos += childA.nodeSize;
15602
+ }
15603
+ }
15604
+ function findDiffEnd(a, b, posA, posB) {
15605
+ for (let iA = a.childCount, iB = b.childCount; ; ) {
15606
+ if (iA == 0 || iB == 0)
15607
+ return iA == iB ? null : { a: posA, b: posB };
15608
+ let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;
15609
+ if (childA == childB) {
15610
+ posA -= size;
15611
+ posB -= size;
15612
+ continue;
15613
+ }
15614
+ if (!childA.sameMarkup(childB))
15615
+ return { a: posA, b: posB };
15616
+ if (childA.isText && childA.text != childB.text) {
15617
+ let same = 0, minSize = Math.min(childA.text.length, childB.text.length);
15618
+ while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {
15619
+ same++;
15620
+ posA--;
15621
+ posB--;
15622
+ }
15623
+ return { a: posA, b: posB };
15624
+ }
15625
+ if (childA.content.size || childB.content.size) {
15626
+ let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);
15627
+ if (inner)
15628
+ return inner;
15629
+ }
15630
+ posA -= size;
15631
+ posB -= size;
15632
+ }
15633
+ }
15634
+ var Fragment25 = class _Fragment {
15635
+ /**
15636
+ @internal
15637
+ */
15638
+ constructor(content, size) {
15639
+ this.content = content;
15640
+ this.size = size || 0;
15641
+ if (size == null)
15642
+ for (let i = 0; i < content.length; i++)
15643
+ this.size += content[i].nodeSize;
15644
+ }
15645
+ /**
15646
+ Invoke a callback for all descendant nodes between the given two
15647
+ positions (relative to start of this fragment). Doesn't descend
15648
+ into a node when the callback returns `false`.
15649
+ */
15650
+ nodesBetween(from, to, f, nodeStart = 0, parent) {
15651
+ for (let i = 0, pos = 0; pos < to; i++) {
15652
+ let child = this.content[i], end = pos + child.nodeSize;
15653
+ if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {
15654
+ let start = pos + 1;
15655
+ child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);
15656
+ }
15657
+ pos = end;
15658
+ }
15659
+ }
15660
+ /**
15661
+ Call the given callback for every descendant node. `pos` will be
15662
+ relative to the start of the fragment. The callback may return
15663
+ `false` to prevent traversal of a given node's children.
15664
+ */
15665
+ descendants(f) {
15666
+ this.nodesBetween(0, this.size, f);
15667
+ }
15668
+ /**
15669
+ Extract the text between `from` and `to`. See the same method on
15670
+ [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
15671
+ */
15672
+ textBetween(from, to, blockSeparator, leafText) {
15673
+ let text = "", first = true;
15674
+ this.nodesBetween(from, to, (node, pos) => {
15675
+ let nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : "";
15676
+ if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) {
15677
+ if (first)
15678
+ first = false;
15679
+ else
15680
+ text += blockSeparator;
15681
+ }
15682
+ text += nodeText;
15683
+ }, 0);
15684
+ return text;
15685
+ }
15686
+ /**
15687
+ Create a new fragment containing the combined content of this
15688
+ fragment and the other.
15689
+ */
15690
+ append(other) {
15691
+ if (!other.size)
15692
+ return this;
15693
+ if (!this.size)
15694
+ return other;
15695
+ let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;
15696
+ if (last.isText && last.sameMarkup(first)) {
15697
+ content[content.length - 1] = last.withText(last.text + first.text);
15698
+ i = 1;
15699
+ }
15700
+ for (; i < other.content.length; i++)
15701
+ content.push(other.content[i]);
15702
+ return new _Fragment(content, this.size + other.size);
15703
+ }
15704
+ /**
15705
+ Cut out the sub-fragment between the two given positions.
15706
+ */
15707
+ cut(from, to = this.size) {
15708
+ if (from == 0 && to == this.size)
15709
+ return this;
15710
+ let result = [], size = 0;
15711
+ if (to > from)
15712
+ for (let i = 0, pos = 0; pos < to; i++) {
15713
+ let child = this.content[i], end = pos + child.nodeSize;
15714
+ if (end > from) {
15715
+ if (pos < from || end > to) {
15716
+ if (child.isText)
15717
+ child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));
15718
+ else
15719
+ child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));
15720
+ }
15721
+ result.push(child);
15722
+ size += child.nodeSize;
15723
+ }
15724
+ pos = end;
15725
+ }
15726
+ return new _Fragment(result, size);
15727
+ }
15728
+ /**
15729
+ @internal
15730
+ */
15731
+ cutByIndex(from, to) {
15732
+ if (from == to)
15733
+ return _Fragment.empty;
15734
+ if (from == 0 && to == this.content.length)
15735
+ return this;
15736
+ return new _Fragment(this.content.slice(from, to));
15737
+ }
15738
+ /**
15739
+ Create a new fragment in which the node at the given index is
15740
+ replaced by the given node.
15741
+ */
15742
+ replaceChild(index, node) {
15743
+ let current = this.content[index];
15744
+ if (current == node)
15745
+ return this;
15746
+ let copy = this.content.slice();
15747
+ let size = this.size + node.nodeSize - current.nodeSize;
15748
+ copy[index] = node;
15749
+ return new _Fragment(copy, size);
15750
+ }
15751
+ /**
15752
+ Create a new fragment by prepending the given node to this
15753
+ fragment.
15754
+ */
15755
+ addToStart(node) {
15756
+ return new _Fragment([node].concat(this.content), this.size + node.nodeSize);
15757
+ }
15758
+ /**
15759
+ Create a new fragment by appending the given node to this
15760
+ fragment.
15761
+ */
15762
+ addToEnd(node) {
15763
+ return new _Fragment(this.content.concat(node), this.size + node.nodeSize);
15764
+ }
15765
+ /**
15766
+ Compare this fragment to another one.
15767
+ */
15768
+ eq(other) {
15769
+ if (this.content.length != other.content.length)
15770
+ return false;
15771
+ for (let i = 0; i < this.content.length; i++)
15772
+ if (!this.content[i].eq(other.content[i]))
15773
+ return false;
15774
+ return true;
15775
+ }
15776
+ /**
15777
+ The first child of the fragment, or `null` if it is empty.
15778
+ */
15779
+ get firstChild() {
15780
+ return this.content.length ? this.content[0] : null;
15781
+ }
15782
+ /**
15783
+ The last child of the fragment, or `null` if it is empty.
15784
+ */
15785
+ get lastChild() {
15786
+ return this.content.length ? this.content[this.content.length - 1] : null;
15787
+ }
15788
+ /**
15789
+ The number of child nodes in this fragment.
15790
+ */
15791
+ get childCount() {
15792
+ return this.content.length;
15793
+ }
15794
+ /**
15795
+ Get the child node at the given index. Raise an error when the
15796
+ index is out of range.
15797
+ */
15798
+ child(index) {
15799
+ let found2 = this.content[index];
15800
+ if (!found2)
15801
+ throw new RangeError("Index " + index + " out of range for " + this);
15802
+ return found2;
15803
+ }
15804
+ /**
15805
+ Get the child node at the given index, if it exists.
15806
+ */
15807
+ maybeChild(index) {
15808
+ return this.content[index] || null;
15809
+ }
15810
+ /**
15811
+ Call `f` for every child node, passing the node, its offset
15812
+ into this parent node, and its index.
15813
+ */
15814
+ forEach(f) {
15815
+ for (let i = 0, p = 0; i < this.content.length; i++) {
15816
+ let child = this.content[i];
15817
+ f(child, p, i);
15818
+ p += child.nodeSize;
15819
+ }
15820
+ }
15821
+ /**
15822
+ Find the first position at which this fragment and another
15823
+ fragment differ, or `null` if they are the same.
15824
+ */
15825
+ findDiffStart(other, pos = 0) {
15826
+ return findDiffStart(this, other, pos);
15827
+ }
15828
+ /**
15829
+ Find the first position, searching from the end, at which this
15830
+ fragment and the given fragment differ, or `null` if they are
15831
+ the same. Since this position will not be the same in both
15832
+ nodes, an object with two separate positions is returned.
15833
+ */
15834
+ findDiffEnd(other, pos = this.size, otherPos = other.size) {
15835
+ return findDiffEnd(this, other, pos, otherPos);
15836
+ }
15837
+ /**
15838
+ Find the index and inner offset corresponding to a given relative
15839
+ position in this fragment. The result object will be reused
15840
+ (overwritten) the next time the function is called. @internal
15841
+ */
15842
+ findIndex(pos) {
15843
+ if (pos == 0)
15844
+ return retIndex(0, pos);
15845
+ if (pos == this.size)
15846
+ return retIndex(this.content.length, pos);
15847
+ if (pos > this.size || pos < 0)
15848
+ throw new RangeError(`Position ${pos} outside of fragment (${this})`);
15849
+ for (let i = 0, curPos = 0; ; i++) {
15850
+ let cur = this.child(i), end = curPos + cur.nodeSize;
15851
+ if (end >= pos) {
15852
+ if (end == pos)
15853
+ return retIndex(i + 1, end);
15854
+ return retIndex(i, curPos);
15855
+ }
15856
+ curPos = end;
15857
+ }
15858
+ }
15859
+ /**
15860
+ Return a debugging string that describes this fragment.
15861
+ */
15862
+ toString() {
15863
+ return "<" + this.toStringInner() + ">";
15864
+ }
15865
+ /**
15866
+ @internal
15867
+ */
15868
+ toStringInner() {
15869
+ return this.content.join(", ");
15870
+ }
15871
+ /**
15872
+ Create a JSON-serializeable representation of this fragment.
15873
+ */
15874
+ toJSON() {
15875
+ return this.content.length ? this.content.map((n) => n.toJSON()) : null;
15876
+ }
15877
+ /**
15878
+ Deserialize a fragment from its JSON representation.
15879
+ */
15880
+ static fromJSON(schema, value) {
15881
+ if (!value)
15882
+ return _Fragment.empty;
15883
+ if (!Array.isArray(value))
15884
+ throw new RangeError("Invalid input for Fragment.fromJSON");
15885
+ return new _Fragment(value.map(schema.nodeFromJSON));
15886
+ }
15887
+ /**
15888
+ Build a fragment from an array of nodes. Ensures that adjacent
15889
+ text nodes with the same marks are joined together.
15890
+ */
15891
+ static fromArray(array) {
15892
+ if (!array.length)
15893
+ return _Fragment.empty;
15894
+ let joined, size = 0;
15895
+ for (let i = 0; i < array.length; i++) {
15896
+ let node = array[i];
15897
+ size += node.nodeSize;
15898
+ if (i && node.isText && array[i - 1].sameMarkup(node)) {
15899
+ if (!joined)
15900
+ joined = array.slice(0, i);
15901
+ joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text);
15902
+ } else if (joined) {
15903
+ joined.push(node);
15904
+ }
15905
+ }
15906
+ return new _Fragment(joined || array, size);
15907
+ }
15908
+ /**
15909
+ Create a fragment from something that can be interpreted as a
15910
+ set of nodes. For `null`, it returns the empty fragment. For a
15911
+ fragment, the fragment itself. For a node or array of nodes, a
15912
+ fragment containing those nodes.
15913
+ */
15914
+ static from(nodes) {
15915
+ if (!nodes)
15916
+ return _Fragment.empty;
15917
+ if (nodes instanceof _Fragment)
15918
+ return nodes;
15919
+ if (Array.isArray(nodes))
15920
+ return this.fromArray(nodes);
15921
+ if (nodes.attrs)
15922
+ return new _Fragment([nodes], nodes.nodeSize);
15923
+ throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
15924
+ }
15925
+ };
15926
+ Fragment25.empty = new Fragment25([], 0);
15927
+ var found = { index: 0, offset: 0 };
15928
+ function retIndex(index, offset) {
15929
+ found.index = index;
15930
+ found.offset = offset;
15931
+ return found;
15932
+ }
15933
+ function compareDeep(a, b) {
15934
+ if (a === b)
15935
+ return true;
15936
+ if (!(a && typeof a == "object") || !(b && typeof b == "object"))
15937
+ return false;
15938
+ let array = Array.isArray(a);
15939
+ if (Array.isArray(b) != array)
15940
+ return false;
15941
+ if (array) {
15942
+ if (a.length != b.length)
15943
+ return false;
15944
+ for (let i = 0; i < a.length; i++)
15945
+ if (!compareDeep(a[i], b[i]))
15946
+ return false;
15947
+ } else {
15948
+ for (let p in a)
15949
+ if (!(p in b) || !compareDeep(a[p], b[p]))
15950
+ return false;
15951
+ for (let p in b)
15952
+ if (!(p in a))
15953
+ return false;
15954
+ }
15955
+ return true;
15956
+ }
15957
+ var Mark = class _Mark {
15958
+ /**
15959
+ @internal
15960
+ */
15961
+ constructor(type, attrs) {
15962
+ this.type = type;
15963
+ this.attrs = attrs;
15964
+ }
15965
+ /**
15966
+ Given a set of marks, create a new set which contains this one as
15967
+ well, in the right position. If this mark is already in the set,
15968
+ the set itself is returned. If any marks that are set to be
15969
+ [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
15970
+ those are replaced by this one.
15971
+ */
15972
+ addToSet(set) {
15973
+ let copy, placed = false;
15974
+ for (let i = 0; i < set.length; i++) {
15975
+ let other = set[i];
15976
+ if (this.eq(other))
15977
+ return set;
15978
+ if (this.type.excludes(other.type)) {
15979
+ if (!copy)
15980
+ copy = set.slice(0, i);
15981
+ } else if (other.type.excludes(this.type)) {
15982
+ return set;
15983
+ } else {
15984
+ if (!placed && other.type.rank > this.type.rank) {
15985
+ if (!copy)
15986
+ copy = set.slice(0, i);
15987
+ copy.push(this);
15988
+ placed = true;
15989
+ }
15990
+ if (copy)
15991
+ copy.push(other);
15992
+ }
15993
+ }
15994
+ if (!copy)
15995
+ copy = set.slice();
15996
+ if (!placed)
15997
+ copy.push(this);
15998
+ return copy;
15999
+ }
16000
+ /**
16001
+ Remove this mark from the given set, returning a new set. If this
16002
+ mark is not in the set, the set itself is returned.
16003
+ */
16004
+ removeFromSet(set) {
16005
+ for (let i = 0; i < set.length; i++)
16006
+ if (this.eq(set[i]))
16007
+ return set.slice(0, i).concat(set.slice(i + 1));
16008
+ return set;
16009
+ }
16010
+ /**
16011
+ Test whether this mark is in the given set of marks.
16012
+ */
16013
+ isInSet(set) {
16014
+ for (let i = 0; i < set.length; i++)
16015
+ if (this.eq(set[i]))
16016
+ return true;
16017
+ return false;
16018
+ }
16019
+ /**
16020
+ Test whether this mark has the same type and attributes as
16021
+ another mark.
16022
+ */
16023
+ eq(other) {
16024
+ return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs);
16025
+ }
16026
+ /**
16027
+ Convert this mark to a JSON-serializeable representation.
16028
+ */
16029
+ toJSON() {
16030
+ let obj = { type: this.type.name };
16031
+ for (let _ in this.attrs) {
16032
+ obj.attrs = this.attrs;
16033
+ break;
16034
+ }
16035
+ return obj;
16036
+ }
16037
+ /**
16038
+ Deserialize a mark from JSON.
16039
+ */
16040
+ static fromJSON(schema, json) {
16041
+ if (!json)
16042
+ throw new RangeError("Invalid input for Mark.fromJSON");
16043
+ let type = schema.marks[json.type];
16044
+ if (!type)
16045
+ throw new RangeError(`There is no mark type ${json.type} in this schema`);
16046
+ let mark = type.create(json.attrs);
16047
+ type.checkAttrs(mark.attrs);
16048
+ return mark;
16049
+ }
16050
+ /**
16051
+ Test whether two sets of marks are identical.
16052
+ */
16053
+ static sameSet(a, b) {
16054
+ if (a == b)
16055
+ return true;
16056
+ if (a.length != b.length)
16057
+ return false;
16058
+ for (let i = 0; i < a.length; i++)
16059
+ if (!a[i].eq(b[i]))
16060
+ return false;
16061
+ return true;
16062
+ }
16063
+ /**
16064
+ Create a properly sorted mark set from null, a single mark, or an
16065
+ unsorted array of marks.
16066
+ */
16067
+ static setFrom(marks) {
16068
+ if (!marks || Array.isArray(marks) && marks.length == 0)
16069
+ return _Mark.none;
16070
+ if (marks instanceof _Mark)
16071
+ return [marks];
16072
+ let copy = marks.slice();
16073
+ copy.sort((a, b) => a.type.rank - b.type.rank);
16074
+ return copy;
16075
+ }
16076
+ };
16077
+ Mark.none = [];
16078
+ var ReplaceError = class extends Error {
16079
+ };
16080
+ var Slice = class _Slice {
16081
+ /**
16082
+ Create a slice. When specifying a non-zero open depth, you must
16083
+ make sure that there are nodes of at least that depth at the
16084
+ appropriate side of the fragment—i.e. if the fragment is an
16085
+ empty paragraph node, `openStart` and `openEnd` can't be greater
16086
+ than 1.
16087
+
16088
+ It is not necessary for the content of open nodes to conform to
16089
+ the schema's content constraints, though it should be a valid
16090
+ start/end/middle for such a node, depending on which sides are
16091
+ open.
16092
+ */
16093
+ constructor(content, openStart, openEnd) {
16094
+ this.content = content;
16095
+ this.openStart = openStart;
16096
+ this.openEnd = openEnd;
16097
+ }
16098
+ /**
16099
+ The size this slice would add when inserted into a document.
16100
+ */
16101
+ get size() {
16102
+ return this.content.size - this.openStart - this.openEnd;
16103
+ }
16104
+ /**
16105
+ @internal
16106
+ */
16107
+ insertAt(pos, fragment) {
16108
+ let content = insertInto(this.content, pos + this.openStart, fragment);
16109
+ return content && new _Slice(content, this.openStart, this.openEnd);
16110
+ }
16111
+ /**
16112
+ @internal
16113
+ */
16114
+ removeBetween(from, to) {
16115
+ return new _Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);
16116
+ }
16117
+ /**
16118
+ Tests whether this slice is equal to another slice.
16119
+ */
16120
+ eq(other) {
16121
+ return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;
16122
+ }
16123
+ /**
16124
+ @internal
16125
+ */
16126
+ toString() {
16127
+ return this.content + "(" + this.openStart + "," + this.openEnd + ")";
16128
+ }
16129
+ /**
16130
+ Convert a slice to a JSON-serializable representation.
16131
+ */
16132
+ toJSON() {
16133
+ if (!this.content.size)
16134
+ return null;
16135
+ let json = { content: this.content.toJSON() };
16136
+ if (this.openStart > 0)
16137
+ json.openStart = this.openStart;
16138
+ if (this.openEnd > 0)
16139
+ json.openEnd = this.openEnd;
16140
+ return json;
16141
+ }
16142
+ /**
16143
+ Deserialize a slice from its JSON representation.
16144
+ */
16145
+ static fromJSON(schema, json) {
16146
+ if (!json)
16147
+ return _Slice.empty;
16148
+ let openStart = json.openStart || 0, openEnd = json.openEnd || 0;
16149
+ if (typeof openStart != "number" || typeof openEnd != "number")
16150
+ throw new RangeError("Invalid input for Slice.fromJSON");
16151
+ return new _Slice(Fragment25.fromJSON(schema, json.content), openStart, openEnd);
16152
+ }
16153
+ /**
16154
+ Create a slice from a fragment by taking the maximum possible
16155
+ open value on both side of the fragment.
16156
+ */
16157
+ static maxOpen(fragment, openIsolating = true) {
16158
+ let openStart = 0, openEnd = 0;
16159
+ for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild)
16160
+ openStart++;
16161
+ for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild)
16162
+ openEnd++;
16163
+ return new _Slice(fragment, openStart, openEnd);
16164
+ }
16165
+ };
16166
+ Slice.empty = new Slice(Fragment25.empty, 0, 0);
16167
+ function removeRange(content, from, to) {
16168
+ let { index, offset } = content.findIndex(from), child = content.maybeChild(index);
16169
+ let { index: indexTo, offset: offsetTo } = content.findIndex(to);
16170
+ if (offset == from || child.isText) {
16171
+ if (offsetTo != to && !content.child(indexTo).isText)
16172
+ throw new RangeError("Removing non-flat range");
16173
+ return content.cut(0, from).append(content.cut(to));
16174
+ }
16175
+ if (index != indexTo)
16176
+ throw new RangeError("Removing non-flat range");
16177
+ return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));
16178
+ }
16179
+ function insertInto(content, dist, insert, parent) {
16180
+ let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);
16181
+ if (offset == dist || child.isText) {
16182
+ if (parent && !parent.canReplace(index, index, insert))
16183
+ return null;
16184
+ return content.cut(0, dist).append(insert).append(content.cut(dist));
16185
+ }
16186
+ let inner = insertInto(child.content, dist - offset - 1, insert, child);
16187
+ return inner && content.replaceChild(index, child.copy(inner));
16188
+ }
16189
+ function replace($from, $to, slice) {
16190
+ if (slice.openStart > $from.depth)
16191
+ throw new ReplaceError("Inserted content deeper than insertion position");
16192
+ if ($from.depth - slice.openStart != $to.depth - slice.openEnd)
16193
+ throw new ReplaceError("Inconsistent open depths");
16194
+ return replaceOuter($from, $to, slice, 0);
16195
+ }
16196
+ function replaceOuter($from, $to, slice, depth) {
16197
+ let index = $from.index(depth), node = $from.node(depth);
16198
+ if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {
16199
+ let inner = replaceOuter($from, $to, slice, depth + 1);
16200
+ return node.copy(node.content.replaceChild(index, inner));
16201
+ } else if (!slice.content.size) {
16202
+ return close(node, replaceTwoWay($from, $to, depth));
16203
+ } else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) {
16204
+ let parent = $from.parent, content = parent.content;
16205
+ return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));
16206
+ } else {
16207
+ let { start, end } = prepareSliceForReplace(slice, $from);
16208
+ return close(node, replaceThreeWay($from, start, end, $to, depth));
16209
+ }
16210
+ }
16211
+ function checkJoin(main, sub) {
16212
+ if (!sub.type.compatibleContent(main.type))
16213
+ throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name);
16214
+ }
16215
+ function joinable($before, $after, depth) {
16216
+ let node = $before.node(depth);
16217
+ checkJoin(node, $after.node(depth));
16218
+ return node;
16219
+ }
16220
+ function addNode(child, target) {
16221
+ let last = target.length - 1;
16222
+ if (last >= 0 && child.isText && child.sameMarkup(target[last]))
16223
+ target[last] = child.withText(target[last].text + child.text);
16224
+ else
16225
+ target.push(child);
16226
+ }
16227
+ function addRange($start, $end, depth, target) {
16228
+ let node = ($end || $start).node(depth);
16229
+ let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;
16230
+ if ($start) {
16231
+ startIndex = $start.index(depth);
16232
+ if ($start.depth > depth) {
16233
+ startIndex++;
16234
+ } else if ($start.textOffset) {
16235
+ addNode($start.nodeAfter, target);
16236
+ startIndex++;
16237
+ }
16238
+ }
16239
+ for (let i = startIndex; i < endIndex; i++)
16240
+ addNode(node.child(i), target);
16241
+ if ($end && $end.depth == depth && $end.textOffset)
16242
+ addNode($end.nodeBefore, target);
16243
+ }
16244
+ function close(node, content) {
16245
+ node.type.checkContent(content);
16246
+ return node.copy(content);
16247
+ }
16248
+ function replaceThreeWay($from, $start, $end, $to, depth) {
16249
+ let openStart = $from.depth > depth && joinable($from, $start, depth + 1);
16250
+ let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);
16251
+ let content = [];
16252
+ addRange(null, $from, depth, content);
16253
+ if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {
16254
+ checkJoin(openStart, openEnd);
16255
+ addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);
16256
+ } else {
16257
+ if (openStart)
16258
+ addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);
16259
+ addRange($start, $end, depth, content);
16260
+ if (openEnd)
16261
+ addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);
16262
+ }
16263
+ addRange($to, null, depth, content);
16264
+ return new Fragment25(content);
16265
+ }
16266
+ function replaceTwoWay($from, $to, depth) {
16267
+ let content = [];
16268
+ addRange(null, $from, depth, content);
16269
+ if ($from.depth > depth) {
16270
+ let type = joinable($from, $to, depth + 1);
16271
+ addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);
16272
+ }
16273
+ addRange($to, null, depth, content);
16274
+ return new Fragment25(content);
16275
+ }
16276
+ function prepareSliceForReplace(slice, $along) {
16277
+ let extra = $along.depth - slice.openStart, parent = $along.node(extra);
16278
+ let node = parent.copy(slice.content);
16279
+ for (let i = extra - 1; i >= 0; i--)
16280
+ node = $along.node(i).copy(Fragment25.from(node));
16281
+ return {
16282
+ start: node.resolveNoCache(slice.openStart + extra),
16283
+ end: node.resolveNoCache(node.content.size - slice.openEnd - extra)
16284
+ };
16285
+ }
16286
+ var ResolvedPos = class _ResolvedPos {
16287
+ /**
16288
+ @internal
16289
+ */
16290
+ constructor(pos, path, parentOffset) {
16291
+ this.pos = pos;
16292
+ this.path = path;
16293
+ this.parentOffset = parentOffset;
16294
+ this.depth = path.length / 3 - 1;
16295
+ }
16296
+ /**
16297
+ @internal
16298
+ */
16299
+ resolveDepth(val) {
16300
+ if (val == null)
16301
+ return this.depth;
16302
+ if (val < 0)
16303
+ return this.depth + val;
16304
+ return val;
16305
+ }
16306
+ /**
16307
+ The parent node that the position points into. Note that even if
16308
+ a position points into a text node, that node is not considered
16309
+ the parent—text nodes are ‘flat’ in this model, and have no content.
16310
+ */
16311
+ get parent() {
16312
+ return this.node(this.depth);
16313
+ }
16314
+ /**
16315
+ The root node in which the position was resolved.
16316
+ */
16317
+ get doc() {
16318
+ return this.node(0);
16319
+ }
16320
+ /**
16321
+ The ancestor node at the given level. `p.node(p.depth)` is the
16322
+ same as `p.parent`.
16323
+ */
16324
+ node(depth) {
16325
+ return this.path[this.resolveDepth(depth) * 3];
16326
+ }
16327
+ /**
16328
+ The index into the ancestor at the given level. If this points
16329
+ at the 3rd node in the 2nd paragraph on the top level, for
16330
+ example, `p.index(0)` is 1 and `p.index(1)` is 2.
16331
+ */
16332
+ index(depth) {
16333
+ return this.path[this.resolveDepth(depth) * 3 + 1];
16334
+ }
16335
+ /**
16336
+ The index pointing after this position into the ancestor at the
16337
+ given level.
16338
+ */
16339
+ indexAfter(depth) {
16340
+ depth = this.resolveDepth(depth);
16341
+ return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);
16342
+ }
16343
+ /**
16344
+ The (absolute) position at the start of the node at the given
16345
+ level.
16346
+ */
16347
+ start(depth) {
16348
+ depth = this.resolveDepth(depth);
16349
+ return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
16350
+ }
16351
+ /**
16352
+ The (absolute) position at the end of the node at the given
16353
+ level.
16354
+ */
16355
+ end(depth) {
16356
+ depth = this.resolveDepth(depth);
16357
+ return this.start(depth) + this.node(depth).content.size;
16358
+ }
16359
+ /**
16360
+ The (absolute) position directly before the wrapping node at the
16361
+ given level, or, when `depth` is `this.depth + 1`, the original
16362
+ position.
16363
+ */
16364
+ before(depth) {
16365
+ depth = this.resolveDepth(depth);
16366
+ if (!depth)
16367
+ throw new RangeError("There is no position before the top-level node");
16368
+ return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];
16369
+ }
16370
+ /**
16371
+ The (absolute) position directly after the wrapping node at the
16372
+ given level, or the original position when `depth` is `this.depth + 1`.
16373
+ */
16374
+ after(depth) {
16375
+ depth = this.resolveDepth(depth);
16376
+ if (!depth)
16377
+ throw new RangeError("There is no position after the top-level node");
16378
+ return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;
16379
+ }
16380
+ /**
16381
+ When this position points into a text node, this returns the
16382
+ distance between the position and the start of the text node.
16383
+ Will be zero for positions that point between nodes.
16384
+ */
16385
+ get textOffset() {
16386
+ return this.pos - this.path[this.path.length - 1];
16387
+ }
16388
+ /**
16389
+ Get the node directly after the position, if any. If the position
16390
+ points into a text node, only the part of that node after the
16391
+ position is returned.
16392
+ */
16393
+ get nodeAfter() {
16394
+ let parent = this.parent, index = this.index(this.depth);
16395
+ if (index == parent.childCount)
16396
+ return null;
16397
+ let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);
16398
+ return dOff ? parent.child(index).cut(dOff) : child;
16399
+ }
16400
+ /**
16401
+ Get the node directly before the position, if any. If the
16402
+ position points into a text node, only the part of that node
16403
+ before the position is returned.
16404
+ */
16405
+ get nodeBefore() {
16406
+ let index = this.index(this.depth);
16407
+ let dOff = this.pos - this.path[this.path.length - 1];
16408
+ if (dOff)
16409
+ return this.parent.child(index).cut(0, dOff);
16410
+ return index == 0 ? null : this.parent.child(index - 1);
16411
+ }
16412
+ /**
16413
+ Get the position at the given index in the parent node at the
16414
+ given depth (which defaults to `this.depth`).
16415
+ */
16416
+ posAtIndex(index, depth) {
16417
+ depth = this.resolveDepth(depth);
16418
+ let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;
16419
+ for (let i = 0; i < index; i++)
16420
+ pos += node.child(i).nodeSize;
16421
+ return pos;
16422
+ }
16423
+ /**
16424
+ Get the marks at this position, factoring in the surrounding
16425
+ marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the
16426
+ position is at the start of a non-empty node, the marks of the
16427
+ node after it (if any) are returned.
16428
+ */
16429
+ marks() {
16430
+ let parent = this.parent, index = this.index();
16431
+ if (parent.content.size == 0)
16432
+ return Mark.none;
16433
+ if (this.textOffset)
16434
+ return parent.child(index).marks;
16435
+ let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);
16436
+ if (!main) {
16437
+ let tmp = main;
16438
+ main = other;
16439
+ other = tmp;
16440
+ }
16441
+ let marks = main.marks;
16442
+ for (var i = 0; i < marks.length; i++)
16443
+ if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks)))
16444
+ marks = marks[i--].removeFromSet(marks);
16445
+ return marks;
16446
+ }
16447
+ /**
16448
+ Get the marks after the current position, if any, except those
16449
+ that are non-inclusive and not present at position `$end`. This
16450
+ is mostly useful for getting the set of marks to preserve after a
16451
+ deletion. Will return `null` if this position is at the end of
16452
+ its parent node or its parent node isn't a textblock (in which
16453
+ case no marks should be preserved).
16454
+ */
16455
+ marksAcross($end) {
16456
+ let after = this.parent.maybeChild(this.index());
16457
+ if (!after || !after.isInline)
16458
+ return null;
16459
+ let marks = after.marks, next = $end.parent.maybeChild($end.index());
16460
+ for (var i = 0; i < marks.length; i++)
16461
+ if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks)))
16462
+ marks = marks[i--].removeFromSet(marks);
16463
+ return marks;
16464
+ }
16465
+ /**
16466
+ The depth up to which this position and the given (non-resolved)
16467
+ position share the same parent nodes.
16468
+ */
16469
+ sharedDepth(pos) {
16470
+ for (let depth = this.depth; depth > 0; depth--)
16471
+ if (this.start(depth) <= pos && this.end(depth) >= pos)
16472
+ return depth;
16473
+ return 0;
16474
+ }
16475
+ /**
16476
+ Returns a range based on the place where this position and the
16477
+ given position diverge around block content. If both point into
16478
+ the same textblock, for example, a range around that textblock
16479
+ will be returned. If they point into different blocks, the range
16480
+ around those blocks in their shared ancestor is returned. You can
16481
+ pass in an optional predicate that will be called with a parent
16482
+ node to see if a range into that parent is acceptable.
16483
+ */
16484
+ blockRange(other = this, pred) {
16485
+ if (other.pos < this.pos)
16486
+ return other.blockRange(this);
16487
+ for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--)
16488
+ if (other.pos <= this.end(d) && (!pred || pred(this.node(d))))
16489
+ return new NodeRange(this, other, d);
16490
+ return null;
16491
+ }
16492
+ /**
16493
+ Query whether the given position shares the same parent node.
16494
+ */
16495
+ sameParent(other) {
16496
+ return this.pos - this.parentOffset == other.pos - other.parentOffset;
16497
+ }
16498
+ /**
16499
+ Return the greater of this and the given position.
16500
+ */
16501
+ max(other) {
16502
+ return other.pos > this.pos ? other : this;
16503
+ }
16504
+ /**
16505
+ Return the smaller of this and the given position.
16506
+ */
16507
+ min(other) {
16508
+ return other.pos < this.pos ? other : this;
16509
+ }
16510
+ /**
16511
+ @internal
16512
+ */
16513
+ toString() {
16514
+ let str = "";
16515
+ for (let i = 1; i <= this.depth; i++)
16516
+ str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1);
16517
+ return str + ":" + this.parentOffset;
16518
+ }
16519
+ /**
16520
+ @internal
16521
+ */
16522
+ static resolve(doc, pos) {
16523
+ if (!(pos >= 0 && pos <= doc.content.size))
16524
+ throw new RangeError("Position " + pos + " out of range");
16525
+ let path = [];
16526
+ let start = 0, parentOffset = pos;
16527
+ for (let node = doc; ; ) {
16528
+ let { index, offset } = node.content.findIndex(parentOffset);
16529
+ let rem = parentOffset - offset;
16530
+ path.push(node, index, start + offset);
16531
+ if (!rem)
16532
+ break;
16533
+ node = node.child(index);
16534
+ if (node.isText)
16535
+ break;
16536
+ parentOffset = rem - 1;
16537
+ start += offset + 1;
16538
+ }
16539
+ return new _ResolvedPos(pos, path, parentOffset);
16540
+ }
16541
+ /**
16542
+ @internal
16543
+ */
16544
+ static resolveCached(doc, pos) {
16545
+ let cache = resolveCache.get(doc);
16546
+ if (cache) {
16547
+ for (let i = 0; i < cache.elts.length; i++) {
16548
+ let elt = cache.elts[i];
16549
+ if (elt.pos == pos)
16550
+ return elt;
16551
+ }
16552
+ } else {
16553
+ resolveCache.set(doc, cache = new ResolveCache());
16554
+ }
16555
+ let result = cache.elts[cache.i] = _ResolvedPos.resolve(doc, pos);
16556
+ cache.i = (cache.i + 1) % resolveCacheSize;
16557
+ return result;
16558
+ }
16559
+ };
16560
+ var ResolveCache = class {
16561
+ constructor() {
16562
+ this.elts = [];
16563
+ this.i = 0;
16564
+ }
16565
+ };
16566
+ var resolveCacheSize = 12;
16567
+ var resolveCache = /* @__PURE__ */ new WeakMap();
16568
+ var NodeRange = class {
16569
+ /**
16570
+ Construct a node range. `$from` and `$to` should point into the
16571
+ same node until at least the given `depth`, since a node range
16572
+ denotes an adjacent set of nodes in a single parent node.
16573
+ */
16574
+ constructor($from, $to, depth) {
16575
+ this.$from = $from;
16576
+ this.$to = $to;
16577
+ this.depth = depth;
16578
+ }
16579
+ /**
16580
+ The position at the start of the range.
16581
+ */
16582
+ get start() {
16583
+ return this.$from.before(this.depth + 1);
16584
+ }
16585
+ /**
16586
+ The position at the end of the range.
16587
+ */
16588
+ get end() {
16589
+ return this.$to.after(this.depth + 1);
16590
+ }
16591
+ /**
16592
+ The parent node that the range points into.
16593
+ */
16594
+ get parent() {
16595
+ return this.$from.node(this.depth);
16596
+ }
16597
+ /**
16598
+ The start index of the range in the parent node.
16599
+ */
16600
+ get startIndex() {
16601
+ return this.$from.index(this.depth);
16602
+ }
16603
+ /**
16604
+ The end index of the range in the parent node.
16605
+ */
16606
+ get endIndex() {
16607
+ return this.$to.indexAfter(this.depth);
16608
+ }
16609
+ };
16610
+ var emptyAttrs = /* @__PURE__ */ Object.create(null);
16611
+ var Node = class _Node {
16612
+ /**
16613
+ @internal
16614
+ */
16615
+ constructor(type, attrs, content, marks = Mark.none) {
16616
+ this.type = type;
16617
+ this.attrs = attrs;
16618
+ this.marks = marks;
16619
+ this.content = content || Fragment25.empty;
16620
+ }
16621
+ /**
16622
+ The array of this node's child nodes.
16623
+ */
16624
+ get children() {
16625
+ return this.content.content;
16626
+ }
16627
+ /**
16628
+ The size of this node, as defined by the integer-based [indexing
16629
+ scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
16630
+ amount of characters. For other leaf nodes, it is one. For
16631
+ non-leaf nodes, it is the size of the content plus two (the
16632
+ start and end token).
16633
+ */
16634
+ get nodeSize() {
16635
+ return this.isLeaf ? 1 : 2 + this.content.size;
16636
+ }
16637
+ /**
16638
+ The number of children that the node has.
16639
+ */
16640
+ get childCount() {
16641
+ return this.content.childCount;
16642
+ }
16643
+ /**
16644
+ Get the child node at the given index. Raises an error when the
16645
+ index is out of range.
16646
+ */
16647
+ child(index) {
16648
+ return this.content.child(index);
16649
+ }
16650
+ /**
16651
+ Get the child node at the given index, if it exists.
16652
+ */
16653
+ maybeChild(index) {
16654
+ return this.content.maybeChild(index);
16655
+ }
16656
+ /**
16657
+ Call `f` for every child node, passing the node, its offset
16658
+ into this parent node, and its index.
16659
+ */
16660
+ forEach(f) {
16661
+ this.content.forEach(f);
16662
+ }
16663
+ /**
16664
+ Invoke a callback for all descendant nodes recursively between
16665
+ the given two positions that are relative to start of this
16666
+ node's content. The callback is invoked with the node, its
16667
+ position relative to the original node (method receiver),
16668
+ its parent node, and its child index. When the callback returns
16669
+ false for a given node, that node's children will not be
16670
+ recursed over. The last parameter can be used to specify a
16671
+ starting position to count from.
16672
+ */
16673
+ nodesBetween(from, to, f, startPos = 0) {
16674
+ this.content.nodesBetween(from, to, f, startPos, this);
16675
+ }
16676
+ /**
16677
+ Call the given callback for every descendant node. Doesn't
16678
+ descend into a node when the callback returns `false`.
16679
+ */
16680
+ descendants(f) {
16681
+ this.nodesBetween(0, this.content.size, f);
16682
+ }
16683
+ /**
16684
+ Concatenates all the text nodes found in this fragment and its
16685
+ children.
16686
+ */
16687
+ get textContent() {
16688
+ return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
16689
+ }
16690
+ /**
16691
+ Get all text between positions `from` and `to`. When
16692
+ `blockSeparator` is given, it will be inserted to separate text
16693
+ from different block nodes. If `leafText` is given, it'll be
16694
+ inserted for every non-text leaf node encountered, otherwise
16695
+ [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.
16696
+ */
16697
+ textBetween(from, to, blockSeparator, leafText) {
16698
+ return this.content.textBetween(from, to, blockSeparator, leafText);
16699
+ }
16700
+ /**
16701
+ Returns this node's first child, or `null` if there are no
16702
+ children.
16703
+ */
16704
+ get firstChild() {
16705
+ return this.content.firstChild;
16706
+ }
16707
+ /**
16708
+ Returns this node's last child, or `null` if there are no
16709
+ children.
16710
+ */
16711
+ get lastChild() {
16712
+ return this.content.lastChild;
16713
+ }
16714
+ /**
16715
+ Test whether two nodes represent the same piece of document.
16716
+ */
16717
+ eq(other) {
16718
+ return this == other || this.sameMarkup(other) && this.content.eq(other.content);
16719
+ }
16720
+ /**
16721
+ Compare the markup (type, attributes, and marks) of this node to
16722
+ those of another. Returns `true` if both have the same markup.
16723
+ */
16724
+ sameMarkup(other) {
16725
+ return this.hasMarkup(other.type, other.attrs, other.marks);
16726
+ }
16727
+ /**
16728
+ Check whether this node's markup correspond to the given type,
16729
+ attributes, and marks.
16730
+ */
16731
+ hasMarkup(type, attrs, marks) {
16732
+ return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark.sameSet(this.marks, marks || Mark.none);
16733
+ }
16734
+ /**
16735
+ Create a new node with the same markup as this node, containing
16736
+ the given content (or empty, if no content is given).
16737
+ */
16738
+ copy(content = null) {
16739
+ if (content == this.content)
16740
+ return this;
16741
+ return new _Node(this.type, this.attrs, content, this.marks);
16742
+ }
16743
+ /**
16744
+ Create a copy of this node, with the given set of marks instead
16745
+ of the node's own marks.
16746
+ */
16747
+ mark(marks) {
16748
+ return marks == this.marks ? this : new _Node(this.type, this.attrs, this.content, marks);
16749
+ }
16750
+ /**
16751
+ Create a copy of this node with only the content between the
16752
+ given positions. If `to` is not given, it defaults to the end of
16753
+ the node.
16754
+ */
16755
+ cut(from, to = this.content.size) {
16756
+ if (from == 0 && to == this.content.size)
16757
+ return this;
16758
+ return this.copy(this.content.cut(from, to));
16759
+ }
16760
+ /**
16761
+ Cut out the part of the document between the given positions, and
16762
+ return it as a `Slice` object.
16763
+ */
16764
+ slice(from, to = this.content.size, includeParents = false) {
16765
+ if (from == to)
16766
+ return Slice.empty;
16767
+ let $from = this.resolve(from), $to = this.resolve(to);
16768
+ let depth = includeParents ? 0 : $from.sharedDepth(to);
16769
+ let start = $from.start(depth), node = $from.node(depth);
16770
+ let content = node.content.cut($from.pos - start, $to.pos - start);
16771
+ return new Slice(content, $from.depth - depth, $to.depth - depth);
16772
+ }
16773
+ /**
16774
+ Replace the part of the document between the given positions with
16775
+ the given slice. The slice must 'fit', meaning its open sides
16776
+ must be able to connect to the surrounding content, and its
16777
+ content nodes must be valid children for the node they are placed
16778
+ into. If any of this is violated, an error of type
16779
+ [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
16780
+ */
16781
+ replace(from, to, slice) {
16782
+ return replace(this.resolve(from), this.resolve(to), slice);
16783
+ }
16784
+ /**
16785
+ Find the node directly after the given position.
16786
+ */
16787
+ nodeAt(pos) {
16788
+ for (let node = this; ; ) {
16789
+ let { index, offset } = node.content.findIndex(pos);
16790
+ node = node.maybeChild(index);
16791
+ if (!node)
16792
+ return null;
16793
+ if (offset == pos || node.isText)
16794
+ return node;
16795
+ pos -= offset + 1;
16796
+ }
16797
+ }
16798
+ /**
16799
+ Find the (direct) child node after the given offset, if any,
16800
+ and return it along with its index and offset relative to this
16801
+ node.
16802
+ */
16803
+ childAfter(pos) {
16804
+ let { index, offset } = this.content.findIndex(pos);
16805
+ return { node: this.content.maybeChild(index), index, offset };
16806
+ }
16807
+ /**
16808
+ Find the (direct) child node before the given offset, if any,
16809
+ and return it along with its index and offset relative to this
16810
+ node.
16811
+ */
16812
+ childBefore(pos) {
16813
+ if (pos == 0)
16814
+ return { node: null, index: 0, offset: 0 };
16815
+ let { index, offset } = this.content.findIndex(pos);
16816
+ if (offset < pos)
16817
+ return { node: this.content.child(index), index, offset };
16818
+ let node = this.content.child(index - 1);
16819
+ return { node, index: index - 1, offset: offset - node.nodeSize };
16820
+ }
16821
+ /**
16822
+ Resolve the given position in the document, returning an
16823
+ [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
16824
+ */
16825
+ resolve(pos) {
16826
+ return ResolvedPos.resolveCached(this, pos);
16827
+ }
16828
+ /**
16829
+ @internal
16830
+ */
16831
+ resolveNoCache(pos) {
16832
+ return ResolvedPos.resolve(this, pos);
16833
+ }
16834
+ /**
16835
+ Test whether a given mark or mark type occurs in this document
16836
+ between the two given positions.
16837
+ */
16838
+ rangeHasMark(from, to, type) {
16839
+ let found2 = false;
16840
+ if (to > from)
16841
+ this.nodesBetween(from, to, (node) => {
16842
+ if (type.isInSet(node.marks))
16843
+ found2 = true;
16844
+ return !found2;
16845
+ });
16846
+ return found2;
16847
+ }
16848
+ /**
16849
+ True when this is a block (non-inline node)
16850
+ */
16851
+ get isBlock() {
16852
+ return this.type.isBlock;
16853
+ }
16854
+ /**
16855
+ True when this is a textblock node, a block node with inline
16856
+ content.
16857
+ */
16858
+ get isTextblock() {
16859
+ return this.type.isTextblock;
16860
+ }
16861
+ /**
16862
+ True when this node allows inline content.
16863
+ */
16864
+ get inlineContent() {
16865
+ return this.type.inlineContent;
16866
+ }
16867
+ /**
16868
+ True when this is an inline node (a text node or a node that can
16869
+ appear among text).
16870
+ */
16871
+ get isInline() {
16872
+ return this.type.isInline;
16873
+ }
16874
+ /**
16875
+ True when this is a text node.
16876
+ */
16877
+ get isText() {
16878
+ return this.type.isText;
16879
+ }
16880
+ /**
16881
+ True when this is a leaf node.
16882
+ */
16883
+ get isLeaf() {
16884
+ return this.type.isLeaf;
16885
+ }
16886
+ /**
16887
+ True when this is an atom, i.e. when it does not have directly
16888
+ editable content. This is usually the same as `isLeaf`, but can
16889
+ be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
16890
+ on a node's spec (typically used when the node is displayed as
16891
+ an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
16892
+ */
16893
+ get isAtom() {
16894
+ return this.type.isAtom;
16895
+ }
16896
+ /**
16897
+ Return a string representation of this node for debugging
16898
+ purposes.
16899
+ */
16900
+ toString() {
16901
+ if (this.type.spec.toDebugString)
16902
+ return this.type.spec.toDebugString(this);
16903
+ let name = this.type.name;
16904
+ if (this.content.size)
16905
+ name += "(" + this.content.toStringInner() + ")";
16906
+ return wrapMarks(this.marks, name);
16907
+ }
16908
+ /**
16909
+ Get the content match in this node at the given index.
16910
+ */
16911
+ contentMatchAt(index) {
16912
+ let match = this.type.contentMatch.matchFragment(this.content, 0, index);
16913
+ if (!match)
16914
+ throw new Error("Called contentMatchAt on a node with invalid content");
16915
+ return match;
16916
+ }
16917
+ /**
16918
+ Test whether replacing the range between `from` and `to` (by
16919
+ child index) with the given replacement fragment (which defaults
16920
+ to the empty fragment) would leave the node's content valid. You
16921
+ can optionally pass `start` and `end` indices into the
16922
+ replacement fragment.
16923
+ */
16924
+ canReplace(from, to, replacement = Fragment25.empty, start = 0, end = replacement.childCount) {
16925
+ let one = this.contentMatchAt(from).matchFragment(replacement, start, end);
16926
+ let two = one && one.matchFragment(this.content, to);
16927
+ if (!two || !two.validEnd)
16928
+ return false;
16929
+ for (let i = start; i < end; i++)
16930
+ if (!this.type.allowsMarks(replacement.child(i).marks))
16931
+ return false;
16932
+ return true;
16933
+ }
16934
+ /**
16935
+ Test whether replacing the range `from` to `to` (by index) with
16936
+ a node of the given type would leave the node's content valid.
16937
+ */
16938
+ canReplaceWith(from, to, type, marks) {
16939
+ if (marks && !this.type.allowsMarks(marks))
16940
+ return false;
16941
+ let start = this.contentMatchAt(from).matchType(type);
16942
+ let end = start && start.matchFragment(this.content, to);
16943
+ return end ? end.validEnd : false;
16944
+ }
16945
+ /**
16946
+ Test whether the given node's content could be appended to this
16947
+ node. If that node is empty, this will only return true if there
16948
+ is at least one node type that can appear in both nodes (to avoid
16949
+ merging completely incompatible nodes).
16950
+ */
16951
+ canAppend(other) {
16952
+ if (other.content.size)
16953
+ return this.canReplace(this.childCount, this.childCount, other.content);
16954
+ else
16955
+ return this.type.compatibleContent(other.type);
16956
+ }
16957
+ /**
16958
+ Check whether this node and its descendants conform to the
16959
+ schema, and raise an exception when they do not.
16960
+ */
16961
+ check() {
16962
+ this.type.checkContent(this.content);
16963
+ this.type.checkAttrs(this.attrs);
16964
+ let copy = Mark.none;
16965
+ for (let i = 0; i < this.marks.length; i++) {
16966
+ let mark = this.marks[i];
16967
+ mark.type.checkAttrs(mark.attrs);
16968
+ copy = mark.addToSet(copy);
16969
+ }
16970
+ if (!Mark.sameSet(copy, this.marks))
16971
+ throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
16972
+ this.content.forEach((node) => node.check());
16973
+ }
16974
+ /**
16975
+ Return a JSON-serializeable representation of this node.
16976
+ */
16977
+ toJSON() {
16978
+ let obj = { type: this.type.name };
16979
+ for (let _ in this.attrs) {
16980
+ obj.attrs = this.attrs;
16981
+ break;
16982
+ }
16983
+ if (this.content.size)
16984
+ obj.content = this.content.toJSON();
16985
+ if (this.marks.length)
16986
+ obj.marks = this.marks.map((n) => n.toJSON());
16987
+ return obj;
16988
+ }
16989
+ /**
16990
+ Deserialize a node from its JSON representation.
16991
+ */
16992
+ static fromJSON(schema, json) {
16993
+ if (!json)
16994
+ throw new RangeError("Invalid input for Node.fromJSON");
16995
+ let marks = void 0;
16996
+ if (json.marks) {
16997
+ if (!Array.isArray(json.marks))
16998
+ throw new RangeError("Invalid mark data for Node.fromJSON");
16999
+ marks = json.marks.map(schema.markFromJSON);
17000
+ }
17001
+ if (json.type == "text") {
17002
+ if (typeof json.text != "string")
17003
+ throw new RangeError("Invalid text node in JSON");
17004
+ return schema.text(json.text, marks);
17005
+ }
17006
+ let content = Fragment25.fromJSON(schema, json.content);
17007
+ let node = schema.nodeType(json.type).create(json.attrs, content, marks);
17008
+ node.type.checkAttrs(node.attrs);
17009
+ return node;
17010
+ }
17011
+ };
17012
+ Node.prototype.text = void 0;
17013
+ function wrapMarks(marks, str) {
17014
+ for (let i = marks.length - 1; i >= 0; i--)
17015
+ str = marks[i].type.name + "(" + str + ")";
17016
+ return str;
17017
+ }
17018
+ var ContentMatch = class _ContentMatch {
17019
+ /**
17020
+ @internal
17021
+ */
17022
+ constructor(validEnd) {
17023
+ this.validEnd = validEnd;
17024
+ this.next = [];
17025
+ this.wrapCache = [];
17026
+ }
17027
+ /**
17028
+ @internal
17029
+ */
17030
+ static parse(string, nodeTypes) {
17031
+ let stream = new TokenStream(string, nodeTypes);
17032
+ if (stream.next == null)
17033
+ return _ContentMatch.empty;
17034
+ let expr = parseExpr(stream);
17035
+ if (stream.next)
17036
+ stream.err("Unexpected trailing text");
17037
+ let match = dfa(nfa(expr));
17038
+ checkForDeadEnds(match, stream);
17039
+ return match;
17040
+ }
17041
+ /**
17042
+ Match a node type, returning a match after that node if
17043
+ successful.
17044
+ */
17045
+ matchType(type) {
17046
+ for (let i = 0; i < this.next.length; i++)
17047
+ if (this.next[i].type == type)
17048
+ return this.next[i].next;
17049
+ return null;
17050
+ }
17051
+ /**
17052
+ Try to match a fragment. Returns the resulting match when
17053
+ successful.
17054
+ */
17055
+ matchFragment(frag, start = 0, end = frag.childCount) {
17056
+ let cur = this;
17057
+ for (let i = start; cur && i < end; i++)
17058
+ cur = cur.matchType(frag.child(i).type);
17059
+ return cur;
17060
+ }
17061
+ /**
17062
+ @internal
17063
+ */
17064
+ get inlineContent() {
17065
+ return this.next.length != 0 && this.next[0].type.isInline;
17066
+ }
17067
+ /**
17068
+ Get the first matching node type at this match position that can
17069
+ be generated.
17070
+ */
17071
+ get defaultType() {
17072
+ for (let i = 0; i < this.next.length; i++) {
17073
+ let { type } = this.next[i];
17074
+ if (!(type.isText || type.hasRequiredAttrs()))
17075
+ return type;
17076
+ }
17077
+ return null;
17078
+ }
17079
+ /**
17080
+ @internal
17081
+ */
17082
+ compatible(other) {
17083
+ for (let i = 0; i < this.next.length; i++)
17084
+ for (let j = 0; j < other.next.length; j++)
17085
+ if (this.next[i].type == other.next[j].type)
17086
+ return true;
17087
+ return false;
17088
+ }
17089
+ /**
17090
+ Try to match the given fragment, and if that fails, see if it can
17091
+ be made to match by inserting nodes in front of it. When
17092
+ successful, return a fragment of inserted nodes (which may be
17093
+ empty if nothing had to be inserted). When `toEnd` is true, only
17094
+ return a fragment if the resulting match goes to the end of the
17095
+ content expression.
17096
+ */
17097
+ fillBefore(after, toEnd = false, startIndex = 0) {
17098
+ let seen = [this];
17099
+ function search(match, types) {
17100
+ let finished = match.matchFragment(after, startIndex);
17101
+ if (finished && (!toEnd || finished.validEnd))
17102
+ return Fragment25.from(types.map((tp) => tp.createAndFill()));
17103
+ for (let i = 0; i < match.next.length; i++) {
17104
+ let { type, next } = match.next[i];
17105
+ if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {
17106
+ seen.push(next);
17107
+ let found2 = search(next, types.concat(type));
17108
+ if (found2)
17109
+ return found2;
17110
+ }
17111
+ }
17112
+ return null;
17113
+ }
17114
+ return search(this, []);
17115
+ }
17116
+ /**
17117
+ Find a set of wrapping node types that would allow a node of the
17118
+ given type to appear at this position. The result may be empty
17119
+ (when it fits directly) and will be null when no such wrapping
17120
+ exists.
17121
+ */
17122
+ findWrapping(target) {
17123
+ for (let i = 0; i < this.wrapCache.length; i += 2)
17124
+ if (this.wrapCache[i] == target)
17125
+ return this.wrapCache[i + 1];
17126
+ let computed = this.computeWrapping(target);
17127
+ this.wrapCache.push(target, computed);
17128
+ return computed;
17129
+ }
17130
+ /**
17131
+ @internal
17132
+ */
17133
+ computeWrapping(target) {
17134
+ let seen = /* @__PURE__ */ Object.create(null), active = [{ match: this, type: null, via: null }];
17135
+ while (active.length) {
17136
+ let current = active.shift(), match = current.match;
17137
+ if (match.matchType(target)) {
17138
+ let result = [];
17139
+ for (let obj = current; obj.type; obj = obj.via)
17140
+ result.push(obj.type);
17141
+ return result.reverse();
17142
+ }
17143
+ for (let i = 0; i < match.next.length; i++) {
17144
+ let { type, next } = match.next[i];
17145
+ if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {
17146
+ active.push({ match: type.contentMatch, type, via: current });
17147
+ seen[type.name] = true;
17148
+ }
17149
+ }
17150
+ }
17151
+ return null;
17152
+ }
17153
+ /**
17154
+ The number of outgoing edges this node has in the finite
17155
+ automaton that describes the content expression.
17156
+ */
17157
+ get edgeCount() {
17158
+ return this.next.length;
17159
+ }
17160
+ /**
17161
+ Get the _n_​th outgoing edge from this node in the finite
17162
+ automaton that describes the content expression.
17163
+ */
17164
+ edge(n) {
17165
+ if (n >= this.next.length)
17166
+ throw new RangeError(`There's no ${n}th edge in this content match`);
17167
+ return this.next[n];
17168
+ }
17169
+ /**
17170
+ @internal
17171
+ */
17172
+ toString() {
17173
+ let seen = [];
17174
+ function scan(m) {
17175
+ seen.push(m);
17176
+ for (let i = 0; i < m.next.length; i++)
17177
+ if (seen.indexOf(m.next[i].next) == -1)
17178
+ scan(m.next[i].next);
17179
+ }
17180
+ scan(this);
17181
+ return seen.map((m, i) => {
17182
+ let out = i + (m.validEnd ? "*" : " ") + " ";
17183
+ for (let i2 = 0; i2 < m.next.length; i2++)
17184
+ out += (i2 ? ", " : "") + m.next[i2].type.name + "->" + seen.indexOf(m.next[i2].next);
17185
+ return out;
17186
+ }).join("\n");
17187
+ }
17188
+ };
17189
+ ContentMatch.empty = new ContentMatch(true);
17190
+ var TokenStream = class {
17191
+ constructor(string, nodeTypes) {
17192
+ this.string = string;
17193
+ this.nodeTypes = nodeTypes;
17194
+ this.inline = null;
17195
+ this.pos = 0;
17196
+ this.tokens = string.split(/\s*(?=\b|\W|$)/);
17197
+ if (this.tokens[this.tokens.length - 1] == "")
17198
+ this.tokens.pop();
17199
+ if (this.tokens[0] == "")
17200
+ this.tokens.shift();
17201
+ }
17202
+ get next() {
17203
+ return this.tokens[this.pos];
17204
+ }
17205
+ eat(tok) {
17206
+ return this.next == tok && (this.pos++ || true);
17207
+ }
17208
+ err(str) {
17209
+ throw new SyntaxError(str + " (in content expression '" + this.string + "')");
17210
+ }
17211
+ };
17212
+ function parseExpr(stream) {
17213
+ let exprs = [];
17214
+ do {
17215
+ exprs.push(parseExprSeq(stream));
17216
+ } while (stream.eat("|"));
17217
+ return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
17218
+ }
17219
+ function parseExprSeq(stream) {
17220
+ let exprs = [];
17221
+ do {
17222
+ exprs.push(parseExprSubscript(stream));
17223
+ } while (stream.next && stream.next != ")" && stream.next != "|");
17224
+ return exprs.length == 1 ? exprs[0] : { type: "seq", exprs };
17225
+ }
17226
+ function parseExprSubscript(stream) {
17227
+ let expr = parseExprAtom(stream);
17228
+ for (; ; ) {
17229
+ if (stream.eat("+"))
17230
+ expr = { type: "plus", expr };
17231
+ else if (stream.eat("*"))
17232
+ expr = { type: "star", expr };
17233
+ else if (stream.eat("?"))
17234
+ expr = { type: "opt", expr };
17235
+ else if (stream.eat("{"))
17236
+ expr = parseExprRange(stream, expr);
17237
+ else
17238
+ break;
17239
+ }
17240
+ return expr;
17241
+ }
17242
+ function parseNum(stream) {
17243
+ if (/\D/.test(stream.next))
17244
+ stream.err("Expected number, got '" + stream.next + "'");
17245
+ let result = Number(stream.next);
17246
+ stream.pos++;
17247
+ return result;
17248
+ }
17249
+ function parseExprRange(stream, expr) {
17250
+ let min = parseNum(stream), max = min;
17251
+ if (stream.eat(",")) {
17252
+ if (stream.next != "}")
17253
+ max = parseNum(stream);
17254
+ else
17255
+ max = -1;
17256
+ }
17257
+ if (!stream.eat("}"))
17258
+ stream.err("Unclosed braced range");
17259
+ return { type: "range", min, max, expr };
17260
+ }
17261
+ function resolveName(stream, name) {
17262
+ let types = stream.nodeTypes, type = types[name];
17263
+ if (type)
17264
+ return [type];
17265
+ let result = [];
17266
+ for (let typeName in types) {
17267
+ let type2 = types[typeName];
17268
+ if (type2.isInGroup(name))
17269
+ result.push(type2);
17270
+ }
17271
+ if (result.length == 0)
17272
+ stream.err("No node type or group '" + name + "' found");
17273
+ return result;
17274
+ }
17275
+ function parseExprAtom(stream) {
17276
+ if (stream.eat("(")) {
17277
+ let expr = parseExpr(stream);
17278
+ if (!stream.eat(")"))
17279
+ stream.err("Missing closing paren");
17280
+ return expr;
17281
+ } else if (!/\W/.test(stream.next)) {
17282
+ let exprs = resolveName(stream, stream.next).map((type) => {
17283
+ if (stream.inline == null)
17284
+ stream.inline = type.isInline;
17285
+ else if (stream.inline != type.isInline)
17286
+ stream.err("Mixing inline and block content");
17287
+ return { type: "name", value: type };
17288
+ });
17289
+ stream.pos++;
17290
+ return exprs.length == 1 ? exprs[0] : { type: "choice", exprs };
17291
+ } else {
17292
+ stream.err("Unexpected token '" + stream.next + "'");
17293
+ }
17294
+ }
17295
+ function nfa(expr) {
17296
+ let nfa2 = [[]];
17297
+ connect(compile(expr, 0), node());
17298
+ return nfa2;
17299
+ function node() {
17300
+ return nfa2.push([]) - 1;
17301
+ }
17302
+ function edge(from, to, term) {
17303
+ let edge2 = { term, to };
17304
+ nfa2[from].push(edge2);
17305
+ return edge2;
17306
+ }
17307
+ function connect(edges, to) {
17308
+ edges.forEach((edge2) => edge2.to = to);
17309
+ }
17310
+ function compile(expr2, from) {
17311
+ if (expr2.type == "choice") {
17312
+ return expr2.exprs.reduce((out, expr3) => out.concat(compile(expr3, from)), []);
17313
+ } else if (expr2.type == "seq") {
17314
+ for (let i = 0; ; i++) {
17315
+ let next = compile(expr2.exprs[i], from);
17316
+ if (i == expr2.exprs.length - 1)
17317
+ return next;
17318
+ connect(next, from = node());
17319
+ }
17320
+ } else if (expr2.type == "star") {
17321
+ let loop = node();
17322
+ edge(from, loop);
17323
+ connect(compile(expr2.expr, loop), loop);
17324
+ return [edge(loop)];
17325
+ } else if (expr2.type == "plus") {
17326
+ let loop = node();
17327
+ connect(compile(expr2.expr, from), loop);
17328
+ connect(compile(expr2.expr, loop), loop);
17329
+ return [edge(loop)];
17330
+ } else if (expr2.type == "opt") {
17331
+ return [edge(from)].concat(compile(expr2.expr, from));
17332
+ } else if (expr2.type == "range") {
17333
+ let cur = from;
17334
+ for (let i = 0; i < expr2.min; i++) {
17335
+ let next = node();
17336
+ connect(compile(expr2.expr, cur), next);
17337
+ cur = next;
17338
+ }
17339
+ if (expr2.max == -1) {
17340
+ connect(compile(expr2.expr, cur), cur);
17341
+ } else {
17342
+ for (let i = expr2.min; i < expr2.max; i++) {
17343
+ let next = node();
17344
+ edge(cur, next);
17345
+ connect(compile(expr2.expr, cur), next);
17346
+ cur = next;
17347
+ }
17348
+ }
17349
+ return [edge(cur)];
17350
+ } else if (expr2.type == "name") {
17351
+ return [edge(from, void 0, expr2.value)];
17352
+ } else {
17353
+ throw new Error("Unknown expr type");
17354
+ }
17355
+ }
17356
+ }
17357
+ function cmp(a, b) {
17358
+ return b - a;
17359
+ }
17360
+ function nullFrom(nfa2, node) {
17361
+ let result = [];
17362
+ scan(node);
17363
+ return result.sort(cmp);
17364
+ function scan(node2) {
17365
+ let edges = nfa2[node2];
17366
+ if (edges.length == 1 && !edges[0].term)
17367
+ return scan(edges[0].to);
17368
+ result.push(node2);
17369
+ for (let i = 0; i < edges.length; i++) {
17370
+ let { term, to } = edges[i];
17371
+ if (!term && result.indexOf(to) == -1)
17372
+ scan(to);
17373
+ }
17374
+ }
17375
+ }
17376
+ function dfa(nfa2) {
17377
+ let labeled = /* @__PURE__ */ Object.create(null);
17378
+ return explore(nullFrom(nfa2, 0));
17379
+ function explore(states) {
17380
+ let out = [];
17381
+ states.forEach((node) => {
17382
+ nfa2[node].forEach(({ term, to }) => {
17383
+ if (!term)
17384
+ return;
17385
+ let set;
17386
+ for (let i = 0; i < out.length; i++)
17387
+ if (out[i][0] == term)
17388
+ set = out[i][1];
17389
+ nullFrom(nfa2, to).forEach((node2) => {
17390
+ if (!set)
17391
+ out.push([term, set = []]);
17392
+ if (set.indexOf(node2) == -1)
17393
+ set.push(node2);
17394
+ });
17395
+ });
17396
+ });
17397
+ let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa2.length - 1) > -1);
17398
+ for (let i = 0; i < out.length; i++) {
17399
+ let states2 = out[i][1].sort(cmp);
17400
+ state.next.push({ type: out[i][0], next: labeled[states2.join(",")] || explore(states2) });
17401
+ }
17402
+ return state;
17403
+ }
17404
+ }
17405
+ function checkForDeadEnds(match, stream) {
17406
+ for (let i = 0, work = [match]; i < work.length; i++) {
17407
+ let state = work[i], dead = !state.validEnd, nodes = [];
17408
+ for (let j = 0; j < state.next.length; j++) {
17409
+ let { type, next } = state.next[j];
17410
+ nodes.push(type.name);
17411
+ if (dead && !(type.isText || type.hasRequiredAttrs()))
17412
+ dead = false;
17413
+ if (work.indexOf(next) == -1)
17414
+ work.push(next);
17415
+ }
17416
+ if (dead)
17417
+ stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
17418
+ }
17419
+ }
17420
+
17421
+ // ../../node_modules/prosemirror-transform/dist/index.js
17422
+ var lower16 = 65535;
17423
+ var factor16 = Math.pow(2, 16);
17424
+ function makeRecover(index, offset) {
17425
+ return index + offset * factor16;
17426
+ }
17427
+ function recoverIndex(value) {
17428
+ return value & lower16;
17429
+ }
17430
+ function recoverOffset(value) {
17431
+ return (value - (value & lower16)) / factor16;
17432
+ }
17433
+ var DEL_BEFORE = 1;
17434
+ var DEL_AFTER = 2;
17435
+ var DEL_ACROSS = 4;
17436
+ var DEL_SIDE = 8;
17437
+ var MapResult = class {
17438
+ /**
17439
+ @internal
17440
+ */
17441
+ constructor(pos, delInfo, recover) {
17442
+ this.pos = pos;
17443
+ this.delInfo = delInfo;
17444
+ this.recover = recover;
17445
+ }
17446
+ /**
17447
+ Tells you whether the position was deleted, that is, whether the
17448
+ step removed the token on the side queried (via the `assoc`)
17449
+ argument from the document.
17450
+ */
17451
+ get deleted() {
17452
+ return (this.delInfo & DEL_SIDE) > 0;
17453
+ }
17454
+ /**
17455
+ Tells you whether the token before the mapped position was deleted.
17456
+ */
17457
+ get deletedBefore() {
17458
+ return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0;
17459
+ }
17460
+ /**
17461
+ True when the token after the mapped position was deleted.
17462
+ */
17463
+ get deletedAfter() {
17464
+ return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0;
17465
+ }
17466
+ /**
17467
+ Tells whether any of the steps mapped through deletes across the
17468
+ position (including both the token before and after the
17469
+ position).
17470
+ */
17471
+ get deletedAcross() {
17472
+ return (this.delInfo & DEL_ACROSS) > 0;
17473
+ }
17474
+ };
17475
+ var StepMap = class _StepMap {
17476
+ /**
17477
+ Create a position map. The modifications to the document are
17478
+ represented as an array of numbers, in which each group of three
17479
+ represents a modified chunk as `[start, oldSize, newSize]`.
17480
+ */
17481
+ constructor(ranges, inverted = false) {
17482
+ this.ranges = ranges;
17483
+ this.inverted = inverted;
17484
+ if (!ranges.length && _StepMap.empty)
17485
+ return _StepMap.empty;
17486
+ }
17487
+ /**
17488
+ @internal
17489
+ */
17490
+ recover(value) {
17491
+ let diff = 0, index = recoverIndex(value);
17492
+ if (!this.inverted)
17493
+ for (let i = 0; i < index; i++)
17494
+ diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
17495
+ return this.ranges[index * 3] + diff + recoverOffset(value);
17496
+ }
17497
+ mapResult(pos, assoc = 1) {
17498
+ return this._map(pos, assoc, false);
17499
+ }
17500
+ map(pos, assoc = 1) {
17501
+ return this._map(pos, assoc, true);
17502
+ }
17503
+ /**
17504
+ @internal
17505
+ */
17506
+ _map(pos, assoc, simple) {
17507
+ let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
17508
+ for (let i = 0; i < this.ranges.length; i += 3) {
17509
+ let start = this.ranges[i] - (this.inverted ? diff : 0);
17510
+ if (start > pos)
17511
+ break;
17512
+ let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;
17513
+ if (pos <= end) {
17514
+ let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;
17515
+ let result = start + diff + (side < 0 ? 0 : newSize);
17516
+ if (simple)
17517
+ return result;
17518
+ let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
17519
+ let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
17520
+ if (assoc < 0 ? pos != start : pos != end)
17521
+ del |= DEL_SIDE;
17522
+ return new MapResult(result, del, recover);
17523
+ }
17524
+ diff += newSize - oldSize;
17525
+ }
17526
+ return simple ? pos + diff : new MapResult(pos + diff, 0, null);
17527
+ }
17528
+ /**
17529
+ @internal
17530
+ */
17531
+ touches(pos, recover) {
17532
+ let diff = 0, index = recoverIndex(recover);
17533
+ let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
17534
+ for (let i = 0; i < this.ranges.length; i += 3) {
17535
+ let start = this.ranges[i] - (this.inverted ? diff : 0);
17536
+ if (start > pos)
17537
+ break;
17538
+ let oldSize = this.ranges[i + oldIndex], end = start + oldSize;
17539
+ if (pos <= end && i == index * 3)
17540
+ return true;
17541
+ diff += this.ranges[i + newIndex] - oldSize;
17542
+ }
17543
+ return false;
17544
+ }
17545
+ /**
17546
+ Calls the given function on each of the changed ranges included in
17547
+ this map.
17548
+ */
17549
+ forEach(f) {
17550
+ let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;
17551
+ for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {
17552
+ let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);
17553
+ let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];
17554
+ f(oldStart, oldStart + oldSize, newStart, newStart + newSize);
17555
+ diff += newSize - oldSize;
17556
+ }
17557
+ }
17558
+ /**
17559
+ Create an inverted version of this map. The result can be used to
17560
+ map positions in the post-step document to the pre-step document.
17561
+ */
17562
+ invert() {
17563
+ return new _StepMap(this.ranges, !this.inverted);
17564
+ }
17565
+ /**
17566
+ @internal
17567
+ */
17568
+ toString() {
17569
+ return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
17570
+ }
17571
+ /**
17572
+ Create a map that moves all positions by offset `n` (which may be
17573
+ negative). This can be useful when applying steps meant for a
17574
+ sub-document to a larger document, or vice-versa.
17575
+ */
17576
+ static offset(n) {
17577
+ return n == 0 ? _StepMap.empty : new _StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);
17578
+ }
17579
+ };
17580
+ StepMap.empty = new StepMap([]);
17581
+ var stepsByID = /* @__PURE__ */ Object.create(null);
17582
+ var Step = class {
17583
+ /**
17584
+ Get the step map that represents the changes made by this step,
17585
+ and which can be used to transform between positions in the old
17586
+ and the new document.
17587
+ */
17588
+ getMap() {
17589
+ return StepMap.empty;
17590
+ }
17591
+ /**
17592
+ Try to merge this step with another one, to be applied directly
17593
+ after it. Returns the merged step when possible, null if the
17594
+ steps can't be merged.
17595
+ */
17596
+ merge(other) {
17597
+ return null;
17598
+ }
17599
+ /**
17600
+ Deserialize a step from its JSON representation. Will call
17601
+ through to the step class' own implementation of this method.
17602
+ */
17603
+ static fromJSON(schema, json) {
17604
+ if (!json || !json.stepType)
17605
+ throw new RangeError("Invalid input for Step.fromJSON");
17606
+ let type = stepsByID[json.stepType];
17607
+ if (!type)
17608
+ throw new RangeError(`No step type ${json.stepType} defined`);
17609
+ return type.fromJSON(schema, json);
17610
+ }
17611
+ /**
17612
+ To be able to serialize steps to JSON, each step needs a string
17613
+ ID to attach to its JSON representation. Use this method to
17614
+ register an ID for your step classes. Try to pick something
17615
+ that's unlikely to clash with steps from other modules.
17616
+ */
17617
+ static jsonID(id, stepClass) {
17618
+ if (id in stepsByID)
17619
+ throw new RangeError("Duplicate use of step JSON ID " + id);
17620
+ stepsByID[id] = stepClass;
17621
+ stepClass.prototype.jsonID = id;
17622
+ return stepClass;
17623
+ }
17624
+ };
17625
+ var StepResult = class _StepResult {
17626
+ /**
17627
+ @internal
17628
+ */
17629
+ constructor(doc, failed) {
17630
+ this.doc = doc;
17631
+ this.failed = failed;
17632
+ }
17633
+ /**
17634
+ Create a successful step result.
17635
+ */
17636
+ static ok(doc) {
17637
+ return new _StepResult(doc, null);
17638
+ }
17639
+ /**
17640
+ Create a failed step result.
17641
+ */
17642
+ static fail(message) {
17643
+ return new _StepResult(null, message);
17644
+ }
17645
+ /**
17646
+ Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
17647
+ arguments. Create a successful result if it succeeds, and a
17648
+ failed one if it throws a `ReplaceError`.
17649
+ */
17650
+ static fromReplace(doc, from, to, slice) {
17651
+ try {
17652
+ return _StepResult.ok(doc.replace(from, to, slice));
17653
+ } catch (e) {
17654
+ if (e instanceof ReplaceError)
17655
+ return _StepResult.fail(e.message);
17656
+ throw e;
17657
+ }
17658
+ }
17659
+ };
17660
+ function mapFragment(fragment, f, parent) {
17661
+ let mapped = [];
17662
+ for (let i = 0; i < fragment.childCount; i++) {
17663
+ let child = fragment.child(i);
17664
+ if (child.content.size)
17665
+ child = child.copy(mapFragment(child.content, f, child));
17666
+ if (child.isInline)
17667
+ child = f(child, parent, i);
17668
+ mapped.push(child);
17669
+ }
17670
+ return Fragment25.fromArray(mapped);
17671
+ }
17672
+ var AddMarkStep = class _AddMarkStep extends Step {
17673
+ /**
17674
+ Create a mark step.
17675
+ */
17676
+ constructor(from, to, mark) {
17677
+ super();
17678
+ this.from = from;
17679
+ this.to = to;
17680
+ this.mark = mark;
17681
+ }
17682
+ apply(doc) {
17683
+ let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);
17684
+ let parent = $from.node($from.sharedDepth(this.to));
17685
+ let slice = new Slice(mapFragment(oldSlice.content, (node, parent2) => {
17686
+ if (!node.isAtom || !parent2.type.allowsMarkType(this.mark.type))
17687
+ return node;
17688
+ return node.mark(this.mark.addToSet(node.marks));
17689
+ }, parent), oldSlice.openStart, oldSlice.openEnd);
17690
+ return StepResult.fromReplace(doc, this.from, this.to, slice);
17691
+ }
17692
+ invert() {
17693
+ return new RemoveMarkStep(this.from, this.to, this.mark);
17694
+ }
17695
+ map(mapping) {
17696
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
17697
+ if (from.deleted && to.deleted || from.pos >= to.pos)
17698
+ return null;
17699
+ return new _AddMarkStep(from.pos, to.pos, this.mark);
17700
+ }
17701
+ merge(other) {
17702
+ if (other instanceof _AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
17703
+ return new _AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
17704
+ return null;
17705
+ }
17706
+ toJSON() {
17707
+ return {
17708
+ stepType: "addMark",
17709
+ mark: this.mark.toJSON(),
17710
+ from: this.from,
17711
+ to: this.to
17712
+ };
17713
+ }
17714
+ /**
17715
+ @internal
17716
+ */
17717
+ static fromJSON(schema, json) {
17718
+ if (typeof json.from != "number" || typeof json.to != "number")
17719
+ throw new RangeError("Invalid input for AddMarkStep.fromJSON");
17720
+ return new _AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
17721
+ }
17722
+ };
17723
+ Step.jsonID("addMark", AddMarkStep);
17724
+ var RemoveMarkStep = class _RemoveMarkStep extends Step {
17725
+ /**
17726
+ Create a mark-removing step.
17727
+ */
17728
+ constructor(from, to, mark) {
17729
+ super();
17730
+ this.from = from;
17731
+ this.to = to;
17732
+ this.mark = mark;
17733
+ }
17734
+ apply(doc) {
17735
+ let oldSlice = doc.slice(this.from, this.to);
17736
+ let slice = new Slice(mapFragment(oldSlice.content, (node) => {
17737
+ return node.mark(this.mark.removeFromSet(node.marks));
17738
+ }, doc), oldSlice.openStart, oldSlice.openEnd);
17739
+ return StepResult.fromReplace(doc, this.from, this.to, slice);
17740
+ }
17741
+ invert() {
17742
+ return new AddMarkStep(this.from, this.to, this.mark);
17743
+ }
17744
+ map(mapping) {
17745
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
17746
+ if (from.deleted && to.deleted || from.pos >= to.pos)
17747
+ return null;
17748
+ return new _RemoveMarkStep(from.pos, to.pos, this.mark);
17749
+ }
17750
+ merge(other) {
17751
+ if (other instanceof _RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from)
17752
+ return new _RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);
17753
+ return null;
17754
+ }
17755
+ toJSON() {
17756
+ return {
17757
+ stepType: "removeMark",
17758
+ mark: this.mark.toJSON(),
17759
+ from: this.from,
17760
+ to: this.to
17761
+ };
17762
+ }
17763
+ /**
17764
+ @internal
17765
+ */
17766
+ static fromJSON(schema, json) {
17767
+ if (typeof json.from != "number" || typeof json.to != "number")
17768
+ throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
17769
+ return new _RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));
17770
+ }
17771
+ };
17772
+ Step.jsonID("removeMark", RemoveMarkStep);
17773
+ var AddNodeMarkStep = class _AddNodeMarkStep extends Step {
17774
+ /**
17775
+ Create a node mark step.
17776
+ */
17777
+ constructor(pos, mark) {
17778
+ super();
17779
+ this.pos = pos;
17780
+ this.mark = mark;
17781
+ }
17782
+ apply(doc) {
17783
+ let node = doc.nodeAt(this.pos);
17784
+ if (!node)
17785
+ return StepResult.fail("No node at mark step's position");
17786
+ let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));
17787
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment25.from(updated), 0, node.isLeaf ? 0 : 1));
17788
+ }
17789
+ invert(doc) {
17790
+ let node = doc.nodeAt(this.pos);
17791
+ if (node) {
17792
+ let newSet = this.mark.addToSet(node.marks);
17793
+ if (newSet.length == node.marks.length) {
17794
+ for (let i = 0; i < node.marks.length; i++)
17795
+ if (!node.marks[i].isInSet(newSet))
17796
+ return new _AddNodeMarkStep(this.pos, node.marks[i]);
17797
+ return new _AddNodeMarkStep(this.pos, this.mark);
17798
+ }
17799
+ }
17800
+ return new RemoveNodeMarkStep(this.pos, this.mark);
17801
+ }
17802
+ map(mapping) {
17803
+ let pos = mapping.mapResult(this.pos, 1);
17804
+ return pos.deletedAfter ? null : new _AddNodeMarkStep(pos.pos, this.mark);
17805
+ }
17806
+ toJSON() {
17807
+ return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
17808
+ }
17809
+ /**
17810
+ @internal
17811
+ */
17812
+ static fromJSON(schema, json) {
17813
+ if (typeof json.pos != "number")
17814
+ throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
17815
+ return new _AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
17816
+ }
17817
+ };
17818
+ Step.jsonID("addNodeMark", AddNodeMarkStep);
17819
+ var RemoveNodeMarkStep = class _RemoveNodeMarkStep extends Step {
17820
+ /**
17821
+ Create a mark-removing step.
17822
+ */
17823
+ constructor(pos, mark) {
17824
+ super();
17825
+ this.pos = pos;
17826
+ this.mark = mark;
17827
+ }
17828
+ apply(doc) {
17829
+ let node = doc.nodeAt(this.pos);
17830
+ if (!node)
17831
+ return StepResult.fail("No node at mark step's position");
17832
+ let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));
17833
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment25.from(updated), 0, node.isLeaf ? 0 : 1));
17834
+ }
17835
+ invert(doc) {
17836
+ let node = doc.nodeAt(this.pos);
17837
+ if (!node || !this.mark.isInSet(node.marks))
17838
+ return this;
17839
+ return new AddNodeMarkStep(this.pos, this.mark);
17840
+ }
17841
+ map(mapping) {
17842
+ let pos = mapping.mapResult(this.pos, 1);
17843
+ return pos.deletedAfter ? null : new _RemoveNodeMarkStep(pos.pos, this.mark);
17844
+ }
17845
+ toJSON() {
17846
+ return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
17847
+ }
17848
+ /**
17849
+ @internal
17850
+ */
17851
+ static fromJSON(schema, json) {
17852
+ if (typeof json.pos != "number")
17853
+ throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
17854
+ return new _RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));
17855
+ }
17856
+ };
17857
+ Step.jsonID("removeNodeMark", RemoveNodeMarkStep);
17858
+ var ReplaceStep = class _ReplaceStep extends Step {
17859
+ /**
17860
+ The given `slice` should fit the 'gap' between `from` and
17861
+ `to`—the depths must line up, and the surrounding nodes must be
17862
+ able to be joined with the open sides of the slice. When
17863
+ `structure` is true, the step will fail if the content between
17864
+ from and to is not just a sequence of closing and then opening
17865
+ tokens (this is to guard against rebased replace steps
17866
+ overwriting something they weren't supposed to).
17867
+ */
17868
+ constructor(from, to, slice, structure = false) {
17869
+ super();
17870
+ this.from = from;
17871
+ this.to = to;
17872
+ this.slice = slice;
17873
+ this.structure = structure;
17874
+ }
17875
+ apply(doc) {
17876
+ if (this.structure && contentBetween(doc, this.from, this.to))
17877
+ return StepResult.fail("Structure replace would overwrite content");
17878
+ return StepResult.fromReplace(doc, this.from, this.to, this.slice);
17879
+ }
17880
+ getMap() {
17881
+ return new StepMap([this.from, this.to - this.from, this.slice.size]);
17882
+ }
17883
+ invert(doc) {
17884
+ return new _ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));
17885
+ }
17886
+ map(mapping) {
17887
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
17888
+ if (from.deletedAcross && to.deletedAcross)
17889
+ return null;
17890
+ return new _ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);
17891
+ }
17892
+ merge(other) {
17893
+ if (!(other instanceof _ReplaceStep) || other.structure || this.structure)
17894
+ return null;
17895
+ if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {
17896
+ let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);
17897
+ return new _ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);
17898
+ } else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {
17899
+ let slice = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);
17900
+ return new _ReplaceStep(other.from, this.to, slice, this.structure);
17901
+ } else {
17902
+ return null;
17903
+ }
17904
+ }
17905
+ toJSON() {
17906
+ let json = { stepType: "replace", from: this.from, to: this.to };
17907
+ if (this.slice.size)
17908
+ json.slice = this.slice.toJSON();
17909
+ if (this.structure)
17910
+ json.structure = true;
17911
+ return json;
17912
+ }
17913
+ /**
17914
+ @internal
17915
+ */
17916
+ static fromJSON(schema, json) {
17917
+ if (typeof json.from != "number" || typeof json.to != "number")
17918
+ throw new RangeError("Invalid input for ReplaceStep.fromJSON");
17919
+ return new _ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);
17920
+ }
17921
+ };
17922
+ Step.jsonID("replace", ReplaceStep);
17923
+ var ReplaceAroundStep = class _ReplaceAroundStep extends Step {
17924
+ /**
17925
+ Create a replace-around step with the given range and gap.
17926
+ `insert` should be the point in the slice into which the content
17927
+ of the gap should be moved. `structure` has the same meaning as
17928
+ it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
17929
+ */
17930
+ constructor(from, to, gapFrom, gapTo, slice, insert, structure = false) {
17931
+ super();
17932
+ this.from = from;
17933
+ this.to = to;
17934
+ this.gapFrom = gapFrom;
17935
+ this.gapTo = gapTo;
17936
+ this.slice = slice;
17937
+ this.insert = insert;
17938
+ this.structure = structure;
17939
+ }
17940
+ apply(doc) {
17941
+ if (this.structure && (contentBetween(doc, this.from, this.gapFrom) || contentBetween(doc, this.gapTo, this.to)))
17942
+ return StepResult.fail("Structure gap-replace would overwrite content");
17943
+ let gap = doc.slice(this.gapFrom, this.gapTo);
17944
+ if (gap.openStart || gap.openEnd)
17945
+ return StepResult.fail("Gap is not a flat range");
17946
+ let inserted = this.slice.insertAt(this.insert, gap.content);
17947
+ if (!inserted)
17948
+ return StepResult.fail("Content does not fit in gap");
17949
+ return StepResult.fromReplace(doc, this.from, this.to, inserted);
17950
+ }
17951
+ getMap() {
17952
+ return new StepMap([
17953
+ this.from,
17954
+ this.gapFrom - this.from,
17955
+ this.insert,
17956
+ this.gapTo,
17957
+ this.to - this.gapTo,
17958
+ this.slice.size - this.insert
17959
+ ]);
17960
+ }
17961
+ invert(doc) {
17962
+ let gap = this.gapTo - this.gapFrom;
17963
+ return new _ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
17964
+ }
17965
+ map(mapping) {
17966
+ let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
17967
+ let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);
17968
+ let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
17969
+ if (from.deletedAcross && to.deletedAcross || gapFrom < from.pos || gapTo > to.pos)
17970
+ return null;
17971
+ return new _ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
17972
+ }
17973
+ toJSON() {
17974
+ let json = {
17975
+ stepType: "replaceAround",
17976
+ from: this.from,
17977
+ to: this.to,
17978
+ gapFrom: this.gapFrom,
17979
+ gapTo: this.gapTo,
17980
+ insert: this.insert
17981
+ };
17982
+ if (this.slice.size)
17983
+ json.slice = this.slice.toJSON();
17984
+ if (this.structure)
17985
+ json.structure = true;
17986
+ return json;
17987
+ }
17988
+ /**
17989
+ @internal
17990
+ */
17991
+ static fromJSON(schema, json) {
17992
+ if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
17993
+ throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
17994
+ return new _ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
17995
+ }
17996
+ };
17997
+ Step.jsonID("replaceAround", ReplaceAroundStep);
17998
+ function contentBetween(doc, from, to) {
17999
+ let $from = doc.resolve(from), dist = to - from, depth = $from.depth;
18000
+ while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
18001
+ depth--;
18002
+ dist--;
18003
+ }
18004
+ if (dist > 0) {
18005
+ let next = $from.node(depth).maybeChild($from.indexAfter(depth));
18006
+ while (dist > 0) {
18007
+ if (!next || next.isLeaf)
18008
+ return true;
18009
+ next = next.firstChild;
18010
+ dist--;
18011
+ }
18012
+ }
18013
+ return false;
18014
+ }
18015
+ var AttrStep = class _AttrStep extends Step {
18016
+ /**
18017
+ Construct an attribute step.
18018
+ */
18019
+ constructor(pos, attr, value) {
18020
+ super();
18021
+ this.pos = pos;
18022
+ this.attr = attr;
18023
+ this.value = value;
18024
+ }
18025
+ apply(doc) {
18026
+ let node = doc.nodeAt(this.pos);
18027
+ if (!node)
18028
+ return StepResult.fail("No node at attribute step's position");
18029
+ let attrs = /* @__PURE__ */ Object.create(null);
18030
+ for (let name in node.attrs)
18031
+ attrs[name] = node.attrs[name];
18032
+ attrs[this.attr] = this.value;
18033
+ let updated = node.type.create(attrs, null, node.marks);
18034
+ return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment25.from(updated), 0, node.isLeaf ? 0 : 1));
18035
+ }
18036
+ getMap() {
18037
+ return StepMap.empty;
18038
+ }
18039
+ invert(doc) {
18040
+ return new _AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
18041
+ }
18042
+ map(mapping) {
18043
+ let pos = mapping.mapResult(this.pos, 1);
18044
+ return pos.deletedAfter ? null : new _AttrStep(pos.pos, this.attr, this.value);
18045
+ }
18046
+ toJSON() {
18047
+ return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
18048
+ }
18049
+ static fromJSON(schema, json) {
18050
+ if (typeof json.pos != "number" || typeof json.attr != "string")
18051
+ throw new RangeError("Invalid input for AttrStep.fromJSON");
18052
+ return new _AttrStep(json.pos, json.attr, json.value);
18053
+ }
18054
+ };
18055
+ Step.jsonID("attr", AttrStep);
18056
+ var DocAttrStep = class _DocAttrStep extends Step {
18057
+ /**
18058
+ Construct an attribute step.
18059
+ */
18060
+ constructor(attr, value) {
18061
+ super();
18062
+ this.attr = attr;
18063
+ this.value = value;
18064
+ }
18065
+ apply(doc) {
18066
+ let attrs = /* @__PURE__ */ Object.create(null);
18067
+ for (let name in doc.attrs)
18068
+ attrs[name] = doc.attrs[name];
18069
+ attrs[this.attr] = this.value;
18070
+ let updated = doc.type.create(attrs, doc.content, doc.marks);
18071
+ return StepResult.ok(updated);
18072
+ }
18073
+ getMap() {
18074
+ return StepMap.empty;
18075
+ }
18076
+ invert(doc) {
18077
+ return new _DocAttrStep(this.attr, doc.attrs[this.attr]);
18078
+ }
18079
+ map(mapping) {
18080
+ return this;
18081
+ }
18082
+ toJSON() {
18083
+ return { stepType: "docAttr", attr: this.attr, value: this.value };
18084
+ }
18085
+ static fromJSON(schema, json) {
18086
+ if (typeof json.attr != "string")
18087
+ throw new RangeError("Invalid input for DocAttrStep.fromJSON");
18088
+ return new _DocAttrStep(json.attr, json.value);
18089
+ }
18090
+ };
18091
+ Step.jsonID("docAttr", DocAttrStep);
18092
+ var TransformError = class extends Error {
18093
+ };
18094
+ TransformError = function TransformError2(message) {
18095
+ let err = Error.call(this, message);
18096
+ err.__proto__ = TransformError2.prototype;
18097
+ return err;
18098
+ };
18099
+ TransformError.prototype = Object.create(Error.prototype);
18100
+ TransformError.prototype.constructor = TransformError;
18101
+ TransformError.prototype.name = "TransformError";
18102
+
18103
+ // ../../node_modules/prosemirror-state/dist/index.js
18104
+ var classesById = /* @__PURE__ */ Object.create(null);
18105
+ var Selection = class {
18106
+ /**
18107
+ Initialize a selection with the head and anchor and ranges. If no
18108
+ ranges are given, constructs a single range across `$anchor` and
18109
+ `$head`.
18110
+ */
18111
+ constructor($anchor, $head, ranges) {
18112
+ this.$anchor = $anchor;
18113
+ this.$head = $head;
18114
+ this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))];
18115
+ }
18116
+ /**
18117
+ The selection's anchor, as an unresolved position.
18118
+ */
18119
+ get anchor() {
18120
+ return this.$anchor.pos;
18121
+ }
18122
+ /**
18123
+ The selection's head.
18124
+ */
18125
+ get head() {
18126
+ return this.$head.pos;
18127
+ }
18128
+ /**
18129
+ The lower bound of the selection's main range.
18130
+ */
18131
+ get from() {
18132
+ return this.$from.pos;
18133
+ }
18134
+ /**
18135
+ The upper bound of the selection's main range.
18136
+ */
18137
+ get to() {
18138
+ return this.$to.pos;
18139
+ }
18140
+ /**
18141
+ The resolved lower bound of the selection's main range.
18142
+ */
18143
+ get $from() {
18144
+ return this.ranges[0].$from;
18145
+ }
18146
+ /**
18147
+ The resolved upper bound of the selection's main range.
18148
+ */
18149
+ get $to() {
18150
+ return this.ranges[0].$to;
18151
+ }
18152
+ /**
18153
+ Indicates whether the selection contains any content.
18154
+ */
18155
+ get empty() {
18156
+ let ranges = this.ranges;
18157
+ for (let i = 0; i < ranges.length; i++)
18158
+ if (ranges[i].$from.pos != ranges[i].$to.pos)
18159
+ return false;
18160
+ return true;
18161
+ }
18162
+ /**
18163
+ Get the content of this selection as a slice.
18164
+ */
18165
+ content() {
18166
+ return this.$from.doc.slice(this.from, this.to, true);
18167
+ }
18168
+ /**
18169
+ Replace the selection with a slice or, if no slice is given,
18170
+ delete the selection. Will append to the given transaction.
18171
+ */
18172
+ replace(tr, content = Slice.empty) {
18173
+ let lastNode = content.content.lastChild, lastParent = null;
18174
+ for (let i = 0; i < content.openEnd; i++) {
18175
+ lastParent = lastNode;
18176
+ lastNode = lastNode.lastChild;
18177
+ }
18178
+ let mapFrom = tr.steps.length, ranges = this.ranges;
18179
+ for (let i = 0; i < ranges.length; i++) {
18180
+ let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
18181
+ tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);
18182
+ if (i == 0)
18183
+ selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);
18184
+ }
18185
+ }
18186
+ /**
18187
+ Replace the selection with the given node, appending the changes
18188
+ to the given transaction.
18189
+ */
18190
+ replaceWith(tr, node) {
18191
+ let mapFrom = tr.steps.length, ranges = this.ranges;
18192
+ for (let i = 0; i < ranges.length; i++) {
18193
+ let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);
18194
+ let from = mapping.map($from.pos), to = mapping.map($to.pos);
18195
+ if (i) {
18196
+ tr.deleteRange(from, to);
18197
+ } else {
18198
+ tr.replaceRangeWith(from, to, node);
18199
+ selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1);
18200
+ }
18201
+ }
18202
+ }
18203
+ /**
18204
+ Find a valid cursor or leaf node selection starting at the given
18205
+ position and searching back if `dir` is negative, and forward if
18206
+ positive. When `textOnly` is true, only consider cursor
18207
+ selections. Will return null when no valid selection position is
18208
+ found.
18209
+ */
18210
+ static findFrom($pos, dir, textOnly = false) {
18211
+ let inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);
18212
+ if (inner)
18213
+ return inner;
18214
+ for (let depth = $pos.depth - 1; depth >= 0; depth--) {
18215
+ let found2 = 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);
18216
+ if (found2)
18217
+ return found2;
18218
+ }
18219
+ return null;
18220
+ }
18221
+ /**
18222
+ Find a valid cursor or leaf node selection near the given
18223
+ position. Searches forward first by default, but if `bias` is
18224
+ negative, it will search backwards first.
18225
+ */
18226
+ static near($pos, bias = 1) {
18227
+ return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));
18228
+ }
18229
+ /**
18230
+ Find the cursor or leaf node selection closest to the start of
18231
+ the given document. Will return an
18232
+ [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position
18233
+ exists.
18234
+ */
18235
+ static atStart(doc) {
18236
+ return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);
18237
+ }
18238
+ /**
18239
+ Find the cursor or leaf node selection closest to the end of the
18240
+ given document.
18241
+ */
18242
+ static atEnd(doc) {
18243
+ return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);
18244
+ }
18245
+ /**
18246
+ Deserialize the JSON representation of a selection. Must be
18247
+ implemented for custom classes (as a static class method).
18248
+ */
18249
+ static fromJSON(doc, json) {
18250
+ if (!json || !json.type)
18251
+ throw new RangeError("Invalid input for Selection.fromJSON");
18252
+ let cls = classesById[json.type];
18253
+ if (!cls)
18254
+ throw new RangeError(`No selection type ${json.type} defined`);
18255
+ return cls.fromJSON(doc, json);
18256
+ }
18257
+ /**
18258
+ To be able to deserialize selections from JSON, custom selection
18259
+ classes must register themselves with an ID string, so that they
18260
+ can be disambiguated. Try to pick something that's unlikely to
18261
+ clash with classes from other modules.
18262
+ */
18263
+ static jsonID(id, selectionClass) {
18264
+ if (id in classesById)
18265
+ throw new RangeError("Duplicate use of selection JSON ID " + id);
18266
+ classesById[id] = selectionClass;
18267
+ selectionClass.prototype.jsonID = id;
18268
+ return selectionClass;
18269
+ }
18270
+ /**
18271
+ Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,
18272
+ which is a value that can be mapped without having access to a
18273
+ current document, and later resolved to a real selection for a
18274
+ given document again. (This is used mostly by the history to
18275
+ track and restore old selections.) The default implementation of
18276
+ this method just converts the selection to a text selection and
18277
+ returns the bookmark for that.
18278
+ */
18279
+ getBookmark() {
18280
+ return TextSelection.between(this.$anchor, this.$head).getBookmark();
18281
+ }
18282
+ };
18283
+ Selection.prototype.visible = true;
18284
+ var SelectionRange = class {
18285
+ /**
18286
+ Create a range.
18287
+ */
18288
+ constructor($from, $to) {
18289
+ this.$from = $from;
18290
+ this.$to = $to;
18291
+ }
18292
+ };
18293
+ var warnedAboutTextSelection = false;
18294
+ function checkTextSelection($pos) {
18295
+ if (!warnedAboutTextSelection && !$pos.parent.inlineContent) {
18296
+ warnedAboutTextSelection = true;
18297
+ console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")");
18298
+ }
18299
+ }
18300
+ var TextSelection = class _TextSelection extends Selection {
18301
+ /**
18302
+ Construct a text selection between the given points.
18303
+ */
18304
+ constructor($anchor, $head = $anchor) {
18305
+ checkTextSelection($anchor);
18306
+ checkTextSelection($head);
18307
+ super($anchor, $head);
18308
+ }
18309
+ /**
18310
+ Returns a resolved position if this is a cursor selection (an
18311
+ empty text selection), and null otherwise.
18312
+ */
18313
+ get $cursor() {
18314
+ return this.$anchor.pos == this.$head.pos ? this.$head : null;
18315
+ }
18316
+ map(doc, mapping) {
18317
+ let $head = doc.resolve(mapping.map(this.head));
18318
+ if (!$head.parent.inlineContent)
18319
+ return Selection.near($head);
18320
+ let $anchor = doc.resolve(mapping.map(this.anchor));
18321
+ return new _TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);
18322
+ }
18323
+ replace(tr, content = Slice.empty) {
18324
+ super.replace(tr, content);
18325
+ if (content == Slice.empty) {
18326
+ let marks = this.$from.marksAcross(this.$to);
18327
+ if (marks)
18328
+ tr.ensureMarks(marks);
18329
+ }
18330
+ }
18331
+ eq(other) {
18332
+ return other instanceof _TextSelection && other.anchor == this.anchor && other.head == this.head;
18333
+ }
18334
+ getBookmark() {
18335
+ return new TextBookmark(this.anchor, this.head);
18336
+ }
18337
+ toJSON() {
18338
+ return { type: "text", anchor: this.anchor, head: this.head };
18339
+ }
18340
+ /**
18341
+ @internal
18342
+ */
18343
+ static fromJSON(doc, json) {
18344
+ if (typeof json.anchor != "number" || typeof json.head != "number")
18345
+ throw new RangeError("Invalid input for TextSelection.fromJSON");
18346
+ return new _TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));
18347
+ }
18348
+ /**
18349
+ Create a text selection from non-resolved positions.
18350
+ */
18351
+ static create(doc, anchor, head = anchor) {
18352
+ let $anchor = doc.resolve(anchor);
18353
+ return new this($anchor, head == anchor ? $anchor : doc.resolve(head));
18354
+ }
18355
+ /**
18356
+ Return a text selection that spans the given positions or, if
18357
+ they aren't text positions, find a text selection near them.
18358
+ `bias` determines whether the method searches forward (default)
18359
+ or backwards (negative number) first. Will fall back to calling
18360
+ [`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document
18361
+ doesn't contain a valid text position.
18362
+ */
18363
+ static between($anchor, $head, bias) {
18364
+ let dPos = $anchor.pos - $head.pos;
18365
+ if (!bias || dPos)
18366
+ bias = dPos >= 0 ? 1 : -1;
18367
+ if (!$head.parent.inlineContent) {
18368
+ let found2 = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);
18369
+ if (found2)
18370
+ $head = found2.$head;
18371
+ else
18372
+ return Selection.near($head, bias);
18373
+ }
18374
+ if (!$anchor.parent.inlineContent) {
18375
+ if (dPos == 0) {
18376
+ $anchor = $head;
18377
+ } else {
18378
+ $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor;
18379
+ if ($anchor.pos < $head.pos != dPos < 0)
18380
+ $anchor = $head;
18381
+ }
18382
+ }
18383
+ return new _TextSelection($anchor, $head);
18384
+ }
18385
+ };
18386
+ Selection.jsonID("text", TextSelection);
18387
+ var TextBookmark = class _TextBookmark {
18388
+ constructor(anchor, head) {
18389
+ this.anchor = anchor;
18390
+ this.head = head;
18391
+ }
18392
+ map(mapping) {
18393
+ return new _TextBookmark(mapping.map(this.anchor), mapping.map(this.head));
18394
+ }
18395
+ resolve(doc) {
18396
+ return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));
18397
+ }
18398
+ };
18399
+ var NodeSelection = class _NodeSelection extends Selection {
18400
+ /**
18401
+ Create a node selection. Does not verify the validity of its
18402
+ argument.
18403
+ */
18404
+ constructor($pos) {
18405
+ let node = $pos.nodeAfter;
18406
+ let $end = $pos.node(0).resolve($pos.pos + node.nodeSize);
18407
+ super($pos, $end);
18408
+ this.node = node;
18409
+ }
18410
+ map(doc, mapping) {
18411
+ let { deleted, pos } = mapping.mapResult(this.anchor);
18412
+ let $pos = doc.resolve(pos);
18413
+ if (deleted)
18414
+ return Selection.near($pos);
18415
+ return new _NodeSelection($pos);
18416
+ }
18417
+ content() {
18418
+ return new Slice(Fragment25.from(this.node), 0, 0);
18419
+ }
18420
+ eq(other) {
18421
+ return other instanceof _NodeSelection && other.anchor == this.anchor;
18422
+ }
18423
+ toJSON() {
18424
+ return { type: "node", anchor: this.anchor };
18425
+ }
18426
+ getBookmark() {
18427
+ return new NodeBookmark(this.anchor);
18428
+ }
18429
+ /**
18430
+ @internal
18431
+ */
18432
+ static fromJSON(doc, json) {
18433
+ if (typeof json.anchor != "number")
18434
+ throw new RangeError("Invalid input for NodeSelection.fromJSON");
18435
+ return new _NodeSelection(doc.resolve(json.anchor));
18436
+ }
18437
+ /**
18438
+ Create a node selection from non-resolved positions.
18439
+ */
18440
+ static create(doc, from) {
18441
+ return new _NodeSelection(doc.resolve(from));
18442
+ }
18443
+ /**
18444
+ Determines whether the given node may be selected as a node
18445
+ selection.
18446
+ */
18447
+ static isSelectable(node) {
18448
+ return !node.isText && node.type.spec.selectable !== false;
18449
+ }
18450
+ };
18451
+ NodeSelection.prototype.visible = false;
18452
+ Selection.jsonID("node", NodeSelection);
18453
+ var NodeBookmark = class _NodeBookmark {
18454
+ constructor(anchor) {
18455
+ this.anchor = anchor;
18456
+ }
18457
+ map(mapping) {
18458
+ let { deleted, pos } = mapping.mapResult(this.anchor);
18459
+ return deleted ? new TextBookmark(pos, pos) : new _NodeBookmark(pos);
18460
+ }
18461
+ resolve(doc) {
18462
+ let $pos = doc.resolve(this.anchor), node = $pos.nodeAfter;
18463
+ if (node && NodeSelection.isSelectable(node))
18464
+ return new NodeSelection($pos);
18465
+ return Selection.near($pos);
18466
+ }
18467
+ };
18468
+ var AllSelection = class _AllSelection extends Selection {
18469
+ /**
18470
+ Create an all-selection over the given document.
18471
+ */
18472
+ constructor(doc) {
18473
+ super(doc.resolve(0), doc.resolve(doc.content.size));
18474
+ }
18475
+ replace(tr, content = Slice.empty) {
18476
+ if (content == Slice.empty) {
18477
+ tr.delete(0, tr.doc.content.size);
18478
+ let sel = Selection.atStart(tr.doc);
18479
+ if (!sel.eq(tr.selection))
18480
+ tr.setSelection(sel);
18481
+ } else {
18482
+ super.replace(tr, content);
18483
+ }
18484
+ }
18485
+ toJSON() {
18486
+ return { type: "all" };
18487
+ }
18488
+ /**
18489
+ @internal
18490
+ */
18491
+ static fromJSON(doc) {
18492
+ return new _AllSelection(doc);
18493
+ }
18494
+ map(doc) {
18495
+ return new _AllSelection(doc);
18496
+ }
18497
+ eq(other) {
18498
+ return other instanceof _AllSelection;
18499
+ }
18500
+ getBookmark() {
18501
+ return AllBookmark;
18502
+ }
18503
+ };
18504
+ Selection.jsonID("all", AllSelection);
18505
+ var AllBookmark = {
18506
+ map() {
18507
+ return this;
18508
+ },
18509
+ resolve(doc) {
18510
+ return new AllSelection(doc);
18511
+ }
18512
+ };
18513
+ function findSelectionIn(doc, node, pos, index, dir, text = false) {
18514
+ if (node.inlineContent)
18515
+ return TextSelection.create(doc, pos);
18516
+ for (let i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) {
18517
+ let child = node.child(i);
18518
+ if (!child.isAtom) {
18519
+ let inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text);
18520
+ if (inner)
18521
+ return inner;
18522
+ } else if (!text && NodeSelection.isSelectable(child)) {
18523
+ return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0));
18524
+ }
18525
+ pos += child.nodeSize * dir;
18526
+ }
18527
+ return null;
18528
+ }
18529
+ function selectionToInsertionEnd(tr, startLen, bias) {
18530
+ let last = tr.steps.length - 1;
18531
+ if (last < startLen)
18532
+ return;
18533
+ let step = tr.steps[last];
18534
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
18535
+ return;
18536
+ let map = tr.mapping.maps[last], end;
18537
+ map.forEach((_from, _to, _newFrom, newTo) => {
18538
+ if (end == null)
18539
+ end = newTo;
18540
+ });
18541
+ tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
18542
+ }
18543
+ function bind(f, self) {
18544
+ return !self || !f ? f : f.bind(self);
18545
+ }
18546
+ var FieldDesc = class {
18547
+ constructor(name, desc, self) {
18548
+ this.name = name;
18549
+ this.init = bind(desc.init, self);
18550
+ this.apply = bind(desc.apply, self);
18551
+ }
18552
+ };
18553
+ var baseFields = [
18554
+ new FieldDesc("doc", {
18555
+ init(config) {
18556
+ return config.doc || config.schema.topNodeType.createAndFill();
18557
+ },
18558
+ apply(tr) {
18559
+ return tr.doc;
18560
+ }
18561
+ }),
18562
+ new FieldDesc("selection", {
18563
+ init(config, instance) {
18564
+ return config.selection || Selection.atStart(instance.doc);
18565
+ },
18566
+ apply(tr) {
18567
+ return tr.selection;
18568
+ }
18569
+ }),
18570
+ new FieldDesc("storedMarks", {
18571
+ init(config) {
18572
+ return config.storedMarks || null;
18573
+ },
18574
+ apply(tr, _marks, _old, state) {
18575
+ return state.selection.$cursor ? tr.storedMarks : null;
18576
+ }
18577
+ }),
18578
+ new FieldDesc("scrollToSelection", {
18579
+ init() {
18580
+ return 0;
18581
+ },
18582
+ apply(tr, prev) {
18583
+ return tr.scrolledIntoView ? prev + 1 : prev;
18584
+ }
18585
+ })
18586
+ ];
18587
+ function bindProps(obj, self, target) {
18588
+ for (let prop in obj) {
18589
+ let val = obj[prop];
18590
+ if (val instanceof Function)
18591
+ val = val.bind(self);
18592
+ else if (prop == "handleDOMEvents")
18593
+ val = bindProps(val, self, {});
18594
+ target[prop] = val;
18595
+ }
18596
+ return target;
18597
+ }
18598
+ var Plugin = class {
18599
+ /**
18600
+ Create a plugin.
18601
+ */
18602
+ constructor(spec) {
18603
+ this.spec = spec;
18604
+ this.props = {};
18605
+ if (spec.props)
18606
+ bindProps(spec.props, this, this.props);
18607
+ this.key = spec.key ? spec.key.key : createKey("plugin");
18608
+ }
18609
+ /**
18610
+ Extract the plugin's state field from an editor state.
18611
+ */
18612
+ getState(state) {
18613
+ return state[this.key];
18614
+ }
18615
+ };
18616
+ var keys = /* @__PURE__ */ Object.create(null);
18617
+ function createKey(name) {
18618
+ if (name in keys)
18619
+ return name + "$" + ++keys[name];
18620
+ keys[name] = 0;
18621
+ return name + "$";
18622
+ }
18623
+
18624
+ // ../../components/ui/UEditor/clipboard-images.ts
18625
+ function getImageFiles(dataTransfer) {
18626
+ if (!dataTransfer) return [];
18627
+ const byKey = /* @__PURE__ */ new Map();
18628
+ for (const item of Array.from(dataTransfer.items ?? [])) {
18629
+ if (item.kind !== "file") continue;
18630
+ if (!item.type.startsWith("image/")) continue;
18631
+ const file = item.getAsFile();
18632
+ if (!file) continue;
18633
+ byKey.set(`${file.name}:${file.size}:${file.lastModified}`, file);
18634
+ }
18635
+ for (const file of Array.from(dataTransfer.files ?? [])) {
18636
+ if (!file.type.startsWith("image/")) continue;
18637
+ byKey.set(`${file.name}:${file.size}:${file.lastModified}`, file);
18638
+ }
18639
+ return Array.from(byKey.values());
18640
+ }
18641
+ function fileToDataUrl(file) {
18642
+ return new Promise((resolve, reject) => {
18643
+ const reader = new FileReader();
18644
+ reader.onload = () => resolve(String(reader.result ?? ""));
18645
+ reader.onerror = () => reject(reader.error ?? new Error("Failed to read image file"));
18646
+ reader.readAsDataURL(file);
18647
+ });
18648
+ }
18649
+ async function resolveImageSrc(file, options) {
18650
+ if (options.insertMode === "upload" && options.upload) {
18651
+ try {
18652
+ const result = await options.upload(file);
18653
+ const src = typeof result === "string" ? result : "";
18654
+ if (src) return src;
18655
+ } catch (err) {
18656
+ if (!options.fallbackToDataUrl) throw err;
18657
+ }
18658
+ }
18659
+ return fileToDataUrl(file);
18660
+ }
18661
+ var ClipboardImages = import_core2.Extension.create({
18662
+ name: "clipboardImages",
18663
+ addOptions() {
18664
+ return {
18665
+ maxFileSize: 10 * 1024 * 1024,
18666
+ allowedMimeTypes: ["image/png", "image/jpeg", "image/webp", "image/gif", "image/svg+xml"],
18667
+ upload: void 0,
18668
+ fallbackToDataUrl: true,
18669
+ insertMode: "base64"
18670
+ };
18671
+ },
18672
+ addProseMirrorPlugins() {
18673
+ const editor = this.editor;
18674
+ const options = this.options;
18675
+ const insertFiles = async (files, selectionPos) => {
18676
+ if (selectionPos !== void 0) {
18677
+ editor.commands.setTextSelection(selectionPos);
18678
+ }
18679
+ for (const file of files) {
18680
+ if (file.size > options.maxFileSize) continue;
18681
+ if (options.allowedMimeTypes.length > 0 && !options.allowedMimeTypes.includes(file.type)) continue;
18682
+ const src = await resolveImageSrc(file, options);
18683
+ editor.chain().focus().setImage({ src, alt: file.name }).run();
18684
+ editor.commands.createParagraphNear();
18685
+ }
18686
+ };
18687
+ return [
18688
+ new Plugin({
18689
+ props: {
18690
+ handlePaste: (_view, event) => {
18691
+ if (!(event instanceof ClipboardEvent)) return false;
18692
+ const files = getImageFiles(event.clipboardData);
18693
+ if (files.length === 0) return false;
18694
+ event.preventDefault();
18695
+ void insertFiles(files);
18696
+ return true;
18697
+ },
18698
+ handleDrop: (view, event, _slice, moved) => {
18699
+ if (moved) return false;
18700
+ if (!(event instanceof DragEvent)) return false;
18701
+ const files = getImageFiles(event.dataTransfer);
18702
+ if (files.length === 0) return false;
18703
+ const pos = view.posAtCoords({ left: event.clientX, top: event.clientY })?.pos;
18704
+ event.preventDefault();
18705
+ void insertFiles(files, pos);
18706
+ return true;
18707
+ }
18708
+ }
18709
+ })
18710
+ ];
18711
+ }
18712
+ });
18713
+
15576
18714
  // ../../components/ui/UEditor/extensions.ts
15577
18715
  var lowlight = (0, import_lowlight.createLowlight)(import_lowlight.common);
15578
- function buildUEditorExtensions({ placeholder, maxCharacters }) {
18716
+ function buildUEditorExtensions({
18717
+ placeholder,
18718
+ maxCharacters,
18719
+ uploadImage,
18720
+ imageInsertMode = "base64"
18721
+ }) {
15579
18722
  return [
15580
18723
  import_extension_document.default,
15581
18724
  import_extension_paragraph.default,
@@ -15632,10 +18775,12 @@ function buildUEditorExtensions({ placeholder, maxCharacters }) {
15632
18775
  }
15633
18776
  }),
15634
18777
  import_extension_image.default.configure({
18778
+ allowBase64: true,
15635
18779
  HTMLAttributes: {
15636
18780
  class: "rounded-lg max-w-full h-auto my-4"
15637
18781
  }
15638
18782
  }),
18783
+ ClipboardImages.configure({ upload: uploadImage, insertMode: imageInsertMode }),
15639
18784
  import_extension_text_style.TextStyle,
15640
18785
  import_extension_color.default,
15641
18786
  import_extension_highlight.default.configure({
@@ -15842,6 +18987,14 @@ var ImageInput = ({ onSubmit, onCancel }) => {
15842
18987
 
15843
18988
  // ../../components/ui/UEditor/toolbar.tsx
15844
18989
  var import_jsx_runtime71 = require("react/jsx-runtime");
18990
+ function fileToDataUrl2(file) {
18991
+ return new Promise((resolve, reject) => {
18992
+ const reader = new FileReader();
18993
+ reader.onload = () => resolve(String(reader.result ?? ""));
18994
+ reader.onerror = () => reject(reader.error ?? new Error("Failed to read image file"));
18995
+ reader.readAsDataURL(file);
18996
+ });
18997
+ }
15845
18998
  var ToolbarButton = import_react42.default.forwardRef(({ onClick, active, disabled, children, title, className }, ref) => {
15846
18999
  const button = /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
15847
19000
  "button",
@@ -15869,10 +19022,35 @@ var ToolbarButton = import_react42.default.forwardRef(({ onClick, active, disabl
15869
19022
  });
15870
19023
  ToolbarButton.displayName = "ToolbarButton";
15871
19024
  var ToolbarDivider = () => /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { className: "w-px h-6 bg-border/50 mx-1" });
15872
- var EditorToolbar = ({ editor, variant }) => {
19025
+ var EditorToolbar = ({
19026
+ editor,
19027
+ variant,
19028
+ uploadImage,
19029
+ imageInsertMode = "base64"
19030
+ }) => {
15873
19031
  const t = (0, import_next_intl3.useTranslations)("UEditor");
15874
19032
  const { textColors, highlightColors } = useEditorColors();
15875
19033
  const [showImageInput, setShowImageInput] = (0, import_react42.useState)(false);
19034
+ const fileInputRef = (0, import_react42.useRef)(null);
19035
+ const [isUploadingImage, setIsUploadingImage] = (0, import_react42.useState)(false);
19036
+ const [imageUploadError, setImageUploadError] = (0, import_react42.useState)(null);
19037
+ const insertImageFiles = async (files) => {
19038
+ if (files.length === 0) return;
19039
+ setIsUploadingImage(true);
19040
+ setImageUploadError(null);
19041
+ for (const file of files) {
19042
+ if (!file.type.startsWith("image/")) continue;
19043
+ try {
19044
+ const src = imageInsertMode === "upload" && uploadImage ? await uploadImage(file) : await fileToDataUrl2(file);
19045
+ if (!src) continue;
19046
+ editor.chain().focus().setImage({ src, alt: file.name }).run();
19047
+ editor.commands.createParagraphNear();
19048
+ } catch {
19049
+ setImageUploadError(t("imageInput.uploadError"));
19050
+ }
19051
+ }
19052
+ setIsUploadingImage(false);
19053
+ };
15876
19054
  if (variant === "minimal") {
15877
19055
  return /* @__PURE__ */ (0, import_jsx_runtime71.jsxs)("div", { className: "flex items-center gap-1 p-2 border-b bg-muted/30", children: [
15878
19056
  /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(ToolbarButton, { onClick: () => editor.chain().focus().toggleBold().run(), active: editor.isActive("bold"), title: t("toolbar.bold"), children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(import_lucide_react36.Bold, { className: "w-4 h-4" }) }),
@@ -16162,7 +19340,34 @@ var EditorToolbar = ({ editor, variant }) => {
16162
19340
  },
16163
19341
  onCancel: () => setShowImageInput(false)
16164
19342
  }
16165
- ) : /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(DropdownMenuItem, { icon: import_lucide_react36.Link, label: t("imageInput.addFromUrl"), onClick: () => setShowImageInput(true) })
19343
+ ) : /* @__PURE__ */ (0, import_jsx_runtime71.jsxs)(import_jsx_runtime71.Fragment, { children: [
19344
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(DropdownMenuItem, { icon: import_lucide_react36.Link, label: t("imageInput.addFromUrl"), onClick: () => setShowImageInput(true) }),
19345
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
19346
+ DropdownMenuItem,
19347
+ {
19348
+ icon: import_lucide_react36.Upload,
19349
+ label: isUploadingImage ? t("imageInput.uploading") : t("imageInput.uploadTab"),
19350
+ disabled: isUploadingImage,
19351
+ onClick: () => fileInputRef.current?.click()
19352
+ }
19353
+ ),
19354
+ imageUploadError && /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(DropdownMenuItem, { label: imageUploadError, disabled: true, destructive: true }),
19355
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
19356
+ "input",
19357
+ {
19358
+ ref: fileInputRef,
19359
+ type: "file",
19360
+ accept: "image/*",
19361
+ multiple: true,
19362
+ className: "hidden",
19363
+ onChange: (e) => {
19364
+ const files = Array.from(e.target.files ?? []);
19365
+ e.target.value = "";
19366
+ void insertImageFiles(files);
19367
+ }
19368
+ }
19369
+ )
19370
+ ] })
16166
19371
  }
16167
19372
  ),
16168
19373
  /* @__PURE__ */ (0, import_jsx_runtime71.jsxs)(
@@ -16653,6 +19858,8 @@ var UEditor = ({
16653
19858
  onChange,
16654
19859
  onHtmlChange,
16655
19860
  onJsonChange,
19861
+ uploadImage,
19862
+ imageInsertMode = "base64",
16656
19863
  placeholder,
16657
19864
  className,
16658
19865
  editable = true,
@@ -16669,8 +19876,8 @@ var UEditor = ({
16669
19876
  const t = (0, import_next_intl6.useTranslations)("UEditor");
16670
19877
  const effectivePlaceholder = placeholder ?? t("placeholder");
16671
19878
  const extensions = (0, import_react44.useMemo)(
16672
- () => buildUEditorExtensions({ placeholder: effectivePlaceholder, maxCharacters }),
16673
- [effectivePlaceholder, maxCharacters]
19879
+ () => buildUEditorExtensions({ placeholder: effectivePlaceholder, maxCharacters, uploadImage, imageInsertMode }),
19880
+ [effectivePlaceholder, maxCharacters, uploadImage, imageInsertMode]
16674
19881
  );
16675
19882
  const editor = (0, import_react45.useEditor)({
16676
19883
  immediatelyRender: false,
@@ -16713,6 +19920,10 @@ var UEditor = ({
16713
19920
  "[&_pre]:!bg-[#1e1e1e]",
16714
19921
  "[&_pre]:!text-[#d4d4d4]",
16715
19922
  "[&_pre_code]:!bg-transparent",
19923
+ "[&_img.ProseMirror-selectednode]:ring-2",
19924
+ "[&_img.ProseMirror-selectednode]:ring-primary/60",
19925
+ "[&_img.ProseMirror-selectednode]:ring-offset-2",
19926
+ "[&_img.ProseMirror-selectednode]:ring-offset-background",
16716
19927
  "[&_hr]:border-t-2",
16717
19928
  "[&_hr]:border-primary/30",
16718
19929
  "[&_hr]:my-8",
@@ -16789,7 +20000,7 @@ var UEditor = ({
16789
20000
  className
16790
20001
  ),
16791
20002
  children: [
16792
- editable && showToolbar && /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(EditorToolbar, { editor, variant }),
20003
+ editable && showToolbar && /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(EditorToolbar, { editor, variant, uploadImage, imageInsertMode }),
16793
20004
  editable && showBubbleMenu && /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(CustomBubbleMenu, { editor }),
16794
20005
  editable && showFloatingMenu && /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(CustomFloatingMenu, { editor }),
16795
20006
  /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(