prosemirror-view 1.26.0 → 1.26.3

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,21 @@
1
+ ## 1.26.3 (2022-06-29)
2
+
3
+ ### Bug fixes
4
+
5
+ Work around a Safari bug where mutation records get delivered even though the observer wasn't observing when the mutations happened.
6
+
7
+ ## 1.26.2 (2022-06-22)
8
+
9
+ ### Bug fixes
10
+
11
+ Mark prosemirror.css as having side effects in package.json.
12
+
13
+ ## 1.26.1 (2022-06-13)
14
+
15
+ ### Bug fixes
16
+
17
+ Fix incorrect types for `handleDrop` and `decorations`. Document open properties on widget specs
18
+
1
19
  ## 1.26.0 (2022-06-07)
2
20
 
3
21
  ### New features
package/dist/index.cjs CHANGED
@@ -444,7 +444,7 @@ function _posAtCoords(view, coords) {
444
444
  }
445
445
  }
446
446
 
447
- var elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top + 1);
447
+ var elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top);
448
448
  var pos;
449
449
 
450
450
  if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
@@ -4724,7 +4724,11 @@ var DOMObserver = function () {
4724
4724
  }, {
4725
4725
  key: "start",
4726
4726
  value: function start() {
4727
- if (this.observer) this.observer.observe(this.view.dom, observeOptions);
4727
+ if (this.observer) {
4728
+ this.observer.takeRecords();
4729
+ this.observer.observe(this.view.dom, observeOptions);
4730
+ }
4731
+
4728
4732
  if (this.onCharData) this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData);
4729
4733
  this.connectSelection();
4730
4734
  }
package/dist/index.d.ts CHANGED
@@ -79,6 +79,10 @@ declare class Decoration {
79
79
  mapping
80
80
  */
81
81
  destroy?: (node: DOMNode) => void;
82
+ /**
83
+ Specs allow arbitrary additional properties.
84
+ */
85
+ [key: string]: any;
82
86
  }): Decoration;
83
87
  /**
84
88
  Creates an inline decoration, which adds the given attributes to
@@ -99,6 +103,10 @@ declare class Decoration {
99
103
  [`inclusiveStart`](https://prosemirror.net/docs/ref/#view.Decoration^inline^spec.inclusiveStart).
100
104
  */
101
105
  inclusiveEnd?: boolean;
106
+ /**
107
+ Specs may have arbitrary additional properties.
108
+ */
109
+ [key: string]: any;
102
110
  }): Decoration;
103
111
  /**
104
112
  Creates a node decoration. `from` and `to` should point precisely
@@ -583,7 +591,7 @@ interface EditorProps {
583
591
  default behavior).
584
592
  */
585
593
  handleDOMEvents?: {
586
- [event in string]: (view: EditorView, event: DOMEventMap[event]) => boolean | void;
594
+ [event in keyof DOMEventMap]?: (view: EditorView, event: DOMEventMap[event]) => boolean | void;
587
595
  };
588
596
  /**
589
597
  Called when the editor receives a `keydown` event.
@@ -636,7 +644,7 @@ interface EditorProps {
636
644
  true if this drop moves from the current selection (which should
637
645
  thus be deleted).
638
646
  */
639
- handleDrop?: (view: EditorView, event: MouseEvent, slice: Slice, moved: boolean) => boolean | void;
647
+ handleDrop?: (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void;
640
648
  /**
641
649
  Called when the view, after updating its state, tries to scroll
642
650
  the selection into view. A handler function may return false to
@@ -746,7 +754,7 @@ interface EditorProps {
746
754
  A set of [document decorations](https://prosemirror.net/docs/ref/#view.Decoration) to show in the
747
755
  view.
748
756
  */
749
- decorations?: (state: EditorState) => DecorationSource | null;
757
+ decorations?: (state: EditorState) => DecorationSource | null | undefined;
750
758
  /**
751
759
  When this returns false, the content of the view is not directly
752
760
  editable.
package/dist/index.js CHANGED
@@ -367,7 +367,7 @@ function posAtCoords(view, coords) {
367
367
  ({ startContainer: node, startOffset: offset } = range);
368
368
  }
369
369
  let elt = (view.root.elementFromPoint ? view.root : doc)
370
- .elementFromPoint(coords.left, coords.top + 1);
370
+ .elementFromPoint(coords.left, coords.top);
371
371
  let pos;
372
372
  if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
373
373
  let box = view.dom.getBoundingClientRect();
@@ -4234,8 +4234,10 @@ class DOMObserver {
4234
4234
  }
4235
4235
  }
4236
4236
  start() {
4237
- if (this.observer)
4237
+ if (this.observer) {
4238
+ this.observer.takeRecords();
4238
4239
  this.observer.observe(this.view.dom, observeOptions);
4240
+ }
4239
4241
  if (this.onCharData)
4240
4242
  this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData);
4241
4243
  this.connectSelection();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.26.0",
3
+ "version": "1.26.3",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "./style/prosemirror.css": "./style/prosemirror.css"
15
15
  },
16
- "sideEffects": false,
16
+ "sideEffects": ["./style/prosemirror.css"],
17
17
  "style": "style/prosemirror.css",
18
18
  "license": "MIT",
19
19
  "maintainers": [
package/src/decoration.ts CHANGED
@@ -182,6 +182,9 @@ export class Decoration {
182
182
  /// Called when the widget decoration is removed as a result of
183
183
  /// mapping
184
184
  destroy?: (node: DOMNode) => void
185
+
186
+ /// Specs allow arbitrary additional properties.
187
+ [key: string]: any
185
188
  }): Decoration {
186
189
  return new Decoration(pos, pos, new WidgetType(toDOM, spec))
187
190
  }
@@ -200,6 +203,9 @@ export class Decoration {
200
203
  /// See
201
204
  /// [`inclusiveStart`](#view.Decoration^inline^spec.inclusiveStart).
202
205
  inclusiveEnd?: boolean
206
+
207
+ /// Specs may have arbitrary additional properties.
208
+ [key: string]: any
203
209
  }) {
204
210
  return new Decoration(from, to, new InlineType(attrs, spec))
205
211
  }
package/src/domcoords.ts CHANGED
@@ -260,7 +260,7 @@ export function posAtCoords(view: EditorView, coords: {top: number, left: number
260
260
  }
261
261
 
262
262
  let elt = ((view.root as any).elementFromPoint ? view.root : doc)
263
- .elementFromPoint(coords.left, coords.top + 1) as HTMLElement
263
+ .elementFromPoint(coords.left, coords.top) as HTMLElement
264
264
  let pos
265
265
  if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
266
266
  let box = view.dom.getBoundingClientRect()
@@ -84,8 +84,10 @@ export class DOMObserver {
84
84
  }
85
85
 
86
86
  start() {
87
- if (this.observer)
87
+ if (this.observer) {
88
+ this.observer.takeRecords()
88
89
  this.observer.observe(this.view.dom, observeOptions)
90
+ }
89
91
  if (this.onCharData)
90
92
  this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData)
91
93
  this.connectSelection()
package/src/index.ts CHANGED
@@ -537,7 +537,7 @@ export interface EditorProps {
537
537
  /// `preventDefault` yourself (or not, if you want to allow the
538
538
  /// default behavior).
539
539
  handleDOMEvents?: {
540
- [event in string]: (view: EditorView, event: DOMEventMap[event]) => boolean | void
540
+ [event in keyof DOMEventMap]?: (view: EditorView, event: DOMEventMap[event]) => boolean | void
541
541
  }
542
542
 
543
543
  /// Called when the editor receives a `keydown` event.
@@ -579,7 +579,7 @@ export interface EditorProps {
579
579
  /// Called when something is dropped on the editor. `moved` will be
580
580
  /// true if this drop moves from the current selection (which should
581
581
  /// thus be deleted).
582
- handleDrop?: (view: EditorView, event: MouseEvent, slice: Slice, moved: boolean) => boolean | void
582
+ handleDrop?: (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void
583
583
 
584
584
  /// Called when the view, after updating its state, tries to scroll
585
585
  /// the selection into view. A handler function may return false to
@@ -672,7 +672,7 @@ export interface EditorProps {
672
672
 
673
673
  /// A set of [document decorations](#view.Decoration) to show in the
674
674
  /// view.
675
- decorations?: (state: EditorState) => DecorationSource | null
675
+ decorations?: (state: EditorState) => DecorationSource | null | undefined
676
676
 
677
677
  /// When this returns false, the content of the view is not directly
678
678
  /// editable.