prosemirror-view 1.33.11 → 1.34.1

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,17 @@
1
+ ## 1.34.1 (2024-08-26)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix null dereferences caused by the behavior of Chrome's newly supported `caretPositionFromPoint` method.
6
+
7
+ Fix an issue where on Android, with GBoard, enter presses in code blocks while a spell correction was selected didn't insert a new line.
8
+
9
+ ## 1.34.0 (2024-08-23)
10
+
11
+ ### New features
12
+
13
+ The `DecorationGroup` interface now has a `forEachSet` method to iterate though the contained decoration sets.
14
+
1
15
  ## 1.33.11 (2024-08-19)
2
16
 
3
17
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -135,7 +135,7 @@ function caretFromPoint(doc, x, y) {
135
135
  var pos = doc.caretPositionFromPoint(x, y);
136
136
  if (pos) return {
137
137
  node: pos.offsetNode,
138
- offset: pos.offset
138
+ offset: Math.min(nodeSize(pos.offsetNode), pos.offset)
139
139
  };
140
140
  } catch (_) {}
141
141
  }
@@ -143,7 +143,7 @@ function caretFromPoint(doc, x, y) {
143
143
  var range = doc.caretRangeFromPoint(x, y);
144
144
  if (range) return {
145
145
  node: range.startContainer,
146
- offset: range.startOffset
146
+ offset: Math.min(nodeSize(range.startContainer), range.startOffset)
147
147
  };
148
148
  }
149
149
  }
@@ -3816,6 +3816,11 @@ var DecorationSet = function () {
3816
3816
  }
3817
3817
  return result;
3818
3818
  }
3819
+ }, {
3820
+ key: "forEachSet",
3821
+ value: function forEachSet(f) {
3822
+ f(this);
3823
+ }
3819
3824
  }], [{
3820
3825
  key: "create",
3821
3826
  value: function create(doc, decorations) {
@@ -3879,6 +3884,11 @@ var DecorationGroup = function () {
3879
3884
  }
3880
3885
  return result ? removeOverlap(sorted ? result : result.sort(byPos)) : none;
3881
3886
  }
3887
+ }, {
3888
+ key: "forEachSet",
3889
+ value: function forEachSet(f) {
3890
+ for (var i = 0; i < this.members.length; i++) this.members[i].forEachSet(f);
3891
+ }
3882
3892
  }], [{
3883
3893
  key: "from",
3884
3894
  value: function from(members) {
@@ -4550,6 +4560,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4550
4560
  }
4551
4561
  view.input.lastKeyCode = null;
4552
4562
  var change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
4563
+ if (change) view.input.domChangeCount++;
4553
4564
  if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some(function (n) {
4554
4565
  return n.nodeType == 1 && !isInline.test(n.nodeName);
4555
4566
  }) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", function (f) {
@@ -4577,7 +4588,6 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4577
4588
  return;
4578
4589
  }
4579
4590
  }
4580
- view.input.domChangeCount++;
4581
4591
  if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof prosemirrorState.TextSelection) {
4582
4592
  if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse.from) {
4583
4593
  change.start = view.state.selection.from;
package/dist/index.d.cts CHANGED
@@ -160,6 +160,10 @@ interface DecorationSource {
160
160
  Extract a DecorationSource containing decorations for the given child node at the given offset.
161
161
  */
162
162
  forChild(offset: number, child: Node): DecorationSource;
163
+ /**
164
+ Call the given function for each decoration set in the group.
165
+ */
166
+ forEachSet(f: (set: DecorationSet) => void): void;
163
167
  }
164
168
  /**
165
169
  A collection of [decorations](https://prosemirror.net/docs/ref/#view.Decoration), organized in such
@@ -215,6 +219,7 @@ declare class DecorationSet implements DecorationSource {
215
219
  The empty set of decorations.
216
220
  */
217
221
  static empty: DecorationSet;
222
+ forEachSet(f: (set: DecorationSet) => void): void;
218
223
  }
219
224
  declare class DecorationGroup implements DecorationSource {
220
225
  readonly members: readonly DecorationSet[];
@@ -224,6 +229,7 @@ declare class DecorationGroup implements DecorationSource {
224
229
  eq(other: DecorationGroup): boolean;
225
230
  locals(node: Node): readonly any[];
226
231
  static from(members: readonly DecorationSource[]): DecorationSource;
232
+ forEachSet(f: (set: DecorationSet) => void): void;
227
233
  }
228
234
 
229
235
  declare global {
package/dist/index.d.ts CHANGED
@@ -160,6 +160,10 @@ interface DecorationSource {
160
160
  Extract a DecorationSource containing decorations for the given child node at the given offset.
161
161
  */
162
162
  forChild(offset: number, child: Node): DecorationSource;
163
+ /**
164
+ Call the given function for each decoration set in the group.
165
+ */
166
+ forEachSet(f: (set: DecorationSet) => void): void;
163
167
  }
164
168
  /**
165
169
  A collection of [decorations](https://prosemirror.net/docs/ref/#view.Decoration), organized in such
@@ -215,6 +219,7 @@ declare class DecorationSet implements DecorationSource {
215
219
  The empty set of decorations.
216
220
  */
217
221
  static empty: DecorationSet;
222
+ forEachSet(f: (set: DecorationSet) => void): void;
218
223
  }
219
224
  declare class DecorationGroup implements DecorationSource {
220
225
  readonly members: readonly DecorationSet[];
@@ -224,6 +229,7 @@ declare class DecorationGroup implements DecorationSource {
224
229
  eq(other: DecorationGroup): boolean;
225
230
  locals(node: Node): readonly any[];
226
231
  static from(members: readonly DecorationSource[]): DecorationSource;
232
+ forEachSet(f: (set: DecorationSet) => void): void;
227
233
  }
228
234
 
229
235
  declare global {
package/dist/index.js CHANGED
@@ -139,15 +139,18 @@ function caretFromPoint(doc, x, y) {
139
139
  if (doc.caretPositionFromPoint) {
140
140
  try { // Firefox throws for this call in hard-to-predict circumstances (#994)
141
141
  let pos = doc.caretPositionFromPoint(x, y);
142
+ // Clip the offset, because Chrome will return a text offset
143
+ // into <input> nodes, which can't be treated as a regular DOM
144
+ // offset
142
145
  if (pos)
143
- return { node: pos.offsetNode, offset: pos.offset };
146
+ return { node: pos.offsetNode, offset: Math.min(nodeSize(pos.offsetNode), pos.offset) };
144
147
  }
145
148
  catch (_) { }
146
149
  }
147
150
  if (doc.caretRangeFromPoint) {
148
151
  let range = doc.caretRangeFromPoint(x, y);
149
152
  if (range)
150
- return { node: range.startContainer, offset: range.startOffset };
153
+ return { node: range.startContainer, offset: Math.min(nodeSize(range.startContainer), range.startOffset) };
151
154
  }
152
155
  }
153
156
 
@@ -4160,6 +4163,7 @@ class DecorationSet {
4160
4163
  }
4161
4164
  return result;
4162
4165
  }
4166
+ forEachSet(f) { f(this); }
4163
4167
  }
4164
4168
  /**
4165
4169
  The empty set of decorations.
@@ -4235,6 +4239,10 @@ class DecorationGroup {
4235
4239
  members.reduce((r, m) => r.concat(m instanceof DecorationSet ? m : m.members), []));
4236
4240
  }
4237
4241
  }
4242
+ forEachSet(f) {
4243
+ for (let i = 0; i < this.members.length; i++)
4244
+ this.members[i].forEachSet(f);
4245
+ }
4238
4246
  }
4239
4247
  function mapChildren(oldChildren, newLocal, mapping, node, offset, oldOffset, options) {
4240
4248
  let children = oldChildren.slice();
@@ -4897,6 +4905,8 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4897
4905
  }
4898
4906
  view.input.lastKeyCode = null;
4899
4907
  let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
4908
+ if (change)
4909
+ view.input.domChangeCount++;
4900
4910
  if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) &&
4901
4911
  addedNodes.some(n => n.nodeType == 1 && !isInline.test(n.nodeName)) &&
4902
4912
  (!change || change.endA >= change.endB) &&
@@ -4922,7 +4932,6 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4922
4932
  return;
4923
4933
  }
4924
4934
  }
4925
- view.input.domChangeCount++;
4926
4935
  // Handle the case where overwriting a selection by typing matches
4927
4936
  // the start or end of the selected content, creating a change
4928
4937
  // that's smaller than what was actually overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.33.11",
3
+ "version": "1.34.1",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/decoration.ts CHANGED
@@ -262,6 +262,8 @@ export interface DecorationSource {
262
262
  forChild(offset: number, child: Node): DecorationSource
263
263
  /// @internal
264
264
  eq(other: DecorationSource): boolean
265
+ /// Call the given function for each decoration set in the group.
266
+ forEachSet(f: (set: DecorationSet) => void): void
265
267
  }
266
268
 
267
269
  /// A collection of [decorations](#view.Decoration), organized in such
@@ -475,6 +477,8 @@ export class DecorationSet implements DecorationSource {
475
477
 
476
478
  /// @internal
477
479
  static removeOverlap = removeOverlap
480
+
481
+ forEachSet(f: (set: DecorationSet) => void) { f(this) }
478
482
  }
479
483
 
480
484
  const empty = DecorationSet.empty
@@ -542,6 +546,10 @@ class DecorationGroup implements DecorationSource {
542
546
  [] as DecorationSet[]))
543
547
  }
544
548
  }
549
+
550
+ forEachSet(f: (set: DecorationSet) => void) {
551
+ for (let i = 0; i < this.members.length; i++) this.members[i].forEachSet(f)
552
+ }
545
553
  }
546
554
 
547
555
  function mapChildren(
package/src/dom.ts CHANGED
@@ -141,11 +141,14 @@ export function caretFromPoint(doc: Document, x: number, y: number): {node: Node
141
141
  if ((doc as any).caretPositionFromPoint) {
142
142
  try { // Firefox throws for this call in hard-to-predict circumstances (#994)
143
143
  let pos = (doc as any).caretPositionFromPoint(x, y)
144
- if (pos) return {node: pos.offsetNode, offset: pos.offset}
144
+ // Clip the offset, because Chrome will return a text offset
145
+ // into <input> nodes, which can't be treated as a regular DOM
146
+ // offset
147
+ if (pos) return {node: pos.offsetNode, offset: Math.min(nodeSize(pos.offsetNode), pos.offset)}
145
148
  } catch (_) {}
146
149
  }
147
150
  if (doc.caretRangeFromPoint) {
148
151
  let range = doc.caretRangeFromPoint(x, y)
149
- if (range) return {node: range.startContainer, offset: range.startOffset}
152
+ if (range) return {node: range.startContainer, offset: Math.min(nodeSize(range.startContainer), range.startOffset)}
150
153
  }
151
154
  }
package/src/domchange.ts CHANGED
@@ -120,6 +120,7 @@ export function readDOMChange(view: EditorView, from: number, to: number, typeOv
120
120
  view.input.lastKeyCode = null
121
121
 
122
122
  let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide)
123
+ if (change) view.input.domChangeCount++
123
124
  if ((browser.ios && view.input.lastIOSEnter > Date.now() - 225 || browser.android) &&
124
125
  addedNodes.some(n => n.nodeType == 1 && !isInline.test(n.nodeName)) &&
125
126
  (!change || change.endA >= change.endB) &&
@@ -144,7 +145,6 @@ export function readDOMChange(view: EditorView, from: number, to: number, typeOv
144
145
  }
145
146
  }
146
147
 
147
- view.input.domChangeCount++
148
148
  // Handle the case where overwriting a selection by typing matches
149
149
  // the start or end of the selected content, creating a change
150
150
  // that's smaller than what was actually overwritten.