prosemirror-view 1.30.1 → 1.30.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 CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.30.2 (2023-03-13)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where `posAtCoords` could incorrectly return positions outside of a table when querying a coordinate inside it.
6
+
7
+ Update the type of the `getPos` callback to include undefined in its return type. Update broken link (ViewProps -> EditorProps) Also detect iOS enter when the new block type is a less common node
8
+
9
+ Fix an issue where Enter on iOS would sometimes not be handled by the library.
10
+
1
11
  ## 1.30.1 (2023-02-04)
2
12
 
3
13
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -388,15 +388,16 @@ function posFromElement(view, elt, coords) {
388
388
  function posFromCaret(view, node, offset, coords) {
389
389
  var outsideBlock = -1;
390
390
 
391
- for (var cur = node;;) {
391
+ for (var cur = node, sawBlock = false;;) {
392
392
  if (cur == view.dom) break;
393
393
  var desc = view.docView.nearestDesc(cur, true);
394
394
  if (!desc) return null;
395
395
 
396
- if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
396
+ if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent && !sawBlock || !desc.contentDOM)) {
397
397
  var rect = desc.dom.getBoundingClientRect();
398
398
 
399
- if (desc.node.isBlock && desc.parent) {
399
+ if (desc.node.isBlock && desc.parent && !sawBlock) {
400
+ sawBlock = true;
400
401
  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;
401
402
  }
402
403
 
@@ -5169,6 +5170,8 @@ function ruleFromNode(dom) {
5169
5170
  return null;
5170
5171
  }
5171
5172
 
5173
+ var isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;
5174
+
5172
5175
  function readDOMChange(view, from, to, typeOver, addedNodes) {
5173
5176
  if (from < 0) {
5174
5177
  var origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null;
@@ -5210,7 +5213,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
5210
5213
  var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
5211
5214
 
5212
5215
  if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some(function (n) {
5213
- return n.nodeName == "DIV" || n.nodeName == "P" || n.nodeName == "LI";
5216
+ return n.nodeType == 1 && !isInline.test(n.nodeName);
5214
5217
  }) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", function (f) {
5215
5218
  return f(view, keyEvent(13, "Enter"));
5216
5219
  })) {
package/dist/index.d.ts CHANGED
@@ -601,12 +601,12 @@ declare class EditorView {
601
601
  dispatch(tr: Transaction): void;
602
602
  }
603
603
  /**
604
- The type of function [provided](https://prosemirror.net/docs/ref/#view.ViewProps.nodeViews) to
604
+ The type of function [provided](https://prosemirror.net/docs/ref/#view.EditorProps.nodeViews) to
605
605
  create [node views](https://prosemirror.net/docs/ref/#view.NodeView).
606
606
  */
607
- declare type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
607
+ declare type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number | undefined, decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView;
608
608
  /**
609
- The function types [used](https://prosemirror.net/docs/ref/#view.ViewProps.markViews) to create
609
+ The function types [used](https://prosemirror.net/docs/ref/#view.EditorProps.markViews) to create
610
610
  mark views.
611
611
  */
612
612
  declare type MarkViewConstructor = (mark: Mark, view: EditorView, inline: boolean) => {
@@ -767,6 +767,8 @@ interface EditorProps<P = any> {
767
767
  node's display behavior. The third argument `getPos` is a
768
768
  function that can be called to get the node's current position,
769
769
  which can be useful when creating transactions to update it.
770
+ Note that if the node is not in the document, the position
771
+ returned by this function will be `undefined`.
770
772
 
771
773
  `decorations` is an array of node or inline decorations that are
772
774
  active around the node. They are automatically drawn in the
@@ -782,7 +784,7 @@ interface EditorProps<P = any> {
782
784
  inner decorations.
783
785
 
784
786
  (For backwards compatibility reasons, [mark
785
- views](https://prosemirror.net/docs/ref/#view.ViewProps.markViews) can also be included in this
787
+ views](https://prosemirror.net/docs/ref/#view.EditorProps.markViews) can also be included in this
786
788
  object.)
787
789
  */
788
790
  nodeViews?: {
package/dist/index.js CHANGED
@@ -315,15 +315,16 @@ function posFromCaret(view, node, offset, coords) {
315
315
  // fall outside of. If so, we take the position before/after that
316
316
  // block. If not, we call `posFromDOM` on the raw node/offset.
317
317
  let outsideBlock = -1;
318
- for (let cur = node;;) {
318
+ for (let cur = node, sawBlock = false;;) {
319
319
  if (cur == view.dom)
320
320
  break;
321
321
  let desc = view.docView.nearestDesc(cur, true);
322
322
  if (!desc)
323
323
  return null;
324
- if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
324
+ if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent && !sawBlock || !desc.contentDOM)) {
325
325
  let rect = desc.dom.getBoundingClientRect();
326
- if (desc.node.isBlock && desc.parent) {
326
+ if (desc.node.isBlock && desc.parent && !sawBlock) {
327
+ sawBlock = true;
327
328
  if (rect.left > coords.left || rect.top > coords.top)
328
329
  outsideBlock = desc.posBefore;
329
330
  else if (rect.right < coords.left || rect.bottom < coords.top)
@@ -4574,6 +4575,7 @@ function ruleFromNode(dom) {
4574
4575
  }
4575
4576
  return null;
4576
4577
  }
4578
+ const isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;
4577
4579
  function readDOMChange(view, from, to, typeOver, addedNodes) {
4578
4580
  if (from < 0) {
4579
4581
  let origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null;
@@ -4612,7 +4614,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4612
4614
  view.input.lastKeyCode = null;
4613
4615
  let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
4614
4616
  if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) &&
4615
- addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P" || n.nodeName == "LI") &&
4617
+ addedNodes.some(n => n.nodeType == 1 && !isInline.test(n.nodeName)) &&
4616
4618
  (!change || change.endA >= change.endB) &&
4617
4619
  view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
4618
4620
  view.input.lastIOSEnter = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.30.1",
3
+ "version": "1.30.2",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/domchange.ts CHANGED
@@ -76,6 +76,8 @@ function ruleFromNode(dom: DOMNode): ParseRule | null {
76
76
  return null
77
77
  }
78
78
 
79
+ const isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i
80
+
79
81
  export function readDOMChange(view: EditorView, from: number, to: number, typeOver: boolean, addedNodes: readonly DOMNode[]) {
80
82
  if (from < 0) {
81
83
  let origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null
@@ -115,7 +117,7 @@ export function readDOMChange(view: EditorView, from: number, to: number, typeOv
115
117
 
116
118
  let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide)
117
119
  if ((browser.ios && view.input.lastIOSEnter > Date.now() - 225 || browser.android) &&
118
- addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P" || n.nodeName == "LI") &&
120
+ addedNodes.some(n => n.nodeType == 1 && !isInline.test(n.nodeName)) &&
119
121
  (!change || change.endA >= change.endB) &&
120
122
  view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
121
123
  view.input.lastIOSEnter = 0
package/src/domcoords.ts CHANGED
@@ -211,13 +211,14 @@ function posFromCaret(view: EditorView, node: Node, offset: number, coords: {top
211
211
  // fall outside of. If so, we take the position before/after that
212
212
  // block. If not, we call `posFromDOM` on the raw node/offset.
213
213
  let outsideBlock = -1
214
- for (let cur = node;;) {
214
+ for (let cur = node, sawBlock = false;;) {
215
215
  if (cur == view.dom) break
216
216
  let desc = view.docView.nearestDesc(cur, true)
217
217
  if (!desc) return null
218
- if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM)) {
218
+ if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent && !sawBlock || !desc.contentDOM)) {
219
219
  let rect = (desc.dom as HTMLElement).getBoundingClientRect()
220
- if (desc.node.isBlock && desc.parent) {
220
+ if (desc.node.isBlock && desc.parent && !sawBlock) {
221
+ sawBlock = true
221
222
  if (rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore
222
223
  else if (rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter
223
224
  }
package/src/index.ts CHANGED
@@ -544,12 +544,12 @@ function checkStateComponent(plugin: Plugin) {
544
544
  throw new RangeError("Plugins passed directly to the view must not have a state component")
545
545
  }
546
546
 
547
- /// The type of function [provided](#view.ViewProps.nodeViews) to
547
+ /// The type of function [provided](#view.EditorProps.nodeViews) to
548
548
  /// create [node views](#view.NodeView).
549
- export type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number,
549
+ export type NodeViewConstructor = (node: Node, view: EditorView, getPos: () => number | undefined,
550
550
  decorations: readonly Decoration[], innerDecorations: DecorationSource) => NodeView
551
551
 
552
- /// The function types [used](#view.ViewProps.markViews) to create
552
+ /// The function types [used](#view.EditorProps.markViews) to create
553
553
  /// mark views.
554
554
  export type MarkViewConstructor = (mark: Mark, view: EditorView, inline: boolean) => {dom: HTMLElement, contentDOM?: HTMLElement}
555
555
 
@@ -684,6 +684,8 @@ export interface EditorProps<P = any> {
684
684
  /// node's display behavior. The third argument `getPos` is a
685
685
  /// function that can be called to get the node's current position,
686
686
  /// which can be useful when creating transactions to update it.
687
+ /// Note that if the node is not in the document, the position
688
+ /// returned by this function will be `undefined`.
687
689
  ///
688
690
  /// `decorations` is an array of node or inline decorations that are
689
691
  /// active around the node. They are automatically drawn in the
@@ -699,7 +701,7 @@ export interface EditorProps<P = any> {
699
701
  /// inner decorations.
700
702
  ///
701
703
  /// (For backwards compatibility reasons, [mark
702
- /// views](#view.ViewProps.markViews) can also be included in this
704
+ /// views](#view.EditorProps.markViews) can also be included in this
703
705
  /// object.)
704
706
  nodeViews?: {[node: string]: NodeViewConstructor}
705
707