1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | import OrderedMap = require('orderedmap');
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export class ContentMatch<S extends Schema = any> {
|
23 | |
24 |
|
25 |
|
26 |
|
27 | defaultType?: NodeType | undefined;
|
28 | |
29 |
|
30 |
|
31 |
|
32 | edgeCount: number;
|
33 | |
34 |
|
35 |
|
36 | validEnd: boolean;
|
37 | |
38 |
|
39 |
|
40 |
|
41 | matchType(type: NodeType<S>): ContentMatch<S> | null | undefined;
|
42 | |
43 |
|
44 |
|
45 |
|
46 | matchFragment(frag: Fragment<S>, start?: number, end?: number): ContentMatch<S> | null | undefined;
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | fillBefore(after: Fragment<S>, toEnd?: boolean, startIndex?: number): Fragment<S> | null | undefined;
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | findWrapping(target: NodeType<S>): Array<NodeType<S>> | null | undefined;
|
63 | |
64 |
|
65 |
|
66 |
|
67 | edge(n: number): { type: NodeType; next: ContentMatch };
|
68 | }
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | export class Fragment<S extends Schema = any> {
|
77 | |
78 |
|
79 |
|
80 |
|
81 | size: number;
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 | nodesBetween(
|
88 | from: number,
|
89 | to: number,
|
90 | f: (
|
91 | node: ProsemirrorNode<S>,
|
92 | start: number,
|
93 | parent: ProsemirrorNode<S>,
|
94 | index: number,
|
95 | ) => boolean | null | undefined | void,
|
96 | startPos?: number,
|
97 | ): void;
|
98 | |
99 |
|
100 |
|
101 |
|
102 | descendants(
|
103 | f: (node: ProsemirrorNode<S>, pos: number, parent: ProsemirrorNode<S>) => boolean | null | undefined | void,
|
104 | ): void;
|
105 | |
106 |
|
107 |
|
108 | textBetween(
|
109 | from: number,
|
110 | to: number,
|
111 | blockSeparator?: string | null,
|
112 | leafText?: string | ((leafNode: ProsemirrorNode) => string) | null,
|
113 | ): string;
|
114 | /**
|
115 | * Create a new fragment containing the combined content of this
|
116 | * fragment and the other.
|
117 | */
|
118 | append(other: Fragment<S>): Fragment<S>;
|
119 | /**
|
120 | * Cut out the sub-fragment between the two given positions.
|
121 | */
|
122 | cut(from: number, to?: number): Fragment<S>;
|
123 | /**
|
124 | * Create a new fragment in which the node at the given index is
|
125 | * replaced by the given node.
|
126 | */
|
127 | replaceChild(index: number, node: ProsemirrorNode<S>): Fragment<S>;
|
128 | /**
|
129 | * Compare this fragment to another one.
|
130 | */
|
131 | eq(other: Fragment<S>): boolean;
|
132 | /**
|
133 | * The first child of the fragment, or `null` if it is empty.
|
134 | */
|
135 | firstChild?: ProsemirrorNode<S> | null | undefined;
|
136 | /**
|
137 | * The last child of the fragment, or `null` if it is empty.
|
138 | */
|
139 | lastChild?: ProsemirrorNode<S> | null | undefined;
|
140 | /**
|
141 | * The number of child nodes in this fragment.
|
142 | */
|
143 | childCount: number;
|
144 | /**
|
145 | * Get the child node at the given index. Raise an error when the
|
146 | * index is out of range.
|
147 | */
|
148 | child(index: number): ProsemirrorNode<S>;
|
149 | /**
|
150 | * Get the child node at the given index, if it exists.
|
151 | */
|
152 | maybeChild(index: number): ProsemirrorNode<S> | null | undefined;
|
153 | /**
|
154 | * Call `f` for every child node, passing the node, its offset
|
155 | * into this parent node, and its index.
|
156 | */
|
157 | forEach(f: (node: ProsemirrorNode<S>, offset: number, index: number) => void): void;
|
158 | /**
|
159 | * Find the first position at which this fragment and another
|
160 | * fragment differ, or `null` if they are the same.
|
161 | */
|
162 | findDiffStart(other: Fragment<S>): number | null | undefined;
|
163 | /**
|
164 | * Find the first position, searching from the end, at which this
|
165 | * fragment and the given fragment differ, or `null` if they are the
|
166 | * same. Since this position will not be the same in both nodes, an
|
167 | * object with two separate positions is returned.
|
168 | */
|
169 | findDiffEnd(other: Fragment<S>): { a: number; b: number } | null | undefined;
|
170 | /**
|
171 | * Return a debugging string that describes this fragment.
|
172 | */
|
173 | toString(): string;
|
174 | /**
|
175 | * Create a JSON-serializeable representation of this fragment.
|
176 | */
|
177 | toJSON(): { [key: string]: any } | null | undefined;
|
178 | /**
|
179 | * Deserialize a fragment from its JSON representation.
|
180 | */
|
181 | static fromJSON<S extends Schema = any>(schema: S, value?: { [key: string]: any }): Fragment<S>;
|
182 | /**
|
183 | * Build a fragment from an array of nodes. Ensures that adjacent
|
184 | * text nodes with the same marks are joined together.
|
185 | */
|
186 | static fromArray<S extends Schema = any>(array: Array<ProsemirrorNode<S>>): Fragment<S>;
|
187 | /**
|
188 | * Create a fragment from something that can be interpreted as a set
|
189 | * of nodes. For `null`, it returns the empty fragment. For a
|
190 | * fragment, the fragment itself. For a node or array of nodes, a
|
191 | * fragment containing those nodes.
|
192 | */
|
193 | static from<S extends Schema = any>(
|
194 | nodes?: Fragment<S> | ProsemirrorNode<S> | Array<ProsemirrorNode<S>>,
|
195 | ): Fragment<S>;
|
196 | /**
|
197 | * An empty fragment. Intended to be reused whenever a node doesn't
|
198 | * contain anything (rather than allocating a new empty fragment for
|
199 | * each leaf node).
|
200 | */
|
201 | static empty: Fragment;
|
202 | }
|
203 | /**
|
204 | * These are the options recognized by the
|
205 | * [`parse`](#model.DOMParser.parse) and
|
206 | * [`parseSlice`](#model.DOMParser.parseSlice) methods.
|
207 | */
|
208 | export interface ParseOptions<S extends Schema = any> {
|
209 | /**
|
210 | * By default, whitespace is collapsed as per HTML's rules. Pass
|
211 | * `true` to preserve whitespace, but normalize newlines to
|
212 | * spaces, and `"full"` to preserve whitespace entirely.
|
213 | */
|
214 | preserveWhitespace?: boolean | 'full' | null | undefined;
|
215 | /**
|
216 | * When given, the parser will, beside parsing the content,
|
217 | * record the document positions of the given DOM positions. It
|
218 | * will do so by writing to the objects, adding a `pos` property
|
219 | * that holds the document position. DOM positions that are not
|
220 | * in the parsed content will not be written to.
|
221 | */
|
222 | findPositions?: Array<{ node: Node; offset: number }> | null | undefined;
|
223 | /**
|
224 | * The child node index to start parsing from.
|
225 | */
|
226 | from?: number | null | undefined;
|
227 | /**
|
228 | * The child node index to stop parsing at.
|
229 | */
|
230 | to?: number | null | undefined;
|
231 | /**
|
232 | * By default, the content is parsed into the schema's default
|
233 | * [top node type](#model.Schema.topNodeType). You can pass this
|
234 | * option to use the type and attributes from a different node
|
235 | * as the top container.
|
236 | */
|
237 | topNode?: ProsemirrorNode<S> | null | undefined;
|
238 | /**
|
239 | * Provide the starting content match that content parsed into the
|
240 | * top node is matched against.
|
241 | */
|
242 | topMatch?: ContentMatch | null | undefined;
|
243 | /**
|
244 | * A set of additional nodes to count as
|
245 | * [context](#model.ParseRule.context) when parsing, above the
|
246 | * given [top node](#model.ParseOptions.topNode).
|
247 | */
|
248 | context?: ResolvedPos<S> | null | undefined;
|
249 | }
|
250 | /**
|
251 | * A value that describes how to parse a given DOM node or inline
|
252 | * style as a ProseMirror node or mark.
|
253 | */
|
254 | export interface ParseRule {
|
255 | /**
|
256 | * A CSS selector describing the kind of DOM elements to match. A
|
257 | * single rule should have _either_ a `tag` or a `style` property.
|
258 | */
|
259 | tag?: string | null | undefined;
|
260 | /**
|
261 | * The namespace to match. This should be used with `tag`.
|
262 | * Nodes are only matched when the namespace matches or this property
|
263 | * is null.
|
264 | */
|
265 | namespace?: string | null | undefined;
|
266 | /**
|
267 | * A CSS property name to match. When given, this rule matches
|
268 | * inline styles that list that property. May also have the form
|
269 | * `"property=value"`, in which case the rule only matches if the
|
270 | * propery's value exactly matches the given value. (For more
|
271 | * complicated filters, use [`getAttrs`](#model.ParseRule.getAttrs)
|
272 | * and return undefined to indicate that the match failed.)
|
273 | */
|
274 | style?: string | null | undefined;
|
275 | /**
|
276 | * Can be used to change the order in which the parse rules in a
|
277 | * schema are tried. Those with higher priority come first. Rules
|
278 | * without a priority are counted as having priority 50. This
|
279 | * property is only meaningful in a schema—when directly
|
280 | * constructing a parser, the order of the rule array is used.
|
281 | */
|
282 | priority?: number | null | undefined;
|
283 | /**
|
284 | * By default, when a rule matches an element or style, no further
|
285 | * rules get a chance to match it. By setting this to false,
|
286 | * you indicate that even when this rule matches, other rules
|
287 | * that come after it should also run.
|
288 | */
|
289 | consuming?: boolean | null | undefined;
|
290 | /**
|
291 | * When given, restricts this rule to only match when the current
|
292 | * context—the parent nodes into which the content is being
|
293 | * parsed—matches this expression. Should contain one or more node
|
294 | * names or node group names followed by single or double slashes.
|
295 | * For example `"paragraph/"` means the rule only matches when the
|
296 | * parent node is a paragraph, `"blockquote/paragraph/"` restricts
|
297 | * it to be in a paragraph that is inside a blockquote, and
|
298 | * `"section//"` matches any position inside a section—a double
|
299 | * slash matches any sequence of ancestor nodes. To allow multiple
|
300 | * different contexts, they can be separated by a pipe (`|`)
|
301 | * character, as in `"blockquote/|list_item/"`.
|
302 | */
|
303 | context?: string | null | undefined;
|
304 | /**
|
305 | * The name of the node type to create when this rule matches. Only
|
306 | * valid for rules with a `tag` property, not for style rules. Each
|
307 | * rule should have one of a `node`, `mark`, or `ignore` property
|
308 | * (except when it appears in a [node](#model.NodeSpec.parseDOM) or
|
309 | * [mark spec](#model.MarkSpec.parseDOM), in which case the `node`
|
310 | * or `mark` property will be derived from its position).
|
311 | */
|
312 | node?: string | null | undefined;
|
313 | /**
|
314 | * The name of the mark type to wrap the matched content in.
|
315 | */
|
316 | mark?: string | null | undefined;
|
317 | /**
|
318 | * When true, ignore content that matches this rule.
|
319 | */
|
320 | ignore?: boolean | null | undefined;
|
321 | /**
|
322 | * When true, ignore the node that matches this rule, but do parse
|
323 | * its content.
|
324 | */
|
325 | skip?: boolean | null | undefined;
|
326 | /**
|
327 | * Attributes for the node or mark created by this rule. When
|
328 | * `getAttrs` is provided, it takes precedence.
|
329 | */
|
330 | attrs?: { [key: string]: any } | null | undefined;
|
331 | /**
|
332 | * A function used to compute the attributes for the node or mark
|
333 | * created by this rule. Can also be used to describe further
|
334 | * conditions the DOM element or style must match. When it returns
|
335 | * `false`, the rule won't match. When it returns null or undefined,
|
336 | * that is interpreted as an empty/default set of attributes.
|
337 | *
|
338 | * Called with a DOM Element for `tag` rules, and with a string (the
|
339 | * style's value) for `style` rules.
|
340 | */
|
341 | getAttrs?: ((p: Node | string) => { [key: string]: any } | false | null | undefined) | null | undefined;
|
342 | /**
|
343 | * For `tag` rules that produce non-leaf nodes or marks, by default
|
344 | * the content of the DOM element is parsed as content of the mark
|
345 | * or node. If the child nodes are in a descendent node, this may be
|
346 | * a CSS selector string that the parser must use to find the actual
|
347 | * content element, or a function that returns the actual content
|
348 | * element to the parser.
|
349 | */
|
350 | contentElement?: string | ((p: Node) => Node) | null | undefined;
|
351 | /**
|
352 | * Can be used to override the content of a matched node. When
|
353 | * present, instead of parsing the node's child nodes, the result of
|
354 | * this function is used.
|
355 | */
|
356 | getContent?: (<S extends Schema = any>(p: Node, schema: S) => Fragment<S>) | null | undefined;
|
357 | /**
|
358 | * Controls whether whitespace should be preserved when parsing the
|
359 | * content inside the matched element. `false` means whitespace may
|
360 | * be collapsed, `true` means that whitespace should be preserved
|
361 | * but newlines normalized to spaces, and `"full"` means that
|
362 | * newlines should also be preserved.
|
363 | */
|
364 | preserveWhitespace?: boolean | 'full' | null | undefined;
|
365 | }
|
366 | /**
|
367 | * A DOM parser represents a strategy for parsing DOM content into
|
368 | * a ProseMirror document conforming to a given schema. Its behavior
|
369 | * is defined by an array of [rules](#model.ParseRule).
|
370 | */
|
371 | export class DOMParser<S extends Schema = any> {
|
372 | /**
|
373 | * Create a parser that targets the given schema, using the given
|
374 | * parsing rules.
|
375 | */
|
376 | constructor(schema: S, rules: ParseRule[]);
|
377 | /**
|
378 | * The schema into which the parser parses.
|
379 | */
|
380 | schema: S;
|
381 | /**
|
382 | * The set of [parse rules](#model.ParseRule) that the parser
|
383 | * uses, in order of precedence.
|
384 | */
|
385 | rules: ParseRule[];
|
386 | /**
|
387 | * Parse a document from the content of a DOM node.
|
388 | */
|
389 | parse(dom: Node, options?: ParseOptions<S>): ProsemirrorNode<S>;
|
390 | /**
|
391 | * Parses the content of the given DOM node, like
|
392 | * [`parse`](#model.DOMParser.parse), and takes the same set of
|
393 | * options. But unlike that method, which produces a whole node,
|
394 | * this one returns a slice that is open at the sides, meaning that
|
395 | * the schema constraints aren't applied to the start of nodes to
|
396 | * the left of the input and the end of nodes at the end.
|
397 | */
|
398 | parseSlice(dom: Node, options?: ParseOptions<S>): Slice<S>;
|
399 | /**
|
400 | * Construct a DOM parser using the parsing rules listed in a
|
401 | * schema's [node specs](#model.NodeSpec.parseDOM), reordered by
|
402 | * [priority](#model.ParseRule.priority).
|
403 | */
|
404 | static fromSchema<S extends Schema = any>(schema: S): DOMParser<S>;
|
405 | }
|
406 | /**
|
407 | * A mark is a piece of information that can be attached to a node,
|
408 | * such as it being emphasized, in code font, or a link. It has a type
|
409 | * and optionally a set of attributes that provide further information
|
410 | * (such as the target of the link). Marks are created through a
|
411 | * `Schema`, which controls which types exist and which
|
412 | * attributes they have.
|
413 | */
|
414 | export class Mark<S extends Schema = any> {
|
415 | /**
|
416 | * The type of this mark.
|
417 | */
|
418 | type: MarkType<S>;
|
419 | /**
|
420 | * The attributes associated with this mark.
|
421 | */
|
422 | attrs: { [key: string]: any };
|
423 | /**
|
424 | * Given a set of marks, create a new set which contains this one as
|
425 | * well, in the right position. If this mark is already in the set,
|
426 | * the set itself is returned. If any marks that are set to be
|
427 | * [exclusive](#model.MarkSpec.excludes) with this mark are present,
|
428 | * those are replaced by this one.
|
429 | */
|
430 | addToSet(set: Array<Mark<S>>): Array<Mark<S>>;
|
431 | /**
|
432 | * Remove this mark from the given set, returning a new set. If this
|
433 | * mark is not in the set, the set itself is returned.
|
434 | */
|
435 | removeFromSet(set: Array<Mark<S>>): Array<Mark<S>>;
|
436 | /**
|
437 | * Test whether this mark is in the given set of marks.
|
438 | */
|
439 | isInSet(set: Array<Mark<S>>): boolean;
|
440 | /**
|
441 | * Test whether this mark has the same type and attributes as
|
442 | * another mark.
|
443 | */
|
444 | eq(other: Mark<S>): boolean;
|
445 | /**
|
446 | * Convert this mark to a JSON-serializeable representation.
|
447 | */
|
448 | toJSON(): { [key: string]: any };
|
449 | static fromJSON<S extends Schema = any>(schema: S, json: { [key: string]: any }): Mark<S>;
|
450 | /**
|
451 | * Test whether two sets of marks are identical.
|
452 | */
|
453 | static sameSet<S extends Schema = any>(a: Array<Mark<S>>, b: Array<Mark<S>>): boolean;
|
454 | /**
|
455 | * Create a properly sorted mark set from null, a single mark, or an
|
456 | * unsorted array of marks.
|
457 | */
|
458 | static setFrom<S extends Schema = any>(marks?: Mark<S> | Array<Mark<S>>): Array<Mark<S>>;
|
459 | /**
|
460 | * The empty set of marks.
|
461 | */
|
462 | static none: Mark[];
|
463 | }
|
464 | /**
|
465 | * This class represents a node in the tree that makes up a
|
466 | * ProseMirror document. So a document is an instance of `Node`, with
|
467 | * children that are also instances of `Node`.
|
468 | *
|
469 | * Nodes are persistent data structures. Instead of changing them, you
|
470 | * create new ones with the content you want. Old ones keep pointing
|
471 | * at the old document shape. This is made cheaper by sharing
|
472 | * structure between the old and new data as much as possible, which a
|
473 | * tree shape like this (without back pointers) makes easy.
|
474 | *
|
475 | * **Do not** directly mutate the properties of a `Node` object. See
|
476 | * [the guide](/docs/guide/#doc) for more information.
|
477 | */
|
478 | declare class ProsemirrorNode<S extends Schema = any> {
|
479 | /**
|
480 | * The type of node that this is.
|
481 | */
|
482 | type: NodeType<S>;
|
483 | /**
|
484 | * An object mapping attribute names to values. The kind of
|
485 | * attributes allowed and required are
|
486 | * [determined](#model.NodeSpec.attrs) by the node type.
|
487 | */
|
488 | attrs: { [key: string]: any };
|
489 | /**
|
490 | * A container holding the node's children.
|
491 | */
|
492 | content: Fragment<S>;
|
493 | /**
|
494 | * The marks (things like whether it is emphasized or part of a
|
495 | * link) applied to this node.
|
496 | */
|
497 | marks: Array<Mark<S>>;
|
498 | /**
|
499 | * For text nodes, this contains the node's text content.
|
500 | */
|
501 | text?: string | null | undefined;
|
502 | /**
|
503 | * The size of this node, as defined by the integer-based [indexing
|
504 | * scheme](/docs/guide/#doc.indexing). For text nodes, this is the
|
505 | * amount of characters. For other leaf nodes, it is one. For
|
506 | * non-leaf nodes, it is the size of the content plus two (the start
|
507 | * and end token).
|
508 | */
|
509 | nodeSize: number;
|
510 | /**
|
511 | * The number of children that the node has.
|
512 | */
|
513 | childCount: number;
|
514 | /**
|
515 | * Get the child node at the given index. Raises an error when the
|
516 | * index is out of range.
|
517 | */
|
518 | child(index: number): ProsemirrorNode<S>;
|
519 | /**
|
520 | * Get the child node at the given index, if it exists.
|
521 | */
|
522 | maybeChild(index: number): ProsemirrorNode<S> | null | undefined;
|
523 | /**
|
524 | * Call `f` for every child node, passing the node, its offset
|
525 | * into this parent node, and its index.
|
526 | */
|
527 | forEach(f: (node: ProsemirrorNode<S>, offset: number, index: number) => void): void;
|
528 | /**
|
529 | * Invoke a callback for all descendant nodes recursively between
|
530 | * the given two positions that are relative to start of this node's
|
531 | * content. The callback is invoked with the node, its
|
532 | * parent-relative position, its parent node, and its child index.
|
533 | * When the callback returns false for a given node, that node's
|
534 | * children will not be recursed over.
|
535 | */
|
536 | nodesBetween(
|
537 | from: number,
|
538 | to: number,
|
539 | f: (
|
540 | node: ProsemirrorNode<S>,
|
541 | pos: number,
|
542 | parent: ProsemirrorNode<S>,
|
543 | index: number,
|
544 | ) => boolean | null | undefined | void,
|
545 | startPos?: number,
|
546 | ): void;
|
547 | /**
|
548 | * Call the given callback for every descendant node. Doesn't
|
549 | * descend into a node when the callback returns `false`.
|
550 | */
|
551 | descendants(
|
552 | f: (node: ProsemirrorNode<S>, pos: number, parent: ProsemirrorNode<S>) => boolean | null | undefined | void,
|
553 | ): void;
|
554 | /**
|
555 | * Concatenates all the text nodes found in this fragment and its
|
556 | * children.
|
557 | */
|
558 | textContent: string;
|
559 | /**
|
560 | * Get all text between positions `from` and `to`. When
|
561 | * `blockSeparator` is given, it will be inserted whenever a new
|
562 | * block node is started. When `leafText` is given, it'll be
|
563 | * inserted for every non-text leaf node encountered.
|
564 | */
|
565 | textBetween(
|
566 | from: number,
|
567 | to: number,
|
568 | blockSeparator?: string,
|
569 | leafText?: string | ((leafNode: ProsemirrorNode) => string) | null,
|
570 | ): string;
|
571 | /**
|
572 | * Returns this node's first child, or `null` if there are no
|
573 | * children.
|
574 | */
|
575 | firstChild?: ProsemirrorNode<S> | null | undefined;
|
576 | /**
|
577 | * Returns this node's last child, or `null` if there are no
|
578 | * children.
|
579 | */
|
580 | lastChild?: ProsemirrorNode<S> | null | undefined;
|
581 | /**
|
582 | * Test whether two nodes represent the same piece of document.
|
583 | */
|
584 | eq(other: ProsemirrorNode<S>): boolean;
|
585 | /**
|
586 | * Compare the markup (type, attributes, and marks) of this node to
|
587 | * those of another. Returns `true` if both have the same markup.
|
588 | */
|
589 | sameMarkup(other: ProsemirrorNode<S>): boolean;
|
590 | /**
|
591 | * Check whether this node's markup correspond to the given type,
|
592 | * attributes, and marks.
|
593 | */
|
594 | hasMarkup(type: NodeType<S>, attrs?: { [key: string]: any }, marks?: Array<Mark<S>>): boolean;
|
595 | /**
|
596 | * Create a new node with the same markup as this node, containing
|
597 | * the given content (or empty, if no content is given).
|
598 | */
|
599 | copy(content?: Fragment<S>): ProsemirrorNode<S>;
|
600 | /**
|
601 | * Create a copy of this node, with the given set of marks instead
|
602 | * of the node's own marks.
|
603 | */
|
604 | mark(marks: Array<Mark<S>>): ProsemirrorNode<S>;
|
605 | /**
|
606 | * Create a copy of this node with only the content between the
|
607 | * given positions. If `to` is not given, it defaults to the end of
|
608 | * the node.
|
609 | */
|
610 | cut(from: number, to?: number): ProsemirrorNode<S>;
|
611 | /**
|
612 | * Cut out the part of the document between the given positions, and
|
613 | * return it as a `Slice` object.
|
614 | */
|
615 | slice(from: number, to?: number): Slice<S>;
|
616 | /**
|
617 | * Replace the part of the document between the given positions with
|
618 | * the given slice. The slice must 'fit', meaning its open sides
|
619 | * must be able to connect to the surrounding content, and its
|
620 | * content nodes must be valid children for the node they are placed
|
621 | * into. If any of this is violated, an error of type
|
622 | * [`ReplaceError`](#model.ReplaceError) is thrown.
|
623 | */
|
624 | replace(from: number, to: number, slice: Slice<S>): ProsemirrorNode<S>;
|
625 | /**
|
626 | * Find the node starting at the given position.
|
627 | */
|
628 | nodeAt(pos: number): ProsemirrorNode<S> | null | undefined;
|
629 | /**
|
630 | * Find the (direct) child node after the given offset, if any,
|
631 | * and return it along with its index and offset relative to this
|
632 | * node.
|
633 | */
|
634 | childAfter(pos: number): { node?: ProsemirrorNode<S> | null | undefined; index: number; offset: number };
|
635 | /**
|
636 | * Find the (direct) child node before the given offset, if any,
|
637 | * and return it along with its index and offset relative to this
|
638 | * node.
|
639 | */
|
640 | childBefore(pos: number): { node?: ProsemirrorNode<S> | null | undefined; index: number; offset: number };
|
641 | /**
|
642 | * Resolve the given position in the document, returning an
|
643 | * [object](#model.ResolvedPos) with information about its context.
|
644 | */
|
645 | resolve(pos: number): ResolvedPos<S>;
|
646 | /**
|
647 | * Test whether a given mark or mark type occurs in this document
|
648 | * between the two given positions.
|
649 | */
|
650 | rangeHasMark(from: number, to: number, type: Mark<S> | MarkType<S>): boolean;
|
651 | /**
|
652 | * True when this is a block (non-inline node)
|
653 | */
|
654 | isBlock: boolean;
|
655 | /**
|
656 | * True when this is a textblock node, a block node with inline
|
657 | * content.
|
658 | */
|
659 | isTextblock: boolean;
|
660 | /**
|
661 | * True when this node has inline content.
|
662 | */
|
663 | inlineContent: boolean;
|
664 | /**
|
665 | * True when this is an inline node (a text node or a node that can
|
666 | * appear among text).
|
667 | */
|
668 | isInline: boolean;
|
669 | /**
|
670 | * True when this is a text node.
|
671 | */
|
672 | isText: boolean;
|
673 | /**
|
674 | * True when this is a leaf node.
|
675 | */
|
676 | isLeaf: boolean;
|
677 | /**
|
678 | * True when this is an atom, i.e. when it does not have directly
|
679 | * editable content. This is usually the same as `isLeaf`, but can
|
680 | * be configured with the [`atom` property](#model.NodeSpec.atom) on
|
681 | * a node's spec (typically used when the node is displayed as an
|
682 | * uneditable [node view](#view.NodeView)).
|
683 | */
|
684 | isAtom: boolean;
|
685 | /**
|
686 | * The node type's [whitespace](#view.NodeSpec.whitespace) option.
|
687 | */
|
688 | whitespace: 'pre' | 'normal';
|
689 | /**
|
690 | * Return a string representation of this node for debugging
|
691 | * purposes.
|
692 | */
|
693 | toString(): string;
|
694 | /**
|
695 | * Get the content match in this node at the given index.
|
696 | */
|
697 | contentMatchAt(index: number): ContentMatch<S>;
|
698 | /**
|
699 | * Test whether replacing the range between `from` and `to` (by
|
700 | * child index) with the given replacement fragment (which defaults
|
701 | * to the empty fragment) would leave the node's content valid. You
|
702 | * can optionally pass `start` and `end` indices into the
|
703 | * replacement fragment.
|
704 | */
|
705 | canReplace(from: number, to: number, replacement?: Fragment<S>, start?: number, end?: number): boolean;
|
706 | /**
|
707 | * Test whether replacing the range `from` to `to` (by index) with a
|
708 | * node of the given type.
|
709 | */
|
710 | canReplaceWith(from: number, to: number, type: NodeType<S>, marks?: Array<Mark<S>>): boolean;
|
711 | /**
|
712 | * Test whether the given node's content could be appended to this
|
713 | * node. If that node is empty, this will only return true if there
|
714 | * is at least one node type that can appear in both nodes (to avoid
|
715 | * merging completely incompatible nodes).
|
716 | */
|
717 | canAppend(other: ProsemirrorNode<S>): boolean;
|
718 | /**
|
719 | * Check whether this node and its descendants conform to the
|
720 | * schema, and raise error when they do not.
|
721 | */
|
722 | check(): void;
|
723 | /**
|
724 | * Return a JSON-serializeable representation of this node.
|
725 | */
|
726 | toJSON(): { [key: string]: any };
|
727 | /**
|
728 | * Deserialize a node from its JSON representation.
|
729 | */
|
730 | static fromJSON<S extends Schema = any>(schema: S, json: { [key: string]: any }): ProsemirrorNode<S>;
|
731 | }
|
732 | export { ProsemirrorNode as Node };
|
733 | /**
|
734 | * Error type raised by [`Node.replace`](#model.Node.replace) when
|
735 | * given an invalid replacement.
|
736 | */
|
737 | export class ReplaceError extends Error {}
|
738 | /**
|
739 | * A slice represents a piece cut out of a larger document. It
|
740 | * stores not only a fragment, but also the depth up to which nodes on
|
741 | * both side are ‘open’ (cut through).
|
742 | */
|
743 | export class Slice<S extends Schema = any> {
|
744 | /**
|
745 | * Create a slice. When specifying a non-zero open depth, you must
|
746 | * make sure that there are nodes of at least that depth at the
|
747 | * appropriate side of the fragment—i.e. if the fragment is an empty
|
748 | * paragraph node, `openStart` and `openEnd` can't be greater than
|
749 | * 1.
|
750 | *
|
751 | * It is not necessary for the content of open nodes to conform to
|
752 | * the schema's content constraints, though it should be a valid
|
753 | * start/end/middle for such a node, depending on which sides are
|
754 | * open.
|
755 | */
|
756 | constructor(content: Fragment<S>, openStart: number, openEnd: number);
|
757 | /**
|
758 | * The slice's content.
|
759 | */
|
760 | content: Fragment<S>;
|
761 | /**
|
762 | * The open depth at the start.
|
763 | */
|
764 | openStart: number;
|
765 | /**
|
766 | * The open depth at the end.
|
767 | */
|
768 | openEnd: number;
|
769 | /**
|
770 | * The size this slice would add when inserted into a document.
|
771 | */
|
772 | size: number;
|
773 | /**
|
774 | * Tests whether this slice is equal to another slice.
|
775 | */
|
776 | eq(other: Slice<S>): boolean;
|
777 | /**
|
778 | * Convert a slice to a JSON-serializable representation.
|
779 | */
|
780 | toJSON(): { [key: string]: any } | null | undefined;
|
781 | /**
|
782 | * Deserialize a slice from its JSON representation.
|
783 | */
|
784 | static fromJSON<S extends Schema = any>(schema: S, json?: { [key: string]: any }): Slice<S>;
|
785 | /**
|
786 | * Create a slice from a fragment by taking the maximum possible
|
787 | * open value on both side of the fragment.
|
788 | */
|
789 | static maxOpen<S extends Schema = any>(fragment: Fragment<S>, openIsolating?: boolean): Slice<S>;
|
790 | /**
|
791 | * The empty slice.
|
792 | */
|
793 | static empty: Slice;
|
794 | }
|
795 | /**
|
796 | * You can [_resolve_](#model.Node.resolve) a position to get more
|
797 | * information about it. Objects of this class represent such a
|
798 | * resolved position, providing various pieces of context information,
|
799 | * and some helper methods.
|
800 | *
|
801 | * Throughout this interface, methods that take an optional `depth`
|
802 | * parameter will interpret undefined as `this.depth` and negative
|
803 | * numbers as `this.depth + value`.
|
804 | */
|
805 | export class ResolvedPos<S extends Schema = any> {
|
806 | /**
|
807 | * The position that was resolved.
|
808 | */
|
809 | pos: number;
|
810 | /**
|
811 | * The number of levels the parent node is from the root. If this
|
812 | * position points directly into the root node, it is 0. If it
|
813 | * points into a top-level paragraph, 1, and so on.
|
814 | */
|
815 | depth: number;
|
816 | /**
|
817 | * The offset this position has into its parent node.
|
818 | */
|
819 | parentOffset: number;
|
820 | /**
|
821 | * The parent node that the position points into. Note that even if
|
822 | * a position points into a text node, that node is not considered
|
823 | * the parent—text nodes are ‘flat’ in this model, and have no content.
|
824 | */
|
825 | parent: ProsemirrorNode<S>;
|
826 | /**
|
827 | * The root node in which the position was resolved.
|
828 | */
|
829 | doc: ProsemirrorNode<S>;
|
830 | /**
|
831 | * The ancestor node at the given level. `p.node(p.depth)` is the
|
832 | * same as `p.parent`.
|
833 | */
|
834 | node(depth?: number): ProsemirrorNode<S>;
|
835 | /**
|
836 | * The index into the ancestor at the given level. If this points at
|
837 | * the 3rd node in the 2nd paragraph on the top level, for example,
|
838 | * `p.index(0)` is 2 and `p.index(1)` is 3.
|
839 | */
|
840 | index(depth?: number): number;
|
841 | /**
|
842 | * The index pointing after this position into the ancestor at the
|
843 | * given level.
|
844 | */
|
845 | indexAfter(depth?: number): number;
|
846 | /**
|
847 | * The (absolute) position at the start of the node at the given
|
848 | * level.
|
849 | */
|
850 | start(depth?: number): number;
|
851 | /**
|
852 | * The (absolute) position at the end of the node at the given
|
853 | * level.
|
854 | */
|
855 | end(depth?: number): number;
|
856 | /**
|
857 | * The (absolute) position directly before the wrapping node at the
|
858 | * given level, or, when `level` is `this.depth + 1`, the original
|
859 | * position.
|
860 | */
|
861 | before(depth?: number): number;
|
862 | /**
|
863 | * The (absolute) position directly after the wrapping node at the
|
864 | * given level, or the original position when `level` is `this.depth + 1`.
|
865 | */
|
866 | after(depth?: number): number;
|
867 | /**
|
868 | * When this position points into a text node, this returns the
|
869 | * distance between the position and the start of the text node.
|
870 | * Will be zero for positions that point between nodes.
|
871 | */
|
872 | textOffset: number;
|
873 | /**
|
874 | * Get the node directly after the position, if any. If the position
|
875 | * points into a text node, only the part of that node after the
|
876 | * position is returned.
|
877 | */
|
878 | nodeAfter?: ProsemirrorNode<S> | null | undefined;
|
879 | /**
|
880 | * Get the node directly before the position, if any. If the
|
881 | * position points into a text node, only the part of that node
|
882 | * before the position is returned.
|
883 | */
|
884 | nodeBefore?: ProsemirrorNode<S> | null | undefined;
|
885 | /**
|
886 | * Get the position at the given index in the parent node at the
|
887 | * given depth (which defaults to this.depth).
|
888 | */
|
889 | posAtIndex(index: number, depth?: number): number;
|
890 | /**
|
891 | * Get the marks at this position, factoring in the surrounding
|
892 | * marks' [`inclusive`](#model.MarkSpec.inclusive) property. If the
|
893 | * position is at the start of a non-empty node, the marks of the
|
894 | * node after it (if any) are returned.
|
895 | */
|
896 | marks(): Array<Mark<S>>;
|
897 | /**
|
898 | * Get the marks after the current position, if any, except those
|
899 | * that are non-inclusive and not present at position `$end`. This
|
900 | * is mostly useful for getting the set of marks to preserve after a
|
901 | * deletion. Will return `null` if this position is at the end of
|
902 | * its parent node or its parent node isn't a textblock (in which
|
903 | * case no marks should be preserved).
|
904 | */
|
905 | marksAcross($end: ResolvedPos<S>): Array<Mark<S>> | null | undefined;
|
906 | /**
|
907 | * The depth up to which this position and the given (non-resolved)
|
908 | * position share the same parent nodes.
|
909 | */
|
910 | sharedDepth(pos: number): number;
|
911 | /**
|
912 | * Returns a range based on the place where this position and the
|
913 | * given position diverge around block content. If both point into
|
914 | * the same textblock, for example, a range around that textblock
|
915 | * will be returned. If they point into different blocks, the range
|
916 | * around those blocks in their shared ancestor is returned. You can
|
917 | * pass in an optional predicate that will be called with a parent
|
918 | * node to see if a range into that parent is acceptable.
|
919 | */
|
920 | blockRange(other?: ResolvedPos<S>, pred?: (p: ProsemirrorNode<S>) => boolean): NodeRange<S> | null | undefined;
|
921 | /**
|
922 | * Query whether the given position shares the same parent node.
|
923 | */
|
924 | sameParent(other: ResolvedPos<S>): boolean;
|
925 | /**
|
926 | * Return the greater of this and the given position.
|
927 | */
|
928 | max(other: ResolvedPos<S>): ResolvedPos<S>;
|
929 | /**
|
930 | * Return the smaller of this and the given position.
|
931 | */
|
932 | min(other: ResolvedPos<S>): ResolvedPos<S>;
|
933 | }
|
934 | /**
|
935 | * Represents a flat range of content, i.e. one that starts and
|
936 | * ends in the same node.
|
937 | */
|
938 | export class NodeRange<S extends Schema = any> {
|
939 | /**
|
940 | * Construct a node range. `$from` and `$to` should point into the
|
941 | * same node until at least the given `depth`, since a node range
|
942 | * denotes an adjacent set of nodes in a single parent node.
|
943 | */
|
944 | constructor($from: ResolvedPos<S>, $to: ResolvedPos<S>, depth: number);
|
945 | /**
|
946 | * A resolved position along the start of the
|
947 | * content. May have a `depth` greater than this object's `depth`
|
948 | * property, since these are the positions that were used to
|
949 | * compute the range, not re-resolved positions directly at its
|
950 | * boundaries.
|
951 | */
|
952 | $from: ResolvedPos<S>;
|
953 | /**
|
954 | * A position along the end of the content. See
|
955 | * caveat for [`$from`](#model.NodeRange.$from).
|
956 | */
|
957 | $to: ResolvedPos<S>;
|
958 | /**
|
959 | * The depth of the node that this range points into.
|
960 | */
|
961 | depth: number;
|
962 | /**
|
963 | * The position at the start of the range.
|
964 | */
|
965 | start: number;
|
966 | /**
|
967 | * The position at the end of the range.
|
968 | */
|
969 | end: number;
|
970 | /**
|
971 | * The parent node that the range points into.
|
972 | */
|
973 | parent: ProsemirrorNode<S>;
|
974 | /**
|
975 | * The start index of the range in the parent node.
|
976 | */
|
977 | startIndex: number;
|
978 | /**
|
979 | * The end index of the range in the parent node.
|
980 | */
|
981 | endIndex: number;
|
982 | }
|
983 | /**
|
984 | * Node types are objects allocated once per `Schema` and used to
|
985 | * [tag](#model.Node.type) `Node` instances. They contain information
|
986 | * about the node type, such as its name and what kind of node it
|
987 | * represents.
|
988 | */
|
989 | export class NodeType<S extends Schema = any> {
|
990 | /**
|
991 | * The name the node type has in this schema.
|
992 | */
|
993 | name: string;
|
994 | /**
|
995 | * A link back to the `Schema` the node type belongs to.
|
996 | */
|
997 | schema: S;
|
998 | /**
|
999 | * The spec that this type is based on
|
1000 | */
|
1001 | spec: NodeSpec;
|
1002 | /**
|
1003 | * The starting match of the node type's content expression.
|
1004 | */
|
1005 | contentMatch: ContentMatch<S>;
|
1006 | /**
|
1007 | * True if this node type has inline content.
|
1008 | */
|
1009 | inlineContent: boolean;
|
1010 | /**
|
1011 | * True if this is a block type
|
1012 | */
|
1013 | isBlock: boolean;
|
1014 | /**
|
1015 | * True if this is the text node type.
|
1016 | */
|
1017 | isText: boolean;
|
1018 | /**
|
1019 | * True if this is an inline type.
|
1020 | */
|
1021 | isInline: boolean;
|
1022 | /**
|
1023 | * True if this is a textblock type, a block that contains inline
|
1024 | * content.
|
1025 | */
|
1026 | isTextblock: boolean;
|
1027 | /**
|
1028 | * True for node types that allow no content.
|
1029 | */
|
1030 | isLeaf: boolean;
|
1031 | /**
|
1032 | * True when this node is an atom, i.e. when it does not have
|
1033 | * directly editable content.
|
1034 | */
|
1035 | isAtom: boolean;
|
1036 | /**
|
1037 | * Tells you whether this node type has any required attributes.
|
1038 | */
|
1039 | hasRequiredAttrs(): boolean;
|
1040 | /**
|
1041 | * Create a `Node` of this type. The given attributes are
|
1042 | * checked and defaulted (you can pass `null` to use the type's
|
1043 | * defaults entirely, if no required attributes exist). `content`
|
1044 | * may be a `Fragment`, a node, an array of nodes, or
|
1045 | * `null`. Similarly `marks` may be `null` to default to the empty
|
1046 | * set of marks.
|
1047 | */
|
1048 | create(
|
1049 | attrs?: { [key: string]: any } | null,
|
1050 | content?: Fragment<S> | ProsemirrorNode<S> | Array<ProsemirrorNode<S>>,
|
1051 | marks?: Array<Mark<S>>,
|
1052 | ): ProsemirrorNode<S>;
|
1053 | /**
|
1054 | * Like [`create`](#model.NodeType.create), but check the given content
|
1055 | * against the node type's content restrictions, and throw an error
|
1056 | * if it doesn't match.
|
1057 | */
|
1058 | createChecked(
|
1059 | attrs?: { [key: string]: any } | null,
|
1060 | content?: Fragment<S> | ProsemirrorNode<S> | Array<ProsemirrorNode<S>>,
|
1061 | marks?: Array<Mark<S>>,
|
1062 | ): ProsemirrorNode<S>;
|
1063 | /**
|
1064 | * Like [`create`](#model.NodeType.create), but see if it is necessary to
|
1065 | * add nodes to the start or end of the given fragment to make it
|
1066 | * fit the node. If no fitting wrapping can be found, return null.
|
1067 | * Note that, due to the fact that required nodes can always be
|
1068 | * created, this will always succeed if you pass null or
|
1069 | * `Fragment.empty` as content.
|
1070 | */
|
1071 | createAndFill(
|
1072 | attrs?: { [key: string]: any } | null,
|
1073 | content?: Fragment<S> | ProsemirrorNode<S> | Array<ProsemirrorNode<S>>,
|
1074 | marks?: Array<Mark<S>>,
|
1075 | ): ProsemirrorNode<S> | null | undefined;
|
1076 | /**
|
1077 | * Returns true if the given fragment is valid content for this node
|
1078 | * type with the given attributes.
|
1079 | */
|
1080 | validContent(content: Fragment<S>): boolean;
|
1081 | /**
|
1082 | * Check whether the given mark type is allowed in this node.
|
1083 | */
|
1084 | allowsMarkType(markType: MarkType<S>): boolean;
|
1085 | /**
|
1086 | * Test whether the given set of marks are allowed in this node.
|
1087 | */
|
1088 | allowsMarks(marks: Array<Mark<S>>): boolean;
|
1089 | /**
|
1090 | * Removes the marks that are not allowed in this node from the given set.
|
1091 | */
|
1092 | allowedMarks(marks: Array<Mark<S>>): Array<Mark<S>>;
|
1093 | }
|
1094 | /**
|
1095 | * Like nodes, marks (which are associated with nodes to signify
|
1096 | * things like emphasis or being part of a link) are
|
1097 | * [tagged](#model.Mark.type) with type objects, which are
|
1098 | * instantiated once per `Schema`.
|
1099 | */
|
1100 | export class MarkType<S extends Schema = any> {
|
1101 | /**
|
1102 | * The name of the mark type.
|
1103 | */
|
1104 | name: string;
|
1105 | /**
|
1106 | * The schema that this mark type instance is part of.
|
1107 | */
|
1108 | schema: S;
|
1109 | /**
|
1110 | * The spec on which the type is based.
|
1111 | */
|
1112 | spec: MarkSpec;
|
1113 | /**
|
1114 | * Create a mark of this type. `attrs` may be `null` or an object
|
1115 | * containing only some of the mark's attributes. The others, if
|
1116 | * they have defaults, will be added.
|
1117 | */
|
1118 | create(attrs?: { [key: string]: any }): Mark<S>;
|
1119 | /**
|
1120 | * When there is a mark of this type in the given set, a new set
|
1121 | * without it is returned. Otherwise, the input set is returned.
|
1122 | */
|
1123 | removeFromSet(set: Array<Mark<S>>): Array<Mark<S>>;
|
1124 | /**
|
1125 | * Tests whether there is a mark of this type in the given set.
|
1126 | */
|
1127 | isInSet(set: Array<Mark<S>>): Mark<S> | null | undefined;
|
1128 | /**
|
1129 | * Queries whether a given mark type is
|
1130 | * [excluded](#model.MarkSpec.excludes) by this one.
|
1131 | */
|
1132 | excludes(other: MarkType<S>): boolean;
|
1133 | }
|
1134 | /**
|
1135 | * An object describing a schema, as passed to the [`Schema`](#model.Schema)
|
1136 | * constructor.
|
1137 | */
|
1138 | export interface SchemaSpec<N extends string = any, M extends string = any> {
|
1139 | /**
|
1140 | * The node types in this schema. Maps names to
|
1141 | * [`NodeSpec`](#model.NodeSpec) objects that describe the node type
|
1142 | * associated with that name. Their order is significant—it
|
1143 | * determines which [parse rules](#model.NodeSpec.parseDOM) take
|
1144 | * precedence by default, and which nodes come first in a given
|
1145 | * [group](#model.NodeSpec.group).
|
1146 | */
|
1147 | nodes: { [name in N]: NodeSpec } | OrderedMap<NodeSpec>;
|
1148 | /**
|
1149 | * The mark types that exist in this schema. The order in which they
|
1150 | * are provided determines the order in which [mark
|
1151 | * sets](#model.Mark.addToSet) are sorted and in which [parse
|
1152 | * rules](#model.MarkSpec.parseDOM) are tried.
|
1153 | */
|
1154 | marks?: { [name in M]: MarkSpec } | OrderedMap<MarkSpec> | null | undefined;
|
1155 | /**
|
1156 | * The name of the default top-level node for the schema. Defaults
|
1157 | * to `"doc"`.
|
1158 | */
|
1159 | topNode?: string | null | undefined;
|
1160 | }
|
1161 | export interface NodeSpec {
|
1162 | /**
|
1163 | * The content expression for this node, as described in the [schema
|
1164 | * guide](/docs/guide/#schema.content_expressions). When not given,
|
1165 | * the node does not allow any content.
|
1166 | */
|
1167 | content?: string | null | undefined;
|
1168 | /**
|
1169 | * The marks that are allowed inside of this node. May be a
|
1170 | * space-separated string referring to mark names or groups, `"_"`
|
1171 | * to explicitly allow all marks, or `""` to disallow marks. When
|
1172 | * not given, nodes with inline content default to allowing all
|
1173 | * marks, other nodes default to not allowing marks.
|
1174 | */
|
1175 | marks?: string | null | undefined;
|
1176 | /**
|
1177 | * The group or space-separated groups to which this node belongs,
|
1178 | * which can be referred to in the content expressions for the
|
1179 | * schema.
|
1180 | */
|
1181 | group?: string | null | undefined;
|
1182 | /**
|
1183 | * Should be set to true for inline nodes. (Implied for text nodes.)
|
1184 | */
|
1185 | inline?: boolean | null | undefined;
|
1186 | /**
|
1187 | * Can be set to true to indicate that, though this isn't a [leaf
|
1188 | * node](#model.NodeType.isLeaf), it doesn't have directly editable
|
1189 | * content and should be treated as a single unit in the view.
|
1190 | */
|
1191 | atom?: boolean | null | undefined;
|
1192 | /**
|
1193 | * The attributes that nodes of this type get.
|
1194 | */
|
1195 | attrs?: { [name: string]: AttributeSpec } | null | undefined;
|
1196 | /**
|
1197 | * Controls whether nodes of this type can be selected as a [node
|
1198 | * selection](#state.NodeSelection). Defaults to true for non-text
|
1199 | * nodes.
|
1200 | */
|
1201 | selectable?: boolean | null | undefined;
|
1202 | /**
|
1203 | * Determines whether nodes of this type can be dragged without
|
1204 | * being selected. Defaults to false.
|
1205 | */
|
1206 | draggable?: boolean | null | undefined;
|
1207 | /**
|
1208 | * Can be used to indicate that this node contains code, which
|
1209 | * causes some commands to behave differently.
|
1210 | */
|
1211 | code?: boolean | null | undefined;
|
1212 | /**
|
1213 | * Controls way whitespace in this a node is parsed. The default is
|
1214 | * `"normal"`, which causes the [DOM parser](#model.DOMParser) to
|
1215 | * collapse whitespace in normal mode, and normalize it (replacing
|
1216 | * newlines and such with spaces) otherwise. `"pre"` causes the
|
1217 | * parser to preserve spaces inside the node. When this option isn't
|
1218 | * given, but [`code`](#model.NodeSpec.code) is true, `whitespace`
|
1219 | * will default to `"pre"`. Note that this option doesn't influence
|
1220 | * the way the node is rendered—that should be handled by `toDOM`
|
1221 | * and/or styling.
|
1222 | */
|
1223 | whitespace?: 'pre' | 'normal';
|
1224 |
|
1225 | /**
|
1226 | * Determines whether this node is considered an important parent
|
1227 | * node during replace operations (such as paste). Non-defining (the
|
1228 | * default) nodes get dropped when their entire content is replaced,
|
1229 | * whereas defining nodes persist and wrap the inserted content.
|
1230 | */
|
1231 | definingAsContext?: boolean | null | undefined;
|
1232 |
|
1233 | /**
|
1234 | * In inserted content the defining parents of the content are
|
1235 | * preserved when possible. Typically, non-default-paragraph
|
1236 | * textblock types, and possibly list items, are marked as defining.
|
1237 | */
|
1238 | definingForContent?: boolean | null | undefined;
|
1239 |
|
1240 | /**
|
1241 | * When enabled, enables both
|
1242 | * [`definingAsContext`](#model.NodeSpec.definingAsContext) and
|
1243 | * [`definingForContent`](#model.NodeSpec.definingForContent).
|
1244 | */
|
1245 | defining?: boolean | null | undefined;
|
1246 | /**
|
1247 | * When enabled (default is false), the sides of nodes of this type
|
1248 | * count as boundaries that regular editing operations, like
|
1249 | * backspacing or lifting, won't cross. An example of a node that
|
1250 | * should probably have this enabled is a table cell.
|
1251 | */
|
1252 | isolating?: boolean | null | undefined;
|
1253 | /**
|
1254 | * Defines the default way a node of this type should be serialized
|
1255 | * to DOM/HTML (as used by
|
1256 | * [`DOMSerializer.fromSchema`](#model.DOMSerializer^fromSchema)).
|
1257 | * Should return a DOM node or an [array
|
1258 | * structure](#model.DOMOutputSpec) that describes one, with an
|
1259 | * optional number zero (“hole”) in it to indicate where the node's
|
1260 | * content should be inserted.
|
1261 | *
|
1262 | * For text nodes, the default is to create a text DOM node. Though
|
1263 | * it is possible to create a serializer where text is rendered
|
1264 | * differently, this is not supported inside the editor, so you
|
1265 | * shouldn't override that in your text node spec.
|
1266 | */
|
1267 | toDOM?: ((node: ProsemirrorNode) => DOMOutputSpec) | null | undefined;
|
1268 | /**
|
1269 | * Associates DOM parser information with this node, which can be
|
1270 | * used by [`DOMParser.fromSchema`](#model.DOMParser^fromSchema) to
|
1271 | * automatically derive a parser. The `node` field in the rules is
|
1272 | * implied (the name of this node will be filled in automatically).
|
1273 | * If you supply your own parser, you do not need to also specify
|
1274 | * parsing rules in your schema.
|
1275 | */
|
1276 | parseDOM?: ParseRule[] | null | undefined;
|
1277 | /**
|
1278 | * Defines the default way a node of this type should be serialized
|
1279 | * to a string representation for debugging (e.g. in error messages).
|
1280 | */
|
1281 | toDebugString?: ((node: ProsemirrorNode) => string) | null | undefined;
|
1282 | /**
|
1283 | * Allow specifying arbitrary fields on a NodeSpec.
|
1284 | */
|
1285 | [key: string]: any;
|
1286 | }
|
1287 | export interface MarkSpec {
|
1288 | /**
|
1289 | * The attributes that marks of this type get.
|
1290 | */
|
1291 | attrs?: { [name: string]: AttributeSpec } | null | undefined;
|
1292 | /**
|
1293 | * Whether this mark should be active when the cursor is positioned
|
1294 | * at its end (or at its start when that is also the start of the
|
1295 | * parent node). Defaults to true.
|
1296 | */
|
1297 | inclusive?: boolean | null | undefined;
|
1298 | /**
|
1299 | * Determines which other marks this mark can coexist with. Should
|
1300 | * be a space-separated strings naming other marks or groups of marks.
|
1301 | * When a mark is [added](#model.Mark.addToSet) to a set, all marks
|
1302 | * that it excludes are removed in the process. If the set contains
|
1303 | * any mark that excludes the new mark but is not, itself, excluded
|
1304 | * by the new mark, the mark can not be added an the set. You can
|
1305 | * use the value `"_"` to indicate that the mark excludes all
|
1306 | * marks in the schema.
|
1307 | *
|
1308 | * Defaults to only being exclusive with marks of the same type. You
|
1309 | * can set it to an empty string (or any string not containing the
|
1310 | * mark's own name) to allow multiple marks of a given type to
|
1311 | * coexist (as long as they have different attributes).
|
1312 | */
|
1313 | excludes?: string | null | undefined;
|
1314 | /**
|
1315 | * The group or space-separated groups to which this mark belongs.
|
1316 | */
|
1317 | group?: string | null | undefined;
|
1318 | /**
|
1319 | * Determines whether marks of this type can span multiple adjacent
|
1320 | * nodes when serialized to DOM/HTML. Defaults to true.
|
1321 | */
|
1322 | spanning?: boolean | null | undefined;
|
1323 | /**
|
1324 | * Defines the default way marks of this type should be serialized
|
1325 | * to DOM/HTML.
|
1326 | */
|
1327 | toDOM?: ((mark: Mark, inline: boolean) => DOMOutputSpec) | null | undefined;
|
1328 | /**
|
1329 | * Associates DOM parser information with this mark (see the
|
1330 | * corresponding [node spec field](#model.NodeSpec.parseDOM)). The
|
1331 | * `mark` field in the rules is implied.
|
1332 | */
|
1333 | parseDOM?: ParseRule[] | null | undefined;
|
1334 | /**
|
1335 | * Allow specifying arbitrary fields on a MarkSpec.
|
1336 | */
|
1337 | [key: string]: any;
|
1338 | }
|
1339 | /**
|
1340 | * Used to [define](#model.NodeSpec.attrs) attributes on nodes or
|
1341 | * marks.
|
1342 | */
|
1343 | export interface AttributeSpec {
|
1344 | /**
|
1345 | * The default value for this attribute, to use when no explicit
|
1346 | * value is provided. Attributes that have no default must be
|
1347 | * provided whenever a node or mark of a type that has them is
|
1348 | * created.
|
1349 | */
|
1350 | default?: any;
|
1351 | }
|
1352 | /**
|
1353 | * A document schema. Holds [node](#model.NodeType) and [mark
|
1354 | * type](#model.MarkType) objects for the nodes and marks that may
|
1355 | * occur in conforming documents, and provides functionality for
|
1356 | * creating and deserializing such documents.
|
1357 | */
|
1358 | export class Schema<N extends string = any, M extends string = any> {
|
1359 | /**
|
1360 | * Construct a schema from a schema [specification](#model.SchemaSpec).
|
1361 | */
|
1362 | constructor(spec: SchemaSpec<N, M>);
|
1363 | /**
|
1364 | * The [spec](#model.SchemaSpec) on which the schema is based,
|
1365 | * with the added guarantee that its `nodes` and `marks`
|
1366 | * properties are
|
1367 | * [`OrderedMap`](https:
|
1368 | * (not raw objects).
|
1369 | */
|
1370 | spec: SchemaSpec<N, M>;
|
1371 | |
1372 |
|
1373 |
|
1374 | nodes: { [name in N]: NodeType<Schema<N, M>> } & { [key: string]: NodeType<Schema<N, M>> };
|
1375 | |
1376 |
|
1377 |
|
1378 | marks: { [name in M]: MarkType<Schema<N, M>> } & { [key: string]: MarkType<Schema<N, M>> };
|
1379 | |
1380 |
|
1381 |
|
1382 |
|
1383 | topNodeType: NodeType<Schema<N, M>>;
|
1384 | |
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 | cached: { [key: string]: any };
|
1390 | |
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 | node(
|
1397 | type: string | NodeType<Schema<N, M>>,
|
1398 | attrs?: { [key: string]: any },
|
1399 | content?: Fragment<Schema<N, M>> | ProsemirrorNode<Schema<N, M>> | Array<ProsemirrorNode<Schema<N, M>>>,
|
1400 | marks?: Array<Mark<Schema<N, M>>>,
|
1401 | ): ProsemirrorNode<Schema<N, M>>;
|
1402 | |
1403 |
|
1404 |
|
1405 |
|
1406 | text(text: string, marks?: Array<Mark<Schema<N, M>>>): ProsemirrorNode<Schema<N, M>>;
|
1407 | |
1408 |
|
1409 |
|
1410 | mark(type: string | MarkType<Schema<N, M>>, attrs?: { [key: string]: any }): Mark<Schema<N, M>>;
|
1411 | |
1412 |
|
1413 |
|
1414 |
|
1415 | nodeFromJSON(json: { [key: string]: any }): ProsemirrorNode<Schema<N, M>>;
|
1416 | |
1417 |
|
1418 |
|
1419 |
|
1420 | markFromJSON(json: { [key: string]: any }): Mark<Schema<N, M>>;
|
1421 | }
|
1422 | export interface DOMOutputSpecArray {
|
1423 | 0: string;
|
1424 | 1?: DOMOutputSpec | 0 | { [attr: string]: string | null | undefined } | undefined;
|
1425 | 2?: DOMOutputSpec | 0 | undefined;
|
1426 | 3?: DOMOutputSpec | 0 | undefined;
|
1427 | 4?: DOMOutputSpec | 0 | undefined;
|
1428 | 5?: DOMOutputSpec | 0 | undefined;
|
1429 | 6?: DOMOutputSpec | 0 | undefined;
|
1430 | 7?: DOMOutputSpec | 0 | undefined;
|
1431 | 8?: DOMOutputSpec | 0 | undefined;
|
1432 | 9?: DOMOutputSpec | 0 | undefined;
|
1433 | }
|
1434 | export type DOMOutputSpec = string | Node | DOMOutputSpecArray | { dom: Node; contentDOM?: Node | undefined };
|
1435 |
|
1436 |
|
1437 |
|
1438 |
|
1439 | export class DOMSerializer<S extends Schema = any> {
|
1440 | |
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 | constructor(
|
1450 | nodes: { [name: string]: (node: ProsemirrorNode<S>) => DOMOutputSpec },
|
1451 | marks: { [name: string]: (mark: Mark<S>, inline: boolean) => DOMOutputSpec },
|
1452 | );
|
1453 | |
1454 |
|
1455 |
|
1456 | nodes: { [name: string]: (node: ProsemirrorNode<S>) => DOMOutputSpec };
|
1457 | |
1458 |
|
1459 |
|
1460 | marks: { [name: string]: (mark: Mark<S>, inline: boolean) => DOMOutputSpec };
|
1461 | |
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 | serializeFragment(fragment: Fragment<S>, options?: { [key: string]: any }): DocumentFragment;
|
1468 | |
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 | serializeNode(node: ProsemirrorNode<S>, options?: { [key: string]: any }): Node;
|
1476 | |
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 | static renderSpec(doc: Document, structure: DOMOutputSpec): { dom: Node; contentDOM?: Node | null | undefined };
|
1482 | |
1483 |
|
1484 |
|
1485 |
|
1486 | static fromSchema<S extends Schema = any>(schema: S): DOMSerializer<S>;
|
1487 | }
|
1488 |
|
\ | No newline at end of file |