prosemirror-view 1.33.2 → 1.33.4

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/src/viewdesc.ts CHANGED
@@ -1,7 +1,7 @@
1
- import {DOMSerializer, Fragment, Mark, Node, ParseRule} from "prosemirror-model"
1
+ import {DOMSerializer, Fragment, Mark, Node, TagParseRule} from "prosemirror-model"
2
2
  import {TextSelection} from "prosemirror-state"
3
3
 
4
- import {domIndex, isEquivalentPosition, DOMNode, textNodeBefore, textNodeAfter} from "./dom"
4
+ import {domIndex, isEquivalentPosition, DOMNode} from "./dom"
5
5
  import * as browser from "./browser"
6
6
  import {Decoration, DecorationSource, WidgetConstructor, WidgetType, NodeType} from "./decoration"
7
7
  import {EditorView} from "./index"
@@ -124,7 +124,7 @@ export class ViewDesc {
124
124
  // When parsing in-editor content (in domchange.js), we allow
125
125
  // descriptions to determine the parse rules that should be used to
126
126
  // parse them.
127
- parseRule(): ParseRule | null { return null }
127
+ parseRule(): Omit<TagParseRule, "tag"> | null { return null }
128
128
 
129
129
  // Used by the editor's event handler to ignore events that come
130
130
  // from certain descs.
@@ -485,6 +485,8 @@ export class ViewDesc {
485
485
  get domAtom() { return false }
486
486
 
487
487
  get ignoreForCoords() { return false }
488
+
489
+ isText(text: string) { return false }
488
490
  }
489
491
 
490
492
  // A widget desc represents a widget decoration, which is a DOM node
@@ -574,7 +576,7 @@ class MarkViewDesc extends ViewDesc {
574
576
  return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom as HTMLElement)
575
577
  }
576
578
 
577
- parseRule(): ParseRule | null {
579
+ parseRule() {
578
580
  if ((this.dirty & NODE_DIRTY) || this.mark.type.spec.reparseInView) return null
579
581
  return {mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM!}
580
582
  }
@@ -664,14 +666,14 @@ export class NodeViewDesc extends ViewDesc {
664
666
  return new NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, view, pos + 1)
665
667
  }
666
668
 
667
- parseRule(): ParseRule | null {
669
+ parseRule() {
668
670
  // Experimental kludge to allow opt-in re-parsing of nodes
669
671
  if (this.node.type.spec.reparseInView) return null
670
672
  // FIXME the assumption that this can always return the current
671
673
  // attrs means that if the user somehow manages to change the
672
674
  // attrs in the dom, that won't be picked up. Not entirely sure
673
675
  // whether this is a problem
674
- let rule: ParseRule = {node: this.node.type.name, attrs: this.node.attrs}
676
+ let rule: Omit<TagParseRule, "tag"> = {node: this.node.type.name, attrs: this.node.attrs}
675
677
  if (this.node.type.whitespace == "pre") rule.preserveWhitespace = "full"
676
678
  if (!this.contentDOM) {
677
679
  rule.getContent = () => this.node.content
@@ -759,15 +761,7 @@ export class NodeViewDesc extends ViewDesc {
759
761
  // are inside of this node
760
762
  let {from, to} = view.state.selection
761
763
  if (!(view.state.selection instanceof TextSelection) || from < pos || to > pos + this.node.content.size) return null
762
- let sel = view.domSelectionRange()
763
- let textBefore = textNodeBefore(sel.focusNode!, sel.focusOffset)
764
- let textAfter = textNodeAfter(sel.focusNode!, sel.focusOffset)
765
- let textNode = textBefore || textAfter
766
- if (textBefore && textAfter && textBefore != textAfter) {
767
- let descAfter = textAfter.pmViewDesc
768
- if (!descAfter || descAfter instanceof TextViewDesc && descAfter.node.text != textAfter.nodeValue)
769
- textNode = textAfter
770
- }
764
+ let textNode = view.input.compositionNode
771
765
  if (!textNode || !this.dom.contains(textNode.parentNode)) return null
772
766
 
773
767
  if (this.node.inlineContent) {
@@ -863,7 +857,7 @@ class TextViewDesc extends NodeViewDesc {
863
857
  super(parent, node, outerDeco, innerDeco, dom, null, nodeDOM, view, 0)
864
858
  }
865
859
 
866
- parseRule(): ParseRule {
860
+ parseRule() {
867
861
  let skip = this.nodeDOM.parentNode
868
862
  while (skip && skip != this.dom && !(skip as any).pmIsDeco) skip = skip.parentNode
869
863
  return {skip: (skip || true) as any}
@@ -913,6 +907,8 @@ class TextViewDesc extends NodeViewDesc {
913
907
  }
914
908
 
915
909
  get domAtom() { return false }
910
+
911
+ isText(text: string) { return this.node.text == text }
916
912
  }
917
913
 
918
914
  // A dummy desc used to tag trailing BR or IMG nodes created to work