prosemirror-view 1.33.6 → 1.33.7
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 +10 -0
- package/dist/index.cjs +38 -9
- package/dist/index.js +29 -11
- package/package.json +1 -1
- package/src/domcoords.ts +5 -4
- package/src/domobserver.ts +18 -3
- package/src/input.ts +1 -1
- package/src/viewdesc.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 1.33.7 (2024-05-31)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Ignore stray `<br>` nodes added to parent list elements when backspacing near uneditable content in Firefox.
|
|
6
|
+
|
|
7
|
+
Fix a crash where the editor tried to call `removeAttribute` on a text node.
|
|
8
|
+
|
|
9
|
+
Fix an issue where coordinates near nested blocks could inappropriately be assigned to be inside those blocks.
|
|
10
|
+
|
|
1
11
|
## 1.33.6 (2024-04-30)
|
|
2
12
|
|
|
3
13
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
3
7
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
4
8
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
9
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
@@ -387,11 +391,11 @@ function posFromCaret(view, node, offset, coords) {
|
|
|
387
391
|
if (cur == view.dom) break;
|
|
388
392
|
var desc = view.docView.nearestDesc(cur, true);
|
|
389
393
|
if (!desc) return null;
|
|
390
|
-
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent
|
|
394
|
+
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
|
|
391
395
|
var rect = desc.dom.getBoundingClientRect();
|
|
392
|
-
if (desc.node.isBlock && desc.parent
|
|
396
|
+
if (desc.node.isBlock && desc.parent) {
|
|
397
|
+
if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore;else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter;
|
|
393
398
|
sawBlock = true;
|
|
394
|
-
if (rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore;else if (rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter;
|
|
395
399
|
}
|
|
396
400
|
if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) {
|
|
397
401
|
var before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2;
|
|
@@ -1387,8 +1391,10 @@ var NodeViewDesc = function (_ViewDesc4) {
|
|
|
1387
1391
|
}, {
|
|
1388
1392
|
key: "deselectNode",
|
|
1389
1393
|
value: function deselectNode() {
|
|
1390
|
-
if (this.nodeDOM.nodeType == 1)
|
|
1391
|
-
|
|
1394
|
+
if (this.nodeDOM.nodeType == 1) {
|
|
1395
|
+
this.nodeDOM.classList.remove("ProseMirror-selectednode");
|
|
1396
|
+
if (this.contentDOM || !this.node.type.spec.draggable) this.dom.removeAttribute("draggable");
|
|
1397
|
+
}
|
|
1392
1398
|
}
|
|
1393
1399
|
}, {
|
|
1394
1400
|
key: "domAtom",
|
|
@@ -3085,7 +3091,7 @@ var MouseDown = function () {
|
|
|
3085
3091
|
}
|
|
3086
3092
|
var target = flushed ? null : event.target;
|
|
3087
3093
|
var targetDesc = target ? view.docView.nearestDesc(target, true) : null;
|
|
3088
|
-
this.target = targetDesc ? targetDesc.dom : null;
|
|
3094
|
+
this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom : null;
|
|
3089
3095
|
var selection = view.state.selection;
|
|
3090
3096
|
if (event.button == 0 && targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof prosemirrorState.NodeSelection && selection.from <= targetPos && selection.to > targetPos) this.mightDrag = {
|
|
3091
3097
|
node: targetNode,
|
|
@@ -4265,14 +4271,30 @@ var DOMObserver = function () {
|
|
|
4265
4271
|
}
|
|
4266
4272
|
}
|
|
4267
4273
|
}
|
|
4268
|
-
if (gecko && added.length
|
|
4274
|
+
if (gecko && added.length) {
|
|
4269
4275
|
var brs = added.filter(function (n) {
|
|
4270
4276
|
return n.nodeName == "BR";
|
|
4271
4277
|
});
|
|
4272
4278
|
if (brs.length == 2) {
|
|
4273
|
-
var
|
|
4274
|
-
|
|
4279
|
+
var _brs = _slicedToArray(brs, 2),
|
|
4280
|
+
a = _brs[0],
|
|
4281
|
+
b = _brs[1];
|
|
4275
4282
|
if (a.parentNode && a.parentNode.parentNode == b.parentNode) b.remove();else a.remove();
|
|
4283
|
+
} else {
|
|
4284
|
+
var focusNode = this.currentSelection.focusNode;
|
|
4285
|
+
var _iterator3 = _createForOfIteratorHelper(brs),
|
|
4286
|
+
_step3;
|
|
4287
|
+
try {
|
|
4288
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
4289
|
+
var br = _step3.value;
|
|
4290
|
+
var parent = br.parentNode;
|
|
4291
|
+
if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent)) br.remove();
|
|
4292
|
+
}
|
|
4293
|
+
} catch (err) {
|
|
4294
|
+
_iterator3.e(err);
|
|
4295
|
+
} finally {
|
|
4296
|
+
_iterator3.f();
|
|
4297
|
+
}
|
|
4276
4298
|
}
|
|
4277
4299
|
}
|
|
4278
4300
|
var readSel = null;
|
|
@@ -4387,6 +4409,13 @@ function safariShadowSelectionRange(view, selection) {
|
|
|
4387
4409
|
view.dom.removeEventListener("beforeinput", read, true);
|
|
4388
4410
|
return found ? rangeToSelectionRange(view, found) : null;
|
|
4389
4411
|
}
|
|
4412
|
+
function blockParent(view, node) {
|
|
4413
|
+
for (var p = node.parentNode; p && p != view.dom; p = p.parentNode) {
|
|
4414
|
+
var desc = view.docView.nearestDesc(p, true);
|
|
4415
|
+
if (desc && desc.node.isBlock) return p;
|
|
4416
|
+
}
|
|
4417
|
+
return null;
|
|
4418
|
+
}
|
|
4390
4419
|
function parseBetween(view, from_, to_) {
|
|
4391
4420
|
var _view$docView$parseRa = view.docView.parseRange(from_, to_),
|
|
4392
4421
|
parent = _view$docView$parseRa.node,
|
package/dist/index.js
CHANGED
|
@@ -396,14 +396,15 @@ function posFromCaret(view, node, offset, coords) {
|
|
|
396
396
|
let desc = view.docView.nearestDesc(cur, true);
|
|
397
397
|
if (!desc)
|
|
398
398
|
return null;
|
|
399
|
-
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent
|
|
399
|
+
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
|
|
400
400
|
let rect = desc.dom.getBoundingClientRect();
|
|
401
|
-
if (desc.node.isBlock && desc.parent
|
|
402
|
-
|
|
403
|
-
if (rect.left > coords.left || rect.top > coords.top)
|
|
401
|
+
if (desc.node.isBlock && desc.parent) {
|
|
402
|
+
// Only apply the horizontal test to the innermost block. Vertical for any parent.
|
|
403
|
+
if (!sawBlock && rect.left > coords.left || rect.top > coords.top)
|
|
404
404
|
outsideBlock = desc.posBefore;
|
|
405
|
-
else if (rect.right < coords.left || rect.bottom < coords.top)
|
|
405
|
+
else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top)
|
|
406
406
|
outsideBlock = desc.posAfter;
|
|
407
|
+
sawBlock = true;
|
|
407
408
|
}
|
|
408
409
|
if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) {
|
|
409
410
|
// If we are inside a leaf, return the side of the leaf closer to the coords
|
|
@@ -1452,10 +1453,11 @@ class NodeViewDesc extends ViewDesc {
|
|
|
1452
1453
|
}
|
|
1453
1454
|
// Remove selected node marking from this node.
|
|
1454
1455
|
deselectNode() {
|
|
1455
|
-
if (this.nodeDOM.nodeType == 1)
|
|
1456
|
+
if (this.nodeDOM.nodeType == 1) {
|
|
1456
1457
|
this.nodeDOM.classList.remove("ProseMirror-selectednode");
|
|
1457
|
-
|
|
1458
|
-
|
|
1458
|
+
if (this.contentDOM || !this.node.type.spec.draggable)
|
|
1459
|
+
this.dom.removeAttribute("draggable");
|
|
1460
|
+
}
|
|
1459
1461
|
}
|
|
1460
1462
|
get domAtom() { return this.node.isAtom; }
|
|
1461
1463
|
}
|
|
@@ -3270,7 +3272,7 @@ class MouseDown {
|
|
|
3270
3272
|
}
|
|
3271
3273
|
const target = flushed ? null : event.target;
|
|
3272
3274
|
const targetDesc = target ? view.docView.nearestDesc(target, true) : null;
|
|
3273
|
-
this.target = targetDesc ? targetDesc.dom : null;
|
|
3275
|
+
this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom : null;
|
|
3274
3276
|
let { selection } = view.state;
|
|
3275
3277
|
if (event.button == 0 &&
|
|
3276
3278
|
targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false ||
|
|
@@ -4602,15 +4604,23 @@ class DOMObserver {
|
|
|
4602
4604
|
}
|
|
4603
4605
|
}
|
|
4604
4606
|
}
|
|
4605
|
-
if (gecko && added.length
|
|
4607
|
+
if (gecko && added.length) {
|
|
4606
4608
|
let brs = added.filter(n => n.nodeName == "BR");
|
|
4607
4609
|
if (brs.length == 2) {
|
|
4608
|
-
let a
|
|
4610
|
+
let [a, b] = brs;
|
|
4609
4611
|
if (a.parentNode && a.parentNode.parentNode == b.parentNode)
|
|
4610
4612
|
b.remove();
|
|
4611
4613
|
else
|
|
4612
4614
|
a.remove();
|
|
4613
4615
|
}
|
|
4616
|
+
else {
|
|
4617
|
+
let { focusNode } = this.currentSelection;
|
|
4618
|
+
for (let br of brs) {
|
|
4619
|
+
let parent = br.parentNode;
|
|
4620
|
+
if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent))
|
|
4621
|
+
br.remove();
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4614
4624
|
}
|
|
4615
4625
|
let readSel = null;
|
|
4616
4626
|
// If it looks like the browser has reset the selection to the
|
|
@@ -4740,6 +4750,14 @@ function safariShadowSelectionRange(view, selection) {
|
|
|
4740
4750
|
view.dom.removeEventListener("beforeinput", read, true);
|
|
4741
4751
|
return found ? rangeToSelectionRange(view, found) : null;
|
|
4742
4752
|
}
|
|
4753
|
+
function blockParent(view, node) {
|
|
4754
|
+
for (let p = node.parentNode; p && p != view.dom; p = p.parentNode) {
|
|
4755
|
+
let desc = view.docView.nearestDesc(p, true);
|
|
4756
|
+
if (desc && desc.node.isBlock)
|
|
4757
|
+
return p;
|
|
4758
|
+
}
|
|
4759
|
+
return null;
|
|
4760
|
+
}
|
|
4743
4761
|
|
|
4744
4762
|
// Note that all referencing and parsing is done with the
|
|
4745
4763
|
// start-of-operation selection and document, since that's the one
|
package/package.json
CHANGED
package/src/domcoords.ts
CHANGED
|
@@ -227,12 +227,13 @@ function posFromCaret(view: EditorView, node: Node, offset: number, coords: {top
|
|
|
227
227
|
if (cur == view.dom) break
|
|
228
228
|
let desc = view.docView.nearestDesc(cur, true)
|
|
229
229
|
if (!desc) return null
|
|
230
|
-
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent
|
|
230
|
+
if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
|
|
231
231
|
let rect = (desc.dom as HTMLElement).getBoundingClientRect()
|
|
232
|
-
if (desc.node.isBlock && desc.parent
|
|
232
|
+
if (desc.node.isBlock && desc.parent) {
|
|
233
|
+
// Only apply the horizontal test to the innermost block. Vertical for any parent.
|
|
234
|
+
if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore
|
|
235
|
+
else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter
|
|
233
236
|
sawBlock = true
|
|
234
|
-
if (rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore
|
|
235
|
-
else if (rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter
|
|
236
237
|
}
|
|
237
238
|
if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) {
|
|
238
239
|
// If we are inside a leaf, return the side of the leaf closer to the coords
|
package/src/domobserver.ts
CHANGED
|
@@ -183,12 +183,19 @@ export class DOMObserver {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
if (browser.gecko && added.length
|
|
187
|
-
let brs = added.filter(n => n.nodeName == "BR")
|
|
186
|
+
if (browser.gecko && added.length) {
|
|
187
|
+
let brs = added.filter(n => n.nodeName == "BR") as HTMLElement[]
|
|
188
188
|
if (brs.length == 2) {
|
|
189
|
-
let a
|
|
189
|
+
let [a, b] = brs
|
|
190
190
|
if (a.parentNode && a.parentNode.parentNode == b.parentNode) b.remove()
|
|
191
191
|
else a.remove()
|
|
192
|
+
} else {
|
|
193
|
+
let {focusNode} = this.currentSelection
|
|
194
|
+
for (let br of brs) {
|
|
195
|
+
let parent = br.parentNode
|
|
196
|
+
if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent))
|
|
197
|
+
br.remove()
|
|
198
|
+
}
|
|
192
199
|
}
|
|
193
200
|
}
|
|
194
201
|
|
|
@@ -317,3 +324,11 @@ export function safariShadowSelectionRange(view: EditorView, selection: DOMSelec
|
|
|
317
324
|
|
|
318
325
|
return found ? rangeToSelectionRange(view, found) : null
|
|
319
326
|
}
|
|
327
|
+
|
|
328
|
+
function blockParent(view: EditorView, node: DOMNode): Node | null {
|
|
329
|
+
for (let p = node.parentNode; p && p != view.dom; p = p.parentNode) {
|
|
330
|
+
let desc = view.docView.nearestDesc(p, true)
|
|
331
|
+
if (desc && desc.node.isBlock) return p
|
|
332
|
+
}
|
|
333
|
+
return null
|
|
334
|
+
}
|
package/src/input.ts
CHANGED
|
@@ -326,7 +326,7 @@ class MouseDown {
|
|
|
326
326
|
|
|
327
327
|
const target = flushed ? null : event.target as HTMLElement
|
|
328
328
|
const targetDesc = target ? view.docView.nearestDesc(target, true) : null
|
|
329
|
-
this.target = targetDesc ? targetDesc.dom as HTMLElement : null
|
|
329
|
+
this.target = targetDesc && targetDesc.dom.nodeType == 1 ? targetDesc.dom as HTMLElement : null
|
|
330
330
|
|
|
331
331
|
let {selection} = view.state
|
|
332
332
|
if (event.button == 0 &&
|
package/src/viewdesc.ts
CHANGED
|
@@ -834,8 +834,10 @@ export class NodeViewDesc extends ViewDesc {
|
|
|
834
834
|
|
|
835
835
|
// Remove selected node marking from this node.
|
|
836
836
|
deselectNode() {
|
|
837
|
-
if (this.nodeDOM.nodeType == 1)
|
|
838
|
-
|
|
837
|
+
if (this.nodeDOM.nodeType == 1) {
|
|
838
|
+
;(this.nodeDOM as HTMLElement).classList.remove("ProseMirror-selectednode")
|
|
839
|
+
if (this.contentDOM || !this.node.type.spec.draggable) (this.dom as HTMLElement).removeAttribute("draggable")
|
|
840
|
+
}
|
|
839
841
|
}
|
|
840
842
|
|
|
841
843
|
get domAtom() { return this.node.isAtom }
|