diff --git a/types/prosemirror-model/index.d.ts b/types/prosemirror-model/index.d.ts index 095b88f3ba..aa02f9b770 100644 --- a/types/prosemirror-model/index.d.ts +++ b/types/prosemirror-model/index.d.ts @@ -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 // David Hahn @@ -246,7 +246,7 @@ export interface ParseOptions { * A value that describes how to parse a given DOM node or inline * style as a ProseMirror node or mark. */ -export interface ParseRule { +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 { * present, instead of parsing the node's child nodes, the result of * this function is used. */ - getContent?: ((p: Node) => Fragment) | null; + getContent?: ((p: Node, schema: S) => Fragment) | 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 { * Create a parser that targets the given schema, using the given * parsing rules. */ - constructor(schema: S, rules: Array>); + constructor(schema: S, rules: ParseRule[]); /** * The schema into which the parser parses. */ @@ -370,7 +370,7 @@ export class DOMParser { * The set of [parse rules](#model.ParseRule) that the parser * uses, in order of precedence. */ - rules: Array>; + rules: ParseRule[]; /** * Parse a document from the content of a DOM node. */ diff --git a/types/prosemirror-state/index.d.ts b/types/prosemirror-state/index.d.ts index db5a16e9d3..7ecf0f3c13 100644 --- a/types/prosemirror-state/index.d.ts +++ b/types/prosemirror-state/index.d.ts @@ -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 // David Hahn @@ -479,6 +479,7 @@ export class EditorState { schema?: S | null; doc?: ProsemirrorNode | null; selection?: Selection | null; + storedMarks?: Mark[] | null; plugins?: Array> | null; }): EditorState; /** diff --git a/types/prosemirror-transform/index.d.ts b/types/prosemirror-transform/index.d.ts index 88f97ff9e4..974a6e8475 100644 --- a/types/prosemirror-transform/index.d.ts +++ b/types/prosemirror-transform/index.d.ts @@ -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 // David Hahn @@ -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( pos: number, nodeType: NodeType ): 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( + doc: ProsemirrorNode, + pos: number, + slice: Slice +): number | null | undefined; diff --git a/types/prosemirror-view/index.d.ts b/types/prosemirror-view/index.d.ts index dba4fb8aec..a539be4593 100644 --- a/types/prosemirror-view/index.d.ts +++ b/types/prosemirror-view/index.d.ts @@ -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 // David Hahn @@ -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 { * 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"`,