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/dist/index.js
CHANGED
|
@@ -1125,6 +1125,11 @@ var WidgetViewDesc = /*@__PURE__*/(function (ViewDesc) {
|
|
|
1125
1125
|
return mutation.type != "selection" || this.widget.spec.ignoreSelection
|
|
1126
1126
|
};
|
|
1127
1127
|
|
|
1128
|
+
WidgetViewDesc.prototype.destroy = function destroy () {
|
|
1129
|
+
this.widget.type.destroy(this.dom);
|
|
1130
|
+
ViewDesc.prototype.destroy.call(this);
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1128
1133
|
prototypeAccessors$1.domAtom.get = function () { return true };
|
|
1129
1134
|
|
|
1130
1135
|
Object.defineProperties( WidgetViewDesc.prototype, prototypeAccessors$1 );
|
|
@@ -1700,6 +1705,8 @@ function patchAttributes(dom, prev, cur) {
|
|
|
1700
1705
|
{ dom.classList.remove(prevList[i]); } }
|
|
1701
1706
|
for (var i$1 = 0; i$1 < curList.length; i$1++) { if (prevList.indexOf(curList[i$1]) == -1)
|
|
1702
1707
|
{ dom.classList.add(curList[i$1]); } }
|
|
1708
|
+
if (dom.classList.length == 0)
|
|
1709
|
+
{ dom.removeAttribute("class"); }
|
|
1703
1710
|
}
|
|
1704
1711
|
if (prev.style != cur.style) {
|
|
1705
1712
|
if (prev.style) {
|
|
@@ -1744,7 +1751,7 @@ var ViewTreeUpdater = function ViewTreeUpdater(top, lockedNode) {
|
|
|
1744
1751
|
// Tracks whether anything was changed
|
|
1745
1752
|
this.changed = false;
|
|
1746
1753
|
|
|
1747
|
-
this.preMatch = preMatch(top.node.content, top
|
|
1754
|
+
this.preMatch = preMatch(top.node.content, top);
|
|
1748
1755
|
};
|
|
1749
1756
|
|
|
1750
1757
|
// Destroy and remove the children between the given indices in
|
|
@@ -1805,17 +1812,16 @@ ViewTreeUpdater.prototype.syncToMarks = function syncToMarks (marks, inline, vie
|
|
|
1805
1812
|
// Try to find a node desc matching the given data. Skip over it and
|
|
1806
1813
|
// return true when successful.
|
|
1807
1814
|
ViewTreeUpdater.prototype.findNodeMatch = function findNodeMatch (node, outerDeco, innerDeco, index) {
|
|
1808
|
-
var
|
|
1809
|
-
if (index >= this.preMatch.index
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
} }
|
|
1815
|
+
var found = -1, targetDesc;
|
|
1816
|
+
if (index >= this.preMatch.index &&
|
|
1817
|
+
(targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top &&
|
|
1818
|
+
targetDesc.matchesNode(node, outerDeco, innerDeco)) {
|
|
1819
|
+
found = this.top.children.indexOf(targetDesc, this.index);
|
|
1814
1820
|
} else {
|
|
1815
|
-
for (var i
|
|
1816
|
-
var child = children[i
|
|
1821
|
+
for (var i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) {
|
|
1822
|
+
var child = this.top.children[i];
|
|
1817
1823
|
if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) {
|
|
1818
|
-
found = i
|
|
1824
|
+
found = i;
|
|
1819
1825
|
break
|
|
1820
1826
|
}
|
|
1821
1827
|
}
|
|
@@ -1924,22 +1930,44 @@ ViewTreeUpdater.prototype.addHackNode = function addHackNode (nodeName) {
|
|
|
1924
1930
|
}
|
|
1925
1931
|
};
|
|
1926
1932
|
|
|
1927
|
-
// : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number
|
|
1933
|
+
// : (Fragment, [ViewDesc]) → {index: number, matched: Map<ViewDesc, number>, matches: ViewDesc[]}
|
|
1928
1934
|
// Iterate from the end of the fragment and array of descs to find
|
|
1929
1935
|
// directly matching ones, in order to avoid overeagerly reusing those
|
|
1930
1936
|
// for other nodes. Returns the fragment index of the first node that
|
|
1931
1937
|
// is part of the sequence of matched nodes at the end of the
|
|
1932
1938
|
// fragment.
|
|
1933
|
-
function preMatch(frag,
|
|
1934
|
-
var
|
|
1935
|
-
|
|
1936
|
-
|
|
1939
|
+
function preMatch(frag, parentDesc) {
|
|
1940
|
+
var curDesc = parentDesc, descI = curDesc.children.length;
|
|
1941
|
+
var fI = frag.childCount, matched = new Map, matches = [];
|
|
1942
|
+
outer: while (fI > 0) {
|
|
1943
|
+
var desc = (void 0);
|
|
1944
|
+
for (;;) {
|
|
1945
|
+
if (descI) {
|
|
1946
|
+
var next = curDesc.children[descI - 1];
|
|
1947
|
+
if (next instanceof MarkViewDesc) {
|
|
1948
|
+
curDesc = next;
|
|
1949
|
+
descI = next.children.length;
|
|
1950
|
+
} else {
|
|
1951
|
+
desc = next;
|
|
1952
|
+
descI--;
|
|
1953
|
+
break
|
|
1954
|
+
}
|
|
1955
|
+
} else if (curDesc == parentDesc) {
|
|
1956
|
+
break outer
|
|
1957
|
+
} else {
|
|
1958
|
+
// FIXME
|
|
1959
|
+
descI = curDesc.parent.children.indexOf(curDesc);
|
|
1960
|
+
curDesc = curDesc.parent;
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
var node = desc.node;
|
|
1937
1964
|
if (!node) { continue }
|
|
1938
1965
|
if (node != frag.child(fI - 1)) { break }
|
|
1939
1966
|
--fI;
|
|
1940
1967
|
matched.set(desc, fI);
|
|
1968
|
+
matches.push(desc);
|
|
1941
1969
|
}
|
|
1942
|
-
return {index: fI, matched: matched}
|
|
1970
|
+
return {index: fI, matched: matched, matches: matches.reverse()}
|
|
1943
1971
|
}
|
|
1944
1972
|
|
|
1945
1973
|
function compareSide(a, b) { return a.type.side - b.type.side }
|
|
@@ -2970,7 +2998,13 @@ function parseFromClipboard(view, text, html, plainText, $context) {
|
|
|
2970
2998
|
var sliceData = contextNode && /^(\d+) (\d+) (.*)/.exec(contextNode.getAttribute("data-pm-slice"));
|
|
2971
2999
|
if (!slice) {
|
|
2972
3000
|
var parser = view.someProp("clipboardParser") || view.someProp("domParser") || prosemirrorModel.DOMParser.fromSchema(view.state.schema);
|
|
2973
|
-
slice = parser.parseSlice(dom, {
|
|
3001
|
+
slice = parser.parseSlice(dom, {
|
|
3002
|
+
preserveWhitespace: !!(asText || sliceData),
|
|
3003
|
+
context: $context,
|
|
3004
|
+
ruleFromNode: function ruleFromNode(dom) {
|
|
3005
|
+
if (dom.nodeName == "BR" && !dom.nextSibling) { return {ignore: true} }
|
|
3006
|
+
}
|
|
3007
|
+
});
|
|
2974
3008
|
}
|
|
2975
3009
|
if (sliceData) {
|
|
2976
3010
|
slice = addContext(closeSlice(slice, +sliceData[1], +sliceData[2]), sliceData[3]);
|
|
@@ -4125,6 +4159,10 @@ WidgetType.prototype.eq = function eq (other) {
|
|
|
4125
4159
|
this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)))
|
|
4126
4160
|
};
|
|
4127
4161
|
|
|
4162
|
+
WidgetType.prototype.destroy = function destroy (node) {
|
|
4163
|
+
if (this.spec.destroy) { this.spec.destroy(node); }
|
|
4164
|
+
};
|
|
4165
|
+
|
|
4128
4166
|
var InlineType = function InlineType(attrs, spec) {
|
|
4129
4167
|
this.spec = spec || noSpec;
|
|
4130
4168
|
this.attrs = attrs;
|
|
@@ -4252,6 +4290,10 @@ Decoration.prototype.map = function map (mapping, offset, oldOffset) {
|
|
|
4252
4290
|
// key are interchangeable—if widgets differ in, for example,
|
|
4253
4291
|
// the behavior of some event handler, they should get
|
|
4254
4292
|
// different keys.
|
|
4293
|
+
//
|
|
4294
|
+
// destroy:: ?(node: dom.Node)
|
|
4295
|
+
// Called when the widget decoration is removed as a result of
|
|
4296
|
+
// mapping
|
|
4255
4297
|
Decoration.widget = function widget (pos, toDOM, spec) {
|
|
4256
4298
|
return new Decoration(pos, pos, new WidgetType(toDOM, spec))
|
|
4257
4299
|
};
|
|
@@ -4847,7 +4889,7 @@ var EditorView = function EditorView(place, props) {
|
|
|
4847
4889
|
this.updatePluginViews();
|
|
4848
4890
|
};
|
|
4849
4891
|
|
|
4850
|
-
var prototypeAccessors$2 = { props: { configurable: true },root: { configurable: true } };
|
|
4892
|
+
var prototypeAccessors$2 = { props: { configurable: true },root: { configurable: true },isDestroyed: { configurable: true } };
|
|
4851
4893
|
|
|
4852
4894
|
// composing:: boolean
|
|
4853
4895
|
// Holds `true` when a
|
|
@@ -5157,6 +5199,14 @@ EditorView.prototype.destroy = function destroy () {
|
|
|
5157
5199
|
this.docView = null;
|
|
5158
5200
|
};
|
|
5159
5201
|
|
|
5202
|
+
// :: boolean
|
|
5203
|
+
// This is true when the view has been
|
|
5204
|
+
// [destroyed](#view.EditorView.destroy) (and thus should not be
|
|
5205
|
+
// used anymore).
|
|
5206
|
+
prototypeAccessors$2.isDestroyed.get = function () {
|
|
5207
|
+
return this.docView == null
|
|
5208
|
+
};
|
|
5209
|
+
|
|
5160
5210
|
// Used for testing.
|
|
5161
5211
|
EditorView.prototype.dispatchEvent = function dispatchEvent$1 (event) {
|
|
5162
5212
|
return dispatchEvent(this, event)
|
|
@@ -5427,7 +5477,7 @@ function checkStateComponent(plugin) {
|
|
|
5427
5477
|
// view](#state.PluginSpec.view) and
|
|
5428
5478
|
// [props](#state.PluginSpec.props). Passing plugins with a state
|
|
5429
5479
|
// component (a [state field](#state.PluginSpec.state) field or a
|
|
5430
|
-
// [transaction
|
|
5480
|
+
// [transaction](#state.PluginSpec.filterTransaction) filter or
|
|
5431
5481
|
// appender) will result in an error, since such plugins must be
|
|
5432
5482
|
// present in the state to work.
|
|
5433
5483
|
//
|