@nerd-bible/wordgard 0.5.3-beta3 → 0.5.3-beta5

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/editor.js CHANGED
@@ -2,47 +2,11 @@ import { GardState, GardSelection, TextblockMap, BidiSpan, Transaction } from 'w
2
2
  import { Attributes, Elt, Node, Leaf, parse, Slice, Plot, serialize, Pos, ChangeSet, ValidationError, Mark } from 'wordgard/doc';
3
3
  import { StyleModule } from 'style-mod';
4
4
  import { findClusterBreak } from '@marijn/find-cluster-break';
5
+ import { findAbove, PointSet, RangeSet } from 'wordgard/set';
5
6
  import { enter, insertLineBreak, selectAll, undo, redo, killToLineEnd, yankKilled, transposeChars, Command, deleteUnit, deleteWord, deleteToLineEnd, moveByUnit, moveByLine, moveByWord, moveToLineSide, moveToDocSide, moveByPage, moveToTextblockSide, setAlignment, toggleUnderline, toggleEmphasis, toggleStrong, deleteLine, insertText, setDirection, deleteSelection, Menu, findWrappable, wrapBlockRange, autoJoinBlocks } from 'wordgard/command';
6
7
  import { PhraseSet, phrases } from 'wordgard/phrases';
7
8
  import { history } from 'wordgard/history';
8
9
 
9
- function eqArray(a, b) {
10
- if (!a || !b)
11
- return a == b;
12
- if (a == b)
13
- return true;
14
- if (a.length != b.length)
15
- return false;
16
- for (let i = 0; i < a.length; i++)
17
- if (!a[i].eq(b[i]))
18
- return false;
19
- return true;
20
- }
21
- const exceptionSink = /*@__PURE__*/GardState.Facet.define();
22
- function logException(state, exception, context) {
23
- let handler = state.facet(exceptionSink);
24
- if (handler.length)
25
- handler[0](exception);
26
- else if (window.onerror)
27
- window.onerror(String(exception), context, undefined, undefined, exception);
28
- else if (context)
29
- console.error(context + ":", exception);
30
- else
31
- console.error(exception);
32
- }
33
- function findAbove(array, start, n) {
34
- let from = start, to = array.length;
35
- for (;;) {
36
- if (from == to)
37
- return from;
38
- let mid = (from + to) >> 1;
39
- if (array[mid] > n)
40
- to = mid;
41
- else
42
- from = mid + 1;
43
- }
44
- }
45
-
46
10
  function addUpdated(sections, updated) {
47
11
  let result = [];
48
12
  let j = 0, [uFrom, uTo] = updated.length ? [updated[j++], updated[j++]] : [1e9, 1e9];
@@ -126,20 +90,25 @@ function isEmpty(changes) {
126
90
  return changes.length == 0 || changes.length == 2 && changes[1] == -1;
127
91
  }
128
92
  function addRange(ranges, from, to) {
129
- if (!ranges.length || ranges[ranges.length - 1] < from) {
93
+ let last;
94
+ if (!ranges.length || (last = ranges[ranges.length - 1]) < from) {
130
95
  ranges.push(from, to);
131
- return;
132
96
  }
133
- let i = findAbove(ranges, 0, from) & -2, j = i;
134
- if (j && ranges[j - 1] == from) {
135
- j -= 2;
136
- from = ranges[j];
97
+ else if (last == from) {
98
+ ranges[ranges.length - 1] = to;
137
99
  }
138
- while (i < ranges.length && ranges[i] <= to) {
139
- from = Math.min(from, ranges[i++]);
140
- to = Math.max(to, ranges[i++]);
100
+ else {
101
+ let i = findAbove(ranges, 0, from) & -2, j = i;
102
+ if (j && ranges[j - 1] == from) {
103
+ j -= 2;
104
+ from = ranges[j];
105
+ }
106
+ while (i < ranges.length && ranges[i] <= to) {
107
+ from = Math.min(from, ranges[i++]);
108
+ to = Math.max(to, ranges[i++]);
109
+ }
110
+ ranges.splice(j, i - j, from, to);
141
111
  }
142
- ranges.splice(j, i - j, from, to);
143
112
  }
144
113
  function joinRanges(ranges) {
145
114
  if (ranges.length == 1)
@@ -327,6 +296,8 @@ const Decoration = /*@__PURE__*/(function (Decoration) {
327
296
  static source = GardState.Facet.define({
328
297
  combine: sources => sources.concat(nodeSelection)
329
298
  });
299
+ static set(source) { return PointSet.create(source); }
300
+ static none = PointSet.empty;
330
301
  }
331
302
  Decoration.Point = Point;
332
303
  class Range {
@@ -348,6 +319,8 @@ const Decoration = /*@__PURE__*/(function (Decoration) {
348
319
  return new AttributeRangeDecoration(attr, value, options);
349
320
  }
350
321
  static source = GardState.Facet.define();
322
+ static set(source) { return RangeSet.create(source); }
323
+ static none = RangeSet.empty;
351
324
  }
352
325
  Decoration.Range = Range;
353
326
  ;return Decoration})({});
@@ -506,194 +479,6 @@ function nodeSelection(state) {
506
479
  return PointSet.empty;
507
480
  }
508
481
  const none = [];
509
- class PointSet {
510
- values;
511
- positions;
512
- constructor(
513
- values,
514
- positions) {
515
- this.values = values;
516
- this.positions = positions;
517
- }
518
- get length() { return this.positions.length; }
519
- get size() { return this.positions.length ? this.positions[this.positions.length - 1] : 0; }
520
- map(changes, start = 0) {
521
- if (changes.empty)
522
- return this;
523
- let positions = this.positions.slice();
524
- let pos = start, i = 0, startB = start && changes.mapPos(start, -1);
525
- let deleted = [], deletions = 0;
526
- changes.iterGaps((fromA, toA, fromB, _toB, last) => {
527
- let off = fromB - fromA, end = last ? toA : toA - 1;
528
- if (end > pos) {
529
- let nextI = findAbove(positions, i, end - start);
530
- if (off)
531
- for (; i < nextI; i++)
532
- positions[i] += off;
533
- else
534
- i = nextI;
535
- pos = end;
536
- }
537
- }, (_fromA, toA) => {
538
- let nextI = findAbove(positions, i, toA + 1 + start);
539
- for (; i < nextI; i++) {
540
- let mapped = changes.mapPos(positions[i] + start, this.values[i].side < 0 ? -1 : 1, this.values[i].trackMode);
541
- if (mapped == null) {
542
- addDel(deleted, i);
543
- deletions++;
544
- }
545
- else
546
- positions[i] = mapped - startB;
547
- }
548
- pos = toA + 1;
549
- });
550
- if (!deletions)
551
- return new PointSet(this.values, positions);
552
- return new PointSet(applyDel(deleted, deletions, this.values), applyDel(deleted, deletions, positions));
553
- }
554
- merge(other, maskFrom, maskTo = maskFrom) {
555
- if (!this.length)
556
- return other;
557
- if (!other.length && maskFrom == null)
558
- return this;
559
- let posA = this.positions, posB = other.positions;
560
- let pos = new Array((maskFrom == null ? posA.length : 0) + posB.length), values = new Array(pos.length);
561
- for (let i = 0, a = 0, b = 0;;) {
562
- if (a < posA.length && (b == posB.length || (posA[a] - posB[b] || this.values[a].side - other.values[b].side) < 0)) {
563
- if (maskFrom == null || maskFrom > posA[a] || maskTo < posA[a]) {
564
- pos[i] = posA[a];
565
- values[i++] = this.values[a];
566
- }
567
- a++;
568
- }
569
- else if (b < posB.length) {
570
- pos[i] = posB[b];
571
- values[i++] = other.values[b++];
572
- }
573
- else {
574
- return new PointSet(values, pos);
575
- }
576
- }
577
- }
578
- compareRange(fromA, b, fromB, len, change) {
579
- let a = this, endB = fromB + len;
580
- if (a != b || fromA != fromB) {
581
- let iA = findAbove(a.positions, 0, fromA - 1), lA = a.positions.length;
582
- let iB = findAbove(b.positions, 0, fromB - 1), lB = b.positions.length;
583
- let off = fromB - fromA;
584
- let sameVal = a.values == b.values;
585
- for (;;) {
586
- let nextA = iA < lA ? a.positions[iA] + off : 1e9;
587
- let nextB = iB < lB ? b.positions[iB] : 1e9;
588
- let next = Math.min(nextA, nextB);
589
- if (next > endB)
590
- break;
591
- if (nextA == nextB) {
592
- if (!sameVal && !a.values[iA].eq(b.values[iB]))
593
- change(next, a.values[iA]);
594
- iA++;
595
- iB++;
596
- }
597
- else if (nextA < nextB) {
598
- change(nextA, a.values[iA++]);
599
- }
600
- else {
601
- change(nextB, b.values[iB++]);
602
- }
603
- }
604
- }
605
- }
606
- iter() {
607
- return new PointIterator(this);
608
- }
609
- at(pos) {
610
- let index = findAbove(this.positions, 0, pos - 1);
611
- return index < this.positions.length && this.positions[index] == pos ? this.values[index] : undefined;
612
- }
613
- static create(source) {
614
- if (typeof source != "function") {
615
- let array = source;
616
- source = add => { for (let [pos, value] of array)
617
- add(pos, value); };
618
- }
619
- let positions = [], values = [], curPos = -1, curVal;
620
- source((pos, value) => {
621
- if (curPos > pos || curPos == pos && curVal.side > value.side) {
622
- for (let i = positions.length;;) {
623
- positions[i] = positions[i - 1];
624
- values[i] = values[i - 1];
625
- --i;
626
- if (!i || (positions[i - 1] - pos || values[i - 1].side - value.side) <= 0) {
627
- positions[i] = pos;
628
- values[i] = value;
629
- break;
630
- }
631
- }
632
- }
633
- else {
634
- positions.push(pos);
635
- values.push(value);
636
- curPos = pos;
637
- curVal = value;
638
- }
639
- });
640
- return new PointSet(values, positions);
641
- }
642
- static empty = /*@__PURE__*/(() => new PointSet(none, none))();
643
- }
644
- class PointIterator {
645
- set;
646
- constructor(set) {
647
- this.set = set;
648
- this.fill(0);
649
- }
650
- get to() { return this.from; }
651
- fill(i) {
652
- this.i = i;
653
- if (i < this.set.positions.length) {
654
- this.from = this.set.positions[i];
655
- this.value = this.set.values[i];
656
- }
657
- else {
658
- this.from = 1e8;
659
- this.value = null;
660
- }
661
- }
662
- next() {
663
- if (this.value)
664
- this.fill(this.i + 1);
665
- }
666
- get side() {
667
- return this.value ? this.value.side : 1;
668
- }
669
- goto(pos, inclusive) {
670
- let i = findAbove(this.set.positions, 0, pos - 1);
671
- if (!inclusive) {
672
- while (i < this.set.values.length && this.set.values[i].side < 1000000000)
673
- i++;
674
- }
675
- this.fill(i);
676
- }
677
- }
678
- function addDel(deleted, i) {
679
- let last = deleted.length - 1;
680
- if (last >= 0 && deleted[last] == i)
681
- deleted[last] = i + 1;
682
- else
683
- deleted.push(i, i + 1);
684
- }
685
- function applyDel(deleted, deletions, array) {
686
- let result = new Array(array.length - deletions);
687
- for (let iA = 0, iR = 0, iD = 0;;) {
688
- let last = iD == deleted.length, from = last ? array.length : deleted[iD++];
689
- while (iA < from)
690
- result[iR++] = array[iA++];
691
- if (last)
692
- return result;
693
- let to = deleted[iD++];
694
- iA += to - from;
695
- }
696
- }
697
482
  function getDecoSet(state) {
698
483
  let set = { points: new Map, ranges: new Map };
699
484
  for (let src of state.facet(Decoration.Point.source))
@@ -702,169 +487,6 @@ function getDecoSet(state) {
702
487
  set.ranges.set(src, src(state));
703
488
  return set;
704
489
  }
705
- class RangeSet {
706
- values;
707
- from;
708
- to;
709
- constructor(
710
- values,
711
- from,
712
- to) {
713
- this.values = values;
714
- this.from = from;
715
- this.to = to;
716
- }
717
- get length() { return this.from.length; }
718
- get size() { return this.to.length ? this.to[this.to.length - 1] : 0; }
719
- map(changes, start = 0) {
720
- if (changes.empty || !this.length)
721
- return this;
722
- let from = this.from.slice(), to = this.to.slice();
723
- let pos = start, i = 0, startB = start && changes.mapPos(start, -1);
724
- let deleted = [], deletions = 0;
725
- changes.iterGaps((fromA, toA, fromB, _toB, last) => {
726
- let off = fromB - fromA, end = last ? toA : toA - 1;
727
- if (end > pos) {
728
- let nextI = findAbove(to, i, end - start);
729
- if (off)
730
- for (; i < nextI; i++) {
731
- from[i] += off;
732
- to[i] += off;
733
- }
734
- else
735
- i = nextI;
736
- pos = end;
737
- }
738
- }, (_fromA, toA) => {
739
- let nextI = findAbove(from, i, toA - start);
740
- for (; i < nextI; i++) {
741
- let value = this.values[i];
742
- let mappedFrom = changes.mapPos(from[i] + start, value.inclusiveStart ? -1 : 1);
743
- let mappedTo = changes.mapPos(to[i] + start, value.inclusiveEnd ? 1 : -1);
744
- if (mappedFrom >= mappedTo) {
745
- addDel(deleted, i);
746
- deletions++;
747
- }
748
- else {
749
- from[i] = mappedFrom - startB;
750
- to[i] = mappedTo - startB;
751
- }
752
- }
753
- pos = toA + 1;
754
- });
755
- if (!deletions)
756
- return new RangeSet(this.values, from, to);
757
- return new RangeSet(applyDel(deleted, deletions, this.values), applyDel(deleted, deletions, from), applyDel(deleted, deletions, to));
758
- }
759
- merge(other, maskFrom, maskTo = maskFrom) {
760
- if (!this.length)
761
- return other;
762
- if (!other.length && maskFrom == null)
763
- return this;
764
- let fromA = this.from, fromB = other.from;
765
- let from = new Array((maskFrom == null ? fromA.length : 0) + fromB.length);
766
- let to = new Array(from.length), values = new Array(from.length);
767
- for (let i = 0, a = 0, b = 0, at = 0;;) {
768
- if (a < fromA.length && (b == fromB.length || fromA[a] < fromB[b])) {
769
- if (maskFrom == null || maskFrom >= this.to[a] || maskTo <= this.from[a]) {
770
- if ((from[i] = fromA[a]) < at)
771
- throw new Error("Overlapping ranges");
772
- at = to[i] = this.to[a];
773
- values[i++] = this.values[a];
774
- }
775
- a++;
776
- }
777
- else if (b < fromB.length) {
778
- if ((from[i] = fromB[b]) < at)
779
- throw new Error("Overlapping ranges");
780
- at = to[i] = other.to[b];
781
- values[i++] = other.values[b++];
782
- }
783
- else {
784
- return new RangeSet(values, from, to);
785
- }
786
- }
787
- }
788
- iter() {
789
- return new RangeIterator(this);
790
- }
791
- compareRange(fromA, b, fromB, len, change) {
792
- let a = this, toB = fromB + len;
793
- if (a != b || fromA != fromB) {
794
- let iA = findAbove(a.to, 0, fromA - 1), lA = a.from.length;
795
- let iB = findAbove(b.to, 0, fromB - 1), lB = b.from.length;
796
- let off = fromB - fromA;
797
- let sameVals = a.values == b.values;
798
- for (;;) {
799
- let [startA, endA] = iA < lA ? [a.from[iA] + off, a.to[iA] + off] : [1e9, 1e9];
800
- let [startB, endB] = iB < lB ? [b.from[iB], b.to[iB]] : [1e9, 1e9];
801
- let start = Math.min(startA, startB);
802
- if (start > toB)
803
- break;
804
- if (startA == startB) {
805
- if (endA != endB || !sameVals && !a.values[iA].eq(b.values[iB]))
806
- change(start, Math.max(endA, endB));
807
- iA++;
808
- iB++;
809
- }
810
- else if (startA < startB) {
811
- change(startA, endA);
812
- iA++;
813
- }
814
- else {
815
- change(startB, endB);
816
- iB++;
817
- }
818
- }
819
- }
820
- }
821
- static create(source) {
822
- if (typeof source != "function") {
823
- let array = source;
824
- source = add => { for (let [from, to, value] of array)
825
- add(from, to, value); };
826
- }
827
- let from = [], to = [], values = [], curPos = -1;
828
- source((f, t, value) => {
829
- if (f >= t)
830
- throw new Error("Ranges cannot be empty");
831
- if (f < curPos)
832
- throw new Error("Ranges must be added in order and cannot overlap");
833
- from.push(f);
834
- to.push(t);
835
- curPos = t;
836
- values.push(value);
837
- });
838
- return new RangeSet(values, from, to);
839
- }
840
- static empty = /*@__PURE__*/(() => new RangeSet(none, none, none))();
841
- }
842
- class RangeIterator {
843
- set;
844
- constructor(set) {
845
- this.set = set;
846
- this.fill(0);
847
- }
848
- fill(i) {
849
- this.i = i;
850
- if (i < this.set.from.length) {
851
- this.from = this.set.from[i];
852
- this.to = this.set.to[i];
853
- this.value = this.set.values[i];
854
- }
855
- else {
856
- this.from = this.to = 1e8;
857
- this.value = null;
858
- }
859
- }
860
- next() {
861
- if (this.value)
862
- this.fill(this.i + 1);
863
- }
864
- goto(pos) {
865
- this.fill(findAbove(this.set.to, 0, pos));
866
- }
867
- }
868
490
  function compareDecoSet(setA, setB, cmp) {
869
491
  for (let [srcA, valA] of setA)
870
492
  cmp(valA, setB.get(srcA) || null);
@@ -963,43 +585,43 @@ function addAtomicityChanges(changes, prev, nodes) {
963
585
  }
964
586
  return added.length ? addUpdated(changes, added) : changes;
965
587
  }
966
- class HeapIterator {
967
- rangeHeap;
968
- pointHeap;
588
+ class SpanIterator {
589
+ ranges;
590
+ points;
969
591
  end;
970
592
  active = [];
593
+ activeEnd = [];
971
594
  from;
972
595
  to;
973
596
  point = null;
597
+ pointSource = null;
974
598
  done = false;
975
- constructor(rangeHeap, pointHeap, start, end) {
976
- this.rangeHeap = rangeHeap;
977
- this.pointHeap = pointHeap;
599
+ constructor(ranges, points, start, end) {
600
+ this.ranges = ranges;
601
+ this.points = points;
978
602
  this.end = end;
979
- for (let i = rangeHeap.length >> 1; i >= 0; i--)
980
- bubble(rangeHeap, i, cmpRangeFrom);
981
- for (let i = pointHeap.length >> 1; i >= 0; i--)
982
- bubble(pointHeap, i, cmpPoint);
983
603
  this.from = this.to = start;
984
604
  }
985
605
  next() {
986
606
  if (this.done)
987
607
  return this;
988
- if (this.point) {
989
- this.point.next();
990
- if (!this.point.value)
991
- popHeap(this.pointHeap, cmpPoint);
992
- else
993
- bubble(this.pointHeap, 0, cmpPoint);
608
+ if (this.point)
994
609
  this.point = null;
995
- }
996
- let { rangeHeap, pointHeap, active } = this;
610
+ let { ranges, points, active, activeEnd } = this;
997
611
  while (true) {
998
- let [startPos, startSide] = rangeHeap.length
999
- ? [rangeHeap[0].from, rangeHeap[0].value.inclusiveStart ? -1 : 1]
612
+ let [startPos, startSide] = ranges.value
613
+ ? [ranges.from, ranges.value.inclusiveStart ? -1 : 1]
1000
614
  : [1e9, 0];
1001
- let [endPos, endSide] = active.length ? [active[0].to, active[0].value.inclusiveEnd ? 1 : -1] : [1e9, 0];
1002
- let { from: pointPos, side: pointSide } = pointHeap.length ? pointHeap[0] : { from: 1e9, side: 1 };
615
+ let endPos = 1e9, endSide = 0, nextActive = -1;
616
+ for (let i = 0; i < active.length; i++) {
617
+ let pos = activeEnd[i], side = active[i].inclusiveEnd ? 1 : -1;
618
+ if ((pos - endPos || side - endSide) < 0) {
619
+ endPos = pos;
620
+ endSide = side;
621
+ nextActive = i;
622
+ }
623
+ }
624
+ let { pos: pointPos, side: pointSide } = points.value ? points : { pos: 1e9, side: 1 };
1003
625
  let nextPos = Math.min(startPos, endPos, pointPos);
1004
626
  if (this.to == this.end && nextPos > this.to) {
1005
627
  this.done = true;
@@ -1011,81 +633,32 @@ class HeapIterator {
1011
633
  break;
1012
634
  }
1013
635
  else if (pointPos == nextPos && (startPos > pointPos || pointSide < 0) && (endPos > pointPos || pointSide < 0)) {
1014
- this.point = this.pointHeap[0];
1015
- this.from = this.to = pointPos;
636
+ this.point = this.points.value;
637
+ this.pointSource = this.points.set;
638
+ this.from = this.to = this.points.pos;
639
+ this.points.next();
1016
640
  break;
1017
641
  }
1018
642
  else if ((startPos - endPos || startSide - endSide) < 0) {
1019
- let first = rangeHeap[0];
1020
- sink(active, active.push(first) - 1, cmpRangeTo);
1021
- popHeap(rangeHeap, cmpRangeFrom);
643
+ active.push(this.ranges.value);
644
+ activeEnd.push(this.ranges.to);
645
+ this.ranges.next();
1022
646
  }
1023
647
  else {
1024
- let first = active[0];
1025
- first.next();
1026
- if (first.value)
1027
- sink(rangeHeap, rangeHeap.push(first) - 1, cmpRangeFrom);
1028
- popHeap(active, cmpRangeTo);
648
+ active.splice(nextActive, 1);
649
+ activeEnd.splice(nextActive, 1);
1029
650
  }
1030
651
  }
1031
652
  return this;
1032
653
  }
1033
654
  }
1034
- function bubble(heap, index, cmp) {
1035
- for (let cur = heap[index];;) {
1036
- let childIndex = (index << 1) + 1;
1037
- if (childIndex >= heap.length)
1038
- break;
1039
- let child = heap[childIndex];
1040
- if (childIndex + 1 < heap.length && cmp(child, heap[childIndex + 1]) >= 0) {
1041
- child = heap[childIndex + 1];
1042
- childIndex++;
1043
- }
1044
- if (cmp(cur, child) < 0)
1045
- break;
1046
- heap[childIndex] = cur;
1047
- heap[index] = child;
1048
- index = childIndex;
1049
- }
1050
- }
1051
- function sink(heap, index, cmp) {
1052
- let elt = heap[index];
1053
- while (index > 0) {
1054
- let parent = (index - 1) >> 1;
1055
- if (cmp(heap[parent], elt) < 0)
1056
- break;
1057
- heap[index] = heap[parent];
1058
- heap[parent] = elt;
1059
- index = parent;
1060
- }
1061
- }
1062
- function popHeap(heap, cmp) {
1063
- let last = heap.pop();
1064
- if (heap.length) {
1065
- heap[0] = last;
1066
- bubble(heap, 0, cmp);
1067
- }
1068
- }
1069
- function cmpBool(a, b) {
1070
- return a ? (b ? 0 : 1) : (b ? -1 : 0);
1071
- }
1072
- function cmpRangeFrom(a, b) {
1073
- return a.from - b.from || cmpBool(b.value.inclusiveStart, a.value.inclusiveStart);
1074
- }
1075
- function cmpRangeTo(a, b) {
1076
- return a.to - b.to || cmpBool(a.value.inclusiveEnd, b.value.inclusiveEnd);
1077
- }
1078
- function cmpPoint(a, b) {
1079
- return a.from - b.from || a.side - b.side;
1080
- }
1081
655
  function nodeWrappers(schema, tag, active, atom) {
1082
656
  let wrappers;
1083
657
  for (let mark of tag.marks)
1084
658
  if (mark.type.element)
1085
659
  (wrappers || (wrappers = [])).push(mark);
1086
660
  if (active.length) {
1087
- for (let cur of active) {
1088
- let val = cur.value;
661
+ for (let val of active) {
1089
662
  if (val instanceof WrapperRangeDecoration && (tagScope(tag, atom) & val.scope) &&
1090
663
  (!val.query || schema.matchNode(tag.type, val.query)))
1091
664
  (wrappers || (wrappers = [])).push(val);
@@ -1119,8 +692,9 @@ class DecoIterator {
1119
692
  globalAttrs;
1120
693
  schema;
1121
694
  pos;
1122
- rangeIter = [];
1123
- pointIter = [];
695
+ rangeCursor;
696
+ pointSets;
697
+ pointCursor;
1124
698
  endWidgets;
1125
699
  constructor(state, decoSet) {
1126
700
  this.state = state;
@@ -1133,16 +707,9 @@ class DecoIterator {
1133
707
  this.globalAttrs = state.facet(tagAttribute);
1134
708
  this.pos = state.doc.resolve(0);
1135
709
  this.schema = state.schema;
1136
- for (let s of state.facet(Decoration.Range.source)) {
1137
- let set = decoSet.ranges.get(s);
1138
- if (set?.length)
1139
- this.rangeIter.push(set.iter());
1140
- }
1141
- for (let s of state.facet(Decoration.Point.source)) {
1142
- let set = decoSet.points.get(s);
1143
- if (set?.length)
1144
- this.pointIter.push(set.iter());
1145
- }
710
+ this.rangeCursor = RangeSet.cursor(state.facet(Decoration.Range.source).map(s => s(state)));
711
+ this.pointSets = state.facet(Decoration.Point.source).map(s => s(state));
712
+ this.pointCursor = PointSet.cursor(this.pointSets);
1146
713
  }
1147
714
  widgets(tag, place, walker) {
1148
715
  if (place == 2 && tag.type.isInline)
@@ -1163,11 +730,9 @@ class DecoIterator {
1163
730
  typeof tw.widget == "function");
1164
731
  }
1165
732
  walk(from, inclusiveStart, to, walker) {
1166
- for (let i of this.rangeIter)
1167
- i.goto(from);
1168
- for (let i of this.pointIter)
1169
- i.goto(from, inclusiveStart);
1170
- let iter = new HeapIterator(this.rangeIter.filter(i => i.value), this.pointIter.filter(i => i.value), from, to);
733
+ this.rangeCursor.goto(from);
734
+ this.pointCursor.goto(from, inclusiveStart ? -1e9 : 1000000000);
735
+ let iter = new SpanIterator(this.rangeCursor, this.pointCursor, from, to);
1171
736
  let pos = this.pos.advance(from - this.pos.pos), started = inclusiveStart;
1172
737
  let atomParent;
1173
738
  for (let p = pos.parent; p; p = p.parent)
@@ -1238,7 +803,7 @@ class DecoIterator {
1238
803
  iter.next();
1239
804
  }
1240
805
  else if (iter.point) {
1241
- let value = iter.point.value;
806
+ let value = iter.point;
1242
807
  if (value instanceof WidgetDecoration) {
1243
808
  walker.widget(value.widget, value.side);
1244
809
  }
@@ -1249,9 +814,9 @@ class DecoIterator {
1249
814
  pendingPos = pos.pos;
1250
815
  }
1251
816
  if (value instanceof ShapeDecoration &&
1252
- (!pendingShape || compareSetPrec(pendingShapeSet, iter.point.set, this.pointIter))) {
817
+ (!pendingShape || compareSetPrec(pendingShapeSet, iter.pointSource, this.pointSets))) {
1253
818
  pendingShape = value;
1254
- pendingShapeSet = iter.point.set;
819
+ pendingShapeSet = iter.pointSource;
1255
820
  }
1256
821
  else {
1257
822
  pendingDeco.push(value);
@@ -1299,8 +864,7 @@ class DecoIterator {
1299
864
  if (tag.type == type) {
1300
865
  shape = target && shape instanceof Elt ? shape.wrap(elt, target) : elt.fill([shape]);
1301
866
  }
1302
- for (let iter of active) {
1303
- let deco = iter.value;
867
+ for (let deco of active) {
1304
868
  if (deco instanceof AttributeRangeDecoration && (scope & deco.scope) &&
1305
869
  (!deco.query || this.schema.matchNode(tag.type, deco.query)))
1306
870
  Attributes.push(add || (add = []), deco.attribute, deco.value);
@@ -1316,15 +880,40 @@ class DecoIterator {
1316
880
  }
1317
881
  function compareSetPrec(setA, setB, array) {
1318
882
  if (setA != setB)
1319
- for (let i of array) {
1320
- if (i.set == setA)
883
+ for (let set of array) {
884
+ if (set == setA)
1321
885
  return -1;
1322
- if (i.set == setB)
886
+ if (set == setB)
1323
887
  return 1;
1324
888
  }
1325
889
  return 0;
1326
890
  }
1327
891
 
892
+ function eqArray(a, b) {
893
+ if (!a || !b)
894
+ return a == b;
895
+ if (a == b)
896
+ return true;
897
+ if (a.length != b.length)
898
+ return false;
899
+ for (let i = 0; i < a.length; i++)
900
+ if (!a[i].eq(b[i]))
901
+ return false;
902
+ return true;
903
+ }
904
+ const exceptionSink = /*@__PURE__*/GardState.Facet.define();
905
+ function logException(state, exception, context) {
906
+ let handler = state.facet(exceptionSink);
907
+ if (handler.length)
908
+ handler[0](exception);
909
+ else if (window.onerror)
910
+ window.onerror(String(exception), context, undefined, undefined, exception);
911
+ else if (context)
912
+ console.error(context + ":", exception);
913
+ else
914
+ console.error(exception);
915
+ }
916
+
1328
917
  function getSelection(root) {
1329
918
  let target;
1330
919
  if (root.nodeType == 11) { target = root.getSelection ? root : root.ownerDocument;
@@ -1362,8 +951,8 @@ function rmDOM(dom) {
1362
951
  }
1363
952
  function isBlockElement(node) {
1364
953
  let tile = node.wgTile;
1365
- if (tile?.node)
1366
- return tile.node.isBlock;
954
+ if (tile?.tag)
955
+ return tile.tag.type.isBlock;
1367
956
  return node.nodeType == 1 && /^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(node.nodeName);
1368
957
  }
1369
958
  function isBlocking(node) {
@@ -1674,7 +1263,7 @@ class Tile {
1674
1263
  get isSpanning() { return false; }
1675
1264
  get isComposition() { return (this.flags & 128) > 0; }
1676
1265
  get isPoint() { return (this.flags & 16) > 0; }
1677
- get node() { return null; }
1266
+ get tag() { return null; }
1678
1267
  posBeforeChild(child, ownStart = this.posAtStart) {
1679
1268
  for (let i = 0, pos = ownStart;; i++) {
1680
1269
  let cur = this.children[i];
@@ -1705,7 +1294,7 @@ class Tile {
1705
1294
  }
1706
1295
  get nodeParent() {
1707
1296
  let tile = this;
1708
- while (!tile.node)
1297
+ while (!tile.tag)
1709
1298
  tile = tile.parent;
1710
1299
  return tile;
1711
1300
  }
@@ -1723,7 +1312,7 @@ class Tile {
1723
1312
  }
1724
1313
  nearestNode() {
1725
1314
  let tile = this;
1726
- while (!tile.node)
1315
+ while (!tile.tag)
1727
1316
  tile = tile.parent;
1728
1317
  return tile;
1729
1318
  }
@@ -1791,15 +1380,15 @@ class CompositeTile extends Tile {
1791
1380
  next = rmDOM(next);
1792
1381
  }
1793
1382
  posAtCoordsInner(start, state, x, y, textblock, orientation) {
1794
- let { node } = this, outerOrientation = orientation;
1795
- if (node && node.isPlot) {
1796
- orientation = node.type.orientation == "row" ? 0 : 1;
1797
- if (node.isTextblock)
1798
- textblock = TextblockMap.get(state, start, node);
1799
- else if (node.isBlock)
1383
+ let { tag } = this, outerOrientation = orientation;
1384
+ if (tag && tag.isPlot) {
1385
+ orientation = tag.type.orientation == "row" ? 0 : 1;
1386
+ if (tag.isTextblock)
1387
+ textblock = TextblockMap.get(state, start, start ? state.doc.plotAt(start - 1) : state.doc);
1388
+ else if (tag.type.isBlock)
1800
1389
  textblock = null;
1801
1390
  }
1802
- else if (node && node.isText) {
1391
+ else if (tag && tag.isText) {
1803
1392
  orientation = 0;
1804
1393
  }
1805
1394
  let result = this.isAtom || !this.children.length ? null
@@ -1809,7 +1398,7 @@ class CompositeTile extends Tile {
1809
1398
  return result;
1810
1399
  let rect = this.dom.getBoundingClientRect();
1811
1400
  let after = outerOrientation == 0 ? x > (rect.left + rect.right) / 2 : y > (rect.top + rect.bottom) / 2;
1812
- let target = this.node && this.node.type.isSelectable &&
1401
+ let target = this.tag && this.tag.type.isSelectable &&
1813
1402
  x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom ? start : null;
1814
1403
  return CoordPos.create(start + (after ? this.length - 2 * this.boundary : 0), after ? -1 : 1, target);
1815
1404
  }
@@ -1836,7 +1425,7 @@ class CompositeTile extends Tile {
1836
1425
  let pos = this.posBeforeChild(closest, start);
1837
1426
  if (closest.dom.nodeName == "BR")
1838
1427
  return CoordPos.create(pos, 1);
1839
- if (closest.node && closest.node.isPlot && closest.node.isInline) {
1428
+ if (closest.tag && closest.tag.isPlot && closest.tag.type.isInline) {
1840
1429
  if (x > rect.right)
1841
1430
  return CoordPos.create(pos + closest.length, -1);
1842
1431
  if (x < rect.left)
@@ -1922,7 +1511,7 @@ class DocTile extends CompositeTile {
1922
1511
  .updateRanges(state, getDecoSet(state), [0, state.doc.length], wg);
1923
1512
  }
1924
1513
  get isDoc() { return true; }
1925
- get node() { return this.state.doc; }
1514
+ get tag() { return this.state.doc.tag; }
1926
1515
  update(state, changes, wg, composition) {
1927
1516
  let decoSet = getDecoSet(state);
1928
1517
  let changed = findChangedRanges(this.state, this.decoSet, state, decoSet, changes);
@@ -1976,7 +1565,7 @@ class DocTile extends CompositeTile {
1976
1565
  nearest(dom, requireNode = false) {
1977
1566
  for (let cur = dom; cur; cur = cur.parentNode) {
1978
1567
  let elt = cur.wgTile;
1979
- if (elt && (!requireNode || elt.node) && this.owns(elt))
1568
+ if (elt && (!requireNode || elt.tag) && this.owns(elt))
1980
1569
  return elt;
1981
1570
  }
1982
1571
  return null;
@@ -1997,7 +1586,7 @@ class DocTile extends CompositeTile {
1997
1586
  for (let ch of parent.children) {
1998
1587
  let end = off + ch.length;
1999
1588
  if (pos < end) {
2000
- if (off == pos && ch.node || ch instanceof TextTile)
1589
+ if (off == pos && ch.tag || ch instanceof TextTile)
2001
1590
  return ch;
2002
1591
  parent = ch;
2003
1592
  off += ch.boundary;
@@ -2129,7 +1718,7 @@ class DocTile extends CompositeTile {
2129
1718
  dom = dom.parentNode;
2130
1719
  domBefore = dom.previousSibling;
2131
1720
  }
2132
- if (elt.node && elt.node.isInline && elt.node.isPlot && (!domBefore || !domBefore.nextSibling))
1721
+ if (elt.tag && elt.tag.type.isInline && elt.tag.isPlot && (!domBefore || !domBefore.nextSibling))
2133
1722
  return domBefore ? elt.posAfter : elt.posBefore;
2134
1723
  while (domBefore && !((eltBefore = domBefore.wgTile) && eltBefore.parent == elt))
2135
1724
  domBefore = domBefore.previousSibling;
@@ -2162,18 +1751,18 @@ function textTileRect(tile, offset) {
2162
1751
  }
2163
1752
  class EltTile extends CompositeTile {
2164
1753
  elt;
2165
- _node;
2166
- constructor(elt, _node, flags, length, dom) {
1754
+ _tag;
1755
+ constructor(elt, _tag, flags, length, dom) {
2167
1756
  super(dom, flags);
2168
1757
  this.elt = elt;
2169
- this._node = _node;
1758
+ this._tag = _tag;
2170
1759
  this.length = length;
2171
1760
  }
2172
1761
  get isSpanning() { return (this.flags & 4) > 0; }
2173
- get isNodeOuter() { return !!this.node; }
2174
- get isAtom() { return !!this._node && (this.flags & 512) > 0; }
2175
- get boundary() { return this._node && !(this.flags & 512) ? 1 : 0; }
2176
- get node() { return this._node; }
1762
+ get isNodeOuter() { return !!this.tag; }
1763
+ get isAtom() { return !!this._tag && (this.flags & 512) > 0; }
1764
+ get boundary() { return this._tag && !(this.flags & 512) ? 1 : 0; }
1765
+ get tag() { return this._tag; }
2177
1766
  get contentTile() {
2178
1767
  if (!(this.flags & 1024))
2179
1768
  return null;
@@ -2182,7 +1771,7 @@ class EltTile extends CompositeTile {
2182
1771
  return ch.contentTile;
2183
1772
  return this;
2184
1773
  }
2185
- static of(elt, node, flags, length, dom) {
1774
+ static of(elt, tag, flags, length, dom) {
2186
1775
  if (elt.hasContent) {
2187
1776
  flags |= 1024;
2188
1777
  if (elt.children.length > 1) {
@@ -2191,7 +1780,7 @@ class EltTile extends CompositeTile {
2191
1780
  flags |= 4096;
2192
1781
  }
2193
1782
  }
2194
- return new EltTile(elt, node, flags, length, dom || elt.outerDOM());
1783
+ return new EltTile(elt, tag, flags, length, dom || elt.outerDOM());
2195
1784
  }
2196
1785
  }
2197
1786
  function setUneditable(dom) {
@@ -2205,16 +1794,16 @@ function setUneditable(dom) {
2205
1794
  }
2206
1795
  class WidgetTile extends Tile {
2207
1796
  widget;
2208
- _node;
2209
- constructor(widget, _node, flags, dom, length = 0) {
1797
+ _tag;
1798
+ constructor(widget, _tag, flags, dom, length = 0) {
2210
1799
  super(dom, flags);
2211
1800
  this.widget = widget;
2212
- this._node = _node;
1801
+ this._tag = _tag;
2213
1802
  this.length = length;
2214
1803
  }
2215
- get isNodeOuter() { return !!this._node; }
1804
+ get isNodeOuter() { return !!this._tag; }
2216
1805
  get isAtom() { return true; }
2217
- get node() { return this._node; }
1806
+ get tag() { return this._tag; }
2218
1807
  get children() { return noChildren; }
2219
1808
  ignoreEvent(event) { return !this.widget.type.propagateEvent(event); }
2220
1809
  get ignoreMutations() { return !this.widget.type.editable; }
@@ -2231,7 +1820,7 @@ class WidgetTile extends Tile {
2231
1820
  ? JSON.stringify(this.widget.value) : super.toString();
2232
1821
  }
2233
1822
  posAtCoordsInner(start, state, x, y, textblock, orientation) {
2234
- if (!this.node)
1823
+ if (!this.tag)
2235
1824
  return CoordPos.create(start, 1);
2236
1825
  let rect = this.dom.nodeType == 1 ? this.dom.getBoundingClientRect()
2237
1826
  : textRange(this.dom, 0, this.length).getBoundingClientRect();
@@ -2386,7 +1975,7 @@ class TilePointer {
2386
1975
  let { index, tile, parent } = this;
2387
1976
  for (;;) {
2388
1977
  if (!index) {
2389
- if (!parent || (tile instanceof EltTile ? tile.node : !(tile instanceof TextTile)))
1978
+ if (!parent || (tile instanceof EltTile ? tile.tag : !(tile instanceof TextTile)))
2390
1979
  break;
2391
1980
  ({ index, tile, parent } = parent);
2392
1981
  }
@@ -2431,7 +2020,7 @@ class ContentUpdate {
2431
2020
  }
2432
2021
  else {
2433
2022
  this.reused.set(tile, 2);
2434
- let inner = EltTile.of(tile.elt, tile.node, tile.flags, tile.boundary * 2, tile.dom);
2023
+ let inner = EltTile.of(tile.elt, tile.tag, tile.flags, tile.boundary * 2, tile.dom);
2435
2024
  this.new.addChild(inner);
2436
2025
  this.new = inner;
2437
2026
  }
@@ -2467,17 +2056,17 @@ class ContentUpdate {
2467
2056
  for (let w = this.new; w && w.isWrapper; w = w.parent)
2468
2057
  wrappers++;
2469
2058
  let shape = tile instanceof EltTile ? tile.elt : tile instanceof WidgetTile ? tile.widget : null;
2470
- if (!shape || !tile.node)
2059
+ if (!shape || !tile.tag)
2471
2060
  throw new Error("Unexpected atom tile");
2472
- this.partialNode = { node: tile.node, reuse: tile, shape, wrappers };
2061
+ this.partialNode = { tag: tile.tag, length: to - from, reuse: tile, shape, wrappers };
2473
2062
  }
2474
2063
  else {
2475
2064
  if (!this.partialNode)
2476
2065
  throw new Error("Missing partial node");
2477
2066
  if (to == tile.length) {
2478
- let { node, shape, reuse } = this.partialNode;
2067
+ let { tag, length, shape, reuse } = this.partialNode;
2479
2068
  this.partialNode = null;
2480
- this.new.addChild(this.buildNodeShape(node, shape, reuse));
2069
+ this.new.addChild(this.buildNodeShape(tag, length + (to - from), shape, reuse));
2481
2070
  }
2482
2071
  }
2483
2072
  }
@@ -2512,13 +2101,13 @@ class ContentUpdate {
2512
2101
  index++;
2513
2102
  }
2514
2103
  else {
2515
- if (tile.node) {
2516
- while (!nw.node && nw.parent)
2104
+ if (tile.tag) {
2105
+ while (!nw.tag && nw.parent)
2517
2106
  nw = nw.parent;
2518
2107
  if (!nw.parent)
2519
2108
  break;
2520
- if (!nw.node.tag.eq(tile.node.tag) &&
2521
- (this.deco.hasEndWidget(tile.node.type) || this.deco.hasEndWidget(nw.node.type)))
2109
+ if (!nw.tag.eq(tile.tag) &&
2110
+ (this.deco.hasEndWidget(tile.tag.type) || this.deco.hasEndWidget(nw.tag.type)))
2522
2111
  cut.push(pos);
2523
2112
  nw = nw.parent;
2524
2113
  if (!nw)
@@ -2611,7 +2200,7 @@ class ContentUpdate {
2611
2200
  this.deco.walk(start, includeStart, end, {
2612
2201
  enter: (node, elt, wrappers) => {
2613
2202
  this.openWrappers(wrappers, reuse);
2614
- let tile = this.buildNodeShape(node, elt, reuse ? this.old.tileAfter() : null);
2203
+ let tile = this.buildNodeShape(node.tag, node.length, elt, reuse ? this.old.tileAfter() : null);
2615
2204
  this.new.addChild(tile);
2616
2205
  this.new = tile.contentTile;
2617
2206
  if (!this.new)
@@ -2649,14 +2238,14 @@ class ContentUpdate {
2649
2238
  }
2650
2239
  }
2651
2240
  else if (partial != null) {
2652
- this.partialNode = { node, shape, wrappers: wrapCount, reuse: reuse ? this.old.tileAfter() : null };
2241
+ this.partialNode = { tag: node.tag, length: partial, shape, wrappers: wrapCount, reuse: reuse ? this.old.tileAfter() : null };
2653
2242
  if (reuse)
2654
2243
  this.old = this.old.walk(partial, 1);
2655
2244
  this.posB += partial;
2656
2245
  return;
2657
2246
  }
2658
2247
  else {
2659
- this.new.addChild(this.buildNodeShape(node, shape, reuse ? this.old.tileAfter() : null));
2248
+ this.new.addChild(this.buildNodeShape(node.tag, node.length, shape, reuse ? this.old.tileAfter() : null));
2660
2249
  }
2661
2250
  for (let i = 0; i < wrapCount; i++)
2662
2251
  this.up();
@@ -2668,13 +2257,13 @@ class ContentUpdate {
2668
2257
  if (!this.partialNode)
2669
2258
  throw new Error("Continuing unknown partial node");
2670
2259
  this.posB += length;
2671
- this.partialNode.node = node;
2260
+ this.partialNode.tag = node.tag;
2672
2261
  if (reuse)
2673
2262
  this.old = this.old.walk(length, 1);
2674
2263
  if (done) {
2675
- let { node, shape, wrappers, reuse } = this.partialNode;
2264
+ let { tag, shape, wrappers, reuse } = this.partialNode;
2676
2265
  this.partialNode = null;
2677
- this.new.addChild(this.buildNodeShape(node, shape, reuse));
2266
+ this.new.addChild(this.buildNodeShape(tag, node.length, shape, reuse));
2678
2267
  for (let i = 0; i < wrappers; i++)
2679
2268
  this.up();
2680
2269
  }
@@ -2724,7 +2313,7 @@ class ContentUpdate {
2724
2313
  }
2725
2314
  return null;
2726
2315
  }
2727
- buildNodeShape(node, shape, reuse, inEditable = true, afterContent = 0) {
2316
+ buildNodeShape(tag, length, shape, reuse, inEditable = true, afterContent = 0) {
2728
2317
  if (shape instanceof Elt) {
2729
2318
  if (inEditable && !shape.hasContent) {
2730
2319
  if (Attributes.get(shape.attrs, "contenteditable") == null && !/^(br|hr|img|input|wbr)$/i.test(shape.tagName))
@@ -2740,9 +2329,9 @@ class ContentUpdate {
2740
2329
  else if (!strict)
2741
2330
  updateAttributes(dom, reusable.elt.attrs, shape.attrs);
2742
2331
  }
2743
- let flags = (node ? (shape.hasContent ? 0 : 512)
2332
+ let flags = (tag ? (shape.hasContent ? 0 : 512)
2744
2333
  : 1 | (shape.hasContent ? 0 : 16)) | afterContent;
2745
- let tile = EltTile.of(shape, node, flags, node ? node.length : 0, dom);
2334
+ let tile = EltTile.of(shape, tag, flags, tag ? length : 0, dom);
2746
2335
  let afterContentInner = 0;
2747
2336
  for (let ch of shape.children) {
2748
2337
  if (ch === 0) {
@@ -2750,7 +2339,7 @@ class ContentUpdate {
2750
2339
  tile.flags |= 2;
2751
2340
  }
2752
2341
  else {
2753
- tile.addChild(this.buildNodeShape(null, typeof ch == "string" ? Widget.text.of(ch) : ch, reusable ? reusable.children : reuse, inEditable, afterContentInner));
2342
+ tile.addChild(this.buildNodeShape(null, 0, typeof ch == "string" ? Widget.text.of(ch) : ch, reusable ? reusable.children : reuse, inEditable, afterContentInner));
2754
2343
  }
2755
2344
  }
2756
2345
  return tile;
@@ -2766,8 +2355,8 @@ class ContentUpdate {
2766
2355
  }
2767
2356
  if (inEditable && !shape.type.editable)
2768
2357
  setUneditable(dom);
2769
- let flags = (node ? 512 : 16 | 1) | afterContent;
2770
- let tile = new WidgetTile(shape, node, flags, dom, node ? node.length : 0);
2358
+ let flags = (tag ? 512 : 16 | 1) | afterContent;
2359
+ let tile = new WidgetTile(shape, tag, flags, dom, tag ? length : 0);
2771
2360
  if (shape.type.connect)
2772
2361
  this.toConnect.push(tile);
2773
2362
  return tile;
@@ -2779,8 +2368,8 @@ class ContentUpdate {
2779
2368
  return;
2780
2369
  while (tile.isNodeInner)
2781
2370
  tile = tile.parent;
2782
- let node = tile.node;
2783
- if (!node || !node.isPlot || !(node.isTextblock || node.isInline))
2371
+ let tag = tile.tag;
2372
+ if (!tag || !tag.isPlot || !(tag.isTextblock || tag.type.isInline))
2784
2373
  return;
2785
2374
  let hasHack = -1, needsHack = true;
2786
2375
  for (let parent = this.new, i = parent.children.length;;) {
@@ -2963,9 +2552,9 @@ function coordsAtPos(wg, pos, assoc) {
2963
2552
  return new Coords(tile, flattenV(singleRect(textRange(tile.dom, from, to), side, true), (side < 0) == ltrAt(wg.state, pos, assoc)));
2964
2553
  }
2965
2554
  let tagTile = tile;
2966
- while (!tagTile.node)
2555
+ while (!tagTile.tag)
2967
2556
  tagTile = tagTile.parent;
2968
- let horizontal = tagTile.node.isPlot && tagTile.node.type.orientation == "column";
2557
+ let horizontal = tagTile.tag.isPlot && tagTile.tag.type.orientation == "column";
2969
2558
  if (tile instanceof WidgetTile) {
2970
2559
  let after = pos > tilePos + tile.length / 2;
2971
2560
  if (tile.widget.type.inFlow) {
@@ -5416,7 +5005,10 @@ class Wordgard {
5416
5005
  }
5417
5006
  nodeFromDOM(node) {
5418
5007
  let tile = this.docTile.nearest(node, true);
5419
- return tile && tile != this.docTile ? { pos: tile.posBefore, node: tile.node } : null;
5008
+ if (!tile || tile == this.docTile)
5009
+ return null;
5010
+ let pos = tile.posBefore, n = this.state.doc.nodeAt(pos);
5011
+ return n && { pos, node: n };
5420
5012
  }
5421
5013
  posAtCoords(coords) {
5422
5014
  let elt = (this.root.elementFromPoint ? this.root : this.dom.ownerDocument)
@@ -7424,11 +7016,11 @@ function showPlaceholder(state) {
7424
7016
  else if (state.doc.length == 2 && state.doc.firstChild.isPlot)
7425
7017
  pos = 1;
7426
7018
  else
7427
- return PointSet.empty;
7019
+ return Decoration.Point.none;
7428
7020
  let shape = state.facet(placeholderShape);
7429
7021
  if (!shape.length)
7430
- return PointSet.empty;
7431
- return PointSet.create([[pos, Decoration.Point.widget(placeholderWidget.of(shape[0]), { side: 1 })]]);
7022
+ return Decoration.Point.none;
7023
+ return Decoration.Point.set([[pos, Decoration.Point.widget(placeholderWidget.of(shape[0]), { side: 1 })]]);
7432
7024
  }
7433
7025
  const placeholderField = /*@__PURE__*/GardState.Field.define({
7434
7026
  create(state) {
@@ -7532,4 +7124,4 @@ function dropCursor() {
7532
7124
  return [dropCursorPos, drawDropCursor];
7533
7125
  }
7534
7126
 
7535
- export { Decoration, Dialog, InputRule, KeyBinding, Panel, PointSet, RangeSet, Tooltip, Widget, Wordgard, dropCursor, menuBar, placeholder };
7127
+ export { Decoration, Dialog, InputRule, KeyBinding, Panel, Tooltip, Widget, Wordgard, dropCursor, menuBar, placeholder };