index.d.ts 57 KB

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