Merge pull request #26721 from SALT-AND-PEPPER/update-prosemirror-typings-june-18

Update prosemirror typings june 18
This commit is contained in:
Nathan Shively-Sanders
2018-06-21 13:57:25 -07:00
committed by GitHub
4 changed files with 83 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for prosemirror-model 1.4
// Type definitions for prosemirror-model 1.5
// Project: https://github.com/ProseMirror/prosemirror-model
// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
// David Hahn <https://github.com/davidka>
@@ -246,7 +246,7 @@ export interface ParseOptions<S extends Schema = any> {
* A value that describes how to parse a given DOM node or inline
* style as a ProseMirror node or mark.
*/
export interface ParseRule<S extends Schema = any> {
export interface ParseRule {
/**
* A CSS selector describing the kind of DOM elements to match. A
* single rule should have _either_ a `tag` or a `style` property.
@@ -341,7 +341,7 @@ export interface ParseRule<S extends Schema = any> {
* present, instead of parsing the node's child nodes, the result of
* this function is used.
*/
getContent?: ((p: Node) => Fragment<S>) | null;
getContent?: (<S extends Schema = any>(p: Node, schema: S) => Fragment<S>) | null;
/**
* Controls whether whitespace should be preserved when parsing the
* content inside the matched element. `false` means whitespace may
@@ -361,7 +361,7 @@ export class DOMParser<S extends Schema = any> {
* Create a parser that targets the given schema, using the given
* parsing rules.
*/
constructor(schema: S, rules: Array<ParseRule<S>>);
constructor(schema: S, rules: ParseRule[]);
/**
* The schema into which the parser parses.
*/
@@ -370,7 +370,7 @@ export class DOMParser<S extends Schema = any> {
* The set of [parse rules](#model.ParseRule) that the parser
* uses, in order of precedence.
*/
rules: Array<ParseRule<S>>;
rules: ParseRule[];
/**
* Parse a document from the content of a DOM node.
*/

View File

@@ -1,4 +1,4 @@
// Type definitions for prosemirror-state 1.1
// Type definitions for prosemirror-state 1.2
// Project: https://github.com/ProseMirror/prosemirror-state
// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
// David Hahn <https://github.com/davidka>
@@ -479,6 +479,7 @@ export class EditorState<S extends Schema = any> {
schema?: S | null;
doc?: ProsemirrorNode<S> | null;
selection?: Selection<S> | null;
storedMarks?: Mark[] | null;
plugins?: Array<Plugin<S>> | null;
}): EditorState<S>;
/**

View File

@@ -1,4 +1,4 @@
// Type definitions for prosemirror-transform 1.0
// Type definitions for prosemirror-transform 1.1
// Project: https://github.com/ProseMirror/prosemirror-transform
// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
// David Hahn <https://github.com/davidka>
@@ -143,6 +143,12 @@ export class Mapping implements Mappable {
* mirroring information).
*/
appendMapping(mapping: Mapping): void;
/**
* Finds the offset of the step map that mirrors the map at the
* given offset, in this mapping (as per the second argument to
* appendMap).
*/
getMirror(n: number): number | undefined | null;
/**
* Append the inverse of the given mapping to this one.
*/
@@ -550,3 +556,15 @@ export function insertPoint<S extends Schema = any>(
pos: number,
nodeType: NodeType<S>
): number | null | undefined;
/**
* Finds a position at or around the given position where the given
* slice can be inserted. Will look at parent nodes' nearest boundary
* and try there, even if the original position wasn't directly at
* the start or end of that node. Returns null when no position was
* found.
*/
export function dropPoint<S extends Schema = any>(
doc: ProsemirrorNode<S>,
pos: number,
slice: Slice<S>
): number | null | undefined;

View File

@@ -1,4 +1,4 @@
// Type definitions for prosemirror-view 1.2
// Type definitions for prosemirror-view 1.3
// Project: https://github.com/ProseMirror/prosemirror-view
// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
// David Hahn <https://github.com/davidka>
@@ -41,14 +41,46 @@ export class Decoration {
spec: { [key: string]: any };
/**
* Creates a widget decoration, which is a DOM node that's shown in
* the document at the given position.
* the document at the given position. It is recommended that you
* delay rendering the widget by passing a function that will be
* called when the widget is actually drawn in a view, but you can
* also directly pass a DOM node. getPos can be used to find the
* widget's current document position.
*
* @param spec These options are supported:
* @param spec.side Controls which side of the document position
* this widget is associated with. When negative, it is drawn before
* a cursor at its position, and content inserted at that position
* ends up after the widget. When zero (the default) or positive, the
* widget is drawn after the cursor and content inserted there ends
* up before the widget.
*
* When there are multiple widgets at a given position, their side
* values determine the order in which they appear. Those with lower
* values appear first. The ordering of widgets with the same side
* value is unspecified.
*
* When marks is null, side also determines the marks that the widget
* is wrapped in—those of the node before when negative, those of
* the node after when positive.
* @param spec.marks The precise set of marks to draw around the widget.
* @param spec.stopEvent Can be used to control which DOM events, when
* they bubble out of this widget, the editor view should ignore.
* @param spec.key When comparing decorations of this type (in order to
* decide whether it needs to be redrawn), ProseMirror will by default
* compare the widget DOM node by identity. If you pass a key, that key
* will be compared instead, which can be useful when you generate
* decorations on the fly and don't want to store and reuse DOM nodes.
* Make sure that any widgets with the same key are interchangeable—if
* widgets differ in, for example, the behavior of some event handler,
* they should get different keys.
*/
static widget(
pos: number,
dom: Node,
toDOM: ((view: EditorView, getPos: () => number) => Node) | Node,
spec?: {
side?: number | null;
marks?: Mark[];
marks?: Mark[] | null;
stopEvent?: ((event: Event) => boolean) | null;
key?: string | null;
}
@@ -251,6 +283,27 @@ export class EditorView<S extends Schema = any> {
* necessary).
*/
domAtPos(pos: number): { node: Node; offset: number };
/**
* Find the DOM node that represents the document node after the
* given position. May return null when the position doesn't point
* in front of a node or if the node is inside an opaque node view.
*
* This is intended to be able to call things like getBoundingClientRect
* on that DOM node. Do not mutate the editor DOM directly, or add
* styling this way, since that will be immediately overriden by the
* editor as it redraws the node.
*/
nodeDOM(pos: number): Node | null | undefined;
/**
* Find the document position that corresponds to a given DOM position.
* (Whenever possible, it is preferable to inspect the document structure
* directly, rather than poking around in the DOM, but sometimes—for
* example when interpreting an event target—you don't have a choice.)
*
* The bias (default: -1) parameter can be used to influence which side of
* a DOM node to use when the position is inside a leaf node.
*/
posAtDOM(node: Node, offset: number, bias?: number | null): number;
/**
* Find out whether the selection is at the end of a textblock when
* moving in a given direction. When, for example, given `"left"`,