1 | // Type definitions for prosemirror-view 1.23
|
2 | // Project: https://github.com/ProseMirror/prosemirror-view
|
3 | // Definitions by: Bradley Ayers <https://github.com/bradleyayers>
|
4 | // David Hahn <https://github.com/davidka>
|
5 | // Tim Baumann <https://github.com/timjb>
|
6 | // Patrick Simmelbauer <https://github.com/patsimm>
|
7 | // Ifiok Jr. <https://github.com/ifiokjr>
|
8 | // Mike Morearty <https://github.com/mmorearty>
|
9 | // Ocavue <https://github.com/ocavue>
|
10 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
11 | // TypeScript Version: 3.0
|
12 |
|
13 | import { DOMParser, DOMSerializer, Node as ProsemirrorNode, ResolvedPos, Slice, Schema, Mark } from 'prosemirror-model';
|
14 | import { EditorState, Selection, Transaction, Plugin } from 'prosemirror-state';
|
15 | import { Mapping } from 'prosemirror-transform';
|
16 |
|
17 | // Exported for testing
|
18 | export function __serializeForClipboard<S extends Schema = any>(
|
19 | view: EditorView<S>,
|
20 | slice: Slice<S>,
|
21 | ): { dom: HTMLElement; text: string };
|
22 | export function __parseFromClipboard<S extends Schema = any>(
|
23 | view: EditorView<S>,
|
24 | text: string,
|
25 | html: string,
|
26 | plainText: boolean,
|
27 | $context: ResolvedPos<S>,
|
28 | ): Slice<S>;
|
29 | export function __endComposition(view: EditorView, forceUpdate?: boolean): boolean;
|
30 |
|
31 | /**
|
32 | * The `spec` for a widget decoration
|
33 | */
|
34 | export interface WidgetDecorationSpec {
|
35 | /**
|
36 | * Controls which side of the document position this widget is
|
37 | * associated with. When negative, it is drawn before a cursor
|
38 | * at its position, and content inserted at that position ends
|
39 | * up after the widget. When zero (the default) or positive, the
|
40 | * widget is drawn after the cursor and content inserted there
|
41 | * ends up before the widget.
|
42 | *
|
43 | * When there are multiple widgets at a given position, their
|
44 | * `side` values determine the order in which they appear. Those
|
45 | * with lower values appear first. The ordering of widgets with
|
46 | * the same `side` value is unspecified.
|
47 | *
|
48 | * When `marks` is null, `side` also determines the marks that
|
49 | * the widget is wrapped in—those of the node before when
|
50 | * negative, those of the node after when positive.
|
51 | */
|
52 | side?: number | null | undefined;
|
53 | /**
|
54 | * The precise set of marks to draw around the widget.
|
55 | */
|
56 | marks?: Mark[] | null | undefined;
|
57 | /**
|
58 | * Can be used to control which DOM events, when they bubble out
|
59 | * of this widget, the editor view should ignore.
|
60 | */
|
61 | stopEvent?: ((event: Event) => boolean) | null | undefined;
|
62 | /**
|
63 | * When set (defaults to false), selection changes inside the
|
64 | * widget are ignored, and don't cause ProseMirror to try and
|
65 | * re-sync the selection with its selection state.
|
66 | */
|
67 | ignoreSelection?: boolean;
|
68 | /**
|
69 | * When comparing decorations of this type (in order to decide
|
70 | * whether it needs to be redrawn), ProseMirror will by default
|
71 | * compare the widget DOM node by identity. If you pass a key,
|
72 | * that key will be compared instead, which can be useful when
|
73 | * you generate decorations on the fly and don't want to store
|
74 | * and reuse DOM nodes. Make sure that any widgets with the same
|
75 | * key are interchangeable—if widgets differ in, for example,
|
76 | * the behavior of some event handler, they should get
|
77 | * different keys.
|
78 | */
|
79 | key?: string | null | undefined;
|
80 | /**
|
81 | * Called when the widget decoration is removed as a result of mapping
|
82 | */
|
83 | destroy?: (node: Node) => void;
|
84 | }
|
85 | /**
|
86 | * The `spec` for the inline decoration.
|
87 | */
|
88 | export interface InlineDecorationSpec {
|
89 | /**
|
90 | * Determines how the left side of the decoration is
|
91 | * [mapped](#transform.Position_Mapping) when content is
|
92 | * inserted directly at that position. By default, the decoration
|
93 | * won't include the new content, but you can set this to `true`
|
94 | * to make it inclusive.
|
95 | */
|
96 | inclusiveStart?: boolean | null | undefined;
|
97 | /**
|
98 | * Determines how the right side of the decoration is mapped.
|
99 | */
|
100 | inclusiveEnd?: boolean | null | undefined;
|
101 | }
|
102 | /**
|
103 | * Decoration objects can be provided to the view through the
|
104 | * [`decorations` prop](#view.EditorProps.decorations). They come in
|
105 | * several variants—see the static members of this class for details.
|
106 | */
|
107 | export class Decoration<T extends object = { [key: string]: any }> {
|
108 | /**
|
109 | * The start position of the decoration.
|
110 | */
|
111 | from: number;
|
112 | /**
|
113 | * The end position. Will be the same as `from` for [widget
|
114 | * decorations](#view.Decoration^widget).
|
115 | */
|
116 | to: number;
|
117 | /**
|
118 | * The spec provided when creating this decoration. Can be useful
|
119 | * if you've stored extra information in that object.
|
120 | */
|
121 | spec: T;
|
122 | /**
|
123 | * Creates a widget decoration, which is a DOM node that's shown in
|
124 | * the document at the given position. It is recommended that you
|
125 | * delay rendering the widget by passing a function that will be
|
126 | * called when the widget is actually drawn in a view, but you can
|
127 | * also directly pass a DOM node. getPos can be used to find the
|
128 | * widget's current document position.
|
129 | */
|
130 | static widget<T extends object = { [key: string]: any }>(
|
131 | pos: number,
|
132 | toDOM: ((view: EditorView, getPos: () => number) => Node) | Node,
|
133 | spec?: T & WidgetDecorationSpec,
|
134 | ): Decoration<T & WidgetDecorationSpec>;
|
135 | /**
|
136 | * Creates an inline decoration, which adds the given attributes to
|
137 | * each inline node between `from` and `to`.
|
138 | */
|
139 | static inline<T extends object = { [key: string]: any }>(
|
140 | from: number,
|
141 | to: number,
|
142 | attrs: DecorationAttrs,
|
143 | spec?: T & InlineDecorationSpec,
|
144 | ): Decoration<T & InlineDecorationSpec>;
|
145 | /**
|
146 | * Creates a node decoration. `from` and `to` should point precisely
|
147 | * before and after a node in the document. That node, and only that
|
148 | * node, will receive the given attributes.
|
149 | */
|
150 | static node<T extends object = { [key: string]: any }>(
|
151 | from: number,
|
152 | to: number,
|
153 | attrs: DecorationAttrs,
|
154 | spec?: T,
|
155 | ): Decoration<T>;
|
156 | }
|
157 | /**
|
158 | * A set of attributes to add to a decorated node. Most properties
|
159 | * simply directly correspond to DOM attributes of the same name,
|
160 | * which will be set to the property's value. These are exceptions:
|
161 | */
|
162 | export interface DecorationAttrs {
|
163 | /**
|
164 | * A CSS class name or a space-separated set of class names to be
|
165 | * _added_ to the classes that the node already had.
|
166 | */
|
167 | class?: string | null | undefined;
|
168 | /**
|
169 | * A string of CSS to be _added_ to the node's existing `style` property.
|
170 | */
|
171 | style?: string | null | undefined;
|
172 | /**
|
173 | * When non-null, the target node is wrapped in a DOM element of
|
174 | * this type (and the other attributes are applied to this element).
|
175 | */
|
176 | nodeName?: string | null | undefined;
|
177 | /**
|
178 | * Specify additional attrs that will be mapped directly to the
|
179 | * target node's DOM attributes.
|
180 | */
|
181 | [key: string]: string | null | undefined;
|
182 | }
|
183 | /**
|
184 | * A collection of [decorations](#view.Decoration), organized in
|
185 | * such a way that the drawing algorithm can efficiently use and
|
186 | * compare them. This is a persistent data structure—it is not
|
187 | * modified, updates create a new value.
|
188 | */
|
189 | export class DecorationSet<S extends Schema = any> {
|
190 | /**
|
191 | * Find all decorations in this set which touch the given range
|
192 | * (including decorations that start or end directly at the
|
193 | * boundaries) and match the given predicate on their spec. When
|
194 | * `start` and `end` are omitted, all decorations in the set are
|
195 | * considered. When `predicate` isn't given, all decorations are
|
196 | * assumed to match.
|
197 | */
|
198 | find(start?: number, end?: number, predicate?: (spec: { [key: string]: any }) => boolean): Decoration[];
|
199 | /**
|
200 | * Map the set of decorations in response to a change in the
|
201 | * document.
|
202 | */
|
203 | map(
|
204 | mapping: Mapping,
|
205 | doc: ProsemirrorNode<S>,
|
206 | options?: { onRemove?: ((decorationSpec: { [key: string]: any }) => void) | null | undefined },
|
207 | ): DecorationSet<S>;
|
208 | /**
|
209 | * Add the given array of decorations to the ones in the set,
|
210 | * producing a new set. Needs access to the current document to
|
211 | * create the appropriate tree structure.
|
212 | */
|
213 | add(doc: ProsemirrorNode<S>, decorations: Decoration[]): DecorationSet<S>;
|
214 | /**
|
215 | * Create a new set that contains the decorations in this set, minus
|
216 | * the ones in the given array.
|
217 | */
|
218 | remove(decorations: Decoration[]): DecorationSet<S>;
|
219 | /**
|
220 | * Create a set of decorations, using the structure of the given
|
221 | * document.
|
222 | */
|
223 | static create<S extends Schema = any>(doc: ProsemirrorNode<S>, decorations: Decoration[]): DecorationSet<S>;
|
224 | /**
|
225 | * The empty set of decorations.
|
226 | */
|
227 | static empty: DecorationSet;
|
228 | }
|
229 | /**
|
230 | * An editor view manages the DOM structure that represents an
|
231 | * editable document. Its state and behavior are determined by its
|
232 | * [props](#view.DirectEditorProps).
|
233 | */
|
234 | export class EditorView<S extends Schema = any> {
|
235 | /**
|
236 | * Create a view. `place` may be a DOM node that the editor should
|
237 | * be appended to, a function that will place it into the document,
|
238 | * or an object whose `mount` property holds the node to use as the
|
239 | * document container. If it is `null`, the editor will not be added
|
240 | * to the document.
|
241 | */
|
242 | constructor(place: Node | ((p: Node) => void) | { mount: Node } | undefined, props: DirectEditorProps<S>);
|
243 | /**
|
244 | * The view's current [state](#state.EditorState).
|
245 | */
|
246 | state: EditorState<S>;
|
247 | /**
|
248 | * An editable DOM node containing the document. (You probably
|
249 | * should not directly interfere with its content.)
|
250 | */
|
251 | dom: Element;
|
252 | /**
|
253 | * Indicates whether the editor is currently [editable](#view.EditorProps.editable).
|
254 | */
|
255 | editable: boolean;
|
256 | /**
|
257 | * When editor content is being dragged, this object contains
|
258 | * information about the dragged slice and whether it is being
|
259 | * copied or moved. At any other time, it is null.
|
260 | */
|
261 | dragging?: { slice: Slice<S>; move: boolean } | null | undefined;
|
262 | /**
|
263 | * Holds true when a composition is active.
|
264 | */
|
265 | composing: boolean;
|
266 | /**
|
267 | * The view's current [props](#view.EditorProps).
|
268 | */
|
269 | props: DirectEditorProps<S>;
|
270 | /**
|
271 | * Update the view's props. Will immediately cause an update to
|
272 | * the DOM.
|
273 | */
|
274 | update(props: DirectEditorProps<S>): void;
|
275 | /**
|
276 | * Update the view by updating existing props object with the object
|
277 | * given as argument. Equivalent to `view.update(Object.assign({},
|
278 | * view.props, props))`.
|
279 | */
|
280 | setProps(props: Partial<DirectEditorProps<S>>): void;
|
281 | /**
|
282 | * Update the editor's `state` prop, without touching any of the
|
283 | * other props.
|
284 | */
|
285 | updateState(state: EditorState<S>): void;
|
286 | /**
|
287 | * Goes over the values of a prop, first those provided directly,
|
288 | * then those from plugins (in order), and calls `f` every time a
|
289 | * non-undefined value is found. When `f` returns a truthy value,
|
290 | * that is immediately returned. When `f` isn't provided, it is
|
291 | * treated as the identity function (the prop value is returned
|
292 | * directly).
|
293 | */
|
294 | someProp(propName: string, f?: (prop: any) => any): any;
|
295 | /**
|
296 | * Query whether the view has focus.
|
297 | */
|
298 | hasFocus(): boolean;
|
299 | /**
|
300 | * Focus the editor.
|
301 | */
|
302 | focus(): void;
|
303 | /**
|
304 | * Get the document root in which the editor exists. This will
|
305 | * usually be the top-level `document`, but might be a [shadow
|
306 | * DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM)
|
307 | * root if the editor is inside one.
|
308 | */
|
309 | root: Document | DocumentFragment;
|
310 | /**
|
311 | * Given a pair of viewport coordinates, return the document
|
312 | * position that corresponds to them. May return null if the given
|
313 | * coordinates aren't inside of the editor. When an object is
|
314 | * returned, its `pos` property is the position nearest to the
|
315 | * coordinates, and its `inside` property holds the position of the
|
316 | * inner node that the position falls inside of, or -1 if it is at
|
317 | * the top level, not in any node.
|
318 | */
|
319 | posAtCoords(coords: { left: number; top: number }): { pos: number; inside: number } | null | undefined;
|
320 | /**
|
321 | * Returns the viewport rectangle at a given document position.
|
322 | * `left` and `right` will be the same number, as this returns a
|
323 | * flat cursor-ish rectangle. If the position is between two things
|
324 | * that aren't directly adjacent, `side` determines which element is
|
325 | * used. When < 0, the element before the position is used,
|
326 | * otherwise the element after.
|
327 | */
|
328 | coordsAtPos(pos: number, side?: number): { left: number; right: number; top: number; bottom: number };
|
329 | /**
|
330 | * Find the DOM position that corresponds to the given document
|
331 | * position. When `side` is negative, find the position as close as
|
332 | * possible to the content before the position. When positive,
|
333 | * prefer positions close to the content after the position. When
|
334 | * zero, prefer as shallow a position as possible.
|
335 | *
|
336 | * Note that you should **not** mutate the editor's internal DOM,
|
337 | * only inspect it (and even that is usually not necessary).
|
338 | */
|
339 | domAtPos(pos: number, side?: number): { node: Node; offset: number };
|
340 | /**
|
341 | * Find the DOM node that represents the document node after the
|
342 | * given position. May return null when the position doesn't point
|
343 | * in front of a node or if the node is inside an opaque node view.
|
344 | *
|
345 | * This is intended to be able to call things like getBoundingClientRect
|
346 | * on that DOM node. Do not mutate the editor DOM directly, or add
|
347 | * styling this way, since that will be immediately overriden by the
|
348 | * editor as it redraws the node.
|
349 | */
|
350 | nodeDOM(pos: number): Node | null | undefined;
|
351 | /**
|
352 | * Find the document position that corresponds to a given DOM position.
|
353 | * (Whenever possible, it is preferable to inspect the document structure
|
354 | * directly, rather than poking around in the DOM, but sometimes—for
|
355 | * example when interpreting an event target—you don't have a choice.)
|
356 | *
|
357 | * The bias (default: -1) parameter can be used to influence which side of
|
358 | * a DOM node to use when the position is inside a leaf node.
|
359 | */
|
360 | posAtDOM(node: Node, offset: number, bias?: number | null): number;
|
361 | /**
|
362 | * Find out whether the selection is at the end of a textblock when
|
363 | * moving in a given direction. When, for example, given `"left"`,
|
364 | * it will return true if moving left from the current cursor
|
365 | * position would leave that position's parent textblock. Will apply
|
366 | * to the view's current state by default, but it is possible to
|
367 | * pass a different state.
|
368 | */
|
369 | endOfTextblock(dir: 'up' | 'down' | 'left' | 'right' | 'forward' | 'backward', state?: EditorState<S>): boolean;
|
370 | /**
|
371 | * Removes the editor from the DOM and destroys all [node
|
372 | * views](#view.NodeView).
|
373 | */
|
374 | destroy(): void;
|
375 | /**
|
376 | * This is true when the view has been
|
377 | * [destroyed](#view.EditorView.destroy) (and thus should not be
|
378 | * used anymore).
|
379 | */
|
380 | isDestroyed: boolean;
|
381 | /**
|
382 | * Dispatch a transaction. Will call
|
383 | * [`dispatchTransaction`](#view.DirectEditorProps.dispatchTransaction)
|
384 | * when given, and otherwise defaults to applying the transaction to
|
385 | * the current state and calling
|
386 | * [`updateState`](#view.EditorView.updateState) with the result.
|
387 | * This method is bound to the view instance, so that it can be
|
388 | * easily passed around.
|
389 | */
|
390 | dispatch(tr: Transaction<S>): void;
|
391 | }
|
392 | /**
|
393 | * Props are configuration values that can be passed to an editor view
|
394 | * or included in a plugin. This interface lists the supported props.
|
395 | *
|
396 | * The various event-handling functions may all return `true` to
|
397 | * indicate that they handled the given event. The view will then take
|
398 | * care to call `preventDefault` on the event, except with
|
399 | * `handleDOMEvents`, where the handler itself is responsible for that.
|
400 | *
|
401 | * How a prop is resolved depends on the prop. Handler functions are
|
402 | * called one at a time, starting with the base props and then
|
403 | * searching through the plugins (in order of appearance) until one of
|
404 | * them returns true. For some props, the first plugin that yields a
|
405 | * value gets precedence.
|
406 | */
|
407 | export interface EditorProps<ThisT = unknown, S extends Schema = any> {
|
408 | /**
|
409 | * Can be an object mapping DOM event type names to functions that
|
410 | * handle them. Such functions will be called before any handling
|
411 | * ProseMirror does of events fired on the editable DOM element.
|
412 | * Contrary to the other event handling props, when returning true
|
413 | * from such a function, you are responsible for calling
|
414 | * `preventDefault` yourself (or not, if you want to allow the
|
415 | * default behavior).
|
416 | */
|
417 | handleDOMEvents?: HandleDOMEventsProp<ThisT, S> | null | undefined;
|
418 | /**
|
419 | * Called when the editor receives a `keydown` event.
|
420 | */
|
421 | handleKeyDown?: ((this: ThisT, view: EditorView<S>, event: KeyboardEvent) => boolean) | null | undefined;
|
422 | /**
|
423 | * Handler for `keypress` events.
|
424 | */
|
425 | handleKeyPress?: ((this: ThisT, view: EditorView<S>, event: KeyboardEvent) => boolean) | null | undefined;
|
426 | /**
|
427 | * Whenever the user directly input text, this handler is called
|
428 | * before the input is applied. If it returns `true`, the default
|
429 | * behavior of actually inserting the text is suppressed.
|
430 | */
|
431 | handleTextInput?:
|
432 | | ((this: ThisT, view: EditorView<S>, from: number, to: number, text: string) => boolean)
|
433 | | null
|
434 | | undefined;
|
435 | /**
|
436 | * Called for each node around a click, from the inside out. The
|
437 | * `direct` flag will be true for the inner node.
|
438 | */
|
439 | handleClickOn?:
|
440 | | ((
|
441 | this: ThisT,
|
442 | view: EditorView<S>,
|
443 | pos: number,
|
444 | node: ProsemirrorNode<S>,
|
445 | nodePos: number,
|
446 | event: MouseEvent,
|
447 | direct: boolean,
|
448 | ) => boolean)
|
449 | | null
|
450 | | undefined;
|
451 | /**
|
452 | * Called when the editor is clicked, after `handleClickOn` handlers
|
453 | * have been called.
|
454 | */
|
455 | handleClick?: ((this: ThisT, view: EditorView<S>, pos: number, event: MouseEvent) => boolean) | null | undefined;
|
456 | /**
|
457 | * Called for each node around a double click.
|
458 | */
|
459 | handleDoubleClickOn?:
|
460 | | ((
|
461 | this: ThisT,
|
462 | view: EditorView<S>,
|
463 | pos: number,
|
464 | node: ProsemirrorNode<S>,
|
465 | nodePos: number,
|
466 | event: MouseEvent,
|
467 | direct: boolean,
|
468 | ) => boolean)
|
469 | | null
|
470 | | undefined;
|
471 | /**
|
472 | * Called when the editor is double-clicked, after `handleDoubleClickOn`.
|
473 | */
|
474 | handleDoubleClick?:
|
475 | | ((this: ThisT, view: EditorView<S>, pos: number, event: MouseEvent) => boolean)
|
476 | | null
|
477 | | undefined;
|
478 | /**
|
479 | * Called for each node around a triple click.
|
480 | */
|
481 | handleTripleClickOn?:
|
482 | | ((
|
483 | this: ThisT,
|
484 | view: EditorView<S>,
|
485 | pos: number,
|
486 | node: ProsemirrorNode<S>,
|
487 | nodePos: number,
|
488 | event: MouseEvent,
|
489 | direct: boolean,
|
490 | ) => boolean)
|
491 | | null
|
492 | | undefined;
|
493 | /**
|
494 | * Called when the editor is triple-clicked, after `handleTripleClickOn`.
|
495 | */
|
496 | handleTripleClick?:
|
497 | | ((this: ThisT, view: EditorView<S>, pos: number, event: MouseEvent) => boolean)
|
498 | | null
|
499 | | undefined;
|
500 | /**
|
501 | * Can be used to override the behavior of pasting. `slice` is the
|
502 | * pasted content parsed by the editor, but you can directly access
|
503 | * the event to get at the raw content.
|
504 | */
|
505 | handlePaste?:
|
506 | | ((this: ThisT, view: EditorView<S>, event: ClipboardEvent, slice: Slice<S>) => boolean)
|
507 | | null
|
508 | | undefined;
|
509 | /**
|
510 | * Called when something is dropped on the editor. `moved` will be
|
511 | * true if this drop moves from the current selection (which should
|
512 | * thus be deleted).
|
513 | */
|
514 | handleDrop?:
|
515 | | ((this: ThisT, view: EditorView<S>, event: Event, slice: Slice<S>, moved: boolean) => boolean)
|
516 | | null
|
517 | | undefined;
|
518 | /**
|
519 | * Called when the view, after updating its state, tries to scroll
|
520 | * the selection into view. A handler function may return false to
|
521 | * indicate that it did not handle the scrolling and further
|
522 | * handlers or the default behavior should be tried.
|
523 | */
|
524 | handleScrollToSelection?: ((this: ThisT, view: EditorView<S>) => boolean) | null | undefined;
|
525 | /**
|
526 | * Can be used to override the way a selection is created when
|
527 | * reading a DOM selection between the given anchor and head.
|
528 | */
|
529 | createSelectionBetween?:
|
530 | | ((
|
531 | this: ThisT,
|
532 | view: EditorView<S>,
|
533 | anchor: ResolvedPos<S>,
|
534 | head: ResolvedPos<S>,
|
535 | ) => Selection<S> | null | undefined)
|
536 | | null
|
537 | | undefined;
|
538 | /**
|
539 | * The [parser](#model.DOMParser) to use when reading editor changes
|
540 | * from the DOM. Defaults to calling
|
541 | * [`DOMParser.fromSchema`](#model.DOMParser^fromSchema) on the
|
542 | * editor's schema.
|
543 | */
|
544 | domParser?: DOMParser<S> | null | undefined;
|
545 | /**
|
546 | * Can be used to transform pasted HTML text, _before_ it is parsed,
|
547 | * for example to clean it up.
|
548 | */
|
549 | transformPastedHTML?: ((this: ThisT, html: string) => string) | null | undefined;
|
550 | /**
|
551 | * The [parser](#model.DOMParser) to use when reading content from
|
552 | * the clipboard. When not given, the value of the
|
553 | * [`domParser`](#view.EditorProps.domParser) prop is used.
|
554 | */
|
555 | clipboardParser?: DOMParser<S> | null | undefined;
|
556 | /**
|
557 | * Transform pasted plain text. The `plain` flag will be true when
|
558 | * the text is pasted as plain text.
|
559 | */
|
560 | transformPastedText?: ((this: ThisT, text: string, plain: boolean) => string) | null | undefined;
|
561 | /**
|
562 | * A function to parse text from the clipboard into a document
|
563 | * slice. Called after
|
564 | * [`transformPastedText`](#view.EditorProps.transformPastedText).
|
565 | * The default behavior is to split the text into lines, wrap them
|
566 | * in `<p>` tags, and call
|
567 | * [`clipboardParser`](#view.EditorProps.clipboardParser) on it.
|
568 | * The `plain` flag will be true when the text is pasted as plain
|
569 | * text.
|
570 | */
|
571 | clipboardTextParser?:
|
572 | | ((this: ThisT, text: string, $context: ResolvedPos<S>, plain: boolean) => Slice<S>)
|
573 | | null
|
574 | | undefined;
|
575 | /**
|
576 | * Can be used to transform pasted content before it is applied to
|
577 | * the document.
|
578 | */
|
579 | transformPasted?: ((this: ThisT, p: Slice<S>) => Slice<S>) | null | undefined;
|
580 | /**
|
581 | * Allows you to pass custom rendering and behavior logic for nodes
|
582 | * and marks. Should map node and mark names to constructor
|
583 | * functions that produce a [`NodeView`](#view.NodeView) object
|
584 | * implementing the node's display behavior. For nodes, the third
|
585 | * argument `getPos` is a function that can be called to get the
|
586 | * node's current position, which can be useful when creating
|
587 | * transactions to update it. For marks, the third argument is a
|
588 | * boolean that indicates whether the mark's content is inline.
|
589 | *
|
590 | * `decorations` is an array of node or inline decorations that are
|
591 | * active around the node. They are automatically drawn in the
|
592 | * normal way, and you will usually just want to ignore this, but
|
593 | * they can also be used as a way to provide context information to
|
594 | * the node view without adding it to the document itself.
|
595 | */
|
596 | nodeViews?:
|
597 | | {
|
598 | [name: string]: ((
|
599 | node: ProsemirrorNode<S>,
|
600 | view: EditorView<S>,
|
601 | /** get the node's current position */
|
602 | getPos: () => number,
|
603 | decorations: Decoration[],
|
604 | ) => NodeView<S>) | ((
|
605 | mark: Mark<S>,
|
606 | view: EditorView<S>,
|
607 | /** indicates whether the mark's content is inline */
|
608 | inline: boolean,
|
609 | ) => Pick<NodeView<S>, 'dom' | 'contentDOM'>);
|
610 | }
|
611 | | null
|
612 | | undefined;
|
613 | /**
|
614 | * The DOM serializer to use when putting content onto the
|
615 | * clipboard. If not given, the result of
|
616 | * [`DOMSerializer.fromSchema`](#model.DOMSerializer^fromSchema)
|
617 | * will be used.
|
618 | */
|
619 | clipboardSerializer?: DOMSerializer<S> | null | undefined;
|
620 | /**
|
621 | * A function that will be called to get the text for the current
|
622 | * selection when copying text to the clipboard. By default, the
|
623 | * editor will use [`textBetween`](#model.Node.textBetween) on the
|
624 | * selected range.
|
625 | */
|
626 | clipboardTextSerializer?: ((this: ThisT, p: Slice<S>) => string) | null | undefined;
|
627 | /**
|
628 | * A set of [document decorations](#view.Decoration) to show in the
|
629 | * view.
|
630 | */
|
631 | decorations?: ((this: ThisT, state: EditorState<S>) => DecorationSet<S> | null | undefined) | null | undefined;
|
632 | /**
|
633 | * When this returns false, the content of the view is not directly
|
634 | * editable.
|
635 | */
|
636 | editable?: ((this: ThisT, state: EditorState<S>) => boolean) | null | undefined;
|
637 | /**
|
638 | * Control the DOM attributes of the editable element. May be either
|
639 | * an object or a function going from an editor state to an object.
|
640 | * By default, the element will get a class `"ProseMirror"`, and
|
641 | * will have its `contentEditable` attribute determined by the
|
642 | * [`editable` prop](#view.EditorProps.editable). Additional classes
|
643 | * provided here will be added to the class. For other attributes,
|
644 | * the value provided first (as in
|
645 | * [`someProp`](#view.EditorView.someProp)) will be used.
|
646 | */
|
647 | attributes?:
|
648 | | { [name: string]: string }
|
649 | | ((this: ThisT, p: EditorState<S>) => { [name: string]: string } | null | undefined | void)
|
650 | | null
|
651 | | undefined;
|
652 | /**
|
653 | * Determines the distance (in pixels) between the cursor and the
|
654 | * end of the visible viewport at which point, when scrolling the
|
655 | * cursor into view, scrolling takes place. Defaults to 0.
|
656 | */
|
657 | scrollThreshold?: number | { top: number; right: number; bottom: number; left: number } | null | undefined;
|
658 | /**
|
659 | * Determines the extra space (in pixels) that is left above or
|
660 | * below the cursor when it is scrolled into view. Defaults to 5.
|
661 | */
|
662 | scrollMargin?: number | { top: number; right: number; bottom: number; left: number } | null | undefined;
|
663 | }
|
664 | /**
|
665 | * A mapping of dom events.
|
666 | */
|
667 | export type HandleDOMEventsProp<ThisT = unknown, S extends Schema = any> = Partial<
|
668 | {
|
669 | [K in keyof DocumentEventMap]: (this: ThisT, view: EditorView<S>, event: DocumentEventMap[K]) => boolean;
|
670 | }
|
671 | > & {
|
672 | [key: string]: (this: ThisT, view: EditorView<S>, event: any) => boolean;
|
673 | };
|
674 | /**
|
675 | * The props object given directly to the editor view supports some
|
676 | * fields that can't be used in plugins:
|
677 | */
|
678 | export interface DirectEditorProps<S extends Schema = any> extends EditorProps<unknown, S> {
|
679 | /**
|
680 | * The current state of the editor.
|
681 | */
|
682 | state: EditorState<S>;
|
683 |
|
684 | /**
|
685 | * A set of plugins to use in the view, applying their [plugin
|
686 | * view](#state.PluginSpec.view) and
|
687 | * [props](#state.PluginSpec.props). Passing plugins with a state
|
688 | * component (a [state field](#state.PluginSpec.state) field or a
|
689 | * [transaction](#state.PluginSpec.filterTransaction) filter or
|
690 | * appender) will result in an error, since such plugins must be
|
691 | * present in the state to work.
|
692 | */
|
693 | plugins?: Plugin[];
|
694 |
|
695 | /**
|
696 | * The callback over which to send transactions (state updates)
|
697 | * produced by the view. If you specify this, you probably want to
|
698 | * make sure this ends up calling the view's
|
699 | * [`updateState`](#view.EditorView.updateState) method with a new
|
700 | * state that has the transaction
|
701 | * [applied](#state.EditorState.apply). The callback will be bound to have
|
702 | * the view instance as its `this` binding.
|
703 | */
|
704 | dispatchTransaction?: ((this: EditorView<S>, tr: Transaction<S>) => void) | null | undefined;
|
705 | }
|
706 | /**
|
707 | * By default, document nodes are rendered using the result of the
|
708 | * [`toDOM`](#model.NodeSpec.toDOM) method of their spec, and managed
|
709 | * entirely by the editor. For some use cases, such as embedded
|
710 | * node-specific editing interfaces, you want more control over
|
711 | * the behavior of a node's in-editor representation, and need to
|
712 | * [define](#view.EditorProps.nodeViews) a custom node view.
|
713 | *
|
714 | * Objects returned as node views must conform to this interface.
|
715 | */
|
716 | export interface NodeView<S extends Schema = any> {
|
717 | /**
|
718 | * The outer DOM node that represents the document node. When not
|
719 | * given, the default strategy is used to create a DOM node.
|
720 | */
|
721 | dom?: Node | null | undefined;
|
722 | /**
|
723 | * The DOM node that should hold the node's content. Only meaningful
|
724 | * if the node view also defines a `dom` property and if its node
|
725 | * type is not a leaf node type. When this is present, ProseMirror
|
726 | * will take care of rendering the node's children into it. When it
|
727 | * is not present, the node view itself is responsible for rendering
|
728 | * (or deciding not to render) its child nodes.
|
729 | */
|
730 | contentDOM?: Node | null | undefined;
|
731 | /**
|
732 | * When given, this will be called when the view is updating itself.
|
733 | * It will be given a node (possibly of a different type), and an
|
734 | * array of active decorations (which are automatically drawn, and
|
735 | * the node view may ignore if it isn't interested in them), and
|
736 | * should return true if it was able to update to that node, and
|
737 | * false otherwise. If the node view has a `contentDOM` property (or
|
738 | * no `dom` property), updating its child nodes will be handled by
|
739 | * ProseMirror.
|
740 | */
|
741 | update?:
|
742 | | ((node: ProsemirrorNode<S>, decorations: Decoration[], innerDecorations: DecorationSet) => boolean)
|
743 | | null
|
744 | | undefined;
|
745 | /**
|
746 | * Can be used to override the way the node's selected status (as a
|
747 | * node selection) is displayed.
|
748 | */
|
749 | selectNode?: (() => void) | null | undefined;
|
750 | /**
|
751 | * When defining a `selectNode` method, you should also provide a
|
752 | * `deselectNode` method to remove the effect again.
|
753 | */
|
754 | deselectNode?: (() => void) | null | undefined;
|
755 | /**
|
756 | * This will be called to handle setting the selection inside the
|
757 | * node. The `anchor` and `head` positions are relative to the start
|
758 | * of the node. By default, a DOM selection will be created between
|
759 | * the DOM positions corresponding to those positions, but if you
|
760 | * override it you can do something else.
|
761 | */
|
762 | setSelection?: ((anchor: number, head: number, root: Document) => void) | null | undefined;
|
763 | /**
|
764 | * Can be used to prevent the editor view from trying to handle some
|
765 | * or all DOM events that bubble up from the node view. Events for
|
766 | * which this returns true are not handled by the editor.
|
767 | */
|
768 | stopEvent?: ((event: Event) => boolean) | null | undefined;
|
769 | /**
|
770 | * Called when a DOM
|
771 | * [mutation](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
|
772 | * or a selection change happens within the view. When the change is
|
773 | * a selection change, the record will have a `type` property of
|
774 | * `"selection"` (which doesn't occur for native mutation records).
|
775 | * Return false if the editor should re-read the selection or
|
776 | * re-parse the range around the mutation, true if it can safely be
|
777 | * ignored.
|
778 | */
|
779 | ignoreMutation?:
|
780 | | ((
|
781 | p:
|
782 | | MutationRecord
|
783 | | {
|
784 | type: 'selection';
|
785 | target: Element;
|
786 | },
|
787 | ) => boolean)
|
788 | | null
|
789 | | undefined;
|
790 | /**
|
791 | * Called when the node view is removed from the editor or the whole
|
792 | * editor is destroyed.
|
793 | */
|
794 | destroy?: (() => void) | null | undefined;
|
795 | }
|
796 |
|
\ | No newline at end of file |