Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#45778 prosemirror-view: Add 'plain' param …
Browse files Browse the repository at this point in the history
…to two APIs by @mmorearty

As of prosemirror-view 1.15, transformPastedText() and clipboardTextParser()
are passed a `plain: boolean` parameter.
  • Loading branch information
mmorearty authored and ngbrown committed Jul 11, 2020
1 parent 28512de commit 19c51b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
11 changes: 7 additions & 4 deletions types/prosemirror-view/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for prosemirror-view 1.11
// Type definitions for prosemirror-view 1.15
// Project: https://github.com/ProseMirror/prosemirror-view
// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
// David Hahn <https://github.com/davidka>
Expand Down Expand Up @@ -530,18 +530,21 @@ export interface EditorProps<ThisT = unknown, S extends Schema = any> {
*/
clipboardParser?: DOMParser<S> | null;
/**
* Transform pasted plain text.
* Transform pasted plain text. The `plain` flag will be true when
* the text is pasted as plain text.
*/
transformPastedText?: ((this: ThisT, text: string) => string) | null;
transformPastedText?: ((this: ThisT, text: string, plain: boolean) => string) | null;
/**
* A function to parse text from the clipboard into a document
* slice. Called after
* [`transformPastedText`](#view.EditorProps.transformPastedText).
* The default behavior is to split the text into lines, wrap them
* in `<p>` tags, and call
* [`clipboardParser`](#view.EditorProps.clipboardParser) on it.
* The `plain` flag will be true when the text is pasted as plain
* text.
*/
clipboardTextParser?: ((this: ThisT, text: string, $context: ResolvedPos<S>) => Slice<S>) | null;
clipboardTextParser?: ((this: ThisT, text: string, $context: ResolvedPos<S>, plain: boolean) => Slice<S>) | null;
/**
* Can be used to transform pasted content before it is applied to
* the document.
Expand Down
20 changes: 18 additions & 2 deletions types/prosemirror-view/prosemirror-view-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as view from 'prosemirror-view';
import * as state from 'prosemirror-state';
import * as model from 'prosemirror-model';
import * as schema from 'prosemirror-schema-basic';
import * as state from 'prosemirror-state';
import * as view from 'prosemirror-view';

const { Decoration } = view;
const decoration = new Decoration();
Expand Down Expand Up @@ -52,3 +53,18 @@ const res5_view = new view.EditorView<typeof schema.schema>(undefined, {
const v: view.EditorView<typeof schema.schema> = this;
},
});

// Test `plain: boolean`
const res6_plugin = new state.Plugin({
props: {
transformPastedText(text, plain) {
const isPlain: boolean = plain;
return text;
},

clipboardTextParser(text, $context, plain) {
const isPlain: boolean = plain;
return model.Slice.empty;
}
}
});

0 comments on commit 19c51b8

Please sign in to comment.