prosemirror-view 1.23.10 → 1.23.13
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 +18 -0
- package/dist/index.es.js +39 -17
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +39 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/domchange.js +7 -5
- package/src/domobserver.js +2 -2
- package/src/index.js +2 -2
- package/src/viewdesc.js +29 -9
package/package.json
CHANGED
package/src/domchange.js
CHANGED
|
@@ -115,15 +115,17 @@ export function readDOMChange(view, from, to, typeOver, addedNodes) {
|
|
|
115
115
|
view.lastKeyCode = null
|
|
116
116
|
|
|
117
117
|
let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide)
|
|
118
|
+
if ((browser.ios && view.lastIOSEnter > Date.now() - 225 || browser.android) &&
|
|
119
|
+
addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P") &&
|
|
120
|
+
(!change || change.endA >= change.endB) &&
|
|
121
|
+
view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
|
|
122
|
+
view.lastIOSEnter = 0
|
|
123
|
+
return
|
|
124
|
+
}
|
|
118
125
|
if (!change) {
|
|
119
126
|
if (typeOver && sel instanceof TextSelection && !sel.empty && sel.$head.sameParent(sel.$anchor) &&
|
|
120
127
|
!view.composing && !(parse.sel && parse.sel.anchor != parse.sel.head)) {
|
|
121
128
|
change = {start: sel.from, endA: sel.to, endB: sel.to}
|
|
122
|
-
} else if ((browser.ios && view.lastIOSEnter > Date.now() - 225 || browser.android) &&
|
|
123
|
-
addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P") &&
|
|
124
|
-
view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
|
|
125
|
-
view.lastIOSEnter = 0
|
|
126
|
-
return
|
|
127
129
|
} else {
|
|
128
130
|
if (parse.sel) {
|
|
129
131
|
let sel = resolveSelection(view, view.state.doc, parse.sel)
|
package/src/domobserver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import browser from "./browser"
|
|
2
2
|
import {domIndex, isEquivalentPosition} from "./dom"
|
|
3
|
-
import {hasFocusAndSelection,
|
|
3
|
+
import {hasFocusAndSelection, selectionToDOM} from "./selection"
|
|
4
4
|
|
|
5
5
|
const observeOptions = {
|
|
6
6
|
childList: true,
|
|
@@ -145,7 +145,7 @@ export class DOMObserver {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
let sel = this.view.root.getSelection()
|
|
148
|
-
let newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) &&
|
|
148
|
+
let newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(this.view) && !this.ignoreSelectionChange(sel)
|
|
149
149
|
|
|
150
150
|
let from = -1, to = -1, typeOver = false, added = []
|
|
151
151
|
if (this.view.editable) {
|
package/src/index.js
CHANGED
|
@@ -75,7 +75,7 @@ export class EditorView {
|
|
|
75
75
|
|
|
76
76
|
// composing:: boolean
|
|
77
77
|
// Holds `true` when a
|
|
78
|
-
// [composition](https://
|
|
78
|
+
// [composition](https://w3c.github.io/uievents/#events-compositionevents)
|
|
79
79
|
// is active.
|
|
80
80
|
|
|
81
81
|
// :: DirectEditorProps
|
|
@@ -643,7 +643,7 @@ function checkStateComponent(plugin) {
|
|
|
643
643
|
|
|
644
644
|
// DirectEditorProps:: interface extends EditorProps
|
|
645
645
|
//
|
|
646
|
-
// The props object given directly to the editor view supports
|
|
646
|
+
// The props object given directly to the editor view supports some
|
|
647
647
|
// fields that can't be used in plugins:
|
|
648
648
|
//
|
|
649
649
|
// state:: EditorState
|
package/src/viewdesc.js
CHANGED
|
@@ -672,8 +672,23 @@ class NodeViewDesc extends ViewDesc {
|
|
|
672
672
|
// whether this is a problem
|
|
673
673
|
let rule = {node: this.node.type.name, attrs: this.node.attrs}
|
|
674
674
|
if (this.node.type.whitespace == "pre") rule.preserveWhitespace = "full"
|
|
675
|
-
if (this.contentDOM
|
|
676
|
-
|
|
675
|
+
if (!this.contentDOM) {
|
|
676
|
+
rule.getContent = () => this.node.content
|
|
677
|
+
} else if (!this.contentLost) {
|
|
678
|
+
rule.contentElement = this.contentDOM
|
|
679
|
+
} else {
|
|
680
|
+
// Chrome likes to randomly recreate parent nodes when
|
|
681
|
+
// backspacing things. When that happens, this tries to find the
|
|
682
|
+
// new parent.
|
|
683
|
+
for (let i = this.children.length - 1; i >= 0; i--) {
|
|
684
|
+
let child = this.children[i]
|
|
685
|
+
if (this.dom.contains(child.dom.parentNode)) {
|
|
686
|
+
rule.contentElement = child.dom.parentNode
|
|
687
|
+
break
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if (!rule.contentElement) rule.getContent = () => Fragment.empty
|
|
691
|
+
}
|
|
677
692
|
return rule
|
|
678
693
|
}
|
|
679
694
|
|
|
@@ -1249,21 +1264,24 @@ class ViewTreeUpdater {
|
|
|
1249
1264
|
// Make sure a textblock looks and behaves correctly in
|
|
1250
1265
|
// contentEditable.
|
|
1251
1266
|
addTextblockHacks() {
|
|
1252
|
-
let lastChild = this.top.children[this.index - 1]
|
|
1253
|
-
while (lastChild instanceof MarkViewDesc)
|
|
1267
|
+
let lastChild = this.top.children[this.index - 1], parent = this.top
|
|
1268
|
+
while (lastChild instanceof MarkViewDesc) {
|
|
1269
|
+
parent = lastChild
|
|
1270
|
+
lastChild = parent.children[parent.children.length - 1]
|
|
1271
|
+
}
|
|
1254
1272
|
|
|
1255
1273
|
if (!lastChild || // Empty textblock
|
|
1256
1274
|
!(lastChild instanceof TextViewDesc) ||
|
|
1257
1275
|
/\n$/.test(lastChild.node.text)) {
|
|
1258
1276
|
// Avoid bugs in Safari's cursor drawing (#1165) and Chrome's mouse selection (#1152)
|
|
1259
1277
|
if ((browser.safari || browser.chrome) && lastChild && lastChild.dom.contentEditable == "false")
|
|
1260
|
-
this.addHackNode("IMG")
|
|
1261
|
-
this.addHackNode("BR")
|
|
1278
|
+
this.addHackNode("IMG", parent)
|
|
1279
|
+
this.addHackNode("BR", this.top)
|
|
1262
1280
|
}
|
|
1263
1281
|
}
|
|
1264
1282
|
|
|
1265
|
-
addHackNode(nodeName) {
|
|
1266
|
-
if (this.index <
|
|
1283
|
+
addHackNode(nodeName, parent) {
|
|
1284
|
+
if (parent == this.top && this.index < parent.children.length && parent.children[this.index].matchesHack(nodeName)) {
|
|
1267
1285
|
this.index++
|
|
1268
1286
|
} else {
|
|
1269
1287
|
let dom = document.createElement(nodeName)
|
|
@@ -1272,7 +1290,9 @@ class ViewTreeUpdater {
|
|
|
1272
1290
|
dom.alt = ""
|
|
1273
1291
|
}
|
|
1274
1292
|
if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak"
|
|
1275
|
-
|
|
1293
|
+
let hack = new TrailingHackViewDesc(this.top, nothing, dom, null)
|
|
1294
|
+
if (parent != this.top) parent.children.push(hack)
|
|
1295
|
+
else parent.children.splice(this.index++, 0, hack)
|
|
1276
1296
|
this.changed = true
|
|
1277
1297
|
}
|
|
1278
1298
|
}
|