prosemirror-view 1.21.0 → 1.23.2
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/CHANGELOG.md +32 -0
- package/dist/index.es.js +69 -19
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +69 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/clipboard.js +7 -1
- package/src/decoration.js +8 -0
- package/src/index.js +9 -1
- package/src/viewdesc.js +43 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
## 1.23.2 (2021-11-19)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Avoid some unnecessary node redraws when marks are present in sibling nodes.
|
|
6
|
+
|
|
7
|
+
## 1.23.1 (2021-11-15)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Restore accidentally reduced lookahead distance in view updating algorithm.
|
|
12
|
+
|
|
13
|
+
## 1.23.0 (2021-11-11)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
When parsing clipboard content, ignore trailing BR nodes that look like they might be there as a contenteditable kludge.
|
|
18
|
+
|
|
19
|
+
### New features
|
|
20
|
+
|
|
21
|
+
`EditorView` now exposes an `isDestroyed` property that can be used to test if the view has been destroyed.
|
|
22
|
+
|
|
23
|
+
## 1.22.0 (2021-11-08)
|
|
24
|
+
|
|
25
|
+
### Bug fixes
|
|
26
|
+
|
|
27
|
+
Fix an issue where some types of node decoration changes could cause an unnecessary cascade of node redraws.
|
|
28
|
+
|
|
29
|
+
### New features
|
|
30
|
+
|
|
31
|
+
Widget decorations now accept a `destroy` option, which will be called when the widget is removed from the view.
|
|
32
|
+
|
|
1
33
|
## 1.21.0 (2021-10-29)
|
|
2
34
|
|
|
3
35
|
### Bug fixes
|
package/dist/index.es.js
CHANGED
|
@@ -1121,6 +1121,11 @@ var WidgetViewDesc = /*@__PURE__*/(function (ViewDesc) {
|
|
|
1121
1121
|
return mutation.type != "selection" || this.widget.spec.ignoreSelection
|
|
1122
1122
|
};
|
|
1123
1123
|
|
|
1124
|
+
WidgetViewDesc.prototype.destroy = function destroy () {
|
|
1125
|
+
this.widget.type.destroy(this.dom);
|
|
1126
|
+
ViewDesc.prototype.destroy.call(this);
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1124
1129
|
prototypeAccessors$1.domAtom.get = function () { return true };
|
|
1125
1130
|
|
|
1126
1131
|
Object.defineProperties( WidgetViewDesc.prototype, prototypeAccessors$1 );
|
|
@@ -1696,6 +1701,8 @@ function patchAttributes(dom, prev, cur) {
|
|
|
1696
1701
|
{ dom.classList.remove(prevList[i]); } }
|
|
1697
1702
|
for (var i$1 = 0; i$1 < curList.length; i$1++) { if (prevList.indexOf(curList[i$1]) == -1)
|
|
1698
1703
|
{ dom.classList.add(curList[i$1]); } }
|
|
1704
|
+
if (dom.classList.length == 0)
|
|
1705
|
+
{ dom.removeAttribute("class"); }
|
|
1699
1706
|
}
|
|
1700
1707
|
if (prev.style != cur.style) {
|
|
1701
1708
|
if (prev.style) {
|
|
@@ -1740,7 +1747,7 @@ var ViewTreeUpdater = function ViewTreeUpdater(top, lockedNode) {
|
|
|
1740
1747
|
// Tracks whether anything was changed
|
|
1741
1748
|
this.changed = false;
|
|
1742
1749
|
|
|
1743
|
-
this.preMatch = preMatch(top.node.content, top
|
|
1750
|
+
this.preMatch = preMatch(top.node.content, top);
|
|
1744
1751
|
};
|
|
1745
1752
|
|
|
1746
1753
|
// Destroy and remove the children between the given indices in
|
|
@@ -1801,17 +1808,16 @@ ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, vie
|
|
|
1801
1808
|
// Try to find a node desc matching the given data. Skip over it and
|
|
1802
1809
|
// return true when successful.
|
|
1803
1810
|
ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) {
|
|
1804
|
-
var
|
|
1805
|
-
if (index >= this.preMatch.index
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
} }
|
|
1811
|
+
var found = -1, targetDesc;
|
|
1812
|
+
if (index >= this.preMatch.index &&
|
|
1813
|
+
(targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top &&
|
|
1814
|
+
targetDesc.matchesNode(node, outerDeco, innerDeco)) {
|
|
1815
|
+
found = this.top.children.indexOf(targetDesc, this.index);
|
|
1810
1816
|
} else {
|
|
1811
|
-
for (var i
|
|
1812
|
-
var child = children[i
|
|
1817
|
+
for (var i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) {
|
|
1818
|
+
var child = this.top.children[i];
|
|
1813
1819
|
if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) {
|
|
1814
|
-
found = i
|
|
1820
|
+
found = i;
|
|
1815
1821
|
break
|
|
1816
1822
|
}
|
|
1817
1823
|
}
|
|
@@ -1920,22 +1926,44 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
|
|
|
1920
1926
|
}
|
|
1921
1927
|
};
|
|
1922
1928
|
|
|
1923
|
-
// : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number
|
|
1929
|
+
// : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>, matches: ViewDesc[]}
|
|
1924
1930
|
// Iterate from the end of the fragment and array of descs to find
|
|
1925
1931
|
// directly matching ones, in order to avoid overeagerly reusing those
|
|
1926
1932
|
// for other nodes. Returns the fragment index of the first node that
|
|
1927
1933
|
// is part of the sequence of matched nodes at the end of the
|
|
1928
1934
|
// fragment.
|
|
1929
|
-
function preMatch(frag,
|
|
1930
|
-
var
|
|
1931
|
-
|
|
1932
|
-
|
|
1935
|
+
function preMatch(frag, parentDesc) {
|
|
1936
|
+
var curDesc = parentDesc, descI = curDesc.children.length;
|
|
1937
|
+
var fI = frag.childCount, matched = new Map, matches = [];
|
|
1938
|
+
outer: while (fI > 0) {
|
|
1939
|
+
var desc = (void 0);
|
|
1940
|
+
for (;;) {
|
|
1941
|
+
if (descI) {
|
|
1942
|
+
var next = curDesc.children[descI - 1];
|
|
1943
|
+
if (next instanceof MarkViewDesc) {
|
|
1944
|
+
curDesc = next;
|
|
1945
|
+
descI = next.children.length;
|
|
1946
|
+
} else {
|
|
1947
|
+
desc = next;
|
|
1948
|
+
descI--;
|
|
1949
|
+
break
|
|
1950
|
+
}
|
|
1951
|
+
} else if (curDesc == parentDesc) {
|
|
1952
|
+
break outer
|
|
1953
|
+
} else {
|
|
1954
|
+
// FIXME
|
|
1955
|
+
descI = curDesc.parent.children.indexOf(curDesc);
|
|
1956
|
+
curDesc = curDesc.parent;
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
var node = desc.node;
|
|
1933
1960
|
if (!node) { continue }
|
|
1934
1961
|
if (node != frag.child(fI - 1)) { break }
|
|
1935
1962
|
--fI;
|
|
1936
1963
|
matched.set(desc, fI);
|
|
1964
|
+
matches.push(desc);
|
|
1937
1965
|
}
|
|
1938
|
-
return {index: fI, matched: matched}
|
|
1966
|
+
return {index: fI, matched: matched, matches: matches.reverse()}
|
|
1939
1967
|
}
|
|
1940
1968
|
|
|
1941
1969
|
function compareSide(a, b) { return a.type.side - b.type.side }
|
|
@@ -2966,7 +2994,13 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2966
2994
|
var sliceData = contextNode && /^(\d+) (\d+) (.*)/.exec(contextNode.getAttribute("data-pm-slice"));
|
|
2967
2995
|
if (!slice) {
|
|
2968
2996
|
var parser = view.someProp("clipboardParser") || view.someProp("domParser") || DOMParser.fromSchema(view.state.schema);
|
|
2969
|
-
slice = parser.parseSlice(dom, {
|
|
2997
|
+
slice = parser.parseSlice(dom, {
|
|
2998
|
+
preserveWhitespace: !!(asText || sliceData),
|
|
2999
|
+
context: $context,
|
|
3000
|
+
ruleFromNode: function ruleFromNode(dom) {
|
|
3001
|
+
if (dom.nodeName == "BR" && !dom.nextSibling) { return {ignore: true} }
|
|
3002
|
+
}
|
|
3003
|
+
});
|
|
2970
3004
|
}
|
|
2971
3005
|
if (sliceData) {
|
|
2972
3006
|
slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3]);
|
|
@@ -4121,6 +4155,10 @@ WidgetType.prototype.eq = function eq (other) {
|
|
|
4121
4155
|
this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)))
|
|
4122
4156
|
};
|
|
4123
4157
|
|
|
4158
|
+
WidgetType.prototype.destroy = function destroy (node) {
|
|
4159
|
+
if (this.spec.destroy) { this.spec.destroy(node); }
|
|
4160
|
+
};
|
|
4161
|
+
|
|
4124
4162
|
var InlineType = function InlineType(attrs, spec) {
|
|
4125
4163
|
this.spec = spec || noSpec;
|
|
4126
4164
|
this.attrs = attrs;
|
|
@@ -4248,6 +4286,10 @@ Decoration.prototype.map = function map (mapping, offset, oldOffset) {
|
|
|
4248
4286
|
// key are interchangeable—if widgets differ in, for example,
|
|
4249
4287
|
// the behavior of some event handler, they should get
|
|
4250
4288
|
// different keys.
|
|
4289
|
+
//
|
|
4290
|
+
// destroy:: ?(node: dom.Node)
|
|
4291
|
+
// Called when the widget decoration is removed as a result of
|
|
4292
|
+
// mapping
|
|
4251
4293
|
Decoration.widget = function widget (pos, toDOM, spec) {
|
|
4252
4294
|
return new Decoration(pos, pos, new WidgetType(toDOM, spec))
|
|
4253
4295
|
};
|
|
@@ -4843,7 +4885,7 @@ var EditorView = function EditorView(place, props) {
|
|
|
4843
4885
|
this.updatePluginViews();
|
|
4844
4886
|
};
|
|
4845
4887
|
|
|
4846
|
-
var prototypeAccessors$2 = { props: { configurable: true },root: { configurable: true } };
|
|
4888
|
+
var prototypeAccessors$2 = { props: { configurable: true },root: { configurable: true },isDestroyed: { configurable: true } };
|
|
4847
4889
|
|
|
4848
4890
|
// composing:: boolean
|
|
4849
4891
|
// Holds `true` when a
|
|
@@ -5153,6 +5195,14 @@ EditorView.prototype.destroy = function destroy () {
|
|
|
5153
5195
|
this.docView = null;
|
|
5154
5196
|
};
|
|
5155
5197
|
|
|
5198
|
+
// :: boolean
|
|
5199
|
+
// This is true when the view has been
|
|
5200
|
+
// [destroyed](#view.EditorView.destroy) (and thus should not be
|
|
5201
|
+
// used anymore).
|
|
5202
|
+
prototypeAccessors$2.isDestroyed.get = function () {
|
|
5203
|
+
return this.docView == null
|
|
5204
|
+
};
|
|
5205
|
+
|
|
5156
5206
|
// Used for testing.
|
|
5157
5207
|
EditorView.prototype.dispatchEvent = function dispatchEvent$1 (event) {
|
|
5158
5208
|
return dispatchEvent(this, event)
|
|
@@ -5423,7 +5473,7 @@ function checkStateComponent(plugin) {
|
|
|
5423
5473
|
// view](#state.PluginSpec.view) and
|
|
5424
5474
|
// [props](#state.PluginSpec.props). Passing plugins with a state
|
|
5425
5475
|
// component (a [state field](#state.PluginSpec.state) field or a
|
|
5426
|
-
// [transaction
|
|
5476
|
+
// [transaction](#state.PluginSpec.filterTransaction) filter or
|
|
5427
5477
|
// appender) will result in an error, since such plugins must be
|
|
5428
5478
|
// present in the state to work.
|
|
5429
5479
|
//
|