prosemirror-view 1.26.5 → 1.27.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,13 @@
1
+ ## 1.27.0 (2022-07-20)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that in some situations caused composition to be disrupted on Chrome due to a workaround for another browser issue activating inappropriately.
6
+
7
+ ### New features
8
+
9
+ `EditorProps` now takes an optional type parameter that indicates the type of `this` in prop functions.
10
+
1
11
  ## 1.26.5 (2022-07-07)
2
12
 
3
13
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -5049,7 +5049,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
5049
5049
  var sel = view.state.selection;
5050
5050
  var parse = parseBetween(view, from, to);
5051
5051
 
5052
- if (chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from) {
5052
+ if (chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from && parse.sel.head == parse.sel.anchor) {
5053
5053
  var text = view.cursorWrapper.deco.type.toDOM.nextSibling;
5054
5054
  var size = text && text.nodeValue ? text.nodeValue.length : 1;
5055
5055
  parse.sel = {
package/dist/index.d.ts CHANGED
@@ -580,8 +580,12 @@ called one at a time, starting with the base props and then
580
580
  searching through the plugins (in order of appearance) until one of
581
581
  them returns true. For some props, the first plugin that yields a
582
582
  value gets precedence.
583
+
584
+ The optional type parameter refers to the type of `this` in prop
585
+ functions, and is used to pass in the plugin type when defining a
586
+ [plugin](https://prosemirror.net/docs/ref/#state.Plugin).
583
587
  */
584
- interface EditorProps {
588
+ interface EditorProps<P = any> {
585
589
  /**
586
590
  Can be an object mapping DOM event type names to functions that
587
591
  handle them. Such functions will be called before any handling
@@ -592,72 +596,72 @@ interface EditorProps {
592
596
  default behavior).
593
597
  */
594
598
  handleDOMEvents?: {
595
- [event in keyof DOMEventMap]?: (view: EditorView, event: DOMEventMap[event]) => boolean | void;
599
+ [event in keyof DOMEventMap]?: (this: P, view: EditorView, event: DOMEventMap[event]) => boolean | void;
596
600
  };
597
601
  /**
598
602
  Called when the editor receives a `keydown` event.
599
603
  */
600
- handleKeyDown?: (view: EditorView, event: KeyboardEvent) => boolean | void;
604
+ handleKeyDown?: (this: P, view: EditorView, event: KeyboardEvent) => boolean | void;
601
605
  /**
602
606
  Handler for `keypress` events.
603
607
  */
604
- handleKeyPress?: (view: EditorView, event: KeyboardEvent) => boolean | void;
608
+ handleKeyPress?: (this: P, view: EditorView, event: KeyboardEvent) => boolean | void;
605
609
  /**
606
610
  Whenever the user directly input text, this handler is called
607
611
  before the input is applied. If it returns `true`, the default
608
612
  behavior of actually inserting the text is suppressed.
609
613
  */
610
- handleTextInput?: (view: EditorView, from: number, to: number, text: string) => boolean | void;
614
+ handleTextInput?: (this: P, view: EditorView, from: number, to: number, text: string) => boolean | void;
611
615
  /**
612
616
  Called for each node around a click, from the inside out. The
613
617
  `direct` flag will be true for the inner node.
614
618
  */
615
- handleClickOn?: (view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
619
+ handleClickOn?: (this: P, view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
616
620
  /**
617
621
  Called when the editor is clicked, after `handleClickOn` handlers
618
622
  have been called.
619
623
  */
620
- handleClick?: (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
624
+ handleClick?: (this: P, view: EditorView, pos: number, event: MouseEvent) => boolean | void;
621
625
  /**
622
626
  Called for each node around a double click.
623
627
  */
624
- handleDoubleClickOn?: (view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
628
+ handleDoubleClickOn?: (this: P, view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
625
629
  /**
626
630
  Called when the editor is double-clicked, after `handleDoubleClickOn`.
627
631
  */
628
- handleDoubleClick?: (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
632
+ handleDoubleClick?: (this: P, view: EditorView, pos: number, event: MouseEvent) => boolean | void;
629
633
  /**
630
634
  Called for each node around a triple click.
631
635
  */
632
- handleTripleClickOn?: (view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
636
+ handleTripleClickOn?: (this: P, view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void;
633
637
  /**
634
638
  Called when the editor is triple-clicked, after `handleTripleClickOn`.
635
639
  */
636
- handleTripleClick?: (view: EditorView, pos: number, event: MouseEvent) => boolean | void;
640
+ handleTripleClick?: (this: P, view: EditorView, pos: number, event: MouseEvent) => boolean | void;
637
641
  /**
638
642
  Can be used to override the behavior of pasting. `slice` is the
639
643
  pasted content parsed by the editor, but you can directly access
640
644
  the event to get at the raw content.
641
645
  */
642
- handlePaste?: (view: EditorView, event: ClipboardEvent, slice: Slice) => boolean | void;
646
+ handlePaste?: (this: P, view: EditorView, event: ClipboardEvent, slice: Slice) => boolean | void;
643
647
  /**
644
648
  Called when something is dropped on the editor. `moved` will be
645
649
  true if this drop moves from the current selection (which should
646
650
  thus be deleted).
647
651
  */
648
- handleDrop?: (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void;
652
+ handleDrop?: (this: P, view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void;
649
653
  /**
650
654
  Called when the view, after updating its state, tries to scroll
651
655
  the selection into view. A handler function may return false to
652
656
  indicate that it did not handle the scrolling and further
653
657
  handlers or the default behavior should be tried.
654
658
  */
655
- handleScrollToSelection?: (view: EditorView) => boolean;
659
+ handleScrollToSelection?: (this: P, view: EditorView) => boolean;
656
660
  /**
657
661
  Can be used to override the way a selection is created when
658
662
  reading a DOM selection between the given anchor and head.
659
663
  */
660
- createSelectionBetween?: (view: EditorView, anchor: ResolvedPos, head: ResolvedPos) => Selection | null;
664
+ createSelectionBetween?: (this: P, view: EditorView, anchor: ResolvedPos, head: ResolvedPos) => Selection | null;
661
665
  /**
662
666
  The [parser](https://prosemirror.net/docs/ref/#model.DOMParser) to use when reading editor changes
663
667
  from the DOM. Defaults to calling
@@ -669,7 +673,7 @@ interface EditorProps {
669
673
  Can be used to transform pasted HTML text, _before_ it is parsed,
670
674
  for example to clean it up.
671
675
  */
672
- transformPastedHTML?: (html: string) => string;
676
+ transformPastedHTML?: (this: P, html: string) => string;
673
677
  /**
674
678
  The [parser](https://prosemirror.net/docs/ref/#model.DOMParser) to use when reading content from
675
679
  the clipboard. When not given, the value of the
@@ -680,7 +684,7 @@ interface EditorProps {
680
684
  Transform pasted plain text. The `plain` flag will be true when
681
685
  the text is pasted as plain text.
682
686
  */
683
- transformPastedText?: (text: string, plain: boolean) => string;
687
+ transformPastedText?: (this: P, text: string, plain: boolean) => string;
684
688
  /**
685
689
  A function to parse text from the clipboard into a document
686
690
  slice. Called after
@@ -690,12 +694,12 @@ interface EditorProps {
690
694
  [`clipboardParser`](https://prosemirror.net/docs/ref/#view.EditorProps.clipboardParser) on it.
691
695
  The `plain` flag will be true when the text is pasted as plain text.
692
696
  */
693
- clipboardTextParser?: (text: string, $context: ResolvedPos, plain: boolean) => Slice;
697
+ clipboardTextParser?: (this: P, text: string, $context: ResolvedPos, plain: boolean) => Slice;
694
698
  /**
695
699
  Can be used to transform pasted content before it is applied to
696
700
  the document.
697
701
  */
698
- transformPasted?: (slice: Slice) => Slice;
702
+ transformPasted?: (this: P, slice: Slice) => Slice;
699
703
  /**
700
704
  Allows you to pass custom rendering and behavior logic for
701
705
  nodes. Should map node names to constructor functions that
@@ -750,17 +754,17 @@ interface EditorProps {
750
754
  editor will use [`textBetween`](https://prosemirror.net/docs/ref/#model.Node.textBetween) on the
751
755
  selected range.
752
756
  */
753
- clipboardTextSerializer?: (content: Slice) => string;
757
+ clipboardTextSerializer?: (this: P, content: Slice) => string;
754
758
  /**
755
759
  A set of [document decorations](https://prosemirror.net/docs/ref/#view.Decoration) to show in the
756
760
  view.
757
761
  */
758
- decorations?: (state: EditorState) => DecorationSource | null | undefined;
762
+ decorations?: (this: P, state: EditorState) => DecorationSource | null | undefined;
759
763
  /**
760
764
  When this returns false, the content of the view is not directly
761
765
  editable.
762
766
  */
763
- editable?: (state: EditorState) => boolean;
767
+ editable?: (this: P, state: EditorState) => boolean;
764
768
  /**
765
769
  Control the DOM attributes of the editable element. May be either
766
770
  an object or a function going from an editor state to an object.
package/dist/index.js CHANGED
@@ -4501,7 +4501,8 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
4501
4501
  let parse = parseBetween(view, from, to);
4502
4502
  // Chrome sometimes leaves the cursor before the inserted text when
4503
4503
  // composing after a cursor wrapper. This moves it forward.
4504
- if (chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from) {
4504
+ if (chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from &&
4505
+ parse.sel.head == parse.sel.anchor) {
4505
4506
  let text = view.cursorWrapper.deco.type.toDOM.nextSibling;
4506
4507
  let size = text && text.nodeValue ? text.nodeValue.length : 1;
4507
4508
  parse.sel = { anchor: parse.sel.anchor + size, head: parse.sel.anchor + size };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-view",
3
- "version": "1.26.5",
3
+ "version": "1.27.0",
4
4
  "description": "ProseMirror's view component",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/src/domchange.ts CHANGED
@@ -99,7 +99,8 @@ export function readDOMChange(view: EditorView, from: number, to: number, typeOv
99
99
 
100
100
  // Chrome sometimes leaves the cursor before the inserted text when
101
101
  // composing after a cursor wrapper. This moves it forward.
102
- if (browser.chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from) {
102
+ if (browser.chrome && view.cursorWrapper && parse.sel && parse.sel.anchor == view.cursorWrapper.deco.from &&
103
+ parse.sel.head == parse.sel.anchor) {
103
104
  let text = (view.cursorWrapper.deco.type as any).toDOM.nextSibling as DOMNode
104
105
  let size = text && text.nodeValue ? text.nodeValue.length : 1
105
106
  parse.sel = {anchor: parse.sel.anchor + size, head: parse.sel.anchor + size}
package/src/index.ts CHANGED
@@ -528,7 +528,11 @@ export interface DOMEventMap extends HTMLElementEventMap {
528
528
  /// searching through the plugins (in order of appearance) until one of
529
529
  /// them returns true. For some props, the first plugin that yields a
530
530
  /// value gets precedence.
531
- export interface EditorProps {
531
+ ///
532
+ /// The optional type parameter refers to the type of `this` in prop
533
+ /// functions, and is used to pass in the plugin type when defining a
534
+ /// [plugin](#state.Plugin).
535
+ export interface EditorProps<P = any> {
532
536
  /// Can be an object mapping DOM event type names to functions that
533
537
  /// handle them. Such functions will be called before any handling
534
538
  /// ProseMirror does of events fired on the editable DOM element.
@@ -537,59 +541,59 @@ export interface EditorProps {
537
541
  /// `preventDefault` yourself (or not, if you want to allow the
538
542
  /// default behavior).
539
543
  handleDOMEvents?: {
540
- [event in keyof DOMEventMap]?: (view: EditorView, event: DOMEventMap[event]) => boolean | void
544
+ [event in keyof DOMEventMap]?: (this: P, view: EditorView, event: DOMEventMap[event]) => boolean | void
541
545
  }
542
546
 
543
547
  /// Called when the editor receives a `keydown` event.
544
- handleKeyDown?: (view: EditorView, event: KeyboardEvent) => boolean | void
548
+ handleKeyDown?: (this: P, view: EditorView, event: KeyboardEvent) => boolean | void
545
549
 
546
550
  /// Handler for `keypress` events.
547
- handleKeyPress?: (view: EditorView, event: KeyboardEvent) => boolean | void
551
+ handleKeyPress?: (this: P, view: EditorView, event: KeyboardEvent) => boolean | void
548
552
 
549
553
  /// Whenever the user directly input text, this handler is called
550
554
  /// before the input is applied. If it returns `true`, the default
551
555
  /// behavior of actually inserting the text is suppressed.
552
- handleTextInput?: (view: EditorView, from: number, to: number, text: string) => boolean | void
556
+ handleTextInput?: (this: P, view: EditorView, from: number, to: number, text: string) => boolean | void
553
557
 
554
558
  /// Called for each node around a click, from the inside out. The
555
559
  /// `direct` flag will be true for the inner node.
556
- handleClickOn?: (view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void
560
+ handleClickOn?: (this: P, view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void
557
561
 
558
562
  /// Called when the editor is clicked, after `handleClickOn` handlers
559
563
  /// have been called.
560
- handleClick?: (view: EditorView, pos: number, event: MouseEvent) => boolean | void
564
+ handleClick?: (this: P, view: EditorView, pos: number, event: MouseEvent) => boolean | void
561
565
 
562
566
  /// Called for each node around a double click.
563
- handleDoubleClickOn?: (view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void
567
+ handleDoubleClickOn?: (this: P, view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void
564
568
 
565
569
  /// Called when the editor is double-clicked, after `handleDoubleClickOn`.
566
- handleDoubleClick?: (view: EditorView, pos: number, event: MouseEvent) => boolean | void
570
+ handleDoubleClick?: (this: P, view: EditorView, pos: number, event: MouseEvent) => boolean | void
567
571
 
568
572
  /// Called for each node around a triple click.
569
- handleTripleClickOn?: (view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void
573
+ handleTripleClickOn?: (this: P, view: EditorView, pos: number, node: Node, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void
570
574
 
571
575
  /// Called when the editor is triple-clicked, after `handleTripleClickOn`.
572
- handleTripleClick?: (view: EditorView, pos: number, event: MouseEvent) => boolean | void
576
+ handleTripleClick?: (this: P, view: EditorView, pos: number, event: MouseEvent) => boolean | void
573
577
 
574
578
  /// Can be used to override the behavior of pasting. `slice` is the
575
579
  /// pasted content parsed by the editor, but you can directly access
576
580
  /// the event to get at the raw content.
577
- handlePaste?: (view: EditorView, event: ClipboardEvent, slice: Slice) => boolean | void
581
+ handlePaste?: (this: P, view: EditorView, event: ClipboardEvent, slice: Slice) => boolean | void
578
582
 
579
583
  /// Called when something is dropped on the editor. `moved` will be
580
584
  /// true if this drop moves from the current selection (which should
581
585
  /// thus be deleted).
582
- handleDrop?: (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void
586
+ handleDrop?: (this: P, view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void
583
587
 
584
588
  /// Called when the view, after updating its state, tries to scroll
585
589
  /// the selection into view. A handler function may return false to
586
590
  /// indicate that it did not handle the scrolling and further
587
591
  /// handlers or the default behavior should be tried.
588
- handleScrollToSelection?: (view: EditorView) => boolean
592
+ handleScrollToSelection?: (this: P, view: EditorView) => boolean
589
593
 
590
594
  /// Can be used to override the way a selection is created when
591
595
  /// reading a DOM selection between the given anchor and head.
592
- createSelectionBetween?: (view: EditorView, anchor: ResolvedPos, head: ResolvedPos) => Selection | null
596
+ createSelectionBetween?: (this: P, view: EditorView, anchor: ResolvedPos, head: ResolvedPos) => Selection | null
593
597
 
594
598
  /// The [parser](#model.DOMParser) to use when reading editor changes
595
599
  /// from the DOM. Defaults to calling
@@ -599,7 +603,7 @@ export interface EditorProps {
599
603
 
600
604
  /// Can be used to transform pasted HTML text, _before_ it is parsed,
601
605
  /// for example to clean it up.
602
- transformPastedHTML?: (html: string) => string
606
+ transformPastedHTML?: (this: P, html: string) => string
603
607
 
604
608
  /// The [parser](#model.DOMParser) to use when reading content from
605
609
  /// the clipboard. When not given, the value of the
@@ -608,7 +612,7 @@ export interface EditorProps {
608
612
 
609
613
  /// Transform pasted plain text. The `plain` flag will be true when
610
614
  /// the text is pasted as plain text.
611
- transformPastedText?: (text: string, plain: boolean) => string
615
+ transformPastedText?: (this: P, text: string, plain: boolean) => string
612
616
 
613
617
  /// A function to parse text from the clipboard into a document
614
618
  /// slice. Called after
@@ -617,11 +621,11 @@ export interface EditorProps {
617
621
  /// in `<p>` tags, and call
618
622
  /// [`clipboardParser`](#view.EditorProps.clipboardParser) on it.
619
623
  /// The `plain` flag will be true when the text is pasted as plain text.
620
- clipboardTextParser?: (text: string, $context: ResolvedPos, plain: boolean) => Slice
624
+ clipboardTextParser?: (this: P, text: string, $context: ResolvedPos, plain: boolean) => Slice
621
625
 
622
626
  /// Can be used to transform pasted content before it is applied to
623
627
  /// the document.
624
- transformPasted?: (slice: Slice) => Slice
628
+ transformPasted?: (this: P, slice: Slice) => Slice
625
629
 
626
630
  /// Allows you to pass custom rendering and behavior logic for
627
631
  /// nodes. Should map node names to constructor functions that
@@ -668,15 +672,15 @@ export interface EditorProps {
668
672
  /// selection when copying text to the clipboard. By default, the
669
673
  /// editor will use [`textBetween`](#model.Node.textBetween) on the
670
674
  /// selected range.
671
- clipboardTextSerializer?: (content: Slice) => string
675
+ clipboardTextSerializer?: (this: P, content: Slice) => string
672
676
 
673
677
  /// A set of [document decorations](#view.Decoration) to show in the
674
678
  /// view.
675
- decorations?: (state: EditorState) => DecorationSource | null | undefined
679
+ decorations?: (this: P, state: EditorState) => DecorationSource | null | undefined
676
680
 
677
681
  /// When this returns false, the content of the view is not directly
678
682
  /// editable.
679
- editable?: (state: EditorState) => boolean
683
+ editable?: (this: P, state: EditorState) => boolean
680
684
 
681
685
  /// Control the DOM attributes of the editable element. May be either
682
686
  /// an object or a function going from an editor state to an object.