prosemirror-view 1.34.3 → 1.35.0

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,9 @@
1
+ ## 1.35.0 (2024-10-29)
2
+
3
+ ### New features
4
+
5
+ The new `NodeView.multiType` flag is now required to opt into handling different node types in a single node view. It used to be the default, but this tripped too many people up.
6
+
1
7
  ## 1.34.3 (2024-09-19)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1564,7 +1564,7 @@ var CustomNodeViewDesc = function (_NodeViewDesc2) {
1564
1564
  key: "update",
1565
1565
  value: function update(node, outerDeco, innerDeco, view) {
1566
1566
  if (this.dirty == NODE_DIRTY) return false;
1567
- if (this.spec.update) {
1567
+ if (this.spec.update && (this.node.type == node.type || this.spec.multiType)) {
1568
1568
  var result = this.spec.update(node, outerDeco, innerDeco);
1569
1569
  if (result) this.updateInner(node, outerDeco, innerDeco, view);
1570
1570
  return result;
@@ -2927,7 +2927,7 @@ editHandlers.keydown = function (view, _event) {
2927
2927
  view.input.lastKeyCode = event.keyCode;
2928
2928
  view.input.lastKeyCodeTime = Date.now();
2929
2929
  if (android && chrome && event.keyCode == 13) return;
2930
- if (view.domObserver.selectionChanged(view.domSelectionRange())) view.domObserver.flush();else if (event.keyCode != 229) view.domObserver.forceFlush();
2930
+ if (event.keyCode != 229) view.domObserver.forceFlush();
2931
2931
  if (ios && event.keyCode == 13 && !event.ctrlKey && !event.altKey && !event.metaKey) {
2932
2932
  var now = Date.now();
2933
2933
  view.input.lastIOSEnter = now;
@@ -4292,11 +4292,6 @@ var DOMObserver = function () {
4292
4292
  }
4293
4293
  return this.queue;
4294
4294
  }
4295
- }, {
4296
- key: "selectionChanged",
4297
- value: function selectionChanged(sel) {
4298
- return !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(this.view) && !this.ignoreSelectionChange(sel);
4299
- }
4300
4295
  }, {
4301
4296
  key: "flush",
4302
4297
  value: function flush() {
@@ -4304,8 +4299,8 @@ var DOMObserver = function () {
4304
4299
  if (!view.docView || this.flushingSoon > -1) return;
4305
4300
  var mutations = this.pendingRecords();
4306
4301
  if (mutations.length) this.queue = [];
4307
- var sel = view.domSelectionRange(),
4308
- newSel = this.selectionChanged(sel);
4302
+ var sel = view.domSelectionRange();
4303
+ var newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(view) && !this.ignoreSelectionChange(sel);
4309
4304
  var from = -1,
4310
4305
  to = -1,
4311
4306
  typeOver = false,
package/dist/index.d.cts CHANGED
@@ -265,19 +265,28 @@ interface NodeView {
265
265
  */
266
266
  contentDOM?: HTMLElement | null;
267
267
  /**
268
- When given, this will be called when the view is updating itself.
269
- It will be given a node (possibly of a different type), an array
270
- of active decorations around the node (which are automatically
271
- drawn, and the node view may ignore if it isn't interested in
272
- them), and a [decoration source](https://prosemirror.net/docs/ref/#view.DecorationSource) that
273
- represents any decorations that apply to the content of the node
274
- (which again may be ignored). It should return true if it was
275
- able to update to that node, and false otherwise. If the node
276
- view has a `contentDOM` property (or no `dom` property), updating
277
- its child nodes will be handled by ProseMirror.
268
+ When given, this will be called when the view is updating
269
+ itself. It will be given a node, an array of active decorations
270
+ around the node (which are automatically drawn, and the node
271
+ view may ignore if it isn't interested in them), and a
272
+ [decoration source](https://prosemirror.net/docs/ref/#view.DecorationSource) that represents any
273
+ decorations that apply to the content of the node (which again
274
+ may be ignored). It should return true if it was able to update
275
+ to that node, and false otherwise. If the node view has a
276
+ `contentDOM` property (or no `dom` property), updating its child
277
+ nodes will be handled by ProseMirror.
278
278
  */
279
279
  update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean;
280
280
  /**
281
+ By default, `update` will only be called when a node of the same
282
+ node type appears in this view's position. When you set this to
283
+ true, it will be called for any node, making it possible to have
284
+ a node view that representsmultiple types of nodes. You will
285
+ need to check the type of the nodes you get in `update` and
286
+ return `false` for types you cannot handle.
287
+ */
288
+ multiType?: boolean;
289
+ /**
281
290
  Can be used to override the way the node's selected status (as a
282
291
  node selection) is displayed.
283
292
  */
package/dist/index.d.ts CHANGED
@@ -265,19 +265,28 @@ interface NodeView {
265
265
  */
266
266
  contentDOM?: HTMLElement | null;
267
267
  /**
268
- When given, this will be called when the view is updating itself.
269
- It will be given a node (possibly of a different type), an array
270
- of active decorations around the node (which are automatically
271
- drawn, and the node view may ignore if it isn't interested in
272
- them), and a [decoration source](https://prosemirror.net/docs/ref/#view.DecorationSource) that
273
- represents any decorations that apply to the content of the node
274
- (which again may be ignored). It should return true if it was
275
- able to update to that node, and false otherwise. If the node
276
- view has a `contentDOM` property (or no `dom` property), updating
277
- its child nodes will be handled by ProseMirror.
268
+ When given, this will be called when the view is updating
269
+ itself. It will be given a node, an array of active decorations
270
+ around the node (which are automatically drawn, and the node
271
+ view may ignore if it isn't interested in them), and a
272
+ [decoration source](https://prosemirror.net/docs/ref/#view.DecorationSource) that represents any
273
+ decorations that apply to the content of the node (which again
274
+ may be ignored). It should return true if it was able to update
275
+ to that node, and false otherwise. If the node view has a
276
+ `contentDOM` property (or no `dom` property), updating its child
277
+ nodes will be handled by ProseMirror.
278
278
  */
279
279
  update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean;
280
280
  /**
281
+ By default, `update` will only be called when a node of the same
282
+ node type appears in this view's position. When you set this to
283
+ true, it will be called for any node, making it possible to have
284
+ a node view that representsmultiple types of nodes. You will
285
+ need to check the type of the nodes you get in `update` and
286
+ return `false` for types you cannot handle.
287
+ */
288
+ multiType?: boolean;
289
+ /**
281
290
  Can be used to override the way the node's selected status (as a
282
291
  node selection) is displayed.
283
292
  */
package/dist/index.js CHANGED
@@ -1552,7 +1552,7 @@ class CustomNodeViewDesc extends NodeViewDesc {
1552
1552
  update(node, outerDeco, innerDeco, view) {
1553
1553
  if (this.dirty == NODE_DIRTY)
1554
1554
  return false;
1555
- if (this.spec.update) {
1555
+ if (this.spec.update && (this.node.type == node.type || this.spec.multiType)) {
1556
1556
  let result = this.spec.update(node, outerDeco, innerDeco);
1557
1557
  if (result)
1558
1558
  this.updateInner(node, outerDeco, innerDeco, view);
@@ -3111,9 +3111,7 @@ editHandlers.keydown = (view, _event) => {
3111
3111
  // and handling them eagerly tends to corrupt the input.
3112
3112
  if (android && chrome && event.keyCode == 13)
3113
3113
  return;
3114
- if (view.domObserver.selectionChanged(view.domSelectionRange()))
3115
- view.domObserver.flush();
3116
- else if (event.keyCode != 229)
3114
+ if (event.keyCode != 229)
3117
3115
  view.domObserver.forceFlush();
3118
3116
  // On iOS, if we preventDefault enter key presses, the virtual
3119
3117
  // keyboard gets confused. So the hack here is to set a flag that
@@ -4636,9 +4634,6 @@ class DOMObserver {
4636
4634
  this.queue.push(mut);
4637
4635
  return this.queue;
4638
4636
  }
4639
- selectionChanged(sel) {
4640
- return !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(this.view) && !this.ignoreSelectionChange(sel);
4641
- }
4642
4637
  flush() {
4643
4638
  let { view } = this;
4644
4639
  if (!view.docView || this.flushingSoon > -1)
@@ -4646,7 +4641,8 @@ class DOMObserver {
4646
4641
  let mutations = this.pendingRecords();
4647
4642
  if (mutations.length)
4648
4643
  this.queue = [];
4649
- let sel = view.domSelectionRange(), newSel = this.selectionChanged(sel);
4644
+ let sel = view.domSelectionRange();
4645
+ let newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(view) && !this.ignoreSelectionChange(sel);
4650
4646
  let from = -1, to = -1, typeOver = false, added = [];
4651
4647
  if (view.editable) {
4652
4648
  for (let i = 0; i < mutations.length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.34.3",
3
+ "version": "1.35.0",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -163,17 +163,14 @@ export class DOMObserver {
163
163
  return this.queue
164
164
  }
165
165
 
166
- selectionChanged(sel: DOMSelectionRange) {
167
- return !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(this.view) && !this.ignoreSelectionChange(sel)
168
- }
169
-
170
166
  flush() {
171
167
  let {view} = this
172
168
  if (!view.docView || this.flushingSoon > -1) return
173
169
  let mutations = this.pendingRecords()
174
170
  if (mutations.length) this.queue = []
175
171
 
176
- let sel = view.domSelectionRange(), newSel = this.selectionChanged(sel)
172
+ let sel = view.domSelectionRange()
173
+ let newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(view) && !this.ignoreSelectionChange(sel)
177
174
 
178
175
  let from = -1, to = -1, typeOver = false, added: Node[] = []
179
176
  if (view.editable) {
package/src/input.ts CHANGED
@@ -112,9 +112,7 @@ editHandlers.keydown = (view: EditorView, _event: Event) => {
112
112
  // to be part of a confused sequence of composition events fired,
113
113
  // and handling them eagerly tends to corrupt the input.
114
114
  if (browser.android && browser.chrome && event.keyCode == 13) return
115
-
116
- if (view.domObserver.selectionChanged(view.domSelectionRange())) view.domObserver.flush()
117
- else if (event.keyCode != 229) view.domObserver.forceFlush()
115
+ if (event.keyCode != 229) view.domObserver.forceFlush()
118
116
 
119
117
  // On iOS, if we preventDefault enter key presses, the virtual
120
118
  // keyboard gets confused. So the hack here is to set a flag that
package/src/viewdesc.ts CHANGED
@@ -33,18 +33,26 @@ export interface NodeView {
33
33
  /// (or deciding not to render) its child nodes.
34
34
  contentDOM?: HTMLElement | null
35
35
 
36
- /// When given, this will be called when the view is updating itself.
37
- /// It will be given a node (possibly of a different type), an array
38
- /// of active decorations around the node (which are automatically
39
- /// drawn, and the node view may ignore if it isn't interested in
40
- /// them), and a [decoration source](#view.DecorationSource) that
41
- /// represents any decorations that apply to the content of the node
42
- /// (which again may be ignored). It should return true if it was
43
- /// able to update to that node, and false otherwise. If the node
44
- /// view has a `contentDOM` property (or no `dom` property), updating
45
- /// its child nodes will be handled by ProseMirror.
36
+ /// When given, this will be called when the view is updating
37
+ /// itself. It will be given a node, an array of active decorations
38
+ /// around the node (which are automatically drawn, and the node
39
+ /// view may ignore if it isn't interested in them), and a
40
+ /// [decoration source](#view.DecorationSource) that represents any
41
+ /// decorations that apply to the content of the node (which again
42
+ /// may be ignored). It should return true if it was able to update
43
+ /// to that node, and false otherwise. If the node view has a
44
+ /// `contentDOM` property (or no `dom` property), updating its child
45
+ /// nodes will be handled by ProseMirror.
46
46
  update?: (node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource) => boolean
47
47
 
48
+ /// By default, `update` will only be called when a node of the same
49
+ /// node type appears in this view's position. When you set this to
50
+ /// true, it will be called for any node, making it possible to have
51
+ /// a node view that representsmultiple types of nodes. You will
52
+ /// need to check the type of the nodes you get in `update` and
53
+ /// return `false` for types you cannot handle.
54
+ multiType?: boolean
55
+
48
56
  /// Can be used to override the way the node's selected status (as a
49
57
  /// node selection) is displayed.
50
58
  selectNode?: () => void
@@ -938,7 +946,7 @@ class CustomNodeViewDesc extends NodeViewDesc {
938
946
  // updates the children.
939
947
  update(node: Node, outerDeco: readonly Decoration[], innerDeco: DecorationSource, view: EditorView) {
940
948
  if (this.dirty == NODE_DIRTY) return false
941
- if (this.spec.update) {
949
+ if (this.spec.update && (this.node.type == node.type || this.spec.multiType)) {
942
950
  let result = this.spec.update(node, outerDeco, innerDeco)
943
951
  if (result) this.updateInner(node, outerDeco, innerDeco, view)
944
952
  return result